The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.view; |
| 18 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 19 | import android.content.ClipData; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 21 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.res.Resources; |
| 23 | import android.content.res.TypedArray; |
| 24 | import android.graphics.Bitmap; |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 25 | import android.graphics.Camera; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.graphics.Canvas; |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 27 | import android.graphics.Insets; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 28 | import android.graphics.Interpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.graphics.LinearGradient; |
| 30 | import android.graphics.Matrix; |
| 31 | import android.graphics.Paint; |
| 32 | import android.graphics.PixelFormat; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 33 | import android.graphics.Point; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.graphics.PorterDuff; |
| 35 | import android.graphics.PorterDuffXfermode; |
| 36 | import android.graphics.Rect; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 37 | import android.graphics.RectF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.graphics.Region; |
| 39 | import android.graphics.Shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.graphics.drawable.ColorDrawable; |
| 41 | import android.graphics.drawable.Drawable; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 42 | import android.hardware.display.DisplayManagerGlobal; |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 43 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.os.Handler; |
| 45 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.os.Parcel; |
| 47 | import android.os.Parcelable; |
| 48 | import android.os.RemoteException; |
| 49 | import android.os.SystemClock; |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 50 | import android.os.SystemProperties; |
Fabrice Di Meglio | d3d9f3f | 2012-09-18 12:55:32 -0700 | [diff] [blame] | 51 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.util.AttributeSet; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 53 | import android.util.FloatProperty; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.util.Log; |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 55 | import android.util.Pools.SynchronizedPool; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 56 | import android.util.Property; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 57 | import android.util.SparseArray; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 58 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.view.ContextMenu.ContextMenuInfo; |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 60 | import android.view.AccessibilityIterators.TextSegmentIterator; |
| 61 | import android.view.AccessibilityIterators.CharacterTextSegmentIterator; |
| 62 | import android.view.AccessibilityIterators.WordTextSegmentIterator; |
| 63 | import android.view.AccessibilityIterators.ParagraphTextSegmentIterator; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 64 | import android.view.accessibility.AccessibilityEvent; |
| 65 | import android.view.accessibility.AccessibilityEventSource; |
| 66 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 67 | import android.view.accessibility.AccessibilityNodeInfo; |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 68 | import android.view.accessibility.AccessibilityNodeProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.view.animation.Animation; |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 70 | import android.view.animation.AnimationUtils; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 71 | import android.view.animation.Transformation; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 72 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.view.inputmethod.InputConnection; |
| 74 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.widget.ScrollBarDrawable; |
| 76 | |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 77 | import static android.os.Build.VERSION_CODES.*; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 78 | import static java.lang.Math.max; |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 79 | |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 80 | import com.android.internal.R; |
| 81 | import com.android.internal.util.Predicate; |
| 82 | import com.android.internal.view.menu.MenuBuilder; |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 83 | import com.google.android.collect.Lists; |
| 84 | import com.google.android.collect.Maps; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 85 | |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 86 | import java.lang.ref.WeakReference; |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 87 | import java.lang.reflect.Field; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 88 | import java.lang.reflect.InvocationTargetException; |
| 89 | import java.lang.reflect.Method; |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 90 | import java.lang.reflect.Modifier; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | import java.util.ArrayList; |
| 92 | import java.util.Arrays; |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 93 | import java.util.Collections; |
| 94 | import java.util.HashMap; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 95 | import java.util.Locale; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 96 | import java.util.concurrent.CopyOnWriteArrayList; |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 97 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | |
| 99 | /** |
| 100 | * <p> |
| 101 | * This class represents the basic building block for user interface components. A View |
| 102 | * occupies a rectangular area on the screen and is responsible for drawing and |
| 103 | * 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] | 104 | * 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] | 105 | * {@link android.view.ViewGroup} subclass is the base class for <em>layouts</em>, which |
| 106 | * are invisible containers that hold other Views (or other ViewGroups) and define |
| 107 | * their layout properties. |
| 108 | * </p> |
| 109 | * |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 110 | * <div class="special reference"> |
| 111 | * <h3>Developer Guides</h3> |
| 112 | * <p>For information about using this class to develop your application's user interface, |
| 113 | * 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] | 114 | * </div> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 115 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | * <a name="Using"></a> |
| 117 | * <h3>Using Views</h3> |
| 118 | * <p> |
| 119 | * All of the views in a window are arranged in a single tree. You can add views |
| 120 | * either from code or by specifying a tree of views in one or more XML layout |
| 121 | * files. There are many specialized subclasses of views that act as controls or |
| 122 | * are capable of displaying text, images, or other content. |
| 123 | * </p> |
| 124 | * <p> |
| 125 | * Once you have created a tree of views, there are typically a few types of |
| 126 | * common operations you may wish to perform: |
| 127 | * <ul> |
| 128 | * <li><strong>Set properties:</strong> for example setting the text of a |
| 129 | * {@link android.widget.TextView}. The available properties and the methods |
| 130 | * that set them will vary among the different subclasses of views. Note that |
| 131 | * properties that are known at build time can be set in the XML layout |
| 132 | * files.</li> |
| 133 | * <li><strong>Set focus:</strong> The framework will handled moving focus in |
| 134 | * response to user input. To force focus to a specific view, call |
| 135 | * {@link #requestFocus}.</li> |
| 136 | * <li><strong>Set up listeners:</strong> Views allow clients to set listeners |
| 137 | * that will be notified when something interesting happens to the view. For |
| 138 | * example, all views will let you set a listener to be notified when the view |
| 139 | * gains or loses focus. You can register such a listener using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 140 | * {@link #setOnFocusChangeListener(android.view.View.OnFocusChangeListener)}. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 141 | * Other view subclasses offer more specialized listeners. For example, a Button |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 142 | * 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] | 143 | * <li><strong>Set visibility:</strong> You can hide or show views using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 144 | * {@link #setVisibility(int)}.</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | * </ul> |
| 146 | * </p> |
| 147 | * <p><em> |
| 148 | * Note: The Android framework is responsible for measuring, laying out and |
| 149 | * drawing views. You should not call methods that perform these actions on |
| 150 | * views yourself unless you are actually implementing a |
| 151 | * {@link android.view.ViewGroup}. |
| 152 | * </em></p> |
| 153 | * |
| 154 | * <a name="Lifecycle"></a> |
| 155 | * <h3>Implementing a Custom View</h3> |
| 156 | * |
| 157 | * <p> |
| 158 | * To implement a custom view, you will usually begin by providing overrides for |
| 159 | * some of the standard methods that the framework calls on all views. You do |
| 160 | * not need to override all of these methods. In fact, you can start by just |
| 161 | * overriding {@link #onDraw(android.graphics.Canvas)}. |
| 162 | * <table border="2" width="85%" align="center" cellpadding="5"> |
| 163 | * <thead> |
| 164 | * <tr><th>Category</th> <th>Methods</th> <th>Description</th></tr> |
| 165 | * </thead> |
| 166 | * |
| 167 | * <tbody> |
| 168 | * <tr> |
| 169 | * <td rowspan="2">Creation</td> |
| 170 | * <td>Constructors</td> |
| 171 | * <td>There is a form of the constructor that are called when the view |
| 172 | * is created from code and a form that is called when the view is |
| 173 | * inflated from a layout file. The second form should parse and apply |
| 174 | * any attributes defined in the layout file. |
| 175 | * </td> |
| 176 | * </tr> |
| 177 | * <tr> |
| 178 | * <td><code>{@link #onFinishInflate()}</code></td> |
| 179 | * <td>Called after a view and all of its children has been inflated |
| 180 | * from XML.</td> |
| 181 | * </tr> |
| 182 | * |
| 183 | * <tr> |
| 184 | * <td rowspan="3">Layout</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 185 | * <td><code>{@link #onMeasure(int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | * <td>Called to determine the size requirements for this view and all |
| 187 | * of its children. |
| 188 | * </td> |
| 189 | * </tr> |
| 190 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 191 | * <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] | 192 | * <td>Called when this view should assign a size and position to all |
| 193 | * of its children. |
| 194 | * </td> |
| 195 | * </tr> |
| 196 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 197 | * <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] | 198 | * <td>Called when the size of this view has changed. |
| 199 | * </td> |
| 200 | * </tr> |
| 201 | * |
| 202 | * <tr> |
| 203 | * <td>Drawing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 204 | * <td><code>{@link #onDraw(android.graphics.Canvas)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | * <td>Called when the view should render its content. |
| 206 | * </td> |
| 207 | * </tr> |
| 208 | * |
| 209 | * <tr> |
| 210 | * <td rowspan="4">Event processing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 211 | * <td><code>{@link #onKeyDown(int, KeyEvent)}</code></td> |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 212 | * <td>Called when a new hardware key event occurs. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | * </td> |
| 214 | * </tr> |
| 215 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 216 | * <td><code>{@link #onKeyUp(int, KeyEvent)}</code></td> |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 217 | * <td>Called when a hardware key up event occurs. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | * </td> |
| 219 | * </tr> |
| 220 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 221 | * <td><code>{@link #onTrackballEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | * <td>Called when a trackball motion event occurs. |
| 223 | * </td> |
| 224 | * </tr> |
| 225 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 226 | * <td><code>{@link #onTouchEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | * <td>Called when a touch screen motion event occurs. |
| 228 | * </td> |
| 229 | * </tr> |
| 230 | * |
| 231 | * <tr> |
| 232 | * <td rowspan="2">Focus</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 233 | * <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] | 234 | * <td>Called when the view gains or loses focus. |
| 235 | * </td> |
| 236 | * </tr> |
| 237 | * |
| 238 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 239 | * <td><code>{@link #onWindowFocusChanged(boolean)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | * <td>Called when the window containing the view gains or loses focus. |
| 241 | * </td> |
| 242 | * </tr> |
| 243 | * |
| 244 | * <tr> |
| 245 | * <td rowspan="3">Attaching</td> |
| 246 | * <td><code>{@link #onAttachedToWindow()}</code></td> |
| 247 | * <td>Called when the view is attached to a window. |
| 248 | * </td> |
| 249 | * </tr> |
| 250 | * |
| 251 | * <tr> |
| 252 | * <td><code>{@link #onDetachedFromWindow}</code></td> |
| 253 | * <td>Called when the view is detached from its window. |
| 254 | * </td> |
| 255 | * </tr> |
| 256 | * |
| 257 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 258 | * <td><code>{@link #onWindowVisibilityChanged(int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | * <td>Called when the visibility of the window containing the view |
| 260 | * has changed. |
| 261 | * </td> |
| 262 | * </tr> |
| 263 | * </tbody> |
| 264 | * |
| 265 | * </table> |
| 266 | * </p> |
| 267 | * |
| 268 | * <a name="IDs"></a> |
| 269 | * <h3>IDs</h3> |
| 270 | * Views may have an integer id associated with them. These ids are typically |
| 271 | * assigned in the layout XML files, and are used to find specific views within |
| 272 | * the view tree. A common pattern is to: |
| 273 | * <ul> |
| 274 | * <li>Define a Button in the layout file and assign it a unique ID. |
| 275 | * <pre> |
Gilles Debunne | 0243caf | 2010-08-24 23:06:35 -0700 | [diff] [blame] | 276 | * <Button |
| 277 | * android:id="@+id/my_button" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | * android:layout_width="wrap_content" |
| 279 | * android:layout_height="wrap_content" |
| 280 | * android:text="@string/my_button_text"/> |
| 281 | * </pre></li> |
| 282 | * <li>From the onCreate method of an Activity, find the Button |
| 283 | * <pre class="prettyprint"> |
| 284 | * Button myButton = (Button) findViewById(R.id.my_button); |
| 285 | * </pre></li> |
| 286 | * </ul> |
| 287 | * <p> |
| 288 | * View IDs need not be unique throughout the tree, but it is good practice to |
| 289 | * ensure that they are at least unique within the part of the tree you are |
| 290 | * searching. |
| 291 | * </p> |
| 292 | * |
| 293 | * <a name="Position"></a> |
| 294 | * <h3>Position</h3> |
| 295 | * <p> |
| 296 | * The geometry of a view is that of a rectangle. A view has a location, |
| 297 | * expressed as a pair of <em>left</em> and <em>top</em> coordinates, and |
| 298 | * two dimensions, expressed as a width and a height. The unit for location |
| 299 | * and dimensions is the pixel. |
| 300 | * </p> |
| 301 | * |
| 302 | * <p> |
| 303 | * It is possible to retrieve the location of a view by invoking the methods |
| 304 | * {@link #getLeft()} and {@link #getTop()}. The former returns the left, or X, |
| 305 | * coordinate of the rectangle representing the view. The latter returns the |
| 306 | * top, or Y, coordinate of the rectangle representing the view. These methods |
| 307 | * both return the location of the view relative to its parent. For instance, |
| 308 | * when getLeft() returns 20, that means the view is located 20 pixels to the |
| 309 | * right of the left edge of its direct parent. |
| 310 | * </p> |
| 311 | * |
| 312 | * <p> |
| 313 | * In addition, several convenience methods are offered to avoid unnecessary |
| 314 | * computations, namely {@link #getRight()} and {@link #getBottom()}. |
| 315 | * These methods return the coordinates of the right and bottom edges of the |
| 316 | * rectangle representing the view. For instance, calling {@link #getRight()} |
| 317 | * is similar to the following computation: <code>getLeft() + getWidth()</code> |
| 318 | * (see <a href="#SizePaddingMargins">Size</a> for more information about the width.) |
| 319 | * </p> |
| 320 | * |
| 321 | * <a name="SizePaddingMargins"></a> |
| 322 | * <h3>Size, padding and margins</h3> |
| 323 | * <p> |
| 324 | * The size of a view is expressed with a width and a height. A view actually |
| 325 | * possess two pairs of width and height values. |
| 326 | * </p> |
| 327 | * |
| 328 | * <p> |
| 329 | * The first pair is known as <em>measured width</em> and |
| 330 | * <em>measured height</em>. These dimensions define how big a view wants to be |
| 331 | * within its parent (see <a href="#Layout">Layout</a> for more details.) The |
| 332 | * measured dimensions can be obtained by calling {@link #getMeasuredWidth()} |
| 333 | * and {@link #getMeasuredHeight()}. |
| 334 | * </p> |
| 335 | * |
| 336 | * <p> |
| 337 | * The second pair is simply known as <em>width</em> and <em>height</em>, or |
| 338 | * sometimes <em>drawing width</em> and <em>drawing height</em>. These |
| 339 | * dimensions define the actual size of the view on screen, at drawing time and |
| 340 | * after layout. These values may, but do not have to, be different from the |
| 341 | * measured width and height. The width and height can be obtained by calling |
| 342 | * {@link #getWidth()} and {@link #getHeight()}. |
| 343 | * </p> |
| 344 | * |
| 345 | * <p> |
| 346 | * To measure its dimensions, a view takes into account its padding. The padding |
| 347 | * is expressed in pixels for the left, top, right and bottom parts of the view. |
| 348 | * Padding can be used to offset the content of the view by a specific amount of |
| 349 | * pixels. For instance, a left padding of 2 will push the view's content by |
| 350 | * 2 pixels to the right of the left edge. Padding can be set using the |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 351 | * {@link #setPadding(int, int, int, int)} or {@link #setPaddingRelative(int, int, int, int)} |
| 352 | * method and queried by calling {@link #getPaddingLeft()}, {@link #getPaddingTop()}, |
| 353 | * {@link #getPaddingRight()}, {@link #getPaddingBottom()}, {@link #getPaddingStart()}, |
| 354 | * {@link #getPaddingEnd()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | * </p> |
| 356 | * |
| 357 | * <p> |
| 358 | * Even though a view can define a padding, it does not provide any support for |
| 359 | * margins. However, view groups provide such a support. Refer to |
| 360 | * {@link android.view.ViewGroup} and |
| 361 | * {@link android.view.ViewGroup.MarginLayoutParams} for further information. |
| 362 | * </p> |
| 363 | * |
| 364 | * <a name="Layout"></a> |
| 365 | * <h3>Layout</h3> |
| 366 | * <p> |
| 367 | * Layout is a two pass process: a measure pass and a layout pass. The measuring |
| 368 | * pass is implemented in {@link #measure(int, int)} and is a top-down traversal |
| 369 | * of the view tree. Each view pushes dimension specifications down the tree |
| 370 | * during the recursion. At the end of the measure pass, every view has stored |
| 371 | * its measurements. The second pass happens in |
| 372 | * {@link #layout(int,int,int,int)} and is also top-down. During |
| 373 | * this pass each parent is responsible for positioning all of its children |
| 374 | * using the sizes computed in the measure pass. |
| 375 | * </p> |
| 376 | * |
| 377 | * <p> |
| 378 | * When a view's measure() method returns, its {@link #getMeasuredWidth()} and |
| 379 | * {@link #getMeasuredHeight()} values must be set, along with those for all of |
| 380 | * that view's descendants. A view's measured width and measured height values |
| 381 | * must respect the constraints imposed by the view's parents. This guarantees |
| 382 | * that at the end of the measure pass, all parents accept all of their |
| 383 | * children's measurements. A parent view may call measure() more than once on |
| 384 | * its children. For example, the parent may measure each child once with |
| 385 | * unspecified dimensions to find out how big they want to be, then call |
| 386 | * measure() on them again with actual numbers if the sum of all the children's |
| 387 | * unconstrained sizes is too big or too small. |
| 388 | * </p> |
| 389 | * |
| 390 | * <p> |
| 391 | * The measure pass uses two classes to communicate dimensions. The |
| 392 | * {@link MeasureSpec} class is used by views to tell their parents how they |
| 393 | * want to be measured and positioned. The base LayoutParams class just |
| 394 | * describes how big the view wants to be for both width and height. For each |
| 395 | * dimension, it can specify one of: |
| 396 | * <ul> |
| 397 | * <li> an exact number |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 398 | * <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] | 399 | * (minus padding) |
| 400 | * <li> WRAP_CONTENT, which means that the view wants to be just big enough to |
| 401 | * enclose its content (plus padding). |
| 402 | * </ul> |
| 403 | * There are subclasses of LayoutParams for different subclasses of ViewGroup. |
| 404 | * For example, AbsoluteLayout has its own subclass of LayoutParams which adds |
| 405 | * an X and Y value. |
| 406 | * </p> |
| 407 | * |
| 408 | * <p> |
| 409 | * MeasureSpecs are used to push requirements down the tree from parent to |
| 410 | * child. A MeasureSpec can be in one of three modes: |
| 411 | * <ul> |
| 412 | * <li>UNSPECIFIED: This is used by a parent to determine the desired dimension |
| 413 | * of a child view. For example, a LinearLayout may call measure() on its child |
| 414 | * with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how |
| 415 | * tall the child view wants to be given a width of 240 pixels. |
| 416 | * <li>EXACTLY: This is used by the parent to impose an exact size on the |
| 417 | * child. The child must use this size, and guarantee that all of its |
| 418 | * descendants will fit within this size. |
| 419 | * <li>AT_MOST: This is used by the parent to impose a maximum size on the |
| 420 | * child. The child must gurantee that it and all of its descendants will fit |
| 421 | * within this size. |
| 422 | * </ul> |
| 423 | * </p> |
| 424 | * |
| 425 | * <p> |
| 426 | * To intiate a layout, call {@link #requestLayout}. This method is typically |
| 427 | * called by a view on itself when it believes that is can no longer fit within |
| 428 | * its current bounds. |
| 429 | * </p> |
| 430 | * |
| 431 | * <a name="Drawing"></a> |
| 432 | * <h3>Drawing</h3> |
| 433 | * <p> |
| 434 | * Drawing is handled by walking the tree and rendering each view that |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 435 | * 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] | 436 | * this means that parents will draw before (i.e., behind) their children, with |
| 437 | * siblings drawn in the order they appear in the tree. |
| 438 | * If you set a background drawable for a View, then the View will draw it for you |
| 439 | * before calling back to its <code>onDraw()</code> method. |
| 440 | * </p> |
| 441 | * |
| 442 | * <p> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 443 | * 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] | 444 | * </p> |
| 445 | * |
| 446 | * <p> |
| 447 | * To force a view to draw, call {@link #invalidate()}. |
| 448 | * </p> |
| 449 | * |
| 450 | * <a name="EventHandlingThreading"></a> |
| 451 | * <h3>Event Handling and Threading</h3> |
| 452 | * <p> |
| 453 | * The basic cycle of a view is as follows: |
| 454 | * <ol> |
| 455 | * <li>An event comes in and is dispatched to the appropriate view. The view |
| 456 | * handles the event and notifies any listeners.</li> |
| 457 | * <li>If in the course of processing the event, the view's bounds may need |
| 458 | * to be changed, the view will call {@link #requestLayout()}.</li> |
| 459 | * <li>Similarly, if in the course of processing the event the view's appearance |
| 460 | * may need to be changed, the view will call {@link #invalidate()}.</li> |
| 461 | * <li>If either {@link #requestLayout()} or {@link #invalidate()} were called, |
| 462 | * the framework will take care of measuring, laying out, and drawing the tree |
| 463 | * as appropriate.</li> |
| 464 | * </ol> |
| 465 | * </p> |
| 466 | * |
| 467 | * <p><em>Note: The entire view tree is single threaded. You must always be on |
| 468 | * the UI thread when calling any method on any view.</em> |
| 469 | * If you are doing work on other threads and want to update the state of a view |
| 470 | * from that thread, you should use a {@link Handler}. |
| 471 | * </p> |
| 472 | * |
| 473 | * <a name="FocusHandling"></a> |
| 474 | * <h3>Focus Handling</h3> |
| 475 | * <p> |
| 476 | * The framework will handle routine focus movement in response to user input. |
| 477 | * This includes changing the focus as views are removed or hidden, or as new |
| 478 | * views become available. Views indicate their willingness to take focus |
| 479 | * through the {@link #isFocusable} method. To change whether a view can take |
| 480 | * focus, call {@link #setFocusable(boolean)}. When in touch mode (see notes below) |
| 481 | * views indicate whether they still would like focus via {@link #isFocusableInTouchMode} |
| 482 | * and can change this via {@link #setFocusableInTouchMode(boolean)}. |
| 483 | * </p> |
| 484 | * <p> |
| 485 | * Focus movement is based on an algorithm which finds the nearest neighbor in a |
| 486 | * given direction. In rare cases, the default algorithm may not match the |
| 487 | * intended behavior of the developer. In these situations, you can provide |
| 488 | * explicit overrides by using these XML attributes in the layout file: |
| 489 | * <pre> |
| 490 | * nextFocusDown |
| 491 | * nextFocusLeft |
| 492 | * nextFocusRight |
| 493 | * nextFocusUp |
| 494 | * </pre> |
| 495 | * </p> |
| 496 | * |
| 497 | * |
| 498 | * <p> |
| 499 | * To get a particular view to take focus, call {@link #requestFocus()}. |
| 500 | * </p> |
| 501 | * |
| 502 | * <a name="TouchMode"></a> |
| 503 | * <h3>Touch Mode</h3> |
| 504 | * <p> |
| 505 | * When a user is navigating a user interface via directional keys such as a D-pad, it is |
| 506 | * necessary to give focus to actionable items such as buttons so the user can see |
| 507 | * what will take input. If the device has touch capabilities, however, and the user |
| 508 | * begins interacting with the interface by touching it, it is no longer necessary to |
| 509 | * always highlight, or give focus to, a particular view. This motivates a mode |
| 510 | * for interaction named 'touch mode'. |
| 511 | * </p> |
| 512 | * <p> |
| 513 | * For a touch capable device, once the user touches the screen, the device |
| 514 | * will enter touch mode. From this point onward, only views for which |
| 515 | * {@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets. |
| 516 | * Other views that are touchable, like buttons, will not take focus when touched; they will |
| 517 | * only fire the on click listeners. |
| 518 | * </p> |
| 519 | * <p> |
| 520 | * Any time a user hits a directional key, such as a D-pad direction, the view device will |
| 521 | * exit touch mode, and find a view to take focus, so that the user may resume interacting |
| 522 | * with the user interface without touching the screen again. |
| 523 | * </p> |
| 524 | * <p> |
| 525 | * The touch mode state is maintained across {@link android.app.Activity}s. Call |
| 526 | * {@link #isInTouchMode} to see whether the device is currently in touch mode. |
| 527 | * </p> |
| 528 | * |
| 529 | * <a name="Scrolling"></a> |
| 530 | * <h3>Scrolling</h3> |
| 531 | * <p> |
| 532 | * The framework provides basic support for views that wish to internally |
| 533 | * scroll their content. This includes keeping track of the X and Y scroll |
| 534 | * offset as well as mechanisms for drawing scrollbars. See |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 535 | * {@link #scrollBy(int, int)}, {@link #scrollTo(int, int)}, and |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 536 | * {@link #awakenScrollBars()} for more details. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | * </p> |
| 538 | * |
| 539 | * <a name="Tags"></a> |
| 540 | * <h3>Tags</h3> |
| 541 | * <p> |
| 542 | * Unlike IDs, tags are not used to identify views. Tags are essentially an |
| 543 | * extra piece of information that can be associated with a view. They are most |
| 544 | * often used as a convenience to store data related to views in the views |
| 545 | * themselves rather than by putting them in a separate structure. |
| 546 | * </p> |
| 547 | * |
Chet Haase | cb150fe | 2012-05-03 15:15:05 -0700 | [diff] [blame] | 548 | * <a name="Properties"></a> |
| 549 | * <h3>Properties</h3> |
| 550 | * <p> |
| 551 | * The View class exposes an {@link #ALPHA} property, as well as several transform-related |
| 552 | * properties, such as {@link #TRANSLATION_X} and {@link #TRANSLATION_Y}. These properties are |
| 553 | * available both in the {@link Property} form as well as in similarly-named setter/getter |
| 554 | * methods (such as {@link #setAlpha(float)} for {@link #ALPHA}). These properties can |
| 555 | * be used to set persistent state associated with these rendering-related properties on the view. |
| 556 | * The properties and methods can also be used in conjunction with |
| 557 | * {@link android.animation.Animator Animator}-based animations, described more in the |
| 558 | * <a href="#Animation">Animation</a> section. |
| 559 | * </p> |
| 560 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | * <a name="Animation"></a> |
| 562 | * <h3>Animation</h3> |
| 563 | * <p> |
Chet Haase | cb150fe | 2012-05-03 15:15:05 -0700 | [diff] [blame] | 564 | * Starting with Android 3.0, the preferred way of animating views is to use the |
| 565 | * {@link android.animation} package APIs. These {@link android.animation.Animator Animator}-based |
| 566 | * classes change actual properties of the View object, such as {@link #setAlpha(float) alpha} and |
| 567 | * {@link #setTranslationX(float) translationX}. This behavior is contrasted to that of the pre-3.0 |
| 568 | * {@link android.view.animation.Animation Animation}-based classes, which instead animate only |
| 569 | * how the view is drawn on the display. In particular, the {@link ViewPropertyAnimator} class |
| 570 | * makes animating these View properties particularly easy and efficient. |
| 571 | * </p> |
| 572 | * <p> |
| 573 | * Alternatively, you can use the pre-3.0 animation classes to animate how Views are rendered. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | * You can attach an {@link Animation} object to a view using |
| 575 | * {@link #setAnimation(Animation)} or |
| 576 | * {@link #startAnimation(Animation)}. The animation can alter the scale, |
| 577 | * rotation, translation and alpha of a view over time. If the animation is |
| 578 | * attached to a view that has children, the animation will affect the entire |
| 579 | * subtree rooted by that node. When an animation is started, the framework will |
| 580 | * take care of redrawing the appropriate views until the animation completes. |
| 581 | * </p> |
| 582 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 583 | * <a name="Security"></a> |
| 584 | * <h3>Security</h3> |
| 585 | * <p> |
| 586 | * Sometimes it is essential that an application be able to verify that an action |
| 587 | * is being performed with the full knowledge and consent of the user, such as |
| 588 | * granting a permission request, making a purchase or clicking on an advertisement. |
| 589 | * Unfortunately, a malicious application could try to spoof the user into |
| 590 | * performing these actions, unaware, by concealing the intended purpose of the view. |
| 591 | * As a remedy, the framework offers a touch filtering mechanism that can be used to |
| 592 | * improve the security of views that provide access to sensitive functionality. |
| 593 | * </p><p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 594 | * To enable touch filtering, call {@link #setFilterTouchesWhenObscured(boolean)} or set the |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 595 | * android:filterTouchesWhenObscured layout attribute to true. When enabled, the framework |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 596 | * will discard touches that are received whenever the view's window is obscured by |
| 597 | * another visible window. As a result, the view will not receive touches whenever a |
| 598 | * toast, dialog or other window appears above the view's window. |
| 599 | * </p><p> |
| 600 | * For more fine-grained control over security, consider overriding the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 601 | * {@link #onFilterTouchEventForSecurity(MotionEvent)} method to implement your own |
| 602 | * security policy. See also {@link MotionEvent#FLAG_WINDOW_IS_OBSCURED}. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 603 | * </p> |
| 604 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 605 | * @attr ref android.R.styleable#View_alpha |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 606 | * @attr ref android.R.styleable#View_background |
| 607 | * @attr ref android.R.styleable#View_clickable |
| 608 | * @attr ref android.R.styleable#View_contentDescription |
| 609 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 610 | * @attr ref android.R.styleable#View_duplicateParentState |
| 611 | * @attr ref android.R.styleable#View_id |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 612 | * @attr ref android.R.styleable#View_requiresFadingEdge |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 613 | * @attr ref android.R.styleable#View_fadeScrollbars |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 614 | * @attr ref android.R.styleable#View_fadingEdgeLength |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 615 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 617 | * @attr ref android.R.styleable#View_isScrollContainer |
| 618 | * @attr ref android.R.styleable#View_focusable |
| 619 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 620 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 621 | * @attr ref android.R.styleable#View_keepScreenOn |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 622 | * @attr ref android.R.styleable#View_layerType |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 623 | * @attr ref android.R.styleable#View_layoutDirection |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 624 | * @attr ref android.R.styleable#View_longClickable |
| 625 | * @attr ref android.R.styleable#View_minHeight |
| 626 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | * @attr ref android.R.styleable#View_nextFocusDown |
| 628 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 629 | * @attr ref android.R.styleable#View_nextFocusRight |
| 630 | * @attr ref android.R.styleable#View_nextFocusUp |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 631 | * @attr ref android.R.styleable#View_onClick |
| 632 | * @attr ref android.R.styleable#View_padding |
| 633 | * @attr ref android.R.styleable#View_paddingBottom |
| 634 | * @attr ref android.R.styleable#View_paddingLeft |
| 635 | * @attr ref android.R.styleable#View_paddingRight |
| 636 | * @attr ref android.R.styleable#View_paddingTop |
Fabrice Di Meglio | 101d5aa | 2012-02-16 18:36:06 -0800 | [diff] [blame] | 637 | * @attr ref android.R.styleable#View_paddingStart |
| 638 | * @attr ref android.R.styleable#View_paddingEnd |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 639 | * @attr ref android.R.styleable#View_saveEnabled |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 640 | * @attr ref android.R.styleable#View_rotation |
| 641 | * @attr ref android.R.styleable#View_rotationX |
| 642 | * @attr ref android.R.styleable#View_rotationY |
| 643 | * @attr ref android.R.styleable#View_scaleX |
| 644 | * @attr ref android.R.styleable#View_scaleY |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 645 | * @attr ref android.R.styleable#View_scrollX |
| 646 | * @attr ref android.R.styleable#View_scrollY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 647 | * @attr ref android.R.styleable#View_scrollbarSize |
| 648 | * @attr ref android.R.styleable#View_scrollbarStyle |
| 649 | * @attr ref android.R.styleable#View_scrollbars |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 650 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 651 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 652 | * @attr ref android.R.styleable#View_scrollbarTrackHorizontal |
| 653 | * @attr ref android.R.styleable#View_scrollbarThumbHorizontal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | * @attr ref android.R.styleable#View_scrollbarThumbVertical |
| 655 | * @attr ref android.R.styleable#View_scrollbarTrackVertical |
| 656 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawHorizontalTrack |
| 657 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawVerticalTrack |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 658 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 659 | * @attr ref android.R.styleable#View_tag |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 660 | * @attr ref android.R.styleable#View_textAlignment |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 661 | * @attr ref android.R.styleable#View_textDirection |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 662 | * @attr ref android.R.styleable#View_transformPivotX |
| 663 | * @attr ref android.R.styleable#View_transformPivotY |
| 664 | * @attr ref android.R.styleable#View_translationX |
| 665 | * @attr ref android.R.styleable#View_translationY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 666 | * @attr ref android.R.styleable#View_visibility |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | * |
| 668 | * @see android.view.ViewGroup |
| 669 | */ |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 670 | public class View implements Drawable.Callback, KeyEvent.Callback, |
Adam Powell | 8fc54f9 | 2011-09-07 16:40:45 -0700 | [diff] [blame] | 671 | AccessibilityEventSource { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 672 | private static final boolean DBG = false; |
| 673 | |
| 674 | /** |
| 675 | * The logging tag used by this class with android.util.Log. |
| 676 | */ |
| 677 | protected static final String VIEW_LOG_TAG = "View"; |
| 678 | |
| 679 | /** |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 680 | * When set to true, apps will draw debugging information about their layouts. |
Romain Guy | 4b8c4f8 | 2012-04-27 15:48:35 -0700 | [diff] [blame] | 681 | * |
| 682 | * @hide |
| 683 | */ |
| 684 | public static final String DEBUG_LAYOUT_PROPERTY = "debug.layout"; |
| 685 | |
| 686 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | * Used to mark a View that has no ID. |
| 688 | */ |
| 689 | public static final int NO_ID = -1; |
| 690 | |
| 691 | /** |
| 692 | * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when |
| 693 | * calling setFlags. |
| 694 | */ |
| 695 | private static final int NOT_FOCUSABLE = 0x00000000; |
| 696 | |
| 697 | /** |
| 698 | * This view wants keystrokes. Use with TAKES_FOCUS_MASK when calling |
| 699 | * setFlags. |
| 700 | */ |
| 701 | private static final int FOCUSABLE = 0x00000001; |
| 702 | |
| 703 | /** |
| 704 | * Mask for use with setFlags indicating bits used for focus. |
| 705 | */ |
| 706 | private static final int FOCUSABLE_MASK = 0x00000001; |
| 707 | |
| 708 | /** |
| 709 | * This view will adjust its padding to fit sytem windows (e.g. status bar) |
| 710 | */ |
| 711 | private static final int FITS_SYSTEM_WINDOWS = 0x00000002; |
| 712 | |
| 713 | /** |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 714 | * This view is visible. |
| 715 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 716 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 717 | */ |
| 718 | public static final int VISIBLE = 0x00000000; |
| 719 | |
| 720 | /** |
| 721 | * 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] | 722 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 723 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 724 | */ |
| 725 | public static final int INVISIBLE = 0x00000004; |
| 726 | |
| 727 | /** |
| 728 | * 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] | 729 | * purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 730 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 731 | */ |
| 732 | public static final int GONE = 0x00000008; |
| 733 | |
| 734 | /** |
| 735 | * Mask for use with setFlags indicating bits used for visibility. |
| 736 | * {@hide} |
| 737 | */ |
| 738 | static final int VISIBILITY_MASK = 0x0000000C; |
| 739 | |
| 740 | private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE}; |
| 741 | |
| 742 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 743 | * This view is enabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | * Use with ENABLED_MASK when calling setFlags. |
| 745 | * {@hide} |
| 746 | */ |
| 747 | static final int ENABLED = 0x00000000; |
| 748 | |
| 749 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 750 | * This view is disabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 751 | * Use with ENABLED_MASK when calling setFlags. |
| 752 | * {@hide} |
| 753 | */ |
| 754 | static final int DISABLED = 0x00000020; |
| 755 | |
| 756 | /** |
| 757 | * Mask for use with setFlags indicating bits used for indicating whether |
| 758 | * this view is enabled |
| 759 | * {@hide} |
| 760 | */ |
| 761 | static final int ENABLED_MASK = 0x00000020; |
| 762 | |
| 763 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 764 | * This view won't draw. {@link #onDraw(android.graphics.Canvas)} won't be |
| 765 | * called and further optimizations will be performed. It is okay to have |
| 766 | * 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] | 767 | * {@hide} |
| 768 | */ |
| 769 | static final int WILL_NOT_DRAW = 0x00000080; |
| 770 | |
| 771 | /** |
| 772 | * Mask for use with setFlags indicating bits used for indicating whether |
| 773 | * this view is will draw |
| 774 | * {@hide} |
| 775 | */ |
| 776 | static final int DRAW_MASK = 0x00000080; |
| 777 | |
| 778 | /** |
| 779 | * <p>This view doesn't show scrollbars.</p> |
| 780 | * {@hide} |
| 781 | */ |
| 782 | static final int SCROLLBARS_NONE = 0x00000000; |
| 783 | |
| 784 | /** |
| 785 | * <p>This view shows horizontal scrollbars.</p> |
| 786 | * {@hide} |
| 787 | */ |
| 788 | static final int SCROLLBARS_HORIZONTAL = 0x00000100; |
| 789 | |
| 790 | /** |
| 791 | * <p>This view shows vertical scrollbars.</p> |
| 792 | * {@hide} |
| 793 | */ |
| 794 | static final int SCROLLBARS_VERTICAL = 0x00000200; |
| 795 | |
| 796 | /** |
| 797 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 798 | * scrollbars are enabled.</p> |
| 799 | * {@hide} |
| 800 | */ |
| 801 | static final int SCROLLBARS_MASK = 0x00000300; |
| 802 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 803 | /** |
| 804 | * Indicates that the view should filter touches when its window is obscured. |
| 805 | * Refer to the class comments for more information about this security feature. |
| 806 | * {@hide} |
| 807 | */ |
| 808 | static final int FILTER_TOUCHES_WHEN_OBSCURED = 0x00000400; |
| 809 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 810 | /** |
| 811 | * Set for framework elements that use FITS_SYSTEM_WINDOWS, to indicate |
| 812 | * that they are optional and should be skipped if the window has |
| 813 | * requested system UI flags that ignore those insets for layout. |
| 814 | */ |
| 815 | static final int OPTIONAL_FITS_SYSTEM_WINDOWS = 0x00000800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 816 | |
| 817 | /** |
| 818 | * <p>This view doesn't show fading edges.</p> |
| 819 | * {@hide} |
| 820 | */ |
| 821 | static final int FADING_EDGE_NONE = 0x00000000; |
| 822 | |
| 823 | /** |
| 824 | * <p>This view shows horizontal fading edges.</p> |
| 825 | * {@hide} |
| 826 | */ |
| 827 | static final int FADING_EDGE_HORIZONTAL = 0x00001000; |
| 828 | |
| 829 | /** |
| 830 | * <p>This view shows vertical fading edges.</p> |
| 831 | * {@hide} |
| 832 | */ |
| 833 | static final int FADING_EDGE_VERTICAL = 0x00002000; |
| 834 | |
| 835 | /** |
| 836 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 837 | * fading edges are enabled.</p> |
| 838 | * {@hide} |
| 839 | */ |
| 840 | static final int FADING_EDGE_MASK = 0x00003000; |
| 841 | |
| 842 | /** |
| 843 | * <p>Indicates this view can be clicked. When clickable, a View reacts |
| 844 | * to clicks by notifying the OnClickListener.<p> |
| 845 | * {@hide} |
| 846 | */ |
| 847 | static final int CLICKABLE = 0x00004000; |
| 848 | |
| 849 | /** |
| 850 | * <p>Indicates this view is caching its drawing into a bitmap.</p> |
| 851 | * {@hide} |
| 852 | */ |
| 853 | static final int DRAWING_CACHE_ENABLED = 0x00008000; |
| 854 | |
| 855 | /** |
| 856 | * <p>Indicates that no icicle should be saved for this view.<p> |
| 857 | * {@hide} |
| 858 | */ |
| 859 | static final int SAVE_DISABLED = 0x000010000; |
| 860 | |
| 861 | /** |
| 862 | * <p>Mask for use with setFlags indicating bits used for the saveEnabled |
| 863 | * property.</p> |
| 864 | * {@hide} |
| 865 | */ |
| 866 | static final int SAVE_DISABLED_MASK = 0x000010000; |
| 867 | |
| 868 | /** |
| 869 | * <p>Indicates that no drawing cache should ever be created for this view.<p> |
| 870 | * {@hide} |
| 871 | */ |
| 872 | static final int WILL_NOT_CACHE_DRAWING = 0x000020000; |
| 873 | |
| 874 | /** |
| 875 | * <p>Indicates this view can take / keep focus when int touch mode.</p> |
| 876 | * {@hide} |
| 877 | */ |
| 878 | static final int FOCUSABLE_IN_TOUCH_MODE = 0x00040000; |
| 879 | |
| 880 | /** |
| 881 | * <p>Enables low quality mode for the drawing cache.</p> |
| 882 | */ |
| 883 | public static final int DRAWING_CACHE_QUALITY_LOW = 0x00080000; |
| 884 | |
| 885 | /** |
| 886 | * <p>Enables high quality mode for the drawing cache.</p> |
| 887 | */ |
| 888 | public static final int DRAWING_CACHE_QUALITY_HIGH = 0x00100000; |
| 889 | |
| 890 | /** |
| 891 | * <p>Enables automatic quality mode for the drawing cache.</p> |
| 892 | */ |
| 893 | public static final int DRAWING_CACHE_QUALITY_AUTO = 0x00000000; |
| 894 | |
| 895 | private static final int[] DRAWING_CACHE_QUALITY_FLAGS = { |
| 896 | DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH |
| 897 | }; |
| 898 | |
| 899 | /** |
| 900 | * <p>Mask for use with setFlags indicating bits used for the cache |
| 901 | * quality property.</p> |
| 902 | * {@hide} |
| 903 | */ |
| 904 | static final int DRAWING_CACHE_QUALITY_MASK = 0x00180000; |
| 905 | |
| 906 | /** |
| 907 | * <p> |
| 908 | * Indicates this view can be long clicked. When long clickable, a View |
| 909 | * reacts to long clicks by notifying the OnLongClickListener or showing a |
| 910 | * context menu. |
| 911 | * </p> |
| 912 | * {@hide} |
| 913 | */ |
| 914 | static final int LONG_CLICKABLE = 0x00200000; |
| 915 | |
| 916 | /** |
| 917 | * <p>Indicates that this view gets its drawable states from its direct parent |
| 918 | * and ignores its original internal states.</p> |
| 919 | * |
| 920 | * @hide |
| 921 | */ |
| 922 | static final int DUPLICATE_PARENT_STATE = 0x00400000; |
| 923 | |
| 924 | /** |
| 925 | * The scrollbar style to display the scrollbars inside the content area, |
| 926 | * without increasing the padding. The scrollbars will be overlaid with |
| 927 | * translucency on the view's content. |
| 928 | */ |
| 929 | public static final int SCROLLBARS_INSIDE_OVERLAY = 0; |
| 930 | |
| 931 | /** |
| 932 | * The scrollbar style to display the scrollbars inside the padded area, |
| 933 | * increasing the padding of the view. The scrollbars will not overlap the |
| 934 | * content area of the view. |
| 935 | */ |
| 936 | public static final int SCROLLBARS_INSIDE_INSET = 0x01000000; |
| 937 | |
| 938 | /** |
| 939 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 940 | * without increasing the padding. The scrollbars will be overlaid with |
| 941 | * translucency. |
| 942 | */ |
| 943 | public static final int SCROLLBARS_OUTSIDE_OVERLAY = 0x02000000; |
| 944 | |
| 945 | /** |
| 946 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 947 | * increasing the padding of the view. The scrollbars will only overlap the |
| 948 | * background, if any. |
| 949 | */ |
| 950 | public static final int SCROLLBARS_OUTSIDE_INSET = 0x03000000; |
| 951 | |
| 952 | /** |
| 953 | * Mask to check if the scrollbar style is overlay or inset. |
| 954 | * {@hide} |
| 955 | */ |
| 956 | static final int SCROLLBARS_INSET_MASK = 0x01000000; |
| 957 | |
| 958 | /** |
| 959 | * Mask to check if the scrollbar style is inside or outside. |
| 960 | * {@hide} |
| 961 | */ |
| 962 | static final int SCROLLBARS_OUTSIDE_MASK = 0x02000000; |
| 963 | |
| 964 | /** |
| 965 | * Mask for scrollbar style. |
| 966 | * {@hide} |
| 967 | */ |
| 968 | static final int SCROLLBARS_STYLE_MASK = 0x03000000; |
| 969 | |
| 970 | /** |
| 971 | * View flag indicating that the screen should remain on while the |
| 972 | * window containing this view is visible to the user. This effectively |
| 973 | * takes care of automatically setting the WindowManager's |
| 974 | * {@link WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON}. |
| 975 | */ |
| 976 | public static final int KEEP_SCREEN_ON = 0x04000000; |
| 977 | |
| 978 | /** |
| 979 | * View flag indicating whether this view should have sound effects enabled |
| 980 | * for events such as clicking and touching. |
| 981 | */ |
| 982 | public static final int SOUND_EFFECTS_ENABLED = 0x08000000; |
| 983 | |
| 984 | /** |
| 985 | * View flag indicating whether this view should have haptic feedback |
| 986 | * enabled for events such as long presses. |
| 987 | */ |
| 988 | public static final int HAPTIC_FEEDBACK_ENABLED = 0x10000000; |
| 989 | |
| 990 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 991 | * <p>Indicates that the view hierarchy should stop saving state when |
| 992 | * it reaches this view. If state saving is initiated immediately at |
| 993 | * the view, it will be allowed. |
| 994 | * {@hide} |
| 995 | */ |
| 996 | static final int PARENT_SAVE_DISABLED = 0x20000000; |
| 997 | |
| 998 | /** |
| 999 | * <p>Mask for use with setFlags indicating bits used for PARENT_SAVE_DISABLED.</p> |
| 1000 | * {@hide} |
| 1001 | */ |
| 1002 | static final int PARENT_SAVE_DISABLED_MASK = 0x20000000; |
| 1003 | |
| 1004 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1005 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 1006 | * should add all focusable Views regardless if they are focusable in touch mode. |
| 1007 | */ |
| 1008 | public static final int FOCUSABLES_ALL = 0x00000000; |
| 1009 | |
| 1010 | /** |
| 1011 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 1012 | * should add only Views focusable in touch mode. |
| 1013 | */ |
| 1014 | public static final int FOCUSABLES_TOUCH_MODE = 0x00000001; |
| 1015 | |
| 1016 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1017 | * 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] | 1018 | * item. |
| 1019 | */ |
| 1020 | public static final int FOCUS_BACKWARD = 0x00000001; |
| 1021 | |
| 1022 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1023 | * 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] | 1024 | * item. |
| 1025 | */ |
| 1026 | public static final int FOCUS_FORWARD = 0x00000002; |
| 1027 | |
| 1028 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1029 | * 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] | 1030 | */ |
| 1031 | public static final int FOCUS_LEFT = 0x00000011; |
| 1032 | |
| 1033 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1034 | * Use with {@link #focusSearch(int)}. Move focus up. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | */ |
| 1036 | public static final int FOCUS_UP = 0x00000021; |
| 1037 | |
| 1038 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1039 | * 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] | 1040 | */ |
| 1041 | public static final int FOCUS_RIGHT = 0x00000042; |
| 1042 | |
| 1043 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1044 | * Use with {@link #focusSearch(int)}. Move focus down. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1045 | */ |
| 1046 | public static final int FOCUS_DOWN = 0x00000082; |
| 1047 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1048 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1049 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1050 | * {@link #getMeasuredWidthAndState()} that provide the actual measured size. |
| 1051 | */ |
| 1052 | public static final int MEASURED_SIZE_MASK = 0x00ffffff; |
| 1053 | |
| 1054 | /** |
| 1055 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1056 | * {@link #getMeasuredWidthAndState()} that provide the additional state bits. |
| 1057 | */ |
| 1058 | public static final int MEASURED_STATE_MASK = 0xff000000; |
| 1059 | |
| 1060 | /** |
| 1061 | * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits |
| 1062 | * for functions that combine both width and height into a single int, |
| 1063 | * such as {@link #getMeasuredState()} and the childState argument of |
| 1064 | * {@link #resolveSizeAndState(int, int, int)}. |
| 1065 | */ |
| 1066 | public static final int MEASURED_HEIGHT_STATE_SHIFT = 16; |
| 1067 | |
| 1068 | /** |
| 1069 | * Bit of {@link #getMeasuredWidthAndState()} and |
| 1070 | * {@link #getMeasuredWidthAndState()} that indicates the measured size |
| 1071 | * is smaller that the space the view would like to have. |
| 1072 | */ |
| 1073 | public static final int MEASURED_STATE_TOO_SMALL = 0x01000000; |
| 1074 | |
| 1075 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | * Base View state sets |
| 1077 | */ |
| 1078 | // Singles |
| 1079 | /** |
| 1080 | * Indicates the view has no states set. States are used with |
| 1081 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1082 | * view depending on its state. |
| 1083 | * |
| 1084 | * @see android.graphics.drawable.Drawable |
| 1085 | * @see #getDrawableState() |
| 1086 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1087 | protected static final int[] EMPTY_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1088 | /** |
| 1089 | * Indicates the view is enabled. States are used with |
| 1090 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1091 | * view depending on its state. |
| 1092 | * |
| 1093 | * @see android.graphics.drawable.Drawable |
| 1094 | * @see #getDrawableState() |
| 1095 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1096 | protected static final int[] ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1097 | /** |
| 1098 | * Indicates the view is focused. States are used with |
| 1099 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1100 | * view depending on its state. |
| 1101 | * |
| 1102 | * @see android.graphics.drawable.Drawable |
| 1103 | * @see #getDrawableState() |
| 1104 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1105 | protected static final int[] FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | /** |
| 1107 | * Indicates the view is selected. States are used with |
| 1108 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1109 | * view depending on its state. |
| 1110 | * |
| 1111 | * @see android.graphics.drawable.Drawable |
| 1112 | * @see #getDrawableState() |
| 1113 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1114 | protected static final int[] SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | /** |
| 1116 | * Indicates the view is pressed. States are used with |
| 1117 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1118 | * view depending on its state. |
| 1119 | * |
| 1120 | * @see android.graphics.drawable.Drawable |
| 1121 | * @see #getDrawableState() |
| 1122 | * @hide |
| 1123 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1124 | protected static final int[] PRESSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1125 | /** |
| 1126 | * Indicates the view's window has focus. States are used with |
| 1127 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1128 | * view depending on its state. |
| 1129 | * |
| 1130 | * @see android.graphics.drawable.Drawable |
| 1131 | * @see #getDrawableState() |
| 1132 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1133 | protected static final int[] WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | // Doubles |
| 1135 | /** |
| 1136 | * Indicates the view is enabled and has the focus. |
| 1137 | * |
| 1138 | * @see #ENABLED_STATE_SET |
| 1139 | * @see #FOCUSED_STATE_SET |
| 1140 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1141 | protected static final int[] ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1142 | /** |
| 1143 | * Indicates the view is enabled and selected. |
| 1144 | * |
| 1145 | * @see #ENABLED_STATE_SET |
| 1146 | * @see #SELECTED_STATE_SET |
| 1147 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1148 | protected static final int[] ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1149 | /** |
| 1150 | * Indicates the view is enabled and that its window has focus. |
| 1151 | * |
| 1152 | * @see #ENABLED_STATE_SET |
| 1153 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1154 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1155 | protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1156 | /** |
| 1157 | * Indicates the view is focused and selected. |
| 1158 | * |
| 1159 | * @see #FOCUSED_STATE_SET |
| 1160 | * @see #SELECTED_STATE_SET |
| 1161 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1162 | protected static final int[] FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | /** |
| 1164 | * Indicates the view has the focus and that its window has the focus. |
| 1165 | * |
| 1166 | * @see #FOCUSED_STATE_SET |
| 1167 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1168 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1169 | protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1170 | /** |
| 1171 | * Indicates the view is selected and that its window has the focus. |
| 1172 | * |
| 1173 | * @see #SELECTED_STATE_SET |
| 1174 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1175 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1176 | protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | // Triples |
| 1178 | /** |
| 1179 | * Indicates the view is enabled, focused and selected. |
| 1180 | * |
| 1181 | * @see #ENABLED_STATE_SET |
| 1182 | * @see #FOCUSED_STATE_SET |
| 1183 | * @see #SELECTED_STATE_SET |
| 1184 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1185 | protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | /** |
| 1187 | * Indicates the view is enabled, focused and its window has the focus. |
| 1188 | * |
| 1189 | * @see #ENABLED_STATE_SET |
| 1190 | * @see #FOCUSED_STATE_SET |
| 1191 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1192 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1193 | 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] | 1194 | /** |
| 1195 | * Indicates the view is enabled, selected and its window has the focus. |
| 1196 | * |
| 1197 | * @see #ENABLED_STATE_SET |
| 1198 | * @see #SELECTED_STATE_SET |
| 1199 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1200 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1201 | 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] | 1202 | /** |
| 1203 | * Indicates the view is focused, selected and its window has the focus. |
| 1204 | * |
| 1205 | * @see #FOCUSED_STATE_SET |
| 1206 | * @see #SELECTED_STATE_SET |
| 1207 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1208 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1209 | 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] | 1210 | /** |
| 1211 | * Indicates the view is enabled, focused, selected and its window |
| 1212 | * has the focus. |
| 1213 | * |
| 1214 | * @see #ENABLED_STATE_SET |
| 1215 | * @see #FOCUSED_STATE_SET |
| 1216 | * @see #SELECTED_STATE_SET |
| 1217 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1218 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1219 | protected static final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1220 | /** |
| 1221 | * Indicates the view is pressed and its window has the focus. |
| 1222 | * |
| 1223 | * @see #PRESSED_STATE_SET |
| 1224 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1225 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1226 | protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | /** |
| 1228 | * Indicates the view is pressed and selected. |
| 1229 | * |
| 1230 | * @see #PRESSED_STATE_SET |
| 1231 | * @see #SELECTED_STATE_SET |
| 1232 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1233 | protected static final int[] PRESSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1234 | /** |
| 1235 | * Indicates the view is pressed, selected and its window has the focus. |
| 1236 | * |
| 1237 | * @see #PRESSED_STATE_SET |
| 1238 | * @see #SELECTED_STATE_SET |
| 1239 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1240 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1241 | 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] | 1242 | /** |
| 1243 | * Indicates the view is pressed and focused. |
| 1244 | * |
| 1245 | * @see #PRESSED_STATE_SET |
| 1246 | * @see #FOCUSED_STATE_SET |
| 1247 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1248 | protected static final int[] PRESSED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | /** |
| 1250 | * Indicates the view is pressed, focused and its window has the focus. |
| 1251 | * |
| 1252 | * @see #PRESSED_STATE_SET |
| 1253 | * @see #FOCUSED_STATE_SET |
| 1254 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1255 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1256 | 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] | 1257 | /** |
| 1258 | * Indicates the view is pressed, focused and selected. |
| 1259 | * |
| 1260 | * @see #PRESSED_STATE_SET |
| 1261 | * @see #SELECTED_STATE_SET |
| 1262 | * @see #FOCUSED_STATE_SET |
| 1263 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1264 | protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1265 | /** |
| 1266 | * Indicates the view is pressed, focused, selected and its window has the focus. |
| 1267 | * |
| 1268 | * @see #PRESSED_STATE_SET |
| 1269 | * @see #FOCUSED_STATE_SET |
| 1270 | * @see #SELECTED_STATE_SET |
| 1271 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1272 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1273 | 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] | 1274 | /** |
| 1275 | * Indicates the view is pressed and enabled. |
| 1276 | * |
| 1277 | * @see #PRESSED_STATE_SET |
| 1278 | * @see #ENABLED_STATE_SET |
| 1279 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1280 | protected static final int[] PRESSED_ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1281 | /** |
| 1282 | * Indicates the view is pressed, enabled and its window has the focus. |
| 1283 | * |
| 1284 | * @see #PRESSED_STATE_SET |
| 1285 | * @see #ENABLED_STATE_SET |
| 1286 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1287 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1288 | 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] | 1289 | /** |
| 1290 | * Indicates the view is pressed, enabled and selected. |
| 1291 | * |
| 1292 | * @see #PRESSED_STATE_SET |
| 1293 | * @see #ENABLED_STATE_SET |
| 1294 | * @see #SELECTED_STATE_SET |
| 1295 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1296 | protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | /** |
| 1298 | * Indicates the view is pressed, enabled, selected and its window has the |
| 1299 | * focus. |
| 1300 | * |
| 1301 | * @see #PRESSED_STATE_SET |
| 1302 | * @see #ENABLED_STATE_SET |
| 1303 | * @see #SELECTED_STATE_SET |
| 1304 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1305 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1306 | protected static final int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1307 | /** |
| 1308 | * Indicates the view is pressed, enabled and focused. |
| 1309 | * |
| 1310 | * @see #PRESSED_STATE_SET |
| 1311 | * @see #ENABLED_STATE_SET |
| 1312 | * @see #FOCUSED_STATE_SET |
| 1313 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1314 | protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1315 | /** |
| 1316 | * Indicates the view is pressed, enabled, focused and its window has the |
| 1317 | * focus. |
| 1318 | * |
| 1319 | * @see #PRESSED_STATE_SET |
| 1320 | * @see #ENABLED_STATE_SET |
| 1321 | * @see #FOCUSED_STATE_SET |
| 1322 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1323 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1324 | protected static final int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | /** |
| 1326 | * Indicates the view is pressed, enabled, focused and selected. |
| 1327 | * |
| 1328 | * @see #PRESSED_STATE_SET |
| 1329 | * @see #ENABLED_STATE_SET |
| 1330 | * @see #SELECTED_STATE_SET |
| 1331 | * @see #FOCUSED_STATE_SET |
| 1332 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1333 | 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] | 1334 | /** |
| 1335 | * Indicates the view is pressed, enabled, focused, selected and its window |
| 1336 | * has the focus. |
| 1337 | * |
| 1338 | * @see #PRESSED_STATE_SET |
| 1339 | * @see #ENABLED_STATE_SET |
| 1340 | * @see #SELECTED_STATE_SET |
| 1341 | * @see #FOCUSED_STATE_SET |
| 1342 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1343 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1344 | 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] | 1345 | |
| 1346 | /** |
| 1347 | * The order here is very important to {@link #getDrawableState()} |
| 1348 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1349 | private static final int[][] VIEW_STATE_SETS; |
| 1350 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1351 | static final int VIEW_STATE_WINDOW_FOCUSED = 1; |
| 1352 | static final int VIEW_STATE_SELECTED = 1 << 1; |
| 1353 | static final int VIEW_STATE_FOCUSED = 1 << 2; |
| 1354 | static final int VIEW_STATE_ENABLED = 1 << 3; |
| 1355 | static final int VIEW_STATE_PRESSED = 1 << 4; |
| 1356 | static final int VIEW_STATE_ACTIVATED = 1 << 5; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1357 | static final int VIEW_STATE_ACCELERATED = 1 << 6; |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1358 | static final int VIEW_STATE_HOVERED = 1 << 7; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1359 | static final int VIEW_STATE_DRAG_CAN_ACCEPT = 1 << 8; |
| 1360 | static final int VIEW_STATE_DRAG_HOVERED = 1 << 9; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1361 | |
| 1362 | static final int[] VIEW_STATE_IDS = new int[] { |
| 1363 | R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED, |
| 1364 | R.attr.state_selected, VIEW_STATE_SELECTED, |
| 1365 | R.attr.state_focused, VIEW_STATE_FOCUSED, |
| 1366 | R.attr.state_enabled, VIEW_STATE_ENABLED, |
| 1367 | R.attr.state_pressed, VIEW_STATE_PRESSED, |
| 1368 | R.attr.state_activated, VIEW_STATE_ACTIVATED, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1369 | R.attr.state_accelerated, VIEW_STATE_ACCELERATED, |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1370 | R.attr.state_hovered, VIEW_STATE_HOVERED, |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1371 | R.attr.state_drag_can_accept, VIEW_STATE_DRAG_CAN_ACCEPT, |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1372 | R.attr.state_drag_hovered, VIEW_STATE_DRAG_HOVERED |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1373 | }; |
| 1374 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1375 | static { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1376 | if ((VIEW_STATE_IDS.length/2) != R.styleable.ViewDrawableStates.length) { |
| 1377 | throw new IllegalStateException( |
| 1378 | "VIEW_STATE_IDs array length does not match ViewDrawableStates style array"); |
| 1379 | } |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1380 | int[] orderedIds = new int[VIEW_STATE_IDS.length]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1381 | for (int i = 0; i < R.styleable.ViewDrawableStates.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1382 | int viewState = R.styleable.ViewDrawableStates[i]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1383 | for (int j = 0; j<VIEW_STATE_IDS.length; j += 2) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1384 | if (VIEW_STATE_IDS[j] == viewState) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1385 | orderedIds[i * 2] = viewState; |
| 1386 | orderedIds[i * 2 + 1] = VIEW_STATE_IDS[j + 1]; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1387 | } |
| 1388 | } |
| 1389 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1390 | final int NUM_BITS = VIEW_STATE_IDS.length / 2; |
| 1391 | VIEW_STATE_SETS = new int[1 << NUM_BITS][]; |
| 1392 | for (int i = 0; i < VIEW_STATE_SETS.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1393 | int numBits = Integer.bitCount(i); |
| 1394 | int[] set = new int[numBits]; |
| 1395 | int pos = 0; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1396 | for (int j = 0; j < orderedIds.length; j += 2) { |
| 1397 | if ((i & orderedIds[j+1]) != 0) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1398 | set[pos++] = orderedIds[j]; |
| 1399 | } |
| 1400 | } |
| 1401 | VIEW_STATE_SETS[i] = set; |
| 1402 | } |
| 1403 | |
| 1404 | EMPTY_STATE_SET = VIEW_STATE_SETS[0]; |
| 1405 | WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_WINDOW_FOCUSED]; |
| 1406 | SELECTED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_SELECTED]; |
| 1407 | SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1408 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED]; |
| 1409 | FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_FOCUSED]; |
| 1410 | FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1411 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED]; |
| 1412 | FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1413 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED]; |
| 1414 | FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1415 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1416 | | VIEW_STATE_FOCUSED]; |
| 1417 | ENABLED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_ENABLED]; |
| 1418 | ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1419 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED]; |
| 1420 | ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1421 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED]; |
| 1422 | ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1423 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1424 | | VIEW_STATE_ENABLED]; |
| 1425 | ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1426 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED]; |
| 1427 | ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1428 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1429 | | VIEW_STATE_ENABLED]; |
| 1430 | ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1431 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1432 | | VIEW_STATE_ENABLED]; |
| 1433 | ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1434 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1435 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED]; |
| 1436 | |
| 1437 | PRESSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_PRESSED]; |
| 1438 | PRESSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1439 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_PRESSED]; |
| 1440 | PRESSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1441 | VIEW_STATE_SELECTED | VIEW_STATE_PRESSED]; |
| 1442 | PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1443 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1444 | | VIEW_STATE_PRESSED]; |
| 1445 | PRESSED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1446 | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1447 | PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1448 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1449 | | VIEW_STATE_PRESSED]; |
| 1450 | PRESSED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1451 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1452 | | VIEW_STATE_PRESSED]; |
| 1453 | PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1454 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1455 | | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1456 | PRESSED_ENABLED_STATE_SET = VIEW_STATE_SETS[ |
| 1457 | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1458 | PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1459 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED |
| 1460 | | VIEW_STATE_PRESSED]; |
| 1461 | PRESSED_ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1462 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED |
| 1463 | | VIEW_STATE_PRESSED]; |
| 1464 | PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1465 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1466 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1467 | PRESSED_ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1468 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED |
| 1469 | | VIEW_STATE_PRESSED]; |
| 1470 | PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1471 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1472 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1473 | PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1474 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1475 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1476 | PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1477 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1478 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED |
| 1479 | | VIEW_STATE_PRESSED]; |
| 1480 | } |
| 1481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1482 | /** |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1483 | * Accessibility event types that are dispatched for text population. |
| 1484 | */ |
| 1485 | private static final int POPULATING_ACCESSIBILITY_EVENT_TYPES = |
| 1486 | AccessibilityEvent.TYPE_VIEW_CLICKED |
| 1487 | | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED |
| 1488 | | AccessibilityEvent.TYPE_VIEW_SELECTED |
| 1489 | | AccessibilityEvent.TYPE_VIEW_FOCUSED |
| 1490 | | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED |
| 1491 | | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER |
Svetoslav Ganov | 9920f4f | 2011-10-07 18:39:11 -0700 | [diff] [blame] | 1492 | | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT |
Svetoslav Ganov | 84dd52e | 2011-11-18 10:24:00 -0800 | [diff] [blame] | 1493 | | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1494 | | AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 1495 | | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED |
| 1496 | | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY; |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1497 | |
| 1498 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1499 | * Temporary Rect currently for use in setBackground(). This will probably |
| 1500 | * be extended in the future to hold our own class with more than just |
| 1501 | * a Rect. :) |
| 1502 | */ |
| 1503 | static final ThreadLocal<Rect> sThreadLocal = new ThreadLocal<Rect>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1504 | |
| 1505 | /** |
| 1506 | * Map used to store views' tags. |
| 1507 | */ |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 1508 | private SparseArray<Object> mKeyedTags; |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1510 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 1511 | * The next available accessibility id. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1512 | */ |
| 1513 | private static int sNextAccessibilityViewId; |
| 1514 | |
| 1515 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1516 | * The animation currently associated with this view. |
| 1517 | * @hide |
| 1518 | */ |
| 1519 | protected Animation mCurrentAnimation = null; |
| 1520 | |
| 1521 | /** |
| 1522 | * Width as measured during measure pass. |
| 1523 | * {@hide} |
| 1524 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1525 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1526 | int mMeasuredWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1527 | |
| 1528 | /** |
| 1529 | * Height as measured during measure pass. |
| 1530 | * {@hide} |
| 1531 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1532 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1533 | int mMeasuredHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1534 | |
| 1535 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1536 | * Flag to indicate that this view was marked INVALIDATED, or had its display list |
| 1537 | * invalidated, prior to the current drawing iteration. If true, the view must re-draw |
| 1538 | * its display list. This flag, used only when hw accelerated, allows us to clear the |
| 1539 | * flag while retaining this information until it's needed (at getDisplayList() time and |
| 1540 | * in drawChild(), when we decide to draw a view's children's display lists into our own). |
| 1541 | * |
| 1542 | * {@hide} |
| 1543 | */ |
| 1544 | boolean mRecreateDisplayList = false; |
| 1545 | |
| 1546 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1547 | * The view's identifier. |
| 1548 | * {@hide} |
| 1549 | * |
| 1550 | * @see #setId(int) |
| 1551 | * @see #getId() |
| 1552 | */ |
| 1553 | @ViewDebug.ExportedProperty(resolveId = true) |
| 1554 | int mID = NO_ID; |
| 1555 | |
| 1556 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 1557 | * The stable ID of this view for accessibility purposes. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1558 | */ |
| 1559 | int mAccessibilityViewId = NO_ID; |
| 1560 | |
| 1561 | /** |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 1562 | * @hide |
| 1563 | */ |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 1564 | private int mAccessibilityCursorPosition = ACCESSIBILITY_CURSOR_POSITION_UNDEFINED; |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 1565 | |
| 1566 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1567 | * The view's tag. |
| 1568 | * {@hide} |
| 1569 | * |
| 1570 | * @see #setTag(Object) |
| 1571 | * @see #getTag() |
| 1572 | */ |
| 1573 | protected Object mTag; |
| 1574 | |
| 1575 | // for mPrivateFlags: |
| 1576 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1577 | static final int PFLAG_WANTS_FOCUS = 0x00000001; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1579 | static final int PFLAG_FOCUSED = 0x00000002; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1580 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1581 | static final int PFLAG_SELECTED = 0x00000004; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1582 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1583 | static final int PFLAG_IS_ROOT_NAMESPACE = 0x00000008; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1584 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1585 | static final int PFLAG_HAS_BOUNDS = 0x00000010; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1586 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1587 | static final int PFLAG_DRAWN = 0x00000020; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1588 | /** |
| 1589 | * When this flag is set, this view is running an animation on behalf of its |
| 1590 | * children and should therefore not cancel invalidate requests, even if they |
| 1591 | * lie outside of this view's bounds. |
| 1592 | * |
| 1593 | * {@hide} |
| 1594 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1595 | static final int PFLAG_DRAW_ANIMATION = 0x00000040; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1596 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1597 | static final int PFLAG_SKIP_DRAW = 0x00000080; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1599 | static final int PFLAG_ONLY_DRAWS_BACKGROUND = 0x00000100; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1600 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1601 | static final int PFLAG_REQUEST_TRANSPARENT_REGIONS = 0x00000200; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1602 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1603 | static final int PFLAG_DRAWABLE_STATE_DIRTY = 0x00000400; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1604 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1605 | static final int PFLAG_MEASURED_DIMENSION_SET = 0x00000800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1606 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1607 | static final int PFLAG_FORCE_LAYOUT = 0x00001000; |
Konstantin Lopyrev | c6dc457 | 2010-08-06 15:01:52 -0700 | [diff] [blame] | 1608 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1609 | static final int PFLAG_LAYOUT_REQUIRED = 0x00002000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1610 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1611 | private static final int PFLAG_PRESSED = 0x00004000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1612 | |
| 1613 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1614 | static final int PFLAG_DRAWING_CACHE_VALID = 0x00008000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1615 | /** |
| 1616 | * Flag used to indicate that this view should be drawn once more (and only once |
| 1617 | * more) after its animation has completed. |
| 1618 | * {@hide} |
| 1619 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1620 | static final int PFLAG_ANIMATION_STARTED = 0x00010000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1621 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1622 | private static final int PFLAG_SAVE_STATE_CALLED = 0x00020000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1623 | |
| 1624 | /** |
| 1625 | * Indicates that the View returned true when onSetAlpha() was called and that |
| 1626 | * the alpha must be restored. |
| 1627 | * {@hide} |
| 1628 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1629 | static final int PFLAG_ALPHA_SET = 0x00040000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1630 | |
| 1631 | /** |
| 1632 | * Set by {@link #setScrollContainer(boolean)}. |
| 1633 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1634 | static final int PFLAG_SCROLL_CONTAINER = 0x00080000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1635 | |
| 1636 | /** |
| 1637 | * Set by {@link #setScrollContainer(boolean)}. |
| 1638 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1639 | static final int PFLAG_SCROLL_CONTAINER_ADDED = 0x00100000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1640 | |
| 1641 | /** |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1642 | * View flag indicating whether this view was invalidated (fully or partially.) |
| 1643 | * |
| 1644 | * @hide |
| 1645 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1646 | static final int PFLAG_DIRTY = 0x00200000; |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1647 | |
| 1648 | /** |
| 1649 | * View flag indicating whether this view was invalidated by an opaque |
| 1650 | * invalidate request. |
| 1651 | * |
| 1652 | * @hide |
| 1653 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1654 | static final int PFLAG_DIRTY_OPAQUE = 0x00400000; |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1655 | |
| 1656 | /** |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1657 | * Mask for {@link #PFLAG_DIRTY} and {@link #PFLAG_DIRTY_OPAQUE}. |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1658 | * |
| 1659 | * @hide |
| 1660 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1661 | static final int PFLAG_DIRTY_MASK = 0x00600000; |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1662 | |
| 1663 | /** |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1664 | * Indicates whether the background is opaque. |
| 1665 | * |
| 1666 | * @hide |
| 1667 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1668 | static final int PFLAG_OPAQUE_BACKGROUND = 0x00800000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1669 | |
| 1670 | /** |
| 1671 | * Indicates whether the scrollbars are opaque. |
| 1672 | * |
| 1673 | * @hide |
| 1674 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1675 | static final int PFLAG_OPAQUE_SCROLLBARS = 0x01000000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1676 | |
| 1677 | /** |
| 1678 | * Indicates whether the view is opaque. |
| 1679 | * |
| 1680 | * @hide |
| 1681 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1682 | static final int PFLAG_OPAQUE_MASK = 0x01800000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1683 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1684 | /** |
| 1685 | * Indicates a prepressed state; |
| 1686 | * the short time between ACTION_DOWN and recognizing |
| 1687 | * a 'real' press. Prepressed is used to recognize quick taps |
| 1688 | * even when they are shorter than ViewConfiguration.getTapTimeout(). |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1689 | * |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1690 | * @hide |
| 1691 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1692 | private static final int PFLAG_PREPRESSED = 0x02000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1693 | |
Adam Powell | c9fbaab | 2010-02-16 17:16:19 -0800 | [diff] [blame] | 1694 | /** |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 1695 | * Indicates whether the view is temporarily detached. |
| 1696 | * |
| 1697 | * @hide |
| 1698 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1699 | static final int PFLAG_CANCEL_NEXT_UP_EVENT = 0x04000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1700 | |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1701 | /** |
| 1702 | * Indicates that we should awaken scroll bars once attached |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1703 | * |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1704 | * @hide |
| 1705 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1706 | private static final int PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH = 0x08000000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1707 | |
| 1708 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1709 | * Indicates that the view has received HOVER_ENTER. Cleared on HOVER_EXIT. |
| 1710 | * @hide |
| 1711 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1712 | private static final int PFLAG_HOVERED = 0x10000000; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1713 | |
| 1714 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1715 | * Indicates that pivotX or pivotY were explicitly set and we should not assume the center |
| 1716 | * for transform operations |
| 1717 | * |
| 1718 | * @hide |
| 1719 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1720 | private static final int PFLAG_PIVOT_EXPLICITLY_SET = 0x20000000; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1721 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1722 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1723 | static final int PFLAG_ACTIVATED = 0x40000000; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1724 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1725 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1726 | * Indicates that this view was specifically invalidated, not just dirtied because some |
| 1727 | * child view was invalidated. The flag is used to determine when we need to recreate |
| 1728 | * a view's display list (as opposed to just returning a reference to its existing |
| 1729 | * display list). |
| 1730 | * |
| 1731 | * @hide |
| 1732 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1733 | static final int PFLAG_INVALIDATED = 0x80000000; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1734 | |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 1735 | /** |
| 1736 | * Masks for mPrivateFlags2, as generated by dumpFlags(): |
| 1737 | * |
| 1738 | * -------|-------|-------|-------| |
| 1739 | * PFLAG2_TEXT_ALIGNMENT_FLAGS[0] |
| 1740 | * PFLAG2_TEXT_DIRECTION_FLAGS[0] |
| 1741 | * 1 PFLAG2_DRAG_CAN_ACCEPT |
| 1742 | * 1 PFLAG2_DRAG_HOVERED |
| 1743 | * 1 PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT |
| 1744 | * 11 PFLAG2_TEXT_DIRECTION_MASK_SHIFT |
| 1745 | * 1 1 PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT |
| 1746 | * 11 PFLAG2_LAYOUT_DIRECTION_MASK |
| 1747 | * 11 1 PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT |
| 1748 | * 1 PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL |
| 1749 | * 1 1 PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT |
| 1750 | * 1 1 PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT |
| 1751 | * 1 PFLAG2_LAYOUT_DIRECTION_RESOLVED |
| 1752 | * 11 PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK |
| 1753 | * 1 PFLAG2_TEXT_DIRECTION_FLAGS[1] |
| 1754 | * 1 PFLAG2_TEXT_DIRECTION_FLAGS[2] |
| 1755 | * 11 PFLAG2_TEXT_DIRECTION_FLAGS[3] |
| 1756 | * 1 PFLAG2_TEXT_DIRECTION_FLAGS[4] |
| 1757 | * 1 1 PFLAG2_TEXT_DIRECTION_FLAGS[5] |
| 1758 | * 111 PFLAG2_TEXT_DIRECTION_MASK |
| 1759 | * 1 PFLAG2_TEXT_DIRECTION_RESOLVED |
| 1760 | * 1 PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT |
| 1761 | * 111 PFLAG2_TEXT_DIRECTION_RESOLVED_MASK |
| 1762 | * 1 PFLAG2_TEXT_ALIGNMENT_FLAGS[1] |
| 1763 | * 1 PFLAG2_TEXT_ALIGNMENT_FLAGS[2] |
| 1764 | * 11 PFLAG2_TEXT_ALIGNMENT_FLAGS[3] |
| 1765 | * 1 PFLAG2_TEXT_ALIGNMENT_FLAGS[4] |
| 1766 | * 1 1 PFLAG2_TEXT_ALIGNMENT_FLAGS[5] |
| 1767 | * 11 PFLAG2_TEXT_ALIGNMENT_FLAGS[6] |
| 1768 | * 111 PFLAG2_TEXT_ALIGNMENT_MASK |
| 1769 | * 1 PFLAG2_TEXT_ALIGNMENT_RESOLVED |
| 1770 | * 1 PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT |
| 1771 | * 111 PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK |
| 1772 | * 11 PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK |
| 1773 | * 1 PFLAG2_HAS_TRANSIENT_STATE |
| 1774 | * 1 PFLAG2_ACCESSIBILITY_FOCUSED |
| 1775 | * 1 PFLAG2_ACCESSIBILITY_STATE_CHANGED |
| 1776 | * 1 PFLAG2_VIEW_QUICK_REJECTED |
| 1777 | * 1 PFLAG2_PADDING_RESOLVED |
| 1778 | * -------|-------|-------|-------| |
| 1779 | */ |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1780 | |
| 1781 | /** |
| 1782 | * Indicates that this view has reported that it can accept the current drag's content. |
| 1783 | * Cleared when the drag operation concludes. |
| 1784 | * @hide |
| 1785 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1786 | static final int PFLAG2_DRAG_CAN_ACCEPT = 0x00000001; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1787 | |
| 1788 | /** |
| 1789 | * Indicates that this view is currently directly under the drag location in a |
| 1790 | * drag-and-drop operation involving content that it can accept. Cleared when |
| 1791 | * the drag exits the view, or when the drag operation concludes. |
| 1792 | * @hide |
| 1793 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1794 | static final int PFLAG2_DRAG_HOVERED = 0x00000002; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1795 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1796 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1797 | * Horizontal layout direction of this view is from Left to Right. |
| 1798 | * Use with {@link #setLayoutDirection}. |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1799 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1800 | public static final int LAYOUT_DIRECTION_LTR = 0; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1801 | |
| 1802 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1803 | * Horizontal layout direction of this view is from Right to Left. |
| 1804 | * Use with {@link #setLayoutDirection}. |
| 1805 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1806 | public static final int LAYOUT_DIRECTION_RTL = 1; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1807 | |
| 1808 | /** |
| 1809 | * Horizontal layout direction of this view is inherited from its parent. |
| 1810 | * Use with {@link #setLayoutDirection}. |
| 1811 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1812 | public static final int LAYOUT_DIRECTION_INHERIT = 2; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1813 | |
| 1814 | /** |
| 1815 | * Horizontal layout direction of this view is from deduced from the default language |
| 1816 | * script for the locale. Use with {@link #setLayoutDirection}. |
| 1817 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1818 | public static final int LAYOUT_DIRECTION_LOCALE = 3; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1819 | |
| 1820 | /** |
| 1821 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1822 | * @hide |
| 1823 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1824 | static final int PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT = 2; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1825 | |
| 1826 | /** |
| 1827 | * Mask for use with private flags indicating bits used for horizontal layout direction. |
| 1828 | * @hide |
| 1829 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1830 | static final int PFLAG2_LAYOUT_DIRECTION_MASK = 0x00000003 << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1831 | |
| 1832 | /** |
| 1833 | * Indicates whether the view horizontal layout direction has been resolved and drawn to the |
| 1834 | * right-to-left direction. |
| 1835 | * @hide |
| 1836 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1837 | static final int PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL = 4 << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1838 | |
| 1839 | /** |
| 1840 | * Indicates whether the view horizontal layout direction has been resolved. |
| 1841 | * @hide |
| 1842 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1843 | static final int PFLAG2_LAYOUT_DIRECTION_RESOLVED = 8 << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1844 | |
| 1845 | /** |
| 1846 | * Mask for use with private flags indicating bits used for resolved horizontal layout direction. |
| 1847 | * @hide |
| 1848 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1849 | static final int PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK = 0x0000000C |
| 1850 | << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1851 | |
| 1852 | /* |
| 1853 | * Array of horizontal layout direction flags for mapping attribute "layoutDirection" to correct |
| 1854 | * flag value. |
| 1855 | * @hide |
| 1856 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1857 | private static final int[] LAYOUT_DIRECTION_FLAGS = { |
| 1858 | LAYOUT_DIRECTION_LTR, |
| 1859 | LAYOUT_DIRECTION_RTL, |
| 1860 | LAYOUT_DIRECTION_INHERIT, |
| 1861 | LAYOUT_DIRECTION_LOCALE |
| 1862 | }; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1863 | |
| 1864 | /** |
| 1865 | * Default horizontal layout direction. |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1866 | */ |
| 1867 | private static final int LAYOUT_DIRECTION_DEFAULT = LAYOUT_DIRECTION_INHERIT; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1868 | |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1869 | /** |
| 1870 | * Indicates that the view is tracking some sort of transient state |
| 1871 | * that the app should not need to be aware of, but that the framework |
| 1872 | * should take special care to preserve. |
| 1873 | * |
| 1874 | * @hide |
| 1875 | */ |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 1876 | static final int PFLAG2_HAS_TRANSIENT_STATE = 0x1 << 22; |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1877 | |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1878 | /** |
| 1879 | * Text direction is inherited thru {@link ViewGroup} |
| 1880 | */ |
| 1881 | public static final int TEXT_DIRECTION_INHERIT = 0; |
| 1882 | |
| 1883 | /** |
| 1884 | * Text direction is using "first strong algorithm". The first strong directional character |
| 1885 | * determines the paragraph direction. If there is no strong directional character, the |
| 1886 | * paragraph direction is the view's resolved layout direction. |
| 1887 | */ |
| 1888 | public static final int TEXT_DIRECTION_FIRST_STRONG = 1; |
| 1889 | |
| 1890 | /** |
| 1891 | * Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains |
| 1892 | * any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. |
| 1893 | * If there are neither, the paragraph direction is the view's resolved layout direction. |
| 1894 | */ |
| 1895 | public static final int TEXT_DIRECTION_ANY_RTL = 2; |
| 1896 | |
| 1897 | /** |
| 1898 | * Text direction is forced to LTR. |
| 1899 | */ |
| 1900 | public static final int TEXT_DIRECTION_LTR = 3; |
| 1901 | |
| 1902 | /** |
| 1903 | * Text direction is forced to RTL. |
| 1904 | */ |
| 1905 | public static final int TEXT_DIRECTION_RTL = 4; |
| 1906 | |
| 1907 | /** |
| 1908 | * Text direction is coming from the system Locale. |
| 1909 | */ |
| 1910 | public static final int TEXT_DIRECTION_LOCALE = 5; |
| 1911 | |
| 1912 | /** |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1913 | * Default text direction is inherited |
| 1914 | */ |
Fabrice Di Meglio | 72898e9 | 2012-10-25 11:22:39 -0700 | [diff] [blame] | 1915 | private static final int TEXT_DIRECTION_DEFAULT = TEXT_DIRECTION_INHERIT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1916 | |
| 1917 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1918 | * Bit shift to get the horizontal layout direction. (bits after LAYOUT_DIRECTION_RESOLVED) |
| 1919 | * @hide |
| 1920 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1921 | static final int PFLAG2_TEXT_DIRECTION_MASK_SHIFT = 6; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1922 | |
| 1923 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1924 | * Mask for use with private flags indicating bits used for text direction. |
| 1925 | * @hide |
| 1926 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1927 | static final int PFLAG2_TEXT_DIRECTION_MASK = 0x00000007 |
| 1928 | << PFLAG2_TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1929 | |
| 1930 | /** |
| 1931 | * Array of text direction flags for mapping attribute "textDirection" to correct |
| 1932 | * flag value. |
| 1933 | * @hide |
| 1934 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1935 | private static final int[] PFLAG2_TEXT_DIRECTION_FLAGS = { |
| 1936 | TEXT_DIRECTION_INHERIT << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1937 | TEXT_DIRECTION_FIRST_STRONG << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1938 | TEXT_DIRECTION_ANY_RTL << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1939 | TEXT_DIRECTION_LTR << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1940 | TEXT_DIRECTION_RTL << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1941 | TEXT_DIRECTION_LOCALE << PFLAG2_TEXT_DIRECTION_MASK_SHIFT |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1942 | }; |
| 1943 | |
| 1944 | /** |
| 1945 | * Indicates whether the view text direction has been resolved. |
| 1946 | * @hide |
| 1947 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1948 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED = 0x00000008 |
| 1949 | << PFLAG2_TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1950 | |
| 1951 | /** |
| 1952 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 1953 | * @hide |
| 1954 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1955 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT = 10; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1956 | |
| 1957 | /** |
| 1958 | * Mask for use with private flags indicating bits used for resolved text direction. |
| 1959 | * @hide |
| 1960 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1961 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED_MASK = 0x00000007 |
| 1962 | << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1963 | |
| 1964 | /** |
| 1965 | * Indicates whether the view text direction has been resolved to the "first strong" heuristic. |
| 1966 | * @hide |
| 1967 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1968 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT = |
| 1969 | TEXT_DIRECTION_FIRST_STRONG << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1970 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1971 | /* |
| 1972 | * Default text alignment. The text alignment of this View is inherited from its parent. |
| 1973 | * Use with {@link #setTextAlignment(int)} |
| 1974 | */ |
| 1975 | public static final int TEXT_ALIGNMENT_INHERIT = 0; |
| 1976 | |
| 1977 | /** |
| 1978 | * Default for the root view. The gravity determines the text alignment, ALIGN_NORMAL, |
| 1979 | * ALIGN_CENTER, or ALIGN_OPPOSITE, which are relative to each paragraph’s text direction. |
| 1980 | * |
| 1981 | * Use with {@link #setTextAlignment(int)} |
| 1982 | */ |
| 1983 | public static final int TEXT_ALIGNMENT_GRAVITY = 1; |
| 1984 | |
| 1985 | /** |
| 1986 | * Align to the start of the paragraph, e.g. ALIGN_NORMAL. |
| 1987 | * |
| 1988 | * Use with {@link #setTextAlignment(int)} |
| 1989 | */ |
| 1990 | public static final int TEXT_ALIGNMENT_TEXT_START = 2; |
| 1991 | |
| 1992 | /** |
| 1993 | * Align to the end of the paragraph, e.g. ALIGN_OPPOSITE. |
| 1994 | * |
| 1995 | * Use with {@link #setTextAlignment(int)} |
| 1996 | */ |
| 1997 | public static final int TEXT_ALIGNMENT_TEXT_END = 3; |
| 1998 | |
| 1999 | /** |
| 2000 | * Center the paragraph, e.g. ALIGN_CENTER. |
| 2001 | * |
| 2002 | * Use with {@link #setTextAlignment(int)} |
| 2003 | */ |
| 2004 | public static final int TEXT_ALIGNMENT_CENTER = 4; |
| 2005 | |
| 2006 | /** |
| 2007 | * Align to the start of the view, which is ALIGN_LEFT if the view’s resolved |
| 2008 | * layoutDirection is LTR, and ALIGN_RIGHT otherwise. |
| 2009 | * |
| 2010 | * Use with {@link #setTextAlignment(int)} |
| 2011 | */ |
| 2012 | public static final int TEXT_ALIGNMENT_VIEW_START = 5; |
| 2013 | |
| 2014 | /** |
| 2015 | * Align to the end of the view, which is ALIGN_RIGHT if the view’s resolved |
| 2016 | * layoutDirection is LTR, and ALIGN_LEFT otherwise. |
| 2017 | * |
| 2018 | * Use with {@link #setTextAlignment(int)} |
| 2019 | */ |
| 2020 | public static final int TEXT_ALIGNMENT_VIEW_END = 6; |
| 2021 | |
| 2022 | /** |
| 2023 | * Default text alignment is inherited |
| 2024 | */ |
Fabrice Di Meglio | 72898e9 | 2012-10-25 11:22:39 -0700 | [diff] [blame] | 2025 | private static final int TEXT_ALIGNMENT_DEFAULT = TEXT_ALIGNMENT_GRAVITY; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2026 | |
| 2027 | /** |
| 2028 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 2029 | * @hide |
| 2030 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2031 | static final int PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT = 13; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2032 | |
| 2033 | /** |
| 2034 | * Mask for use with private flags indicating bits used for text alignment. |
| 2035 | * @hide |
| 2036 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2037 | static final int PFLAG2_TEXT_ALIGNMENT_MASK = 0x00000007 << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2038 | |
| 2039 | /** |
| 2040 | * Array of text direction flags for mapping attribute "textAlignment" to correct |
| 2041 | * flag value. |
| 2042 | * @hide |
| 2043 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2044 | private static final int[] PFLAG2_TEXT_ALIGNMENT_FLAGS = { |
| 2045 | TEXT_ALIGNMENT_INHERIT << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2046 | TEXT_ALIGNMENT_GRAVITY << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2047 | TEXT_ALIGNMENT_TEXT_START << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2048 | TEXT_ALIGNMENT_TEXT_END << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2049 | TEXT_ALIGNMENT_CENTER << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2050 | TEXT_ALIGNMENT_VIEW_START << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2051 | TEXT_ALIGNMENT_VIEW_END << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2052 | }; |
| 2053 | |
| 2054 | /** |
| 2055 | * Indicates whether the view text alignment has been resolved. |
| 2056 | * @hide |
| 2057 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2058 | static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED = 0x00000008 << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2059 | |
| 2060 | /** |
| 2061 | * Bit shift to get the resolved text alignment. |
| 2062 | * @hide |
| 2063 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2064 | static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT = 17; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2065 | |
| 2066 | /** |
| 2067 | * Mask for use with private flags indicating bits used for text alignment. |
| 2068 | * @hide |
| 2069 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2070 | static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK = 0x00000007 |
| 2071 | << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2072 | |
| 2073 | /** |
| 2074 | * Indicates whether if the view text alignment has been resolved to gravity |
| 2075 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2076 | private static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT = |
| 2077 | TEXT_ALIGNMENT_GRAVITY << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2078 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2079 | // Accessiblity constants for mPrivateFlags2 |
| 2080 | |
| 2081 | /** |
Svetoslav Ganov | f9817f7 | 2012-05-22 18:10:31 -0700 | [diff] [blame] | 2082 | * Shift for the bits in {@link #mPrivateFlags2} related to the |
| 2083 | * "importantForAccessibility" attribute. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2084 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2085 | static final int PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT = 20; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2086 | |
| 2087 | /** |
| 2088 | * Automatically determine whether a view is important for accessibility. |
| 2089 | */ |
| 2090 | public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO = 0x00000000; |
| 2091 | |
| 2092 | /** |
| 2093 | * The view is important for accessibility. |
| 2094 | */ |
| 2095 | public static final int IMPORTANT_FOR_ACCESSIBILITY_YES = 0x00000001; |
| 2096 | |
| 2097 | /** |
| 2098 | * The view is not important for accessibility. |
| 2099 | */ |
| 2100 | public static final int IMPORTANT_FOR_ACCESSIBILITY_NO = 0x00000002; |
| 2101 | |
| 2102 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 2103 | * The default whether the view is important for accessibility. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2104 | */ |
| 2105 | static final int IMPORTANT_FOR_ACCESSIBILITY_DEFAULT = IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
| 2106 | |
| 2107 | /** |
| 2108 | * Mask for obtainig the bits which specify how to determine |
| 2109 | * whether a view is important for accessibility. |
| 2110 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2111 | static final int PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK = (IMPORTANT_FOR_ACCESSIBILITY_AUTO |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2112 | | IMPORTANT_FOR_ACCESSIBILITY_YES | IMPORTANT_FOR_ACCESSIBILITY_NO) |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2113 | << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2114 | |
| 2115 | /** |
| 2116 | * Flag indicating whether a view has accessibility focus. |
| 2117 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2118 | static final int PFLAG2_ACCESSIBILITY_FOCUSED = 0x00000040 << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2119 | |
| 2120 | /** |
| 2121 | * Flag indicating whether a view state for accessibility has changed. |
| 2122 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2123 | static final int PFLAG2_ACCESSIBILITY_STATE_CHANGED = 0x00000080 |
| 2124 | << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 2125 | |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 2126 | /** |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 2127 | * Flag indicating whether a view failed the quickReject() check in draw(). This condition |
| 2128 | * is used to check whether later changes to the view's transform should invalidate the |
| 2129 | * view to force the quickReject test to run again. |
| 2130 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2131 | static final int PFLAG2_VIEW_QUICK_REJECTED = 0x10000000; |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 2132 | |
Adam Powell | 0090f20 | 2012-08-07 17:15:30 -0700 | [diff] [blame] | 2133 | /** |
| 2134 | * Flag indicating that start/end padding has been resolved into left/right padding |
| 2135 | * for use in measurement, layout, drawing, etc. This is set by {@link #resolvePadding()} |
| 2136 | * and checked by {@link #measure(int, int)} to determine if padding needs to be resolved |
| 2137 | * during measurement. In some special cases this is required such as when an adapter-based |
| 2138 | * view measures prospective children without attaching them to a window. |
| 2139 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2140 | static final int PFLAG2_PADDING_RESOLVED = 0x20000000; |
Adam Powell | 0090f20 | 2012-08-07 17:15:30 -0700 | [diff] [blame] | 2141 | |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 2142 | /** |
| 2143 | * Flag indicating that the start/end drawables has been resolved into left/right ones. |
| 2144 | */ |
| 2145 | static final int PFLAG2_DRAWABLE_RESOLVED = 0x40000000; |
| 2146 | |
| 2147 | /** |
| 2148 | * Group of bits indicating that RTL properties resolution is done. |
| 2149 | */ |
| 2150 | static final int ALL_RTL_PROPERTIES_RESOLVED = PFLAG2_LAYOUT_DIRECTION_RESOLVED | |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 2151 | PFLAG2_TEXT_DIRECTION_RESOLVED | |
| 2152 | PFLAG2_TEXT_ALIGNMENT_RESOLVED | |
| 2153 | PFLAG2_PADDING_RESOLVED | |
| 2154 | PFLAG2_DRAWABLE_RESOLVED; |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 2155 | |
Svetoslav Ganov | 27e2da7 | 2012-07-02 18:12:00 -0700 | [diff] [blame] | 2156 | // There are a couple of flags left in mPrivateFlags2 |
Svetoslav Ganov | f9817f7 | 2012-05-22 18:10:31 -0700 | [diff] [blame] | 2157 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2158 | /* End of masks for mPrivateFlags2 */ |
| 2159 | |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2160 | /* Masks for mPrivateFlags3 */ |
| 2161 | |
| 2162 | /** |
| 2163 | * Flag indicating that view has a transform animation set on it. This is used to track whether |
| 2164 | * an animation is cleared between successive frames, in order to tell the associated |
| 2165 | * DisplayList to clear its animation matrix. |
| 2166 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2167 | static final int PFLAG3_VIEW_IS_ANIMATING_TRANSFORM = 0x1; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2168 | |
| 2169 | /** |
| 2170 | * Flag indicating that view has an alpha animation set on it. This is used to track whether an |
| 2171 | * animation is cleared between successive frames, in order to tell the associated |
| 2172 | * DisplayList to restore its alpha value. |
| 2173 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2174 | static final int PFLAG3_VIEW_IS_ANIMATING_ALPHA = 0x2; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2175 | |
| 2176 | |
| 2177 | /* End of masks for mPrivateFlags3 */ |
| 2178 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2179 | static final int DRAG_MASK = PFLAG2_DRAG_CAN_ACCEPT | PFLAG2_DRAG_HOVERED; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2180 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 2181 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2182 | * Always allow a user to over-scroll this view, provided it is a |
| 2183 | * view that can scroll. |
| 2184 | * |
| 2185 | * @see #getOverScrollMode() |
| 2186 | * @see #setOverScrollMode(int) |
| 2187 | */ |
| 2188 | public static final int OVER_SCROLL_ALWAYS = 0; |
| 2189 | |
| 2190 | /** |
| 2191 | * Allow a user to over-scroll this view only if the content is large |
| 2192 | * enough to meaningfully scroll, provided it is a view that can scroll. |
| 2193 | * |
| 2194 | * @see #getOverScrollMode() |
| 2195 | * @see #setOverScrollMode(int) |
| 2196 | */ |
| 2197 | public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; |
| 2198 | |
| 2199 | /** |
| 2200 | * Never allow a user to over-scroll this view. |
| 2201 | * |
| 2202 | * @see #getOverScrollMode() |
| 2203 | * @see #setOverScrollMode(int) |
| 2204 | */ |
| 2205 | public static final int OVER_SCROLL_NEVER = 2; |
| 2206 | |
| 2207 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2208 | * Special constant for {@link #setSystemUiVisibility(int)}: View has |
| 2209 | * requested the system UI (status bar) to be visible (the default). |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2210 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2211 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2212 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2213 | public static final int SYSTEM_UI_FLAG_VISIBLE = 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2214 | |
| 2215 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2216 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested the |
| 2217 | * system UI to enter an unobtrusive "low profile" mode. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2218 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2219 | * <p>This is for use in games, book readers, video players, or any other |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2220 | * "immersive" application where the usual system chrome is deemed too distracting. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2221 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2222 | * <p>In low profile mode, the status bar and/or navigation icons may dim. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2223 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2224 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2225 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2226 | public static final int SYSTEM_UI_FLAG_LOW_PROFILE = 0x00000001; |
| 2227 | |
| 2228 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2229 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested that the |
| 2230 | * system navigation be temporarily hidden. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2231 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2232 | * <p>This is an even less obtrusive state than that called for by |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2233 | * {@link #SYSTEM_UI_FLAG_LOW_PROFILE}; on devices that draw essential navigation controls |
| 2234 | * (Home, Back, and the like) on screen, <code>SYSTEM_UI_FLAG_HIDE_NAVIGATION</code> will cause |
| 2235 | * those to disappear. This is useful (in conjunction with the |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2236 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN FLAG_FULLSCREEN} and |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2237 | * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN FLAG_LAYOUT_IN_SCREEN} |
| 2238 | * window flags) for displaying content using every last pixel on the display. |
| 2239 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2240 | * <p>There is a limitation: because navigation controls are so important, the least user |
| 2241 | * interaction will cause them to reappear immediately. When this happens, both |
| 2242 | * this flag and {@link #SYSTEM_UI_FLAG_FULLSCREEN} will be cleared automatically, |
| 2243 | * so that both elements reappear at the same time. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2244 | * |
| 2245 | * @see #setSystemUiVisibility(int) |
| 2246 | */ |
| 2247 | public static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 0x00000002; |
| 2248 | |
| 2249 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2250 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested to go |
| 2251 | * into the normal fullscreen mode so that its content can take over the screen |
| 2252 | * while still allowing the user to interact with the application. |
| 2253 | * |
| 2254 | * <p>This has the same visual effect as |
| 2255 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN |
| 2256 | * WindowManager.LayoutParams.FLAG_FULLSCREEN}, |
| 2257 | * meaning that non-critical screen decorations (such as the status bar) will be |
| 2258 | * hidden while the user is in the View's window, focusing the experience on |
| 2259 | * that content. Unlike the window flag, if you are using ActionBar in |
| 2260 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2261 | * Window.FEATURE_ACTION_BAR_OVERLAY}, then enabling this flag will also |
| 2262 | * hide the action bar. |
| 2263 | * |
| 2264 | * <p>This approach to going fullscreen is best used over the window flag when |
| 2265 | * it is a transient state -- that is, the application does this at certain |
| 2266 | * points in its user interaction where it wants to allow the user to focus |
| 2267 | * on content, but not as a continuous state. For situations where the application |
| 2268 | * would like to simply stay full screen the entire time (such as a game that |
| 2269 | * wants to take over the screen), the |
| 2270 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN window flag} |
| 2271 | * is usually a better approach. The state set here will be removed by the system |
| 2272 | * in various situations (such as the user moving to another application) like |
| 2273 | * the other system UI states. |
| 2274 | * |
| 2275 | * <p>When using this flag, the application should provide some easy facility |
| 2276 | * for the user to go out of it. A common example would be in an e-book |
| 2277 | * reader, where tapping on the screen brings back whatever screen and UI |
| 2278 | * decorations that had been hidden while the user was immersed in reading |
| 2279 | * the book. |
| 2280 | * |
| 2281 | * @see #setSystemUiVisibility(int) |
| 2282 | */ |
| 2283 | public static final int SYSTEM_UI_FLAG_FULLSCREEN = 0x00000004; |
| 2284 | |
| 2285 | /** |
| 2286 | * Flag for {@link #setSystemUiVisibility(int)}: When using other layout |
| 2287 | * flags, we would like a stable view of the content insets given to |
| 2288 | * {@link #fitSystemWindows(Rect)}. This means that the insets seen there |
| 2289 | * will always represent the worst case that the application can expect |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2290 | * as a continuous state. In the stock Android UI this is the space for |
| 2291 | * the system bar, nav bar, and status bar, but not more transient elements |
| 2292 | * such as an input method. |
| 2293 | * |
| 2294 | * The stable layout your UI sees is based on the system UI modes you can |
| 2295 | * switch to. That is, if you specify {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} |
| 2296 | * then you will get a stable layout for changes of the |
| 2297 | * {@link #SYSTEM_UI_FLAG_FULLSCREEN} mode; if you specify |
| 2298 | * {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} and |
| 2299 | * {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, then you can transition |
| 2300 | * to {@link #SYSTEM_UI_FLAG_FULLSCREEN} and {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION} |
| 2301 | * with a stable layout. (Note that you should avoid using |
| 2302 | * {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} by itself.) |
| 2303 | * |
Jeff Smith | a45746e | 2012-07-19 14:19:24 -0500 | [diff] [blame] | 2304 | * If you have set the window flag {@link WindowManager.LayoutParams#FLAG_FULLSCREEN} |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2305 | * to hide the status bar (instead of using {@link #SYSTEM_UI_FLAG_FULLSCREEN}), |
| 2306 | * then a hidden status bar will be considered a "stable" state for purposes |
| 2307 | * here. This allows your UI to continually hide the status bar, while still |
| 2308 | * using the system UI flags to hide the action bar while still retaining |
| 2309 | * a stable layout. Note that changing the window fullscreen flag will never |
| 2310 | * provide a stable layout for a clean transition. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2311 | * |
| 2312 | * <p>If you are using ActionBar in |
| 2313 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2314 | * Window.FEATURE_ACTION_BAR_OVERLAY}, this flag will also impact the |
| 2315 | * insets it adds to those given to the application. |
| 2316 | */ |
| 2317 | public static final int SYSTEM_UI_FLAG_LAYOUT_STABLE = 0x00000100; |
| 2318 | |
| 2319 | /** |
| 2320 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2321 | * to be layed out as if it has requested |
| 2322 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, even if it currently hasn't. This |
| 2323 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2324 | * the expense that some of its user interface may be covered by screen |
| 2325 | * decorations when they are shown. You can perform layout of your inner |
| 2326 | * UI elements to account for the navagation system UI through the |
| 2327 | * {@link #fitSystemWindows(Rect)} method. |
| 2328 | */ |
| 2329 | public static final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 0x00000200; |
| 2330 | |
| 2331 | /** |
| 2332 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2333 | * to be layed out as if it has requested |
| 2334 | * {@link #SYSTEM_UI_FLAG_FULLSCREEN}, even if it currently hasn't. This |
| 2335 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2336 | * the expense that some of its user interface may be covered by screen |
| 2337 | * decorations when they are shown. You can perform layout of your inner |
| 2338 | * UI elements to account for non-fullscreen system UI through the |
| 2339 | * {@link #fitSystemWindows(Rect)} method. |
| 2340 | */ |
| 2341 | public static final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 0x00000400; |
| 2342 | |
| 2343 | /** |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2344 | * @deprecated Use {@link #SYSTEM_UI_FLAG_LOW_PROFILE} instead. |
| 2345 | */ |
| 2346 | public static final int STATUS_BAR_HIDDEN = SYSTEM_UI_FLAG_LOW_PROFILE; |
| 2347 | |
| 2348 | /** |
| 2349 | * @deprecated Use {@link #SYSTEM_UI_FLAG_VISIBLE} instead. |
| 2350 | */ |
| 2351 | public static final int STATUS_BAR_VISIBLE = SYSTEM_UI_FLAG_VISIBLE; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2352 | |
| 2353 | /** |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2354 | * @hide |
| 2355 | * |
| 2356 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2357 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2358 | * |
| 2359 | * Flag to make the status bar not expandable. Unless you also |
| 2360 | * set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show. |
| 2361 | */ |
| 2362 | public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000; |
| 2363 | |
| 2364 | /** |
| 2365 | * @hide |
| 2366 | * |
| 2367 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2368 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2369 | * |
| 2370 | * Flag to hide notification icons and scrolling ticker text. |
| 2371 | */ |
| 2372 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS = 0x00020000; |
| 2373 | |
| 2374 | /** |
| 2375 | * @hide |
| 2376 | * |
| 2377 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2378 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2379 | * |
| 2380 | * Flag to disable incoming notification alerts. This will not block |
| 2381 | * icons, but it will block sound, vibrating and other visual or aural notifications. |
| 2382 | */ |
| 2383 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS = 0x00040000; |
| 2384 | |
| 2385 | /** |
| 2386 | * @hide |
| 2387 | * |
| 2388 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2389 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2390 | * |
| 2391 | * Flag to hide only the scrolling ticker. Note that |
| 2392 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS} implies |
| 2393 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_TICKER}. |
| 2394 | */ |
| 2395 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_TICKER = 0x00080000; |
| 2396 | |
| 2397 | /** |
| 2398 | * @hide |
| 2399 | * |
| 2400 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2401 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2402 | * |
| 2403 | * Flag to hide the center system info area. |
| 2404 | */ |
| 2405 | public static final int STATUS_BAR_DISABLE_SYSTEM_INFO = 0x00100000; |
| 2406 | |
| 2407 | /** |
| 2408 | * @hide |
| 2409 | * |
| 2410 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2411 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2412 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2413 | * Flag to hide only the home button. Don't use this |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2414 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2415 | */ |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2416 | public static final int STATUS_BAR_DISABLE_HOME = 0x00200000; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2417 | |
| 2418 | /** |
| 2419 | * @hide |
| 2420 | * |
| 2421 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2422 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2423 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2424 | * Flag to hide only the back button. Don't use this |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2425 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2426 | */ |
| 2427 | public static final int STATUS_BAR_DISABLE_BACK = 0x00400000; |
| 2428 | |
| 2429 | /** |
| 2430 | * @hide |
| 2431 | * |
| 2432 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2433 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2434 | * |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2435 | * Flag to hide only the clock. You might use this if your activity has |
| 2436 | * its own clock making the status bar's clock redundant. |
| 2437 | */ |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2438 | public static final int STATUS_BAR_DISABLE_CLOCK = 0x00800000; |
| 2439 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2440 | /** |
| 2441 | * @hide |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2442 | * |
| 2443 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2444 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2445 | * |
| 2446 | * Flag to hide only the recent apps button. Don't use this |
| 2447 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2448 | */ |
| 2449 | public static final int STATUS_BAR_DISABLE_RECENT = 0x01000000; |
| 2450 | |
| 2451 | /** |
| 2452 | * @hide |
Daniel Sandler | d5483c3 | 2012-10-19 16:44:15 -0400 | [diff] [blame] | 2453 | * |
| 2454 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2455 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2456 | * |
| 2457 | * Flag to disable the global search gesture. Don't use this |
| 2458 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2459 | */ |
| 2460 | public static final int STATUS_BAR_DISABLE_SEARCH = 0x02000000; |
| 2461 | |
| 2462 | /** |
| 2463 | * @hide |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2464 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2465 | public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x0000FFFF; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2466 | |
| 2467 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2468 | * These are the system UI flags that can be cleared by events outside |
| 2469 | * of an application. Currently this is just the ability to tap on the |
| 2470 | * screen while hiding the navigation bar to have it return. |
| 2471 | * @hide |
| 2472 | */ |
| 2473 | public static final int SYSTEM_UI_CLEARABLE_FLAGS = |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2474 | SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 2475 | | SYSTEM_UI_FLAG_FULLSCREEN; |
| 2476 | |
| 2477 | /** |
| 2478 | * Flags that can impact the layout in relation to system UI. |
| 2479 | */ |
| 2480 | public static final int SYSTEM_UI_LAYOUT_FLAGS = |
| 2481 | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 2482 | | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2483 | |
| 2484 | /** |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 2485 | * Find views that render the specified text. |
| 2486 | * |
| 2487 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2488 | */ |
| 2489 | public static final int FIND_VIEWS_WITH_TEXT = 0x00000001; |
| 2490 | |
| 2491 | /** |
| 2492 | * Find find views that contain the specified content description. |
| 2493 | * |
| 2494 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2495 | */ |
| 2496 | public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 0x00000002; |
| 2497 | |
| 2498 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 2499 | * Find views that contain {@link AccessibilityNodeProvider}. Such |
| 2500 | * a View is a root of virtual view hierarchy and may contain the searched |
| 2501 | * text. If this flag is set Views with providers are automatically |
| 2502 | * added and it is a responsibility of the client to call the APIs of |
| 2503 | * the provider to determine whether the virtual tree rooted at this View |
| 2504 | * contains the text, i.e. getting the list of {@link AccessibilityNodeInfo}s |
| 2505 | * represeting the virtual views with this text. |
| 2506 | * |
| 2507 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2508 | * |
| 2509 | * @hide |
| 2510 | */ |
| 2511 | public static final int FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS = 0x00000004; |
| 2512 | |
| 2513 | /** |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 2514 | * The undefined cursor position. |
| 2515 | */ |
| 2516 | private static final int ACCESSIBILITY_CURSOR_POSITION_UNDEFINED = -1; |
| 2517 | |
| 2518 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2519 | * Indicates that the screen has changed state and is now off. |
| 2520 | * |
| 2521 | * @see #onScreenStateChanged(int) |
| 2522 | */ |
| 2523 | public static final int SCREEN_STATE_OFF = 0x0; |
| 2524 | |
| 2525 | /** |
| 2526 | * Indicates that the screen has changed state and is now on. |
| 2527 | * |
Romain Guy | 1e3d313 | 2012-03-08 15:55:56 -0800 | [diff] [blame] | 2528 | * @see #onScreenStateChanged(int) |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2529 | */ |
| 2530 | public static final int SCREEN_STATE_ON = 0x1; |
| 2531 | |
| 2532 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2533 | * Controls the over-scroll mode for this view. |
| 2534 | * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)}, |
| 2535 | * {@link #OVER_SCROLL_ALWAYS}, {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}, |
| 2536 | * and {@link #OVER_SCROLL_NEVER}. |
| 2537 | */ |
| 2538 | private int mOverScrollMode; |
| 2539 | |
| 2540 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2541 | * The parent this view is attached to. |
| 2542 | * {@hide} |
| 2543 | * |
| 2544 | * @see #getParent() |
| 2545 | */ |
| 2546 | protected ViewParent mParent; |
| 2547 | |
| 2548 | /** |
| 2549 | * {@hide} |
| 2550 | */ |
| 2551 | AttachInfo mAttachInfo; |
| 2552 | |
| 2553 | /** |
| 2554 | * {@hide} |
| 2555 | */ |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2556 | @ViewDebug.ExportedProperty(flagMapping = { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2557 | @ViewDebug.FlagToString(mask = PFLAG_FORCE_LAYOUT, equals = PFLAG_FORCE_LAYOUT, |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2558 | name = "FORCE_LAYOUT"), |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2559 | @ViewDebug.FlagToString(mask = PFLAG_LAYOUT_REQUIRED, equals = PFLAG_LAYOUT_REQUIRED, |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2560 | name = "LAYOUT_REQUIRED"), |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2561 | @ViewDebug.FlagToString(mask = PFLAG_DRAWING_CACHE_VALID, equals = PFLAG_DRAWING_CACHE_VALID, |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 2562 | name = "DRAWING_CACHE_INVALID", outputIf = false), |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2563 | @ViewDebug.FlagToString(mask = PFLAG_DRAWN, equals = PFLAG_DRAWN, name = "DRAWN", outputIf = true), |
| 2564 | @ViewDebug.FlagToString(mask = PFLAG_DRAWN, equals = PFLAG_DRAWN, name = "NOT_DRAWN", outputIf = false), |
| 2565 | @ViewDebug.FlagToString(mask = PFLAG_DIRTY_MASK, equals = PFLAG_DIRTY_OPAQUE, name = "DIRTY_OPAQUE"), |
| 2566 | @ViewDebug.FlagToString(mask = PFLAG_DIRTY_MASK, equals = PFLAG_DIRTY, name = "DIRTY") |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2567 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2568 | int mPrivateFlags; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2569 | int mPrivateFlags2; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2570 | int mPrivateFlags3; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2571 | |
| 2572 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2573 | * This view's request for the visibility of the status bar. |
| 2574 | * @hide |
| 2575 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2576 | @ViewDebug.ExportedProperty(flagMapping = { |
| 2577 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2578 | equals = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2579 | name = "SYSTEM_UI_FLAG_LOW_PROFILE", outputIf = true), |
| 2580 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2581 | equals = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2582 | name = "SYSTEM_UI_FLAG_HIDE_NAVIGATION", outputIf = true), |
| 2583 | @ViewDebug.FlagToString(mask = PUBLIC_STATUS_BAR_VISIBILITY_MASK, |
| 2584 | equals = SYSTEM_UI_FLAG_VISIBLE, |
| 2585 | name = "SYSTEM_UI_FLAG_VISIBLE", outputIf = true) |
| 2586 | }) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2587 | int mSystemUiVisibility; |
| 2588 | |
| 2589 | /** |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 2590 | * Reference count for transient state. |
| 2591 | * @see #setHasTransientState(boolean) |
| 2592 | */ |
| 2593 | int mTransientStateCount = 0; |
| 2594 | |
| 2595 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2596 | * Count of how many windows this view has been attached to. |
| 2597 | */ |
| 2598 | int mWindowAttachCount; |
| 2599 | |
| 2600 | /** |
| 2601 | * The layout parameters associated with this view and used by the parent |
| 2602 | * {@link android.view.ViewGroup} to determine how this view should be |
| 2603 | * laid out. |
| 2604 | * {@hide} |
| 2605 | */ |
| 2606 | protected ViewGroup.LayoutParams mLayoutParams; |
| 2607 | |
| 2608 | /** |
| 2609 | * The view flags hold various views states. |
| 2610 | * {@hide} |
| 2611 | */ |
| 2612 | @ViewDebug.ExportedProperty |
| 2613 | int mViewFlags; |
| 2614 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2615 | static class TransformationInfo { |
| 2616 | /** |
| 2617 | * The transform matrix for the View. This transform is calculated internally |
| 2618 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2619 | * is used by default. Do *not* use this variable directly; instead call |
| 2620 | * getMatrix(), which will automatically recalculate the matrix if necessary |
| 2621 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2622 | */ |
| 2623 | private final Matrix mMatrix = new Matrix(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2624 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2625 | /** |
| 2626 | * The transform matrix for the View. This transform is calculated internally |
| 2627 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2628 | * is used by default. Do *not* use this variable directly; instead call |
| 2629 | * getInverseMatrix(), which will automatically recalculate the matrix if necessary |
| 2630 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2631 | */ |
| 2632 | private Matrix mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2633 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2634 | /** |
| 2635 | * An internal variable that tracks whether we need to recalculate the |
| 2636 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2637 | * have changed since the matrix was last calculated. |
| 2638 | */ |
| 2639 | boolean mMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2640 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2641 | /** |
| 2642 | * An internal variable that tracks whether we need to recalculate the |
| 2643 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2644 | * have changed since the matrix was last calculated. |
| 2645 | */ |
| 2646 | private boolean mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2647 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2648 | /** |
| 2649 | * A variable that tracks whether we need to recalculate the |
| 2650 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2651 | * have changed since the matrix was last calculated. This variable |
| 2652 | * is only valid after a call to updateMatrix() or to a function that |
| 2653 | * calls it such as getMatrix(), hasIdentityMatrix() and getInverseMatrix(). |
| 2654 | */ |
| 2655 | private boolean mMatrixIsIdentity = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2656 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2657 | /** |
| 2658 | * The Camera object is used to compute a 3D matrix when rotationX or rotationY are set. |
| 2659 | */ |
| 2660 | private Camera mCamera = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2661 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2662 | /** |
| 2663 | * This matrix is used when computing the matrix for 3D rotations. |
| 2664 | */ |
| 2665 | private Matrix matrix3D = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2666 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2667 | /** |
| 2668 | * These prev values are used to recalculate a centered pivot point when necessary. The |
| 2669 | * pivot point is only used in matrix operations (when rotation, scale, or translation are |
| 2670 | * set), so thes values are only used then as well. |
| 2671 | */ |
| 2672 | private int mPrevWidth = -1; |
| 2673 | private int mPrevHeight = -1; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2674 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2675 | /** |
| 2676 | * The degrees rotation around the vertical axis through the pivot point. |
| 2677 | */ |
| 2678 | @ViewDebug.ExportedProperty |
| 2679 | float mRotationY = 0f; |
| 2680 | |
| 2681 | /** |
| 2682 | * The degrees rotation around the horizontal axis through the pivot point. |
| 2683 | */ |
| 2684 | @ViewDebug.ExportedProperty |
| 2685 | float mRotationX = 0f; |
| 2686 | |
| 2687 | /** |
| 2688 | * The degrees rotation around the pivot point. |
| 2689 | */ |
| 2690 | @ViewDebug.ExportedProperty |
| 2691 | float mRotation = 0f; |
| 2692 | |
| 2693 | /** |
| 2694 | * The amount of translation of the object away from its left property (post-layout). |
| 2695 | */ |
| 2696 | @ViewDebug.ExportedProperty |
| 2697 | float mTranslationX = 0f; |
| 2698 | |
| 2699 | /** |
| 2700 | * The amount of translation of the object away from its top property (post-layout). |
| 2701 | */ |
| 2702 | @ViewDebug.ExportedProperty |
| 2703 | float mTranslationY = 0f; |
| 2704 | |
| 2705 | /** |
| 2706 | * The amount of scale in the x direction around the pivot point. A |
| 2707 | * value of 1 means no scaling is applied. |
| 2708 | */ |
| 2709 | @ViewDebug.ExportedProperty |
| 2710 | float mScaleX = 1f; |
| 2711 | |
| 2712 | /** |
| 2713 | * The amount of scale in the y direction around the pivot point. A |
| 2714 | * value of 1 means no scaling is applied. |
| 2715 | */ |
| 2716 | @ViewDebug.ExportedProperty |
| 2717 | float mScaleY = 1f; |
| 2718 | |
| 2719 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2720 | * The x location of the point around which the view is rotated and scaled. |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2721 | */ |
| 2722 | @ViewDebug.ExportedProperty |
| 2723 | float mPivotX = 0f; |
| 2724 | |
| 2725 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2726 | * The y location of the point around which the view is rotated and scaled. |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2727 | */ |
| 2728 | @ViewDebug.ExportedProperty |
| 2729 | float mPivotY = 0f; |
| 2730 | |
| 2731 | /** |
| 2732 | * The opacity of the View. This is a value from 0 to 1, where 0 means |
| 2733 | * completely transparent and 1 means completely opaque. |
| 2734 | */ |
| 2735 | @ViewDebug.ExportedProperty |
| 2736 | float mAlpha = 1f; |
| 2737 | } |
| 2738 | |
| 2739 | TransformationInfo mTransformationInfo; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2740 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2741 | private boolean mLastIsOpaque; |
| 2742 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2743 | /** |
| 2744 | * Convenience value to check for float values that are close enough to zero to be considered |
| 2745 | * zero. |
| 2746 | */ |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 2747 | private static final float NONZERO_EPSILON = .001f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2748 | |
| 2749 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2750 | * The distance in pixels from the left edge of this view's parent |
| 2751 | * to the left edge of this view. |
| 2752 | * {@hide} |
| 2753 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2754 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2755 | protected int mLeft; |
| 2756 | /** |
| 2757 | * The distance in pixels from the left edge of this view's parent |
| 2758 | * to the right edge of this view. |
| 2759 | * {@hide} |
| 2760 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2761 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2762 | protected int mRight; |
| 2763 | /** |
| 2764 | * The distance in pixels from the top edge of this view's parent |
| 2765 | * to the top edge of this view. |
| 2766 | * {@hide} |
| 2767 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2768 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2769 | protected int mTop; |
| 2770 | /** |
| 2771 | * The distance in pixels from the top edge of this view's parent |
| 2772 | * to the bottom edge of this view. |
| 2773 | * {@hide} |
| 2774 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2775 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2776 | protected int mBottom; |
| 2777 | |
| 2778 | /** |
| 2779 | * The offset, in pixels, by which the content of this view is scrolled |
| 2780 | * horizontally. |
| 2781 | * {@hide} |
| 2782 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2783 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2784 | protected int mScrollX; |
| 2785 | /** |
| 2786 | * The offset, in pixels, by which the content of this view is scrolled |
| 2787 | * vertically. |
| 2788 | * {@hide} |
| 2789 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2790 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2791 | protected int mScrollY; |
| 2792 | |
| 2793 | /** |
| 2794 | * The left padding in pixels, that is the distance in pixels between the |
| 2795 | * left edge of this view and the left edge of its content. |
| 2796 | * {@hide} |
| 2797 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2798 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 75aefb8 | 2012-09-27 19:55:18 -0700 | [diff] [blame] | 2799 | protected int mPaddingLeft = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2800 | /** |
| 2801 | * The right padding in pixels, that is the distance in pixels between the |
| 2802 | * right edge of this view and the right edge of its content. |
| 2803 | * {@hide} |
| 2804 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2805 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 75aefb8 | 2012-09-27 19:55:18 -0700 | [diff] [blame] | 2806 | protected int mPaddingRight = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2807 | /** |
| 2808 | * The top padding in pixels, that is the distance in pixels between the |
| 2809 | * top edge of this view and the top edge of its content. |
| 2810 | * {@hide} |
| 2811 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2812 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2813 | protected int mPaddingTop; |
| 2814 | /** |
| 2815 | * The bottom padding in pixels, that is the distance in pixels between the |
| 2816 | * bottom edge of this view and the bottom edge of its content. |
| 2817 | * {@hide} |
| 2818 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2819 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2820 | protected int mPaddingBottom; |
| 2821 | |
| 2822 | /** |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 2823 | * The layout insets in pixels, that is the distance in pixels between the |
| 2824 | * visible edges of this view its bounds. |
| 2825 | */ |
| 2826 | private Insets mLayoutInsets; |
| 2827 | |
| 2828 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2829 | * Briefly describes the view and is primarily used for accessibility support. |
| 2830 | */ |
| 2831 | private CharSequence mContentDescription; |
| 2832 | |
| 2833 | /** |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 2834 | * Specifies the id of a view for which this view serves as a label for |
| 2835 | * accessibility purposes. |
| 2836 | */ |
| 2837 | private int mLabelForId = View.NO_ID; |
| 2838 | |
| 2839 | /** |
| 2840 | * Predicate for matching labeled view id with its label for |
| 2841 | * accessibility purposes. |
| 2842 | */ |
| 2843 | private MatchLabelForPredicate mMatchLabelForPredicate; |
| 2844 | |
| 2845 | /** |
| 2846 | * Predicate for matching a view by its id. |
| 2847 | */ |
| 2848 | private MatchIdPredicate mMatchIdPredicate; |
| 2849 | |
| 2850 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2851 | * 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] | 2852 | * |
| 2853 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2854 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2855 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2856 | protected int mUserPaddingRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2857 | |
| 2858 | /** |
| 2859 | * 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] | 2860 | * |
| 2861 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2862 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2863 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2864 | protected int mUserPaddingBottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2865 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2866 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2867 | * 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] | 2868 | * |
| 2869 | * @hide |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2870 | */ |
| 2871 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2872 | protected int mUserPaddingLeft; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2873 | |
| 2874 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2875 | * Cache the paddingStart set by the user to append to the scrollbar's size. |
| 2876 | * |
| 2877 | */ |
| 2878 | @ViewDebug.ExportedProperty(category = "padding") |
| 2879 | int mUserPaddingStart; |
| 2880 | |
| 2881 | /** |
| 2882 | * Cache the paddingEnd set by the user to append to the scrollbar's size. |
| 2883 | * |
| 2884 | */ |
| 2885 | @ViewDebug.ExportedProperty(category = "padding") |
| 2886 | int mUserPaddingEnd; |
| 2887 | |
| 2888 | /** |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 2889 | * Cache initial left padding. |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 2890 | * |
| 2891 | * @hide |
| 2892 | */ |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 2893 | int mUserPaddingLeftInitial = 0; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 2894 | |
| 2895 | /** |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 2896 | * Cache initial right padding. |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 2897 | * |
| 2898 | * @hide |
| 2899 | */ |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 2900 | int mUserPaddingRightInitial = 0; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 2901 | |
| 2902 | /** |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 2903 | * Default undefined padding |
| 2904 | */ |
| 2905 | private static final int UNDEFINED_PADDING = Integer.MIN_VALUE; |
| 2906 | |
| 2907 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2908 | * @hide |
| 2909 | */ |
| 2910 | int mOldWidthMeasureSpec = Integer.MIN_VALUE; |
| 2911 | /** |
| 2912 | * @hide |
| 2913 | */ |
| 2914 | int mOldHeightMeasureSpec = Integer.MIN_VALUE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2915 | |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 2916 | @ViewDebug.ExportedProperty(deepExport = true, prefix = "bg_") |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2917 | private Drawable mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2918 | |
| 2919 | private int mBackgroundResource; |
| 2920 | private boolean mBackgroundSizeChanged; |
| 2921 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2922 | static class ListenerInfo { |
| 2923 | /** |
| 2924 | * Listener used to dispatch focus change events. |
| 2925 | * This field should be made private, so it is hidden from the SDK. |
| 2926 | * {@hide} |
| 2927 | */ |
| 2928 | protected OnFocusChangeListener mOnFocusChangeListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2929 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2930 | /** |
| 2931 | * Listeners for layout change events. |
| 2932 | */ |
| 2933 | private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 2934 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2935 | /** |
| 2936 | * Listeners for attach events. |
| 2937 | */ |
| 2938 | private CopyOnWriteArrayList<OnAttachStateChangeListener> mOnAttachStateChangeListeners; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 2939 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2940 | /** |
| 2941 | * Listener used to dispatch click events. |
| 2942 | * This field should be made private, so it is hidden from the SDK. |
| 2943 | * {@hide} |
| 2944 | */ |
| 2945 | public OnClickListener mOnClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2946 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2947 | /** |
| 2948 | * Listener used to dispatch long click events. |
| 2949 | * This field should be made private, so it is hidden from the SDK. |
| 2950 | * {@hide} |
| 2951 | */ |
| 2952 | protected OnLongClickListener mOnLongClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2953 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2954 | /** |
| 2955 | * Listener used to build the context menu. |
| 2956 | * This field should be made private, so it is hidden from the SDK. |
| 2957 | * {@hide} |
| 2958 | */ |
| 2959 | protected OnCreateContextMenuListener mOnCreateContextMenuListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2960 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2961 | private OnKeyListener mOnKeyListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2962 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2963 | private OnTouchListener mOnTouchListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2964 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2965 | private OnHoverListener mOnHoverListener; |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2966 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2967 | private OnGenericMotionListener mOnGenericMotionListener; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2968 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2969 | private OnDragListener mOnDragListener; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 2970 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2971 | private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener; |
| 2972 | } |
| 2973 | |
| 2974 | ListenerInfo mListenerInfo; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2975 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2976 | /** |
| 2977 | * The application environment this view lives in. |
| 2978 | * This field should be made private, so it is hidden from the SDK. |
| 2979 | * {@hide} |
| 2980 | */ |
| 2981 | protected Context mContext; |
| 2982 | |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 2983 | private final Resources mResources; |
| 2984 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2985 | private ScrollabilityCache mScrollCache; |
| 2986 | |
| 2987 | private int[] mDrawableState = null; |
| 2988 | |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2989 | /** |
| 2990 | * Set to true when drawing cache is enabled and cannot be created. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2991 | * |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2992 | * @hide |
| 2993 | */ |
| 2994 | public boolean mCachingFailed; |
| 2995 | |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 2996 | private Bitmap mDrawingCache; |
| 2997 | private Bitmap mUnscaledDrawingCache; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 2998 | private HardwareLayer mHardwareLayer; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2999 | DisplayList mDisplayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3000 | |
| 3001 | /** |
| 3002 | * When this view has focus and the next focus is {@link #FOCUS_LEFT}, |
| 3003 | * the user may specify which view to go to next. |
| 3004 | */ |
| 3005 | private int mNextFocusLeftId = View.NO_ID; |
| 3006 | |
| 3007 | /** |
| 3008 | * When this view has focus and the next focus is {@link #FOCUS_RIGHT}, |
| 3009 | * the user may specify which view to go to next. |
| 3010 | */ |
| 3011 | private int mNextFocusRightId = View.NO_ID; |
| 3012 | |
| 3013 | /** |
| 3014 | * When this view has focus and the next focus is {@link #FOCUS_UP}, |
| 3015 | * the user may specify which view to go to next. |
| 3016 | */ |
| 3017 | private int mNextFocusUpId = View.NO_ID; |
| 3018 | |
| 3019 | /** |
| 3020 | * When this view has focus and the next focus is {@link #FOCUS_DOWN}, |
| 3021 | * the user may specify which view to go to next. |
| 3022 | */ |
| 3023 | private int mNextFocusDownId = View.NO_ID; |
| 3024 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3025 | /** |
| 3026 | * When this view has focus and the next focus is {@link #FOCUS_FORWARD}, |
| 3027 | * the user may specify which view to go to next. |
| 3028 | */ |
| 3029 | int mNextFocusForwardId = View.NO_ID; |
| 3030 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3031 | private CheckForLongPress mPendingCheckForLongPress; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 3032 | private CheckForTap mPendingCheckForTap = null; |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 3033 | private PerformClick mPerformClick; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 3034 | private SendViewScrolledAccessibilityEvent mSendViewScrolledAccessibilityEvent; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3035 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | private UnsetPressedState mUnsetPressedState; |
| 3037 | |
| 3038 | /** |
| 3039 | * Whether the long press's action has been invoked. The tap's action is invoked on the |
| 3040 | * up event while a long press is invoked as soon as the long press duration is reached, so |
| 3041 | * a long press could be performed before the tap is checked, in which case the tap's action |
| 3042 | * should not be invoked. |
| 3043 | */ |
| 3044 | private boolean mHasPerformedLongPress; |
| 3045 | |
| 3046 | /** |
| 3047 | * The minimum height of the view. We'll try our best to have the height |
| 3048 | * of this view to at least this amount. |
| 3049 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 3050 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3051 | private int mMinHeight; |
| 3052 | |
| 3053 | /** |
| 3054 | * The minimum width of the view. We'll try our best to have the width |
| 3055 | * of this view to at least this amount. |
| 3056 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 3057 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3058 | private int mMinWidth; |
| 3059 | |
| 3060 | /** |
| 3061 | * The delegate to handle touch events that are physically in this view |
| 3062 | * but should be handled by another view. |
| 3063 | */ |
| 3064 | private TouchDelegate mTouchDelegate = null; |
| 3065 | |
| 3066 | /** |
| 3067 | * Solid color to use as a background when creating the drawing cache. Enables |
| 3068 | * the cache to use 16 bit bitmaps instead of 32 bit. |
| 3069 | */ |
| 3070 | private int mDrawingCacheBackgroundColor = 0; |
| 3071 | |
| 3072 | /** |
| 3073 | * Special tree observer used when mAttachInfo is null. |
| 3074 | */ |
| 3075 | private ViewTreeObserver mFloatingTreeObserver; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3076 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 3077 | /** |
| 3078 | * Cache the touch slop from the context that created the view. |
| 3079 | */ |
| 3080 | private int mTouchSlop; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3081 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3082 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 3083 | * Object that handles automatic animation of view properties. |
| 3084 | */ |
| 3085 | private ViewPropertyAnimator mAnimator = null; |
| 3086 | |
| 3087 | /** |
Christopher Tate | 251602f | 2011-01-28 17:54:12 -0800 | [diff] [blame] | 3088 | * Flag indicating that a drag can cross window boundaries. When |
| 3089 | * {@link #startDrag(ClipData, DragShadowBuilder, Object, int)} is called |
| 3090 | * with this flag set, all visible applications will be able to participate |
| 3091 | * in the drag operation and receive the dragged content. |
Christopher Tate | 7f9ff9d | 2011-02-14 17:31:13 -0800 | [diff] [blame] | 3092 | * |
| 3093 | * @hide |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 3094 | */ |
| 3095 | public static final int DRAG_FLAG_GLOBAL = 1; |
| 3096 | |
| 3097 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3098 | * Vertical scroll factor cached by {@link #getVerticalScrollFactor}. |
| 3099 | */ |
| 3100 | private float mVerticalScrollFactor; |
| 3101 | |
| 3102 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3103 | * Position of the vertical scroll bar. |
| 3104 | */ |
| 3105 | private int mVerticalScrollbarPosition; |
| 3106 | |
| 3107 | /** |
| 3108 | * Position the scroll bar at the default position as determined by the system. |
| 3109 | */ |
| 3110 | public static final int SCROLLBAR_POSITION_DEFAULT = 0; |
| 3111 | |
| 3112 | /** |
| 3113 | * Position the scroll bar along the left edge. |
| 3114 | */ |
| 3115 | public static final int SCROLLBAR_POSITION_LEFT = 1; |
| 3116 | |
| 3117 | /** |
| 3118 | * Position the scroll bar along the right edge. |
| 3119 | */ |
| 3120 | public static final int SCROLLBAR_POSITION_RIGHT = 2; |
| 3121 | |
| 3122 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3123 | * Indicates that the view does not have a layer. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3124 | * |
| 3125 | * @see #getLayerType() |
| 3126 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3127 | * @see #LAYER_TYPE_SOFTWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3128 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3129 | */ |
| 3130 | public static final int LAYER_TYPE_NONE = 0; |
| 3131 | |
| 3132 | /** |
| 3133 | * <p>Indicates that the view has a software layer. A software layer is backed |
| 3134 | * by a bitmap and causes the view to be rendered using Android's software |
| 3135 | * rendering pipeline, even if hardware acceleration is enabled.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3136 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3137 | * <p>Software layers have various usages:</p> |
| 3138 | * <p>When the application is not using hardware acceleration, a software layer |
| 3139 | * is useful to apply a specific color filter and/or blending mode and/or |
| 3140 | * translucency to a view and all its children.</p> |
| 3141 | * <p>When the application is using hardware acceleration, a software layer |
| 3142 | * is useful to render drawing primitives not supported by the hardware |
| 3143 | * accelerated pipeline. It can also be used to cache a complex view tree |
| 3144 | * into a texture and reduce the complexity of drawing operations. For instance, |
| 3145 | * when animating a complex view tree with a translation, a software layer can |
| 3146 | * be used to render the view tree only once.</p> |
| 3147 | * <p>Software layers should be avoided when the affected view tree updates |
| 3148 | * often. Every update will require to re-render the software layer, which can |
| 3149 | * potentially be slow (particularly when hardware acceleration is turned on |
| 3150 | * since the layer will have to be uploaded into a hardware texture after every |
| 3151 | * update.)</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3152 | * |
| 3153 | * @see #getLayerType() |
| 3154 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3155 | * @see #LAYER_TYPE_NONE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3156 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3157 | */ |
| 3158 | public static final int LAYER_TYPE_SOFTWARE = 1; |
| 3159 | |
| 3160 | /** |
| 3161 | * <p>Indicates that the view has a hardware layer. A hardware layer is backed |
| 3162 | * by a hardware specific texture (generally Frame Buffer Objects or FBO on |
| 3163 | * OpenGL hardware) and causes the view to be rendered using Android's hardware |
| 3164 | * rendering pipeline, but only if hardware acceleration is turned on for the |
| 3165 | * view hierarchy. When hardware acceleration is turned off, hardware layers |
| 3166 | * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3167 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3168 | * <p>A hardware layer is useful to apply a specific color filter and/or |
| 3169 | * 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] | 3170 | * <p>A hardware layer can be used to cache a complex view tree into a |
| 3171 | * texture and reduce the complexity of drawing operations. For instance, |
| 3172 | * when animating a complex view tree with a translation, a hardware layer can |
| 3173 | * be used to render the view tree only once.</p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3174 | * <p>A hardware layer can also be used to increase the rendering quality when |
| 3175 | * rotation transformations are applied on a view. It can also be used to |
| 3176 | * prevent potential clipping issues when applying 3D transforms on a view.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3177 | * |
| 3178 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3179 | * @see #setLayerType(int, android.graphics.Paint) |
| 3180 | * @see #LAYER_TYPE_NONE |
| 3181 | * @see #LAYER_TYPE_SOFTWARE |
| 3182 | */ |
| 3183 | public static final int LAYER_TYPE_HARDWARE = 2; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3184 | |
Romain Guy | 3aaff3a | 2011-01-12 14:18:47 -0800 | [diff] [blame] | 3185 | @ViewDebug.ExportedProperty(category = "drawing", mapping = { |
| 3186 | @ViewDebug.IntToString(from = LAYER_TYPE_NONE, to = "NONE"), |
| 3187 | @ViewDebug.IntToString(from = LAYER_TYPE_SOFTWARE, to = "SOFTWARE"), |
| 3188 | @ViewDebug.IntToString(from = LAYER_TYPE_HARDWARE, to = "HARDWARE") |
| 3189 | }) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3190 | int mLayerType = LAYER_TYPE_NONE; |
| 3191 | Paint mLayerPaint; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 3192 | Rect mLocalDirtyRect; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3193 | |
| 3194 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 3195 | * Set to true when the view is sending hover accessibility events because it |
| 3196 | * is the innermost hovered view. |
| 3197 | */ |
| 3198 | private boolean mSendingHoverAccessibilityEvents; |
| 3199 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3200 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 3201 | * Delegate for injecting accessibility functionality. |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3202 | */ |
| 3203 | AccessibilityDelegate mAccessibilityDelegate; |
| 3204 | |
| 3205 | /** |
| 3206 | * Consistency verifier for debugging purposes. |
| 3207 | * @hide |
| 3208 | */ |
| 3209 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 3210 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 3211 | new InputEventConsistencyVerifier(this, 0) : null; |
| 3212 | |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 3213 | private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); |
| 3214 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 3215 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3216 | * Simple constructor to use when creating a view from code. |
| 3217 | * |
| 3218 | * @param context The Context the view is running in, through which it can |
| 3219 | * access the current theme, resources, etc. |
| 3220 | */ |
| 3221 | public View(Context context) { |
| 3222 | mContext = context; |
| 3223 | mResources = context != null ? context.getResources() : null; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3224 | mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED; |
Fabrice Di Meglio | 72898e9 | 2012-10-25 11:22:39 -0700 | [diff] [blame] | 3225 | // Set some flags defaults |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 3226 | mPrivateFlags2 = |
| 3227 | (LAYOUT_DIRECTION_DEFAULT << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3228 | (TEXT_DIRECTION_DEFAULT << PFLAG2_TEXT_DIRECTION_MASK_SHIFT) | |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 3229 | (PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT) | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3230 | (TEXT_ALIGNMENT_DEFAULT << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT) | |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 3231 | (PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT) | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3232 | (IMPORTANT_FOR_ACCESSIBILITY_DEFAULT << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 3233 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3234 | setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS); |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3235 | mUserPaddingStart = UNDEFINED_PADDING; |
| 3236 | mUserPaddingEnd = UNDEFINED_PADDING; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | /** |
| 3240 | * Constructor that is called when inflating a view from XML. This is called |
| 3241 | * when a view is being constructed from an XML file, supplying attributes |
| 3242 | * that were specified in the XML file. This version uses a default style of |
| 3243 | * 0, so the only attribute values applied are those in the Context's Theme |
| 3244 | * and the given AttributeSet. |
| 3245 | * |
| 3246 | * <p> |
| 3247 | * The method onFinishInflate() will be called after all children have been |
| 3248 | * added. |
| 3249 | * |
| 3250 | * @param context The Context the view is running in, through which it can |
| 3251 | * access the current theme, resources, etc. |
| 3252 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 3253 | * @see #View(Context, AttributeSet, int) |
| 3254 | */ |
| 3255 | public View(Context context, AttributeSet attrs) { |
| 3256 | this(context, attrs, 0); |
| 3257 | } |
| 3258 | |
| 3259 | /** |
| 3260 | * Perform inflation from XML and apply a class-specific base style. This |
| 3261 | * constructor of View allows subclasses to use their own base style when |
| 3262 | * they are inflating. For example, a Button class's constructor would call |
| 3263 | * this version of the super class constructor and supply |
| 3264 | * <code>R.attr.buttonStyle</code> for <var>defStyle</var>; this allows |
| 3265 | * the theme's button style to modify all of the base view attributes (in |
| 3266 | * particular its background) as well as the Button class's attributes. |
| 3267 | * |
| 3268 | * @param context The Context the view is running in, through which it can |
| 3269 | * access the current theme, resources, etc. |
| 3270 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 3271 | * @param defStyle The default style to apply to this view. If 0, no style |
| 3272 | * will be applied (beyond what is included in the theme). This may |
| 3273 | * either be an attribute resource, whose value will be retrieved |
| 3274 | * from the current theme, or an explicit style resource. |
| 3275 | * @see #View(Context, AttributeSet) |
| 3276 | */ |
| 3277 | public View(Context context, AttributeSet attrs, int defStyle) { |
| 3278 | this(context); |
| 3279 | |
| 3280 | TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View, |
| 3281 | defStyle, 0); |
| 3282 | |
| 3283 | Drawable background = null; |
| 3284 | |
| 3285 | int leftPadding = -1; |
| 3286 | int topPadding = -1; |
| 3287 | int rightPadding = -1; |
| 3288 | int bottomPadding = -1; |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3289 | int startPadding = UNDEFINED_PADDING; |
| 3290 | int endPadding = UNDEFINED_PADDING; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3291 | |
| 3292 | int padding = -1; |
| 3293 | |
| 3294 | int viewFlagValues = 0; |
| 3295 | int viewFlagMasks = 0; |
| 3296 | |
| 3297 | boolean setScrollContainer = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3299 | int x = 0; |
| 3300 | int y = 0; |
| 3301 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3302 | float tx = 0; |
| 3303 | float ty = 0; |
| 3304 | float rotation = 0; |
| 3305 | float rotationX = 0; |
| 3306 | float rotationY = 0; |
| 3307 | float sx = 1f; |
| 3308 | float sy = 1f; |
| 3309 | boolean transformSet = false; |
| 3310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3311 | int scrollbarStyle = SCROLLBARS_INSIDE_OVERLAY; |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3312 | int overScrollMode = mOverScrollMode; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3313 | boolean initializeScrollbars = false; |
| 3314 | |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3315 | boolean leftPaddingDefined = false; |
| 3316 | boolean rightPaddingDefined = false; |
| 3317 | boolean startPaddingDefined = false; |
| 3318 | boolean endPaddingDefined = false; |
| 3319 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3320 | final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion; |
| 3321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3322 | final int N = a.getIndexCount(); |
| 3323 | for (int i = 0; i < N; i++) { |
| 3324 | int attr = a.getIndex(i); |
| 3325 | switch (attr) { |
| 3326 | case com.android.internal.R.styleable.View_background: |
| 3327 | background = a.getDrawable(attr); |
| 3328 | break; |
| 3329 | case com.android.internal.R.styleable.View_padding: |
| 3330 | padding = a.getDimensionPixelSize(attr, -1); |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 3331 | mUserPaddingLeftInitial = padding; |
| 3332 | mUserPaddingRightInitial = padding; |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3333 | leftPaddingDefined = true; |
| 3334 | rightPaddingDefined = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3335 | break; |
| 3336 | case com.android.internal.R.styleable.View_paddingLeft: |
| 3337 | leftPadding = a.getDimensionPixelSize(attr, -1); |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 3338 | mUserPaddingLeftInitial = leftPadding; |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3339 | leftPaddingDefined = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | break; |
| 3341 | case com.android.internal.R.styleable.View_paddingTop: |
| 3342 | topPadding = a.getDimensionPixelSize(attr, -1); |
| 3343 | break; |
| 3344 | case com.android.internal.R.styleable.View_paddingRight: |
| 3345 | rightPadding = a.getDimensionPixelSize(attr, -1); |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 3346 | mUserPaddingRightInitial = rightPadding; |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3347 | rightPaddingDefined = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3348 | break; |
| 3349 | case com.android.internal.R.styleable.View_paddingBottom: |
| 3350 | bottomPadding = a.getDimensionPixelSize(attr, -1); |
| 3351 | break; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3352 | case com.android.internal.R.styleable.View_paddingStart: |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3353 | startPadding = a.getDimensionPixelSize(attr, UNDEFINED_PADDING); |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3354 | startPaddingDefined = true; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3355 | break; |
| 3356 | case com.android.internal.R.styleable.View_paddingEnd: |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3357 | endPadding = a.getDimensionPixelSize(attr, UNDEFINED_PADDING); |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3358 | endPaddingDefined = true; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3359 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | case com.android.internal.R.styleable.View_scrollX: |
| 3361 | x = a.getDimensionPixelOffset(attr, 0); |
| 3362 | break; |
| 3363 | case com.android.internal.R.styleable.View_scrollY: |
| 3364 | y = a.getDimensionPixelOffset(attr, 0); |
| 3365 | break; |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3366 | case com.android.internal.R.styleable.View_alpha: |
| 3367 | setAlpha(a.getFloat(attr, 1f)); |
| 3368 | break; |
| 3369 | case com.android.internal.R.styleable.View_transformPivotX: |
| 3370 | setPivotX(a.getDimensionPixelOffset(attr, 0)); |
| 3371 | break; |
| 3372 | case com.android.internal.R.styleable.View_transformPivotY: |
| 3373 | setPivotY(a.getDimensionPixelOffset(attr, 0)); |
| 3374 | break; |
| 3375 | case com.android.internal.R.styleable.View_translationX: |
| 3376 | tx = a.getDimensionPixelOffset(attr, 0); |
| 3377 | transformSet = true; |
| 3378 | break; |
| 3379 | case com.android.internal.R.styleable.View_translationY: |
| 3380 | ty = a.getDimensionPixelOffset(attr, 0); |
| 3381 | transformSet = true; |
| 3382 | break; |
| 3383 | case com.android.internal.R.styleable.View_rotation: |
| 3384 | rotation = a.getFloat(attr, 0); |
| 3385 | transformSet = true; |
| 3386 | break; |
| 3387 | case com.android.internal.R.styleable.View_rotationX: |
| 3388 | rotationX = a.getFloat(attr, 0); |
| 3389 | transformSet = true; |
| 3390 | break; |
| 3391 | case com.android.internal.R.styleable.View_rotationY: |
| 3392 | rotationY = a.getFloat(attr, 0); |
| 3393 | transformSet = true; |
| 3394 | break; |
| 3395 | case com.android.internal.R.styleable.View_scaleX: |
| 3396 | sx = a.getFloat(attr, 1f); |
| 3397 | transformSet = true; |
| 3398 | break; |
| 3399 | case com.android.internal.R.styleable.View_scaleY: |
| 3400 | sy = a.getFloat(attr, 1f); |
| 3401 | transformSet = true; |
| 3402 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3403 | case com.android.internal.R.styleable.View_id: |
| 3404 | mID = a.getResourceId(attr, NO_ID); |
| 3405 | break; |
| 3406 | case com.android.internal.R.styleable.View_tag: |
| 3407 | mTag = a.getText(attr); |
| 3408 | break; |
| 3409 | case com.android.internal.R.styleable.View_fitsSystemWindows: |
| 3410 | if (a.getBoolean(attr, false)) { |
| 3411 | viewFlagValues |= FITS_SYSTEM_WINDOWS; |
| 3412 | viewFlagMasks |= FITS_SYSTEM_WINDOWS; |
| 3413 | } |
| 3414 | break; |
| 3415 | case com.android.internal.R.styleable.View_focusable: |
| 3416 | if (a.getBoolean(attr, false)) { |
| 3417 | viewFlagValues |= FOCUSABLE; |
| 3418 | viewFlagMasks |= FOCUSABLE_MASK; |
| 3419 | } |
| 3420 | break; |
| 3421 | case com.android.internal.R.styleable.View_focusableInTouchMode: |
| 3422 | if (a.getBoolean(attr, false)) { |
| 3423 | viewFlagValues |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE; |
| 3424 | viewFlagMasks |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE_MASK; |
| 3425 | } |
| 3426 | break; |
| 3427 | case com.android.internal.R.styleable.View_clickable: |
| 3428 | if (a.getBoolean(attr, false)) { |
| 3429 | viewFlagValues |= CLICKABLE; |
| 3430 | viewFlagMasks |= CLICKABLE; |
| 3431 | } |
| 3432 | break; |
| 3433 | case com.android.internal.R.styleable.View_longClickable: |
| 3434 | if (a.getBoolean(attr, false)) { |
| 3435 | viewFlagValues |= LONG_CLICKABLE; |
| 3436 | viewFlagMasks |= LONG_CLICKABLE; |
| 3437 | } |
| 3438 | break; |
| 3439 | case com.android.internal.R.styleable.View_saveEnabled: |
| 3440 | if (!a.getBoolean(attr, true)) { |
| 3441 | viewFlagValues |= SAVE_DISABLED; |
| 3442 | viewFlagMasks |= SAVE_DISABLED_MASK; |
| 3443 | } |
| 3444 | break; |
| 3445 | case com.android.internal.R.styleable.View_duplicateParentState: |
| 3446 | if (a.getBoolean(attr, false)) { |
| 3447 | viewFlagValues |= DUPLICATE_PARENT_STATE; |
| 3448 | viewFlagMasks |= DUPLICATE_PARENT_STATE; |
| 3449 | } |
| 3450 | break; |
| 3451 | case com.android.internal.R.styleable.View_visibility: |
| 3452 | final int visibility = a.getInt(attr, 0); |
| 3453 | if (visibility != 0) { |
| 3454 | viewFlagValues |= VISIBILITY_FLAGS[visibility]; |
| 3455 | viewFlagMasks |= VISIBILITY_MASK; |
| 3456 | } |
| 3457 | break; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 3458 | case com.android.internal.R.styleable.View_layoutDirection: |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3459 | // Clear any layout direction flags (included resolved bits) already set |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 3460 | mPrivateFlags2 &= |
| 3461 | ~(PFLAG2_LAYOUT_DIRECTION_MASK | PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3462 | // Set the layout direction flags depending on the value of the attribute |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 3463 | final int layoutDirection = a.getInt(attr, -1); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3464 | final int value = (layoutDirection != -1) ? |
| 3465 | LAYOUT_DIRECTION_FLAGS[layoutDirection] : LAYOUT_DIRECTION_DEFAULT; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3466 | mPrivateFlags2 |= (value << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT); |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 3467 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3468 | case com.android.internal.R.styleable.View_drawingCacheQuality: |
| 3469 | final int cacheQuality = a.getInt(attr, 0); |
| 3470 | if (cacheQuality != 0) { |
| 3471 | viewFlagValues |= DRAWING_CACHE_QUALITY_FLAGS[cacheQuality]; |
| 3472 | viewFlagMasks |= DRAWING_CACHE_QUALITY_MASK; |
| 3473 | } |
| 3474 | break; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3475 | case com.android.internal.R.styleable.View_contentDescription: |
Svetoslav Ganov | e47957a | 2012-06-05 14:46:50 -0700 | [diff] [blame] | 3476 | setContentDescription(a.getString(attr)); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3477 | break; |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 3478 | case com.android.internal.R.styleable.View_labelFor: |
| 3479 | setLabelFor(a.getResourceId(attr, NO_ID)); |
| 3480 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3481 | case com.android.internal.R.styleable.View_soundEffectsEnabled: |
| 3482 | if (!a.getBoolean(attr, true)) { |
| 3483 | viewFlagValues &= ~SOUND_EFFECTS_ENABLED; |
| 3484 | viewFlagMasks |= SOUND_EFFECTS_ENABLED; |
| 3485 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3486 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | case com.android.internal.R.styleable.View_hapticFeedbackEnabled: |
| 3488 | if (!a.getBoolean(attr, true)) { |
| 3489 | viewFlagValues &= ~HAPTIC_FEEDBACK_ENABLED; |
| 3490 | viewFlagMasks |= HAPTIC_FEEDBACK_ENABLED; |
| 3491 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3492 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3493 | case R.styleable.View_scrollbars: |
| 3494 | final int scrollbars = a.getInt(attr, SCROLLBARS_NONE); |
| 3495 | if (scrollbars != SCROLLBARS_NONE) { |
| 3496 | viewFlagValues |= scrollbars; |
| 3497 | viewFlagMasks |= SCROLLBARS_MASK; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3498 | initializeScrollbars = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3499 | } |
| 3500 | break; |
Romain Guy | 2a9fa89 | 2011-09-28 16:50:02 -0700 | [diff] [blame] | 3501 | //noinspection deprecation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3502 | case R.styleable.View_fadingEdge: |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3503 | if (targetSdkVersion >= ICE_CREAM_SANDWICH) { |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 3504 | // Ignore the attribute starting with ICS |
| 3505 | break; |
| 3506 | } |
| 3507 | // With builds < ICS, fall through and apply fading edges |
| 3508 | case R.styleable.View_requiresFadingEdge: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3509 | final int fadingEdge = a.getInt(attr, FADING_EDGE_NONE); |
| 3510 | if (fadingEdge != FADING_EDGE_NONE) { |
| 3511 | viewFlagValues |= fadingEdge; |
| 3512 | viewFlagMasks |= FADING_EDGE_MASK; |
| 3513 | initializeFadingEdge(a); |
| 3514 | } |
| 3515 | break; |
| 3516 | case R.styleable.View_scrollbarStyle: |
| 3517 | scrollbarStyle = a.getInt(attr, SCROLLBARS_INSIDE_OVERLAY); |
| 3518 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3519 | viewFlagValues |= scrollbarStyle & SCROLLBARS_STYLE_MASK; |
| 3520 | viewFlagMasks |= SCROLLBARS_STYLE_MASK; |
| 3521 | } |
| 3522 | break; |
| 3523 | case R.styleable.View_isScrollContainer: |
| 3524 | setScrollContainer = true; |
| 3525 | if (a.getBoolean(attr, false)) { |
| 3526 | setScrollContainer(true); |
| 3527 | } |
| 3528 | break; |
| 3529 | case com.android.internal.R.styleable.View_keepScreenOn: |
| 3530 | if (a.getBoolean(attr, false)) { |
| 3531 | viewFlagValues |= KEEP_SCREEN_ON; |
| 3532 | viewFlagMasks |= KEEP_SCREEN_ON; |
| 3533 | } |
| 3534 | break; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 3535 | case R.styleable.View_filterTouchesWhenObscured: |
| 3536 | if (a.getBoolean(attr, false)) { |
| 3537 | viewFlagValues |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3538 | viewFlagMasks |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3539 | } |
| 3540 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3541 | case R.styleable.View_nextFocusLeft: |
| 3542 | mNextFocusLeftId = a.getResourceId(attr, View.NO_ID); |
| 3543 | break; |
| 3544 | case R.styleable.View_nextFocusRight: |
| 3545 | mNextFocusRightId = a.getResourceId(attr, View.NO_ID); |
| 3546 | break; |
| 3547 | case R.styleable.View_nextFocusUp: |
| 3548 | mNextFocusUpId = a.getResourceId(attr, View.NO_ID); |
| 3549 | break; |
| 3550 | case R.styleable.View_nextFocusDown: |
| 3551 | mNextFocusDownId = a.getResourceId(attr, View.NO_ID); |
| 3552 | break; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3553 | case R.styleable.View_nextFocusForward: |
| 3554 | mNextFocusForwardId = a.getResourceId(attr, View.NO_ID); |
| 3555 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3556 | case R.styleable.View_minWidth: |
| 3557 | mMinWidth = a.getDimensionPixelSize(attr, 0); |
| 3558 | break; |
| 3559 | case R.styleable.View_minHeight: |
| 3560 | mMinHeight = a.getDimensionPixelSize(attr, 0); |
| 3561 | break; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3562 | case R.styleable.View_onClick: |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3563 | if (context.isRestricted()) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3564 | throw new IllegalStateException("The android:onClick attribute cannot " |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3565 | + "be used within a restricted context"); |
| 3566 | } |
| 3567 | |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3568 | final String handlerName = a.getString(attr); |
| 3569 | if (handlerName != null) { |
| 3570 | setOnClickListener(new OnClickListener() { |
| 3571 | private Method mHandler; |
| 3572 | |
| 3573 | public void onClick(View v) { |
| 3574 | if (mHandler == null) { |
| 3575 | try { |
| 3576 | mHandler = getContext().getClass().getMethod(handlerName, |
| 3577 | View.class); |
| 3578 | } catch (NoSuchMethodException e) { |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3579 | int id = getId(); |
| 3580 | String idText = id == NO_ID ? "" : " with id '" |
| 3581 | + getContext().getResources().getResourceEntryName( |
| 3582 | id) + "'"; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3583 | throw new IllegalStateException("Could not find a method " + |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3584 | handlerName + "(View) in the activity " |
| 3585 | + getContext().getClass() + " for onClick handler" |
| 3586 | + " on view " + View.this.getClass() + idText, e); |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3587 | } |
| 3588 | } |
| 3589 | |
| 3590 | try { |
| 3591 | mHandler.invoke(getContext(), View.this); |
| 3592 | } catch (IllegalAccessException e) { |
| 3593 | throw new IllegalStateException("Could not execute non " |
| 3594 | + "public method of the activity", e); |
| 3595 | } catch (InvocationTargetException e) { |
| 3596 | throw new IllegalStateException("Could not execute " |
| 3597 | + "method of the activity", e); |
| 3598 | } |
| 3599 | } |
| 3600 | }); |
| 3601 | } |
| 3602 | break; |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3603 | case R.styleable.View_overScrollMode: |
| 3604 | overScrollMode = a.getInt(attr, OVER_SCROLL_IF_CONTENT_SCROLLS); |
| 3605 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3606 | case R.styleable.View_verticalScrollbarPosition: |
| 3607 | mVerticalScrollbarPosition = a.getInt(attr, SCROLLBAR_POSITION_DEFAULT); |
| 3608 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3609 | case R.styleable.View_layerType: |
| 3610 | setLayerType(a.getInt(attr, LAYER_TYPE_NONE), null); |
| 3611 | break; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3612 | case R.styleable.View_textDirection: |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3613 | // Clear any text direction flag already set |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3614 | mPrivateFlags2 &= ~PFLAG2_TEXT_DIRECTION_MASK; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3615 | // Set the text direction flags depending on the value of the attribute |
| 3616 | final int textDirection = a.getInt(attr, -1); |
| 3617 | if (textDirection != -1) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3618 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_FLAGS[textDirection]; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3619 | } |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3620 | break; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3621 | case R.styleable.View_textAlignment: |
| 3622 | // Clear any text alignment flag already set |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3623 | mPrivateFlags2 &= ~PFLAG2_TEXT_ALIGNMENT_MASK; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3624 | // Set the text alignment flag depending on the value of the attribute |
| 3625 | final int textAlignment = a.getInt(attr, TEXT_ALIGNMENT_DEFAULT); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3626 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_FLAGS[textAlignment]; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3627 | break; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3628 | case R.styleable.View_importantForAccessibility: |
| 3629 | setImportantForAccessibility(a.getInt(attr, |
| 3630 | IMPORTANT_FOR_ACCESSIBILITY_DEFAULT)); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 3631 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3632 | } |
| 3633 | } |
| 3634 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3635 | setOverScrollMode(overScrollMode); |
| 3636 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3637 | // Cache start/end user padding as we cannot fully resolve padding here (we dont have yet |
| 3638 | // the resolved layout direction). Those cached values will be used later during padding |
| 3639 | // resolution. |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 3640 | mUserPaddingStart = startPadding; |
| 3641 | mUserPaddingEnd = endPadding; |
| 3642 | |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3643 | if (background != null) { |
| 3644 | setBackground(background); |
| 3645 | } |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 3646 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3647 | if (padding >= 0) { |
| 3648 | leftPadding = padding; |
| 3649 | topPadding = padding; |
| 3650 | rightPadding = padding; |
| 3651 | bottomPadding = padding; |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 3652 | mUserPaddingLeftInitial = padding; |
| 3653 | mUserPaddingRightInitial = padding; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3654 | } |
| 3655 | |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3656 | if (isRtlCompatibilityMode()) { |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 3657 | // RTL compatibility mode: pre Jelly Bean MR1 case OR no RTL support case. |
| 3658 | // left / right padding are used if defined (meaning here nothing to do). If they are not |
| 3659 | // defined and start / end padding are defined (e.g. in Frameworks resources), then we use |
| 3660 | // start / end and resolve them as left / right (layout direction is not taken into account). |
| 3661 | // Padding from the background drawable is stored at this point in mUserPaddingLeftInitial |
| 3662 | // and mUserPaddingRightInitial) so drawable padding will be used as ultimate default if |
| 3663 | // defined. |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3664 | if (!leftPaddingDefined && startPaddingDefined) { |
| 3665 | leftPadding = startPadding; |
| 3666 | } |
Fabrice Di Meglio | 6e6d781 | 2012-10-01 15:32:01 -0700 | [diff] [blame] | 3667 | mUserPaddingLeftInitial = (leftPadding >= 0) ? leftPadding : mUserPaddingLeftInitial; |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3668 | if (!rightPaddingDefined && endPaddingDefined) { |
| 3669 | rightPadding = endPadding; |
| 3670 | } |
Fabrice Di Meglio | 6e6d781 | 2012-10-01 15:32:01 -0700 | [diff] [blame] | 3671 | mUserPaddingRightInitial = (rightPadding >= 0) ? rightPadding : mUserPaddingRightInitial; |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 3672 | } else { |
| 3673 | // Jelly Bean MR1 and after case: if start/end defined, they will override any left/right |
| 3674 | // values defined. Otherwise, left /right values are used. |
| 3675 | // Padding from the background drawable is stored at this point in mUserPaddingLeftInitial |
| 3676 | // and mUserPaddingRightInitial) so drawable padding will be used as ultimate default if |
| 3677 | // defined. |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 3678 | if (leftPaddingDefined) { |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 3679 | mUserPaddingLeftInitial = leftPadding; |
| 3680 | } |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 3681 | if (rightPaddingDefined) { |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 3682 | mUserPaddingRightInitial = rightPadding; |
| 3683 | } |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3684 | } |
| 3685 | |
Fabrice Di Meglio | 3e27c34 | 2012-09-20 17:56:58 -0700 | [diff] [blame] | 3686 | internalSetPadding( |
Fabrice Di Meglio | 75aefb8 | 2012-09-27 19:55:18 -0700 | [diff] [blame] | 3687 | mUserPaddingLeftInitial, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3688 | topPadding >= 0 ? topPadding : mPaddingTop, |
Fabrice Di Meglio | 75aefb8 | 2012-09-27 19:55:18 -0700 | [diff] [blame] | 3689 | mUserPaddingRightInitial, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3690 | bottomPadding >= 0 ? bottomPadding : mPaddingBottom); |
| 3691 | |
| 3692 | if (viewFlagMasks != 0) { |
| 3693 | setFlags(viewFlagValues, viewFlagMasks); |
| 3694 | } |
| 3695 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3696 | if (initializeScrollbars) { |
| 3697 | initializeScrollbars(a); |
| 3698 | } |
| 3699 | |
| 3700 | a.recycle(); |
| 3701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3702 | // Needs to be called after mViewFlags is set |
| 3703 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3704 | recomputePadding(); |
| 3705 | } |
| 3706 | |
| 3707 | if (x != 0 || y != 0) { |
| 3708 | scrollTo(x, y); |
| 3709 | } |
| 3710 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3711 | if (transformSet) { |
| 3712 | setTranslationX(tx); |
| 3713 | setTranslationY(ty); |
| 3714 | setRotation(rotation); |
| 3715 | setRotationX(rotationX); |
| 3716 | setRotationY(rotationY); |
| 3717 | setScaleX(sx); |
| 3718 | setScaleY(sy); |
| 3719 | } |
| 3720 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3721 | if (!setScrollContainer && (viewFlagValues&SCROLLBARS_VERTICAL) != 0) { |
| 3722 | setScrollContainer(true); |
| 3723 | } |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 3724 | |
| 3725 | computeOpaqueFlags(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | /** |
| 3729 | * Non-public constructor for use in testing |
| 3730 | */ |
| 3731 | View() { |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 3732 | mResources = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3733 | } |
| 3734 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3735 | public String toString() { |
| 3736 | StringBuilder out = new StringBuilder(128); |
| 3737 | out.append(getClass().getName()); |
| 3738 | out.append('{'); |
| 3739 | out.append(Integer.toHexString(System.identityHashCode(this))); |
| 3740 | out.append(' '); |
| 3741 | switch (mViewFlags&VISIBILITY_MASK) { |
| 3742 | case VISIBLE: out.append('V'); break; |
| 3743 | case INVISIBLE: out.append('I'); break; |
| 3744 | case GONE: out.append('G'); break; |
| 3745 | default: out.append('.'); break; |
| 3746 | } |
| 3747 | out.append((mViewFlags&FOCUSABLE_MASK) == FOCUSABLE ? 'F' : '.'); |
| 3748 | out.append((mViewFlags&ENABLED_MASK) == ENABLED ? 'E' : '.'); |
| 3749 | out.append((mViewFlags&DRAW_MASK) == WILL_NOT_DRAW ? '.' : 'D'); |
| 3750 | out.append((mViewFlags&SCROLLBARS_HORIZONTAL) != 0 ? 'H' : '.'); |
| 3751 | out.append((mViewFlags&SCROLLBARS_VERTICAL) != 0 ? 'V' : '.'); |
| 3752 | out.append((mViewFlags&CLICKABLE) != 0 ? 'C' : '.'); |
| 3753 | out.append((mViewFlags&LONG_CLICKABLE) != 0 ? 'L' : '.'); |
| 3754 | out.append(' '); |
| 3755 | out.append((mPrivateFlags&PFLAG_IS_ROOT_NAMESPACE) != 0 ? 'R' : '.'); |
| 3756 | out.append((mPrivateFlags&PFLAG_FOCUSED) != 0 ? 'F' : '.'); |
| 3757 | out.append((mPrivateFlags&PFLAG_SELECTED) != 0 ? 'S' : '.'); |
| 3758 | if ((mPrivateFlags&PFLAG_PREPRESSED) != 0) { |
| 3759 | out.append('p'); |
| 3760 | } else { |
| 3761 | out.append((mPrivateFlags&PFLAG_PRESSED) != 0 ? 'P' : '.'); |
| 3762 | } |
| 3763 | out.append((mPrivateFlags&PFLAG_HOVERED) != 0 ? 'H' : '.'); |
| 3764 | out.append((mPrivateFlags&PFLAG_ACTIVATED) != 0 ? 'A' : '.'); |
| 3765 | out.append((mPrivateFlags&PFLAG_INVALIDATED) != 0 ? 'I' : '.'); |
| 3766 | out.append((mPrivateFlags&PFLAG_DIRTY_MASK) != 0 ? 'D' : '.'); |
| 3767 | out.append(' '); |
| 3768 | out.append(mLeft); |
| 3769 | out.append(','); |
| 3770 | out.append(mTop); |
| 3771 | out.append('-'); |
| 3772 | out.append(mRight); |
| 3773 | out.append(','); |
| 3774 | out.append(mBottom); |
| 3775 | final int id = getId(); |
| 3776 | if (id != NO_ID) { |
| 3777 | out.append(" #"); |
| 3778 | out.append(Integer.toHexString(id)); |
| 3779 | final Resources r = mResources; |
| 3780 | if (id != 0 && r != null) { |
| 3781 | try { |
| 3782 | String pkgname; |
| 3783 | switch (id&0xff000000) { |
| 3784 | case 0x7f000000: |
| 3785 | pkgname="app"; |
| 3786 | break; |
| 3787 | case 0x01000000: |
| 3788 | pkgname="android"; |
| 3789 | break; |
| 3790 | default: |
| 3791 | pkgname = r.getResourcePackageName(id); |
| 3792 | break; |
| 3793 | } |
| 3794 | String typename = r.getResourceTypeName(id); |
| 3795 | String entryname = r.getResourceEntryName(id); |
| 3796 | out.append(" "); |
| 3797 | out.append(pkgname); |
| 3798 | out.append(":"); |
| 3799 | out.append(typename); |
| 3800 | out.append("/"); |
| 3801 | out.append(entryname); |
| 3802 | } catch (Resources.NotFoundException e) { |
| 3803 | } |
| 3804 | } |
| 3805 | } |
| 3806 | out.append("}"); |
| 3807 | return out.toString(); |
| 3808 | } |
| 3809 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | /** |
| 3811 | * <p> |
| 3812 | * Initializes the fading edges from a given set of styled attributes. This |
| 3813 | * method should be called by subclasses that need fading edges and when an |
| 3814 | * instance of these subclasses is created programmatically rather than |
| 3815 | * being inflated from XML. This method is automatically called when the XML |
| 3816 | * is inflated. |
| 3817 | * </p> |
| 3818 | * |
| 3819 | * @param a the styled attributes set to initialize the fading edges from |
| 3820 | */ |
| 3821 | protected void initializeFadingEdge(TypedArray a) { |
| 3822 | initScrollCache(); |
| 3823 | |
| 3824 | mScrollCache.fadingEdgeLength = a.getDimensionPixelSize( |
| 3825 | R.styleable.View_fadingEdgeLength, |
| 3826 | ViewConfiguration.get(mContext).getScaledFadingEdgeLength()); |
| 3827 | } |
| 3828 | |
| 3829 | /** |
| 3830 | * Returns the size of the vertical faded edges used to indicate that more |
| 3831 | * content in this view is visible. |
| 3832 | * |
| 3833 | * @return The size in pixels of the vertical faded edge or 0 if vertical |
| 3834 | * faded edges are not enabled for this view. |
| 3835 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3836 | */ |
| 3837 | public int getVerticalFadingEdgeLength() { |
| 3838 | if (isVerticalFadingEdgeEnabled()) { |
| 3839 | ScrollabilityCache cache = mScrollCache; |
| 3840 | if (cache != null) { |
| 3841 | return cache.fadingEdgeLength; |
| 3842 | } |
| 3843 | } |
| 3844 | return 0; |
| 3845 | } |
| 3846 | |
| 3847 | /** |
| 3848 | * Set the size of the faded edge used to indicate that more content in this |
| 3849 | * 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] | 3850 | * {@link #setVerticalFadingEdgeEnabled(boolean)} or |
| 3851 | * {@link #setHorizontalFadingEdgeEnabled(boolean)} to enable the fading edge |
| 3852 | * for the vertical or horizontal fading edges. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3853 | * |
| 3854 | * @param length The size in pixels of the faded edge used to indicate that more |
| 3855 | * content in this view is visible. |
| 3856 | */ |
| 3857 | public void setFadingEdgeLength(int length) { |
| 3858 | initScrollCache(); |
| 3859 | mScrollCache.fadingEdgeLength = length; |
| 3860 | } |
| 3861 | |
| 3862 | /** |
| 3863 | * Returns the size of the horizontal faded edges used to indicate that more |
| 3864 | * content in this view is visible. |
| 3865 | * |
| 3866 | * @return The size in pixels of the horizontal faded edge or 0 if horizontal |
| 3867 | * faded edges are not enabled for this view. |
| 3868 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3869 | */ |
| 3870 | public int getHorizontalFadingEdgeLength() { |
| 3871 | if (isHorizontalFadingEdgeEnabled()) { |
| 3872 | ScrollabilityCache cache = mScrollCache; |
| 3873 | if (cache != null) { |
| 3874 | return cache.fadingEdgeLength; |
| 3875 | } |
| 3876 | } |
| 3877 | return 0; |
| 3878 | } |
| 3879 | |
| 3880 | /** |
| 3881 | * Returns the width of the vertical scrollbar. |
| 3882 | * |
| 3883 | * @return The width in pixels of the vertical scrollbar or 0 if there |
| 3884 | * is no vertical scrollbar. |
| 3885 | */ |
| 3886 | public int getVerticalScrollbarWidth() { |
| 3887 | ScrollabilityCache cache = mScrollCache; |
| 3888 | if (cache != null) { |
| 3889 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3890 | if (scrollBar != null) { |
| 3891 | int size = scrollBar.getSize(true); |
| 3892 | if (size <= 0) { |
| 3893 | size = cache.scrollBarSize; |
| 3894 | } |
| 3895 | return size; |
| 3896 | } |
| 3897 | return 0; |
| 3898 | } |
| 3899 | return 0; |
| 3900 | } |
| 3901 | |
| 3902 | /** |
| 3903 | * Returns the height of the horizontal scrollbar. |
| 3904 | * |
| 3905 | * @return The height in pixels of the horizontal scrollbar or 0 if |
| 3906 | * there is no horizontal scrollbar. |
| 3907 | */ |
| 3908 | protected int getHorizontalScrollbarHeight() { |
| 3909 | ScrollabilityCache cache = mScrollCache; |
| 3910 | if (cache != null) { |
| 3911 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3912 | if (scrollBar != null) { |
| 3913 | int size = scrollBar.getSize(false); |
| 3914 | if (size <= 0) { |
| 3915 | size = cache.scrollBarSize; |
| 3916 | } |
| 3917 | return size; |
| 3918 | } |
| 3919 | return 0; |
| 3920 | } |
| 3921 | return 0; |
| 3922 | } |
| 3923 | |
| 3924 | /** |
| 3925 | * <p> |
| 3926 | * Initializes the scrollbars from a given set of styled attributes. This |
| 3927 | * method should be called by subclasses that need scrollbars and when an |
| 3928 | * instance of these subclasses is created programmatically rather than |
| 3929 | * being inflated from XML. This method is automatically called when the XML |
| 3930 | * is inflated. |
| 3931 | * </p> |
| 3932 | * |
| 3933 | * @param a the styled attributes set to initialize the scrollbars from |
| 3934 | */ |
| 3935 | protected void initializeScrollbars(TypedArray a) { |
| 3936 | initScrollCache(); |
| 3937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3938 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3939 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3940 | if (scrollabilityCache.scrollBar == null) { |
| 3941 | scrollabilityCache.scrollBar = new ScrollBarDrawable(); |
| 3942 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3943 | |
Romain Guy | 8bda248 | 2010-03-02 11:42:11 -0800 | [diff] [blame] | 3944 | 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] | 3945 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3946 | if (!fadeScrollbars) { |
| 3947 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 3948 | } |
| 3949 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3950 | |
| 3951 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3952 | scrollabilityCache.scrollBarFadeDuration = a.getInt( |
| 3953 | R.styleable.View_scrollbarFadeDuration, ViewConfiguration |
| 3954 | .getScrollBarFadeDuration()); |
| 3955 | scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt( |
| 3956 | R.styleable.View_scrollbarDefaultDelayBeforeFade, |
| 3957 | ViewConfiguration.getScrollDefaultDelay()); |
| 3958 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3959 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3960 | scrollabilityCache.scrollBarSize = a.getDimensionPixelSize( |
| 3961 | com.android.internal.R.styleable.View_scrollbarSize, |
| 3962 | ViewConfiguration.get(mContext).getScaledScrollBarSize()); |
| 3963 | |
| 3964 | Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal); |
| 3965 | scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track); |
| 3966 | |
| 3967 | Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal); |
| 3968 | if (thumb != null) { |
| 3969 | scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb); |
| 3970 | } |
| 3971 | |
| 3972 | boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack, |
| 3973 | false); |
| 3974 | if (alwaysDraw) { |
| 3975 | scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true); |
| 3976 | } |
| 3977 | |
| 3978 | track = a.getDrawable(R.styleable.View_scrollbarTrackVertical); |
| 3979 | scrollabilityCache.scrollBar.setVerticalTrackDrawable(track); |
| 3980 | |
| 3981 | thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical); |
| 3982 | if (thumb != null) { |
| 3983 | scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb); |
| 3984 | } |
| 3985 | |
| 3986 | alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack, |
| 3987 | false); |
| 3988 | if (alwaysDraw) { |
| 3989 | scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true); |
| 3990 | } |
| 3991 | |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 3992 | // Apply layout direction to the new Drawables if needed |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 3993 | final int layoutDirection = getLayoutDirection(); |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 3994 | if (track != null) { |
| 3995 | track.setLayoutDirection(layoutDirection); |
| 3996 | } |
| 3997 | if (thumb != null) { |
| 3998 | thumb.setLayoutDirection(layoutDirection); |
| 3999 | } |
| 4000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4001 | // Re-apply user/background padding so that scrollbar(s) get added |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 4002 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | /** |
| 4006 | * <p> |
| 4007 | * Initalizes the scrollability cache if necessary. |
| 4008 | * </p> |
| 4009 | */ |
| 4010 | private void initScrollCache() { |
| 4011 | if (mScrollCache == null) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 4012 | mScrollCache = new ScrollabilityCache(ViewConfiguration.get(mContext), this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4013 | } |
| 4014 | } |
| 4015 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 4016 | private ScrollabilityCache getScrollCache() { |
| 4017 | initScrollCache(); |
| 4018 | return mScrollCache; |
| 4019 | } |
| 4020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4021 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 4022 | * Set the position of the vertical scroll bar. Should be one of |
| 4023 | * {@link #SCROLLBAR_POSITION_DEFAULT}, {@link #SCROLLBAR_POSITION_LEFT} or |
| 4024 | * {@link #SCROLLBAR_POSITION_RIGHT}. |
| 4025 | * |
| 4026 | * @param position Where the vertical scroll bar should be positioned. |
| 4027 | */ |
| 4028 | public void setVerticalScrollbarPosition(int position) { |
| 4029 | if (mVerticalScrollbarPosition != position) { |
| 4030 | mVerticalScrollbarPosition = position; |
| 4031 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 4032 | resolvePadding(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 4033 | } |
| 4034 | } |
| 4035 | |
| 4036 | /** |
| 4037 | * @return The position where the vertical scroll bar will show, if applicable. |
| 4038 | * @see #setVerticalScrollbarPosition(int) |
| 4039 | */ |
| 4040 | public int getVerticalScrollbarPosition() { |
| 4041 | return mVerticalScrollbarPosition; |
| 4042 | } |
| 4043 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4044 | ListenerInfo getListenerInfo() { |
| 4045 | if (mListenerInfo != null) { |
| 4046 | return mListenerInfo; |
| 4047 | } |
| 4048 | mListenerInfo = new ListenerInfo(); |
| 4049 | return mListenerInfo; |
| 4050 | } |
| 4051 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 4052 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4053 | * Register a callback to be invoked when focus of this view changed. |
| 4054 | * |
| 4055 | * @param l The callback that will run. |
| 4056 | */ |
| 4057 | public void setOnFocusChangeListener(OnFocusChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4058 | getListenerInfo().mOnFocusChangeListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4062 | * Add a listener that will be called when the bounds of the view change due to |
| 4063 | * layout processing. |
| 4064 | * |
| 4065 | * @param listener The listener that will be called when layout bounds change. |
| 4066 | */ |
| 4067 | public void addOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4068 | ListenerInfo li = getListenerInfo(); |
| 4069 | if (li.mOnLayoutChangeListeners == null) { |
| 4070 | li.mOnLayoutChangeListeners = new ArrayList<OnLayoutChangeListener>(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4071 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4072 | if (!li.mOnLayoutChangeListeners.contains(listener)) { |
| 4073 | li.mOnLayoutChangeListeners.add(listener); |
Chet Haase | 1a76dcd | 2011-10-06 11:16:40 -0700 | [diff] [blame] | 4074 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | /** |
| 4078 | * Remove a listener for layout changes. |
| 4079 | * |
| 4080 | * @param listener The listener for layout bounds change. |
| 4081 | */ |
| 4082 | public void removeOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4083 | ListenerInfo li = mListenerInfo; |
| 4084 | if (li == null || li.mOnLayoutChangeListeners == null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4085 | return; |
| 4086 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4087 | li.mOnLayoutChangeListeners.remove(listener); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | /** |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4091 | * Add a listener for attach state changes. |
| 4092 | * |
| 4093 | * This listener will be called whenever this view is attached or detached |
| 4094 | * from a window. Remove the listener using |
| 4095 | * {@link #removeOnAttachStateChangeListener(OnAttachStateChangeListener)}. |
| 4096 | * |
| 4097 | * @param listener Listener to attach |
| 4098 | * @see #removeOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 4099 | */ |
| 4100 | public void addOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4101 | ListenerInfo li = getListenerInfo(); |
| 4102 | if (li.mOnAttachStateChangeListeners == null) { |
| 4103 | li.mOnAttachStateChangeListeners |
| 4104 | = new CopyOnWriteArrayList<OnAttachStateChangeListener>(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4105 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4106 | li.mOnAttachStateChangeListeners.add(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4107 | } |
| 4108 | |
| 4109 | /** |
| 4110 | * Remove a listener for attach state changes. The listener will receive no further |
| 4111 | * notification of window attach/detach events. |
| 4112 | * |
| 4113 | * @param listener Listener to remove |
| 4114 | * @see #addOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 4115 | */ |
| 4116 | public void removeOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4117 | ListenerInfo li = mListenerInfo; |
| 4118 | if (li == null || li.mOnAttachStateChangeListeners == null) { |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4119 | return; |
| 4120 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4121 | li.mOnAttachStateChangeListeners.remove(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4122 | } |
| 4123 | |
| 4124 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4125 | * Returns the focus-change callback registered for this view. |
| 4126 | * |
| 4127 | * @return The callback, or null if one is not registered. |
| 4128 | */ |
| 4129 | public OnFocusChangeListener getOnFocusChangeListener() { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4130 | ListenerInfo li = mListenerInfo; |
| 4131 | return li != null ? li.mOnFocusChangeListener : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4132 | } |
| 4133 | |
| 4134 | /** |
| 4135 | * Register a callback to be invoked when this view is clicked. If this view is not |
| 4136 | * clickable, it becomes clickable. |
| 4137 | * |
| 4138 | * @param l The callback that will run |
| 4139 | * |
| 4140 | * @see #setClickable(boolean) |
| 4141 | */ |
| 4142 | public void setOnClickListener(OnClickListener l) { |
| 4143 | if (!isClickable()) { |
| 4144 | setClickable(true); |
| 4145 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4146 | getListenerInfo().mOnClickListener = l; |
| 4147 | } |
| 4148 | |
| 4149 | /** |
| 4150 | * Return whether this view has an attached OnClickListener. Returns |
| 4151 | * true if there is a listener, false if there is none. |
| 4152 | */ |
| 4153 | public boolean hasOnClickListeners() { |
| 4154 | ListenerInfo li = mListenerInfo; |
| 4155 | return (li != null && li.mOnClickListener != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | /** |
| 4159 | * Register a callback to be invoked when this view is clicked and held. If this view is not |
| 4160 | * long clickable, it becomes long clickable. |
| 4161 | * |
| 4162 | * @param l The callback that will run |
| 4163 | * |
| 4164 | * @see #setLongClickable(boolean) |
| 4165 | */ |
| 4166 | public void setOnLongClickListener(OnLongClickListener l) { |
| 4167 | if (!isLongClickable()) { |
| 4168 | setLongClickable(true); |
| 4169 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4170 | getListenerInfo().mOnLongClickListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4171 | } |
| 4172 | |
| 4173 | /** |
| 4174 | * Register a callback to be invoked when the context menu for this view is |
| 4175 | * being built. If this view is not long clickable, it becomes long clickable. |
| 4176 | * |
| 4177 | * @param l The callback that will run |
| 4178 | * |
| 4179 | */ |
| 4180 | public void setOnCreateContextMenuListener(OnCreateContextMenuListener l) { |
| 4181 | if (!isLongClickable()) { |
| 4182 | setLongClickable(true); |
| 4183 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4184 | getListenerInfo().mOnCreateContextMenuListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | } |
| 4186 | |
| 4187 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4188 | * Call this view's OnClickListener, if it is defined. Performs all normal |
| 4189 | * actions associated with clicking: reporting accessibility event, playing |
| 4190 | * a sound, etc. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4191 | * |
| 4192 | * @return True there was an assigned OnClickListener that was called, false |
| 4193 | * otherwise is returned. |
| 4194 | */ |
| 4195 | public boolean performClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4196 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); |
| 4197 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4198 | ListenerInfo li = mListenerInfo; |
| 4199 | if (li != null && li.mOnClickListener != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4200 | playSoundEffect(SoundEffectConstants.CLICK); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4201 | li.mOnClickListener.onClick(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4202 | return true; |
| 4203 | } |
| 4204 | |
| 4205 | return false; |
| 4206 | } |
| 4207 | |
| 4208 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4209 | * Directly call any attached OnClickListener. Unlike {@link #performClick()}, |
| 4210 | * this only calls the listener, and does not do any associated clicking |
| 4211 | * actions like reporting an accessibility event. |
| 4212 | * |
| 4213 | * @return True there was an assigned OnClickListener that was called, false |
| 4214 | * otherwise is returned. |
| 4215 | */ |
| 4216 | public boolean callOnClick() { |
| 4217 | ListenerInfo li = mListenerInfo; |
| 4218 | if (li != null && li.mOnClickListener != null) { |
| 4219 | li.mOnClickListener.onClick(this); |
| 4220 | return true; |
| 4221 | } |
| 4222 | return false; |
| 4223 | } |
| 4224 | |
| 4225 | /** |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 4226 | * Call this view's OnLongClickListener, if it is defined. Invokes the context menu if the |
| 4227 | * OnLongClickListener did not consume the event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4228 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 4229 | * @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] | 4230 | */ |
| 4231 | public boolean performLongClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4232 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 4233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4234 | boolean handled = false; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4235 | ListenerInfo li = mListenerInfo; |
| 4236 | if (li != null && li.mOnLongClickListener != null) { |
| 4237 | handled = li.mOnLongClickListener.onLongClick(View.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4238 | } |
| 4239 | if (!handled) { |
| 4240 | handled = showContextMenu(); |
| 4241 | } |
| 4242 | if (handled) { |
| 4243 | performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); |
| 4244 | } |
| 4245 | return handled; |
| 4246 | } |
| 4247 | |
| 4248 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4249 | * Performs button-related actions during a touch down event. |
| 4250 | * |
| 4251 | * @param event The event. |
| 4252 | * @return True if the down was consumed. |
| 4253 | * |
| 4254 | * @hide |
| 4255 | */ |
| 4256 | protected boolean performButtonActionOnTouchDown(MotionEvent event) { |
| 4257 | if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) { |
| 4258 | if (showContextMenu(event.getX(), event.getY(), event.getMetaState())) { |
| 4259 | return true; |
| 4260 | } |
| 4261 | } |
| 4262 | return false; |
| 4263 | } |
| 4264 | |
| 4265 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4266 | * Bring up the context menu for this view. |
| 4267 | * |
| 4268 | * @return Whether a context menu was displayed. |
| 4269 | */ |
| 4270 | public boolean showContextMenu() { |
| 4271 | return getParent().showContextMenuForChild(this); |
| 4272 | } |
| 4273 | |
| 4274 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4275 | * Bring up the context menu for this view, referring to the item under the specified point. |
| 4276 | * |
| 4277 | * @param x The referenced x coordinate. |
| 4278 | * @param y The referenced y coordinate. |
| 4279 | * @param metaState The keyboard modifiers that were pressed. |
| 4280 | * @return Whether a context menu was displayed. |
| 4281 | * |
| 4282 | * @hide |
| 4283 | */ |
| 4284 | public boolean showContextMenu(float x, float y, int metaState) { |
| 4285 | return showContextMenu(); |
| 4286 | } |
| 4287 | |
| 4288 | /** |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 4289 | * Start an action mode. |
| 4290 | * |
| 4291 | * @param callback Callback that will control the lifecycle of the action mode |
| 4292 | * @return The new action mode if it is started, null otherwise |
| 4293 | * |
| 4294 | * @see ActionMode |
| 4295 | */ |
| 4296 | public ActionMode startActionMode(ActionMode.Callback callback) { |
John Reck | 5160e2a | 2012-02-22 09:35:12 -0800 | [diff] [blame] | 4297 | ViewParent parent = getParent(); |
| 4298 | if (parent == null) return null; |
| 4299 | return parent.startActionModeForChild(this, callback); |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 4300 | } |
| 4301 | |
| 4302 | /** |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 4303 | * Register a callback to be invoked when a hardware key is pressed in this view. |
| 4304 | * Key presses in software input methods will generally not trigger the methods of |
| 4305 | * this listener. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4306 | * @param l the key listener to attach to this view |
| 4307 | */ |
| 4308 | public void setOnKeyListener(OnKeyListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4309 | getListenerInfo().mOnKeyListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4310 | } |
| 4311 | |
| 4312 | /** |
| 4313 | * Register a callback to be invoked when a touch event is sent to this view. |
| 4314 | * @param l the touch listener to attach to this view |
| 4315 | */ |
| 4316 | public void setOnTouchListener(OnTouchListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4317 | getListenerInfo().mOnTouchListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 4321 | * Register a callback to be invoked when a generic motion event is sent to this view. |
| 4322 | * @param l the generic motion listener to attach to this view |
| 4323 | */ |
| 4324 | public void setOnGenericMotionListener(OnGenericMotionListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4325 | getListenerInfo().mOnGenericMotionListener = l; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | /** |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 4329 | * Register a callback to be invoked when a hover event is sent to this view. |
| 4330 | * @param l the hover listener to attach to this view |
| 4331 | */ |
| 4332 | public void setOnHoverListener(OnHoverListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4333 | getListenerInfo().mOnHoverListener = l; |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 4334 | } |
| 4335 | |
| 4336 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 4337 | * Register a drag event listener callback object for this View. The parameter is |
| 4338 | * an implementation of {@link android.view.View.OnDragListener}. To send a drag event to a |
| 4339 | * View, the system calls the |
| 4340 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent)} method. |
| 4341 | * @param l An implementation of {@link android.view.View.OnDragListener}. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 4342 | */ |
| 4343 | public void setOnDragListener(OnDragListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4344 | getListenerInfo().mOnDragListener = l; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 4348 | * Give this view focus. This will cause |
| 4349 | * {@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] | 4350 | * |
| 4351 | * Note: this does not check whether this {@link View} should get focus, it just |
| 4352 | * gives it focus no matter what. It should only be called internally by framework |
| 4353 | * code that knows what it is doing, namely {@link #requestFocus(int, Rect)}. |
| 4354 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 4355 | * @param direction values are {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN}, |
| 4356 | * {@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] | 4357 | * focus moved when requestFocus() is called. It may not always |
| 4358 | * apply, in which case use the default View.FOCUS_DOWN. |
| 4359 | * @param previouslyFocusedRect The rectangle of the view that had focus |
| 4360 | * prior in this View's coordinate system. |
| 4361 | */ |
| 4362 | void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) { |
| 4363 | if (DBG) { |
| 4364 | System.out.println(this + " requestFocus()"); |
| 4365 | } |
| 4366 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4367 | if ((mPrivateFlags & PFLAG_FOCUSED) == 0) { |
| 4368 | mPrivateFlags |= PFLAG_FOCUSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4369 | |
| 4370 | if (mParent != null) { |
| 4371 | mParent.requestChildFocus(this, this); |
| 4372 | } |
| 4373 | |
| 4374 | onFocusChanged(true, direction, previouslyFocusedRect); |
| 4375 | refreshDrawableState(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4376 | |
| 4377 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4378 | notifyAccessibilityStateChanged(); |
| 4379 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4380 | } |
| 4381 | } |
| 4382 | |
| 4383 | /** |
| 4384 | * Request that a rectangle of this view be visible on the screen, |
| 4385 | * scrolling if necessary just enough. |
| 4386 | * |
| 4387 | * <p>A View should call this if it maintains some notion of which part |
| 4388 | * of its content is interesting. For example, a text editing view |
| 4389 | * should call this when its cursor moves. |
| 4390 | * |
| 4391 | * @param rectangle The rectangle. |
| 4392 | * @return Whether any parent scrolled. |
| 4393 | */ |
| 4394 | public boolean requestRectangleOnScreen(Rect rectangle) { |
| 4395 | return requestRectangleOnScreen(rectangle, false); |
| 4396 | } |
| 4397 | |
| 4398 | /** |
| 4399 | * Request that a rectangle of this view be visible on the screen, |
| 4400 | * scrolling if necessary just enough. |
| 4401 | * |
| 4402 | * <p>A View should call this if it maintains some notion of which part |
| 4403 | * of its content is interesting. For example, a text editing view |
| 4404 | * should call this when its cursor moves. |
| 4405 | * |
| 4406 | * <p>When <code>immediate</code> is set to true, scrolling will not be |
| 4407 | * animated. |
| 4408 | * |
| 4409 | * @param rectangle The rectangle. |
| 4410 | * @param immediate True to forbid animated scrolling, false otherwise |
| 4411 | * @return Whether any parent scrolled. |
| 4412 | */ |
| 4413 | public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) { |
Svetoslav Ganov | 989ae75 | 2012-09-25 15:16:48 -0700 | [diff] [blame] | 4414 | if (mParent == null) { |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4415 | return false; |
| 4416 | } |
| 4417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4418 | View child = this; |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4419 | |
Svetoslav Ganov | 989ae75 | 2012-09-25 15:16:48 -0700 | [diff] [blame] | 4420 | RectF position = (mAttachInfo != null) ? mAttachInfo.mTmpTransformRect : new RectF(); |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4421 | position.set(rectangle); |
| 4422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4423 | ViewParent parent = mParent; |
| 4424 | boolean scrolled = false; |
| 4425 | while (parent != null) { |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4426 | rectangle.set((int) position.left, (int) position.top, |
| 4427 | (int) position.right, (int) position.bottom); |
| 4428 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4429 | scrolled |= parent.requestChildRectangleOnScreen(child, |
| 4430 | rectangle, immediate); |
| 4431 | |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4432 | if (!child.hasIdentityMatrix()) { |
| 4433 | child.getMatrix().mapRect(position); |
| 4434 | } |
| 4435 | |
| 4436 | position.offset(child.mLeft, child.mTop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4437 | |
| 4438 | if (!(parent instanceof View)) { |
| 4439 | break; |
| 4440 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4441 | |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4442 | View parentView = (View) parent; |
| 4443 | |
| 4444 | position.offset(-parentView.getScrollX(), -parentView.getScrollY()); |
| 4445 | |
| 4446 | child = parentView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4447 | parent = child.getParent(); |
| 4448 | } |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4449 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4450 | return scrolled; |
| 4451 | } |
| 4452 | |
| 4453 | /** |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 4454 | * Called when this view wants to give up focus. If focus is cleared |
| 4455 | * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} is called. |
| 4456 | * <p> |
| 4457 | * <strong>Note:</strong> When a View clears focus the framework is trying |
| 4458 | * to give focus to the first focusable View from the top. Hence, if this |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame] | 4459 | * View is the first from the top that can take focus, then all callbacks |
| 4460 | * related to clearing focus will be invoked after wich the framework will |
| 4461 | * give focus to this view. |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 4462 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4463 | */ |
| 4464 | public void clearFocus() { |
| 4465 | if (DBG) { |
| 4466 | System.out.println(this + " clearFocus()"); |
| 4467 | } |
| 4468 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4469 | if ((mPrivateFlags & PFLAG_FOCUSED) != 0) { |
| 4470 | mPrivateFlags &= ~PFLAG_FOCUSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4471 | |
| 4472 | if (mParent != null) { |
| 4473 | mParent.clearChildFocus(this); |
| 4474 | } |
| 4475 | |
| 4476 | onFocusChanged(false, 0, null); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4478 | refreshDrawableState(); |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame] | 4479 | |
| 4480 | ensureInputFocusOnFirstFocusable(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4481 | |
| 4482 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4483 | notifyAccessibilityStateChanged(); |
| 4484 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4485 | } |
| 4486 | } |
| 4487 | |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame] | 4488 | void ensureInputFocusOnFirstFocusable() { |
| 4489 | View root = getRootView(); |
| 4490 | if (root != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4491 | root.requestFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4492 | } |
| 4493 | } |
| 4494 | |
| 4495 | /** |
| 4496 | * Called internally by the view system when a new view is getting focus. |
| 4497 | * This is what clears the old focus. |
| 4498 | */ |
| 4499 | void unFocus() { |
| 4500 | if (DBG) { |
| 4501 | System.out.println(this + " unFocus()"); |
| 4502 | } |
| 4503 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4504 | if ((mPrivateFlags & PFLAG_FOCUSED) != 0) { |
| 4505 | mPrivateFlags &= ~PFLAG_FOCUSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4506 | |
| 4507 | onFocusChanged(false, 0, null); |
| 4508 | refreshDrawableState(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4509 | |
| 4510 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4511 | notifyAccessibilityStateChanged(); |
| 4512 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4513 | } |
| 4514 | } |
| 4515 | |
| 4516 | /** |
| 4517 | * Returns true if this view has focus iteself, or is the ancestor of the |
| 4518 | * view that has focus. |
| 4519 | * |
| 4520 | * @return True if this view has or contains focus, false otherwise. |
| 4521 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4522 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4523 | public boolean hasFocus() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4524 | return (mPrivateFlags & PFLAG_FOCUSED) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4525 | } |
| 4526 | |
| 4527 | /** |
| 4528 | * Returns true if this view is focusable or if it contains a reachable View |
| 4529 | * for which {@link #hasFocusable()} returns true. A "reachable hasFocusable()" |
| 4530 | * is a View whose parents do not block descendants focus. |
| 4531 | * |
| 4532 | * Only {@link #VISIBLE} views are considered focusable. |
| 4533 | * |
| 4534 | * @return True if the view is focusable or if the view contains a focusable |
| 4535 | * View, false otherwise. |
| 4536 | * |
| 4537 | * @see ViewGroup#FOCUS_BLOCK_DESCENDANTS |
| 4538 | */ |
| 4539 | public boolean hasFocusable() { |
| 4540 | return (mViewFlags & VISIBILITY_MASK) == VISIBLE && isFocusable(); |
| 4541 | } |
| 4542 | |
| 4543 | /** |
| 4544 | * Called by the view system when the focus state of this view changes. |
| 4545 | * When the focus change event is caused by directional navigation, direction |
| 4546 | * and previouslyFocusedRect provide insight into where the focus is coming from. |
| 4547 | * When overriding, be sure to call up through to the super class so that |
| 4548 | * the standard focus handling will occur. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4549 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4550 | * @param gainFocus True if the View has focus; false otherwise. |
| 4551 | * @param direction The direction focus has moved when requestFocus() |
| 4552 | * is called to give this view focus. Values are |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4553 | * {@link #FOCUS_UP}, {@link #FOCUS_DOWN}, {@link #FOCUS_LEFT}, |
| 4554 | * {@link #FOCUS_RIGHT}, {@link #FOCUS_FORWARD}, or {@link #FOCUS_BACKWARD}. |
| 4555 | * 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] | 4556 | * @param previouslyFocusedRect The rectangle, in this view's coordinate |
| 4557 | * system, of the previously focused view. If applicable, this will be |
| 4558 | * passed in as finer grained information about where the focus is coming |
| 4559 | * from (in addition to direction). Will be <code>null</code> otherwise. |
| 4560 | */ |
| 4561 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4562 | if (gainFocus) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4563 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4564 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4565 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4566 | } |
| 4567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4568 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4569 | if (!gainFocus) { |
| 4570 | if (isPressed()) { |
| 4571 | setPressed(false); |
| 4572 | } |
| 4573 | if (imm != null && mAttachInfo != null |
| 4574 | && mAttachInfo.mHasWindowFocus) { |
| 4575 | imm.focusOut(this); |
| 4576 | } |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4577 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4578 | } else if (imm != null && mAttachInfo != null |
| 4579 | && mAttachInfo.mHasWindowFocus) { |
| 4580 | imm.focusIn(this); |
| 4581 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4582 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 4583 | invalidate(true); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4584 | ListenerInfo li = mListenerInfo; |
| 4585 | if (li != null && li.mOnFocusChangeListener != null) { |
| 4586 | li.mOnFocusChangeListener.onFocusChange(this, gainFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4587 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 4588 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 4589 | if (mAttachInfo != null) { |
| 4590 | mAttachInfo.mKeyDispatchState.reset(this); |
| 4591 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4592 | } |
| 4593 | |
| 4594 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 4595 | * Sends an accessibility event of the given type. If accessibility is |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4596 | * not enabled this method has no effect. The default implementation calls |
| 4597 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first |
| 4598 | * to populate information about the event source (this View), then calls |
| 4599 | * {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} to |
| 4600 | * populate the text content of the event source including its descendants, |
| 4601 | * and last calls |
| 4602 | * {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)} |
| 4603 | * on its parent to resuest sending of the event to interested parties. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4604 | * <p> |
| 4605 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4606 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4607 | * {@link AccessibilityDelegate#sendAccessibilityEvent(View, int)} is |
| 4608 | * responsible for handling this call. |
| 4609 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4610 | * |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4611 | * @param eventType The type of the event to send, as defined by several types from |
| 4612 | * {@link android.view.accessibility.AccessibilityEvent}, such as |
| 4613 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED} or |
| 4614 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4615 | * |
| 4616 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4617 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4618 | * @see ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent) |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4619 | * @see AccessibilityDelegate |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4620 | */ |
| 4621 | public void sendAccessibilityEvent(int eventType) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4622 | if (mAccessibilityDelegate != null) { |
| 4623 | mAccessibilityDelegate.sendAccessibilityEvent(this, eventType); |
| 4624 | } else { |
| 4625 | sendAccessibilityEventInternal(eventType); |
| 4626 | } |
| 4627 | } |
| 4628 | |
| 4629 | /** |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4630 | * Convenience method for sending a {@link AccessibilityEvent#TYPE_ANNOUNCEMENT} |
| 4631 | * {@link AccessibilityEvent} to make an announcement which is related to some |
| 4632 | * sort of a context change for which none of the events representing UI transitions |
| 4633 | * is a good fit. For example, announcing a new page in a book. If accessibility |
| 4634 | * is not enabled this method does nothing. |
| 4635 | * |
| 4636 | * @param text The announcement text. |
| 4637 | */ |
| 4638 | public void announceForAccessibility(CharSequence text) { |
Svetoslav Ganov | 7a82b2b | 2012-07-02 18:33:23 -0700 | [diff] [blame] | 4639 | if (AccessibilityManager.getInstance(mContext).isEnabled() && mParent != null) { |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4640 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 4641 | AccessibilityEvent.TYPE_ANNOUNCEMENT); |
Svetoslav Ganov | 7a82b2b | 2012-07-02 18:33:23 -0700 | [diff] [blame] | 4642 | onInitializeAccessibilityEvent(event); |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4643 | event.getText().add(text); |
Svetoslav Ganov | 7a82b2b | 2012-07-02 18:33:23 -0700 | [diff] [blame] | 4644 | event.setContentDescription(null); |
| 4645 | mParent.requestSendAccessibilityEvent(this, event); |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4646 | } |
| 4647 | } |
| 4648 | |
| 4649 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4650 | * @see #sendAccessibilityEvent(int) |
| 4651 | * |
| 4652 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4653 | */ |
| 4654 | void sendAccessibilityEventInternal(int eventType) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4655 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4656 | sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType)); |
| 4657 | } |
| 4658 | } |
| 4659 | |
| 4660 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4661 | * This method behaves exactly as {@link #sendAccessibilityEvent(int)} but |
| 4662 | * takes as an argument an empty {@link AccessibilityEvent} and does not |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4663 | * perform a check whether accessibility is enabled. |
| 4664 | * <p> |
| 4665 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4666 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4667 | * {@link AccessibilityDelegate#sendAccessibilityEventUnchecked(View, AccessibilityEvent)} |
| 4668 | * is responsible for handling this call. |
| 4669 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4670 | * |
| 4671 | * @param event The event to send. |
| 4672 | * |
| 4673 | * @see #sendAccessibilityEvent(int) |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4674 | */ |
| 4675 | public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4676 | if (mAccessibilityDelegate != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4677 | mAccessibilityDelegate.sendAccessibilityEventUnchecked(this, event); |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4678 | } else { |
| 4679 | sendAccessibilityEventUncheckedInternal(event); |
| 4680 | } |
| 4681 | } |
| 4682 | |
| 4683 | /** |
| 4684 | * @see #sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 4685 | * |
| 4686 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4687 | */ |
| 4688 | void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 9cd1eca | 2011-01-13 14:24:02 -0800 | [diff] [blame] | 4689 | if (!isShown()) { |
| 4690 | return; |
| 4691 | } |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4692 | onInitializeAccessibilityEvent(event); |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4693 | // Only a subset of accessibility events populates text content. |
| 4694 | if ((event.getEventType() & POPULATING_ACCESSIBILITY_EVENT_TYPES) != 0) { |
| 4695 | dispatchPopulateAccessibilityEvent(event); |
| 4696 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4697 | // In the beginning we called #isShown(), so we know that getParent() is not null. |
| 4698 | getParent().requestSendAccessibilityEvent(this, event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4699 | } |
| 4700 | |
| 4701 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4702 | * Dispatches an {@link AccessibilityEvent} to the {@link View} first and then |
| 4703 | * to its children for adding their text content to the event. Note that the |
| 4704 | * event text is populated in a separate dispatch path since we add to the |
| 4705 | * 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] | 4706 | * A typical implementation will call |
| 4707 | * {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} on the this view |
| 4708 | * and then call the {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
| 4709 | * on each child. Override this method if custom population of the event text |
| 4710 | * content is required. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4711 | * <p> |
| 4712 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4713 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4714 | * {@link AccessibilityDelegate#dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4715 | * is responsible for handling this call. |
| 4716 | * </p> |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4717 | * <p> |
| 4718 | * <em>Note:</em> Accessibility events of certain types are not dispatched for |
| 4719 | * populating the event text via this method. For details refer to {@link AccessibilityEvent}. |
| 4720 | * </p> |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4721 | * |
| 4722 | * @param event The event. |
| 4723 | * |
| 4724 | * @return True if the event population was completed. |
| 4725 | */ |
| 4726 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4727 | if (mAccessibilityDelegate != null) { |
| 4728 | return mAccessibilityDelegate.dispatchPopulateAccessibilityEvent(this, event); |
| 4729 | } else { |
| 4730 | return dispatchPopulateAccessibilityEventInternal(event); |
| 4731 | } |
| 4732 | } |
| 4733 | |
| 4734 | /** |
| 4735 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4736 | * |
| 4737 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4738 | */ |
| 4739 | boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4740 | onPopulateAccessibilityEvent(event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4741 | return false; |
| 4742 | } |
| 4743 | |
| 4744 | /** |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4745 | * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4746 | * 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] | 4747 | * text content. While this method is free to modify event |
| 4748 | * attributes other than text content, doing so should normally be performed in |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4749 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}. |
| 4750 | * <p> |
| 4751 | * Example: Adding formatted date string to an accessibility event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4752 | * to the text added by the super implementation: |
| 4753 | * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4754 | * super.onPopulateAccessibilityEvent(event); |
| 4755 | * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; |
| 4756 | * String selectedDateUtterance = DateUtils.formatDateTime(mContext, |
| 4757 | * mCurrentDate.getTimeInMillis(), flags); |
| 4758 | * event.getText().add(selectedDateUtterance); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4759 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4760 | * <p> |
| 4761 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4762 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4763 | * {@link AccessibilityDelegate#onPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4764 | * is responsible for handling this call. |
| 4765 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4766 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4767 | * information to the event, in case the default implementation has basic information to add. |
| 4768 | * </p> |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4769 | * |
| 4770 | * @param event The accessibility event which to populate. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4771 | * |
| 4772 | * @see #sendAccessibilityEvent(int) |
| 4773 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4774 | */ |
| 4775 | public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4776 | if (mAccessibilityDelegate != null) { |
| 4777 | mAccessibilityDelegate.onPopulateAccessibilityEvent(this, event); |
| 4778 | } else { |
| 4779 | onPopulateAccessibilityEventInternal(event); |
| 4780 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4784 | * @see #onPopulateAccessibilityEvent(AccessibilityEvent) |
| 4785 | * |
| 4786 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4787 | */ |
| 4788 | void onPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
| 4789 | |
| 4790 | } |
| 4791 | |
| 4792 | /** |
| 4793 | * Initializes an {@link AccessibilityEvent} with information about |
| 4794 | * this View which is the event source. In other words, the source of |
| 4795 | * an accessibility event is the view whose state change triggered firing |
| 4796 | * the event. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4797 | * <p> |
| 4798 | * Example: Setting the password property of an event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4799 | * to properties set by the super implementation: |
| 4800 | * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 4801 | * super.onInitializeAccessibilityEvent(event); |
| 4802 | * event.setPassword(true); |
| 4803 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4804 | * <p> |
| 4805 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4806 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4807 | * {@link AccessibilityDelegate#onInitializeAccessibilityEvent(View, AccessibilityEvent)} |
| 4808 | * is responsible for handling this call. |
| 4809 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4810 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4811 | * information to the event, in case the default implementation has basic information to add. |
| 4812 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4813 | * @param event The event to initialize. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4814 | * |
| 4815 | * @see #sendAccessibilityEvent(int) |
| 4816 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4817 | */ |
| 4818 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4819 | if (mAccessibilityDelegate != null) { |
| 4820 | mAccessibilityDelegate.onInitializeAccessibilityEvent(this, event); |
| 4821 | } else { |
| 4822 | onInitializeAccessibilityEventInternal(event); |
| 4823 | } |
| 4824 | } |
| 4825 | |
| 4826 | /** |
| 4827 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4828 | * |
| 4829 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4830 | */ |
| 4831 | void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4832 | event.setSource(this); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4833 | event.setClassName(View.class.getName()); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4834 | event.setPackageName(getContext().getPackageName()); |
| 4835 | event.setEnabled(isEnabled()); |
| 4836 | event.setContentDescription(mContentDescription); |
| 4837 | |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4838 | if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && mAttachInfo != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4839 | ArrayList<View> focusablesTempList = mAttachInfo.mTempArrayList; |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4840 | getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, |
| 4841 | FOCUSABLES_ALL); |
| 4842 | event.setItemCount(focusablesTempList.size()); |
| 4843 | event.setCurrentItemIndex(focusablesTempList.indexOf(this)); |
| 4844 | focusablesTempList.clear(); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4845 | } |
| 4846 | } |
| 4847 | |
| 4848 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4849 | * Returns an {@link AccessibilityNodeInfo} representing this view from the |
| 4850 | * point of view of an {@link android.accessibilityservice.AccessibilityService}. |
| 4851 | * This method is responsible for obtaining an accessibility node info from a |
| 4852 | * pool of reusable instances and calling |
| 4853 | * {@link #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} on this view to |
| 4854 | * initialize the former. |
| 4855 | * <p> |
| 4856 | * Note: The client is responsible for recycling the obtained instance by calling |
| 4857 | * {@link AccessibilityNodeInfo#recycle()} to minimize object creation. |
| 4858 | * </p> |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4859 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4860 | * @return A populated {@link AccessibilityNodeInfo}. |
| 4861 | * |
| 4862 | * @see AccessibilityNodeInfo |
| 4863 | */ |
| 4864 | public AccessibilityNodeInfo createAccessibilityNodeInfo() { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4865 | AccessibilityNodeProvider provider = getAccessibilityNodeProvider(); |
| 4866 | if (provider != null) { |
| 4867 | return provider.createAccessibilityNodeInfo(View.NO_ID); |
| 4868 | } else { |
| 4869 | AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this); |
| 4870 | onInitializeAccessibilityNodeInfo(info); |
| 4871 | return info; |
| 4872 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4873 | } |
| 4874 | |
| 4875 | /** |
| 4876 | * Initializes an {@link AccessibilityNodeInfo} with information about this view. |
| 4877 | * The base implementation sets: |
| 4878 | * <ul> |
| 4879 | * <li>{@link AccessibilityNodeInfo#setParent(View)},</li> |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4880 | * <li>{@link AccessibilityNodeInfo#setBoundsInParent(Rect)},</li> |
| 4881 | * <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li> |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4882 | * <li>{@link AccessibilityNodeInfo#setPackageName(CharSequence)},</li> |
| 4883 | * <li>{@link AccessibilityNodeInfo#setClassName(CharSequence)},</li> |
| 4884 | * <li>{@link AccessibilityNodeInfo#setContentDescription(CharSequence)},</li> |
| 4885 | * <li>{@link AccessibilityNodeInfo#setEnabled(boolean)},</li> |
| 4886 | * <li>{@link AccessibilityNodeInfo#setClickable(boolean)},</li> |
| 4887 | * <li>{@link AccessibilityNodeInfo#setFocusable(boolean)},</li> |
| 4888 | * <li>{@link AccessibilityNodeInfo#setFocused(boolean)},</li> |
| 4889 | * <li>{@link AccessibilityNodeInfo#setLongClickable(boolean)},</li> |
| 4890 | * <li>{@link AccessibilityNodeInfo#setSelected(boolean)},</li> |
| 4891 | * </ul> |
| 4892 | * <p> |
| 4893 | * Subclasses should override this method, call the super implementation, |
| 4894 | * and set additional attributes. |
| 4895 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4896 | * <p> |
| 4897 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4898 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4899 | * {@link AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)} |
| 4900 | * is responsible for handling this call. |
| 4901 | * </p> |
| 4902 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4903 | * @param info The instance to initialize. |
| 4904 | */ |
| 4905 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4906 | if (mAccessibilityDelegate != null) { |
| 4907 | mAccessibilityDelegate.onInitializeAccessibilityNodeInfo(this, info); |
| 4908 | } else { |
| 4909 | onInitializeAccessibilityNodeInfoInternal(info); |
| 4910 | } |
| 4911 | } |
| 4912 | |
| 4913 | /** |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4914 | * Gets the location of this view in screen coordintates. |
| 4915 | * |
| 4916 | * @param outRect The output location |
| 4917 | */ |
Svetoslav Ganov | 78bd983 | 2012-10-15 19:12:29 -0700 | [diff] [blame] | 4918 | void getBoundsOnScreen(Rect outRect) { |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4919 | if (mAttachInfo == null) { |
| 4920 | return; |
| 4921 | } |
| 4922 | |
| 4923 | RectF position = mAttachInfo.mTmpTransformRect; |
Svetoslav Ganov | 14b2b74 | 2012-05-08 16:36:34 -0700 | [diff] [blame] | 4924 | position.set(0, 0, mRight - mLeft, mBottom - mTop); |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4925 | |
| 4926 | if (!hasIdentityMatrix()) { |
| 4927 | getMatrix().mapRect(position); |
| 4928 | } |
| 4929 | |
Svetoslav Ganov | 14b2b74 | 2012-05-08 16:36:34 -0700 | [diff] [blame] | 4930 | position.offset(mLeft, mTop); |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4931 | |
| 4932 | ViewParent parent = mParent; |
| 4933 | while (parent instanceof View) { |
| 4934 | View parentView = (View) parent; |
| 4935 | |
| 4936 | position.offset(-parentView.mScrollX, -parentView.mScrollY); |
| 4937 | |
| 4938 | if (!parentView.hasIdentityMatrix()) { |
| 4939 | parentView.getMatrix().mapRect(position); |
| 4940 | } |
| 4941 | |
| 4942 | position.offset(parentView.mLeft, parentView.mTop); |
| 4943 | |
| 4944 | parent = parentView.mParent; |
| 4945 | } |
| 4946 | |
| 4947 | if (parent instanceof ViewRootImpl) { |
| 4948 | ViewRootImpl viewRootImpl = (ViewRootImpl) parent; |
| 4949 | position.offset(0, -viewRootImpl.mCurScrollY); |
| 4950 | } |
| 4951 | |
| 4952 | position.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
| 4953 | |
| 4954 | outRect.set((int) (position.left + 0.5f), (int) (position.top + 0.5f), |
| 4955 | (int) (position.right + 0.5f), (int) (position.bottom + 0.5f)); |
| 4956 | } |
| 4957 | |
| 4958 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4959 | * @see #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 4960 | * |
| 4961 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4962 | */ |
| 4963 | void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4964 | Rect bounds = mAttachInfo.mTmpInvalRect; |
Svetoslav Ganov | 983119a | 2012-07-03 21:04:10 -0700 | [diff] [blame] | 4965 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4966 | getDrawingRect(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4967 | info.setBoundsInParent(bounds); |
| 4968 | |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4969 | getBoundsOnScreen(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4970 | info.setBoundsInScreen(bounds); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4971 | |
Svetoslav Ganov | c406be9 | 2012-05-11 16:12:32 -0700 | [diff] [blame] | 4972 | ViewParent parent = getParentForAccessibility(); |
| 4973 | if (parent instanceof View) { |
| 4974 | info.setParent((View) parent); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4975 | } |
| 4976 | |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 4977 | if (mID != View.NO_ID) { |
| 4978 | View rootView = getRootView(); |
| 4979 | if (rootView == null) { |
| 4980 | rootView = this; |
| 4981 | } |
| 4982 | View label = rootView.findLabelForView(this, mID); |
| 4983 | if (label != null) { |
| 4984 | info.setLabeledBy(label); |
| 4985 | } |
| 4986 | } |
| 4987 | |
| 4988 | if (mLabelForId != View.NO_ID) { |
| 4989 | View rootView = getRootView(); |
| 4990 | if (rootView == null) { |
| 4991 | rootView = this; |
| 4992 | } |
| 4993 | View labeled = rootView.findViewInsideOutShouldExist(this, mLabelForId); |
| 4994 | if (labeled != null) { |
| 4995 | info.setLabelFor(labeled); |
| 4996 | } |
| 4997 | } |
| 4998 | |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4999 | info.setVisibleToUser(isVisibleToUser()); |
| 5000 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5001 | info.setPackageName(mContext.getPackageName()); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 5002 | info.setClassName(View.class.getName()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5003 | info.setContentDescription(getContentDescription()); |
| 5004 | |
| 5005 | info.setEnabled(isEnabled()); |
| 5006 | info.setClickable(isClickable()); |
| 5007 | info.setFocusable(isFocusable()); |
| 5008 | info.setFocused(isFocused()); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5009 | info.setAccessibilityFocused(isAccessibilityFocused()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5010 | info.setSelected(isSelected()); |
| 5011 | info.setLongClickable(isLongClickable()); |
| 5012 | |
| 5013 | // TODO: These make sense only if we are in an AdapterView but all |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 5014 | // views can be selected. Maybe from accessibility perspective |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5015 | // we should report as selectable view in an AdapterView. |
| 5016 | info.addAction(AccessibilityNodeInfo.ACTION_SELECT); |
| 5017 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION); |
| 5018 | |
| 5019 | if (isFocusable()) { |
| 5020 | if (isFocused()) { |
| 5021 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS); |
| 5022 | } else { |
| 5023 | info.addAction(AccessibilityNodeInfo.ACTION_FOCUS); |
| 5024 | } |
| 5025 | } |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5026 | |
Svetoslav Ganov | 02afe2c | 2012-05-07 17:51:59 -0700 | [diff] [blame] | 5027 | if (!isAccessibilityFocused()) { |
Svetoslav Ganov | 27e2da7 | 2012-07-02 18:12:00 -0700 | [diff] [blame] | 5028 | info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS); |
Svetoslav Ganov | 02afe2c | 2012-05-07 17:51:59 -0700 | [diff] [blame] | 5029 | } else { |
| 5030 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS); |
| 5031 | } |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5032 | |
Svetoslav Ganov | fb1e80a | 2012-05-16 17:33:19 -0700 | [diff] [blame] | 5033 | if (isClickable() && isEnabled()) { |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5034 | info.addAction(AccessibilityNodeInfo.ACTION_CLICK); |
| 5035 | } |
| 5036 | |
Svetoslav Ganov | fb1e80a | 2012-05-16 17:33:19 -0700 | [diff] [blame] | 5037 | if (isLongClickable() && isEnabled()) { |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5038 | info.addAction(AccessibilityNodeInfo.ACTION_LONG_CLICK); |
| 5039 | } |
| 5040 | |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 5041 | if (mContentDescription != null && mContentDescription.length() > 0) { |
Svetoslav Ganov | 2b435aa | 2012-05-04 17:16:37 -0700 | [diff] [blame] | 5042 | info.addAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY); |
| 5043 | info.addAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY); |
| 5044 | info.setMovementGranularities(AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 5045 | | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD |
| 5046 | | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH); |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5047 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5048 | } |
| 5049 | |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 5050 | private View findLabelForView(View view, int labeledId) { |
| 5051 | if (mMatchLabelForPredicate == null) { |
| 5052 | mMatchLabelForPredicate = new MatchLabelForPredicate(); |
| 5053 | } |
| 5054 | mMatchLabelForPredicate.mLabeledId = labeledId; |
| 5055 | return findViewByPredicateInsideOut(view, mMatchLabelForPredicate); |
| 5056 | } |
| 5057 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5058 | /** |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 5059 | * Computes whether this view is visible to the user. Such a view is |
| 5060 | * attached, visible, all its predecessors are visible, it is not clipped |
| 5061 | * entirely by its predecessors, and has an alpha greater than zero. |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 5062 | * |
| 5063 | * @return Whether the view is visible on the screen. |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 5064 | * |
| 5065 | * @hide |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 5066 | */ |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 5067 | protected boolean isVisibleToUser() { |
| 5068 | return isVisibleToUser(null); |
| 5069 | } |
| 5070 | |
| 5071 | /** |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5072 | * Computes whether the given portion of this view is visible to the user. |
| 5073 | * Such a view is attached, visible, all its predecessors are visible, |
| 5074 | * has an alpha greater than zero, and the specified portion is not |
| 5075 | * clipped entirely by its predecessors. |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 5076 | * |
| 5077 | * @param boundInView the portion of the view to test; coordinates should be relative; may be |
| 5078 | * <code>null</code>, and the entire view will be tested in this case. |
| 5079 | * When <code>true</code> is returned by the function, the actual visible |
| 5080 | * region will be stored in this parameter; that is, if boundInView is fully |
| 5081 | * contained within the view, no modification will be made, otherwise regions |
| 5082 | * outside of the visible area of the view will be clipped. |
| 5083 | * |
| 5084 | * @return Whether the specified portion of the view is visible on the screen. |
| 5085 | * |
| 5086 | * @hide |
| 5087 | */ |
| 5088 | protected boolean isVisibleToUser(Rect boundInView) { |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5089 | if (mAttachInfo != null) { |
Svetoslav Ganov | 11f19f1 | 2012-11-02 16:03:06 -0700 | [diff] [blame] | 5090 | // Attached to invisible window means this view is not visible. |
| 5091 | if (mAttachInfo.mWindowVisibility != View.VISIBLE) { |
| 5092 | return false; |
| 5093 | } |
| 5094 | // An invisible predecessor or one with alpha zero means |
| 5095 | // that this view is not visible to the user. |
| 5096 | Object current = this; |
| 5097 | while (current instanceof View) { |
| 5098 | View view = (View) current; |
| 5099 | // We have attach info so this view is attached and there is no |
| 5100 | // need to check whether we reach to ViewRootImpl on the way up. |
| 5101 | if (view.getAlpha() <= 0 || view.getVisibility() != VISIBLE) { |
| 5102 | return false; |
| 5103 | } |
| 5104 | current = view.mParent; |
| 5105 | } |
| 5106 | // Check if the view is entirely covered by its predecessors. |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5107 | Rect visibleRect = mAttachInfo.mTmpInvalRect; |
| 5108 | Point offset = mAttachInfo.mPoint; |
Svetoslav Ganov | 11f19f1 | 2012-11-02 16:03:06 -0700 | [diff] [blame] | 5109 | if (!getGlobalVisibleRect(visibleRect, offset)) { |
| 5110 | return false; |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 5111 | } |
Svetoslav Ganov | 11f19f1 | 2012-11-02 16:03:06 -0700 | [diff] [blame] | 5112 | // Check if the visible portion intersects the rectangle of interest. |
| 5113 | if (boundInView != null) { |
| 5114 | visibleRect.offset(-offset.x, -offset.y); |
| 5115 | return boundInView.intersect(visibleRect); |
| 5116 | } |
| 5117 | return true; |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5118 | } |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5119 | return false; |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | /** |
alanv | b72fe7a | 2012-08-27 16:44:25 -0700 | [diff] [blame] | 5123 | * Returns the delegate for implementing accessibility support via |
| 5124 | * composition. For more details see {@link AccessibilityDelegate}. |
| 5125 | * |
| 5126 | * @return The delegate, or null if none set. |
| 5127 | * |
| 5128 | * @hide |
| 5129 | */ |
| 5130 | public AccessibilityDelegate getAccessibilityDelegate() { |
| 5131 | return mAccessibilityDelegate; |
| 5132 | } |
| 5133 | |
| 5134 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 5135 | * Sets a delegate for implementing accessibility support via composition as |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 5136 | * opposed to inheritance. The delegate's primary use is for implementing |
| 5137 | * backwards compatible widgets. For more details see {@link AccessibilityDelegate}. |
| 5138 | * |
| 5139 | * @param delegate The delegate instance. |
| 5140 | * |
| 5141 | * @see AccessibilityDelegate |
| 5142 | */ |
| 5143 | public void setAccessibilityDelegate(AccessibilityDelegate delegate) { |
| 5144 | mAccessibilityDelegate = delegate; |
| 5145 | } |
| 5146 | |
| 5147 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5148 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 5149 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 5150 | * that explore the window content. |
| 5151 | * <p> |
| 5152 | * If this method returns an instance, this instance is responsible for managing |
| 5153 | * {@link AccessibilityNodeInfo}s describing the virtual sub-tree rooted at this |
| 5154 | * View including the one representing the View itself. Similarly the returned |
| 5155 | * instance is responsible for performing accessibility actions on any virtual |
| 5156 | * view or the root view itself. |
| 5157 | * </p> |
| 5158 | * <p> |
| 5159 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 5160 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 5161 | * {@link AccessibilityDelegate#getAccessibilityNodeProvider(View)} |
| 5162 | * is responsible for handling this call. |
| 5163 | * </p> |
| 5164 | * |
| 5165 | * @return The provider. |
| 5166 | * |
| 5167 | * @see AccessibilityNodeProvider |
| 5168 | */ |
| 5169 | public AccessibilityNodeProvider getAccessibilityNodeProvider() { |
| 5170 | if (mAccessibilityDelegate != null) { |
| 5171 | return mAccessibilityDelegate.getAccessibilityNodeProvider(this); |
| 5172 | } else { |
| 5173 | return null; |
| 5174 | } |
| 5175 | } |
| 5176 | |
| 5177 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5178 | * Gets the unique identifier of this view on the screen for accessibility purposes. |
| 5179 | * If this {@link View} is not attached to any window, {@value #NO_ID} is returned. |
| 5180 | * |
| 5181 | * @return The view accessibility id. |
| 5182 | * |
| 5183 | * @hide |
| 5184 | */ |
| 5185 | public int getAccessibilityViewId() { |
| 5186 | if (mAccessibilityViewId == NO_ID) { |
| 5187 | mAccessibilityViewId = sNextAccessibilityViewId++; |
| 5188 | } |
| 5189 | return mAccessibilityViewId; |
| 5190 | } |
| 5191 | |
| 5192 | /** |
| 5193 | * Gets the unique identifier of the window in which this View reseides. |
| 5194 | * |
| 5195 | * @return The window accessibility id. |
| 5196 | * |
| 5197 | * @hide |
| 5198 | */ |
| 5199 | public int getAccessibilityWindowId() { |
| 5200 | return mAttachInfo != null ? mAttachInfo.mAccessibilityWindowId : NO_ID; |
| 5201 | } |
| 5202 | |
| 5203 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5204 | * Gets the {@link View} description. It briefly describes the view and is |
| 5205 | * primarily used for accessibility support. Set this property to enable |
| 5206 | * better accessibility support for your application. This is especially |
| 5207 | * true for views that do not have textual representation (For example, |
| 5208 | * ImageButton). |
| 5209 | * |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5210 | * @return The content description. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5211 | * |
| 5212 | * @attr ref android.R.styleable#View_contentDescription |
| 5213 | */ |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5214 | @ViewDebug.ExportedProperty(category = "accessibility") |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5215 | public CharSequence getContentDescription() { |
| 5216 | return mContentDescription; |
| 5217 | } |
| 5218 | |
| 5219 | /** |
| 5220 | * Sets the {@link View} description. It briefly describes the view and is |
| 5221 | * primarily used for accessibility support. Set this property to enable |
| 5222 | * better accessibility support for your application. This is especially |
| 5223 | * true for views that do not have textual representation (For example, |
| 5224 | * ImageButton). |
| 5225 | * |
| 5226 | * @param contentDescription The content description. |
| 5227 | * |
| 5228 | * @attr ref android.R.styleable#View_contentDescription |
| 5229 | */ |
Svetoslav Ganov | e261e28 | 2011-10-18 17:47:04 -0700 | [diff] [blame] | 5230 | @RemotableViewMethod |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5231 | public void setContentDescription(CharSequence contentDescription) { |
Svetoslav Ganov | b708f77 | 2012-10-10 21:25:55 -0700 | [diff] [blame] | 5232 | if (mContentDescription == null) { |
| 5233 | if (contentDescription == null) { |
| 5234 | return; |
| 5235 | } |
| 5236 | } else if (mContentDescription.equals(contentDescription)) { |
| 5237 | return; |
| 5238 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5239 | mContentDescription = contentDescription; |
Svetoslav Ganov | e47957a | 2012-06-05 14:46:50 -0700 | [diff] [blame] | 5240 | final boolean nonEmptyDesc = contentDescription != null && contentDescription.length() > 0; |
| 5241 | if (nonEmptyDesc && getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 5242 | setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 5243 | } |
Svetoslav Ganov | b708f77 | 2012-10-10 21:25:55 -0700 | [diff] [blame] | 5244 | notifyAccessibilityStateChanged(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5245 | } |
| 5246 | |
| 5247 | /** |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 5248 | * Gets the id of a view for which this view serves as a label for |
| 5249 | * accessibility purposes. |
| 5250 | * |
| 5251 | * @return The labeled view id. |
| 5252 | */ |
| 5253 | @ViewDebug.ExportedProperty(category = "accessibility") |
| 5254 | public int getLabelFor() { |
| 5255 | return mLabelForId; |
| 5256 | } |
| 5257 | |
| 5258 | /** |
| 5259 | * Sets the id of a view for which this view serves as a label for |
| 5260 | * accessibility purposes. |
| 5261 | * |
| 5262 | * @param id The labeled view id. |
| 5263 | */ |
| 5264 | @RemotableViewMethod |
| 5265 | public void setLabelFor(int id) { |
| 5266 | mLabelForId = id; |
| 5267 | if (mLabelForId != View.NO_ID |
| 5268 | && mID == View.NO_ID) { |
| 5269 | mID = generateViewId(); |
| 5270 | } |
| 5271 | } |
| 5272 | |
| 5273 | /** |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5274 | * Invoked whenever this view loses focus, either by losing window focus or by losing |
| 5275 | * focus within its window. This method can be used to clear any state tied to the |
| 5276 | * focus. For instance, if a button is held pressed with the trackball and the window |
| 5277 | * loses focus, this method can be used to cancel the press. |
| 5278 | * |
| 5279 | * Subclasses of View overriding this method should always call super.onFocusLost(). |
| 5280 | * |
| 5281 | * @see #onFocusChanged(boolean, int, android.graphics.Rect) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5282 | * @see #onWindowFocusChanged(boolean) |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5283 | * |
| 5284 | * @hide pending API council approval |
| 5285 | */ |
| 5286 | protected void onFocusLost() { |
| 5287 | resetPressedState(); |
| 5288 | } |
| 5289 | |
| 5290 | private void resetPressedState() { |
| 5291 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 5292 | return; |
| 5293 | } |
| 5294 | |
| 5295 | if (isPressed()) { |
| 5296 | setPressed(false); |
| 5297 | |
| 5298 | if (!mHasPerformedLongPress) { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 5299 | removeLongPressCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5300 | } |
| 5301 | } |
| 5302 | } |
| 5303 | |
| 5304 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5305 | * Returns true if this view has focus |
| 5306 | * |
| 5307 | * @return True if this view has focus, false otherwise. |
| 5308 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5309 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5310 | public boolean isFocused() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5311 | return (mPrivateFlags & PFLAG_FOCUSED) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | /** |
| 5315 | * Find the view in the hierarchy rooted at this view that currently has |
| 5316 | * focus. |
| 5317 | * |
| 5318 | * @return The view that currently has focus, or null if no focused view can |
| 5319 | * be found. |
| 5320 | */ |
| 5321 | public View findFocus() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5322 | return (mPrivateFlags & PFLAG_FOCUSED) != 0 ? this : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5323 | } |
| 5324 | |
| 5325 | /** |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5326 | * Indicates whether this view is one of the set of scrollable containers in |
| 5327 | * its window. |
| 5328 | * |
| 5329 | * @return whether this view is one of the set of scrollable containers in |
| 5330 | * its window |
| 5331 | * |
| 5332 | * @attr ref android.R.styleable#View_isScrollContainer |
| 5333 | */ |
| 5334 | public boolean isScrollContainer() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5335 | return (mPrivateFlags & PFLAG_SCROLL_CONTAINER_ADDED) != 0; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5339 | * Change whether this view is one of the set of scrollable containers in |
| 5340 | * its window. This will be used to determine whether the window can |
| 5341 | * resize or must pan when a soft input area is open -- scrollable |
| 5342 | * containers allow the window to use resize mode since the container |
| 5343 | * will appropriately shrink. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5344 | * |
| 5345 | * @attr ref android.R.styleable#View_isScrollContainer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5346 | */ |
| 5347 | public void setScrollContainer(boolean isScrollContainer) { |
| 5348 | if (isScrollContainer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5349 | if (mAttachInfo != null && (mPrivateFlags&PFLAG_SCROLL_CONTAINER_ADDED) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5350 | mAttachInfo.mScrollContainers.add(this); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5351 | mPrivateFlags |= PFLAG_SCROLL_CONTAINER_ADDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5352 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5353 | mPrivateFlags |= PFLAG_SCROLL_CONTAINER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5354 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5355 | if ((mPrivateFlags&PFLAG_SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5356 | mAttachInfo.mScrollContainers.remove(this); |
| 5357 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5358 | mPrivateFlags &= ~(PFLAG_SCROLL_CONTAINER|PFLAG_SCROLL_CONTAINER_ADDED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5359 | } |
| 5360 | } |
| 5361 | |
| 5362 | /** |
| 5363 | * Returns the quality of the drawing cache. |
| 5364 | * |
| 5365 | * @return One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 5366 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 5367 | * |
| 5368 | * @see #setDrawingCacheQuality(int) |
| 5369 | * @see #setDrawingCacheEnabled(boolean) |
| 5370 | * @see #isDrawingCacheEnabled() |
| 5371 | * |
| 5372 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 5373 | */ |
| 5374 | public int getDrawingCacheQuality() { |
| 5375 | return mViewFlags & DRAWING_CACHE_QUALITY_MASK; |
| 5376 | } |
| 5377 | |
| 5378 | /** |
| 5379 | * Set the drawing cache quality of this view. This value is used only when the |
| 5380 | * drawing cache is enabled |
| 5381 | * |
| 5382 | * @param quality One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 5383 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 5384 | * |
| 5385 | * @see #getDrawingCacheQuality() |
| 5386 | * @see #setDrawingCacheEnabled(boolean) |
| 5387 | * @see #isDrawingCacheEnabled() |
| 5388 | * |
| 5389 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 5390 | */ |
| 5391 | public void setDrawingCacheQuality(int quality) { |
| 5392 | setFlags(quality, DRAWING_CACHE_QUALITY_MASK); |
| 5393 | } |
| 5394 | |
| 5395 | /** |
| 5396 | * Returns whether the screen should remain on, corresponding to the current |
| 5397 | * value of {@link #KEEP_SCREEN_ON}. |
| 5398 | * |
| 5399 | * @return Returns true if {@link #KEEP_SCREEN_ON} is set. |
| 5400 | * |
| 5401 | * @see #setKeepScreenOn(boolean) |
| 5402 | * |
| 5403 | * @attr ref android.R.styleable#View_keepScreenOn |
| 5404 | */ |
| 5405 | public boolean getKeepScreenOn() { |
| 5406 | return (mViewFlags & KEEP_SCREEN_ON) != 0; |
| 5407 | } |
| 5408 | |
| 5409 | /** |
| 5410 | * Controls whether the screen should remain on, modifying the |
| 5411 | * value of {@link #KEEP_SCREEN_ON}. |
| 5412 | * |
| 5413 | * @param keepScreenOn Supply true to set {@link #KEEP_SCREEN_ON}. |
| 5414 | * |
| 5415 | * @see #getKeepScreenOn() |
| 5416 | * |
| 5417 | * @attr ref android.R.styleable#View_keepScreenOn |
| 5418 | */ |
| 5419 | public void setKeepScreenOn(boolean keepScreenOn) { |
| 5420 | setFlags(keepScreenOn ? KEEP_SCREEN_ON : 0, KEEP_SCREEN_ON); |
| 5421 | } |
| 5422 | |
| 5423 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5424 | * Gets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 5425 | * @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] | 5426 | * |
| 5427 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 5428 | */ |
| 5429 | public int getNextFocusLeftId() { |
| 5430 | return mNextFocusLeftId; |
| 5431 | } |
| 5432 | |
| 5433 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5434 | * Sets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 5435 | * @param nextFocusLeftId The next focus ID, or {@link #NO_ID} if the framework should |
| 5436 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5437 | * |
| 5438 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 5439 | */ |
| 5440 | public void setNextFocusLeftId(int nextFocusLeftId) { |
| 5441 | mNextFocusLeftId = nextFocusLeftId; |
| 5442 | } |
| 5443 | |
| 5444 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5445 | * Gets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 5446 | * @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] | 5447 | * |
| 5448 | * @attr ref android.R.styleable#View_nextFocusRight |
| 5449 | */ |
| 5450 | public int getNextFocusRightId() { |
| 5451 | return mNextFocusRightId; |
| 5452 | } |
| 5453 | |
| 5454 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5455 | * Sets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 5456 | * @param nextFocusRightId The next focus ID, or {@link #NO_ID} if the framework should |
| 5457 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5458 | * |
| 5459 | * @attr ref android.R.styleable#View_nextFocusRight |
| 5460 | */ |
| 5461 | public void setNextFocusRightId(int nextFocusRightId) { |
| 5462 | mNextFocusRightId = nextFocusRightId; |
| 5463 | } |
| 5464 | |
| 5465 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5466 | * Gets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 5467 | * @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] | 5468 | * |
| 5469 | * @attr ref android.R.styleable#View_nextFocusUp |
| 5470 | */ |
| 5471 | public int getNextFocusUpId() { |
| 5472 | return mNextFocusUpId; |
| 5473 | } |
| 5474 | |
| 5475 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5476 | * Sets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 5477 | * @param nextFocusUpId The next focus ID, or {@link #NO_ID} if the framework should |
| 5478 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5479 | * |
| 5480 | * @attr ref android.R.styleable#View_nextFocusUp |
| 5481 | */ |
| 5482 | public void setNextFocusUpId(int nextFocusUpId) { |
| 5483 | mNextFocusUpId = nextFocusUpId; |
| 5484 | } |
| 5485 | |
| 5486 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5487 | * Gets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 5488 | * @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] | 5489 | * |
| 5490 | * @attr ref android.R.styleable#View_nextFocusDown |
| 5491 | */ |
| 5492 | public int getNextFocusDownId() { |
| 5493 | return mNextFocusDownId; |
| 5494 | } |
| 5495 | |
| 5496 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5497 | * Sets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 5498 | * @param nextFocusDownId The next focus ID, or {@link #NO_ID} if the framework should |
| 5499 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5500 | * |
| 5501 | * @attr ref android.R.styleable#View_nextFocusDown |
| 5502 | */ |
| 5503 | public void setNextFocusDownId(int nextFocusDownId) { |
| 5504 | mNextFocusDownId = nextFocusDownId; |
| 5505 | } |
| 5506 | |
| 5507 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5508 | * Gets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 5509 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
| 5510 | * |
| 5511 | * @attr ref android.R.styleable#View_nextFocusForward |
| 5512 | */ |
| 5513 | public int getNextFocusForwardId() { |
| 5514 | return mNextFocusForwardId; |
| 5515 | } |
| 5516 | |
| 5517 | /** |
| 5518 | * Sets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 5519 | * @param nextFocusForwardId The next focus ID, or {@link #NO_ID} if the framework should |
| 5520 | * decide automatically. |
| 5521 | * |
| 5522 | * @attr ref android.R.styleable#View_nextFocusForward |
| 5523 | */ |
| 5524 | public void setNextFocusForwardId(int nextFocusForwardId) { |
| 5525 | mNextFocusForwardId = nextFocusForwardId; |
| 5526 | } |
| 5527 | |
| 5528 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5529 | * Returns the visibility of this view and all of its ancestors |
| 5530 | * |
| 5531 | * @return True if this view and all of its ancestors are {@link #VISIBLE} |
| 5532 | */ |
| 5533 | public boolean isShown() { |
| 5534 | View current = this; |
| 5535 | //noinspection ConstantConditions |
| 5536 | do { |
| 5537 | if ((current.mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 5538 | return false; |
| 5539 | } |
| 5540 | ViewParent parent = current.mParent; |
| 5541 | if (parent == null) { |
| 5542 | return false; // We are not attached to the view root |
| 5543 | } |
| 5544 | if (!(parent instanceof View)) { |
| 5545 | return true; |
| 5546 | } |
| 5547 | current = (View) parent; |
| 5548 | } while (current != null); |
| 5549 | |
| 5550 | return false; |
| 5551 | } |
| 5552 | |
| 5553 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5554 | * Called by the view hierarchy when the content insets for a window have |
| 5555 | * changed, to allow it to adjust its content to fit within those windows. |
| 5556 | * The content insets tell you the space that the status bar, input method, |
| 5557 | * and other system windows infringe on the application's window. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5558 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5559 | * <p>You do not normally need to deal with this function, since the default |
| 5560 | * window decoration given to applications takes care of applying it to the |
| 5561 | * content of the window. If you use {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} |
| 5562 | * or {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} this will not be the case, |
| 5563 | * and your content can be placed under those system elements. You can then |
| 5564 | * use this method within your view hierarchy if you have parts of your UI |
| 5565 | * which you would like to ensure are not being covered. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5566 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5567 | * <p>The default implementation of this method simply applies the content |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5568 | * inset's to the view's padding, consuming that content (modifying the |
| 5569 | * insets to be 0), and returning true. This behavior is off by default, but can |
| 5570 | * be enabled through {@link #setFitsSystemWindows(boolean)}. |
| 5571 | * |
| 5572 | * <p>This function's traversal down the hierarchy is depth-first. The same content |
| 5573 | * insets object is propagated down the hierarchy, so any changes made to it will |
| 5574 | * be seen by all following views (including potentially ones above in |
| 5575 | * the hierarchy since this is a depth-first traversal). The first view |
| 5576 | * that returns true will abort the entire traversal. |
| 5577 | * |
| 5578 | * <p>The default implementation works well for a situation where it is |
| 5579 | * used with a container that covers the entire window, allowing it to |
| 5580 | * apply the appropriate insets to its content on all edges. If you need |
| 5581 | * a more complicated layout (such as two different views fitting system |
| 5582 | * windows, one on the top of the window, and one on the bottom), |
| 5583 | * you can override the method and handle the insets however you would like. |
| 5584 | * Note that the insets provided by the framework are always relative to the |
| 5585 | * far edges of the window, not accounting for the location of the called view |
| 5586 | * within that window. (In fact when this method is called you do not yet know |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5587 | * where the layout will place the view, as it is done before layout happens.) |
| 5588 | * |
| 5589 | * <p>Note: unlike many View methods, there is no dispatch phase to this |
| 5590 | * call. If you are overriding it in a ViewGroup and want to allow the |
| 5591 | * call to continue to your children, you must be sure to call the super |
| 5592 | * implementation. |
| 5593 | * |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5594 | * <p>Here is a sample layout that makes use of fitting system windows |
| 5595 | * to have controls for a video view placed inside of the window decorations |
| 5596 | * that it hides and shows. This can be used with code like the second |
| 5597 | * sample (video player) shown in {@link #setSystemUiVisibility(int)}. |
| 5598 | * |
| 5599 | * {@sample development/samples/ApiDemos/res/layout/video_player.xml complete} |
| 5600 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5601 | * @param insets Current content insets of the window. Prior to |
| 5602 | * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} you must not modify |
| 5603 | * the insets or else you and Android will be unhappy. |
| 5604 | * |
| 5605 | * @return Return true if this view applied the insets and it should not |
| 5606 | * continue propagating further down the hierarchy, false otherwise. |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5607 | * @see #getFitsSystemWindows() |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5608 | * @see #setFitsSystemWindows(boolean) |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5609 | * @see #setSystemUiVisibility(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5610 | */ |
| 5611 | protected boolean fitSystemWindows(Rect insets) { |
| 5612 | if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) { |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 5613 | mUserPaddingStart = UNDEFINED_PADDING; |
| 5614 | mUserPaddingEnd = UNDEFINED_PADDING; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5615 | if ((mViewFlags & OPTIONAL_FITS_SYSTEM_WINDOWS) == 0 |
| 5616 | || mAttachInfo == null |
| 5617 | || (mAttachInfo.mSystemUiVisibility & SYSTEM_UI_LAYOUT_FLAGS) == 0) { |
| 5618 | internalSetPadding(insets.left, insets.top, insets.right, insets.bottom); |
| 5619 | return true; |
| 5620 | } else { |
| 5621 | internalSetPadding(0, 0, 0, 0); |
| 5622 | return false; |
| 5623 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5624 | } |
| 5625 | return false; |
| 5626 | } |
| 5627 | |
| 5628 | /** |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5629 | * Sets whether or not this view should account for system screen decorations |
| 5630 | * such as the status bar and inset its content; that is, controlling whether |
| 5631 | * the default implementation of {@link #fitSystemWindows(Rect)} will be |
| 5632 | * executed. See that method for more details. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5633 | * |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5634 | * <p>Note that if you are providing your own implementation of |
| 5635 | * {@link #fitSystemWindows(Rect)}, then there is no need to set this |
| 5636 | * flag to true -- your implementation will be overriding the default |
| 5637 | * implementation that checks this flag. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5638 | * |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5639 | * @param fitSystemWindows If true, then the default implementation of |
| 5640 | * {@link #fitSystemWindows(Rect)} will be executed. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5641 | * |
| 5642 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5643 | * @see #getFitsSystemWindows() |
| 5644 | * @see #fitSystemWindows(Rect) |
| 5645 | * @see #setSystemUiVisibility(int) |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5646 | */ |
| 5647 | public void setFitsSystemWindows(boolean fitSystemWindows) { |
| 5648 | setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS); |
| 5649 | } |
| 5650 | |
| 5651 | /** |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5652 | * Check for state of {@link #setFitsSystemWindows(boolean). If this method |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5653 | * returns true, the default implementation of {@link #fitSystemWindows(Rect)} |
| 5654 | * will be executed. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5655 | * |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5656 | * @return Returns true if the default implementation of |
| 5657 | * {@link #fitSystemWindows(Rect)} will be executed. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5658 | * |
| 5659 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5660 | * @see #setFitsSystemWindows() |
| 5661 | * @see #fitSystemWindows(Rect) |
| 5662 | * @see #setSystemUiVisibility(int) |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5663 | */ |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5664 | public boolean getFitsSystemWindows() { |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5665 | return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS; |
| 5666 | } |
| 5667 | |
Dianne Hackborn | b1b55e6 | 2012-05-10 16:25:54 -0700 | [diff] [blame] | 5668 | /** @hide */ |
| 5669 | public boolean fitsSystemWindows() { |
| 5670 | return getFitsSystemWindows(); |
| 5671 | } |
| 5672 | |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5673 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5674 | * Ask that a new dispatch of {@link #fitSystemWindows(Rect)} be performed. |
| 5675 | */ |
| 5676 | public void requestFitSystemWindows() { |
| 5677 | if (mParent != null) { |
| 5678 | mParent.requestFitSystemWindows(); |
| 5679 | } |
| 5680 | } |
| 5681 | |
| 5682 | /** |
| 5683 | * For use by PhoneWindow to make its own system window fitting optional. |
| 5684 | * @hide |
| 5685 | */ |
| 5686 | public void makeOptionalFitsSystemWindows() { |
| 5687 | setFlags(OPTIONAL_FITS_SYSTEM_WINDOWS, OPTIONAL_FITS_SYSTEM_WINDOWS); |
| 5688 | } |
| 5689 | |
| 5690 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5691 | * Returns the visibility status for this view. |
| 5692 | * |
| 5693 | * @return One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 5694 | * @attr ref android.R.styleable#View_visibility |
| 5695 | */ |
| 5696 | @ViewDebug.ExportedProperty(mapping = { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5697 | @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), |
| 5698 | @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), |
| 5699 | @ViewDebug.IntToString(from = GONE, to = "GONE") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5700 | }) |
| 5701 | public int getVisibility() { |
| 5702 | return mViewFlags & VISIBILITY_MASK; |
| 5703 | } |
| 5704 | |
| 5705 | /** |
| 5706 | * Set the enabled state of this view. |
| 5707 | * |
| 5708 | * @param visibility One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 5709 | * @attr ref android.R.styleable#View_visibility |
| 5710 | */ |
| 5711 | @RemotableViewMethod |
| 5712 | public void setVisibility(int visibility) { |
| 5713 | setFlags(visibility, VISIBILITY_MASK); |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5714 | if (mBackground != null) mBackground.setVisible(visibility == VISIBLE, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | /** |
| 5718 | * Returns the enabled status for this view. The interpretation of the |
| 5719 | * enabled state varies by subclass. |
| 5720 | * |
| 5721 | * @return True if this view is enabled, false otherwise. |
| 5722 | */ |
| 5723 | @ViewDebug.ExportedProperty |
| 5724 | public boolean isEnabled() { |
| 5725 | return (mViewFlags & ENABLED_MASK) == ENABLED; |
| 5726 | } |
| 5727 | |
| 5728 | /** |
| 5729 | * Set the enabled state of this view. The interpretation of the enabled |
| 5730 | * state varies by subclass. |
| 5731 | * |
| 5732 | * @param enabled True if this view is enabled, false otherwise. |
| 5733 | */ |
Jeff Sharkey | 2b95c24 | 2010-02-08 17:40:30 -0800 | [diff] [blame] | 5734 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5735 | public void setEnabled(boolean enabled) { |
Amith Yamasani | a2ef00b | 2009-07-30 16:14:34 -0700 | [diff] [blame] | 5736 | if (enabled == isEnabled()) return; |
| 5737 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5738 | setFlags(enabled ? ENABLED : DISABLED, ENABLED_MASK); |
| 5739 | |
| 5740 | /* |
| 5741 | * The View most likely has to change its appearance, so refresh |
| 5742 | * the drawable state. |
| 5743 | */ |
| 5744 | refreshDrawableState(); |
| 5745 | |
| 5746 | // Invalidate too, since the default behavior for views is to be |
| 5747 | // be drawn at 50% alpha rather than to change the drawable. |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 5748 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5749 | } |
| 5750 | |
| 5751 | /** |
| 5752 | * Set whether this view can receive the focus. |
| 5753 | * |
| 5754 | * Setting this to false will also ensure that this view is not focusable |
| 5755 | * in touch mode. |
| 5756 | * |
| 5757 | * @param focusable If true, this view can receive the focus. |
| 5758 | * |
| 5759 | * @see #setFocusableInTouchMode(boolean) |
| 5760 | * @attr ref android.R.styleable#View_focusable |
| 5761 | */ |
| 5762 | public void setFocusable(boolean focusable) { |
| 5763 | if (!focusable) { |
| 5764 | setFlags(0, FOCUSABLE_IN_TOUCH_MODE); |
| 5765 | } |
| 5766 | setFlags(focusable ? FOCUSABLE : NOT_FOCUSABLE, FOCUSABLE_MASK); |
| 5767 | } |
| 5768 | |
| 5769 | /** |
| 5770 | * Set whether this view can receive focus while in touch mode. |
| 5771 | * |
| 5772 | * Setting this to true will also ensure that this view is focusable. |
| 5773 | * |
| 5774 | * @param focusableInTouchMode If true, this view can receive the focus while |
| 5775 | * in touch mode. |
| 5776 | * |
| 5777 | * @see #setFocusable(boolean) |
| 5778 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 5779 | */ |
| 5780 | public void setFocusableInTouchMode(boolean focusableInTouchMode) { |
| 5781 | // Focusable in touch mode should always be set before the focusable flag |
| 5782 | // otherwise, setting the focusable flag will trigger a focusableViewAvailable() |
| 5783 | // which, in touch mode, will not successfully request focus on this view |
| 5784 | // because the focusable in touch mode flag is not set |
| 5785 | setFlags(focusableInTouchMode ? FOCUSABLE_IN_TOUCH_MODE : 0, FOCUSABLE_IN_TOUCH_MODE); |
| 5786 | if (focusableInTouchMode) { |
| 5787 | setFlags(FOCUSABLE, FOCUSABLE_MASK); |
| 5788 | } |
| 5789 | } |
| 5790 | |
| 5791 | /** |
| 5792 | * Set whether this view should have sound effects enabled for events such as |
| 5793 | * clicking and touching. |
| 5794 | * |
| 5795 | * <p>You may wish to disable sound effects for a view if you already play sounds, |
| 5796 | * for instance, a dial key that plays dtmf tones. |
| 5797 | * |
| 5798 | * @param soundEffectsEnabled whether sound effects are enabled for this view. |
| 5799 | * @see #isSoundEffectsEnabled() |
| 5800 | * @see #playSoundEffect(int) |
| 5801 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5802 | */ |
| 5803 | public void setSoundEffectsEnabled(boolean soundEffectsEnabled) { |
| 5804 | setFlags(soundEffectsEnabled ? SOUND_EFFECTS_ENABLED: 0, SOUND_EFFECTS_ENABLED); |
| 5805 | } |
| 5806 | |
| 5807 | /** |
| 5808 | * @return whether this view should have sound effects enabled for events such as |
| 5809 | * clicking and touching. |
| 5810 | * |
| 5811 | * @see #setSoundEffectsEnabled(boolean) |
| 5812 | * @see #playSoundEffect(int) |
| 5813 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5814 | */ |
| 5815 | @ViewDebug.ExportedProperty |
| 5816 | public boolean isSoundEffectsEnabled() { |
| 5817 | return SOUND_EFFECTS_ENABLED == (mViewFlags & SOUND_EFFECTS_ENABLED); |
| 5818 | } |
| 5819 | |
| 5820 | /** |
| 5821 | * Set whether this view should have haptic feedback for events such as |
| 5822 | * long presses. |
| 5823 | * |
| 5824 | * <p>You may wish to disable haptic feedback if your view already controls |
| 5825 | * its own haptic feedback. |
| 5826 | * |
| 5827 | * @param hapticFeedbackEnabled whether haptic feedback enabled for this view. |
| 5828 | * @see #isHapticFeedbackEnabled() |
| 5829 | * @see #performHapticFeedback(int) |
| 5830 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5831 | */ |
| 5832 | public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) { |
| 5833 | setFlags(hapticFeedbackEnabled ? HAPTIC_FEEDBACK_ENABLED: 0, HAPTIC_FEEDBACK_ENABLED); |
| 5834 | } |
| 5835 | |
| 5836 | /** |
| 5837 | * @return whether this view should have haptic feedback enabled for events |
| 5838 | * long presses. |
| 5839 | * |
| 5840 | * @see #setHapticFeedbackEnabled(boolean) |
| 5841 | * @see #performHapticFeedback(int) |
| 5842 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5843 | */ |
| 5844 | @ViewDebug.ExportedProperty |
| 5845 | public boolean isHapticFeedbackEnabled() { |
| 5846 | return HAPTIC_FEEDBACK_ENABLED == (mViewFlags & HAPTIC_FEEDBACK_ENABLED); |
| 5847 | } |
| 5848 | |
| 5849 | /** |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5850 | * Returns the layout direction for this view. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5851 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5852 | * @return One of {@link #LAYOUT_DIRECTION_LTR}, |
| 5853 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5854 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 5855 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 5856 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5857 | * @attr ref android.R.styleable#View_layoutDirection |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5858 | * |
| 5859 | * @hide |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5860 | */ |
Fabrice Di Meglio | bce84d2 | 2011-06-02 15:57:01 -0700 | [diff] [blame] | 5861 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5862 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "LTR"), |
| 5863 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RTL"), |
| 5864 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"), |
| 5865 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE") |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5866 | }) |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5867 | public int getRawLayoutDirection() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5868 | return (mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >> PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | /** |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5872 | * Set the layout direction for this view. This will propagate a reset of layout direction |
| 5873 | * 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] | 5874 | * |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5875 | * @param layoutDirection the layout direction to set. Should be one of: |
| 5876 | * |
| 5877 | * {@link #LAYOUT_DIRECTION_LTR}, |
| 5878 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5879 | * {@link #LAYOUT_DIRECTION_INHERIT}, |
| 5880 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
| 5881 | * |
| 5882 | * Resolution will be done if the value is set to LAYOUT_DIRECTION_INHERIT. The resolution |
| 5883 | * proceeds up the parent chain of the view to get the value. If there is no parent, then it |
| 5884 | * will return the default {@link #LAYOUT_DIRECTION_LTR}. |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5885 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5886 | * @attr ref android.R.styleable#View_layoutDirection |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5887 | */ |
| 5888 | @RemotableViewMethod |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5889 | public void setLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 5890 | if (getRawLayoutDirection() != layoutDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 5891 | // Reset the current layout direction and the resolved one |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5892 | mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_MASK; |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 5893 | resetRtlProperties(); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 5894 | // Set the new layout direction (filtered) |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5895 | mPrivateFlags2 |= |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5896 | ((layoutDirection << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) & PFLAG2_LAYOUT_DIRECTION_MASK); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5897 | // We need to resolve all RTL properties as they all depend on layout direction |
| 5898 | resolveRtlPropertiesIfNeeded(); |
Fabrice Di Meglio | acb1c12 | 2012-10-02 14:18:55 -0700 | [diff] [blame] | 5899 | requestLayout(); |
| 5900 | invalidate(true); |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5901 | } |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5902 | } |
| 5903 | |
| 5904 | /** |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5905 | * Returns the resolved layout direction for this view. |
| 5906 | * |
| 5907 | * @return {@link #LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5908 | * {@link #LAYOUT_DIRECTION_LTR} if the layout direction is not RTL. |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5909 | * |
| 5910 | * For compatibility, this will return {@link #LAYOUT_DIRECTION_LTR} if API version |
| 5911 | * is lower than {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}. |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 5912 | * |
| 5913 | * @attr ref android.R.styleable#View_layoutDirection |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5914 | */ |
| 5915 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5916 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"), |
| 5917 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL") |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5918 | }) |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 5919 | public int getLayoutDirection() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 5920 | final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion; |
| 5921 | if (targetSdkVersion < JELLY_BEAN_MR1) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5922 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 5923 | return LAYOUT_DIRECTION_LTR; |
| 5924 | } |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5925 | return ((mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL) == |
| 5926 | PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL) ? LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5927 | } |
| 5928 | |
| 5929 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5930 | * Indicates whether or not this view's layout is right-to-left. This is resolved from |
| 5931 | * layout attribute and/or the inherited value from the parent |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5932 | * |
| 5933 | * @return true if the layout is right-to-left. |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 5934 | * |
| 5935 | * @hide |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5936 | */ |
| 5937 | @ViewDebug.ExportedProperty(category = "layout") |
| 5938 | public boolean isLayoutRtl() { |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 5939 | return (getLayoutDirection() == LAYOUT_DIRECTION_RTL); |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5940 | } |
| 5941 | |
| 5942 | /** |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5943 | * Indicates whether the view is currently tracking transient state that the |
| 5944 | * app should not need to concern itself with saving and restoring, but that |
| 5945 | * the framework should take special note to preserve when possible. |
| 5946 | * |
Adam Powell | 785c447 | 2012-05-02 21:25:39 -0700 | [diff] [blame] | 5947 | * <p>A view with transient state cannot be trivially rebound from an external |
| 5948 | * data source, such as an adapter binding item views in a list. This may be |
| 5949 | * because the view is performing an animation, tracking user selection |
| 5950 | * of content, or similar.</p> |
| 5951 | * |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5952 | * @return true if the view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5953 | */ |
| 5954 | @ViewDebug.ExportedProperty(category = "layout") |
| 5955 | public boolean hasTransientState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5956 | return (mPrivateFlags2 & PFLAG2_HAS_TRANSIENT_STATE) == PFLAG2_HAS_TRANSIENT_STATE; |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5957 | } |
| 5958 | |
| 5959 | /** |
| 5960 | * Set whether this view is currently tracking transient state that the |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 5961 | * framework should attempt to preserve when possible. This flag is reference counted, |
| 5962 | * so every call to setHasTransientState(true) should be paired with a later call |
| 5963 | * to setHasTransientState(false). |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5964 | * |
Adam Powell | 785c447 | 2012-05-02 21:25:39 -0700 | [diff] [blame] | 5965 | * <p>A view with transient state cannot be trivially rebound from an external |
| 5966 | * data source, such as an adapter binding item views in a list. This may be |
| 5967 | * because the view is performing an animation, tracking user selection |
| 5968 | * of content, or similar.</p> |
| 5969 | * |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5970 | * @param hasTransientState true if this view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5971 | */ |
| 5972 | public void setHasTransientState(boolean hasTransientState) { |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 5973 | mTransientStateCount = hasTransientState ? mTransientStateCount + 1 : |
| 5974 | mTransientStateCount - 1; |
| 5975 | if (mTransientStateCount < 0) { |
| 5976 | mTransientStateCount = 0; |
| 5977 | Log.e(VIEW_LOG_TAG, "hasTransientState decremented below 0: " + |
| 5978 | "unmatched pair of setHasTransientState calls"); |
| 5979 | } |
| 5980 | if ((hasTransientState && mTransientStateCount == 1) || |
Adam Powell | 057a585 | 2012-05-11 10:28:38 -0700 | [diff] [blame] | 5981 | (!hasTransientState && mTransientStateCount == 0)) { |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 5982 | // update flag if we've just incremented up from 0 or decremented down to 0 |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5983 | mPrivateFlags2 = (mPrivateFlags2 & ~PFLAG2_HAS_TRANSIENT_STATE) | |
| 5984 | (hasTransientState ? PFLAG2_HAS_TRANSIENT_STATE : 0); |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 5985 | if (mParent != null) { |
| 5986 | try { |
| 5987 | mParent.childHasTransientStateChanged(this, hasTransientState); |
| 5988 | } catch (AbstractMethodError e) { |
| 5989 | Log.e(VIEW_LOG_TAG, mParent.getClass().getSimpleName() + |
| 5990 | " does not fully implement ViewParent", e); |
| 5991 | } |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5992 | } |
| 5993 | } |
| 5994 | } |
| 5995 | |
| 5996 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5997 | * If this view doesn't do any drawing on its own, set this flag to |
| 5998 | * allow further optimizations. By default, this flag is not set on |
| 5999 | * View, but could be set on some View subclasses such as ViewGroup. |
| 6000 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6001 | * Typically, if you override {@link #onDraw(android.graphics.Canvas)} |
| 6002 | * you should clear this flag. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6003 | * |
| 6004 | * @param willNotDraw whether or not this View draw on its own |
| 6005 | */ |
| 6006 | public void setWillNotDraw(boolean willNotDraw) { |
| 6007 | setFlags(willNotDraw ? WILL_NOT_DRAW : 0, DRAW_MASK); |
| 6008 | } |
| 6009 | |
| 6010 | /** |
| 6011 | * Returns whether or not this View draws on its own. |
| 6012 | * |
| 6013 | * @return true if this view has nothing to draw, false otherwise |
| 6014 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 6015 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6016 | public boolean willNotDraw() { |
| 6017 | return (mViewFlags & DRAW_MASK) == WILL_NOT_DRAW; |
| 6018 | } |
| 6019 | |
| 6020 | /** |
| 6021 | * When a View's drawing cache is enabled, drawing is redirected to an |
| 6022 | * offscreen bitmap. Some views, like an ImageView, must be able to |
| 6023 | * bypass this mechanism if they already draw a single bitmap, to avoid |
| 6024 | * unnecessary usage of the memory. |
| 6025 | * |
| 6026 | * @param willNotCacheDrawing true if this view does not cache its |
| 6027 | * drawing, false otherwise |
| 6028 | */ |
| 6029 | public void setWillNotCacheDrawing(boolean willNotCacheDrawing) { |
| 6030 | setFlags(willNotCacheDrawing ? WILL_NOT_CACHE_DRAWING : 0, WILL_NOT_CACHE_DRAWING); |
| 6031 | } |
| 6032 | |
| 6033 | /** |
| 6034 | * Returns whether or not this View can cache its drawing or not. |
| 6035 | * |
| 6036 | * @return true if this view does not cache its drawing, false otherwise |
| 6037 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 6038 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6039 | public boolean willNotCacheDrawing() { |
| 6040 | return (mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING; |
| 6041 | } |
| 6042 | |
| 6043 | /** |
| 6044 | * Indicates whether this view reacts to click events or not. |
| 6045 | * |
| 6046 | * @return true if the view is clickable, false otherwise |
| 6047 | * |
| 6048 | * @see #setClickable(boolean) |
| 6049 | * @attr ref android.R.styleable#View_clickable |
| 6050 | */ |
| 6051 | @ViewDebug.ExportedProperty |
| 6052 | public boolean isClickable() { |
| 6053 | return (mViewFlags & CLICKABLE) == CLICKABLE; |
| 6054 | } |
| 6055 | |
| 6056 | /** |
| 6057 | * Enables or disables click events for this view. When a view |
| 6058 | * is clickable it will change its state to "pressed" on every click. |
| 6059 | * Subclasses should set the view clickable to visually react to |
| 6060 | * user's clicks. |
| 6061 | * |
| 6062 | * @param clickable true to make the view clickable, false otherwise |
| 6063 | * |
| 6064 | * @see #isClickable() |
| 6065 | * @attr ref android.R.styleable#View_clickable |
| 6066 | */ |
| 6067 | public void setClickable(boolean clickable) { |
| 6068 | setFlags(clickable ? CLICKABLE : 0, CLICKABLE); |
| 6069 | } |
| 6070 | |
| 6071 | /** |
| 6072 | * Indicates whether this view reacts to long click events or not. |
| 6073 | * |
| 6074 | * @return true if the view is long clickable, false otherwise |
| 6075 | * |
| 6076 | * @see #setLongClickable(boolean) |
| 6077 | * @attr ref android.R.styleable#View_longClickable |
| 6078 | */ |
| 6079 | public boolean isLongClickable() { |
| 6080 | return (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 6081 | } |
| 6082 | |
| 6083 | /** |
| 6084 | * Enables or disables long click events for this view. When a view is long |
| 6085 | * clickable it reacts to the user holding down the button for a longer |
| 6086 | * duration than a tap. This event can either launch the listener or a |
| 6087 | * context menu. |
| 6088 | * |
| 6089 | * @param longClickable true to make the view long clickable, false otherwise |
| 6090 | * @see #isLongClickable() |
| 6091 | * @attr ref android.R.styleable#View_longClickable |
| 6092 | */ |
| 6093 | public void setLongClickable(boolean longClickable) { |
| 6094 | setFlags(longClickable ? LONG_CLICKABLE : 0, LONG_CLICKABLE); |
| 6095 | } |
| 6096 | |
| 6097 | /** |
Chet Haase | 49afa5b | 2010-08-23 11:39:53 -0700 | [diff] [blame] | 6098 | * Sets the pressed state for this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6099 | * |
| 6100 | * @see #isClickable() |
| 6101 | * @see #setClickable(boolean) |
| 6102 | * |
| 6103 | * @param pressed Pass true to set the View's internal state to "pressed", or false to reverts |
| 6104 | * the View's internal state from a previously set "pressed" state. |
| 6105 | */ |
| 6106 | public void setPressed(boolean pressed) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6107 | final boolean needsRefresh = pressed != ((mPrivateFlags & PFLAG_PRESSED) == PFLAG_PRESSED); |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 6108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6109 | if (pressed) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6110 | mPrivateFlags |= PFLAG_PRESSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6111 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6112 | mPrivateFlags &= ~PFLAG_PRESSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6113 | } |
Adam Powell | 035a1fc | 2012-02-27 15:23:50 -0800 | [diff] [blame] | 6114 | |
| 6115 | if (needsRefresh) { |
| 6116 | refreshDrawableState(); |
| 6117 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6118 | dispatchSetPressed(pressed); |
| 6119 | } |
| 6120 | |
| 6121 | /** |
| 6122 | * Dispatch setPressed to all of this View's children. |
| 6123 | * |
| 6124 | * @see #setPressed(boolean) |
| 6125 | * |
| 6126 | * @param pressed The new pressed state |
| 6127 | */ |
| 6128 | protected void dispatchSetPressed(boolean pressed) { |
| 6129 | } |
| 6130 | |
| 6131 | /** |
| 6132 | * Indicates whether the view is currently in pressed state. Unless |
| 6133 | * {@link #setPressed(boolean)} is explicitly called, only clickable views can enter |
| 6134 | * the pressed state. |
| 6135 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 6136 | * @see #setPressed(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6137 | * @see #isClickable() |
| 6138 | * @see #setClickable(boolean) |
| 6139 | * |
| 6140 | * @return true if the view is currently pressed, false otherwise |
| 6141 | */ |
| 6142 | public boolean isPressed() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6143 | return (mPrivateFlags & PFLAG_PRESSED) == PFLAG_PRESSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6144 | } |
| 6145 | |
| 6146 | /** |
| 6147 | * Indicates whether this view will save its state (that is, |
| 6148 | * whether its {@link #onSaveInstanceState} method will be called). |
| 6149 | * |
| 6150 | * @return Returns true if the view state saving is enabled, else false. |
| 6151 | * |
| 6152 | * @see #setSaveEnabled(boolean) |
| 6153 | * @attr ref android.R.styleable#View_saveEnabled |
| 6154 | */ |
| 6155 | public boolean isSaveEnabled() { |
| 6156 | return (mViewFlags & SAVE_DISABLED_MASK) != SAVE_DISABLED; |
| 6157 | } |
| 6158 | |
| 6159 | /** |
| 6160 | * Controls whether the saving of this view's state is |
| 6161 | * enabled (that is, whether its {@link #onSaveInstanceState} method |
| 6162 | * will be called). Note that even if freezing is enabled, the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6163 | * 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] | 6164 | * for its state to be saved. This flag can only disable the |
| 6165 | * saving of this view; any child views may still have their state saved. |
| 6166 | * |
| 6167 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 6168 | * (the default) to allow it. |
| 6169 | * |
| 6170 | * @see #isSaveEnabled() |
| 6171 | * @see #setId(int) |
| 6172 | * @see #onSaveInstanceState() |
| 6173 | * @attr ref android.R.styleable#View_saveEnabled |
| 6174 | */ |
| 6175 | public void setSaveEnabled(boolean enabled) { |
| 6176 | setFlags(enabled ? 0 : SAVE_DISABLED, SAVE_DISABLED_MASK); |
| 6177 | } |
| 6178 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6179 | /** |
| 6180 | * Gets whether the framework should discard touches when the view's |
| 6181 | * window is obscured by another visible window. |
| 6182 | * Refer to the {@link View} security documentation for more details. |
| 6183 | * |
| 6184 | * @return True if touch filtering is enabled. |
| 6185 | * |
| 6186 | * @see #setFilterTouchesWhenObscured(boolean) |
| 6187 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 6188 | */ |
| 6189 | @ViewDebug.ExportedProperty |
| 6190 | public boolean getFilterTouchesWhenObscured() { |
| 6191 | return (mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0; |
| 6192 | } |
| 6193 | |
| 6194 | /** |
| 6195 | * Sets whether the framework should discard touches when the view's |
| 6196 | * window is obscured by another visible window. |
| 6197 | * Refer to the {@link View} security documentation for more details. |
| 6198 | * |
| 6199 | * @param enabled True if touch filtering should be enabled. |
| 6200 | * |
| 6201 | * @see #getFilterTouchesWhenObscured |
| 6202 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 6203 | */ |
| 6204 | public void setFilterTouchesWhenObscured(boolean enabled) { |
| 6205 | setFlags(enabled ? 0 : FILTER_TOUCHES_WHEN_OBSCURED, |
| 6206 | FILTER_TOUCHES_WHEN_OBSCURED); |
| 6207 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6208 | |
| 6209 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 6210 | * Indicates whether the entire hierarchy under this view will save its |
| 6211 | * state when a state saving traversal occurs from its parent. The default |
| 6212 | * is true; if false, these views will not be saved unless |
| 6213 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 6214 | * |
| 6215 | * @return Returns true if the view state saving from parent is enabled, else false. |
| 6216 | * |
| 6217 | * @see #setSaveFromParentEnabled(boolean) |
| 6218 | */ |
| 6219 | public boolean isSaveFromParentEnabled() { |
| 6220 | return (mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED; |
| 6221 | } |
| 6222 | |
| 6223 | /** |
| 6224 | * Controls whether the entire hierarchy under this view will save its |
| 6225 | * state when a state saving traversal occurs from its parent. The default |
| 6226 | * is true; if false, these views will not be saved unless |
| 6227 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 6228 | * |
| 6229 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 6230 | * (the default) to allow it. |
| 6231 | * |
| 6232 | * @see #isSaveFromParentEnabled() |
| 6233 | * @see #setId(int) |
| 6234 | * @see #onSaveInstanceState() |
| 6235 | */ |
| 6236 | public void setSaveFromParentEnabled(boolean enabled) { |
| 6237 | setFlags(enabled ? 0 : PARENT_SAVE_DISABLED, PARENT_SAVE_DISABLED_MASK); |
| 6238 | } |
| 6239 | |
| 6240 | |
| 6241 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6242 | * Returns whether this View is able to take focus. |
| 6243 | * |
| 6244 | * @return True if this view can take focus, or false otherwise. |
| 6245 | * @attr ref android.R.styleable#View_focusable |
| 6246 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 6247 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6248 | public final boolean isFocusable() { |
| 6249 | return FOCUSABLE == (mViewFlags & FOCUSABLE_MASK); |
| 6250 | } |
| 6251 | |
| 6252 | /** |
| 6253 | * When a view is focusable, it may not want to take focus when in touch mode. |
| 6254 | * For example, a button would like focus when the user is navigating via a D-pad |
| 6255 | * so that the user can click on it, but once the user starts touching the screen, |
| 6256 | * the button shouldn't take focus |
| 6257 | * @return Whether the view is focusable in touch mode. |
| 6258 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 6259 | */ |
| 6260 | @ViewDebug.ExportedProperty |
| 6261 | public final boolean isFocusableInTouchMode() { |
| 6262 | return FOCUSABLE_IN_TOUCH_MODE == (mViewFlags & FOCUSABLE_IN_TOUCH_MODE); |
| 6263 | } |
| 6264 | |
| 6265 | /** |
| 6266 | * Find the nearest view in the specified direction that can take focus. |
| 6267 | * This does not actually give focus to that view. |
| 6268 | * |
| 6269 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6270 | * |
| 6271 | * @return The nearest focusable in the specified direction, or null if none |
| 6272 | * can be found. |
| 6273 | */ |
| 6274 | public View focusSearch(int direction) { |
| 6275 | if (mParent != null) { |
| 6276 | return mParent.focusSearch(this, direction); |
| 6277 | } else { |
| 6278 | return null; |
| 6279 | } |
| 6280 | } |
| 6281 | |
| 6282 | /** |
| 6283 | * This method is the last chance for the focused view and its ancestors to |
| 6284 | * respond to an arrow key. This is called when the focused view did not |
| 6285 | * consume the key internally, nor could the view system find a new view in |
| 6286 | * the requested direction to give focus to. |
| 6287 | * |
| 6288 | * @param focused The currently focused view. |
| 6289 | * @param direction The direction focus wants to move. One of FOCUS_UP, |
| 6290 | * FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. |
| 6291 | * @return True if the this view consumed this unhandled move. |
| 6292 | */ |
| 6293 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 6294 | return false; |
| 6295 | } |
| 6296 | |
| 6297 | /** |
| 6298 | * 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] | 6299 | * use the root to look up the view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6300 | * @param root The root view of the hierarchy containing this view. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6301 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, |
| 6302 | * or FOCUS_BACKWARD. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6303 | * @return The user specified next view, or null if there is none. |
| 6304 | */ |
| 6305 | View findUserSetNextFocus(View root, int direction) { |
| 6306 | switch (direction) { |
| 6307 | case FOCUS_LEFT: |
| 6308 | if (mNextFocusLeftId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6309 | return findViewInsideOutShouldExist(root, mNextFocusLeftId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6310 | case FOCUS_RIGHT: |
| 6311 | if (mNextFocusRightId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6312 | return findViewInsideOutShouldExist(root, mNextFocusRightId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6313 | case FOCUS_UP: |
| 6314 | if (mNextFocusUpId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6315 | return findViewInsideOutShouldExist(root, mNextFocusUpId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6316 | case FOCUS_DOWN: |
| 6317 | if (mNextFocusDownId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6318 | return findViewInsideOutShouldExist(root, mNextFocusDownId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6319 | case FOCUS_FORWARD: |
| 6320 | if (mNextFocusForwardId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6321 | return findViewInsideOutShouldExist(root, mNextFocusForwardId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6322 | case FOCUS_BACKWARD: { |
John Reck | 1ecebbb | 2012-03-06 16:08:54 -0800 | [diff] [blame] | 6323 | if (mID == View.NO_ID) return null; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6324 | final int id = mID; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6325 | return root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6326 | @Override |
| 6327 | public boolean apply(View t) { |
| 6328 | return t.mNextFocusForwardId == id; |
| 6329 | } |
| 6330 | }); |
| 6331 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6332 | } |
| 6333 | return null; |
| 6334 | } |
| 6335 | |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 6336 | private View findViewInsideOutShouldExist(View root, int id) { |
| 6337 | if (mMatchIdPredicate == null) { |
| 6338 | mMatchIdPredicate = new MatchIdPredicate(); |
| 6339 | } |
| 6340 | mMatchIdPredicate.mId = id; |
| 6341 | View result = root.findViewByPredicateInsideOut(this, mMatchIdPredicate); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6342 | if (result == null) { |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 6343 | Log.w(VIEW_LOG_TAG, "couldn't find view with id " + id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6344 | } |
| 6345 | return result; |
| 6346 | } |
| 6347 | |
| 6348 | /** |
| 6349 | * Find and return all focusable views that are descendants of this view, |
| 6350 | * possibly including this view if it is focusable itself. |
| 6351 | * |
| 6352 | * @param direction The direction of the focus |
| 6353 | * @return A list of focusable views |
| 6354 | */ |
| 6355 | public ArrayList<View> getFocusables(int direction) { |
| 6356 | ArrayList<View> result = new ArrayList<View>(24); |
| 6357 | addFocusables(result, direction); |
| 6358 | return result; |
| 6359 | } |
| 6360 | |
| 6361 | /** |
| 6362 | * Add any focusable views that are descendants of this view (possibly |
| 6363 | * including this view if it is focusable itself) to views. If we are in touch mode, |
| 6364 | * only add views that are also focusable in touch mode. |
| 6365 | * |
| 6366 | * @param views Focusable views found so far |
| 6367 | * @param direction The direction of the focus |
| 6368 | */ |
| 6369 | public void addFocusables(ArrayList<View> views, int direction) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6370 | addFocusables(views, direction, FOCUSABLES_TOUCH_MODE); |
| 6371 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6372 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6373 | /** |
| 6374 | * Adds any focusable views that are descendants of this view (possibly |
| 6375 | * including this view if it is focusable itself) to views. This method |
| 6376 | * adds all focusable views regardless if we are in touch mode or |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6377 | * only views focusable in touch mode if we are in touch mode or |
| 6378 | * only views that can take accessibility focus if accessibility is enabeld |
| 6379 | * depending on the focusable mode paramater. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6380 | * |
| 6381 | * @param views Focusable views found so far or null if all we are interested is |
| 6382 | * the number of focusables. |
| 6383 | * @param direction The direction of the focus. |
| 6384 | * @param focusableMode The type of focusables to be added. |
| 6385 | * |
| 6386 | * @see #FOCUSABLES_ALL |
| 6387 | * @see #FOCUSABLES_TOUCH_MODE |
| 6388 | */ |
| 6389 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6390 | if (views == null) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6391 | return; |
| 6392 | } |
Svetoslav Ganov | 3cb889c | 2012-04-16 19:10:30 -0700 | [diff] [blame] | 6393 | if (!isFocusable()) { |
| 6394 | return; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6395 | } |
Svetoslav Ganov | 3cb889c | 2012-04-16 19:10:30 -0700 | [diff] [blame] | 6396 | if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE |
| 6397 | && isInTouchMode() && !isFocusableInTouchMode()) { |
| 6398 | return; |
| 6399 | } |
| 6400 | views.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6401 | } |
| 6402 | |
| 6403 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6404 | * Finds the Views that contain given text. The containment is case insensitive. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6405 | * The search is performed by either the text that the View renders or the content |
| 6406 | * description that describes the view for accessibility purposes and the view does |
| 6407 | * not render or both. Clients can specify how the search is to be performed via |
| 6408 | * passing the {@link #FIND_VIEWS_WITH_TEXT} and |
| 6409 | * {@link #FIND_VIEWS_WITH_CONTENT_DESCRIPTION} flags. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6410 | * |
| 6411 | * @param outViews The output list of matching Views. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6412 | * @param searched The text to match against. |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 6413 | * |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6414 | * @see #FIND_VIEWS_WITH_TEXT |
| 6415 | * @see #FIND_VIEWS_WITH_CONTENT_DESCRIPTION |
| 6416 | * @see #setContentDescription(CharSequence) |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6417 | */ |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6418 | public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 6419 | if (getAccessibilityNodeProvider() != null) { |
| 6420 | if ((flags & FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS) != 0) { |
| 6421 | outViews.add(this); |
| 6422 | } |
| 6423 | } else if ((flags & FIND_VIEWS_WITH_CONTENT_DESCRIPTION) != 0 |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6424 | && (searched != null && searched.length() > 0) |
| 6425 | && (mContentDescription != null && mContentDescription.length() > 0)) { |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6426 | String searchedLowerCase = searched.toString().toLowerCase(); |
| 6427 | String contentDescriptionLowerCase = mContentDescription.toString().toLowerCase(); |
| 6428 | if (contentDescriptionLowerCase.contains(searchedLowerCase)) { |
| 6429 | outViews.add(this); |
| 6430 | } |
| 6431 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6432 | } |
| 6433 | |
| 6434 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6435 | * Find and return all touchable views that are descendants of this view, |
| 6436 | * possibly including this view if it is touchable itself. |
| 6437 | * |
| 6438 | * @return A list of touchable views |
| 6439 | */ |
| 6440 | public ArrayList<View> getTouchables() { |
| 6441 | ArrayList<View> result = new ArrayList<View>(); |
| 6442 | addTouchables(result); |
| 6443 | return result; |
| 6444 | } |
| 6445 | |
| 6446 | /** |
| 6447 | * Add any touchable views that are descendants of this view (possibly |
| 6448 | * including this view if it is touchable itself) to views. |
| 6449 | * |
| 6450 | * @param views Touchable views found so far |
| 6451 | */ |
| 6452 | public void addTouchables(ArrayList<View> views) { |
| 6453 | final int viewFlags = mViewFlags; |
| 6454 | |
| 6455 | if (((viewFlags & CLICKABLE) == CLICKABLE || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) |
| 6456 | && (viewFlags & ENABLED_MASK) == ENABLED) { |
| 6457 | views.add(this); |
| 6458 | } |
| 6459 | } |
| 6460 | |
| 6461 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6462 | * Returns whether this View is accessibility focused. |
| 6463 | * |
| 6464 | * @return True if this View is accessibility focused. |
| 6465 | */ |
| 6466 | boolean isAccessibilityFocused() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6467 | return (mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6468 | } |
| 6469 | |
| 6470 | /** |
| 6471 | * Call this to try to give accessibility focus to this view. |
| 6472 | * |
| 6473 | * A view will not actually take focus if {@link AccessibilityManager#isEnabled()} |
| 6474 | * returns false or the view is no visible or the view already has accessibility |
| 6475 | * focus. |
| 6476 | * |
| 6477 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
| 6478 | * have focus, and you want your parent to look for the next one. |
| 6479 | * |
| 6480 | * @return Whether this view actually took accessibility focus. |
| 6481 | * |
| 6482 | * @hide |
| 6483 | */ |
| 6484 | public boolean requestAccessibilityFocus() { |
Svetoslav Ganov | 07b726c | 2012-04-30 12:24:57 -0700 | [diff] [blame] | 6485 | AccessibilityManager manager = AccessibilityManager.getInstance(mContext); |
| 6486 | if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6487 | return false; |
| 6488 | } |
| 6489 | if ((mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 6490 | return false; |
| 6491 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6492 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) == 0) { |
| 6493 | mPrivateFlags2 |= PFLAG2_ACCESSIBILITY_FOCUSED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6494 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 6495 | if (viewRootImpl != null) { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6496 | viewRootImpl.setAccessibilityFocus(this, null); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6497 | } |
| 6498 | invalidate(); |
| 6499 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED); |
| 6500 | notifyAccessibilityStateChanged(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6501 | return true; |
| 6502 | } |
| 6503 | return false; |
| 6504 | } |
| 6505 | |
| 6506 | /** |
| 6507 | * Call this to try to clear accessibility focus of this view. |
| 6508 | * |
| 6509 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
| 6510 | * have focus, and you want your parent to look for the next one. |
| 6511 | * |
| 6512 | * @hide |
| 6513 | */ |
| 6514 | public void clearAccessibilityFocus() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6515 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0) { |
| 6516 | mPrivateFlags2 &= ~PFLAG2_ACCESSIBILITY_FOCUSED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6517 | invalidate(); |
| 6518 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED); |
| 6519 | notifyAccessibilityStateChanged(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6520 | } |
Svetoslav Ganov | c00d008 | 2012-05-22 18:37:49 -0700 | [diff] [blame] | 6521 | // Clear the global reference of accessibility focus if this |
| 6522 | // view or any of its descendants had accessibility focus. |
| 6523 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 6524 | if (viewRootImpl != null) { |
| 6525 | View focusHost = viewRootImpl.getAccessibilityFocusedHost(); |
| 6526 | if (focusHost != null && ViewRootImpl.isViewDescendantOf(focusHost, this)) { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6527 | viewRootImpl.setAccessibilityFocus(null, null); |
Svetoslav Ganov | c00d008 | 2012-05-22 18:37:49 -0700 | [diff] [blame] | 6528 | } |
| 6529 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6530 | } |
| 6531 | |
Svetoslav Ganov | 8ffe8b3 | 2012-06-15 10:31:31 -0700 | [diff] [blame] | 6532 | private void sendAccessibilityHoverEvent(int eventType) { |
| 6533 | // Since we are not delivering to a client accessibility events from not |
| 6534 | // important views (unless the clinet request that) we need to fire the |
| 6535 | // event from the deepest view exposed to the client. As a consequence if |
| 6536 | // the user crosses a not exposed view the client will see enter and exit |
| 6537 | // of the exposed predecessor followed by and enter and exit of that same |
| 6538 | // predecessor when entering and exiting the not exposed descendant. This |
| 6539 | // is fine since the client has a clear idea which view is hovered at the |
| 6540 | // price of a couple more events being sent. This is a simple and |
| 6541 | // working solution. |
| 6542 | View source = this; |
| 6543 | while (true) { |
| 6544 | if (source.includeForAccessibility()) { |
| 6545 | source.sendAccessibilityEvent(eventType); |
| 6546 | return; |
| 6547 | } |
| 6548 | ViewParent parent = source.getParent(); |
| 6549 | if (parent instanceof View) { |
| 6550 | source = (View) parent; |
| 6551 | } else { |
| 6552 | return; |
| 6553 | } |
| 6554 | } |
| 6555 | } |
| 6556 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6557 | /** |
| 6558 | * Clears accessibility focus without calling any callback methods |
| 6559 | * normally invoked in {@link #clearAccessibilityFocus()}. This method |
| 6560 | * is used for clearing accessibility focus when giving this focus to |
| 6561 | * another view. |
| 6562 | */ |
| 6563 | void clearAccessibilityFocusNoCallbacks() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6564 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0) { |
| 6565 | mPrivateFlags2 &= ~PFLAG2_ACCESSIBILITY_FOCUSED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6566 | invalidate(); |
| 6567 | } |
| 6568 | } |
| 6569 | |
| 6570 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6571 | * Call this to try to give focus to a specific view or to one of its |
| 6572 | * descendants. |
| 6573 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6574 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6575 | * false), or if it is focusable and it is not focusable in touch mode |
| 6576 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6577 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6578 | * 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] | 6579 | * have focus, and you want your parent to look for the next one. |
| 6580 | * |
| 6581 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with arguments |
| 6582 | * {@link #FOCUS_DOWN} and <code>null</code>. |
| 6583 | * |
| 6584 | * @return Whether this view or one of its descendants actually took focus. |
| 6585 | */ |
| 6586 | public final boolean requestFocus() { |
| 6587 | return requestFocus(View.FOCUS_DOWN); |
| 6588 | } |
| 6589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6590 | /** |
| 6591 | * Call this to try to give focus to a specific view or to one of its |
| 6592 | * descendants and give it a hint about what direction focus is heading. |
| 6593 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6594 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6595 | * false), or if it is focusable and it is not focusable in touch mode |
| 6596 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6597 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6598 | * 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] | 6599 | * have focus, and you want your parent to look for the next one. |
| 6600 | * |
| 6601 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with |
| 6602 | * <code>null</code> set for the previously focused rectangle. |
| 6603 | * |
| 6604 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6605 | * @return Whether this view or one of its descendants actually took focus. |
| 6606 | */ |
| 6607 | public final boolean requestFocus(int direction) { |
| 6608 | return requestFocus(direction, null); |
| 6609 | } |
| 6610 | |
| 6611 | /** |
| 6612 | * Call this to try to give focus to a specific view or to one of its descendants |
| 6613 | * and give it hints about the direction and a specific rectangle that the focus |
| 6614 | * is coming from. The rectangle can help give larger views a finer grained hint |
| 6615 | * about where focus is coming from, and therefore, where to show selection, or |
| 6616 | * forward focus change internally. |
| 6617 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6618 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6619 | * false), or if it is focusable and it is not focusable in touch mode |
| 6620 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6621 | * |
| 6622 | * A View will not take focus if it is not visible. |
| 6623 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6624 | * A View will not take focus if one of its parents has |
| 6625 | * {@link android.view.ViewGroup#getDescendantFocusability()} equal to |
| 6626 | * {@link ViewGroup#FOCUS_BLOCK_DESCENDANTS}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6627 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6628 | * 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] | 6629 | * have focus, and you want your parent to look for the next one. |
| 6630 | * |
| 6631 | * You may wish to override this method if your custom {@link View} has an internal |
| 6632 | * {@link View} that it wishes to forward the request to. |
| 6633 | * |
| 6634 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6635 | * @param previouslyFocusedRect The rectangle (in this View's coordinate system) |
| 6636 | * to give a finer grained hint about where focus is coming from. May be null |
| 6637 | * if there is no hint. |
| 6638 | * @return Whether this view or one of its descendants actually took focus. |
| 6639 | */ |
| 6640 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6641 | return requestFocusNoSearch(direction, previouslyFocusedRect); |
| 6642 | } |
| 6643 | |
| 6644 | private boolean requestFocusNoSearch(int direction, Rect previouslyFocusedRect) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6645 | // need to be focusable |
| 6646 | if ((mViewFlags & FOCUSABLE_MASK) != FOCUSABLE || |
| 6647 | (mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 6648 | return false; |
| 6649 | } |
| 6650 | |
| 6651 | // need to be focusable in touch mode if in touch mode |
| 6652 | if (isInTouchMode() && |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6653 | (FOCUSABLE_IN_TOUCH_MODE != (mViewFlags & FOCUSABLE_IN_TOUCH_MODE))) { |
| 6654 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6655 | } |
| 6656 | |
| 6657 | // need to not have any parents blocking us |
| 6658 | if (hasAncestorThatBlocksDescendantFocus()) { |
| 6659 | return false; |
| 6660 | } |
| 6661 | |
| 6662 | handleFocusGainInternal(direction, previouslyFocusedRect); |
| 6663 | return true; |
| 6664 | } |
| 6665 | |
| 6666 | /** |
| 6667 | * Call this to try to give focus to a specific view or to one of its descendants. This is a |
| 6668 | * special variant of {@link #requestFocus() } that will allow views that are not focuable in |
| 6669 | * touch mode to request focus when they are touched. |
| 6670 | * |
| 6671 | * @return Whether this view or one of its descendants actually took focus. |
| 6672 | * |
| 6673 | * @see #isInTouchMode() |
| 6674 | * |
| 6675 | */ |
| 6676 | public final boolean requestFocusFromTouch() { |
| 6677 | // Leave touch mode if we need to |
| 6678 | if (isInTouchMode()) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6679 | ViewRootImpl viewRoot = getViewRootImpl(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6680 | if (viewRoot != null) { |
| 6681 | viewRoot.ensureTouchMode(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6682 | } |
| 6683 | } |
| 6684 | return requestFocus(View.FOCUS_DOWN); |
| 6685 | } |
| 6686 | |
| 6687 | /** |
| 6688 | * @return Whether any ancestor of this view blocks descendant focus. |
| 6689 | */ |
| 6690 | private boolean hasAncestorThatBlocksDescendantFocus() { |
| 6691 | ViewParent ancestor = mParent; |
| 6692 | while (ancestor instanceof ViewGroup) { |
| 6693 | final ViewGroup vgAncestor = (ViewGroup) ancestor; |
| 6694 | if (vgAncestor.getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS) { |
| 6695 | return true; |
| 6696 | } else { |
| 6697 | ancestor = vgAncestor.getParent(); |
| 6698 | } |
| 6699 | } |
| 6700 | return false; |
| 6701 | } |
| 6702 | |
| 6703 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6704 | * Gets the mode for determining whether this View is important for accessibility |
| 6705 | * which is if it fires accessibility events and if it is reported to |
| 6706 | * accessibility services that query the screen. |
| 6707 | * |
| 6708 | * @return The mode for determining whether a View is important for accessibility. |
| 6709 | * |
| 6710 | * @attr ref android.R.styleable#View_importantForAccessibility |
| 6711 | * |
| 6712 | * @see #IMPORTANT_FOR_ACCESSIBILITY_YES |
| 6713 | * @see #IMPORTANT_FOR_ACCESSIBILITY_NO |
| 6714 | * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 6715 | */ |
| 6716 | @ViewDebug.ExportedProperty(category = "accessibility", mapping = { |
Svetoslav Ganov | f9817f7 | 2012-05-22 18:10:31 -0700 | [diff] [blame] | 6717 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_AUTO, to = "auto"), |
| 6718 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_YES, to = "yes"), |
| 6719 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_NO, to = "no") |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6720 | }) |
| 6721 | public int getImportantForAccessibility() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6722 | return (mPrivateFlags2 & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK) |
| 6723 | >> PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6724 | } |
| 6725 | |
| 6726 | /** |
| 6727 | * Sets how to determine whether this view is important for accessibility |
| 6728 | * which is if it fires accessibility events and if it is reported to |
| 6729 | * accessibility services that query the screen. |
| 6730 | * |
| 6731 | * @param mode How to determine whether this view is important for accessibility. |
| 6732 | * |
| 6733 | * @attr ref android.R.styleable#View_importantForAccessibility |
| 6734 | * |
| 6735 | * @see #IMPORTANT_FOR_ACCESSIBILITY_YES |
| 6736 | * @see #IMPORTANT_FOR_ACCESSIBILITY_NO |
| 6737 | * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 6738 | */ |
| 6739 | public void setImportantForAccessibility(int mode) { |
| 6740 | if (mode != getImportantForAccessibility()) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6741 | mPrivateFlags2 &= ~PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK; |
| 6742 | mPrivateFlags2 |= (mode << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT) |
| 6743 | & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6744 | notifyAccessibilityStateChanged(); |
| 6745 | } |
| 6746 | } |
| 6747 | |
| 6748 | /** |
| 6749 | * Gets whether this view should be exposed for accessibility. |
| 6750 | * |
| 6751 | * @return Whether the view is exposed for accessibility. |
| 6752 | * |
| 6753 | * @hide |
| 6754 | */ |
| 6755 | public boolean isImportantForAccessibility() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6756 | final int mode = (mPrivateFlags2 & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK) |
| 6757 | >> PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6758 | switch (mode) { |
| 6759 | case IMPORTANT_FOR_ACCESSIBILITY_YES: |
| 6760 | return true; |
| 6761 | case IMPORTANT_FOR_ACCESSIBILITY_NO: |
| 6762 | return false; |
| 6763 | case IMPORTANT_FOR_ACCESSIBILITY_AUTO: |
Svetoslav Ganov | 34caec9 | 2012-07-19 18:07:58 -0700 | [diff] [blame] | 6764 | return isActionableForAccessibility() || hasListenersForAccessibility() |
| 6765 | || getAccessibilityNodeProvider() != null; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6766 | default: |
| 6767 | throw new IllegalArgumentException("Unknow important for accessibility mode: " |
| 6768 | + mode); |
| 6769 | } |
| 6770 | } |
| 6771 | |
| 6772 | /** |
| 6773 | * Gets the parent for accessibility purposes. Note that the parent for |
| 6774 | * accessibility is not necessary the immediate parent. It is the first |
| 6775 | * predecessor that is important for accessibility. |
| 6776 | * |
| 6777 | * @return The parent for accessibility purposes. |
| 6778 | */ |
| 6779 | public ViewParent getParentForAccessibility() { |
| 6780 | if (mParent instanceof View) { |
| 6781 | View parentView = (View) mParent; |
| 6782 | if (parentView.includeForAccessibility()) { |
| 6783 | return mParent; |
| 6784 | } else { |
| 6785 | return mParent.getParentForAccessibility(); |
| 6786 | } |
| 6787 | } |
| 6788 | return null; |
| 6789 | } |
| 6790 | |
| 6791 | /** |
| 6792 | * Adds the children of a given View for accessibility. Since some Views are |
| 6793 | * not important for accessibility the children for accessibility are not |
| 6794 | * necessarily direct children of the riew, rather they are the first level of |
| 6795 | * descendants important for accessibility. |
| 6796 | * |
| 6797 | * @param children The list of children for accessibility. |
| 6798 | */ |
| 6799 | public void addChildrenForAccessibility(ArrayList<View> children) { |
| 6800 | if (includeForAccessibility()) { |
| 6801 | children.add(this); |
| 6802 | } |
| 6803 | } |
| 6804 | |
| 6805 | /** |
| 6806 | * Whether to regard this view for accessibility. A view is regarded for |
| 6807 | * accessibility if it is important for accessibility or the querying |
| 6808 | * accessibility service has explicitly requested that view not |
| 6809 | * important for accessibility are regarded. |
| 6810 | * |
| 6811 | * @return Whether to regard the view for accessibility. |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6812 | * |
| 6813 | * @hide |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6814 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6815 | public boolean includeForAccessibility() { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6816 | if (mAttachInfo != null) { |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 6817 | return mAttachInfo.mIncludeNotImportantViews || isImportantForAccessibility(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6818 | } |
| 6819 | return false; |
| 6820 | } |
| 6821 | |
| 6822 | /** |
| 6823 | * Returns whether the View is considered actionable from |
| 6824 | * accessibility perspective. Such view are important for |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 6825 | * accessibility. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6826 | * |
| 6827 | * @return True if the view is actionable for accessibility. |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6828 | * |
| 6829 | * @hide |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6830 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6831 | public boolean isActionableForAccessibility() { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6832 | return (isClickable() || isLongClickable() || isFocusable()); |
| 6833 | } |
| 6834 | |
| 6835 | /** |
| 6836 | * Returns whether the View has registered callbacks wich makes it |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 6837 | * important for accessibility. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6838 | * |
| 6839 | * @return True if the view is actionable for accessibility. |
| 6840 | */ |
| 6841 | private boolean hasListenersForAccessibility() { |
| 6842 | ListenerInfo info = getListenerInfo(); |
| 6843 | return mTouchDelegate != null || info.mOnKeyListener != null |
| 6844 | || info.mOnTouchListener != null || info.mOnGenericMotionListener != null |
| 6845 | || info.mOnHoverListener != null || info.mOnDragListener != null; |
| 6846 | } |
| 6847 | |
| 6848 | /** |
| 6849 | * Notifies accessibility services that some view's important for |
| 6850 | * accessibility state has changed. Note that such notifications |
| 6851 | * are made at most once every |
| 6852 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()} |
| 6853 | * to avoid unnecessary load to the system. Also once a view has |
| 6854 | * made a notifucation this method is a NOP until the notification has |
| 6855 | * been sent to clients. |
| 6856 | * |
| 6857 | * @hide |
| 6858 | * |
| 6859 | * TODO: Makse sure this method is called for any view state change |
| 6860 | * that is interesting for accessilility purposes. |
| 6861 | */ |
| 6862 | public void notifyAccessibilityStateChanged() { |
Svetoslav Ganov | c406be9 | 2012-05-11 16:12:32 -0700 | [diff] [blame] | 6863 | if (!AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 6864 | return; |
| 6865 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6866 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_STATE_CHANGED) == 0) { |
| 6867 | mPrivateFlags2 |= PFLAG2_ACCESSIBILITY_STATE_CHANGED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6868 | if (mParent != null) { |
| 6869 | mParent.childAccessibilityStateChanged(this); |
| 6870 | } |
| 6871 | } |
| 6872 | } |
| 6873 | |
| 6874 | /** |
| 6875 | * Reset the state indicating the this view has requested clients |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 6876 | * interested in its accessibility state to be notified. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6877 | * |
| 6878 | * @hide |
| 6879 | */ |
| 6880 | public void resetAccessibilityStateChanged() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6881 | mPrivateFlags2 &= ~PFLAG2_ACCESSIBILITY_STATE_CHANGED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6882 | } |
| 6883 | |
| 6884 | /** |
| 6885 | * Performs the specified accessibility action on the view. For |
| 6886 | * possible accessibility actions look at {@link AccessibilityNodeInfo}. |
Svetoslav Ganov | 96985fc | 2012-10-09 16:25:54 -0700 | [diff] [blame] | 6887 | * <p> |
| 6888 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 6889 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 6890 | * {@link AccessibilityDelegate#performAccessibilityAction(View, int, Bundle)} |
| 6891 | * is responsible for handling this call. |
| 6892 | * </p> |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6893 | * |
| 6894 | * @param action The action to perform. |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6895 | * @param arguments Optional action arguments. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6896 | * @return Whether the action was performed. |
| 6897 | */ |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6898 | public boolean performAccessibilityAction(int action, Bundle arguments) { |
alanv | 8eeefef | 2012-05-07 16:57:53 -0700 | [diff] [blame] | 6899 | if (mAccessibilityDelegate != null) { |
| 6900 | return mAccessibilityDelegate.performAccessibilityAction(this, action, arguments); |
| 6901 | } else { |
| 6902 | return performAccessibilityActionInternal(action, arguments); |
| 6903 | } |
| 6904 | } |
| 6905 | |
| 6906 | /** |
| 6907 | * @see #performAccessibilityAction(int, Bundle) |
| 6908 | * |
| 6909 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 6910 | */ |
| 6911 | boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6912 | switch (action) { |
| 6913 | case AccessibilityNodeInfo.ACTION_CLICK: { |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6914 | if (isClickable()) { |
Svetoslav Ganov | 96985fc | 2012-10-09 16:25:54 -0700 | [diff] [blame] | 6915 | performClick(); |
| 6916 | return true; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6917 | } |
| 6918 | } break; |
| 6919 | case AccessibilityNodeInfo.ACTION_LONG_CLICK: { |
| 6920 | if (isLongClickable()) { |
Svetoslav Ganov | 96985fc | 2012-10-09 16:25:54 -0700 | [diff] [blame] | 6921 | performLongClick(); |
| 6922 | return true; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6923 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6924 | } break; |
| 6925 | case AccessibilityNodeInfo.ACTION_FOCUS: { |
| 6926 | if (!hasFocus()) { |
| 6927 | // Get out of touch mode since accessibility |
| 6928 | // wants to move focus around. |
| 6929 | getViewRootImpl().ensureTouchMode(false); |
| 6930 | return requestFocus(); |
| 6931 | } |
| 6932 | } break; |
| 6933 | case AccessibilityNodeInfo.ACTION_CLEAR_FOCUS: { |
| 6934 | if (hasFocus()) { |
| 6935 | clearFocus(); |
| 6936 | return !isFocused(); |
| 6937 | } |
| 6938 | } break; |
| 6939 | case AccessibilityNodeInfo.ACTION_SELECT: { |
| 6940 | if (!isSelected()) { |
| 6941 | setSelected(true); |
| 6942 | return isSelected(); |
| 6943 | } |
| 6944 | } break; |
| 6945 | case AccessibilityNodeInfo.ACTION_CLEAR_SELECTION: { |
| 6946 | if (isSelected()) { |
| 6947 | setSelected(false); |
| 6948 | return !isSelected(); |
| 6949 | } |
| 6950 | } break; |
| 6951 | case AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS: { |
Svetoslav Ganov | 27e2da7 | 2012-07-02 18:12:00 -0700 | [diff] [blame] | 6952 | if (!isAccessibilityFocused()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6953 | return requestAccessibilityFocus(); |
| 6954 | } |
| 6955 | } break; |
| 6956 | case AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS: { |
| 6957 | if (isAccessibilityFocused()) { |
| 6958 | clearAccessibilityFocus(); |
| 6959 | return true; |
| 6960 | } |
| 6961 | } break; |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6962 | case AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY: { |
| 6963 | if (arguments != null) { |
| 6964 | final int granularity = arguments.getInt( |
| 6965 | AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT); |
| 6966 | return nextAtGranularity(granularity); |
| 6967 | } |
| 6968 | } break; |
| 6969 | case AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY: { |
| 6970 | if (arguments != null) { |
| 6971 | final int granularity = arguments.getInt( |
| 6972 | AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT); |
| 6973 | return previousAtGranularity(granularity); |
| 6974 | } |
| 6975 | } break; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6976 | } |
| 6977 | return false; |
| 6978 | } |
| 6979 | |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6980 | private boolean nextAtGranularity(int granularity) { |
| 6981 | CharSequence text = getIterableTextForAccessibility(); |
Svetoslav Ganov | 64899e5 | 2012-05-15 21:09:30 -0700 | [diff] [blame] | 6982 | if (text == null || text.length() == 0) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6983 | return false; |
| 6984 | } |
| 6985 | TextSegmentIterator iterator = getIteratorForGranularity(granularity); |
| 6986 | if (iterator == null) { |
| 6987 | return false; |
| 6988 | } |
| 6989 | final int current = getAccessibilityCursorPosition(); |
| 6990 | final int[] range = iterator.following(current); |
| 6991 | if (range == null) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6992 | return false; |
| 6993 | } |
| 6994 | final int start = range[0]; |
| 6995 | final int end = range[1]; |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 6996 | setAccessibilityCursorPosition(end); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6997 | sendViewTextTraversedAtGranularityEvent( |
| 6998 | AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, |
| 6999 | granularity, start, end); |
| 7000 | return true; |
| 7001 | } |
| 7002 | |
| 7003 | private boolean previousAtGranularity(int granularity) { |
| 7004 | CharSequence text = getIterableTextForAccessibility(); |
Svetoslav Ganov | 64899e5 | 2012-05-15 21:09:30 -0700 | [diff] [blame] | 7005 | if (text == null || text.length() == 0) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7006 | return false; |
| 7007 | } |
| 7008 | TextSegmentIterator iterator = getIteratorForGranularity(granularity); |
| 7009 | if (iterator == null) { |
| 7010 | return false; |
| 7011 | } |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 7012 | int current = getAccessibilityCursorPosition(); |
| 7013 | if (current == ACCESSIBILITY_CURSOR_POSITION_UNDEFINED) { |
| 7014 | current = text.length(); |
Svetoslav Ganov | 02c6fca | 2012-11-26 17:32:17 -0800 | [diff] [blame] | 7015 | setAccessibilityCursorPosition(current); |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 7016 | } else if (granularity == AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER) { |
| 7017 | // When traversing by character we always put the cursor after the character |
| 7018 | // to ease edit and have to compensate before asking the for previous segment. |
| 7019 | current--; |
Svetoslav Ganov | 02c6fca | 2012-11-26 17:32:17 -0800 | [diff] [blame] | 7020 | setAccessibilityCursorPosition(current); |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 7021 | } |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7022 | final int[] range = iterator.preceding(current); |
| 7023 | if (range == null) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7024 | return false; |
| 7025 | } |
| 7026 | final int start = range[0]; |
| 7027 | final int end = range[1]; |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 7028 | // Always put the cursor after the character to ease edit. |
| 7029 | if (granularity == AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER) { |
| 7030 | setAccessibilityCursorPosition(end); |
| 7031 | } else { |
| 7032 | setAccessibilityCursorPosition(start); |
| 7033 | } |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7034 | sendViewTextTraversedAtGranularityEvent( |
| 7035 | AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, |
| 7036 | granularity, start, end); |
| 7037 | return true; |
| 7038 | } |
| 7039 | |
| 7040 | /** |
| 7041 | * Gets the text reported for accessibility purposes. |
| 7042 | * |
| 7043 | * @return The accessibility text. |
| 7044 | * |
| 7045 | * @hide |
| 7046 | */ |
| 7047 | public CharSequence getIterableTextForAccessibility() { |
Svetoslav Ganov | 05282aa | 2012-09-06 18:59:29 -0700 | [diff] [blame] | 7048 | return getContentDescription(); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7049 | } |
| 7050 | |
| 7051 | /** |
| 7052 | * @hide |
| 7053 | */ |
| 7054 | public int getAccessibilityCursorPosition() { |
| 7055 | return mAccessibilityCursorPosition; |
| 7056 | } |
| 7057 | |
| 7058 | /** |
| 7059 | * @hide |
| 7060 | */ |
| 7061 | public void setAccessibilityCursorPosition(int position) { |
| 7062 | mAccessibilityCursorPosition = position; |
| 7063 | } |
| 7064 | |
| 7065 | private void sendViewTextTraversedAtGranularityEvent(int action, int granularity, |
| 7066 | int fromIndex, int toIndex) { |
| 7067 | if (mParent == null) { |
| 7068 | return; |
| 7069 | } |
| 7070 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 7071 | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY); |
| 7072 | onInitializeAccessibilityEvent(event); |
| 7073 | onPopulateAccessibilityEvent(event); |
| 7074 | event.setFromIndex(fromIndex); |
| 7075 | event.setToIndex(toIndex); |
| 7076 | event.setAction(action); |
| 7077 | event.setMovementGranularity(granularity); |
| 7078 | mParent.requestSendAccessibilityEvent(this, event); |
| 7079 | } |
| 7080 | |
| 7081 | /** |
| 7082 | * @hide |
| 7083 | */ |
| 7084 | public TextSegmentIterator getIteratorForGranularity(int granularity) { |
| 7085 | switch (granularity) { |
| 7086 | case AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER: { |
| 7087 | CharSequence text = getIterableTextForAccessibility(); |
| 7088 | if (text != null && text.length() > 0) { |
| 7089 | CharacterTextSegmentIterator iterator = |
Svetoslav Ganov | bbd3155 | 2012-06-11 12:08:18 -0700 | [diff] [blame] | 7090 | CharacterTextSegmentIterator.getInstance( |
| 7091 | mContext.getResources().getConfiguration().locale); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7092 | iterator.initialize(text.toString()); |
| 7093 | return iterator; |
| 7094 | } |
| 7095 | } break; |
| 7096 | case AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD: { |
| 7097 | CharSequence text = getIterableTextForAccessibility(); |
| 7098 | if (text != null && text.length() > 0) { |
| 7099 | WordTextSegmentIterator iterator = |
Svetoslav Ganov | bbd3155 | 2012-06-11 12:08:18 -0700 | [diff] [blame] | 7100 | WordTextSegmentIterator.getInstance( |
| 7101 | mContext.getResources().getConfiguration().locale); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7102 | iterator.initialize(text.toString()); |
| 7103 | return iterator; |
| 7104 | } |
| 7105 | } break; |
| 7106 | case AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH: { |
| 7107 | CharSequence text = getIterableTextForAccessibility(); |
| 7108 | if (text != null && text.length() > 0) { |
| 7109 | ParagraphTextSegmentIterator iterator = |
| 7110 | ParagraphTextSegmentIterator.getInstance(); |
| 7111 | iterator.initialize(text.toString()); |
| 7112 | return iterator; |
| 7113 | } |
| 7114 | } break; |
| 7115 | } |
| 7116 | return null; |
| 7117 | } |
| 7118 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7119 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7120 | * @hide |
| 7121 | */ |
| 7122 | public void dispatchStartTemporaryDetach() { |
Svetoslav Ganov | 961bf0e | 2012-05-08 09:40:03 -0700 | [diff] [blame] | 7123 | clearAccessibilityFocus(); |
Romain Guy | 38c2ece | 2012-05-24 14:20:56 -0700 | [diff] [blame] | 7124 | clearDisplayList(); |
| 7125 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7126 | onStartTemporaryDetach(); |
| 7127 | } |
| 7128 | |
| 7129 | /** |
| 7130 | * 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] | 7131 | * {@link ViewGroup#detachViewFromParent(View) ViewGroup.detachViewFromParent}. |
| 7132 | * It will either be followed by {@link #onFinishTemporaryDetach()} or |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7133 | * {@link #onDetachedFromWindow()} when the container is done. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7134 | */ |
| 7135 | public void onStartTemporaryDetach() { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7136 | removeUnsetPressCallback(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7137 | mPrivateFlags |= PFLAG_CANCEL_NEXT_UP_EVENT; |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7138 | } |
| 7139 | |
| 7140 | /** |
| 7141 | * @hide |
| 7142 | */ |
| 7143 | public void dispatchFinishTemporaryDetach() { |
| 7144 | onFinishTemporaryDetach(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7145 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7146 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7147 | /** |
| 7148 | * Called after {@link #onStartTemporaryDetach} when the container is done |
| 7149 | * changing the view. |
| 7150 | */ |
| 7151 | public void onFinishTemporaryDetach() { |
| 7152 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7154 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7155 | * Return the global {@link KeyEvent.DispatcherState KeyEvent.DispatcherState} |
| 7156 | * for this view's window. Returns null if the view is not currently attached |
| 7157 | * 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] | 7158 | * just use the standard high-level event callbacks like |
| 7159 | * {@link #onKeyDown(int, KeyEvent)}. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7160 | */ |
| 7161 | public KeyEvent.DispatcherState getKeyDispatcherState() { |
| 7162 | return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null; |
| 7163 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7164 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7165 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7166 | * Dispatch a key event before it is processed by any input method |
| 7167 | * associated with the view hierarchy. This can be used to intercept |
| 7168 | * key events in special situations before the IME consumes them; a |
| 7169 | * typical example would be handling the BACK key to update the application's |
| 7170 | * UI instead of allowing the IME to see it and close itself. |
| 7171 | * |
| 7172 | * @param event The key event to be dispatched. |
| 7173 | * @return True if the event was handled, false otherwise. |
| 7174 | */ |
| 7175 | public boolean dispatchKeyEventPreIme(KeyEvent event) { |
| 7176 | return onKeyPreIme(event.getKeyCode(), event); |
| 7177 | } |
| 7178 | |
| 7179 | /** |
| 7180 | * Dispatch a key event to the next view on the focus path. This path runs |
| 7181 | * from the top of the view tree down to the currently focused view. If this |
| 7182 | * view has focus, it will dispatch to itself. Otherwise it will dispatch |
| 7183 | * the next node down the focus path. This method also fires any key |
| 7184 | * listeners. |
| 7185 | * |
| 7186 | * @param event The key event to be dispatched. |
| 7187 | * @return True if the event was handled, false otherwise. |
| 7188 | */ |
| 7189 | public boolean dispatchKeyEvent(KeyEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7190 | if (mInputEventConsistencyVerifier != null) { |
| 7191 | mInputEventConsistencyVerifier.onKeyEvent(event, 0); |
| 7192 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7193 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7194 | // Give any attached key listener a first crack at the event. |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 7195 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7196 | ListenerInfo li = mListenerInfo; |
| 7197 | if (li != null && li.mOnKeyListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 7198 | && li.mOnKeyListener.onKey(this, event.getKeyCode(), event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7199 | return true; |
| 7200 | } |
| 7201 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7202 | if (event.dispatch(this, mAttachInfo != null |
| 7203 | ? mAttachInfo.mKeyDispatchState : null, this)) { |
| 7204 | return true; |
| 7205 | } |
| 7206 | |
| 7207 | if (mInputEventConsistencyVerifier != null) { |
| 7208 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 7209 | } |
| 7210 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7211 | } |
| 7212 | |
| 7213 | /** |
| 7214 | * Dispatches a key shortcut event. |
| 7215 | * |
| 7216 | * @param event The key event to be dispatched. |
| 7217 | * @return True if the event was handled by the view, false otherwise. |
| 7218 | */ |
| 7219 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 7220 | return onKeyShortcut(event.getKeyCode(), event); |
| 7221 | } |
| 7222 | |
| 7223 | /** |
| 7224 | * Pass the touch screen motion event down to the target view, or this |
| 7225 | * view if it is the target. |
| 7226 | * |
| 7227 | * @param event The motion event to be dispatched. |
| 7228 | * @return True if the event was handled by the view, false otherwise. |
| 7229 | */ |
| 7230 | public boolean dispatchTouchEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7231 | if (mInputEventConsistencyVerifier != null) { |
| 7232 | mInputEventConsistencyVerifier.onTouchEvent(event, 0); |
| 7233 | } |
| 7234 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7235 | if (onFilterTouchEventForSecurity(event)) { |
| 7236 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7237 | ListenerInfo li = mListenerInfo; |
| 7238 | if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 7239 | && li.mOnTouchListener.onTouch(this, event)) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7240 | return true; |
| 7241 | } |
| 7242 | |
| 7243 | if (onTouchEvent(event)) { |
| 7244 | return true; |
| 7245 | } |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7246 | } |
| 7247 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7248 | if (mInputEventConsistencyVerifier != null) { |
| 7249 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7250 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7251 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7252 | } |
| 7253 | |
| 7254 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7255 | * Filter the touch event to apply security policies. |
| 7256 | * |
| 7257 | * @param event The motion event to be filtered. |
| 7258 | * @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] | 7259 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7260 | * @see #getFilterTouchesWhenObscured |
| 7261 | */ |
| 7262 | public boolean onFilterTouchEventForSecurity(MotionEvent event) { |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 7263 | //noinspection RedundantIfStatement |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7264 | if ((mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0 |
| 7265 | && (event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) { |
| 7266 | // Window is obscured, drop this touch. |
| 7267 | return false; |
| 7268 | } |
| 7269 | return true; |
| 7270 | } |
| 7271 | |
| 7272 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7273 | * Pass a trackball motion event down to the focused view. |
| 7274 | * |
| 7275 | * @param event The motion event to be dispatched. |
| 7276 | * @return True if the event was handled by the view, false otherwise. |
| 7277 | */ |
| 7278 | public boolean dispatchTrackballEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7279 | if (mInputEventConsistencyVerifier != null) { |
| 7280 | mInputEventConsistencyVerifier.onTrackballEvent(event, 0); |
| 7281 | } |
| 7282 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 7283 | return onTrackballEvent(event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7284 | } |
| 7285 | |
| 7286 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7287 | * Dispatch a generic motion event. |
| 7288 | * <p> |
| 7289 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 7290 | * 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] | 7291 | * 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] | 7292 | * to {@link #onHoverEvent(MotionEvent)}. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7293 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7294 | * |
| 7295 | * @param event The motion event to be dispatched. |
| 7296 | * @return True if the event was handled by the view, false otherwise. |
| 7297 | */ |
| 7298 | public boolean dispatchGenericMotionEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7299 | if (mInputEventConsistencyVerifier != null) { |
| 7300 | mInputEventConsistencyVerifier.onGenericMotionEvent(event, 0); |
| 7301 | } |
| 7302 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7303 | final int source = event.getSource(); |
| 7304 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 7305 | final int action = event.getAction(); |
| 7306 | if (action == MotionEvent.ACTION_HOVER_ENTER |
| 7307 | || action == MotionEvent.ACTION_HOVER_MOVE |
| 7308 | || action == MotionEvent.ACTION_HOVER_EXIT) { |
| 7309 | if (dispatchHoverEvent(event)) { |
| 7310 | return true; |
| 7311 | } |
| 7312 | } else if (dispatchGenericPointerEvent(event)) { |
| 7313 | return true; |
| 7314 | } |
| 7315 | } else if (dispatchGenericFocusedEvent(event)) { |
| 7316 | return true; |
| 7317 | } |
| 7318 | |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7319 | if (dispatchGenericMotionEventInternal(event)) { |
| 7320 | return true; |
| 7321 | } |
| 7322 | |
| 7323 | if (mInputEventConsistencyVerifier != null) { |
| 7324 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 7325 | } |
| 7326 | return false; |
| 7327 | } |
| 7328 | |
| 7329 | private boolean dispatchGenericMotionEventInternal(MotionEvent event) { |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 7330 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7331 | ListenerInfo li = mListenerInfo; |
| 7332 | if (li != null && li.mOnGenericMotionListener != null |
| 7333 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 7334 | && li.mOnGenericMotionListener.onGenericMotion(this, event)) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7335 | return true; |
| 7336 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7337 | |
| 7338 | if (onGenericMotionEvent(event)) { |
| 7339 | return true; |
| 7340 | } |
| 7341 | |
| 7342 | if (mInputEventConsistencyVerifier != null) { |
| 7343 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 7344 | } |
| 7345 | return false; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7346 | } |
| 7347 | |
| 7348 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7349 | * Dispatch a hover event. |
| 7350 | * <p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7351 | * Do not call this method directly. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7352 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7353 | * </p> |
| 7354 | * |
| 7355 | * @param event The motion event to be dispatched. |
| 7356 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7357 | */ |
| 7358 | protected boolean dispatchHoverEvent(MotionEvent event) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 7359 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7360 | ListenerInfo li = mListenerInfo; |
| 7361 | if (li != null && li.mOnHoverListener != null |
| 7362 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 7363 | && li.mOnHoverListener.onHover(this, event)) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7364 | return true; |
| 7365 | } |
| 7366 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7367 | return onHoverEvent(event); |
| 7368 | } |
| 7369 | |
| 7370 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 7371 | * Returns true if the view has a child to which it has recently sent |
| 7372 | * {@link MotionEvent#ACTION_HOVER_ENTER}. If this view is hovered and |
| 7373 | * it does not have a hovered child, then it must be the innermost hovered view. |
| 7374 | * @hide |
| 7375 | */ |
| 7376 | protected boolean hasHoveredChild() { |
| 7377 | return false; |
| 7378 | } |
| 7379 | |
| 7380 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7381 | * Dispatch a generic motion event to the view under the first pointer. |
| 7382 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7383 | * Do not call this method directly. |
| 7384 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7385 | * </p> |
| 7386 | * |
| 7387 | * @param event The motion event to be dispatched. |
| 7388 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7389 | */ |
| 7390 | protected boolean dispatchGenericPointerEvent(MotionEvent event) { |
| 7391 | return false; |
| 7392 | } |
| 7393 | |
| 7394 | /** |
| 7395 | * Dispatch a generic motion event to the currently focused view. |
| 7396 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7397 | * Do not call this method directly. |
| 7398 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7399 | * </p> |
| 7400 | * |
| 7401 | * @param event The motion event to be dispatched. |
| 7402 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7403 | */ |
| 7404 | protected boolean dispatchGenericFocusedEvent(MotionEvent event) { |
| 7405 | return false; |
| 7406 | } |
| 7407 | |
| 7408 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7409 | * Dispatch a pointer event. |
| 7410 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7411 | * Dispatches touch related pointer events to {@link #onTouchEvent(MotionEvent)} and all |
| 7412 | * other events to {@link #onGenericMotionEvent(MotionEvent)}. This separation of concerns |
| 7413 | * reinforces the invariant that {@link #onTouchEvent(MotionEvent)} is really about touches |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7414 | * and should not be expected to handle other pointing device features. |
| 7415 | * </p> |
| 7416 | * |
| 7417 | * @param event The motion event to be dispatched. |
| 7418 | * @return True if the event was handled by the view, false otherwise. |
| 7419 | * @hide |
| 7420 | */ |
| 7421 | public final boolean dispatchPointerEvent(MotionEvent event) { |
| 7422 | if (event.isTouchEvent()) { |
| 7423 | return dispatchTouchEvent(event); |
| 7424 | } else { |
| 7425 | return dispatchGenericMotionEvent(event); |
| 7426 | } |
| 7427 | } |
| 7428 | |
| 7429 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7430 | * Called when the window containing this view gains or loses window focus. |
| 7431 | * ViewGroups should override to route to their children. |
| 7432 | * |
| 7433 | * @param hasFocus True if the window containing this view now has focus, |
| 7434 | * false otherwise. |
| 7435 | */ |
| 7436 | public void dispatchWindowFocusChanged(boolean hasFocus) { |
| 7437 | onWindowFocusChanged(hasFocus); |
| 7438 | } |
| 7439 | |
| 7440 | /** |
| 7441 | * Called when the window containing this view gains or loses focus. Note |
| 7442 | * that this is separate from view focus: to receive key events, both |
| 7443 | * your view and its window must have focus. If a window is displayed |
| 7444 | * on top of yours that takes input focus, then your own window will lose |
| 7445 | * focus but the view focus will remain unchanged. |
| 7446 | * |
| 7447 | * @param hasWindowFocus True if the window containing this view now has |
| 7448 | * focus, false otherwise. |
| 7449 | */ |
| 7450 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 7451 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 7452 | if (!hasWindowFocus) { |
| 7453 | if (isPressed()) { |
| 7454 | setPressed(false); |
| 7455 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7456 | if (imm != null && (mPrivateFlags & PFLAG_FOCUSED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7457 | imm.focusOut(this); |
| 7458 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7459 | removeLongPressCallback(); |
Tony Wu | 26edf20 | 2010-09-13 19:54:00 +0800 | [diff] [blame] | 7460 | removeTapCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 7461 | onFocusLost(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7462 | } else if (imm != null && (mPrivateFlags & PFLAG_FOCUSED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7463 | imm.focusIn(this); |
| 7464 | } |
| 7465 | refreshDrawableState(); |
| 7466 | } |
| 7467 | |
| 7468 | /** |
| 7469 | * Returns true if this view is in a window that currently has window focus. |
| 7470 | * Note that this is not the same as the view itself having focus. |
| 7471 | * |
| 7472 | * @return True if this view is in a window that currently has window focus. |
| 7473 | */ |
| 7474 | public boolean hasWindowFocus() { |
| 7475 | return mAttachInfo != null && mAttachInfo.mHasWindowFocus; |
| 7476 | } |
| 7477 | |
| 7478 | /** |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7479 | * Dispatch a view visibility change down the view hierarchy. |
| 7480 | * ViewGroups should override to route to their children. |
| 7481 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 7482 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7483 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 7484 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7485 | */ |
| 7486 | protected void dispatchVisibilityChanged(View changedView, int visibility) { |
| 7487 | onVisibilityChanged(changedView, visibility); |
| 7488 | } |
| 7489 | |
| 7490 | /** |
| 7491 | * Called when the visibility of the view or an ancestor of the view is changed. |
| 7492 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 7493 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7494 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 7495 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7496 | */ |
| 7497 | protected void onVisibilityChanged(View changedView, int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 7498 | if (visibility == VISIBLE) { |
| 7499 | if (mAttachInfo != null) { |
| 7500 | initialAwakenScrollBars(); |
| 7501 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7502 | mPrivateFlags |= PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH; |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 7503 | } |
| 7504 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7505 | } |
| 7506 | |
| 7507 | /** |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7508 | * Dispatch a hint about whether this view is displayed. For instance, when |
| 7509 | * a View moves out of the screen, it might receives a display hint indicating |
| 7510 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 7511 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7512 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7513 | * @param hint A hint about whether or not this view is displayed: |
| 7514 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 7515 | */ |
| 7516 | public void dispatchDisplayHint(int hint) { |
| 7517 | onDisplayHint(hint); |
| 7518 | } |
| 7519 | |
| 7520 | /** |
| 7521 | * Gives this view a hint about whether is displayed or not. For instance, when |
| 7522 | * a View moves out of the screen, it might receives a display hint indicating |
| 7523 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 7524 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7525 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7526 | * @param hint A hint about whether or not this view is displayed: |
| 7527 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 7528 | */ |
| 7529 | protected void onDisplayHint(int hint) { |
| 7530 | } |
| 7531 | |
| 7532 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7533 | * Dispatch a window visibility change down the view hierarchy. |
| 7534 | * ViewGroups should override to route to their children. |
| 7535 | * |
| 7536 | * @param visibility The new visibility of the window. |
| 7537 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7538 | * @see #onWindowVisibilityChanged(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7539 | */ |
| 7540 | public void dispatchWindowVisibilityChanged(int visibility) { |
| 7541 | onWindowVisibilityChanged(visibility); |
| 7542 | } |
| 7543 | |
| 7544 | /** |
| 7545 | * Called when the window containing has change its visibility |
| 7546 | * (between {@link #GONE}, {@link #INVISIBLE}, and {@link #VISIBLE}). Note |
| 7547 | * that this tells you whether or not your window is being made visible |
| 7548 | * to the window manager; this does <em>not</em> tell you whether or not |
| 7549 | * your window is obscured by other windows on the screen, even if it |
| 7550 | * is itself visible. |
| 7551 | * |
| 7552 | * @param visibility The new visibility of the window. |
| 7553 | */ |
| 7554 | protected void onWindowVisibilityChanged(int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 7555 | if (visibility == VISIBLE) { |
| 7556 | initialAwakenScrollBars(); |
| 7557 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7558 | } |
| 7559 | |
| 7560 | /** |
| 7561 | * Returns the current visibility of the window this view is attached to |
| 7562 | * (either {@link #GONE}, {@link #INVISIBLE}, or {@link #VISIBLE}). |
| 7563 | * |
| 7564 | * @return Returns the current visibility of the view's window. |
| 7565 | */ |
| 7566 | public int getWindowVisibility() { |
| 7567 | return mAttachInfo != null ? mAttachInfo.mWindowVisibility : GONE; |
| 7568 | } |
| 7569 | |
| 7570 | /** |
| 7571 | * Retrieve the overall visible display size in which the window this view is |
| 7572 | * attached to has been positioned in. This takes into account screen |
| 7573 | * decorations above the window, for both cases where the window itself |
| 7574 | * is being position inside of them or the window is being placed under |
| 7575 | * then and covered insets are used for the window to position its content |
| 7576 | * inside. In effect, this tells you the available area where content can |
| 7577 | * be placed and remain visible to users. |
| 7578 | * |
| 7579 | * <p>This function requires an IPC back to the window manager to retrieve |
| 7580 | * the requested information, so should not be used in performance critical |
| 7581 | * code like drawing. |
| 7582 | * |
| 7583 | * @param outRect Filled in with the visible display frame. If the view |
| 7584 | * is not attached to a window, this is simply the raw display size. |
| 7585 | */ |
| 7586 | public void getWindowVisibleDisplayFrame(Rect outRect) { |
| 7587 | if (mAttachInfo != null) { |
| 7588 | try { |
| 7589 | mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect); |
| 7590 | } catch (RemoteException e) { |
| 7591 | return; |
| 7592 | } |
| 7593 | // XXX This is really broken, and probably all needs to be done |
| 7594 | // in the window manager, and we need to know more about whether |
| 7595 | // we want the area behind or in front of the IME. |
| 7596 | final Rect insets = mAttachInfo.mVisibleInsets; |
| 7597 | outRect.left += insets.left; |
| 7598 | outRect.top += insets.top; |
| 7599 | outRect.right -= insets.right; |
| 7600 | outRect.bottom -= insets.bottom; |
| 7601 | return; |
| 7602 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 7603 | // The view is not attached to a display so we don't have a context. |
| 7604 | // Make a best guess about the display size. |
| 7605 | Display d = DisplayManagerGlobal.getInstance().getRealDisplay(Display.DEFAULT_DISPLAY); |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 7606 | d.getRectSize(outRect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7607 | } |
| 7608 | |
| 7609 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7610 | * Dispatch a notification about a resource configuration change down |
| 7611 | * the view hierarchy. |
| 7612 | * ViewGroups should override to route to their children. |
| 7613 | * |
| 7614 | * @param newConfig The new resource configuration. |
| 7615 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7616 | * @see #onConfigurationChanged(android.content.res.Configuration) |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7617 | */ |
| 7618 | public void dispatchConfigurationChanged(Configuration newConfig) { |
| 7619 | onConfigurationChanged(newConfig); |
| 7620 | } |
| 7621 | |
| 7622 | /** |
| 7623 | * Called when the current configuration of the resources being used |
| 7624 | * by the application have changed. You can use this to decide when |
| 7625 | * to reload resources that can changed based on orientation and other |
| 7626 | * configuration characterstics. You only need to use this if you are |
| 7627 | * not relying on the normal {@link android.app.Activity} mechanism of |
| 7628 | * recreating the activity instance upon a configuration change. |
| 7629 | * |
| 7630 | * @param newConfig The new resource configuration. |
| 7631 | */ |
| 7632 | protected void onConfigurationChanged(Configuration newConfig) { |
| 7633 | } |
| 7634 | |
| 7635 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7636 | * Private function to aggregate all per-view attributes in to the view |
| 7637 | * root. |
| 7638 | */ |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7639 | void dispatchCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 7640 | performCollectViewAttributes(attachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7641 | } |
| 7642 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7643 | void performCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 7644 | if ((visibility & VISIBILITY_MASK) == VISIBLE) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7645 | if ((mViewFlags & KEEP_SCREEN_ON) == KEEP_SCREEN_ON) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7646 | attachInfo.mKeepScreenOn = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7647 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7648 | attachInfo.mSystemUiVisibility |= mSystemUiVisibility; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7649 | ListenerInfo li = mListenerInfo; |
| 7650 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7651 | attachInfo.mHasSystemUiListeners = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7652 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7653 | } |
| 7654 | } |
| 7655 | |
| 7656 | void needGlobalAttributesUpdate(boolean force) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7657 | final AttachInfo ai = mAttachInfo; |
Craig Mautner | 7eac0f5 | 2012-09-13 13:14:14 -0700 | [diff] [blame] | 7658 | if (ai != null && !ai.mRecomputeGlobalAttributes) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7659 | if (force || ai.mKeepScreenOn || (ai.mSystemUiVisibility != 0) |
| 7660 | || ai.mHasSystemUiListeners) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7661 | ai.mRecomputeGlobalAttributes = true; |
| 7662 | } |
| 7663 | } |
| 7664 | } |
| 7665 | |
| 7666 | /** |
| 7667 | * Returns whether the device is currently in touch mode. Touch mode is entered |
| 7668 | * once the user begins interacting with the device by touch, and affects various |
| 7669 | * things like whether focus is always visible to the user. |
| 7670 | * |
| 7671 | * @return Whether the device is in touch mode. |
| 7672 | */ |
| 7673 | @ViewDebug.ExportedProperty |
| 7674 | public boolean isInTouchMode() { |
| 7675 | if (mAttachInfo != null) { |
| 7676 | return mAttachInfo.mInTouchMode; |
| 7677 | } else { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7678 | return ViewRootImpl.isInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7679 | } |
| 7680 | } |
| 7681 | |
| 7682 | /** |
| 7683 | * Returns the context the view is running in, through which it can |
| 7684 | * access the current theme, resources, etc. |
| 7685 | * |
| 7686 | * @return The view's Context. |
| 7687 | */ |
| 7688 | @ViewDebug.CapturedViewProperty |
| 7689 | public final Context getContext() { |
| 7690 | return mContext; |
| 7691 | } |
| 7692 | |
| 7693 | /** |
| 7694 | * Handle a key event before it is processed by any input method |
| 7695 | * associated with the view hierarchy. This can be used to intercept |
| 7696 | * key events in special situations before the IME consumes them; a |
| 7697 | * typical example would be handling the BACK key to update the application's |
| 7698 | * UI instead of allowing the IME to see it and close itself. |
| 7699 | * |
| 7700 | * @param keyCode The value in event.getKeyCode(). |
| 7701 | * @param event Description of the key event. |
| 7702 | * @return If you handled the event, return true. If you want to allow the |
| 7703 | * event to be handled by the next receiver, return false. |
| 7704 | */ |
| 7705 | public boolean onKeyPreIme(int keyCode, KeyEvent event) { |
| 7706 | return false; |
| 7707 | } |
| 7708 | |
| 7709 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 7710 | * Default implementation of {@link KeyEvent.Callback#onKeyDown(int, KeyEvent) |
| 7711 | * KeyEvent.Callback.onKeyDown()}: perform press of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7712 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or {@link KeyEvent#KEYCODE_ENTER} |
| 7713 | * is released, if the view is enabled and clickable. |
| 7714 | * |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7715 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7716 | * although some may elect to do so in some situations. Do not rely on this to |
| 7717 | * catch software key presses. |
| 7718 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7719 | * @param keyCode A key code that represents the button pressed, from |
| 7720 | * {@link android.view.KeyEvent}. |
| 7721 | * @param event The KeyEvent object that defines the button action. |
| 7722 | */ |
| 7723 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 7724 | boolean result = false; |
| 7725 | |
| 7726 | switch (keyCode) { |
| 7727 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 7728 | case KeyEvent.KEYCODE_ENTER: { |
| 7729 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 7730 | return true; |
| 7731 | } |
| 7732 | // Long clickable items don't necessarily have to be clickable |
| 7733 | if (((mViewFlags & CLICKABLE) == CLICKABLE || |
| 7734 | (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) && |
| 7735 | (event.getRepeatCount() == 0)) { |
| 7736 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7737 | checkForLongClick(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7738 | return true; |
| 7739 | } |
| 7740 | break; |
| 7741 | } |
| 7742 | } |
| 7743 | return result; |
| 7744 | } |
| 7745 | |
| 7746 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7747 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 7748 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 7749 | * the event). |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7750 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7751 | * although some may elect to do so in some situations. Do not rely on this to |
| 7752 | * catch software key presses. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7753 | */ |
| 7754 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 7755 | return false; |
| 7756 | } |
| 7757 | |
| 7758 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 7759 | * Default implementation of {@link KeyEvent.Callback#onKeyUp(int, KeyEvent) |
| 7760 | * KeyEvent.Callback.onKeyUp()}: perform clicking of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7761 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or |
| 7762 | * {@link KeyEvent#KEYCODE_ENTER} is released. |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7763 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7764 | * although some may elect to do so in some situations. Do not rely on this to |
| 7765 | * catch software key presses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7766 | * |
| 7767 | * @param keyCode A key code that represents the button pressed, from |
| 7768 | * {@link android.view.KeyEvent}. |
| 7769 | * @param event The KeyEvent object that defines the button action. |
| 7770 | */ |
| 7771 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 7772 | boolean result = false; |
| 7773 | |
| 7774 | switch (keyCode) { |
| 7775 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 7776 | case KeyEvent.KEYCODE_ENTER: { |
| 7777 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 7778 | return true; |
| 7779 | } |
| 7780 | if ((mViewFlags & CLICKABLE) == CLICKABLE && isPressed()) { |
| 7781 | setPressed(false); |
| 7782 | |
| 7783 | if (!mHasPerformedLongPress) { |
| 7784 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7785 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7786 | |
| 7787 | result = performClick(); |
| 7788 | } |
| 7789 | } |
| 7790 | break; |
| 7791 | } |
| 7792 | } |
| 7793 | return result; |
| 7794 | } |
| 7795 | |
| 7796 | /** |
| 7797 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 7798 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 7799 | * the event). |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7800 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7801 | * although some may elect to do so in some situations. Do not rely on this to |
| 7802 | * catch software key presses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7803 | * |
| 7804 | * @param keyCode A key code that represents the button pressed, from |
| 7805 | * {@link android.view.KeyEvent}. |
| 7806 | * @param repeatCount The number of times the action was made. |
| 7807 | * @param event The KeyEvent object that defines the button action. |
| 7808 | */ |
| 7809 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 7810 | return false; |
| 7811 | } |
| 7812 | |
| 7813 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 7814 | * Called on the focused view when a key shortcut event is not handled. |
| 7815 | * Override this method to implement local key shortcuts for the View. |
| 7816 | * Key shortcuts can also be implemented by setting the |
| 7817 | * {@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] | 7818 | * |
| 7819 | * @param keyCode The value in event.getKeyCode(). |
| 7820 | * @param event Description of the key event. |
| 7821 | * @return If you handled the event, return true. If you want to allow the |
| 7822 | * event to be handled by the next receiver, return false. |
| 7823 | */ |
| 7824 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 7825 | return false; |
| 7826 | } |
| 7827 | |
| 7828 | /** |
| 7829 | * Check whether the called view is a text editor, in which case it |
| 7830 | * would make sense to automatically display a soft input window for |
| 7831 | * it. Subclasses should override this if they implement |
| 7832 | * {@link #onCreateInputConnection(EditorInfo)} to return true if |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7833 | * a call on that method would return a non-null InputConnection, and |
| 7834 | * they are really a first-class editor that the user would normally |
| 7835 | * start typing on when the go into a window containing your view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7836 | * |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7837 | * <p>The default implementation always returns false. This does |
| 7838 | * <em>not</em> mean that its {@link #onCreateInputConnection(EditorInfo)} |
| 7839 | * will not be called or the user can not otherwise perform edits on your |
| 7840 | * view; it is just a hint to the system that this is not the primary |
| 7841 | * purpose of this view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7842 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7843 | * @return Returns true if this view is a text editor, else false. |
| 7844 | */ |
| 7845 | public boolean onCheckIsTextEditor() { |
| 7846 | return false; |
| 7847 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7848 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7849 | /** |
| 7850 | * Create a new InputConnection for an InputMethod to interact |
| 7851 | * with the view. The default implementation returns null, since it doesn't |
| 7852 | * support input methods. You can override this to implement such support. |
| 7853 | * This is only needed for views that take focus and text input. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7854 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7855 | * <p>When implementing this, you probably also want to implement |
| 7856 | * {@link #onCheckIsTextEditor()} to indicate you will return a |
| 7857 | * non-null InputConnection. |
| 7858 | * |
| 7859 | * @param outAttrs Fill in with attribute information about the connection. |
| 7860 | */ |
| 7861 | public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
| 7862 | return null; |
| 7863 | } |
| 7864 | |
| 7865 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7866 | * Called by the {@link android.view.inputmethod.InputMethodManager} |
| 7867 | * when a view who is not the current |
| 7868 | * input connection target is trying to make a call on the manager. The |
| 7869 | * default implementation returns false; you can override this to return |
| 7870 | * true for certain views if you are performing InputConnection proxying |
| 7871 | * to them. |
| 7872 | * @param view The View that is making the InputMethodManager call. |
| 7873 | * @return Return true to allow the call, false to reject. |
| 7874 | */ |
| 7875 | public boolean checkInputConnectionProxy(View view) { |
| 7876 | return false; |
| 7877 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7878 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7879 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7880 | * Show the context menu for this view. It is not safe to hold on to the |
| 7881 | * menu after returning from this method. |
| 7882 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 7883 | * You should normally not overload this method. Overload |
| 7884 | * {@link #onCreateContextMenu(ContextMenu)} or define an |
| 7885 | * {@link OnCreateContextMenuListener} to add items to the context menu. |
| 7886 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7887 | * @param menu The context menu to populate |
| 7888 | */ |
| 7889 | public void createContextMenu(ContextMenu menu) { |
| 7890 | ContextMenuInfo menuInfo = getContextMenuInfo(); |
| 7891 | |
| 7892 | // Sets the current menu info so all items added to menu will have |
| 7893 | // my extra info set. |
| 7894 | ((MenuBuilder)menu).setCurrentMenuInfo(menuInfo); |
| 7895 | |
| 7896 | onCreateContextMenu(menu); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7897 | ListenerInfo li = mListenerInfo; |
| 7898 | if (li != null && li.mOnCreateContextMenuListener != null) { |
| 7899 | li.mOnCreateContextMenuListener.onCreateContextMenu(menu, this, menuInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7900 | } |
| 7901 | |
| 7902 | // Clear the extra information so subsequent items that aren't mine don't |
| 7903 | // have my extra info. |
| 7904 | ((MenuBuilder)menu).setCurrentMenuInfo(null); |
| 7905 | |
| 7906 | if (mParent != null) { |
| 7907 | mParent.createContextMenu(menu); |
| 7908 | } |
| 7909 | } |
| 7910 | |
| 7911 | /** |
| 7912 | * Views should implement this if they have extra information to associate |
| 7913 | * with the context menu. The return result is supplied as a parameter to |
| 7914 | * the {@link OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} |
| 7915 | * callback. |
| 7916 | * |
| 7917 | * @return Extra information about the item for which the context menu |
| 7918 | * should be shown. This information will vary across different |
| 7919 | * subclasses of View. |
| 7920 | */ |
| 7921 | protected ContextMenuInfo getContextMenuInfo() { |
| 7922 | return null; |
| 7923 | } |
| 7924 | |
| 7925 | /** |
| 7926 | * Views should implement this if the view itself is going to add items to |
| 7927 | * the context menu. |
| 7928 | * |
| 7929 | * @param menu the context menu to populate |
| 7930 | */ |
| 7931 | protected void onCreateContextMenu(ContextMenu menu) { |
| 7932 | } |
| 7933 | |
| 7934 | /** |
| 7935 | * Implement this method to handle trackball motion events. The |
| 7936 | * <em>relative</em> movement of the trackball since the last event |
| 7937 | * can be retrieve with {@link MotionEvent#getX MotionEvent.getX()} and |
| 7938 | * {@link MotionEvent#getY MotionEvent.getY()}. These are normalized so |
| 7939 | * that a movement of 1 corresponds to the user pressing one DPAD key (so |
| 7940 | * they will often be fractional values, representing the more fine-grained |
| 7941 | * movement information available from a trackball). |
| 7942 | * |
| 7943 | * @param event The motion event. |
| 7944 | * @return True if the event was handled, false otherwise. |
| 7945 | */ |
| 7946 | public boolean onTrackballEvent(MotionEvent event) { |
| 7947 | return false; |
| 7948 | } |
| 7949 | |
| 7950 | /** |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7951 | * Implement this method to handle generic motion events. |
| 7952 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7953 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 7954 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7955 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 7956 | * the class of input that was received. Implementations of this method |
| 7957 | * must examine the bits in the source before processing the event. |
| 7958 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7959 | * </p><p> |
| 7960 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 7961 | * are delivered to the view under the pointer. All other generic motion events are |
| 7962 | * delivered to the focused view. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7963 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 7964 | * <pre> public boolean onGenericMotionEvent(MotionEvent event) { |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7965 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7966 | * if (event.getAction() == MotionEvent.ACTION_MOVE) { |
| 7967 | * // process the joystick movement... |
| 7968 | * return true; |
| 7969 | * } |
| 7970 | * } |
| 7971 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 7972 | * switch (event.getAction()) { |
| 7973 | * case MotionEvent.ACTION_HOVER_MOVE: |
| 7974 | * // process the mouse hover movement... |
| 7975 | * return true; |
| 7976 | * case MotionEvent.ACTION_SCROLL: |
| 7977 | * // process the scroll wheel movement... |
| 7978 | * return true; |
| 7979 | * } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7980 | * } |
| 7981 | * return super.onGenericMotionEvent(event); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 7982 | * }</pre> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7983 | * |
| 7984 | * @param event The generic motion event being processed. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7985 | * @return True if the event was handled, false otherwise. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7986 | */ |
| 7987 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 7988 | return false; |
| 7989 | } |
| 7990 | |
| 7991 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7992 | * Implement this method to handle hover events. |
| 7993 | * <p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7994 | * This method is called whenever a pointer is hovering into, over, or out of the |
| 7995 | * bounds of a view and the view is not currently being touched. |
| 7996 | * Hover events are represented as pointer events with action |
| 7997 | * {@link MotionEvent#ACTION_HOVER_ENTER}, {@link MotionEvent#ACTION_HOVER_MOVE}, |
| 7998 | * or {@link MotionEvent#ACTION_HOVER_EXIT}. |
| 7999 | * </p> |
| 8000 | * <ul> |
| 8001 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_ENTER} |
| 8002 | * when the pointer enters the bounds of the view.</li> |
| 8003 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_MOVE} |
| 8004 | * when the pointer has already entered the bounds of the view and has moved.</li> |
| 8005 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_EXIT} |
| 8006 | * when the pointer has exited the bounds of the view or when the pointer is |
| 8007 | * about to go down due to a button click, tap, or similar user action that |
| 8008 | * causes the view to be touched.</li> |
| 8009 | * </ul> |
| 8010 | * <p> |
| 8011 | * The view should implement this method to return true to indicate that it is |
| 8012 | * handling the hover event, such as by changing its drawable state. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8013 | * </p><p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8014 | * The default implementation calls {@link #setHovered} to update the hovered state |
| 8015 | * 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] | 8016 | * is enabled and is clickable. The default implementation also sends hover |
| 8017 | * accessibility events. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8018 | * </p> |
| 8019 | * |
| 8020 | * @param event The motion event that describes the hover. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8021 | * @return True if the view handled the hover event. |
| 8022 | * |
| 8023 | * @see #isHovered |
| 8024 | * @see #setHovered |
| 8025 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8026 | */ |
| 8027 | public boolean onHoverEvent(MotionEvent event) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8028 | // The root view may receive hover (or touch) events that are outside the bounds of |
| 8029 | // the window. This code ensures that we only send accessibility events for |
| 8030 | // hovers that are actually within the bounds of the root view. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8031 | final int action = event.getActionMasked(); |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8032 | if (!mSendingHoverAccessibilityEvents) { |
| 8033 | if ((action == MotionEvent.ACTION_HOVER_ENTER |
| 8034 | || action == MotionEvent.ACTION_HOVER_MOVE) |
| 8035 | && !hasHoveredChild() |
| 8036 | && pointInView(event.getX(), event.getY())) { |
Svetoslav Ganov | 8ffe8b3 | 2012-06-15 10:31:31 -0700 | [diff] [blame] | 8037 | sendAccessibilityHoverEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8038 | mSendingHoverAccessibilityEvents = true; |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8039 | } |
| 8040 | } else { |
| 8041 | if (action == MotionEvent.ACTION_HOVER_EXIT |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8042 | || (action == MotionEvent.ACTION_MOVE |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8043 | && !pointInView(event.getX(), event.getY()))) { |
| 8044 | mSendingHoverAccessibilityEvents = false; |
Svetoslav Ganov | 8ffe8b3 | 2012-06-15 10:31:31 -0700 | [diff] [blame] | 8045 | sendAccessibilityHoverEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8046 | // If the window does not have input focus we take away accessibility |
| 8047 | // focus as soon as the user stop hovering over the view. |
Jeff Brown | 59a422e | 2012-04-19 15:19:19 -0700 | [diff] [blame] | 8048 | if (mAttachInfo != null && !mAttachInfo.mHasWindowFocus) { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 8049 | getViewRootImpl().setAccessibilityFocus(null, null); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8050 | } |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8051 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 8052 | } |
| 8053 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 8054 | if (isHoverable()) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8055 | switch (action) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8056 | case MotionEvent.ACTION_HOVER_ENTER: |
| 8057 | setHovered(true); |
| 8058 | break; |
| 8059 | case MotionEvent.ACTION_HOVER_EXIT: |
| 8060 | setHovered(false); |
| 8061 | break; |
| 8062 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 8063 | |
| 8064 | // Dispatch the event to onGenericMotionEvent before returning true. |
| 8065 | // This is to provide compatibility with existing applications that |
| 8066 | // handled HOVER_MOVE events in onGenericMotionEvent and that would |
| 8067 | // break because of the new default handling for hoverable views |
| 8068 | // in onHoverEvent. |
| 8069 | // Note that onGenericMotionEvent will be called by default when |
| 8070 | // onHoverEvent returns false (refer to dispatchGenericMotionEvent). |
| 8071 | dispatchGenericMotionEventInternal(event); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8072 | return true; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8073 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8074 | |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 8075 | return false; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8076 | } |
| 8077 | |
| 8078 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 8079 | * Returns true if the view should handle {@link #onHoverEvent} |
| 8080 | * by calling {@link #setHovered} to change its hovered state. |
| 8081 | * |
| 8082 | * @return True if the view is hoverable. |
| 8083 | */ |
| 8084 | private boolean isHoverable() { |
| 8085 | final int viewFlags = mViewFlags; |
| 8086 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
| 8087 | return false; |
| 8088 | } |
| 8089 | |
| 8090 | return (viewFlags & CLICKABLE) == CLICKABLE |
| 8091 | || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 8092 | } |
| 8093 | |
| 8094 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8095 | * Returns true if the view is currently hovered. |
| 8096 | * |
| 8097 | * @return True if the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8098 | * |
| 8099 | * @see #setHovered |
| 8100 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8101 | */ |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8102 | @ViewDebug.ExportedProperty |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8103 | public boolean isHovered() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8104 | return (mPrivateFlags & PFLAG_HOVERED) != 0; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8105 | } |
| 8106 | |
| 8107 | /** |
| 8108 | * Sets whether the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8109 | * <p> |
| 8110 | * Calling this method also changes the drawable state of the view. This |
| 8111 | * enables the view to react to hover by using different drawable resources |
| 8112 | * to change its appearance. |
| 8113 | * </p><p> |
| 8114 | * The {@link #onHoverChanged} method is called when the hovered state changes. |
| 8115 | * </p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8116 | * |
| 8117 | * @param hovered True if the view is hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8118 | * |
| 8119 | * @see #isHovered |
| 8120 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8121 | */ |
| 8122 | public void setHovered(boolean hovered) { |
| 8123 | if (hovered) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8124 | if ((mPrivateFlags & PFLAG_HOVERED) == 0) { |
| 8125 | mPrivateFlags |= PFLAG_HOVERED; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8126 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8127 | onHoverChanged(true); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8128 | } |
| 8129 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8130 | if ((mPrivateFlags & PFLAG_HOVERED) != 0) { |
| 8131 | mPrivateFlags &= ~PFLAG_HOVERED; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8132 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8133 | onHoverChanged(false); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8134 | } |
| 8135 | } |
| 8136 | } |
| 8137 | |
| 8138 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8139 | * Implement this method to handle hover state changes. |
| 8140 | * <p> |
| 8141 | * This method is called whenever the hover state changes as a result of a |
| 8142 | * call to {@link #setHovered}. |
| 8143 | * </p> |
| 8144 | * |
| 8145 | * @param hovered The current hover state, as returned by {@link #isHovered}. |
| 8146 | * |
| 8147 | * @see #isHovered |
| 8148 | * @see #setHovered |
| 8149 | */ |
| 8150 | public void onHoverChanged(boolean hovered) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8151 | } |
| 8152 | |
| 8153 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8154 | * Implement this method to handle touch screen motion events. |
| 8155 | * |
| 8156 | * @param event The motion event. |
| 8157 | * @return True if the event was handled, false otherwise. |
| 8158 | */ |
| 8159 | public boolean onTouchEvent(MotionEvent event) { |
| 8160 | final int viewFlags = mViewFlags; |
| 8161 | |
| 8162 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8163 | if (event.getAction() == MotionEvent.ACTION_UP && (mPrivateFlags & PFLAG_PRESSED) != 0) { |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8164 | setPressed(false); |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 8165 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8166 | // A disabled view that is clickable still consumes the touch |
| 8167 | // events, it just doesn't respond to them. |
| 8168 | return (((viewFlags & CLICKABLE) == CLICKABLE || |
| 8169 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)); |
| 8170 | } |
| 8171 | |
| 8172 | if (mTouchDelegate != null) { |
| 8173 | if (mTouchDelegate.onTouchEvent(event)) { |
| 8174 | return true; |
| 8175 | } |
| 8176 | } |
| 8177 | |
| 8178 | if (((viewFlags & CLICKABLE) == CLICKABLE || |
| 8179 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)) { |
| 8180 | switch (event.getAction()) { |
| 8181 | case MotionEvent.ACTION_UP: |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8182 | boolean prepressed = (mPrivateFlags & PFLAG_PREPRESSED) != 0; |
| 8183 | if ((mPrivateFlags & PFLAG_PRESSED) != 0 || prepressed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8184 | // take focus if we don't have it already and we should in |
| 8185 | // touch mode. |
| 8186 | boolean focusTaken = false; |
| 8187 | if (isFocusable() && isFocusableInTouchMode() && !isFocused()) { |
| 8188 | focusTaken = requestFocus(); |
| 8189 | } |
| 8190 | |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 8191 | if (prepressed) { |
| 8192 | // The button is being released before we actually |
| 8193 | // showed it as pressed. Make it show the pressed |
| 8194 | // state now (before scheduling the click) to ensure |
| 8195 | // the user sees it. |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8196 | setPressed(true); |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 8197 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8199 | if (!mHasPerformedLongPress) { |
| 8200 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8201 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8202 | |
| 8203 | // Only perform take click actions if we were in the pressed state |
| 8204 | if (!focusTaken) { |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 8205 | // Use a Runnable and post this rather than calling |
| 8206 | // performClick directly. This lets other visual state |
| 8207 | // of the view update before click actions start. |
| 8208 | if (mPerformClick == null) { |
| 8209 | mPerformClick = new PerformClick(); |
| 8210 | } |
| 8211 | if (!post(mPerformClick)) { |
| 8212 | performClick(); |
| 8213 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8214 | } |
| 8215 | } |
| 8216 | |
| 8217 | if (mUnsetPressedState == null) { |
| 8218 | mUnsetPressedState = new UnsetPressedState(); |
| 8219 | } |
| 8220 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8221 | if (prepressed) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8222 | postDelayed(mUnsetPressedState, |
| 8223 | ViewConfiguration.getPressedStateDuration()); |
| 8224 | } else if (!post(mUnsetPressedState)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8225 | // If the post failed, unpress right now |
| 8226 | mUnsetPressedState.run(); |
| 8227 | } |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8228 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8229 | } |
| 8230 | break; |
| 8231 | |
| 8232 | case MotionEvent.ACTION_DOWN: |
Adam Powell | 3b02339 | 2010-03-11 16:30:28 -0800 | [diff] [blame] | 8233 | mHasPerformedLongPress = false; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8234 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 8235 | if (performButtonActionOnTouchDown(event)) { |
| 8236 | break; |
| 8237 | } |
| 8238 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8239 | // 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] | 8240 | boolean isInScrollingContainer = isInScrollingContainer(); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8241 | |
| 8242 | // For views inside a scrolling container, delay the pressed feedback for |
| 8243 | // a short period in case this is a scroll. |
| 8244 | if (isInScrollingContainer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8245 | mPrivateFlags |= PFLAG_PREPRESSED; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8246 | if (mPendingCheckForTap == null) { |
| 8247 | mPendingCheckForTap = new CheckForTap(); |
| 8248 | } |
| 8249 | postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); |
| 8250 | } else { |
| 8251 | // Not inside a scrolling container, so show the feedback right away |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8252 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8253 | checkForLongClick(0); |
| 8254 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8255 | break; |
| 8256 | |
| 8257 | case MotionEvent.ACTION_CANCEL: |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8258 | setPressed(false); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8259 | removeTapCallback(); |
Adam Powell | 5311c44 | 2012-10-22 12:15:49 -0700 | [diff] [blame] | 8260 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8261 | break; |
| 8262 | |
| 8263 | case MotionEvent.ACTION_MOVE: |
| 8264 | final int x = (int) event.getX(); |
| 8265 | final int y = (int) event.getY(); |
| 8266 | |
| 8267 | // Be lenient about moving outside of buttons |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8268 | if (!pointInView(x, y, mTouchSlop)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8269 | // Outside button |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8270 | removeTapCallback(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8271 | if ((mPrivateFlags & PFLAG_PRESSED) != 0) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8272 | // Remove any future long press/tap checks |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8273 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8274 | |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8275 | setPressed(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8276 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8277 | } |
| 8278 | break; |
| 8279 | } |
| 8280 | return true; |
| 8281 | } |
| 8282 | |
| 8283 | return false; |
| 8284 | } |
| 8285 | |
| 8286 | /** |
Adam Powell | 1029866 | 2011-08-14 18:26:30 -0700 | [diff] [blame] | 8287 | * @hide |
| 8288 | */ |
| 8289 | public boolean isInScrollingContainer() { |
| 8290 | ViewParent p = getParent(); |
| 8291 | while (p != null && p instanceof ViewGroup) { |
| 8292 | if (((ViewGroup) p).shouldDelayChildPressedState()) { |
| 8293 | return true; |
| 8294 | } |
| 8295 | p = p.getParent(); |
| 8296 | } |
| 8297 | return false; |
| 8298 | } |
| 8299 | |
| 8300 | /** |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8301 | * Remove the longpress detection timer. |
| 8302 | */ |
| 8303 | private void removeLongPressCallback() { |
| 8304 | if (mPendingCheckForLongPress != null) { |
| 8305 | removeCallbacks(mPendingCheckForLongPress); |
| 8306 | } |
| 8307 | } |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 8308 | |
| 8309 | /** |
| 8310 | * Remove the pending click action |
| 8311 | */ |
| 8312 | private void removePerformClickCallback() { |
| 8313 | if (mPerformClick != null) { |
| 8314 | removeCallbacks(mPerformClick); |
| 8315 | } |
| 8316 | } |
| 8317 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8318 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 8319 | * Remove the prepress detection timer. |
| 8320 | */ |
| 8321 | private void removeUnsetPressCallback() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8322 | if ((mPrivateFlags & PFLAG_PRESSED) != 0 && mUnsetPressedState != null) { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 8323 | setPressed(false); |
| 8324 | removeCallbacks(mUnsetPressedState); |
| 8325 | } |
| 8326 | } |
| 8327 | |
| 8328 | /** |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8329 | * Remove the tap detection timer. |
| 8330 | */ |
| 8331 | private void removeTapCallback() { |
| 8332 | if (mPendingCheckForTap != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8333 | mPrivateFlags &= ~PFLAG_PREPRESSED; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8334 | removeCallbacks(mPendingCheckForTap); |
| 8335 | } |
| 8336 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8337 | |
| 8338 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8339 | * Cancels a pending long press. Your subclass can use this if you |
| 8340 | * want the context menu to come up if the user presses and holds |
| 8341 | * at the same place, but you don't want it to come up if they press |
| 8342 | * and then move around enough to cause scrolling. |
| 8343 | */ |
| 8344 | public void cancelLongPress() { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8345 | removeLongPressCallback(); |
Adam Powell | 732ebb1 | 2010-02-02 15:28:14 -0800 | [diff] [blame] | 8346 | |
| 8347 | /* |
| 8348 | * The prepressed state handled by the tap callback is a display |
| 8349 | * construct, but the tap callback will post a long press callback |
| 8350 | * less its own timeout. Remove it here. |
| 8351 | */ |
| 8352 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8353 | } |
| 8354 | |
| 8355 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8356 | * Remove the pending callback for sending a |
| 8357 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 8358 | */ |
| 8359 | private void removeSendViewScrolledAccessibilityEventCallback() { |
| 8360 | if (mSendViewScrolledAccessibilityEvent != null) { |
| 8361 | removeCallbacks(mSendViewScrolledAccessibilityEvent); |
Svetoslav Ganov | 4a812ae | 2012-05-29 16:46:10 -0700 | [diff] [blame] | 8362 | mSendViewScrolledAccessibilityEvent.mIsPending = false; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8363 | } |
| 8364 | } |
| 8365 | |
| 8366 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8367 | * Sets the TouchDelegate for this View. |
| 8368 | */ |
| 8369 | public void setTouchDelegate(TouchDelegate delegate) { |
| 8370 | mTouchDelegate = delegate; |
| 8371 | } |
| 8372 | |
| 8373 | /** |
| 8374 | * Gets the TouchDelegate for this View. |
| 8375 | */ |
| 8376 | public TouchDelegate getTouchDelegate() { |
| 8377 | return mTouchDelegate; |
| 8378 | } |
| 8379 | |
| 8380 | /** |
| 8381 | * Set flags controlling behavior of this view. |
| 8382 | * |
| 8383 | * @param flags Constant indicating the value which should be set |
| 8384 | * @param mask Constant indicating the bit range that should be changed |
| 8385 | */ |
| 8386 | void setFlags(int flags, int mask) { |
| 8387 | int old = mViewFlags; |
| 8388 | mViewFlags = (mViewFlags & ~mask) | (flags & mask); |
| 8389 | |
| 8390 | int changed = mViewFlags ^ old; |
| 8391 | if (changed == 0) { |
| 8392 | return; |
| 8393 | } |
| 8394 | int privateFlags = mPrivateFlags; |
| 8395 | |
| 8396 | /* Check if the FOCUSABLE bit has changed */ |
| 8397 | if (((changed & FOCUSABLE_MASK) != 0) && |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8398 | ((privateFlags & PFLAG_HAS_BOUNDS) !=0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8399 | if (((old & FOCUSABLE_MASK) == FOCUSABLE) |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8400 | && ((privateFlags & PFLAG_FOCUSED) != 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8401 | /* Give up focus if we are no longer focusable */ |
| 8402 | clearFocus(); |
| 8403 | } else if (((old & FOCUSABLE_MASK) == NOT_FOCUSABLE) |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8404 | && ((privateFlags & PFLAG_FOCUSED) == 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8405 | /* |
| 8406 | * Tell the view system that we are now available to take focus |
| 8407 | * if no one else already has it. |
| 8408 | */ |
| 8409 | if (mParent != null) mParent.focusableViewAvailable(this); |
| 8410 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8411 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 8412 | notifyAccessibilityStateChanged(); |
| 8413 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8414 | } |
| 8415 | |
| 8416 | if ((flags & VISIBILITY_MASK) == VISIBLE) { |
| 8417 | if ((changed & VISIBILITY_MASK) != 0) { |
| 8418 | /* |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 8419 | * 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] | 8420 | * it was not visible. Marking it drawn ensures that the invalidation will |
| 8421 | * go through. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8422 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8423 | mPrivateFlags |= PFLAG_DRAWN; |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 8424 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8425 | |
| 8426 | needGlobalAttributesUpdate(true); |
| 8427 | |
| 8428 | // a view becoming visible is worth notifying the parent |
| 8429 | // about in case nothing has focus. even if this specific view |
| 8430 | // isn't focusable, it may contain something that is, so let |
| 8431 | // the root view try to give this focus if nothing else does. |
| 8432 | if ((mParent != null) && (mBottom > mTop) && (mRight > mLeft)) { |
| 8433 | mParent.focusableViewAvailable(this); |
| 8434 | } |
| 8435 | } |
| 8436 | } |
| 8437 | |
| 8438 | /* Check if the GONE bit has changed */ |
| 8439 | if ((changed & GONE) != 0) { |
| 8440 | needGlobalAttributesUpdate(false); |
| 8441 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8442 | |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 8443 | if (((mViewFlags & VISIBILITY_MASK) == GONE)) { |
| 8444 | if (hasFocus()) clearFocus(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8445 | clearAccessibilityFocus(); |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 8446 | destroyDrawingCache(); |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8447 | if (mParent instanceof View) { |
| 8448 | // GONE views noop invalidation, so invalidate the parent |
| 8449 | ((View) mParent).invalidate(true); |
| 8450 | } |
| 8451 | // Mark the view drawn to ensure that it gets invalidated properly the next |
| 8452 | // time it is visible and gets invalidated |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8453 | mPrivateFlags |= PFLAG_DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8454 | } |
| 8455 | if (mAttachInfo != null) { |
| 8456 | mAttachInfo.mViewVisibilityChanged = true; |
| 8457 | } |
| 8458 | } |
| 8459 | |
| 8460 | /* Check if the VISIBLE bit has changed */ |
| 8461 | if ((changed & INVISIBLE) != 0) { |
| 8462 | needGlobalAttributesUpdate(false); |
Chet Haase | c8a9a70 | 2011-06-17 12:13:42 -0700 | [diff] [blame] | 8463 | /* |
| 8464 | * If this view is becoming invisible, set the DRAWN flag so that |
| 8465 | * the next invalidate() will not be skipped. |
| 8466 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8467 | mPrivateFlags |= PFLAG_DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8468 | |
| 8469 | if (((mViewFlags & VISIBILITY_MASK) == INVISIBLE) && hasFocus()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8470 | // root view becoming invisible shouldn't clear focus and accessibility focus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8471 | if (getRootView() != this) { |
| 8472 | clearFocus(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8473 | clearAccessibilityFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8474 | } |
| 8475 | } |
| 8476 | if (mAttachInfo != null) { |
| 8477 | mAttachInfo.mViewVisibilityChanged = true; |
| 8478 | } |
| 8479 | } |
| 8480 | |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 8481 | if ((changed & VISIBILITY_MASK) != 0) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 8482 | if (mParent instanceof ViewGroup) { |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 8483 | ((ViewGroup) mParent).onChildVisibilityChanged(this, |
| 8484 | (changed & VISIBILITY_MASK), (flags & VISIBILITY_MASK)); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8485 | ((View) mParent).invalidate(true); |
Chet Haase | e4e6e20 | 2011-08-29 14:34:30 -0700 | [diff] [blame] | 8486 | } else if (mParent != null) { |
| 8487 | mParent.invalidateChild(this, null); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 8488 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 8489 | dispatchVisibilityChanged(this, (flags & VISIBILITY_MASK)); |
| 8490 | } |
| 8491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8492 | if ((changed & WILL_NOT_CACHE_DRAWING) != 0) { |
| 8493 | destroyDrawingCache(); |
| 8494 | } |
| 8495 | |
| 8496 | if ((changed & DRAWING_CACHE_ENABLED) != 0) { |
| 8497 | destroyDrawingCache(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8498 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8499 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8500 | } |
| 8501 | |
| 8502 | if ((changed & DRAWING_CACHE_QUALITY_MASK) != 0) { |
| 8503 | destroyDrawingCache(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8504 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8505 | } |
| 8506 | |
| 8507 | if ((changed & DRAW_MASK) != 0) { |
| 8508 | if ((mViewFlags & WILL_NOT_DRAW) != 0) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8509 | if (mBackground != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8510 | mPrivateFlags &= ~PFLAG_SKIP_DRAW; |
| 8511 | mPrivateFlags |= PFLAG_ONLY_DRAWS_BACKGROUND; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8512 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8513 | mPrivateFlags |= PFLAG_SKIP_DRAW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8514 | } |
| 8515 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8516 | mPrivateFlags &= ~PFLAG_SKIP_DRAW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8517 | } |
| 8518 | requestLayout(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8519 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8520 | } |
| 8521 | |
| 8522 | if ((changed & KEEP_SCREEN_ON) != 0) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8523 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8524 | mParent.recomputeViewAttributes(this); |
| 8525 | } |
| 8526 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8527 | |
| 8528 | if (AccessibilityManager.getInstance(mContext).isEnabled() |
| 8529 | && ((changed & FOCUSABLE) != 0 || (changed & CLICKABLE) != 0 |
| 8530 | || (changed & LONG_CLICKABLE) != 0 || (changed & ENABLED) != 0)) { |
| 8531 | notifyAccessibilityStateChanged(); |
| 8532 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8533 | } |
| 8534 | |
| 8535 | /** |
| 8536 | * Change the view's z order in the tree, so it's on top of other sibling |
| 8537 | * views |
| 8538 | */ |
| 8539 | public void bringToFront() { |
| 8540 | if (mParent != null) { |
| 8541 | mParent.bringChildToFront(this); |
| 8542 | } |
| 8543 | } |
| 8544 | |
| 8545 | /** |
| 8546 | * This is called in response to an internal scroll in this view (i.e., the |
| 8547 | * view scrolled its own contents). This is typically as a result of |
| 8548 | * {@link #scrollBy(int, int)} or {@link #scrollTo(int, int)} having been |
| 8549 | * called. |
| 8550 | * |
| 8551 | * @param l Current horizontal scroll origin. |
| 8552 | * @param t Current vertical scroll origin. |
| 8553 | * @param oldl Previous horizontal scroll origin. |
| 8554 | * @param oldt Previous vertical scroll origin. |
| 8555 | */ |
| 8556 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8557 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 8558 | postSendViewScrolledAccessibilityEventCallback(); |
| 8559 | } |
| 8560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8561 | mBackgroundSizeChanged = true; |
| 8562 | |
| 8563 | final AttachInfo ai = mAttachInfo; |
| 8564 | if (ai != null) { |
| 8565 | ai.mViewScrollChanged = true; |
| 8566 | } |
| 8567 | } |
| 8568 | |
| 8569 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8570 | * Interface definition for a callback to be invoked when the layout bounds of a view |
| 8571 | * changes due to layout processing. |
| 8572 | */ |
| 8573 | public interface OnLayoutChangeListener { |
| 8574 | /** |
| 8575 | * Called when the focus state of a view has changed. |
| 8576 | * |
| 8577 | * @param v The view whose state has changed. |
| 8578 | * @param left The new value of the view's left property. |
| 8579 | * @param top The new value of the view's top property. |
| 8580 | * @param right The new value of the view's right property. |
| 8581 | * @param bottom The new value of the view's bottom property. |
| 8582 | * @param oldLeft The previous value of the view's left property. |
| 8583 | * @param oldTop The previous value of the view's top property. |
| 8584 | * @param oldRight The previous value of the view's right property. |
| 8585 | * @param oldBottom The previous value of the view's bottom property. |
| 8586 | */ |
| 8587 | void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 8588 | int oldLeft, int oldTop, int oldRight, int oldBottom); |
| 8589 | } |
| 8590 | |
| 8591 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8592 | * This is called during layout when the size of this view has changed. If |
| 8593 | * you were just added to the view hierarchy, you're called with the old |
| 8594 | * values of 0. |
| 8595 | * |
| 8596 | * @param w Current width of this view. |
| 8597 | * @param h Current height of this view. |
| 8598 | * @param oldw Old width of this view. |
| 8599 | * @param oldh Old height of this view. |
| 8600 | */ |
| 8601 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 8602 | } |
| 8603 | |
| 8604 | /** |
| 8605 | * Called by draw to draw the child views. This may be overridden |
| 8606 | * by derived classes to gain control just before its children are drawn |
| 8607 | * (but after its own view has been drawn). |
| 8608 | * @param canvas the canvas on which to draw the view |
| 8609 | */ |
| 8610 | protected void dispatchDraw(Canvas canvas) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8612 | } |
| 8613 | |
| 8614 | /** |
| 8615 | * Gets the parent of this view. Note that the parent is a |
| 8616 | * ViewParent and not necessarily a View. |
| 8617 | * |
| 8618 | * @return Parent of this view. |
| 8619 | */ |
| 8620 | public final ViewParent getParent() { |
| 8621 | return mParent; |
| 8622 | } |
| 8623 | |
| 8624 | /** |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 8625 | * Set the horizontal scrolled position of your view. This will cause a call to |
| 8626 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8627 | * invalidated. |
| 8628 | * @param value the x position to scroll to |
| 8629 | */ |
| 8630 | public void setScrollX(int value) { |
| 8631 | scrollTo(value, mScrollY); |
| 8632 | } |
| 8633 | |
| 8634 | /** |
| 8635 | * Set the vertical scrolled position of your view. This will cause a call to |
| 8636 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8637 | * invalidated. |
| 8638 | * @param value the y position to scroll to |
| 8639 | */ |
| 8640 | public void setScrollY(int value) { |
| 8641 | scrollTo(mScrollX, value); |
| 8642 | } |
| 8643 | |
| 8644 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8645 | * Return the scrolled left position of this view. This is the left edge of |
| 8646 | * the displayed part of your view. You do not need to draw any pixels |
| 8647 | * farther left, since those are outside of the frame of your view on |
| 8648 | * screen. |
| 8649 | * |
| 8650 | * @return The left edge of the displayed part of your view, in pixels. |
| 8651 | */ |
| 8652 | public final int getScrollX() { |
| 8653 | return mScrollX; |
| 8654 | } |
| 8655 | |
| 8656 | /** |
| 8657 | * Return the scrolled top position of this view. This is the top edge of |
| 8658 | * the displayed part of your view. You do not need to draw any pixels above |
| 8659 | * it, since those are outside of the frame of your view on screen. |
| 8660 | * |
| 8661 | * @return The top edge of the displayed part of your view, in pixels. |
| 8662 | */ |
| 8663 | public final int getScrollY() { |
| 8664 | return mScrollY; |
| 8665 | } |
| 8666 | |
| 8667 | /** |
| 8668 | * Return the width of the your view. |
| 8669 | * |
| 8670 | * @return The width of your view, in pixels. |
| 8671 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 8672 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8673 | public final int getWidth() { |
| 8674 | return mRight - mLeft; |
| 8675 | } |
| 8676 | |
| 8677 | /** |
| 8678 | * Return the height of your view. |
| 8679 | * |
| 8680 | * @return The height of your view, in pixels. |
| 8681 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 8682 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8683 | public final int getHeight() { |
| 8684 | return mBottom - mTop; |
| 8685 | } |
| 8686 | |
| 8687 | /** |
| 8688 | * Return the visible drawing bounds of your view. Fills in the output |
| 8689 | * rectangle with the values from getScrollX(), getScrollY(), |
Svetoslav Ganov | 78bd983 | 2012-10-15 19:12:29 -0700 | [diff] [blame] | 8690 | * getWidth(), and getHeight(). These bounds do not account for any |
| 8691 | * transformation properties currently set on the view, such as |
| 8692 | * {@link #setScaleX(float)} or {@link #setRotation(float)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8693 | * |
| 8694 | * @param outRect The (scrolled) drawing bounds of the view. |
| 8695 | */ |
| 8696 | public void getDrawingRect(Rect outRect) { |
| 8697 | outRect.left = mScrollX; |
| 8698 | outRect.top = mScrollY; |
| 8699 | outRect.right = mScrollX + (mRight - mLeft); |
| 8700 | outRect.bottom = mScrollY + (mBottom - mTop); |
| 8701 | } |
| 8702 | |
| 8703 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8704 | * Like {@link #getMeasuredWidthAndState()}, but only returns the |
| 8705 | * raw width component (that is the result is masked by |
| 8706 | * {@link #MEASURED_SIZE_MASK}). |
| 8707 | * |
| 8708 | * @return The raw measured width of this view. |
| 8709 | */ |
| 8710 | public final int getMeasuredWidth() { |
| 8711 | return mMeasuredWidth & MEASURED_SIZE_MASK; |
| 8712 | } |
| 8713 | |
| 8714 | /** |
| 8715 | * Return the full width measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8716 | * 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] | 8717 | * 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] | 8718 | * This should be used during measurement and layout calculations only. Use |
| 8719 | * {@link #getWidth()} to see how wide a view is after layout. |
| 8720 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8721 | * @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] | 8722 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8723 | public final int getMeasuredWidthAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8724 | return mMeasuredWidth; |
| 8725 | } |
| 8726 | |
| 8727 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8728 | * Like {@link #getMeasuredHeightAndState()}, but only returns the |
| 8729 | * raw width component (that is the result is masked by |
| 8730 | * {@link #MEASURED_SIZE_MASK}). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8731 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8732 | * @return The raw measured height of this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8733 | */ |
| 8734 | public final int getMeasuredHeight() { |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8735 | return mMeasuredHeight & MEASURED_SIZE_MASK; |
| 8736 | } |
| 8737 | |
| 8738 | /** |
| 8739 | * Return the full height measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8740 | * 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] | 8741 | * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
| 8742 | * This should be used during measurement and layout calculations only. Use |
| 8743 | * {@link #getHeight()} to see how wide a view is after layout. |
| 8744 | * |
| 8745 | * @return The measured width of this view as a bit mask. |
| 8746 | */ |
| 8747 | public final int getMeasuredHeightAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8748 | return mMeasuredHeight; |
| 8749 | } |
| 8750 | |
| 8751 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8752 | * Return only the state bits of {@link #getMeasuredWidthAndState()} |
| 8753 | * and {@link #getMeasuredHeightAndState()}, combined into one integer. |
| 8754 | * The width component is in the regular bits {@link #MEASURED_STATE_MASK} |
| 8755 | * and the height component is at the shifted bits |
| 8756 | * {@link #MEASURED_HEIGHT_STATE_SHIFT}>>{@link #MEASURED_STATE_MASK}. |
| 8757 | */ |
| 8758 | public final int getMeasuredState() { |
| 8759 | return (mMeasuredWidth&MEASURED_STATE_MASK) |
| 8760 | | ((mMeasuredHeight>>MEASURED_HEIGHT_STATE_SHIFT) |
| 8761 | & (MEASURED_STATE_MASK>>MEASURED_HEIGHT_STATE_SHIFT)); |
| 8762 | } |
| 8763 | |
| 8764 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8765 | * The transform matrix of this view, which is calculated based on the current |
| 8766 | * roation, scale, and pivot properties. |
| 8767 | * |
| 8768 | * @see #getRotation() |
| 8769 | * @see #getScaleX() |
| 8770 | * @see #getScaleY() |
| 8771 | * @see #getPivotX() |
| 8772 | * @see #getPivotY() |
| 8773 | * @return The current transform matrix for the view |
| 8774 | */ |
| 8775 | public Matrix getMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8776 | if (mTransformationInfo != null) { |
| 8777 | updateMatrix(); |
| 8778 | return mTransformationInfo.mMatrix; |
| 8779 | } |
| 8780 | return Matrix.IDENTITY_MATRIX; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8781 | } |
| 8782 | |
| 8783 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8784 | * Utility function to determine if the value is far enough away from zero to be |
| 8785 | * considered non-zero. |
| 8786 | * @param value A floating point value to check for zero-ness |
| 8787 | * @return whether the passed-in value is far enough away from zero to be considered non-zero |
| 8788 | */ |
| 8789 | private static boolean nonzero(float value) { |
| 8790 | return (value < -NONZERO_EPSILON || value > NONZERO_EPSILON); |
| 8791 | } |
| 8792 | |
| 8793 | /** |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8794 | * Returns true if the transform matrix is the identity matrix. |
| 8795 | * Recomputes the matrix if necessary. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8796 | * |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8797 | * @return True if the transform matrix is the identity matrix, false otherwise. |
| 8798 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8799 | final boolean hasIdentityMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8800 | if (mTransformationInfo != null) { |
| 8801 | updateMatrix(); |
| 8802 | return mTransformationInfo.mMatrixIsIdentity; |
| 8803 | } |
| 8804 | return true; |
| 8805 | } |
| 8806 | |
| 8807 | void ensureTransformationInfo() { |
| 8808 | if (mTransformationInfo == null) { |
| 8809 | mTransformationInfo = new TransformationInfo(); |
| 8810 | } |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8811 | } |
| 8812 | |
| 8813 | /** |
| 8814 | * Recomputes the transform matrix if necessary. |
| 8815 | */ |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8816 | private void updateMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8817 | final TransformationInfo info = mTransformationInfo; |
| 8818 | if (info == null) { |
| 8819 | return; |
| 8820 | } |
| 8821 | if (info.mMatrixDirty) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8822 | // transform-related properties have changed since the last time someone |
| 8823 | // asked for the matrix; recalculate it with the current values |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8824 | |
| 8825 | // Figure out if we need to update the pivot point |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8826 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8827 | if ((mRight - mLeft) != info.mPrevWidth || (mBottom - mTop) != info.mPrevHeight) { |
| 8828 | info.mPrevWidth = mRight - mLeft; |
| 8829 | info.mPrevHeight = mBottom - mTop; |
| 8830 | info.mPivotX = info.mPrevWidth / 2f; |
| 8831 | info.mPivotY = info.mPrevHeight / 2f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8832 | } |
| 8833 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8834 | info.mMatrix.reset(); |
| 8835 | if (!nonzero(info.mRotationX) && !nonzero(info.mRotationY)) { |
| 8836 | info.mMatrix.setTranslate(info.mTranslationX, info.mTranslationY); |
| 8837 | info.mMatrix.preRotate(info.mRotation, info.mPivotX, info.mPivotY); |
| 8838 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8839 | } else { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8840 | if (info.mCamera == null) { |
| 8841 | info.mCamera = new Camera(); |
| 8842 | info.matrix3D = new Matrix(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8843 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8844 | info.mCamera.save(); |
| 8845 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
| 8846 | info.mCamera.rotate(info.mRotationX, info.mRotationY, -info.mRotation); |
| 8847 | info.mCamera.getMatrix(info.matrix3D); |
| 8848 | info.matrix3D.preTranslate(-info.mPivotX, -info.mPivotY); |
| 8849 | info.matrix3D.postTranslate(info.mPivotX + info.mTranslationX, |
| 8850 | info.mPivotY + info.mTranslationY); |
| 8851 | info.mMatrix.postConcat(info.matrix3D); |
| 8852 | info.mCamera.restore(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8853 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8854 | info.mMatrixDirty = false; |
| 8855 | info.mMatrixIsIdentity = info.mMatrix.isIdentity(); |
| 8856 | info.mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8857 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8858 | } |
| 8859 | |
Tobias Dubois | defdb1e | 2010-12-15 11:35:30 +0100 | [diff] [blame] | 8860 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8861 | * Utility method to retrieve the inverse of the current mMatrix property. |
| 8862 | * We cache the matrix to avoid recalculating it when transform properties |
| 8863 | * have not changed. |
| 8864 | * |
| 8865 | * @return The inverse of the current matrix of this view. |
| 8866 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8867 | final Matrix getInverseMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8868 | final TransformationInfo info = mTransformationInfo; |
| 8869 | if (info != null) { |
| 8870 | updateMatrix(); |
| 8871 | if (info.mInverseMatrixDirty) { |
| 8872 | if (info.mInverseMatrix == null) { |
| 8873 | info.mInverseMatrix = new Matrix(); |
| 8874 | } |
| 8875 | info.mMatrix.invert(info.mInverseMatrix); |
| 8876 | info.mInverseMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8877 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8878 | return info.mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8879 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8880 | return Matrix.IDENTITY_MATRIX; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8881 | } |
| 8882 | |
| 8883 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8884 | * Gets the distance along the Z axis from the camera to this view. |
| 8885 | * |
| 8886 | * @see #setCameraDistance(float) |
| 8887 | * |
| 8888 | * @return The distance along the Z axis. |
| 8889 | */ |
| 8890 | public float getCameraDistance() { |
| 8891 | ensureTransformationInfo(); |
| 8892 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
| 8893 | final TransformationInfo info = mTransformationInfo; |
| 8894 | if (info.mCamera == null) { |
| 8895 | info.mCamera = new Camera(); |
| 8896 | info.matrix3D = new Matrix(); |
| 8897 | } |
| 8898 | return -(info.mCamera.getLocationZ() * dpi); |
| 8899 | } |
| 8900 | |
| 8901 | /** |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8902 | * <p>Sets the distance along the Z axis (orthogonal to the X/Y plane on which |
| 8903 | * views are drawn) from the camera to this view. The camera's distance |
| 8904 | * affects 3D transformations, for instance rotations around the X and Y |
| 8905 | * axis. If the rotationX or rotationY properties are changed and this view is |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8906 | * large (more than half the size of the screen), it is recommended to always |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8907 | * use a camera distance that's greater than the height (X axis rotation) or |
| 8908 | * the width (Y axis rotation) of this view.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8909 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8910 | * <p>The distance of the camera from the view plane can have an affect on the |
| 8911 | * perspective distortion of the view when it is rotated around the x or y axis. |
| 8912 | * For example, a large distance will result in a large viewing angle, and there |
| 8913 | * will not be much perspective distortion of the view as it rotates. A short |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8914 | * distance may cause much more perspective distortion upon rotation, and can |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8915 | * also result in some drawing artifacts if the rotated view ends up partially |
| 8916 | * behind the camera (which is why the recommendation is to use a distance at |
| 8917 | * least as far as the size of the view, if the view is to be rotated.)</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8918 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8919 | * <p>The distance is expressed in "depth pixels." The default distance depends |
| 8920 | * on the screen density. For instance, on a medium density display, the |
| 8921 | * default distance is 1280. On a high density display, the default distance |
| 8922 | * is 1920.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8923 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8924 | * <p>If you want to specify a distance that leads to visually consistent |
| 8925 | * results across various densities, use the following formula:</p> |
| 8926 | * <pre> |
| 8927 | * float scale = context.getResources().getDisplayMetrics().density; |
| 8928 | * view.setCameraDistance(distance * scale); |
| 8929 | * </pre> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8930 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8931 | * <p>The density scale factor of a high density display is 1.5, |
| 8932 | * and 1920 = 1280 * 1.5.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8933 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8934 | * @param distance The distance in "depth pixels", if negative the opposite |
| 8935 | * value is used |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8936 | * |
| 8937 | * @see #setRotationX(float) |
| 8938 | * @see #setRotationY(float) |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8939 | */ |
| 8940 | public void setCameraDistance(float distance) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8941 | invalidateViewProperty(true, false); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8942 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8943 | ensureTransformationInfo(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8944 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8945 | final TransformationInfo info = mTransformationInfo; |
| 8946 | if (info.mCamera == null) { |
| 8947 | info.mCamera = new Camera(); |
| 8948 | info.matrix3D = new Matrix(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8949 | } |
| 8950 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8951 | info.mCamera.setLocation(0.0f, 0.0f, -Math.abs(distance) / dpi); |
| 8952 | info.mMatrixDirty = true; |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8953 | |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8954 | invalidateViewProperty(false, false); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8955 | if (mDisplayList != null) { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 8956 | mDisplayList.setCameraDistance(-Math.abs(distance) / dpi); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8957 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8958 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 8959 | // View was rejected last time it was drawn by its parent; this may have changed |
| 8960 | invalidateParentIfNeeded(); |
| 8961 | } |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8962 | } |
| 8963 | |
| 8964 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8965 | * The degrees that the view is rotated around the pivot point. |
| 8966 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8967 | * @see #setRotation(float) |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8968 | * @see #getPivotX() |
| 8969 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8970 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8971 | * @return The degrees of rotation. |
| 8972 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8973 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8974 | public float getRotation() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8975 | return mTransformationInfo != null ? mTransformationInfo.mRotation : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8976 | } |
| 8977 | |
| 8978 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8979 | * Sets the degrees that the view is rotated around the pivot point. Increasing values |
| 8980 | * result in clockwise rotation. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8981 | * |
| 8982 | * @param rotation The degrees of rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8983 | * |
| 8984 | * @see #getRotation() |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8985 | * @see #getPivotX() |
| 8986 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8987 | * @see #setRotationX(float) |
| 8988 | * @see #setRotationY(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8989 | * |
| 8990 | * @attr ref android.R.styleable#View_rotation |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8991 | */ |
| 8992 | public void setRotation(float rotation) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8993 | ensureTransformationInfo(); |
| 8994 | final TransformationInfo info = mTransformationInfo; |
| 8995 | if (info.mRotation != rotation) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8996 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8997 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8998 | info.mRotation = rotation; |
| 8999 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9000 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9001 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9002 | mDisplayList.setRotation(rotation); |
| 9003 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9004 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9005 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9006 | invalidateParentIfNeeded(); |
| 9007 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9008 | } |
| 9009 | } |
| 9010 | |
| 9011 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9012 | * The degrees that the view is rotated around the vertical axis through the pivot point. |
| 9013 | * |
| 9014 | * @see #getPivotX() |
| 9015 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9016 | * @see #setRotationY(float) |
| 9017 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9018 | * @return The degrees of Y rotation. |
| 9019 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9020 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9021 | public float getRotationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9022 | return mTransformationInfo != null ? mTransformationInfo.mRotationY : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9023 | } |
| 9024 | |
| 9025 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 9026 | * Sets the degrees that the view is rotated around the vertical axis through the pivot point. |
| 9027 | * Increasing values result in counter-clockwise rotation from the viewpoint of looking |
| 9028 | * down the y axis. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9029 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9030 | * When rotating large views, it is recommended to adjust the camera distance |
| 9031 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9032 | * |
| 9033 | * @param rotationY The degrees of Y rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9034 | * |
| 9035 | * @see #getRotationY() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9036 | * @see #getPivotX() |
| 9037 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9038 | * @see #setRotation(float) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9039 | * @see #setRotationX(float) |
| 9040 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9041 | * |
| 9042 | * @attr ref android.R.styleable#View_rotationY |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9043 | */ |
| 9044 | public void setRotationY(float rotationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9045 | ensureTransformationInfo(); |
| 9046 | final TransformationInfo info = mTransformationInfo; |
| 9047 | if (info.mRotationY != rotationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9048 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9049 | info.mRotationY = rotationY; |
| 9050 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9051 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9052 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9053 | mDisplayList.setRotationY(rotationY); |
| 9054 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9055 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9056 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9057 | invalidateParentIfNeeded(); |
| 9058 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9059 | } |
| 9060 | } |
| 9061 | |
| 9062 | /** |
| 9063 | * The degrees that the view is rotated around the horizontal axis through the pivot point. |
| 9064 | * |
| 9065 | * @see #getPivotX() |
| 9066 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9067 | * @see #setRotationX(float) |
| 9068 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9069 | * @return The degrees of X rotation. |
| 9070 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9071 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9072 | public float getRotationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9073 | return mTransformationInfo != null ? mTransformationInfo.mRotationX : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9074 | } |
| 9075 | |
| 9076 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 9077 | * Sets the degrees that the view is rotated around the horizontal axis through the pivot point. |
| 9078 | * Increasing values result in clockwise rotation from the viewpoint of looking down the |
| 9079 | * x axis. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9080 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9081 | * When rotating large views, it is recommended to adjust the camera distance |
| 9082 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9083 | * |
| 9084 | * @param rotationX The degrees of X rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9085 | * |
| 9086 | * @see #getRotationX() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9087 | * @see #getPivotX() |
| 9088 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9089 | * @see #setRotation(float) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9090 | * @see #setRotationY(float) |
| 9091 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9092 | * |
| 9093 | * @attr ref android.R.styleable#View_rotationX |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9094 | */ |
| 9095 | public void setRotationX(float rotationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9096 | ensureTransformationInfo(); |
| 9097 | final TransformationInfo info = mTransformationInfo; |
| 9098 | if (info.mRotationX != rotationX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9099 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9100 | info.mRotationX = rotationX; |
| 9101 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9102 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9103 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9104 | mDisplayList.setRotationX(rotationX); |
| 9105 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9106 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9107 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9108 | invalidateParentIfNeeded(); |
| 9109 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9110 | } |
| 9111 | } |
| 9112 | |
| 9113 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9114 | * The amount that the view is scaled in x around the pivot point, as a proportion of |
| 9115 | * the view's unscaled width. A value of 1, the default, means that no scaling is applied. |
| 9116 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 9117 | * <p>By default, this is 1.0f. |
| 9118 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9119 | * @see #getPivotX() |
| 9120 | * @see #getPivotY() |
| 9121 | * @return The scaling factor. |
| 9122 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9123 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9124 | public float getScaleX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9125 | return mTransformationInfo != null ? mTransformationInfo.mScaleX : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9126 | } |
| 9127 | |
| 9128 | /** |
| 9129 | * Sets the amount that the view is scaled in x around the pivot point, as a proportion of |
| 9130 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 9131 | * |
| 9132 | * @param scaleX The scaling factor. |
| 9133 | * @see #getPivotX() |
| 9134 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9135 | * |
| 9136 | * @attr ref android.R.styleable#View_scaleX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9137 | */ |
| 9138 | public void setScaleX(float scaleX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9139 | ensureTransformationInfo(); |
| 9140 | final TransformationInfo info = mTransformationInfo; |
| 9141 | if (info.mScaleX != scaleX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9142 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9143 | info.mScaleX = scaleX; |
| 9144 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9145 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9146 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9147 | mDisplayList.setScaleX(scaleX); |
| 9148 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9149 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9150 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9151 | invalidateParentIfNeeded(); |
| 9152 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9153 | } |
| 9154 | } |
| 9155 | |
| 9156 | /** |
| 9157 | * The amount that the view is scaled in y around the pivot point, as a proportion of |
| 9158 | * the view's unscaled height. A value of 1, the default, means that no scaling is applied. |
| 9159 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 9160 | * <p>By default, this is 1.0f. |
| 9161 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9162 | * @see #getPivotX() |
| 9163 | * @see #getPivotY() |
| 9164 | * @return The scaling factor. |
| 9165 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9166 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9167 | public float getScaleY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9168 | return mTransformationInfo != null ? mTransformationInfo.mScaleY : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9169 | } |
| 9170 | |
| 9171 | /** |
| 9172 | * Sets the amount that the view is scaled in Y around the pivot point, as a proportion of |
| 9173 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 9174 | * |
| 9175 | * @param scaleY The scaling factor. |
| 9176 | * @see #getPivotX() |
| 9177 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9178 | * |
| 9179 | * @attr ref android.R.styleable#View_scaleY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9180 | */ |
| 9181 | public void setScaleY(float scaleY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9182 | ensureTransformationInfo(); |
| 9183 | final TransformationInfo info = mTransformationInfo; |
| 9184 | if (info.mScaleY != scaleY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9185 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9186 | info.mScaleY = scaleY; |
| 9187 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9188 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9189 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9190 | mDisplayList.setScaleY(scaleY); |
| 9191 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9192 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9193 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9194 | invalidateParentIfNeeded(); |
| 9195 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9196 | } |
| 9197 | } |
| 9198 | |
| 9199 | /** |
| 9200 | * The x location of the point around which the view is {@link #setRotation(float) rotated} |
| 9201 | * and {@link #setScaleX(float) scaled}. |
| 9202 | * |
| 9203 | * @see #getRotation() |
| 9204 | * @see #getScaleX() |
| 9205 | * @see #getScaleY() |
| 9206 | * @see #getPivotY() |
| 9207 | * @return The x location of the pivot point. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9208 | * |
| 9209 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9210 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9211 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9212 | public float getPivotX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9213 | return mTransformationInfo != null ? mTransformationInfo.mPivotX : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9214 | } |
| 9215 | |
| 9216 | /** |
| 9217 | * Sets the x location of the point around which the view is |
| 9218 | * {@link #setRotation(float) rotated} and {@link #setScaleX(float) scaled}. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9219 | * By default, the pivot point is centered on the object. |
| 9220 | * Setting this property disables this behavior and causes the view to use only the |
| 9221 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9222 | * |
| 9223 | * @param pivotX The x location of the pivot point. |
| 9224 | * @see #getRotation() |
| 9225 | * @see #getScaleX() |
| 9226 | * @see #getScaleY() |
| 9227 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9228 | * |
| 9229 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9230 | */ |
| 9231 | public void setPivotX(float pivotX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9232 | ensureTransformationInfo(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9233 | mPrivateFlags |= PFLAG_PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9234 | final TransformationInfo info = mTransformationInfo; |
| 9235 | if (info.mPivotX != pivotX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9236 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9237 | info.mPivotX = pivotX; |
| 9238 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9239 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9240 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9241 | mDisplayList.setPivotX(pivotX); |
| 9242 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9243 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9244 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9245 | invalidateParentIfNeeded(); |
| 9246 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9247 | } |
| 9248 | } |
| 9249 | |
| 9250 | /** |
| 9251 | * The y location of the point around which the view is {@link #setRotation(float) rotated} |
| 9252 | * and {@link #setScaleY(float) scaled}. |
| 9253 | * |
| 9254 | * @see #getRotation() |
| 9255 | * @see #getScaleX() |
| 9256 | * @see #getScaleY() |
| 9257 | * @see #getPivotY() |
| 9258 | * @return The y location of the pivot point. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9259 | * |
| 9260 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9261 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9262 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9263 | public float getPivotY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9264 | return mTransformationInfo != null ? mTransformationInfo.mPivotY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9265 | } |
| 9266 | |
| 9267 | /** |
| 9268 | * 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] | 9269 | * and {@link #setScaleY(float) scaled}. By default, the pivot point is centered on the object. |
| 9270 | * Setting this property disables this behavior and causes the view to use only the |
| 9271 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9272 | * |
| 9273 | * @param pivotY The y location of the pivot point. |
| 9274 | * @see #getRotation() |
| 9275 | * @see #getScaleX() |
| 9276 | * @see #getScaleY() |
| 9277 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9278 | * |
| 9279 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9280 | */ |
| 9281 | public void setPivotY(float pivotY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9282 | ensureTransformationInfo(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9283 | mPrivateFlags |= PFLAG_PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9284 | final TransformationInfo info = mTransformationInfo; |
| 9285 | if (info.mPivotY != pivotY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9286 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9287 | info.mPivotY = pivotY; |
| 9288 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9289 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9290 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9291 | mDisplayList.setPivotY(pivotY); |
| 9292 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9293 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9294 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9295 | invalidateParentIfNeeded(); |
| 9296 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9297 | } |
| 9298 | } |
| 9299 | |
| 9300 | /** |
| 9301 | * The opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 9302 | * completely transparent and 1 means the view is completely opaque. |
| 9303 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 9304 | * <p>By default this is 1.0f. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9305 | * @return The opacity of the view. |
| 9306 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9307 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9308 | public float getAlpha() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9309 | return mTransformationInfo != null ? mTransformationInfo.mAlpha : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9310 | } |
| 9311 | |
| 9312 | /** |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 9313 | * Returns whether this View has content which overlaps. This function, intended to be |
| 9314 | * overridden by specific View types, is an optimization when alpha is set on a view. If |
| 9315 | * rendering overlaps in a view with alpha < 1, that view is drawn to an offscreen buffer |
| 9316 | * and then composited it into place, which can be expensive. If the view has no overlapping |
| 9317 | * rendering, the view can draw each primitive with the appropriate alpha value directly. |
| 9318 | * An example of overlapping rendering is a TextView with a background image, such as a |
| 9319 | * Button. An example of non-overlapping rendering is a TextView with no background, or |
| 9320 | * an ImageView with only the foreground image. The default implementation returns true; |
| 9321 | * subclasses should override if they have cases which can be optimized. |
| 9322 | * |
| 9323 | * @return true if the content in this view might overlap, false otherwise. |
| 9324 | */ |
| 9325 | public boolean hasOverlappingRendering() { |
| 9326 | return true; |
| 9327 | } |
| 9328 | |
| 9329 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9330 | * <p>Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 9331 | * completely transparent and 1 means the view is completely opaque.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9332 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9333 | * <p>If this view overrides {@link #onSetAlpha(int)} to return true, then this view is |
| 9334 | * responsible for applying the opacity itself. Otherwise, calling this method is |
| 9335 | * equivalent to calling {@link #setLayerType(int, android.graphics.Paint)} and |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9336 | * setting a hardware layer.</p> |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9337 | * |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9338 | * <p>Note that setting alpha to a translucent value (0 < alpha < 1) may have |
| 9339 | * performance implications. It is generally best to use the alpha property sparingly and |
| 9340 | * transiently, as in the case of fading animations.</p> |
| 9341 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9342 | * @param alpha The opacity of the view. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9343 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9344 | * @see #setLayerType(int, android.graphics.Paint) |
| 9345 | * |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9346 | * @attr ref android.R.styleable#View_alpha |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9347 | */ |
| 9348 | public void setAlpha(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9349 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9350 | if (mTransformationInfo.mAlpha != alpha) { |
| 9351 | mTransformationInfo.mAlpha = alpha; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9352 | if (onSetAlpha((int) (alpha * 255))) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9353 | mPrivateFlags |= PFLAG_ALPHA_SET; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9354 | // subclass is handling alpha - don't optimize rendering cache invalidation |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9355 | invalidateParentCaches(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9356 | invalidate(true); |
| 9357 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9358 | mPrivateFlags &= ~PFLAG_ALPHA_SET; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9359 | invalidateViewProperty(true, false); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9360 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9361 | mDisplayList.setAlpha(alpha); |
| 9362 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9363 | } |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9364 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9365 | } |
| 9366 | |
| 9367 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 9368 | * Faster version of setAlpha() which performs the same steps except there are |
| 9369 | * no calls to invalidate(). The caller of this function should perform proper invalidation |
| 9370 | * on the parent and this object. The return value indicates whether the subclass handles |
| 9371 | * alpha (the return value for onSetAlpha()). |
| 9372 | * |
| 9373 | * @param alpha The new value for the alpha property |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9374 | * @return true if the View subclass handles alpha (the return value for onSetAlpha()) and |
| 9375 | * 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] | 9376 | */ |
| 9377 | boolean setAlphaNoInvalidation(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9378 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9379 | if (mTransformationInfo.mAlpha != alpha) { |
| 9380 | mTransformationInfo.mAlpha = alpha; |
| 9381 | boolean subclassHandlesAlpha = onSetAlpha((int) (alpha * 255)); |
| 9382 | if (subclassHandlesAlpha) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9383 | mPrivateFlags |= PFLAG_ALPHA_SET; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9384 | return true; |
| 9385 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9386 | mPrivateFlags &= ~PFLAG_ALPHA_SET; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9387 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9388 | mDisplayList.setAlpha(alpha); |
| 9389 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9390 | } |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 9391 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9392 | return false; |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 9393 | } |
| 9394 | |
| 9395 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9396 | * Top position of this view relative to its parent. |
| 9397 | * |
| 9398 | * @return The top of this view, in pixels. |
| 9399 | */ |
| 9400 | @ViewDebug.CapturedViewProperty |
| 9401 | public final int getTop() { |
| 9402 | return mTop; |
| 9403 | } |
| 9404 | |
| 9405 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9406 | * Sets the top position of this view relative to its parent. This method is meant to be called |
| 9407 | * by the layout system and should not generally be called otherwise, because the property |
| 9408 | * may be changed at any time by the layout. |
| 9409 | * |
| 9410 | * @param top The top of this view, in pixels. |
| 9411 | */ |
| 9412 | public final void setTop(int top) { |
| 9413 | if (top != mTop) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9414 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9415 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9416 | || mTransformationInfo.mMatrixIsIdentity; |
| 9417 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9418 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9419 | int minTop; |
| 9420 | int yLoc; |
| 9421 | if (top < mTop) { |
| 9422 | minTop = top; |
| 9423 | yLoc = top - mTop; |
| 9424 | } else { |
| 9425 | minTop = mTop; |
| 9426 | yLoc = 0; |
| 9427 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9428 | invalidate(0, yLoc, mRight - mLeft, mBottom - minTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9429 | } |
| 9430 | } else { |
| 9431 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9432 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9433 | } |
| 9434 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9435 | int width = mRight - mLeft; |
| 9436 | int oldHeight = mBottom - mTop; |
| 9437 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9438 | mTop = top; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9439 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9440 | mDisplayList.setTop(mTop); |
| 9441 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9442 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9443 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 9444 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9445 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9446 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9447 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9448 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9449 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9450 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9451 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9452 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9453 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9454 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9455 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9456 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9457 | invalidateParentIfNeeded(); |
| 9458 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9459 | } |
| 9460 | } |
| 9461 | |
| 9462 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9463 | * Bottom position of this view relative to its parent. |
| 9464 | * |
| 9465 | * @return The bottom of this view, in pixels. |
| 9466 | */ |
| 9467 | @ViewDebug.CapturedViewProperty |
| 9468 | public final int getBottom() { |
| 9469 | return mBottom; |
| 9470 | } |
| 9471 | |
| 9472 | /** |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 9473 | * True if this view has changed since the last time being drawn. |
| 9474 | * |
| 9475 | * @return The dirty state of this view. |
| 9476 | */ |
| 9477 | public boolean isDirty() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9478 | return (mPrivateFlags & PFLAG_DIRTY_MASK) != 0; |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 9479 | } |
| 9480 | |
| 9481 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9482 | * Sets the bottom position of this view relative to its parent. This method is meant to be |
| 9483 | * called by the layout system and should not generally be called otherwise, because the |
| 9484 | * property may be changed at any time by the layout. |
| 9485 | * |
| 9486 | * @param bottom The bottom of this view, in pixels. |
| 9487 | */ |
| 9488 | public final void setBottom(int bottom) { |
| 9489 | if (bottom != mBottom) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9490 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9491 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9492 | || mTransformationInfo.mMatrixIsIdentity; |
| 9493 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9494 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9495 | int maxBottom; |
| 9496 | if (bottom < mBottom) { |
| 9497 | maxBottom = mBottom; |
| 9498 | } else { |
| 9499 | maxBottom = bottom; |
| 9500 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9501 | invalidate(0, 0, mRight - mLeft, maxBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9502 | } |
| 9503 | } else { |
| 9504 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9505 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9506 | } |
| 9507 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9508 | int width = mRight - mLeft; |
| 9509 | int oldHeight = mBottom - mTop; |
| 9510 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9511 | mBottom = bottom; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9512 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9513 | mDisplayList.setBottom(mBottom); |
| 9514 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9515 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9516 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 9517 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9518 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9519 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9520 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9521 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9522 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9523 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9524 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9525 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9526 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9527 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9528 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9529 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9530 | invalidateParentIfNeeded(); |
| 9531 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9532 | } |
| 9533 | } |
| 9534 | |
| 9535 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9536 | * Left position of this view relative to its parent. |
| 9537 | * |
| 9538 | * @return The left edge of this view, in pixels. |
| 9539 | */ |
| 9540 | @ViewDebug.CapturedViewProperty |
| 9541 | public final int getLeft() { |
| 9542 | return mLeft; |
| 9543 | } |
| 9544 | |
| 9545 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9546 | * Sets the left position of this view relative to its parent. This method is meant to be called |
| 9547 | * by the layout system and should not generally be called otherwise, because the property |
| 9548 | * may be changed at any time by the layout. |
| 9549 | * |
| 9550 | * @param left The bottom of this view, in pixels. |
| 9551 | */ |
| 9552 | public final void setLeft(int left) { |
| 9553 | if (left != mLeft) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9554 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9555 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9556 | || mTransformationInfo.mMatrixIsIdentity; |
| 9557 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9558 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9559 | int minLeft; |
| 9560 | int xLoc; |
| 9561 | if (left < mLeft) { |
| 9562 | minLeft = left; |
| 9563 | xLoc = left - mLeft; |
| 9564 | } else { |
| 9565 | minLeft = mLeft; |
| 9566 | xLoc = 0; |
| 9567 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9568 | invalidate(xLoc, 0, mRight - minLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9569 | } |
| 9570 | } else { |
| 9571 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9572 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9573 | } |
| 9574 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9575 | int oldWidth = mRight - mLeft; |
| 9576 | int height = mBottom - mTop; |
| 9577 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9578 | mLeft = left; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9579 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9580 | mDisplayList.setLeft(left); |
| 9581 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9582 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9583 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 9584 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9585 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9586 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9587 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9588 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9589 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9590 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9591 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9592 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9593 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9594 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9595 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9596 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9597 | invalidateParentIfNeeded(); |
| 9598 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9599 | } |
| 9600 | } |
| 9601 | |
| 9602 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9603 | * Right position of this view relative to its parent. |
| 9604 | * |
| 9605 | * @return The right edge of this view, in pixels. |
| 9606 | */ |
| 9607 | @ViewDebug.CapturedViewProperty |
| 9608 | public final int getRight() { |
| 9609 | return mRight; |
| 9610 | } |
| 9611 | |
| 9612 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9613 | * Sets the right position of this view relative to its parent. This method is meant to be called |
| 9614 | * by the layout system and should not generally be called otherwise, because the property |
| 9615 | * may be changed at any time by the layout. |
| 9616 | * |
| 9617 | * @param right The bottom of this view, in pixels. |
| 9618 | */ |
| 9619 | public final void setRight(int right) { |
| 9620 | if (right != mRight) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9621 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9622 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9623 | || mTransformationInfo.mMatrixIsIdentity; |
| 9624 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9625 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9626 | int maxRight; |
| 9627 | if (right < mRight) { |
| 9628 | maxRight = mRight; |
| 9629 | } else { |
| 9630 | maxRight = right; |
| 9631 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9632 | invalidate(0, 0, maxRight - mLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9633 | } |
| 9634 | } else { |
| 9635 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9636 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9637 | } |
| 9638 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9639 | int oldWidth = mRight - mLeft; |
| 9640 | int height = mBottom - mTop; |
| 9641 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9642 | mRight = right; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9643 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9644 | mDisplayList.setRight(mRight); |
| 9645 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9646 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9647 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 9648 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9649 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9650 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9651 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9652 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9653 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9654 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9655 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9656 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9657 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9658 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9659 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9660 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9661 | invalidateParentIfNeeded(); |
| 9662 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9663 | } |
| 9664 | } |
| 9665 | |
| 9666 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9667 | * The visual x position of this view, in pixels. This is equivalent to the |
| 9668 | * {@link #setTranslationX(float) translationX} property plus the current |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9669 | * {@link #getLeft() left} property. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9670 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9671 | * @return The visual x position of this view, in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9672 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9673 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9674 | public float getX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9675 | return mLeft + (mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9676 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9677 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9678 | /** |
| 9679 | * Sets the visual x position of this view, in pixels. This is equivalent to setting the |
| 9680 | * {@link #setTranslationX(float) translationX} property to be the difference between |
| 9681 | * the x value passed in and the current {@link #getLeft() left} property. |
| 9682 | * |
| 9683 | * @param x The visual x position of this view, in pixels. |
| 9684 | */ |
| 9685 | public void setX(float x) { |
| 9686 | setTranslationX(x - mLeft); |
| 9687 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9688 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9689 | /** |
| 9690 | * The visual y position of this view, in pixels. This is equivalent to the |
| 9691 | * {@link #setTranslationY(float) translationY} property plus the current |
| 9692 | * {@link #getTop() top} property. |
| 9693 | * |
| 9694 | * @return The visual y position of this view, in pixels. |
| 9695 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9696 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9697 | public float getY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9698 | return mTop + (mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9699 | } |
| 9700 | |
| 9701 | /** |
| 9702 | * Sets the visual y position of this view, in pixels. This is equivalent to setting the |
| 9703 | * {@link #setTranslationY(float) translationY} property to be the difference between |
| 9704 | * the y value passed in and the current {@link #getTop() top} property. |
| 9705 | * |
| 9706 | * @param y The visual y position of this view, in pixels. |
| 9707 | */ |
| 9708 | public void setY(float y) { |
| 9709 | setTranslationY(y - mTop); |
| 9710 | } |
| 9711 | |
| 9712 | |
| 9713 | /** |
| 9714 | * The horizontal location of this view relative to its {@link #getLeft() left} position. |
| 9715 | * This position is post-layout, in addition to wherever the object's |
| 9716 | * layout placed it. |
| 9717 | * |
| 9718 | * @return The horizontal position of this view relative to its left position, in pixels. |
| 9719 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9720 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9721 | public float getTranslationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9722 | return mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9723 | } |
| 9724 | |
| 9725 | /** |
| 9726 | * Sets the horizontal location of this view relative to its {@link #getLeft() left} position. |
| 9727 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 9728 | * layout placed it. |
| 9729 | * |
| 9730 | * @param translationX The horizontal position of this view relative to its left position, |
| 9731 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9732 | * |
| 9733 | * @attr ref android.R.styleable#View_translationX |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9734 | */ |
| 9735 | public void setTranslationX(float translationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9736 | ensureTransformationInfo(); |
| 9737 | final TransformationInfo info = mTransformationInfo; |
| 9738 | if (info.mTranslationX != translationX) { |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9739 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9740 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9741 | info.mTranslationX = translationX; |
| 9742 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9743 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9744 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9745 | mDisplayList.setTranslationX(translationX); |
| 9746 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9747 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9748 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9749 | invalidateParentIfNeeded(); |
| 9750 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9751 | } |
| 9752 | } |
| 9753 | |
| 9754 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9755 | * The horizontal location of this view relative to its {@link #getTop() top} position. |
| 9756 | * This position is post-layout, in addition to wherever the object's |
| 9757 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9758 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9759 | * @return The vertical position of this view relative to its top position, |
| 9760 | * in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9761 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9762 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9763 | public float getTranslationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9764 | return mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9765 | } |
| 9766 | |
| 9767 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9768 | * Sets the vertical location of this view relative to its {@link #getTop() top} position. |
| 9769 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 9770 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9771 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9772 | * @param translationY The vertical position of this view relative to its top position, |
| 9773 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9774 | * |
| 9775 | * @attr ref android.R.styleable#View_translationY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9776 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9777 | public void setTranslationY(float translationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9778 | ensureTransformationInfo(); |
| 9779 | final TransformationInfo info = mTransformationInfo; |
| 9780 | if (info.mTranslationY != translationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9781 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9782 | info.mTranslationY = translationY; |
| 9783 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9784 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9785 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9786 | mDisplayList.setTranslationY(translationY); |
| 9787 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9788 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9789 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9790 | invalidateParentIfNeeded(); |
| 9791 | } |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9792 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9793 | } |
| 9794 | |
| 9795 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9796 | * Hit rectangle in parent's coordinates |
| 9797 | * |
| 9798 | * @param outRect The hit rectangle of the view. |
| 9799 | */ |
| 9800 | public void getHitRect(Rect outRect) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9801 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9802 | final TransformationInfo info = mTransformationInfo; |
| 9803 | if (info == null || info.mMatrixIsIdentity || mAttachInfo == null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9804 | outRect.set(mLeft, mTop, mRight, mBottom); |
| 9805 | } else { |
| 9806 | final RectF tmpRect = mAttachInfo.mTmpTransformRect; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9807 | tmpRect.set(-info.mPivotX, -info.mPivotY, |
| 9808 | getWidth() - info.mPivotX, getHeight() - info.mPivotY); |
| 9809 | info.mMatrix.mapRect(tmpRect); |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9810 | outRect.set((int) tmpRect.left + mLeft, (int) tmpRect.top + mTop, |
| 9811 | (int) tmpRect.right + mLeft, (int) tmpRect.bottom + mTop); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9812 | } |
| 9813 | } |
| 9814 | |
| 9815 | /** |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 9816 | * Determines whether the given point, in local coordinates is inside the view. |
| 9817 | */ |
| 9818 | /*package*/ final boolean pointInView(float localX, float localY) { |
| 9819 | return localX >= 0 && localX < (mRight - mLeft) |
| 9820 | && localY >= 0 && localY < (mBottom - mTop); |
| 9821 | } |
| 9822 | |
| 9823 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9824 | * Utility method to determine whether the given point, in local coordinates, |
| 9825 | * is inside the view, where the area of the view is expanded by the slop factor. |
| 9826 | * This method is called while processing touch-move events to determine if the event |
| 9827 | * is still within the view. |
| 9828 | */ |
| 9829 | private boolean pointInView(float localX, float localY, float slop) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 9830 | return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) && |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9831 | localY < ((mBottom - mTop) + slop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9832 | } |
| 9833 | |
| 9834 | /** |
| 9835 | * When a view has focus and the user navigates away from it, the next view is searched for |
| 9836 | * starting from the rectangle filled in by this method. |
| 9837 | * |
Fabrice Di Meglio | c11f77f | 2012-09-18 15:33:07 -0700 | [diff] [blame] | 9838 | * By default, the rectangle is the {@link #getDrawingRect(android.graphics.Rect)}) |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9839 | * of the view. However, if your view maintains some idea of internal selection, |
| 9840 | * such as a cursor, or a selected row or column, you should override this method and |
| 9841 | * fill in a more specific rectangle. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9842 | * |
| 9843 | * @param r The rectangle to fill in, in this view's coordinates. |
| 9844 | */ |
| 9845 | public void getFocusedRect(Rect r) { |
| 9846 | getDrawingRect(r); |
| 9847 | } |
| 9848 | |
| 9849 | /** |
| 9850 | * If some part of this view is not clipped by any of its parents, then |
| 9851 | * 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] | 9852 | * coordinates (without taking possible View rotations into account), offset |
| 9853 | * it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)). |
| 9854 | * 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] | 9855 | * |
| 9856 | * @param r If true is returned, r holds the global coordinates of the |
| 9857 | * visible portion of this view. |
| 9858 | * @param globalOffset If true is returned, globalOffset holds the dx,dy |
| 9859 | * between this view and its root. globalOffet may be null. |
| 9860 | * @return true if r is non-empty (i.e. part of the view is visible at the |
| 9861 | * root level. |
| 9862 | */ |
| 9863 | public boolean getGlobalVisibleRect(Rect r, Point globalOffset) { |
| 9864 | int width = mRight - mLeft; |
| 9865 | int height = mBottom - mTop; |
| 9866 | if (width > 0 && height > 0) { |
| 9867 | r.set(0, 0, width, height); |
| 9868 | if (globalOffset != null) { |
| 9869 | globalOffset.set(-mScrollX, -mScrollY); |
| 9870 | } |
| 9871 | return mParent == null || mParent.getChildVisibleRect(this, r, globalOffset); |
| 9872 | } |
| 9873 | return false; |
| 9874 | } |
| 9875 | |
| 9876 | public final boolean getGlobalVisibleRect(Rect r) { |
| 9877 | return getGlobalVisibleRect(r, null); |
| 9878 | } |
| 9879 | |
| 9880 | public final boolean getLocalVisibleRect(Rect r) { |
Romain Guy | ab4c4f4f | 2012-05-06 13:11:24 -0700 | [diff] [blame] | 9881 | final Point offset = mAttachInfo != null ? mAttachInfo.mPoint : new Point(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9882 | if (getGlobalVisibleRect(r, offset)) { |
| 9883 | r.offset(-offset.x, -offset.y); // make r local |
| 9884 | return true; |
| 9885 | } |
| 9886 | return false; |
| 9887 | } |
| 9888 | |
| 9889 | /** |
| 9890 | * Offset this view's vertical location by the specified number of pixels. |
| 9891 | * |
| 9892 | * @param offset the number of pixels to offset the view by |
| 9893 | */ |
| 9894 | public void offsetTopAndBottom(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9895 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9896 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9897 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9898 | || mTransformationInfo.mMatrixIsIdentity; |
| 9899 | if (matrixIsIdentity) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9900 | if (mDisplayList != null) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9901 | invalidateViewProperty(false, false); |
| 9902 | } else { |
| 9903 | final ViewParent p = mParent; |
| 9904 | if (p != null && mAttachInfo != null) { |
| 9905 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 9906 | int minTop; |
| 9907 | int maxBottom; |
| 9908 | int yLoc; |
| 9909 | if (offset < 0) { |
| 9910 | minTop = mTop + offset; |
| 9911 | maxBottom = mBottom; |
| 9912 | yLoc = offset; |
| 9913 | } else { |
| 9914 | minTop = mTop; |
| 9915 | maxBottom = mBottom + offset; |
| 9916 | yLoc = 0; |
| 9917 | } |
| 9918 | r.set(0, yLoc, mRight - mLeft, maxBottom - minTop); |
| 9919 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 9920 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9921 | } |
| 9922 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9923 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9924 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9925 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9926 | mTop += offset; |
| 9927 | mBottom += offset; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9928 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9929 | mDisplayList.offsetTopBottom(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9930 | invalidateViewProperty(false, false); |
| 9931 | } else { |
| 9932 | if (!matrixIsIdentity) { |
| 9933 | invalidateViewProperty(false, true); |
| 9934 | } |
| 9935 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9936 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9937 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9938 | } |
| 9939 | |
| 9940 | /** |
| 9941 | * Offset this view's horizontal location by the specified amount of pixels. |
| 9942 | * |
| 9943 | * @param offset the numer of pixels to offset the view by |
| 9944 | */ |
| 9945 | public void offsetLeftAndRight(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9946 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9947 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9948 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9949 | || mTransformationInfo.mMatrixIsIdentity; |
| 9950 | if (matrixIsIdentity) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9951 | if (mDisplayList != null) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9952 | invalidateViewProperty(false, false); |
| 9953 | } else { |
| 9954 | final ViewParent p = mParent; |
| 9955 | if (p != null && mAttachInfo != null) { |
| 9956 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 9957 | int minLeft; |
| 9958 | int maxRight; |
| 9959 | if (offset < 0) { |
| 9960 | minLeft = mLeft + offset; |
| 9961 | maxRight = mRight; |
| 9962 | } else { |
| 9963 | minLeft = mLeft; |
| 9964 | maxRight = mRight + offset; |
| 9965 | } |
| 9966 | r.set(0, 0, maxRight - minLeft, mBottom - mTop); |
| 9967 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 9968 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9969 | } |
| 9970 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9971 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9972 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9973 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9974 | mLeft += offset; |
| 9975 | mRight += offset; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9976 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9977 | mDisplayList.offsetLeftRight(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9978 | invalidateViewProperty(false, false); |
| 9979 | } else { |
| 9980 | if (!matrixIsIdentity) { |
| 9981 | invalidateViewProperty(false, true); |
| 9982 | } |
| 9983 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9984 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9985 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9986 | } |
| 9987 | |
| 9988 | /** |
| 9989 | * Get the LayoutParams associated with this view. All views should have |
| 9990 | * layout parameters. These supply parameters to the <i>parent</i> of this |
| 9991 | * view specifying how it should be arranged. There are many subclasses of |
| 9992 | * ViewGroup.LayoutParams, and these correspond to the different subclasses |
| 9993 | * of ViewGroup that are responsible for arranging their children. |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 9994 | * |
| 9995 | * This method may return null if this View is not attached to a parent |
| 9996 | * ViewGroup or {@link #setLayoutParams(android.view.ViewGroup.LayoutParams)} |
| 9997 | * was not invoked successfully. When a View is attached to a parent |
| 9998 | * ViewGroup, this method must not return null. |
| 9999 | * |
| 10000 | * @return The LayoutParams associated with this view, or null if no |
| 10001 | * parameters have been set yet |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10002 | */ |
Konstantin Lopyrev | 91a7f5f | 2010-08-10 18:54:54 -0700 | [diff] [blame] | 10003 | @ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10004 | public ViewGroup.LayoutParams getLayoutParams() { |
| 10005 | return mLayoutParams; |
| 10006 | } |
| 10007 | |
| 10008 | /** |
| 10009 | * Set the layout parameters associated with this view. These supply |
| 10010 | * parameters to the <i>parent</i> of this view specifying how it should be |
| 10011 | * arranged. There are many subclasses of ViewGroup.LayoutParams, and these |
| 10012 | * correspond to the different subclasses of ViewGroup that are responsible |
| 10013 | * for arranging their children. |
| 10014 | * |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 10015 | * @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] | 10016 | */ |
| 10017 | public void setLayoutParams(ViewGroup.LayoutParams params) { |
| 10018 | if (params == null) { |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 10019 | throw new NullPointerException("Layout parameters cannot be null"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10020 | } |
| 10021 | mLayoutParams = params; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 10022 | resolveLayoutParams(); |
Philip Milne | d7dd890 | 2012-01-26 16:55:30 -0800 | [diff] [blame] | 10023 | if (mParent instanceof ViewGroup) { |
| 10024 | ((ViewGroup) mParent).onSetLayoutParams(this, params); |
| 10025 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10026 | requestLayout(); |
| 10027 | } |
| 10028 | |
| 10029 | /** |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 10030 | * Resolve the layout parameters depending on the resolved layout direction |
Fabrice Di Meglio | fcc3348 | 2012-10-18 11:11:51 -0700 | [diff] [blame] | 10031 | * |
| 10032 | * @hide |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 10033 | */ |
Fabrice Di Meglio | fcc3348 | 2012-10-18 11:11:51 -0700 | [diff] [blame] | 10034 | public void resolveLayoutParams() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 10035 | if (mLayoutParams != null) { |
Fabrice Di Meglio | 2918ab6 | 2012-10-10 16:39:25 -0700 | [diff] [blame] | 10036 | mLayoutParams.resolveLayoutDirection(getLayoutDirection()); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 10037 | } |
| 10038 | } |
| 10039 | |
| 10040 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10041 | * Set the scrolled position of your view. This will cause a call to |
| 10042 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 10043 | * invalidated. |
| 10044 | * @param x the x position to scroll to |
| 10045 | * @param y the y position to scroll to |
| 10046 | */ |
| 10047 | public void scrollTo(int x, int y) { |
| 10048 | if (mScrollX != x || mScrollY != y) { |
| 10049 | int oldX = mScrollX; |
| 10050 | int oldY = mScrollY; |
| 10051 | mScrollX = x; |
| 10052 | mScrollY = y; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10053 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10054 | onScrollChanged(mScrollX, mScrollY, oldX, oldY); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10055 | if (!awakenScrollBars()) { |
Adam Powell | df3ae4f | 2012-04-10 18:55:22 -0700 | [diff] [blame] | 10056 | postInvalidateOnAnimation(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10057 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10058 | } |
| 10059 | } |
| 10060 | |
| 10061 | /** |
| 10062 | * Move the scrolled position of your view. This will cause a call to |
| 10063 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 10064 | * invalidated. |
| 10065 | * @param x the amount of pixels to scroll by horizontally |
| 10066 | * @param y the amount of pixels to scroll by vertically |
| 10067 | */ |
| 10068 | public void scrollBy(int x, int y) { |
| 10069 | scrollTo(mScrollX + x, mScrollY + y); |
| 10070 | } |
| 10071 | |
| 10072 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10073 | * <p>Trigger the scrollbars to draw. When invoked this method starts an |
| 10074 | * animation to fade the scrollbars out after a default delay. If a subclass |
| 10075 | * provides animated scrolling, the start delay should equal the duration |
| 10076 | * of the scrolling animation.</p> |
| 10077 | * |
| 10078 | * <p>The animation starts only if at least one of the scrollbars is |
| 10079 | * enabled, as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 10080 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 10081 | * this method returns true, and false otherwise. If the animation is |
| 10082 | * started, this method calls {@link #invalidate()}; in that case the |
| 10083 | * caller should not call {@link #invalidate()}.</p> |
| 10084 | * |
| 10085 | * <p>This method should be invoked every time a subclass directly updates |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10086 | * the scroll parameters.</p> |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10087 | * |
| 10088 | * <p>This method is automatically invoked by {@link #scrollBy(int, int)} |
| 10089 | * and {@link #scrollTo(int, int)}.</p> |
| 10090 | * |
| 10091 | * @return true if the animation is played, false otherwise |
| 10092 | * |
| 10093 | * @see #awakenScrollBars(int) |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10094 | * @see #scrollBy(int, int) |
| 10095 | * @see #scrollTo(int, int) |
| 10096 | * @see #isHorizontalScrollBarEnabled() |
| 10097 | * @see #isVerticalScrollBarEnabled() |
| 10098 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 10099 | * @see #setVerticalScrollBarEnabled(boolean) |
| 10100 | */ |
| 10101 | protected boolean awakenScrollBars() { |
| 10102 | return mScrollCache != null && |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10103 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade, true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10104 | } |
| 10105 | |
| 10106 | /** |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 10107 | * Trigger the scrollbars to draw. |
| 10108 | * This method differs from awakenScrollBars() only in its default duration. |
| 10109 | * initialAwakenScrollBars() will show the scroll bars for longer than |
| 10110 | * usual to give the user more of a chance to notice them. |
| 10111 | * |
| 10112 | * @return true if the animation is played, false otherwise. |
| 10113 | */ |
| 10114 | private boolean initialAwakenScrollBars() { |
| 10115 | return mScrollCache != null && |
| 10116 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade * 4, true); |
| 10117 | } |
| 10118 | |
| 10119 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10120 | * <p> |
| 10121 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 10122 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 10123 | * provides animated scrolling, the start delay should equal the duration of |
| 10124 | * the scrolling animation. |
| 10125 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10126 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10127 | * <p> |
| 10128 | * The animation starts only if at least one of the scrollbars is enabled, |
| 10129 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 10130 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 10131 | * this method returns true, and false otherwise. If the animation is |
| 10132 | * started, this method calls {@link #invalidate()}; in that case the caller |
| 10133 | * should not call {@link #invalidate()}. |
| 10134 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10135 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10136 | * <p> |
| 10137 | * This method should be invoked everytime a subclass directly updates the |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10138 | * scroll parameters. |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10139 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10140 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10141 | * @param startDelay the delay, in milliseconds, after which the animation |
| 10142 | * should start; when the delay is 0, the animation starts |
| 10143 | * immediately |
| 10144 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10145 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10146 | * @see #scrollBy(int, int) |
| 10147 | * @see #scrollTo(int, int) |
| 10148 | * @see #isHorizontalScrollBarEnabled() |
| 10149 | * @see #isVerticalScrollBarEnabled() |
| 10150 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 10151 | * @see #setVerticalScrollBarEnabled(boolean) |
| 10152 | */ |
| 10153 | protected boolean awakenScrollBars(int startDelay) { |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10154 | return awakenScrollBars(startDelay, true); |
| 10155 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10156 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10157 | /** |
| 10158 | * <p> |
| 10159 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 10160 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 10161 | * provides animated scrolling, the start delay should equal the duration of |
| 10162 | * the scrolling animation. |
| 10163 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10164 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10165 | * <p> |
| 10166 | * The animation starts only if at least one of the scrollbars is enabled, |
| 10167 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 10168 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 10169 | * this method returns true, and false otherwise. If the animation is |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10170 | * started, this method calls {@link #invalidate()} if the invalidate parameter |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10171 | * is set to true; in that case the caller |
| 10172 | * should not call {@link #invalidate()}. |
| 10173 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10174 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10175 | * <p> |
| 10176 | * This method should be invoked everytime a subclass directly updates the |
| 10177 | * scroll parameters. |
| 10178 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10179 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10180 | * @param startDelay the delay, in milliseconds, after which the animation |
| 10181 | * should start; when the delay is 0, the animation starts |
| 10182 | * immediately |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10183 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10184 | * @param invalidate Wheter this method should call invalidate |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10185 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10186 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10187 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10188 | * @see #scrollBy(int, int) |
| 10189 | * @see #scrollTo(int, int) |
| 10190 | * @see #isHorizontalScrollBarEnabled() |
| 10191 | * @see #isVerticalScrollBarEnabled() |
| 10192 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 10193 | * @see #setVerticalScrollBarEnabled(boolean) |
| 10194 | */ |
| 10195 | protected boolean awakenScrollBars(int startDelay, boolean invalidate) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10196 | final ScrollabilityCache scrollCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10197 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10198 | if (scrollCache == null || !scrollCache.fadeScrollBars) { |
| 10199 | return false; |
| 10200 | } |
| 10201 | |
| 10202 | if (scrollCache.scrollBar == null) { |
| 10203 | scrollCache.scrollBar = new ScrollBarDrawable(); |
| 10204 | } |
| 10205 | |
| 10206 | if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) { |
| 10207 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10208 | if (invalidate) { |
| 10209 | // Invalidate to show the scrollbars |
Adam Powell | df3ae4f | 2012-04-10 18:55:22 -0700 | [diff] [blame] | 10210 | postInvalidateOnAnimation(); |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10211 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10212 | |
| 10213 | if (scrollCache.state == ScrollabilityCache.OFF) { |
| 10214 | // FIXME: this is copied from WindowManagerService. |
| 10215 | // We should get this value from the system when it |
| 10216 | // is possible to do so. |
| 10217 | final int KEY_REPEAT_FIRST_DELAY = 750; |
| 10218 | startDelay = Math.max(KEY_REPEAT_FIRST_DELAY, startDelay); |
| 10219 | } |
| 10220 | |
| 10221 | // Tell mScrollCache when we should start fading. This may |
| 10222 | // extend the fade start time if one was already scheduled |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 10223 | long fadeStartTime = AnimationUtils.currentAnimationTimeMillis() + startDelay; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10224 | scrollCache.fadeStartTime = fadeStartTime; |
| 10225 | scrollCache.state = ScrollabilityCache.ON; |
| 10226 | |
| 10227 | // Schedule our fader to run, unscheduling any old ones first |
| 10228 | if (mAttachInfo != null) { |
| 10229 | mAttachInfo.mHandler.removeCallbacks(scrollCache); |
| 10230 | mAttachInfo.mHandler.postAtTime(scrollCache, fadeStartTime); |
| 10231 | } |
| 10232 | |
| 10233 | return true; |
| 10234 | } |
| 10235 | |
| 10236 | return false; |
| 10237 | } |
| 10238 | |
| 10239 | /** |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10240 | * Do not invalidate views which are not visible and which are not running an animation. They |
| 10241 | * will not get drawn and they should not set dirty flags as if they will be drawn |
| 10242 | */ |
| 10243 | private boolean skipInvalidate() { |
| 10244 | return (mViewFlags & VISIBILITY_MASK) != VISIBLE && mCurrentAnimation == null && |
| 10245 | (!(mParent instanceof ViewGroup) || |
| 10246 | !((ViewGroup) mParent).isViewTransitioning(this)); |
| 10247 | } |
| 10248 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 10249 | * 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] | 10250 | * visible, {@link #onDraw(android.graphics.Canvas)} will be called at some point |
| 10251 | * in the future. This must be called from a UI thread. To call from a non-UI |
| 10252 | * thread, call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10253 | * |
| 10254 | * WARNING: This method is destructive to dirty. |
| 10255 | * @param dirty the rectangle representing the bounds of the dirty region |
| 10256 | */ |
| 10257 | public void invalidate(Rect dirty) { |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10258 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 10259 | return; |
| 10260 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10261 | if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_HAS_BOUNDS)) == (PFLAG_DRAWN | PFLAG_HAS_BOUNDS) || |
| 10262 | (mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == PFLAG_DRAWING_CACHE_VALID || |
| 10263 | (mPrivateFlags & PFLAG_INVALIDATED) != PFLAG_INVALIDATED) { |
| 10264 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
| 10265 | mPrivateFlags |= PFLAG_INVALIDATED; |
| 10266 | mPrivateFlags |= PFLAG_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10267 | final ViewParent p = mParent; |
| 10268 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10269 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 10270 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 10271 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 10272 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 10273 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10274 | p.invalidateChild(this, null); |
| 10275 | return; |
| 10276 | } |
Romain Guy | af636eb | 2010-12-09 17:47:21 -0800 | [diff] [blame] | 10277 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10278 | if (p != null && ai != null) { |
| 10279 | final int scrollX = mScrollX; |
| 10280 | final int scrollY = mScrollY; |
| 10281 | final Rect r = ai.mTmpInvalRect; |
| 10282 | r.set(dirty.left - scrollX, dirty.top - scrollY, |
| 10283 | dirty.right - scrollX, dirty.bottom - scrollY); |
| 10284 | mParent.invalidateChild(this, r); |
| 10285 | } |
| 10286 | } |
| 10287 | } |
| 10288 | |
| 10289 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 10290 | * 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] | 10291 | * The coordinates of the dirty rect are relative to the view. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10292 | * If the view is visible, {@link #onDraw(android.graphics.Canvas)} |
| 10293 | * will be called at some point in the future. This must be called from |
| 10294 | * 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] | 10295 | * @param l the left position of the dirty region |
| 10296 | * @param t the top position of the dirty region |
| 10297 | * @param r the right position of the dirty region |
| 10298 | * @param b the bottom position of the dirty region |
| 10299 | */ |
| 10300 | public void invalidate(int l, int t, int r, int b) { |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10301 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 10302 | return; |
| 10303 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10304 | if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_HAS_BOUNDS)) == (PFLAG_DRAWN | PFLAG_HAS_BOUNDS) || |
| 10305 | (mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == PFLAG_DRAWING_CACHE_VALID || |
| 10306 | (mPrivateFlags & PFLAG_INVALIDATED) != PFLAG_INVALIDATED) { |
| 10307 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
| 10308 | mPrivateFlags |= PFLAG_INVALIDATED; |
| 10309 | mPrivateFlags |= PFLAG_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10310 | final ViewParent p = mParent; |
| 10311 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10312 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 10313 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 10314 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 10315 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 10316 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10317 | p.invalidateChild(this, null); |
| 10318 | return; |
| 10319 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 10320 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10321 | if (p != null && ai != null && l < r && t < b) { |
| 10322 | final int scrollX = mScrollX; |
| 10323 | final int scrollY = mScrollY; |
| 10324 | final Rect tmpr = ai.mTmpInvalRect; |
| 10325 | tmpr.set(l - scrollX, t - scrollY, r - scrollX, b - scrollY); |
| 10326 | p.invalidateChild(this, tmpr); |
| 10327 | } |
| 10328 | } |
| 10329 | } |
| 10330 | |
| 10331 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10332 | * Invalidate the whole view. If the view is visible, |
| 10333 | * {@link #onDraw(android.graphics.Canvas)} will be called at some point in |
| 10334 | * the future. This must be called from a UI thread. To call from a non-UI thread, |
| 10335 | * call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10336 | */ |
| 10337 | public void invalidate() { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10338 | invalidate(true); |
| 10339 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10340 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10341 | /** |
| 10342 | * This is where the invalidate() work actually happens. A full invalidate() |
| 10343 | * causes the drawing cache to be invalidated, but this function can be called with |
| 10344 | * invalidateCache set to false to skip that invalidation step for cases that do not |
| 10345 | * need it (for example, a component that remains at the same dimensions with the same |
| 10346 | * content). |
| 10347 | * |
| 10348 | * @param invalidateCache Whether the drawing cache for this view should be invalidated as |
| 10349 | * well. This is usually true for a full invalidate, but may be set to false if the |
| 10350 | * View's contents or dimensions have not changed. |
| 10351 | */ |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 10352 | void invalidate(boolean invalidateCache) { |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10353 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 10354 | return; |
| 10355 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10356 | if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_HAS_BOUNDS)) == (PFLAG_DRAWN | PFLAG_HAS_BOUNDS) || |
| 10357 | (invalidateCache && (mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == PFLAG_DRAWING_CACHE_VALID) || |
| 10358 | (mPrivateFlags & PFLAG_INVALIDATED) != PFLAG_INVALIDATED || isOpaque() != mLastIsOpaque) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10359 | mLastIsOpaque = isOpaque(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10360 | mPrivateFlags &= ~PFLAG_DRAWN; |
| 10361 | mPrivateFlags |= PFLAG_DIRTY; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10362 | if (invalidateCache) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10363 | mPrivateFlags |= PFLAG_INVALIDATED; |
| 10364 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10365 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10366 | final AttachInfo ai = mAttachInfo; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 10367 | final ViewParent p = mParent; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10368 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 10369 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 10370 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 10371 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 10372 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10373 | p.invalidateChild(this, null); |
| 10374 | return; |
| 10375 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 10376 | } |
Michael Jurka | ebefea4 | 2010-11-15 16:04:01 -0800 | [diff] [blame] | 10377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10378 | if (p != null && ai != null) { |
| 10379 | final Rect r = ai.mTmpInvalRect; |
| 10380 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 10381 | // Don't call invalidate -- we don't want to internally scroll |
| 10382 | // our own bounds |
| 10383 | p.invalidateChild(this, r); |
| 10384 | } |
| 10385 | } |
| 10386 | } |
| 10387 | |
| 10388 | /** |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10389 | * Quick invalidation for View property changes (alpha, translationXY, etc.). We don't want to |
| 10390 | * set any flags or handle all of the cases handled by the default invalidation methods. |
| 10391 | * Instead, we just want to schedule a traversal in ViewRootImpl with the appropriate |
| 10392 | * dirty rect. This method calls into fast invalidation methods in ViewGroup that |
| 10393 | * walk up the hierarchy, transforming the dirty rect as necessary. |
| 10394 | * |
| 10395 | * The method also handles normal invalidation logic if display list properties are not |
| 10396 | * being used in this view. The invalidateParent and forceRedraw flags are used by that |
| 10397 | * backup approach, to handle these cases used in the various property-setting methods. |
| 10398 | * |
| 10399 | * @param invalidateParent Force a call to invalidateParentCaches() if display list properties |
| 10400 | * are not being used in this view |
| 10401 | * @param forceRedraw Mark the view as DRAWN to force the invalidation to propagate, if display |
| 10402 | * list properties are not being used in this view |
| 10403 | */ |
| 10404 | void invalidateViewProperty(boolean invalidateParent, boolean forceRedraw) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10405 | if (mDisplayList == null || (mPrivateFlags & PFLAG_DRAW_ANIMATION) == PFLAG_DRAW_ANIMATION) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10406 | if (invalidateParent) { |
| 10407 | invalidateParentCaches(); |
| 10408 | } |
| 10409 | if (forceRedraw) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10410 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10411 | } |
| 10412 | invalidate(false); |
| 10413 | } else { |
| 10414 | final AttachInfo ai = mAttachInfo; |
| 10415 | final ViewParent p = mParent; |
| 10416 | if (p != null && ai != null) { |
| 10417 | final Rect r = ai.mTmpInvalRect; |
| 10418 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 10419 | if (mParent instanceof ViewGroup) { |
| 10420 | ((ViewGroup) mParent).invalidateChildFast(this, r); |
| 10421 | } else { |
| 10422 | mParent.invalidateChild(this, r); |
| 10423 | } |
| 10424 | } |
| 10425 | } |
| 10426 | } |
| 10427 | |
| 10428 | /** |
| 10429 | * Utility method to transform a given Rect by the current matrix of this view. |
| 10430 | */ |
| 10431 | void transformRect(final Rect rect) { |
| 10432 | if (!getMatrix().isIdentity()) { |
| 10433 | RectF boundingRect = mAttachInfo.mTmpTransformRect; |
| 10434 | boundingRect.set(rect); |
| 10435 | getMatrix().mapRect(boundingRect); |
| 10436 | rect.set((int) (boundingRect.left - 0.5f), |
| 10437 | (int) (boundingRect.top - 0.5f), |
| 10438 | (int) (boundingRect.right + 0.5f), |
| 10439 | (int) (boundingRect.bottom + 0.5f)); |
| 10440 | } |
| 10441 | } |
| 10442 | |
| 10443 | /** |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10444 | * 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] | 10445 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 10446 | * 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] | 10447 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method only |
| 10448 | * clears the parent caches and does not causes an invalidate event. |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10449 | * |
| 10450 | * @hide |
| 10451 | */ |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10452 | protected void invalidateParentCaches() { |
| 10453 | if (mParent instanceof View) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10454 | ((View) mParent).mPrivateFlags |= PFLAG_INVALIDATED; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10455 | } |
| 10456 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10457 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10458 | /** |
| 10459 | * Used to indicate that the parent of this view should be invalidated. This functionality |
| 10460 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 10461 | * which is necessary when various parent-managed properties of the view change, such as |
| 10462 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method will propagate |
| 10463 | * an invalidation event to the parent. |
| 10464 | * |
| 10465 | * @hide |
| 10466 | */ |
| 10467 | protected void invalidateParentIfNeeded() { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10468 | if (isHardwareAccelerated() && mParent instanceof View) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10469 | ((View) mParent).invalidate(true); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10470 | } |
| 10471 | } |
| 10472 | |
| 10473 | /** |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10474 | * Indicates whether this View is opaque. An opaque View guarantees that it will |
| 10475 | * draw all the pixels overlapping its bounds using a fully opaque color. |
| 10476 | * |
| 10477 | * Subclasses of View should override this method whenever possible to indicate |
| 10478 | * whether an instance is opaque. Opaque Views are treated in a special way by |
| 10479 | * the View hierarchy, possibly allowing it to perform optimizations during |
| 10480 | * invalidate/draw passes. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10481 | * |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10482 | * @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] | 10483 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 10484 | @ViewDebug.ExportedProperty(category = "drawing") |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10485 | public boolean isOpaque() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10486 | return (mPrivateFlags & PFLAG_OPAQUE_MASK) == PFLAG_OPAQUE_MASK && |
Romain Guy | f877308 | 2012-07-12 18:01:00 -0700 | [diff] [blame] | 10487 | ((mTransformationInfo != null ? mTransformationInfo.mAlpha : 1.0f) >= 1.0f); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10488 | } |
| 10489 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 10490 | /** |
| 10491 | * @hide |
| 10492 | */ |
| 10493 | protected void computeOpaqueFlags() { |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10494 | // Opaque if: |
| 10495 | // - Has a background |
| 10496 | // - Background is opaque |
| 10497 | // - Doesn't have scrollbars or scrollbars are inside overlay |
| 10498 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10499 | if (mBackground != null && mBackground.getOpacity() == PixelFormat.OPAQUE) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10500 | mPrivateFlags |= PFLAG_OPAQUE_BACKGROUND; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10501 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10502 | mPrivateFlags &= ~PFLAG_OPAQUE_BACKGROUND; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10503 | } |
| 10504 | |
| 10505 | final int flags = mViewFlags; |
| 10506 | if (((flags & SCROLLBARS_VERTICAL) == 0 && (flags & SCROLLBARS_HORIZONTAL) == 0) || |
| 10507 | (flags & SCROLLBARS_STYLE_MASK) == SCROLLBARS_INSIDE_OVERLAY) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10508 | mPrivateFlags |= PFLAG_OPAQUE_SCROLLBARS; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10509 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10510 | mPrivateFlags &= ~PFLAG_OPAQUE_SCROLLBARS; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10511 | } |
| 10512 | } |
| 10513 | |
| 10514 | /** |
| 10515 | * @hide |
| 10516 | */ |
| 10517 | protected boolean hasOpaqueScrollbars() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10518 | return (mPrivateFlags & PFLAG_OPAQUE_SCROLLBARS) == PFLAG_OPAQUE_SCROLLBARS; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10519 | } |
| 10520 | |
| 10521 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10522 | * @return A handler associated with the thread running the View. This |
| 10523 | * handler can be used to pump events in the UI events queue. |
| 10524 | */ |
| 10525 | public Handler getHandler() { |
| 10526 | if (mAttachInfo != null) { |
| 10527 | return mAttachInfo.mHandler; |
| 10528 | } |
| 10529 | return null; |
| 10530 | } |
| 10531 | |
| 10532 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10533 | * Gets the view root associated with the View. |
| 10534 | * @return The view root, or null if none. |
| 10535 | * @hide |
| 10536 | */ |
| 10537 | public ViewRootImpl getViewRootImpl() { |
| 10538 | if (mAttachInfo != null) { |
| 10539 | return mAttachInfo.mViewRootImpl; |
| 10540 | } |
| 10541 | return null; |
| 10542 | } |
| 10543 | |
| 10544 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10545 | * <p>Causes the Runnable to be added to the message queue. |
| 10546 | * The runnable will be run on the user interface thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10547 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10548 | * @param action The Runnable that will be executed. |
| 10549 | * |
| 10550 | * @return Returns true if the Runnable was successfully placed in to the |
| 10551 | * message queue. Returns false on failure, usually because the |
| 10552 | * looper processing the message queue is exiting. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10553 | * |
| 10554 | * @see #postDelayed |
| 10555 | * @see #removeCallbacks |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10556 | */ |
| 10557 | public boolean post(Runnable action) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10558 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10559 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10560 | return attachInfo.mHandler.post(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10561 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10562 | // Assume that post will succeed later |
| 10563 | ViewRootImpl.getRunQueue().post(action); |
| 10564 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10565 | } |
| 10566 | |
| 10567 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10568 | * <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] | 10569 | * after the specified amount of time elapses. |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10570 | * The runnable will be run on the user interface thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10571 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10572 | * @param action The Runnable that will be executed. |
| 10573 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 10574 | * will be executed. |
| 10575 | * |
| 10576 | * @return true if the Runnable was successfully placed in to the |
| 10577 | * message queue. Returns false on failure, usually because the |
| 10578 | * looper processing the message queue is exiting. Note that a |
| 10579 | * result of true does not mean the Runnable will be processed -- |
| 10580 | * if the looper is quit before the delivery time of the message |
| 10581 | * occurs then the message will be dropped. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10582 | * |
| 10583 | * @see #post |
| 10584 | * @see #removeCallbacks |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10585 | */ |
| 10586 | public boolean postDelayed(Runnable action, long delayMillis) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10587 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10588 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10589 | return attachInfo.mHandler.postDelayed(action, delayMillis); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10590 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10591 | // Assume that post will succeed later |
| 10592 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 10593 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10594 | } |
| 10595 | |
| 10596 | /** |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10597 | * <p>Causes the Runnable to execute on the next animation time step. |
| 10598 | * The runnable will be run on the user interface thread.</p> |
| 10599 | * |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10600 | * @param action The Runnable that will be executed. |
| 10601 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10602 | * @see #postOnAnimationDelayed |
| 10603 | * @see #removeCallbacks |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10604 | */ |
| 10605 | public void postOnAnimation(Runnable action) { |
| 10606 | final AttachInfo attachInfo = mAttachInfo; |
| 10607 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 10608 | attachInfo.mViewRootImpl.mChoreographer.postCallback( |
| 10609 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10610 | } else { |
| 10611 | // Assume that post will succeed later |
| 10612 | ViewRootImpl.getRunQueue().post(action); |
| 10613 | } |
| 10614 | } |
| 10615 | |
| 10616 | /** |
| 10617 | * <p>Causes the Runnable to execute on the next animation time step, |
| 10618 | * after the specified amount of time elapses. |
| 10619 | * The runnable will be run on the user interface thread.</p> |
| 10620 | * |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10621 | * @param action The Runnable that will be executed. |
| 10622 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 10623 | * will be executed. |
| 10624 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10625 | * @see #postOnAnimation |
| 10626 | * @see #removeCallbacks |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10627 | */ |
| 10628 | public void postOnAnimationDelayed(Runnable action, long delayMillis) { |
| 10629 | final AttachInfo attachInfo = mAttachInfo; |
| 10630 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 10631 | attachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 10632 | Choreographer.CALLBACK_ANIMATION, action, null, delayMillis); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10633 | } else { |
| 10634 | // Assume that post will succeed later |
| 10635 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 10636 | } |
| 10637 | } |
| 10638 | |
| 10639 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10640 | * <p>Removes the specified Runnable from the message queue.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10641 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10642 | * @param action The Runnable to remove from the message handling queue |
| 10643 | * |
| 10644 | * @return true if this view could ask the Handler to remove the Runnable, |
| 10645 | * false otherwise. When the returned value is true, the Runnable |
| 10646 | * may or may not have been actually removed from the message queue |
| 10647 | * (for instance, if the Runnable was not in the queue already.) |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10648 | * |
| 10649 | * @see #post |
| 10650 | * @see #postDelayed |
| 10651 | * @see #postOnAnimation |
| 10652 | * @see #postOnAnimationDelayed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10653 | */ |
| 10654 | public boolean removeCallbacks(Runnable action) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 10655 | if (action != null) { |
| 10656 | final AttachInfo attachInfo = mAttachInfo; |
| 10657 | if (attachInfo != null) { |
| 10658 | attachInfo.mHandler.removeCallbacks(action); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 10659 | attachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 10660 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 10661 | } else { |
| 10662 | // Assume that post will succeed later |
| 10663 | ViewRootImpl.getRunQueue().removeCallbacks(action); |
| 10664 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10665 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10666 | return true; |
| 10667 | } |
| 10668 | |
| 10669 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10670 | * <p>Cause an invalidate to happen on a subsequent cycle through the event loop. |
| 10671 | * 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] | 10672 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10673 | * <p>This method can be invoked from outside of the UI thread |
| 10674 | * only when this View is attached to a window.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10675 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10676 | * @see #invalidate() |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10677 | * @see #postInvalidateDelayed(long) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10678 | */ |
| 10679 | public void postInvalidate() { |
| 10680 | postInvalidateDelayed(0); |
| 10681 | } |
| 10682 | |
| 10683 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10684 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 10685 | * through the event loop. Use this to invalidate the View from a non-UI thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10686 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10687 | * <p>This method can be invoked from outside of the UI thread |
| 10688 | * 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] | 10689 | * |
| 10690 | * @param left The left coordinate of the rectangle to invalidate. |
| 10691 | * @param top The top coordinate of the rectangle to invalidate. |
| 10692 | * @param right The right coordinate of the rectangle to invalidate. |
| 10693 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 10694 | * |
| 10695 | * @see #invalidate(int, int, int, int) |
| 10696 | * @see #invalidate(Rect) |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10697 | * @see #postInvalidateDelayed(long, int, int, int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10698 | */ |
| 10699 | public void postInvalidate(int left, int top, int right, int bottom) { |
| 10700 | postInvalidateDelayed(0, left, top, right, bottom); |
| 10701 | } |
| 10702 | |
| 10703 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10704 | * <p>Cause an invalidate to happen on a subsequent cycle through the event |
| 10705 | * loop. Waits for the specified amount of time.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10706 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10707 | * <p>This method can be invoked from outside of the UI thread |
| 10708 | * 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] | 10709 | * |
| 10710 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 10711 | * invalidation by |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10712 | * |
| 10713 | * @see #invalidate() |
| 10714 | * @see #postInvalidate() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10715 | */ |
| 10716 | public void postInvalidateDelayed(long delayMilliseconds) { |
| 10717 | // We try only with the AttachInfo because there's no point in invalidating |
| 10718 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10719 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10720 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10721 | attachInfo.mViewRootImpl.dispatchInvalidateDelayed(this, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10722 | } |
| 10723 | } |
| 10724 | |
| 10725 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10726 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 10727 | * through the event loop. Waits for the specified amount of time.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10728 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10729 | * <p>This method can be invoked from outside of the UI thread |
| 10730 | * 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] | 10731 | * |
| 10732 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 10733 | * invalidation by |
| 10734 | * @param left The left coordinate of the rectangle to invalidate. |
| 10735 | * @param top The top coordinate of the rectangle to invalidate. |
| 10736 | * @param right The right coordinate of the rectangle to invalidate. |
| 10737 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10738 | * |
| 10739 | * @see #invalidate(int, int, int, int) |
| 10740 | * @see #invalidate(Rect) |
| 10741 | * @see #postInvalidate(int, int, int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10742 | */ |
| 10743 | public void postInvalidateDelayed(long delayMilliseconds, int left, int top, |
| 10744 | int right, int bottom) { |
| 10745 | |
| 10746 | // We try only with the AttachInfo because there's no point in invalidating |
| 10747 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10748 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10749 | if (attachInfo != null) { |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 10750 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.obtain(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10751 | info.target = this; |
| 10752 | info.left = left; |
| 10753 | info.top = top; |
| 10754 | info.right = right; |
| 10755 | info.bottom = bottom; |
| 10756 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10757 | attachInfo.mViewRootImpl.dispatchInvalidateRectDelayed(info, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10758 | } |
| 10759 | } |
| 10760 | |
| 10761 | /** |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10762 | * <p>Cause an invalidate to happen on the next animation time step, typically the |
| 10763 | * next display frame.</p> |
| 10764 | * |
| 10765 | * <p>This method can be invoked from outside of the UI thread |
| 10766 | * only when this View is attached to a window.</p> |
| 10767 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10768 | * @see #invalidate() |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10769 | */ |
| 10770 | public void postInvalidateOnAnimation() { |
| 10771 | // We try only with the AttachInfo because there's no point in invalidating |
| 10772 | // if we are not attached to our window |
| 10773 | final AttachInfo attachInfo = mAttachInfo; |
| 10774 | if (attachInfo != null) { |
| 10775 | attachInfo.mViewRootImpl.dispatchInvalidateOnAnimation(this); |
| 10776 | } |
| 10777 | } |
| 10778 | |
| 10779 | /** |
| 10780 | * <p>Cause an invalidate of the specified area to happen on the next animation |
| 10781 | * time step, typically the next display frame.</p> |
| 10782 | * |
| 10783 | * <p>This method can be invoked from outside of the UI thread |
| 10784 | * only when this View is attached to a window.</p> |
| 10785 | * |
| 10786 | * @param left The left coordinate of the rectangle to invalidate. |
| 10787 | * @param top The top coordinate of the rectangle to invalidate. |
| 10788 | * @param right The right coordinate of the rectangle to invalidate. |
| 10789 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 10790 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10791 | * @see #invalidate(int, int, int, int) |
| 10792 | * @see #invalidate(Rect) |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10793 | */ |
| 10794 | public void postInvalidateOnAnimation(int left, int top, int right, int bottom) { |
| 10795 | // We try only with the AttachInfo because there's no point in invalidating |
| 10796 | // if we are not attached to our window |
| 10797 | final AttachInfo attachInfo = mAttachInfo; |
| 10798 | if (attachInfo != null) { |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 10799 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.obtain(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10800 | info.target = this; |
| 10801 | info.left = left; |
| 10802 | info.top = top; |
| 10803 | info.right = right; |
| 10804 | info.bottom = bottom; |
| 10805 | |
| 10806 | attachInfo.mViewRootImpl.dispatchInvalidateRectOnAnimation(info); |
| 10807 | } |
| 10808 | } |
| 10809 | |
| 10810 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 10811 | * Post a callback to send a {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} event. |
| 10812 | * This event is sent at most once every |
| 10813 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
| 10814 | */ |
| 10815 | private void postSendViewScrolledAccessibilityEventCallback() { |
| 10816 | if (mSendViewScrolledAccessibilityEvent == null) { |
| 10817 | mSendViewScrolledAccessibilityEvent = new SendViewScrolledAccessibilityEvent(); |
| 10818 | } |
| 10819 | if (!mSendViewScrolledAccessibilityEvent.mIsPending) { |
| 10820 | mSendViewScrolledAccessibilityEvent.mIsPending = true; |
| 10821 | postDelayed(mSendViewScrolledAccessibilityEvent, |
| 10822 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval()); |
| 10823 | } |
| 10824 | } |
| 10825 | |
| 10826 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10827 | * Called by a parent to request that a child update its values for mScrollX |
| 10828 | * and mScrollY if necessary. This will typically be done if the child is |
| 10829 | * animating a scroll using a {@link android.widget.Scroller Scroller} |
| 10830 | * object. |
| 10831 | */ |
| 10832 | public void computeScroll() { |
| 10833 | } |
| 10834 | |
| 10835 | /** |
| 10836 | * <p>Indicate whether the horizontal edges are faded when the view is |
| 10837 | * scrolled horizontally.</p> |
| 10838 | * |
| 10839 | * @return true if the horizontal edges should are faded on scroll, false |
| 10840 | * otherwise |
| 10841 | * |
| 10842 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10843 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10844 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10845 | */ |
| 10846 | public boolean isHorizontalFadingEdgeEnabled() { |
| 10847 | return (mViewFlags & FADING_EDGE_HORIZONTAL) == FADING_EDGE_HORIZONTAL; |
| 10848 | } |
| 10849 | |
| 10850 | /** |
| 10851 | * <p>Define whether the horizontal edges should be faded when this view |
| 10852 | * is scrolled horizontally.</p> |
| 10853 | * |
| 10854 | * @param horizontalFadingEdgeEnabled true if the horizontal edges should |
| 10855 | * be faded when the view is scrolled |
| 10856 | * horizontally |
| 10857 | * |
| 10858 | * @see #isHorizontalFadingEdgeEnabled() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10859 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10860 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10861 | */ |
| 10862 | public void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled) { |
| 10863 | if (isHorizontalFadingEdgeEnabled() != horizontalFadingEdgeEnabled) { |
| 10864 | if (horizontalFadingEdgeEnabled) { |
| 10865 | initScrollCache(); |
| 10866 | } |
| 10867 | |
| 10868 | mViewFlags ^= FADING_EDGE_HORIZONTAL; |
| 10869 | } |
| 10870 | } |
| 10871 | |
| 10872 | /** |
| 10873 | * <p>Indicate whether the vertical edges are faded when the view is |
| 10874 | * scrolled horizontally.</p> |
| 10875 | * |
| 10876 | * @return true if the vertical edges should are faded on scroll, false |
| 10877 | * otherwise |
| 10878 | * |
| 10879 | * @see #setVerticalFadingEdgeEnabled(boolean) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10880 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10881 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10882 | */ |
| 10883 | public boolean isVerticalFadingEdgeEnabled() { |
| 10884 | return (mViewFlags & FADING_EDGE_VERTICAL) == FADING_EDGE_VERTICAL; |
| 10885 | } |
| 10886 | |
| 10887 | /** |
| 10888 | * <p>Define whether the vertical edges should be faded when this view |
| 10889 | * is scrolled vertically.</p> |
| 10890 | * |
| 10891 | * @param verticalFadingEdgeEnabled true if the vertical edges should |
| 10892 | * be faded when the view is scrolled |
| 10893 | * vertically |
| 10894 | * |
| 10895 | * @see #isVerticalFadingEdgeEnabled() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10896 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10897 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10898 | */ |
| 10899 | public void setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled) { |
| 10900 | if (isVerticalFadingEdgeEnabled() != verticalFadingEdgeEnabled) { |
| 10901 | if (verticalFadingEdgeEnabled) { |
| 10902 | initScrollCache(); |
| 10903 | } |
| 10904 | |
| 10905 | mViewFlags ^= FADING_EDGE_VERTICAL; |
| 10906 | } |
| 10907 | } |
| 10908 | |
| 10909 | /** |
| 10910 | * Returns the strength, or intensity, of the top faded edge. The strength is |
| 10911 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10912 | * returns 0.0 or 1.0 but no value in between. |
| 10913 | * |
| 10914 | * Subclasses should override this method to provide a smoother fade transition |
| 10915 | * when scrolling occurs. |
| 10916 | * |
| 10917 | * @return the intensity of the top fade as a float between 0.0f and 1.0f |
| 10918 | */ |
| 10919 | protected float getTopFadingEdgeStrength() { |
| 10920 | return computeVerticalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 10921 | } |
| 10922 | |
| 10923 | /** |
| 10924 | * Returns the strength, or intensity, of the bottom faded edge. The strength is |
| 10925 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10926 | * returns 0.0 or 1.0 but no value in between. |
| 10927 | * |
| 10928 | * Subclasses should override this method to provide a smoother fade transition |
| 10929 | * when scrolling occurs. |
| 10930 | * |
| 10931 | * @return the intensity of the bottom fade as a float between 0.0f and 1.0f |
| 10932 | */ |
| 10933 | protected float getBottomFadingEdgeStrength() { |
| 10934 | return computeVerticalScrollOffset() + computeVerticalScrollExtent() < |
| 10935 | computeVerticalScrollRange() ? 1.0f : 0.0f; |
| 10936 | } |
| 10937 | |
| 10938 | /** |
| 10939 | * Returns the strength, or intensity, of the left faded edge. The strength is |
| 10940 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10941 | * returns 0.0 or 1.0 but no value in between. |
| 10942 | * |
| 10943 | * Subclasses should override this method to provide a smoother fade transition |
| 10944 | * when scrolling occurs. |
| 10945 | * |
| 10946 | * @return the intensity of the left fade as a float between 0.0f and 1.0f |
| 10947 | */ |
| 10948 | protected float getLeftFadingEdgeStrength() { |
| 10949 | return computeHorizontalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 10950 | } |
| 10951 | |
| 10952 | /** |
| 10953 | * Returns the strength, or intensity, of the right faded edge. The strength is |
| 10954 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10955 | * returns 0.0 or 1.0 but no value in between. |
| 10956 | * |
| 10957 | * Subclasses should override this method to provide a smoother fade transition |
| 10958 | * when scrolling occurs. |
| 10959 | * |
| 10960 | * @return the intensity of the right fade as a float between 0.0f and 1.0f |
| 10961 | */ |
| 10962 | protected float getRightFadingEdgeStrength() { |
| 10963 | return computeHorizontalScrollOffset() + computeHorizontalScrollExtent() < |
| 10964 | computeHorizontalScrollRange() ? 1.0f : 0.0f; |
| 10965 | } |
| 10966 | |
| 10967 | /** |
| 10968 | * <p>Indicate whether the horizontal scrollbar should be drawn or not. The |
| 10969 | * scrollbar is not drawn by default.</p> |
| 10970 | * |
| 10971 | * @return true if the horizontal scrollbar should be painted, false |
| 10972 | * otherwise |
| 10973 | * |
| 10974 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 10975 | */ |
| 10976 | public boolean isHorizontalScrollBarEnabled() { |
| 10977 | return (mViewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 10978 | } |
| 10979 | |
| 10980 | /** |
| 10981 | * <p>Define whether the horizontal scrollbar should be drawn or not. The |
| 10982 | * scrollbar is not drawn by default.</p> |
| 10983 | * |
| 10984 | * @param horizontalScrollBarEnabled true if the horizontal scrollbar should |
| 10985 | * be painted |
| 10986 | * |
| 10987 | * @see #isHorizontalScrollBarEnabled() |
| 10988 | */ |
| 10989 | public void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled) { |
| 10990 | if (isHorizontalScrollBarEnabled() != horizontalScrollBarEnabled) { |
| 10991 | mViewFlags ^= SCROLLBARS_HORIZONTAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10992 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10993 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10994 | } |
| 10995 | } |
| 10996 | |
| 10997 | /** |
| 10998 | * <p>Indicate whether the vertical scrollbar should be drawn or not. The |
| 10999 | * scrollbar is not drawn by default.</p> |
| 11000 | * |
| 11001 | * @return true if the vertical scrollbar should be painted, false |
| 11002 | * otherwise |
| 11003 | * |
| 11004 | * @see #setVerticalScrollBarEnabled(boolean) |
| 11005 | */ |
| 11006 | public boolean isVerticalScrollBarEnabled() { |
| 11007 | return (mViewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL; |
| 11008 | } |
| 11009 | |
| 11010 | /** |
| 11011 | * <p>Define whether the vertical scrollbar should be drawn or not. The |
| 11012 | * scrollbar is not drawn by default.</p> |
| 11013 | * |
| 11014 | * @param verticalScrollBarEnabled true if the vertical scrollbar should |
| 11015 | * be painted |
| 11016 | * |
| 11017 | * @see #isVerticalScrollBarEnabled() |
| 11018 | */ |
| 11019 | public void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled) { |
| 11020 | if (isVerticalScrollBarEnabled() != verticalScrollBarEnabled) { |
| 11021 | mViewFlags ^= SCROLLBARS_VERTICAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 11022 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11023 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11024 | } |
| 11025 | } |
| 11026 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11027 | /** |
| 11028 | * @hide |
| 11029 | */ |
| 11030 | protected void recomputePadding() { |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 11031 | internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11032 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11033 | |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 11034 | /** |
| 11035 | * Define whether scrollbars will fade when the view is not scrolling. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11036 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 11037 | * @param fadeScrollbars wheter to enable fading |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11038 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11039 | * @attr ref android.R.styleable#View_fadeScrollbars |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 11040 | */ |
| 11041 | public void setScrollbarFadingEnabled(boolean fadeScrollbars) { |
| 11042 | initScrollCache(); |
| 11043 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
| 11044 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11045 | if (fadeScrollbars) { |
| 11046 | scrollabilityCache.state = ScrollabilityCache.OFF; |
| 11047 | } else { |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 11048 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 11049 | } |
| 11050 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11051 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11052 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11053 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11054 | * Returns true if scrollbars will fade when this view is not scrolling |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11055 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11056 | * @return true if scrollbar fading is enabled |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11057 | * |
| 11058 | * @attr ref android.R.styleable#View_fadeScrollbars |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11059 | */ |
| 11060 | public boolean isScrollbarFadingEnabled() { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11061 | return mScrollCache != null && mScrollCache.fadeScrollBars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11062 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11063 | |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11064 | /** |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11065 | * |
| 11066 | * Returns the delay before scrollbars fade. |
| 11067 | * |
| 11068 | * @return the delay before scrollbars fade |
| 11069 | * |
| 11070 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 11071 | */ |
| 11072 | public int getScrollBarDefaultDelayBeforeFade() { |
| 11073 | return mScrollCache == null ? ViewConfiguration.getScrollDefaultDelay() : |
| 11074 | mScrollCache.scrollBarDefaultDelayBeforeFade; |
| 11075 | } |
| 11076 | |
| 11077 | /** |
| 11078 | * Define the delay before scrollbars fade. |
| 11079 | * |
| 11080 | * @param scrollBarDefaultDelayBeforeFade - the delay before scrollbars fade |
| 11081 | * |
| 11082 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 11083 | */ |
| 11084 | public void setScrollBarDefaultDelayBeforeFade(int scrollBarDefaultDelayBeforeFade) { |
| 11085 | getScrollCache().scrollBarDefaultDelayBeforeFade = scrollBarDefaultDelayBeforeFade; |
| 11086 | } |
| 11087 | |
| 11088 | /** |
| 11089 | * |
| 11090 | * Returns the scrollbar fade duration. |
| 11091 | * |
| 11092 | * @return the scrollbar fade duration |
| 11093 | * |
| 11094 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
| 11095 | */ |
| 11096 | public int getScrollBarFadeDuration() { |
| 11097 | return mScrollCache == null ? ViewConfiguration.getScrollBarFadeDuration() : |
| 11098 | mScrollCache.scrollBarFadeDuration; |
| 11099 | } |
| 11100 | |
| 11101 | /** |
| 11102 | * Define the scrollbar fade duration. |
| 11103 | * |
| 11104 | * @param scrollBarFadeDuration - the scrollbar fade duration |
| 11105 | * |
| 11106 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
| 11107 | */ |
| 11108 | public void setScrollBarFadeDuration(int scrollBarFadeDuration) { |
| 11109 | getScrollCache().scrollBarFadeDuration = scrollBarFadeDuration; |
| 11110 | } |
| 11111 | |
| 11112 | /** |
| 11113 | * |
| 11114 | * Returns the scrollbar size. |
| 11115 | * |
| 11116 | * @return the scrollbar size |
| 11117 | * |
| 11118 | * @attr ref android.R.styleable#View_scrollbarSize |
| 11119 | */ |
| 11120 | public int getScrollBarSize() { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 11121 | return mScrollCache == null ? ViewConfiguration.get(mContext).getScaledScrollBarSize() : |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11122 | mScrollCache.scrollBarSize; |
| 11123 | } |
| 11124 | |
| 11125 | /** |
| 11126 | * Define the scrollbar size. |
| 11127 | * |
| 11128 | * @param scrollBarSize - the scrollbar size |
| 11129 | * |
| 11130 | * @attr ref android.R.styleable#View_scrollbarSize |
| 11131 | */ |
| 11132 | public void setScrollBarSize(int scrollBarSize) { |
| 11133 | getScrollCache().scrollBarSize = scrollBarSize; |
| 11134 | } |
| 11135 | |
| 11136 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11137 | * <p>Specify the style of the scrollbars. The scrollbars can be overlaid or |
| 11138 | * inset. When inset, they add to the padding of the view. And the scrollbars |
| 11139 | * can be drawn inside the padding area or on the edge of the view. For example, |
| 11140 | * if a view has a background drawable and you want to draw the scrollbars |
| 11141 | * inside the padding specified by the drawable, you can use |
| 11142 | * SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to |
| 11143 | * appear at the edge of the view, ignoring the padding, then you can use |
| 11144 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.</p> |
| 11145 | * @param style the style of the scrollbars. Should be one of |
| 11146 | * SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, |
| 11147 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. |
| 11148 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 11149 | * @see #SCROLLBARS_INSIDE_INSET |
| 11150 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 11151 | * @see #SCROLLBARS_OUTSIDE_INSET |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11152 | * |
| 11153 | * @attr ref android.R.styleable#View_scrollbarStyle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11154 | */ |
| 11155 | public void setScrollBarStyle(int style) { |
| 11156 | if (style != (mViewFlags & SCROLLBARS_STYLE_MASK)) { |
| 11157 | mViewFlags = (mViewFlags & ~SCROLLBARS_STYLE_MASK) | (style & SCROLLBARS_STYLE_MASK); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 11158 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11159 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11160 | } |
| 11161 | } |
| 11162 | |
| 11163 | /** |
| 11164 | * <p>Returns the current scrollbar style.</p> |
| 11165 | * @return the current scrollbar style |
| 11166 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 11167 | * @see #SCROLLBARS_INSIDE_INSET |
| 11168 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 11169 | * @see #SCROLLBARS_OUTSIDE_INSET |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11170 | * |
| 11171 | * @attr ref android.R.styleable#View_scrollbarStyle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11172 | */ |
Jeff Sharkey | 010d7e5 | 2011-08-08 21:05:02 -0700 | [diff] [blame] | 11173 | @ViewDebug.ExportedProperty(mapping = { |
| 11174 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_OVERLAY, to = "INSIDE_OVERLAY"), |
| 11175 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_INSET, to = "INSIDE_INSET"), |
| 11176 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_OVERLAY, to = "OUTSIDE_OVERLAY"), |
| 11177 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_INSET, to = "OUTSIDE_INSET") |
| 11178 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11179 | public int getScrollBarStyle() { |
| 11180 | return mViewFlags & SCROLLBARS_STYLE_MASK; |
| 11181 | } |
| 11182 | |
| 11183 | /** |
| 11184 | * <p>Compute the horizontal range that the horizontal scrollbar |
| 11185 | * represents.</p> |
| 11186 | * |
| 11187 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11188 | * units used by {@link #computeHorizontalScrollExtent()} and |
| 11189 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 11190 | * |
| 11191 | * <p>The default range is the drawing width of this view.</p> |
| 11192 | * |
| 11193 | * @return the total horizontal range represented by the horizontal |
| 11194 | * scrollbar |
| 11195 | * |
| 11196 | * @see #computeHorizontalScrollExtent() |
| 11197 | * @see #computeHorizontalScrollOffset() |
| 11198 | * @see android.widget.ScrollBarDrawable |
| 11199 | */ |
| 11200 | protected int computeHorizontalScrollRange() { |
| 11201 | return getWidth(); |
| 11202 | } |
| 11203 | |
| 11204 | /** |
| 11205 | * <p>Compute the horizontal offset of the horizontal scrollbar's thumb |
| 11206 | * within the horizontal range. This value is used to compute the position |
| 11207 | * of the thumb within the scrollbar's track.</p> |
| 11208 | * |
| 11209 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11210 | * units used by {@link #computeHorizontalScrollRange()} and |
| 11211 | * {@link #computeHorizontalScrollExtent()}.</p> |
| 11212 | * |
| 11213 | * <p>The default offset is the scroll offset of this view.</p> |
| 11214 | * |
| 11215 | * @return the horizontal offset of the scrollbar's thumb |
| 11216 | * |
| 11217 | * @see #computeHorizontalScrollRange() |
| 11218 | * @see #computeHorizontalScrollExtent() |
| 11219 | * @see android.widget.ScrollBarDrawable |
| 11220 | */ |
| 11221 | protected int computeHorizontalScrollOffset() { |
| 11222 | return mScrollX; |
| 11223 | } |
| 11224 | |
| 11225 | /** |
| 11226 | * <p>Compute the horizontal extent of the horizontal scrollbar's thumb |
| 11227 | * within the horizontal range. This value is used to compute the length |
| 11228 | * of the thumb within the scrollbar's track.</p> |
| 11229 | * |
| 11230 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11231 | * units used by {@link #computeHorizontalScrollRange()} and |
| 11232 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 11233 | * |
| 11234 | * <p>The default extent is the drawing width of this view.</p> |
| 11235 | * |
| 11236 | * @return the horizontal extent of the scrollbar's thumb |
| 11237 | * |
| 11238 | * @see #computeHorizontalScrollRange() |
| 11239 | * @see #computeHorizontalScrollOffset() |
| 11240 | * @see android.widget.ScrollBarDrawable |
| 11241 | */ |
| 11242 | protected int computeHorizontalScrollExtent() { |
| 11243 | return getWidth(); |
| 11244 | } |
| 11245 | |
| 11246 | /** |
| 11247 | * <p>Compute the vertical range that the vertical scrollbar represents.</p> |
| 11248 | * |
| 11249 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11250 | * units used by {@link #computeVerticalScrollExtent()} and |
| 11251 | * {@link #computeVerticalScrollOffset()}.</p> |
| 11252 | * |
| 11253 | * @return the total vertical range represented by the vertical scrollbar |
| 11254 | * |
| 11255 | * <p>The default range is the drawing height of this view.</p> |
| 11256 | * |
| 11257 | * @see #computeVerticalScrollExtent() |
| 11258 | * @see #computeVerticalScrollOffset() |
| 11259 | * @see android.widget.ScrollBarDrawable |
| 11260 | */ |
| 11261 | protected int computeVerticalScrollRange() { |
| 11262 | return getHeight(); |
| 11263 | } |
| 11264 | |
| 11265 | /** |
| 11266 | * <p>Compute the vertical offset of the vertical scrollbar's thumb |
| 11267 | * within the horizontal range. This value is used to compute the position |
| 11268 | * of the thumb within the scrollbar's track.</p> |
| 11269 | * |
| 11270 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11271 | * units used by {@link #computeVerticalScrollRange()} and |
| 11272 | * {@link #computeVerticalScrollExtent()}.</p> |
| 11273 | * |
| 11274 | * <p>The default offset is the scroll offset of this view.</p> |
| 11275 | * |
| 11276 | * @return the vertical offset of the scrollbar's thumb |
| 11277 | * |
| 11278 | * @see #computeVerticalScrollRange() |
| 11279 | * @see #computeVerticalScrollExtent() |
| 11280 | * @see android.widget.ScrollBarDrawable |
| 11281 | */ |
| 11282 | protected int computeVerticalScrollOffset() { |
| 11283 | return mScrollY; |
| 11284 | } |
| 11285 | |
| 11286 | /** |
| 11287 | * <p>Compute the vertical extent of the horizontal scrollbar's thumb |
| 11288 | * within the vertical range. This value is used to compute the length |
| 11289 | * of the thumb within the scrollbar's track.</p> |
| 11290 | * |
| 11291 | * <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] | 11292 | * units used by {@link #computeVerticalScrollRange()} and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11293 | * {@link #computeVerticalScrollOffset()}.</p> |
| 11294 | * |
| 11295 | * <p>The default extent is the drawing height of this view.</p> |
| 11296 | * |
| 11297 | * @return the vertical extent of the scrollbar's thumb |
| 11298 | * |
| 11299 | * @see #computeVerticalScrollRange() |
| 11300 | * @see #computeVerticalScrollOffset() |
| 11301 | * @see android.widget.ScrollBarDrawable |
| 11302 | */ |
| 11303 | protected int computeVerticalScrollExtent() { |
| 11304 | return getHeight(); |
| 11305 | } |
| 11306 | |
| 11307 | /** |
Adam Powell | 6915944 | 2011-06-13 17:53:06 -0700 | [diff] [blame] | 11308 | * Check if this view can be scrolled horizontally in a certain direction. |
| 11309 | * |
| 11310 | * @param direction Negative to check scrolling left, positive to check scrolling right. |
| 11311 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 11312 | */ |
| 11313 | public boolean canScrollHorizontally(int direction) { |
| 11314 | final int offset = computeHorizontalScrollOffset(); |
| 11315 | final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent(); |
| 11316 | if (range == 0) return false; |
| 11317 | if (direction < 0) { |
| 11318 | return offset > 0; |
| 11319 | } else { |
| 11320 | return offset < range - 1; |
| 11321 | } |
| 11322 | } |
| 11323 | |
| 11324 | /** |
| 11325 | * Check if this view can be scrolled vertically in a certain direction. |
| 11326 | * |
| 11327 | * @param direction Negative to check scrolling up, positive to check scrolling down. |
| 11328 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 11329 | */ |
| 11330 | public boolean canScrollVertically(int direction) { |
| 11331 | final int offset = computeVerticalScrollOffset(); |
| 11332 | final int range = computeVerticalScrollRange() - computeVerticalScrollExtent(); |
| 11333 | if (range == 0) return false; |
| 11334 | if (direction < 0) { |
| 11335 | return offset > 0; |
| 11336 | } else { |
| 11337 | return offset < range - 1; |
| 11338 | } |
| 11339 | } |
| 11340 | |
| 11341 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11342 | * <p>Request the drawing of the horizontal and the vertical scrollbar. The |
| 11343 | * scrollbars are painted only if they have been awakened first.</p> |
| 11344 | * |
| 11345 | * @param canvas the canvas on which to draw the scrollbars |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11346 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11347 | * @see #awakenScrollBars(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11348 | */ |
Romain Guy | 1d5b3a6 | 2009-11-05 18:44:12 -0800 | [diff] [blame] | 11349 | protected final void onDrawScrollBars(Canvas canvas) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11350 | // scrollbars are drawn only when the animation is running |
| 11351 | final ScrollabilityCache cache = mScrollCache; |
| 11352 | if (cache != null) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11353 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11354 | int state = cache.state; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11355 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11356 | if (state == ScrollabilityCache.OFF) { |
| 11357 | return; |
| 11358 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11359 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11360 | boolean invalidate = false; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11361 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11362 | if (state == ScrollabilityCache.FADING) { |
| 11363 | // We're fading -- get our fade interpolation |
| 11364 | if (cache.interpolatorValues == null) { |
| 11365 | cache.interpolatorValues = new float[1]; |
| 11366 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11367 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11368 | float[] values = cache.interpolatorValues; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11369 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11370 | // Stops the animation if we're done |
| 11371 | if (cache.scrollBarInterpolator.timeToValues(values) == |
| 11372 | Interpolator.Result.FREEZE_END) { |
| 11373 | cache.state = ScrollabilityCache.OFF; |
| 11374 | } else { |
| 11375 | cache.scrollBar.setAlpha(Math.round(values[0])); |
| 11376 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11377 | |
| 11378 | // This will make the scroll bars inval themselves after |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11379 | // drawing. We only want this when we're fading so that |
| 11380 | // we prevent excessive redraws |
| 11381 | invalidate = true; |
| 11382 | } else { |
| 11383 | // We're just on -- but we may have been fading before so |
| 11384 | // reset alpha |
| 11385 | cache.scrollBar.setAlpha(255); |
| 11386 | } |
| 11387 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11389 | final int viewFlags = mViewFlags; |
| 11390 | |
| 11391 | final boolean drawHorizontalScrollBar = |
| 11392 | (viewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 11393 | final boolean drawVerticalScrollBar = |
| 11394 | (viewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL |
| 11395 | && !isVerticalScrollBarHidden(); |
| 11396 | |
| 11397 | if (drawVerticalScrollBar || drawHorizontalScrollBar) { |
| 11398 | final int width = mRight - mLeft; |
| 11399 | final int height = mBottom - mTop; |
| 11400 | |
| 11401 | final ScrollBarDrawable scrollBar = cache.scrollBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11402 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11403 | final int scrollX = mScrollX; |
| 11404 | final int scrollY = mScrollY; |
| 11405 | final int inside = (viewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0; |
| 11406 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11407 | int left, top, right, bottom; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11408 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11409 | if (drawHorizontalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 11410 | int size = scrollBar.getSize(false); |
| 11411 | if (size <= 0) { |
| 11412 | size = cache.scrollBarSize; |
| 11413 | } |
| 11414 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11415 | scrollBar.setParameters(computeHorizontalScrollRange(), |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11416 | computeHorizontalScrollOffset(), |
| 11417 | computeHorizontalScrollExtent(), false); |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11418 | final int verticalScrollBarGap = drawVerticalScrollBar ? |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11419 | getVerticalScrollbarWidth() : 0; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11420 | top = scrollY + height - size - (mUserPaddingBottom & inside); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11421 | left = scrollX + (mPaddingLeft & inside); |
| 11422 | right = scrollX + width - (mUserPaddingRight & inside) - verticalScrollBarGap; |
| 11423 | bottom = top + size; |
| 11424 | onDrawHorizontalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 11425 | if (invalidate) { |
| 11426 | invalidate(left, top, right, bottom); |
| 11427 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11428 | } |
| 11429 | |
| 11430 | if (drawVerticalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 11431 | int size = scrollBar.getSize(true); |
| 11432 | if (size <= 0) { |
| 11433 | size = cache.scrollBarSize; |
| 11434 | } |
| 11435 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11436 | scrollBar.setParameters(computeVerticalScrollRange(), |
| 11437 | computeVerticalScrollOffset(), |
| 11438 | computeVerticalScrollExtent(), true); |
Fabrice Di Meglio | c91b6ca | 2012-06-22 14:51:15 -0700 | [diff] [blame] | 11439 | int verticalScrollbarPosition = mVerticalScrollbarPosition; |
| 11440 | if (verticalScrollbarPosition == SCROLLBAR_POSITION_DEFAULT) { |
| 11441 | verticalScrollbarPosition = isLayoutRtl() ? |
| 11442 | SCROLLBAR_POSITION_LEFT : SCROLLBAR_POSITION_RIGHT; |
| 11443 | } |
| 11444 | switch (verticalScrollbarPosition) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11445 | default: |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11446 | case SCROLLBAR_POSITION_RIGHT: |
| 11447 | left = scrollX + width - size - (mUserPaddingRight & inside); |
| 11448 | break; |
| 11449 | case SCROLLBAR_POSITION_LEFT: |
| 11450 | left = scrollX + (mUserPaddingLeft & inside); |
| 11451 | break; |
| 11452 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11453 | top = scrollY + (mPaddingTop & inside); |
| 11454 | right = left + size; |
| 11455 | bottom = scrollY + height - (mUserPaddingBottom & inside); |
| 11456 | onDrawVerticalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 11457 | if (invalidate) { |
| 11458 | invalidate(left, top, right, bottom); |
| 11459 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11460 | } |
| 11461 | } |
| 11462 | } |
| 11463 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11464 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11465 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11466 | * 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] | 11467 | * FastScroller is visible. |
| 11468 | * @return whether to temporarily hide the vertical scrollbar |
| 11469 | * @hide |
| 11470 | */ |
| 11471 | protected boolean isVerticalScrollBarHidden() { |
| 11472 | return false; |
| 11473 | } |
| 11474 | |
| 11475 | /** |
| 11476 | * <p>Draw the horizontal scrollbar if |
| 11477 | * {@link #isHorizontalScrollBarEnabled()} returns true.</p> |
| 11478 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11479 | * @param canvas the canvas on which to draw the scrollbar |
| 11480 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11481 | * |
| 11482 | * @see #isHorizontalScrollBarEnabled() |
| 11483 | * @see #computeHorizontalScrollRange() |
| 11484 | * @see #computeHorizontalScrollExtent() |
| 11485 | * @see #computeHorizontalScrollOffset() |
| 11486 | * @see android.widget.ScrollBarDrawable |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11487 | * @hide |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11488 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 11489 | protected void onDrawHorizontalScrollBar(Canvas canvas, Drawable scrollBar, |
| 11490 | int l, int t, int r, int b) { |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11491 | scrollBar.setBounds(l, t, r, b); |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11492 | scrollBar.draw(canvas); |
| 11493 | } |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11494 | |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11495 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11496 | * <p>Draw the vertical scrollbar if {@link #isVerticalScrollBarEnabled()} |
| 11497 | * returns true.</p> |
| 11498 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11499 | * @param canvas the canvas on which to draw the scrollbar |
| 11500 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11501 | * |
| 11502 | * @see #isVerticalScrollBarEnabled() |
| 11503 | * @see #computeVerticalScrollRange() |
| 11504 | * @see #computeVerticalScrollExtent() |
| 11505 | * @see #computeVerticalScrollOffset() |
| 11506 | * @see android.widget.ScrollBarDrawable |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11507 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11508 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 11509 | protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, |
| 11510 | int l, int t, int r, int b) { |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11511 | scrollBar.setBounds(l, t, r, b); |
| 11512 | scrollBar.draw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11513 | } |
| 11514 | |
| 11515 | /** |
| 11516 | * Implement this to do your drawing. |
| 11517 | * |
| 11518 | * @param canvas the canvas on which the background will be drawn |
| 11519 | */ |
| 11520 | protected void onDraw(Canvas canvas) { |
| 11521 | } |
| 11522 | |
| 11523 | /* |
| 11524 | * Caller is responsible for calling requestLayout if necessary. |
| 11525 | * (This allows addViewInLayout to not request a new layout.) |
| 11526 | */ |
| 11527 | void assignParent(ViewParent parent) { |
| 11528 | if (mParent == null) { |
| 11529 | mParent = parent; |
| 11530 | } else if (parent == null) { |
| 11531 | mParent = null; |
| 11532 | } else { |
| 11533 | throw new RuntimeException("view " + this + " being added, but" |
| 11534 | + " it already has a parent"); |
| 11535 | } |
| 11536 | } |
| 11537 | |
| 11538 | /** |
| 11539 | * This is called when the view is attached to a window. At this point it |
| 11540 | * has a Surface and will start drawing. Note that this function is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11541 | * guaranteed to be called before {@link #onDraw(android.graphics.Canvas)}, |
| 11542 | * however it may be called any time before the first onDraw -- including |
| 11543 | * before or after {@link #onMeasure(int, int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11544 | * |
| 11545 | * @see #onDetachedFromWindow() |
| 11546 | */ |
| 11547 | protected void onAttachedToWindow() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11548 | if ((mPrivateFlags & PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11549 | mParent.requestTransparentRegion(this); |
| 11550 | } |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11551 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11552 | if ((mPrivateFlags & PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH) != 0) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 11553 | initialAwakenScrollBars(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11554 | mPrivateFlags &= ~PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH; |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 11555 | } |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11556 | |
Chet Haase | a9b61ac | 2010-12-20 07:40:25 -0800 | [diff] [blame] | 11557 | jumpDrawablesToCurrentState(); |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11558 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 11559 | clearAccessibilityFocus(); |
Amith Yamasani | 4503c8d | 2011-06-17 12:36:14 -0700 | [diff] [blame] | 11560 | if (isFocused()) { |
| 11561 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 11562 | imm.focusIn(this); |
| 11563 | } |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11564 | |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame^] | 11565 | if (mDisplayList != null) { |
| 11566 | mDisplayList.setDirty(false); |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11567 | } |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 11568 | } |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 11569 | |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11570 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11571 | * Resolve all RTL related properties. |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 11572 | * |
| 11573 | * @hide |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11574 | */ |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 11575 | public void resolveRtlPropertiesIfNeeded() { |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11576 | if (!needRtlPropertiesResolution()) return; |
| 11577 | |
| 11578 | // Order is important here: LayoutDirection MUST be resolved first |
| 11579 | if (!isLayoutDirectionResolved()) { |
| 11580 | resolveLayoutDirection(); |
| 11581 | resolveLayoutParams(); |
| 11582 | } |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11583 | // ... then we can resolve the others properties depending on the resolved LayoutDirection. |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11584 | if (!isTextDirectionResolved()) { |
| 11585 | resolveTextDirection(); |
| 11586 | } |
| 11587 | if (!isTextAlignmentResolved()) { |
| 11588 | resolveTextAlignment(); |
| 11589 | } |
| 11590 | if (!isPaddingResolved()) { |
| 11591 | resolvePadding(); |
| 11592 | } |
| 11593 | if (!isDrawablesResolved()) { |
| 11594 | resolveDrawables(); |
| 11595 | } |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 11596 | onRtlPropertiesChanged(getLayoutDirection()); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11597 | } |
| 11598 | |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 11599 | /** |
| 11600 | * Reset resolution of all RTL related properties. |
| 11601 | * |
| 11602 | * @hide |
| 11603 | */ |
| 11604 | public void resetRtlProperties() { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11605 | resetResolvedLayoutDirection(); |
| 11606 | resetResolvedTextDirection(); |
| 11607 | resetResolvedTextAlignment(); |
| 11608 | resetResolvedPadding(); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11609 | resetResolvedDrawables(); |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11610 | } |
| 11611 | |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 11612 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 11613 | * @see #onScreenStateChanged(int) |
| 11614 | */ |
| 11615 | void dispatchScreenStateChanged(int screenState) { |
| 11616 | onScreenStateChanged(screenState); |
| 11617 | } |
| 11618 | |
| 11619 | /** |
| 11620 | * This method is called whenever the state of the screen this view is |
| 11621 | * attached to changes. A state change will usually occurs when the screen |
| 11622 | * turns on or off (whether it happens automatically or the user does it |
| 11623 | * manually.) |
| 11624 | * |
| 11625 | * @param screenState The new state of the screen. Can be either |
| 11626 | * {@link #SCREEN_STATE_ON} or {@link #SCREEN_STATE_OFF} |
| 11627 | */ |
| 11628 | public void onScreenStateChanged(int screenState) { |
| 11629 | } |
| 11630 | |
| 11631 | /** |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11632 | * Return true if the application tag in the AndroidManifest has set "supportRtl" to true |
| 11633 | */ |
| 11634 | private boolean hasRtlSupport() { |
| 11635 | return mContext.getApplicationInfo().hasRtlSupport(); |
| 11636 | } |
| 11637 | |
| 11638 | /** |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 11639 | * Return true if we are in RTL compatibility mode (either before Jelly Bean MR1 or |
| 11640 | * RTL not supported) |
| 11641 | */ |
| 11642 | private boolean isRtlCompatibilityMode() { |
| 11643 | final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion; |
| 11644 | return targetSdkVersion < JELLY_BEAN_MR1 || !hasRtlSupport(); |
| 11645 | } |
| 11646 | |
| 11647 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11648 | * @return true if RTL properties need resolution. |
| 11649 | */ |
| 11650 | private boolean needRtlPropertiesResolution() { |
| 11651 | return (mPrivateFlags2 & ALL_RTL_PROPERTIES_RESOLVED) != ALL_RTL_PROPERTIES_RESOLVED; |
| 11652 | } |
| 11653 | |
| 11654 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11655 | * Called when any RTL property (layout direction or text direction or text alignment) has |
| 11656 | * been changed. |
| 11657 | * |
| 11658 | * Subclasses need to override this method to take care of cached information that depends on the |
| 11659 | * resolved layout direction, or to inform child views that inherit their layout direction. |
| 11660 | * |
| 11661 | * The default implementation does nothing. |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 11662 | * |
| 11663 | * @param layoutDirection the direction of the layout |
| 11664 | * |
| 11665 | * @see #LAYOUT_DIRECTION_LTR |
| 11666 | * @see #LAYOUT_DIRECTION_RTL |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11667 | */ |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 11668 | public void onRtlPropertiesChanged(int layoutDirection) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11669 | } |
| 11670 | |
| 11671 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11672 | * Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing |
| 11673 | * that the parent directionality can and will be resolved before its children. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11674 | * |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11675 | * @return true if resolution has been done, false otherwise. |
| 11676 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11677 | * @hide |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 11678 | */ |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11679 | public boolean resolveLayoutDirection() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11680 | // Clear any previous layout direction resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11681 | mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11682 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11683 | if (hasRtlSupport()) { |
| 11684 | // Set resolved depending on layout direction |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 11685 | switch ((mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >> |
| 11686 | PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) { |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11687 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | b93911f | 2012-06-26 19:43:15 -0700 | [diff] [blame] | 11688 | // We cannot resolve yet. LTR is by default and let the resolution happen again |
| 11689 | // later to get the correct resolved value |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11690 | if (!canResolveLayoutDirection()) return false; |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 11691 | |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11692 | View parent = ((View) mParent); |
| 11693 | // Parent has not yet resolved, LTR is still the default |
| 11694 | if (!parent.isLayoutDirectionResolved()) return false; |
Fabrice Di Meglio | b93911f | 2012-06-26 19:43:15 -0700 | [diff] [blame] | 11695 | |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11696 | if (parent.getLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11697 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11698 | } |
| 11699 | break; |
| 11700 | case LAYOUT_DIRECTION_RTL: |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11701 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11702 | break; |
| 11703 | case LAYOUT_DIRECTION_LOCALE: |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11704 | if((LAYOUT_DIRECTION_RTL == |
| 11705 | TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()))) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11706 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 11707 | } |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11708 | break; |
| 11709 | default: |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 11710 | // Nothing to do, LTR by default |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11711 | } |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 11712 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11713 | |
| 11714 | // Set to resolved |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11715 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11716 | return true; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11717 | } |
| 11718 | |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 11719 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11720 | * Check if layout direction resolution can be done. |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11721 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11722 | * @return true if layout direction resolution can be done otherwise return false. |
| 11723 | * |
| 11724 | * @hide |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11725 | */ |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11726 | public boolean canResolveLayoutDirection() { |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11727 | switch (getRawLayoutDirection()) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11728 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11729 | return (mParent != null) && (mParent instanceof ViewGroup) && |
| 11730 | ((ViewGroup) mParent).canResolveLayoutDirection(); |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11731 | default: |
| 11732 | return true; |
| 11733 | } |
| 11734 | } |
| 11735 | |
| 11736 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11737 | * Reset the resolved layout direction. Layout direction will be resolved during a call to |
| 11738 | * {@link #onMeasure(int, int)}. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11739 | * |
| 11740 | * @hide |
| 11741 | */ |
| 11742 | public void resetResolvedLayoutDirection() { |
| 11743 | // Reset the current resolved bits |
| 11744 | mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11745 | } |
| 11746 | |
| 11747 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11748 | * @return true if the layout direction is inherited. |
| 11749 | * |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 11750 | * @hide |
| 11751 | */ |
| 11752 | public boolean isLayoutDirectionInherited() { |
| 11753 | return (getRawLayoutDirection() == LAYOUT_DIRECTION_INHERIT); |
| 11754 | } |
| 11755 | |
| 11756 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11757 | * @return true if layout direction has been resolved. |
| 11758 | */ |
| 11759 | private boolean isLayoutDirectionResolved() { |
| 11760 | return (mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_RESOLVED) == PFLAG2_LAYOUT_DIRECTION_RESOLVED; |
| 11761 | } |
| 11762 | |
| 11763 | /** |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11764 | * Return if padding has been resolved |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11765 | * |
| 11766 | * @hide |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11767 | */ |
| 11768 | boolean isPaddingResolved() { |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11769 | return (mPrivateFlags2 & PFLAG2_PADDING_RESOLVED) == PFLAG2_PADDING_RESOLVED; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11770 | } |
| 11771 | |
| 11772 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11773 | * Resolve padding depending on layout direction. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11774 | * |
| 11775 | * @hide |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 11776 | */ |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 11777 | public void resolvePadding() { |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 11778 | if (!isRtlCompatibilityMode()) { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11779 | // Post Jelly Bean MR1 case: we need to take the resolved layout direction into account. |
| 11780 | // If start / end padding are defined, they will be resolved (hence overriding) to |
| 11781 | // left / right or right / left depending on the resolved layout direction. |
| 11782 | // If start / end padding are not defined, use the left / right ones. |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 11783 | int resolvedLayoutDirection = getLayoutDirection(); |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 11784 | // Set user padding to initial values ... |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 11785 | mUserPaddingLeft = mUserPaddingLeftInitial; |
| 11786 | mUserPaddingRight = mUserPaddingRightInitial; |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 11787 | // ... then resolve it. |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11788 | switch (resolvedLayoutDirection) { |
| 11789 | case LAYOUT_DIRECTION_RTL: |
| 11790 | if (mUserPaddingStart != UNDEFINED_PADDING) { |
| 11791 | mUserPaddingRight = mUserPaddingStart; |
| 11792 | } |
| 11793 | if (mUserPaddingEnd != UNDEFINED_PADDING) { |
| 11794 | mUserPaddingLeft = mUserPaddingEnd; |
| 11795 | } |
| 11796 | break; |
| 11797 | case LAYOUT_DIRECTION_LTR: |
| 11798 | default: |
| 11799 | if (mUserPaddingStart != UNDEFINED_PADDING) { |
| 11800 | mUserPaddingLeft = mUserPaddingStart; |
| 11801 | } |
| 11802 | if (mUserPaddingEnd != UNDEFINED_PADDING) { |
| 11803 | mUserPaddingRight = mUserPaddingEnd; |
| 11804 | } |
| 11805 | } |
| 11806 | |
| 11807 | mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom; |
| 11808 | |
| 11809 | internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, |
| 11810 | mUserPaddingBottom); |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 11811 | onRtlPropertiesChanged(resolvedLayoutDirection); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11812 | } |
| 11813 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11814 | mPrivateFlags2 |= PFLAG2_PADDING_RESOLVED; |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 11815 | } |
| 11816 | |
| 11817 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11818 | * Reset the resolved layout direction. |
| 11819 | * |
| 11820 | * @hide |
| 11821 | */ |
| 11822 | public void resetResolvedPadding() { |
| 11823 | mPrivateFlags2 &= ~PFLAG2_PADDING_RESOLVED; |
| 11824 | } |
| 11825 | |
| 11826 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11827 | * This is called when the view is detached from a window. At this point it |
| 11828 | * no longer has a surface for drawing. |
| 11829 | * |
| 11830 | * @see #onAttachedToWindow() |
| 11831 | */ |
| 11832 | protected void onDetachedFromWindow() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11833 | mPrivateFlags &= ~PFLAG_CANCEL_NEXT_UP_EVENT; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11834 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 11835 | removeUnsetPressCallback(); |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 11836 | removeLongPressCallback(); |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 11837 | removePerformClickCallback(); |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 11838 | removeSendViewScrolledAccessibilityEventCallback(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11839 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11840 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11841 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11842 | destroyLayer(false); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 11843 | |
| 11844 | if (mAttachInfo != null) { |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11845 | if (mDisplayList != null) { |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame^] | 11846 | mDisplayList.setDirty(true); |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11847 | mAttachInfo.mViewRootImpl.enqueueDisplayList(mDisplayList); |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11848 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 11849 | mAttachInfo.mViewRootImpl.cancelInvalidate(this); |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11850 | } else { |
Romain Guy | 38c2ece | 2012-05-24 14:20:56 -0700 | [diff] [blame] | 11851 | // Should never happen |
| 11852 | clearDisplayList(); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 11853 | } |
| 11854 | |
Patrick Dubroy | ec84c3a | 2011-01-13 17:55:37 -0800 | [diff] [blame] | 11855 | mCurrentAnimation = null; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 11856 | |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11857 | resetRtlProperties(); |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 11858 | onRtlPropertiesChanged(LAYOUT_DIRECTION_DEFAULT); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 11859 | resetAccessibilityStateChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11860 | } |
| 11861 | |
| 11862 | /** |
| 11863 | * @return The number of times this view has been attached to a window |
| 11864 | */ |
| 11865 | protected int getWindowAttachCount() { |
| 11866 | return mWindowAttachCount; |
| 11867 | } |
| 11868 | |
| 11869 | /** |
| 11870 | * Retrieve a unique token identifying the window this view is attached to. |
| 11871 | * @return Return the window's token for use in |
| 11872 | * {@link WindowManager.LayoutParams#token WindowManager.LayoutParams.token}. |
| 11873 | */ |
| 11874 | public IBinder getWindowToken() { |
| 11875 | return mAttachInfo != null ? mAttachInfo.mWindowToken : null; |
| 11876 | } |
| 11877 | |
| 11878 | /** |
| 11879 | * Retrieve a unique token identifying the top-level "real" window of |
| 11880 | * the window that this view is attached to. That is, this is like |
| 11881 | * {@link #getWindowToken}, except if the window this view in is a panel |
| 11882 | * window (attached to another containing window), then the token of |
| 11883 | * the containing window is returned instead. |
| 11884 | * |
| 11885 | * @return Returns the associated window token, either |
| 11886 | * {@link #getWindowToken()} or the containing window's token. |
| 11887 | */ |
| 11888 | public IBinder getApplicationWindowToken() { |
| 11889 | AttachInfo ai = mAttachInfo; |
| 11890 | if (ai != null) { |
| 11891 | IBinder appWindowToken = ai.mPanelParentWindowToken; |
| 11892 | if (appWindowToken == null) { |
| 11893 | appWindowToken = ai.mWindowToken; |
| 11894 | } |
| 11895 | return appWindowToken; |
| 11896 | } |
| 11897 | return null; |
| 11898 | } |
| 11899 | |
| 11900 | /** |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 11901 | * Gets the logical display to which the view's window has been attached. |
| 11902 | * |
| 11903 | * @return The logical display, or null if the view is not currently attached to a window. |
| 11904 | */ |
| 11905 | public Display getDisplay() { |
| 11906 | return mAttachInfo != null ? mAttachInfo.mDisplay : null; |
| 11907 | } |
| 11908 | |
| 11909 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11910 | * Retrieve private session object this view hierarchy is using to |
| 11911 | * communicate with the window manager. |
| 11912 | * @return the session object to communicate with the window manager |
| 11913 | */ |
| 11914 | /*package*/ IWindowSession getWindowSession() { |
| 11915 | return mAttachInfo != null ? mAttachInfo.mSession : null; |
| 11916 | } |
| 11917 | |
| 11918 | /** |
| 11919 | * @param info the {@link android.view.View.AttachInfo} to associated with |
| 11920 | * this view |
| 11921 | */ |
| 11922 | void dispatchAttachedToWindow(AttachInfo info, int visibility) { |
| 11923 | //System.out.println("Attached! " + this); |
| 11924 | mAttachInfo = info; |
| 11925 | mWindowAttachCount++; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 11926 | // We will need to evaluate the drawable state at least once. |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11927 | mPrivateFlags |= PFLAG_DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11928 | if (mFloatingTreeObserver != null) { |
| 11929 | info.mTreeObserver.merge(mFloatingTreeObserver); |
| 11930 | mFloatingTreeObserver = null; |
| 11931 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11932 | if ((mPrivateFlags&PFLAG_SCROLL_CONTAINER) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11933 | mAttachInfo.mScrollContainers.add(this); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11934 | mPrivateFlags |= PFLAG_SCROLL_CONTAINER_ADDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11935 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 11936 | performCollectViewAttributes(mAttachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11937 | onAttachedToWindow(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11938 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11939 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11940 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11941 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11942 | if (listeners != null && listeners.size() > 0) { |
| 11943 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 11944 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 11945 | // could mutate the list by calling the various add/remove methods. This prevents |
| 11946 | // the array from being modified while we iterate it. |
| 11947 | for (OnAttachStateChangeListener listener : listeners) { |
| 11948 | listener.onViewAttachedToWindow(this); |
| 11949 | } |
| 11950 | } |
| 11951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11952 | int vis = info.mWindowVisibility; |
| 11953 | if (vis != GONE) { |
| 11954 | onWindowVisibilityChanged(vis); |
| 11955 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11956 | if ((mPrivateFlags&PFLAG_DRAWABLE_STATE_DIRTY) != 0) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 11957 | // If nobody has evaluated the drawable state yet, then do it now. |
| 11958 | refreshDrawableState(); |
| 11959 | } |
Craig Mautner | 7eac0f5 | 2012-09-13 13:14:14 -0700 | [diff] [blame] | 11960 | needGlobalAttributesUpdate(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11961 | } |
| 11962 | |
| 11963 | void dispatchDetachedFromWindow() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11964 | AttachInfo info = mAttachInfo; |
| 11965 | if (info != null) { |
| 11966 | int vis = info.mWindowVisibility; |
| 11967 | if (vis != GONE) { |
| 11968 | onWindowVisibilityChanged(GONE); |
| 11969 | } |
| 11970 | } |
| 11971 | |
| 11972 | onDetachedFromWindow(); |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 11973 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11974 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11975 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11976 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11977 | if (listeners != null && listeners.size() > 0) { |
| 11978 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 11979 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 11980 | // could mutate the list by calling the various add/remove methods. This prevents |
| 11981 | // the array from being modified while we iterate it. |
| 11982 | for (OnAttachStateChangeListener listener : listeners) { |
| 11983 | listener.onViewDetachedFromWindow(this); |
| 11984 | } |
| 11985 | } |
| 11986 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11987 | if ((mPrivateFlags & PFLAG_SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11988 | mAttachInfo.mScrollContainers.remove(this); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11989 | mPrivateFlags &= ~PFLAG_SCROLL_CONTAINER_ADDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11990 | } |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 11991 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11992 | mAttachInfo = null; |
| 11993 | } |
| 11994 | |
| 11995 | /** |
| 11996 | * Store this view hierarchy's frozen state into the given container. |
| 11997 | * |
| 11998 | * @param container The SparseArray in which to save the view's state. |
| 11999 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12000 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 12001 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 12002 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12003 | */ |
| 12004 | public void saveHierarchyState(SparseArray<Parcelable> container) { |
| 12005 | dispatchSaveInstanceState(container); |
| 12006 | } |
| 12007 | |
| 12008 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12009 | * Called by {@link #saveHierarchyState(android.util.SparseArray)} to store the state for |
| 12010 | * this view and its children. May be overridden to modify how freezing happens to a |
| 12011 | * 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] | 12012 | * |
| 12013 | * @param container The SparseArray in which to save the view's state. |
| 12014 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12015 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 12016 | * @see #saveHierarchyState(android.util.SparseArray) |
| 12017 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12018 | */ |
| 12019 | protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 12020 | if (mID != NO_ID && (mViewFlags & SAVE_DISABLED_MASK) == 0) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12021 | mPrivateFlags &= ~PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12022 | Parcelable state = onSaveInstanceState(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12023 | if ((mPrivateFlags & PFLAG_SAVE_STATE_CALLED) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12024 | throw new IllegalStateException( |
| 12025 | "Derived class did not call super.onSaveInstanceState()"); |
| 12026 | } |
| 12027 | if (state != null) { |
| 12028 | // Log.i("View", "Freezing #" + Integer.toHexString(mID) |
| 12029 | // + ": " + state); |
| 12030 | container.put(mID, state); |
| 12031 | } |
| 12032 | } |
| 12033 | } |
| 12034 | |
| 12035 | /** |
| 12036 | * Hook allowing a view to generate a representation of its internal state |
| 12037 | * that can later be used to create a new instance with that same state. |
| 12038 | * This state should only contain information that is not persistent or can |
| 12039 | * not be reconstructed later. For example, you will never store your |
| 12040 | * current position on screen because that will be computed again when a |
| 12041 | * new instance of the view is placed in its view hierarchy. |
| 12042 | * <p> |
| 12043 | * Some examples of things you may store here: the current cursor position |
| 12044 | * in a text view (but usually not the text itself since that is stored in a |
| 12045 | * content provider or other persistent storage), the currently selected |
| 12046 | * item in a list view. |
| 12047 | * |
| 12048 | * @return Returns a Parcelable object containing the view's current dynamic |
| 12049 | * state, or null if there is nothing interesting to save. The |
| 12050 | * default implementation returns null. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12051 | * @see #onRestoreInstanceState(android.os.Parcelable) |
| 12052 | * @see #saveHierarchyState(android.util.SparseArray) |
| 12053 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12054 | * @see #setSaveEnabled(boolean) |
| 12055 | */ |
| 12056 | protected Parcelable onSaveInstanceState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12057 | mPrivateFlags |= PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12058 | return BaseSavedState.EMPTY_STATE; |
| 12059 | } |
| 12060 | |
| 12061 | /** |
| 12062 | * Restore this view hierarchy's frozen state from the given container. |
| 12063 | * |
| 12064 | * @param container The SparseArray which holds previously frozen states. |
| 12065 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12066 | * @see #saveHierarchyState(android.util.SparseArray) |
| 12067 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 12068 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12069 | */ |
| 12070 | public void restoreHierarchyState(SparseArray<Parcelable> container) { |
| 12071 | dispatchRestoreInstanceState(container); |
| 12072 | } |
| 12073 | |
| 12074 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12075 | * Called by {@link #restoreHierarchyState(android.util.SparseArray)} to retrieve the |
| 12076 | * state for this view and its children. May be overridden to modify how restoring |
| 12077 | * happens to a view's children; for example, some views may want to not store state |
| 12078 | * for their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12079 | * |
| 12080 | * @param container The SparseArray which holds previously saved state. |
| 12081 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12082 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 12083 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 12084 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12085 | */ |
| 12086 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 12087 | if (mID != NO_ID) { |
| 12088 | Parcelable state = container.get(mID); |
| 12089 | if (state != null) { |
| 12090 | // Log.i("View", "Restoreing #" + Integer.toHexString(mID) |
| 12091 | // + ": " + state); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12092 | mPrivateFlags &= ~PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12093 | onRestoreInstanceState(state); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12094 | if ((mPrivateFlags & PFLAG_SAVE_STATE_CALLED) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12095 | throw new IllegalStateException( |
| 12096 | "Derived class did not call super.onRestoreInstanceState()"); |
| 12097 | } |
| 12098 | } |
| 12099 | } |
| 12100 | } |
| 12101 | |
| 12102 | /** |
| 12103 | * Hook allowing a view to re-apply a representation of its internal state that had previously |
| 12104 | * been generated by {@link #onSaveInstanceState}. This function will never be called with a |
| 12105 | * null state. |
| 12106 | * |
| 12107 | * @param state The frozen state that had previously been returned by |
| 12108 | * {@link #onSaveInstanceState}. |
| 12109 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12110 | * @see #onSaveInstanceState() |
| 12111 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 12112 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12113 | */ |
| 12114 | protected void onRestoreInstanceState(Parcelable state) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12115 | mPrivateFlags |= PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12116 | if (state != BaseSavedState.EMPTY_STATE && state != null) { |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 12117 | throw new IllegalArgumentException("Wrong state class, expecting View State but " |
| 12118 | + "received " + state.getClass().toString() + " instead. This usually happens " |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12119 | + "when two views of different type have the same id in the same hierarchy. " |
| 12120 | + "This view's id is " + ViewDebug.resolveId(mContext, getId()) + ". Make sure " |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 12121 | + "other views do not use the same id."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12122 | } |
| 12123 | } |
| 12124 | |
| 12125 | /** |
| 12126 | * <p>Return the time at which the drawing of the view hierarchy started.</p> |
| 12127 | * |
| 12128 | * @return the drawing start time in milliseconds |
| 12129 | */ |
| 12130 | public long getDrawingTime() { |
| 12131 | return mAttachInfo != null ? mAttachInfo.mDrawingTime : 0; |
| 12132 | } |
| 12133 | |
| 12134 | /** |
| 12135 | * <p>Enables or disables the duplication of the parent's state into this view. When |
| 12136 | * duplication is enabled, this view gets its drawable state from its parent rather |
| 12137 | * than from its own internal properties.</p> |
| 12138 | * |
| 12139 | * <p>Note: in the current implementation, setting this property to true after the |
| 12140 | * view was added to a ViewGroup might have no effect at all. This property should |
| 12141 | * always be used from XML or set to true before adding this view to a ViewGroup.</p> |
| 12142 | * |
| 12143 | * <p>Note: if this view's parent addStateFromChildren property is enabled and this |
| 12144 | * property is enabled, an exception will be thrown.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12145 | * |
Gilles Debunne | fb81703 | 2011-01-13 13:52:49 -0800 | [diff] [blame] | 12146 | * <p>Note: if the child view uses and updates additionnal states which are unknown to the |
| 12147 | * 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] | 12148 | * |
| 12149 | * @param enabled True to enable duplication of the parent's drawable state, false |
| 12150 | * to disable it. |
| 12151 | * |
| 12152 | * @see #getDrawableState() |
| 12153 | * @see #isDuplicateParentStateEnabled() |
| 12154 | */ |
| 12155 | public void setDuplicateParentStateEnabled(boolean enabled) { |
| 12156 | setFlags(enabled ? DUPLICATE_PARENT_STATE : 0, DUPLICATE_PARENT_STATE); |
| 12157 | } |
| 12158 | |
| 12159 | /** |
| 12160 | * <p>Indicates whether this duplicates its drawable state from its parent.</p> |
| 12161 | * |
| 12162 | * @return True if this view's drawable state is duplicated from the parent, |
| 12163 | * false otherwise |
| 12164 | * |
| 12165 | * @see #getDrawableState() |
| 12166 | * @see #setDuplicateParentStateEnabled(boolean) |
| 12167 | */ |
| 12168 | public boolean isDuplicateParentStateEnabled() { |
| 12169 | return (mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE; |
| 12170 | } |
| 12171 | |
| 12172 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12173 | * <p>Specifies the type of layer backing this view. The layer can be |
| 12174 | * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or |
| 12175 | * {@link #LAYER_TYPE_HARDWARE hardware}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12176 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12177 | * <p>A layer is associated with an optional {@link android.graphics.Paint} |
| 12178 | * instance that controls how the layer is composed on screen. The following |
| 12179 | * properties of the paint are taken into account when composing the layer:</p> |
| 12180 | * <ul> |
| 12181 | * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> |
| 12182 | * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> |
| 12183 | * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> |
| 12184 | * </ul> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12185 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12186 | * <p>If this view has an alpha value set to < 1.0 by calling |
| 12187 | * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by |
| 12188 | * this view's alpha value. Calling {@link #setAlpha(float)} is therefore |
| 12189 | * equivalent to setting a hardware layer on this view and providing a paint with |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 12190 | * the desired alpha value.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12191 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12192 | * <p>Refer to the documentation of {@link #LAYER_TYPE_NONE disabled}, |
| 12193 | * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware} |
| 12194 | * for more information on when and how to use layers.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12195 | * |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 12196 | * @param layerType The type of layer to use with this view, must be one of |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12197 | * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 12198 | * {@link #LAYER_TYPE_HARDWARE} |
| 12199 | * @param paint The paint used to compose the layer. This argument is optional |
| 12200 | * and can be null. It is ignored when the layer type is |
| 12201 | * {@link #LAYER_TYPE_NONE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12202 | * |
| 12203 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12204 | * @see #LAYER_TYPE_NONE |
| 12205 | * @see #LAYER_TYPE_SOFTWARE |
| 12206 | * @see #LAYER_TYPE_HARDWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12207 | * @see #setAlpha(float) |
| 12208 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12209 | * @attr ref android.R.styleable#View_layerType |
| 12210 | */ |
| 12211 | public void setLayerType(int layerType, Paint paint) { |
| 12212 | if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12213 | 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] | 12214 | + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE"); |
| 12215 | } |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12216 | |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 12217 | if (layerType == mLayerType) { |
| 12218 | if (layerType != LAYER_TYPE_NONE && paint != mLayerPaint) { |
| 12219 | mLayerPaint = paint == null ? new Paint() : paint; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 12220 | invalidateParentCaches(); |
| 12221 | invalidate(true); |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 12222 | } |
| 12223 | return; |
| 12224 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12225 | |
| 12226 | // Destroy any previous software drawing cache if needed |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12227 | switch (mLayerType) { |
Chet Haase | 6f33e81 | 2011-05-17 12:42:19 -0700 | [diff] [blame] | 12228 | case LAYER_TYPE_HARDWARE: |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12229 | destroyLayer(false); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12230 | // fall through - non-accelerated views may use software layer mechanism instead |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12231 | case LAYER_TYPE_SOFTWARE: |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12232 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12233 | break; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12234 | default: |
| 12235 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12236 | } |
| 12237 | |
| 12238 | mLayerType = layerType; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 12239 | final boolean layerDisabled = mLayerType == LAYER_TYPE_NONE; |
| 12240 | mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint); |
| 12241 | mLocalDirtyRect = layerDisabled ? null : new Rect(); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12242 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 12243 | invalidateParentCaches(); |
| 12244 | invalidate(true); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12245 | } |
| 12246 | |
| 12247 | /** |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 12248 | * Updates the {@link Paint} object used with the current layer (used only if the current |
| 12249 | * layer type is not set to {@link #LAYER_TYPE_NONE}). Changed properties of the Paint |
| 12250 | * provided to {@link #setLayerType(int, android.graphics.Paint)} will be used the next time |
| 12251 | * the View is redrawn, but {@link #setLayerPaint(android.graphics.Paint)} must be called to |
| 12252 | * ensure that the view gets redrawn immediately. |
| 12253 | * |
| 12254 | * <p>A layer is associated with an optional {@link android.graphics.Paint} |
| 12255 | * instance that controls how the layer is composed on screen. The following |
| 12256 | * properties of the paint are taken into account when composing the layer:</p> |
| 12257 | * <ul> |
| 12258 | * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> |
| 12259 | * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> |
| 12260 | * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> |
| 12261 | * </ul> |
| 12262 | * |
| 12263 | * <p>If this view has an alpha value set to < 1.0 by calling |
| 12264 | * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by |
| 12265 | * this view's alpha value. Calling {@link #setAlpha(float)} is therefore |
| 12266 | * equivalent to setting a hardware layer on this view and providing a paint with |
| 12267 | * the desired alpha value.</p> |
| 12268 | * |
| 12269 | * @param paint The paint used to compose the layer. This argument is optional |
| 12270 | * and can be null. It is ignored when the layer type is |
| 12271 | * {@link #LAYER_TYPE_NONE} |
| 12272 | * |
| 12273 | * @see #setLayerType(int, android.graphics.Paint) |
| 12274 | */ |
| 12275 | public void setLayerPaint(Paint paint) { |
| 12276 | int layerType = getLayerType(); |
| 12277 | if (layerType != LAYER_TYPE_NONE) { |
| 12278 | mLayerPaint = paint == null ? new Paint() : paint; |
| 12279 | if (layerType == LAYER_TYPE_HARDWARE) { |
| 12280 | HardwareLayer layer = getHardwareLayer(); |
| 12281 | if (layer != null) { |
| 12282 | layer.setLayerPaint(paint); |
| 12283 | } |
| 12284 | invalidateViewProperty(false, false); |
| 12285 | } else { |
| 12286 | invalidate(); |
| 12287 | } |
| 12288 | } |
| 12289 | } |
| 12290 | |
| 12291 | /** |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 12292 | * Indicates whether this view has a static layer. A view with layer type |
| 12293 | * {@link #LAYER_TYPE_NONE} is a static layer. Other types of layers are |
| 12294 | * dynamic. |
| 12295 | */ |
| 12296 | boolean hasStaticLayer() { |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 12297 | return true; |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 12298 | } |
| 12299 | |
| 12300 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12301 | * Indicates what type of layer is currently associated with this view. By default |
| 12302 | * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}. |
| 12303 | * Refer to the documentation of {@link #setLayerType(int, android.graphics.Paint)} |
| 12304 | * for more information on the different types of layers. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12305 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12306 | * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 12307 | * {@link #LAYER_TYPE_HARDWARE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12308 | * |
| 12309 | * @see #setLayerType(int, android.graphics.Paint) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12310 | * @see #buildLayer() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12311 | * @see #LAYER_TYPE_NONE |
| 12312 | * @see #LAYER_TYPE_SOFTWARE |
| 12313 | * @see #LAYER_TYPE_HARDWARE |
| 12314 | */ |
| 12315 | public int getLayerType() { |
| 12316 | return mLayerType; |
| 12317 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12318 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12319 | /** |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12320 | * Forces this view's layer to be created and this view to be rendered |
| 12321 | * into its layer. If this view's layer type is set to {@link #LAYER_TYPE_NONE}, |
| 12322 | * invoking this method will have no effect. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12323 | * |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12324 | * This method can for instance be used to render a view into its layer before |
| 12325 | * starting an animation. If this view is complex, rendering into the layer |
| 12326 | * before starting the animation will avoid skipping frames. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12327 | * |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12328 | * @throws IllegalStateException If this view is not attached to a window |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12329 | * |
| 12330 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12331 | */ |
| 12332 | public void buildLayer() { |
| 12333 | if (mLayerType == LAYER_TYPE_NONE) return; |
| 12334 | |
| 12335 | if (mAttachInfo == null) { |
| 12336 | throw new IllegalStateException("This view must be attached to a window first"); |
| 12337 | } |
| 12338 | |
| 12339 | switch (mLayerType) { |
| 12340 | case LAYER_TYPE_HARDWARE: |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 12341 | if (mAttachInfo.mHardwareRenderer != null && |
| 12342 | mAttachInfo.mHardwareRenderer.isEnabled() && |
| 12343 | mAttachInfo.mHardwareRenderer.validate()) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12344 | getHardwareLayer(); |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 12345 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12346 | break; |
| 12347 | case LAYER_TYPE_SOFTWARE: |
| 12348 | buildDrawingCache(true); |
| 12349 | break; |
| 12350 | } |
| 12351 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12352 | |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12353 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12354 | * <p>Returns a hardware layer that can be used to draw this view again |
| 12355 | * without executing its draw method.</p> |
| 12356 | * |
| 12357 | * @return A HardwareLayer ready to render, or null if an error occurred. |
| 12358 | */ |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12359 | HardwareLayer getHardwareLayer() { |
Romain Guy | ea83503 | 2011-07-28 19:24:37 -0700 | [diff] [blame] | 12360 | if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null || |
| 12361 | !mAttachInfo.mHardwareRenderer.isEnabled()) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12362 | return null; |
| 12363 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12364 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12365 | if (!mAttachInfo.mHardwareRenderer.validate()) return null; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12366 | |
| 12367 | final int width = mRight - mLeft; |
| 12368 | final int height = mBottom - mTop; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12369 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12370 | if (width == 0 || height == 0) { |
| 12371 | return null; |
| 12372 | } |
| 12373 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12374 | if ((mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == 0 || mHardwareLayer == null) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12375 | if (mHardwareLayer == null) { |
| 12376 | mHardwareLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer( |
| 12377 | width, height, isOpaque()); |
Michael Jurka | 952e02b | 2012-03-13 18:34:35 -0700 | [diff] [blame] | 12378 | mLocalDirtyRect.set(0, 0, width, height); |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 12379 | } else { |
| 12380 | if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) { |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 12381 | if (mHardwareLayer.resize(width, height)) { |
| 12382 | mLocalDirtyRect.set(0, 0, width, height); |
| 12383 | } |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 12384 | } |
| 12385 | |
| 12386 | // This should not be necessary but applications that change |
| 12387 | // the parameters of their background drawable without calling |
| 12388 | // this.setBackground(Drawable) can leave the view in a bad state |
| 12389 | // (for instance isOpaque() returns true, but the background is |
| 12390 | // not opaque.) |
| 12391 | computeOpaqueFlags(); |
| 12392 | |
| 12393 | final boolean opaque = isOpaque(); |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 12394 | if (mHardwareLayer.isValid() && mHardwareLayer.isOpaque() != opaque) { |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 12395 | mHardwareLayer.setOpaque(opaque); |
| 12396 | mLocalDirtyRect.set(0, 0, width, height); |
| 12397 | } |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12398 | } |
| 12399 | |
Romain Guy | 5cd5c3f | 2011-10-17 17:10:02 -0700 | [diff] [blame] | 12400 | // The layer is not valid if the underlying GPU resources cannot be allocated |
| 12401 | if (!mHardwareLayer.isValid()) { |
| 12402 | return null; |
| 12403 | } |
| 12404 | |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 12405 | mHardwareLayer.setLayerPaint(mLayerPaint); |
| 12406 | mHardwareLayer.redrawLater(getHardwareLayerDisplayList(mHardwareLayer), mLocalDirtyRect); |
| 12407 | ViewRootImpl viewRoot = getViewRootImpl(); |
| 12408 | if (viewRoot != null) viewRoot.pushHardwareLayerUpdate(mHardwareLayer); |
| 12409 | |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12410 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12411 | } |
| 12412 | |
| 12413 | return mHardwareLayer; |
| 12414 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12415 | |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 12416 | /** |
| 12417 | * Destroys this View's hardware layer if possible. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12418 | * |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 12419 | * @return True if the layer was destroyed, false otherwise. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12420 | * |
| 12421 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 12422 | * @see #LAYER_TYPE_HARDWARE |
| 12423 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12424 | boolean destroyLayer(boolean valid) { |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12425 | if (mHardwareLayer != null) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12426 | AttachInfo info = mAttachInfo; |
| 12427 | if (info != null && info.mHardwareRenderer != null && |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12428 | info.mHardwareRenderer.isEnabled() && |
| 12429 | (valid || info.mHardwareRenderer.validate())) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12430 | mHardwareLayer.destroy(); |
| 12431 | mHardwareLayer = null; |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12432 | |
Chet Haase | 6a2d17f | 2012-09-30 12:14:13 -0700 | [diff] [blame] | 12433 | if (mDisplayList != null) { |
| 12434 | mDisplayList.reset(); |
| 12435 | } |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12436 | invalidate(true); |
| 12437 | invalidateParentCaches(); |
| 12438 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 12439 | return true; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12440 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 12441 | return false; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12442 | } |
| 12443 | |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12444 | /** |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12445 | * Destroys all hardware rendering resources. This method is invoked |
| 12446 | * when the system needs to reclaim resources. Upon execution of this |
| 12447 | * method, you should free any OpenGL resources created by the view. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12448 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12449 | * Note: you <strong>must</strong> call |
| 12450 | * <code>super.destroyHardwareResources()</code> when overriding |
| 12451 | * this method. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12452 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12453 | * @hide |
| 12454 | */ |
| 12455 | protected void destroyHardwareResources() { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12456 | destroyLayer(true); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12457 | } |
| 12458 | |
| 12459 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12460 | * <p>Enables or disables the drawing cache. When the drawing cache is enabled, the next call |
| 12461 | * to {@link #getDrawingCache()} or {@link #buildDrawingCache()} will draw the view in a |
| 12462 | * bitmap. Calling {@link #draw(android.graphics.Canvas)} will not draw from the cache when |
| 12463 | * the cache is enabled. To benefit from the cache, you must request the drawing cache by |
| 12464 | * calling {@link #getDrawingCache()} and draw it on screen if the returned bitmap is not |
| 12465 | * null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12466 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12467 | * <p>Enabling the drawing cache is similar to |
| 12468 | * {@link #setLayerType(int, android.graphics.Paint) setting a layer} when hardware |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12469 | * acceleration is turned off. When hardware acceleration is turned on, enabling the |
| 12470 | * drawing cache has no effect on rendering because the system uses a different mechanism |
| 12471 | * for acceleration which ignores the flag. If you want to use a Bitmap for the view, even |
| 12472 | * when hardware acceleration is enabled, see {@link #setLayerType(int, android.graphics.Paint)} |
| 12473 | * for information on how to enable software and hardware layers.</p> |
| 12474 | * |
| 12475 | * <p>This API can be used to manually generate |
| 12476 | * a bitmap copy of this view, by setting the flag to <code>true</code> and calling |
| 12477 | * {@link #getDrawingCache()}.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12478 | * |
| 12479 | * @param enabled true to enable the drawing cache, false otherwise |
| 12480 | * |
| 12481 | * @see #isDrawingCacheEnabled() |
| 12482 | * @see #getDrawingCache() |
| 12483 | * @see #buildDrawingCache() |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12484 | * @see #setLayerType(int, android.graphics.Paint) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12485 | */ |
| 12486 | public void setDrawingCacheEnabled(boolean enabled) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12487 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12488 | setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED); |
| 12489 | } |
| 12490 | |
| 12491 | /** |
| 12492 | * <p>Indicates whether the drawing cache is enabled for this view.</p> |
| 12493 | * |
| 12494 | * @return true if the drawing cache is enabled |
| 12495 | * |
| 12496 | * @see #setDrawingCacheEnabled(boolean) |
| 12497 | * @see #getDrawingCache() |
| 12498 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 12499 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12500 | public boolean isDrawingCacheEnabled() { |
| 12501 | return (mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED; |
| 12502 | } |
| 12503 | |
| 12504 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12505 | * Debugging utility which recursively outputs the dirty state of a view and its |
| 12506 | * descendants. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12507 | * |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12508 | * @hide |
| 12509 | */ |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12510 | @SuppressWarnings({"UnusedDeclaration"}) |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12511 | public void outputDirtyFlags(String indent, boolean clear, int clearMask) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12512 | Log.d("View", indent + this + " DIRTY(" + (mPrivateFlags & View.PFLAG_DIRTY_MASK) + |
| 12513 | ") DRAWN(" + (mPrivateFlags & PFLAG_DRAWN) + ")" + " CACHE_VALID(" + |
| 12514 | (mPrivateFlags & View.PFLAG_DRAWING_CACHE_VALID) + |
| 12515 | ") INVALIDATED(" + (mPrivateFlags & PFLAG_INVALIDATED) + ")"); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12516 | if (clear) { |
| 12517 | mPrivateFlags &= clearMask; |
| 12518 | } |
| 12519 | if (this instanceof ViewGroup) { |
| 12520 | ViewGroup parent = (ViewGroup) this; |
| 12521 | final int count = parent.getChildCount(); |
| 12522 | for (int i = 0; i < count; i++) { |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 12523 | final View child = parent.getChildAt(i); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12524 | child.outputDirtyFlags(indent + " ", clear, clearMask); |
| 12525 | } |
| 12526 | } |
| 12527 | } |
| 12528 | |
| 12529 | /** |
| 12530 | * This method is used by ViewGroup to cause its children to restore or recreate their |
| 12531 | * display lists. It is called by getDisplayList() when the parent ViewGroup does not need |
| 12532 | * to recreate its own display list, which would happen if it went through the normal |
| 12533 | * draw/dispatchDraw mechanisms. |
| 12534 | * |
| 12535 | * @hide |
| 12536 | */ |
| 12537 | protected void dispatchGetDisplayList() {} |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 12538 | |
| 12539 | /** |
| 12540 | * A view that is not attached or hardware accelerated cannot create a display list. |
| 12541 | * This method checks these conditions and returns the appropriate result. |
| 12542 | * |
| 12543 | * @return true if view has the ability to create a display list, false otherwise. |
| 12544 | * |
| 12545 | * @hide |
| 12546 | */ |
| 12547 | public boolean canHaveDisplayList() { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12548 | return !(mAttachInfo == null || mAttachInfo.mHardwareRenderer == null); |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 12549 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12550 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12551 | /** |
Gilles Debunne | b35ab7b | 2011-12-05 15:54:00 -0800 | [diff] [blame] | 12552 | * @return The HardwareRenderer associated with that view or null if hardware rendering |
| 12553 | * is not supported or this this has not been attached to a window. |
| 12554 | * |
| 12555 | * @hide |
| 12556 | */ |
| 12557 | public HardwareRenderer getHardwareRenderer() { |
| 12558 | if (mAttachInfo != null) { |
| 12559 | return mAttachInfo.mHardwareRenderer; |
| 12560 | } |
| 12561 | return null; |
| 12562 | } |
| 12563 | |
| 12564 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12565 | * Returns a DisplayList. If the incoming displayList is null, one will be created. |
| 12566 | * Otherwise, the same display list will be returned (after having been rendered into |
| 12567 | * along the way, depending on the invalidation state of the view). |
| 12568 | * |
| 12569 | * @param displayList The previous version of this displayList, could be null. |
| 12570 | * @param isLayer Whether the requester of the display list is a layer. If so, |
| 12571 | * the view will avoid creating a layer inside the resulting display list. |
| 12572 | * @return A new or reused DisplayList object. |
| 12573 | */ |
| 12574 | private DisplayList getDisplayList(DisplayList displayList, boolean isLayer) { |
| 12575 | if (!canHaveDisplayList()) { |
| 12576 | return null; |
| 12577 | } |
| 12578 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12579 | if (((mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == 0 || |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12580 | displayList == null || !displayList.isValid() || |
| 12581 | (!isLayer && mRecreateDisplayList))) { |
| 12582 | // Don't need to recreate the display list, just need to tell our |
| 12583 | // children to restore/recreate theirs |
| 12584 | if (displayList != null && displayList.isValid() && |
| 12585 | !isLayer && !mRecreateDisplayList) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12586 | mPrivateFlags |= PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID; |
| 12587 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12588 | dispatchGetDisplayList(); |
| 12589 | |
| 12590 | return displayList; |
| 12591 | } |
| 12592 | |
| 12593 | if (!isLayer) { |
| 12594 | // If we got here, we're recreating it. Mark it as such to ensure that |
| 12595 | // we copy in child display lists into ours in drawChild() |
| 12596 | mRecreateDisplayList = true; |
| 12597 | } |
| 12598 | if (displayList == null) { |
| 12599 | final String name = getClass().getSimpleName(); |
| 12600 | displayList = mAttachInfo.mHardwareRenderer.createDisplayList(name); |
| 12601 | // If we're creating a new display list, make sure our parent gets invalidated |
| 12602 | // since they will need to recreate their display list to account for this |
| 12603 | // new child display list. |
| 12604 | invalidateParentCaches(); |
| 12605 | } |
| 12606 | |
| 12607 | boolean caching = false; |
| 12608 | final HardwareCanvas canvas = displayList.start(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12609 | int width = mRight - mLeft; |
| 12610 | int height = mBottom - mTop; |
| 12611 | |
| 12612 | try { |
| 12613 | canvas.setViewport(width, height); |
| 12614 | // The dirty rect should always be null for a display list |
| 12615 | canvas.onPreDraw(null); |
Michael Jurka | ba64974 | 2012-06-28 19:12:58 -0700 | [diff] [blame] | 12616 | int layerType = getLayerType(); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 12617 | if (!isLayer && layerType != LAYER_TYPE_NONE) { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 12618 | if (layerType == LAYER_TYPE_HARDWARE) { |
| 12619 | final HardwareLayer layer = getHardwareLayer(); |
| 12620 | if (layer != null && layer.isValid()) { |
| 12621 | canvas.drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 12622 | } else { |
| 12623 | canvas.saveLayer(0, 0, mRight - mLeft, mBottom - mTop, mLayerPaint, |
| 12624 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | |
| 12625 | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 12626 | } |
| 12627 | caching = true; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12628 | } else { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 12629 | buildDrawingCache(true); |
| 12630 | Bitmap cache = getDrawingCache(true); |
| 12631 | if (cache != null) { |
| 12632 | canvas.drawBitmap(cache, 0, 0, mLayerPaint); |
| 12633 | caching = true; |
| 12634 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12635 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12636 | } else { |
| 12637 | |
| 12638 | computeScroll(); |
| 12639 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12640 | canvas.translate(-mScrollX, -mScrollY); |
| 12641 | if (!isLayer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12642 | mPrivateFlags |= PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID; |
| 12643 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12644 | } |
| 12645 | |
| 12646 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12647 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12648 | dispatchDraw(canvas); |
| 12649 | } else { |
| 12650 | draw(canvas); |
| 12651 | } |
| 12652 | } |
| 12653 | } finally { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12654 | canvas.onPostDraw(); |
| 12655 | |
| 12656 | displayList.end(); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 12657 | displayList.setCaching(caching); |
| 12658 | if (isLayer) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12659 | displayList.setLeftTopRightBottom(0, 0, width, height); |
| 12660 | } else { |
| 12661 | setDisplayListProperties(displayList); |
| 12662 | } |
| 12663 | } |
| 12664 | } else if (!isLayer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12665 | mPrivateFlags |= PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID; |
| 12666 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12667 | } |
| 12668 | |
| 12669 | return displayList; |
| 12670 | } |
| 12671 | |
| 12672 | /** |
| 12673 | * Get the DisplayList for the HardwareLayer |
| 12674 | * |
| 12675 | * @param layer The HardwareLayer whose DisplayList we want |
| 12676 | * @return A DisplayList fopr the specified HardwareLayer |
| 12677 | */ |
| 12678 | private DisplayList getHardwareLayerDisplayList(HardwareLayer layer) { |
| 12679 | DisplayList displayList = getDisplayList(layer.getDisplayList(), true); |
| 12680 | layer.setDisplayList(displayList); |
| 12681 | return displayList; |
| 12682 | } |
| 12683 | |
| 12684 | |
| 12685 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12686 | * <p>Returns a display list that can be used to draw this view again |
| 12687 | * without executing its draw method.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12688 | * |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12689 | * @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] | 12690 | * |
| 12691 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12692 | */ |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12693 | public DisplayList getDisplayList() { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12694 | mDisplayList = getDisplayList(mDisplayList, false); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12695 | return mDisplayList; |
| 12696 | } |
| 12697 | |
Romain Guy | 38c2ece | 2012-05-24 14:20:56 -0700 | [diff] [blame] | 12698 | private void clearDisplayList() { |
| 12699 | if (mDisplayList != null) { |
| 12700 | mDisplayList.invalidate(); |
| 12701 | mDisplayList.clear(); |
| 12702 | } |
| 12703 | } |
| 12704 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12705 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12706 | * <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] | 12707 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12708 | * @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] | 12709 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12710 | * @see #getDrawingCache(boolean) |
| 12711 | */ |
| 12712 | public Bitmap getDrawingCache() { |
| 12713 | return getDrawingCache(false); |
| 12714 | } |
| 12715 | |
| 12716 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12717 | * <p>Returns the bitmap in which this view drawing is cached. The returned bitmap |
| 12718 | * is null when caching is disabled. If caching is enabled and the cache is not ready, |
| 12719 | * this method will create it. Calling {@link #draw(android.graphics.Canvas)} will not |
| 12720 | * draw from the cache when the cache is enabled. To benefit from the cache, you must |
| 12721 | * request the drawing cache by calling this method and draw it on screen if the |
| 12722 | * returned bitmap is not null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12723 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12724 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 12725 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 12726 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 12727 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 12728 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 12729 | * size than the view. This implies that your application must be able to handle this |
| 12730 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12731 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12732 | * @param autoScale Indicates whether the generated bitmap should be scaled based on |
| 12733 | * the current density of the screen when the application is in compatibility |
| 12734 | * mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12735 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12736 | * @return A bitmap representing this view or null if cache is disabled. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12737 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12738 | * @see #setDrawingCacheEnabled(boolean) |
| 12739 | * @see #isDrawingCacheEnabled() |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12740 | * @see #buildDrawingCache(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12741 | * @see #destroyDrawingCache() |
| 12742 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12743 | public Bitmap getDrawingCache(boolean autoScale) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12744 | if ((mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING) { |
| 12745 | return null; |
| 12746 | } |
| 12747 | if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12748 | buildDrawingCache(autoScale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12749 | } |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12750 | return autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12751 | } |
| 12752 | |
| 12753 | /** |
| 12754 | * <p>Frees the resources used by the drawing cache. If you call |
| 12755 | * {@link #buildDrawingCache()} manually without calling |
| 12756 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 12757 | * should cleanup the cache with this method afterwards.</p> |
| 12758 | * |
| 12759 | * @see #setDrawingCacheEnabled(boolean) |
| 12760 | * @see #buildDrawingCache() |
| 12761 | * @see #getDrawingCache() |
| 12762 | */ |
| 12763 | public void destroyDrawingCache() { |
| 12764 | if (mDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12765 | mDrawingCache.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12766 | mDrawingCache = null; |
| 12767 | } |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12768 | if (mUnscaledDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12769 | mUnscaledDrawingCache.recycle(); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12770 | mUnscaledDrawingCache = null; |
| 12771 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12772 | } |
| 12773 | |
| 12774 | /** |
| 12775 | * 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] | 12776 | * 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] | 12777 | * view will always be drawn on top of a solid color. |
| 12778 | * |
| 12779 | * @param color The background color to use for the drawing cache's bitmap |
| 12780 | * |
| 12781 | * @see #setDrawingCacheEnabled(boolean) |
| 12782 | * @see #buildDrawingCache() |
| 12783 | * @see #getDrawingCache() |
| 12784 | */ |
| 12785 | public void setDrawingCacheBackgroundColor(int color) { |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 12786 | if (color != mDrawingCacheBackgroundColor) { |
| 12787 | mDrawingCacheBackgroundColor = color; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12788 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 12789 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12790 | } |
| 12791 | |
| 12792 | /** |
| 12793 | * @see #setDrawingCacheBackgroundColor(int) |
| 12794 | * |
| 12795 | * @return The background color to used for the drawing cache's bitmap |
| 12796 | */ |
| 12797 | public int getDrawingCacheBackgroundColor() { |
| 12798 | return mDrawingCacheBackgroundColor; |
| 12799 | } |
| 12800 | |
| 12801 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12802 | * <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] | 12803 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12804 | * @see #buildDrawingCache(boolean) |
| 12805 | */ |
| 12806 | public void buildDrawingCache() { |
| 12807 | buildDrawingCache(false); |
| 12808 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 12809 | |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12810 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12811 | * <p>Forces the drawing cache to be built if the drawing cache is invalid.</p> |
| 12812 | * |
| 12813 | * <p>If you call {@link #buildDrawingCache()} manually without calling |
| 12814 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 12815 | * should cleanup the cache by calling {@link #destroyDrawingCache()} afterwards.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12816 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12817 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 12818 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 12819 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 12820 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 12821 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 12822 | * size than the view. This implies that your application must be able to handle this |
| 12823 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12824 | * |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 12825 | * <p>You should avoid calling this method when hardware acceleration is enabled. If |
| 12826 | * 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] | 12827 | * 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] | 12828 | * performance.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12829 | * |
| 12830 | * @see #getDrawingCache() |
| 12831 | * @see #destroyDrawingCache() |
| 12832 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12833 | public void buildDrawingCache(boolean autoScale) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12834 | if ((mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == 0 || (autoScale ? |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12835 | mDrawingCache == null : mUnscaledDrawingCache == null)) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12836 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12837 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12838 | int width = mRight - mLeft; |
| 12839 | int height = mBottom - mTop; |
| 12840 | |
| 12841 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12842 | final boolean scalingRequired = attachInfo != null && attachInfo.mScalingRequired; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12843 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12844 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12845 | width = (int) ((width * attachInfo.mApplicationScale) + 0.5f); |
| 12846 | height = (int) ((height * attachInfo.mApplicationScale) + 0.5f); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12847 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12848 | |
| 12849 | final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 12850 | final boolean opaque = drawingCacheBackgroundColor != 0 || isOpaque(); |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 12851 | final boolean use32BitCache = attachInfo != null && attachInfo.mUse32BitDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12852 | |
Romain Guy | af61cc4 | 2012-09-30 10:49:15 -0700 | [diff] [blame] | 12853 | final long projectedBitmapSize = width * height * (opaque && !use32BitCache ? 2 : 4); |
| 12854 | final long drawingCacheSize = |
Chris Craik | 10e9d1d | 2012-09-06 14:42:44 -0700 | [diff] [blame] | 12855 | ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize(); |
| 12856 | if (width <= 0 || height <= 0 || projectedBitmapSize > drawingCacheSize) { |
Chris Craik | 3667aa3 | 2012-09-06 14:56:39 -0700 | [diff] [blame] | 12857 | if (width > 0 && height > 0) { |
| 12858 | Log.w(VIEW_LOG_TAG, "View too large to fit into drawing cache, needs " |
| 12859 | + projectedBitmapSize + " bytes, only " |
| 12860 | + drawingCacheSize + " available"); |
| 12861 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12862 | destroyDrawingCache(); |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12863 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12864 | return; |
| 12865 | } |
| 12866 | |
| 12867 | boolean clear = true; |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12868 | Bitmap bitmap = autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12869 | |
| 12870 | if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12871 | Bitmap.Config quality; |
| 12872 | if (!opaque) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12873 | // Never pick ARGB_4444 because it looks awful |
| 12874 | // 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] | 12875 | switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) { |
| 12876 | case DRAWING_CACHE_QUALITY_AUTO: |
| 12877 | quality = Bitmap.Config.ARGB_8888; |
| 12878 | break; |
| 12879 | case DRAWING_CACHE_QUALITY_LOW: |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12880 | quality = Bitmap.Config.ARGB_8888; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12881 | break; |
| 12882 | case DRAWING_CACHE_QUALITY_HIGH: |
| 12883 | quality = Bitmap.Config.ARGB_8888; |
| 12884 | break; |
| 12885 | default: |
| 12886 | quality = Bitmap.Config.ARGB_8888; |
| 12887 | break; |
| 12888 | } |
| 12889 | } else { |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 12890 | // Optimization for translucent windows |
| 12891 | // 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] | 12892 | 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] | 12893 | } |
| 12894 | |
| 12895 | // Try to cleanup memory |
| 12896 | if (bitmap != null) bitmap.recycle(); |
| 12897 | |
| 12898 | try { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 12899 | bitmap = Bitmap.createBitmap(mResources.getDisplayMetrics(), |
| 12900 | width, height, quality); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 12901 | bitmap.setDensity(getResources().getDisplayMetrics().densityDpi); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12902 | if (autoScale) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12903 | mDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12904 | } else { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12905 | mUnscaledDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12906 | } |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 12907 | if (opaque && use32BitCache) bitmap.setHasAlpha(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12908 | } catch (OutOfMemoryError e) { |
| 12909 | // If there is not enough memory to create the bitmap cache, just |
| 12910 | // ignore the issue as bitmap caches are not required to draw the |
| 12911 | // view hierarchy |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12912 | if (autoScale) { |
| 12913 | mDrawingCache = null; |
| 12914 | } else { |
| 12915 | mUnscaledDrawingCache = null; |
| 12916 | } |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12917 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12918 | return; |
| 12919 | } |
| 12920 | |
| 12921 | clear = drawingCacheBackgroundColor != 0; |
| 12922 | } |
| 12923 | |
| 12924 | Canvas canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12925 | if (attachInfo != null) { |
| 12926 | canvas = attachInfo.mCanvas; |
| 12927 | if (canvas == null) { |
| 12928 | canvas = new Canvas(); |
| 12929 | } |
| 12930 | canvas.setBitmap(bitmap); |
| 12931 | // Temporarily clobber the cached Canvas in case one of our children |
| 12932 | // is also using a drawing cache. Without this, the children would |
| 12933 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 12934 | // thing would happen (invisible views, corrupted drawings, etc.) |
| 12935 | attachInfo.mCanvas = null; |
| 12936 | } else { |
| 12937 | // This case should hopefully never or seldom happen |
| 12938 | canvas = new Canvas(bitmap); |
| 12939 | } |
| 12940 | |
| 12941 | if (clear) { |
| 12942 | bitmap.eraseColor(drawingCacheBackgroundColor); |
| 12943 | } |
| 12944 | |
| 12945 | computeScroll(); |
| 12946 | final int restoreCount = canvas.save(); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12947 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12948 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12949 | final float scale = attachInfo.mApplicationScale; |
| 12950 | canvas.scale(scale, scale); |
| 12951 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12952 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12953 | canvas.translate(-mScrollX, -mScrollY); |
| 12954 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12955 | mPrivateFlags |= PFLAG_DRAWN; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12956 | if (mAttachInfo == null || !mAttachInfo.mHardwareAccelerated || |
| 12957 | mLayerType != LAYER_TYPE_NONE) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12958 | mPrivateFlags |= PFLAG_DRAWING_CACHE_VALID; |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 12959 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12960 | |
| 12961 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12962 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
| 12963 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12964 | dispatchDraw(canvas); |
| 12965 | } else { |
| 12966 | draw(canvas); |
| 12967 | } |
| 12968 | |
| 12969 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 12970 | canvas.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12971 | |
| 12972 | if (attachInfo != null) { |
| 12973 | // Restore the cached Canvas for our siblings |
| 12974 | attachInfo.mCanvas = canvas; |
| 12975 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12976 | } |
| 12977 | } |
| 12978 | |
| 12979 | /** |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12980 | * Create a snapshot of the view into a bitmap. We should probably make |
| 12981 | * some form of this public, but should think about the API. |
| 12982 | */ |
Romain Guy | 223ff5c | 2010-03-02 17:07:47 -0800 | [diff] [blame] | 12983 | Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) { |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12984 | int width = mRight - mLeft; |
| 12985 | int height = mBottom - mTop; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12986 | |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12987 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 12988 | final float scale = attachInfo != null ? attachInfo.mApplicationScale : 1.0f; |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12989 | width = (int) ((width * scale) + 0.5f); |
| 12990 | height = (int) ((height * scale) + 0.5f); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12991 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 12992 | Bitmap bitmap = Bitmap.createBitmap(mResources.getDisplayMetrics(), |
| 12993 | width > 0 ? width : 1, height > 0 ? height : 1, quality); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12994 | if (bitmap == null) { |
| 12995 | throw new OutOfMemoryError(); |
| 12996 | } |
| 12997 | |
Romain Guy | c529d8d | 2011-09-06 15:01:39 -0700 | [diff] [blame] | 12998 | Resources resources = getResources(); |
| 12999 | if (resources != null) { |
| 13000 | bitmap.setDensity(resources.getDisplayMetrics().densityDpi); |
| 13001 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13002 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13003 | Canvas canvas; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13004 | if (attachInfo != null) { |
| 13005 | canvas = attachInfo.mCanvas; |
| 13006 | if (canvas == null) { |
| 13007 | canvas = new Canvas(); |
| 13008 | } |
| 13009 | canvas.setBitmap(bitmap); |
| 13010 | // Temporarily clobber the cached Canvas in case one of our children |
| 13011 | // is also using a drawing cache. Without this, the children would |
| 13012 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 13013 | // things would happen (invisible views, corrupted drawings, etc.) |
| 13014 | attachInfo.mCanvas = null; |
| 13015 | } else { |
| 13016 | // This case should hopefully never or seldom happen |
| 13017 | canvas = new Canvas(bitmap); |
| 13018 | } |
| 13019 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13020 | if ((backgroundColor & 0xff000000) != 0) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13021 | bitmap.eraseColor(backgroundColor); |
| 13022 | } |
| 13023 | |
| 13024 | computeScroll(); |
| 13025 | final int restoreCount = canvas.save(); |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 13026 | canvas.scale(scale, scale); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13027 | canvas.translate(-mScrollX, -mScrollY); |
| 13028 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13029 | // Temporarily remove the dirty mask |
| 13030 | int flags = mPrivateFlags; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13031 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13032 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13033 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13034 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13035 | dispatchDraw(canvas); |
| 13036 | } else { |
| 13037 | draw(canvas); |
| 13038 | } |
| 13039 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13040 | mPrivateFlags = flags; |
| 13041 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13042 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 13043 | canvas.setBitmap(null); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13044 | |
| 13045 | if (attachInfo != null) { |
| 13046 | // Restore the cached Canvas for our siblings |
| 13047 | attachInfo.mCanvas = canvas; |
| 13048 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13049 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13050 | return bitmap; |
| 13051 | } |
| 13052 | |
| 13053 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13054 | * Indicates whether this View is currently in edit mode. A View is usually |
| 13055 | * in edit mode when displayed within a developer tool. For instance, if |
| 13056 | * this View is being drawn by a visual user interface builder, this method |
| 13057 | * should return true. |
| 13058 | * |
| 13059 | * Subclasses should check the return value of this method to provide |
| 13060 | * different behaviors if their normal behavior might interfere with the |
| 13061 | * host environment. For instance: the class spawns a thread in its |
| 13062 | * constructor, the drawing code relies on device-specific features, etc. |
| 13063 | * |
| 13064 | * This method is usually checked in the drawing code of custom widgets. |
| 13065 | * |
| 13066 | * @return True if this View is in edit mode, false otherwise. |
| 13067 | */ |
| 13068 | public boolean isInEditMode() { |
| 13069 | return false; |
| 13070 | } |
| 13071 | |
| 13072 | /** |
| 13073 | * If the View draws content inside its padding and enables fading edges, |
| 13074 | * it needs to support padding offsets. Padding offsets are added to the |
| 13075 | * fading edges to extend the length of the fade so that it covers pixels |
| 13076 | * drawn inside the padding. |
| 13077 | * |
| 13078 | * Subclasses of this class should override this method if they need |
| 13079 | * to draw content inside the padding. |
| 13080 | * |
| 13081 | * @return True if padding offset must be applied, false otherwise. |
| 13082 | * |
| 13083 | * @see #getLeftPaddingOffset() |
| 13084 | * @see #getRightPaddingOffset() |
| 13085 | * @see #getTopPaddingOffset() |
| 13086 | * @see #getBottomPaddingOffset() |
| 13087 | * |
| 13088 | * @since CURRENT |
| 13089 | */ |
| 13090 | protected boolean isPaddingOffsetRequired() { |
| 13091 | return false; |
| 13092 | } |
| 13093 | |
| 13094 | /** |
| 13095 | * Amount by which to extend the left fading region. Called only when |
| 13096 | * {@link #isPaddingOffsetRequired()} returns true. |
| 13097 | * |
| 13098 | * @return The left padding offset in pixels. |
| 13099 | * |
| 13100 | * @see #isPaddingOffsetRequired() |
| 13101 | * |
| 13102 | * @since CURRENT |
| 13103 | */ |
| 13104 | protected int getLeftPaddingOffset() { |
| 13105 | return 0; |
| 13106 | } |
| 13107 | |
| 13108 | /** |
| 13109 | * Amount by which to extend the right fading region. Called only when |
| 13110 | * {@link #isPaddingOffsetRequired()} returns true. |
| 13111 | * |
| 13112 | * @return The right padding offset in pixels. |
| 13113 | * |
| 13114 | * @see #isPaddingOffsetRequired() |
| 13115 | * |
| 13116 | * @since CURRENT |
| 13117 | */ |
| 13118 | protected int getRightPaddingOffset() { |
| 13119 | return 0; |
| 13120 | } |
| 13121 | |
| 13122 | /** |
| 13123 | * Amount by which to extend the top fading region. Called only when |
| 13124 | * {@link #isPaddingOffsetRequired()} returns true. |
| 13125 | * |
| 13126 | * @return The top padding offset in pixels. |
| 13127 | * |
| 13128 | * @see #isPaddingOffsetRequired() |
| 13129 | * |
| 13130 | * @since CURRENT |
| 13131 | */ |
| 13132 | protected int getTopPaddingOffset() { |
| 13133 | return 0; |
| 13134 | } |
| 13135 | |
| 13136 | /** |
| 13137 | * Amount by which to extend the bottom fading region. Called only when |
| 13138 | * {@link #isPaddingOffsetRequired()} returns true. |
| 13139 | * |
| 13140 | * @return The bottom padding offset in pixels. |
| 13141 | * |
| 13142 | * @see #isPaddingOffsetRequired() |
| 13143 | * |
| 13144 | * @since CURRENT |
| 13145 | */ |
| 13146 | protected int getBottomPaddingOffset() { |
| 13147 | return 0; |
| 13148 | } |
| 13149 | |
| 13150 | /** |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13151 | * @hide |
| 13152 | * @param offsetRequired |
| 13153 | */ |
| 13154 | protected int getFadeTop(boolean offsetRequired) { |
| 13155 | int top = mPaddingTop; |
| 13156 | if (offsetRequired) top += getTopPaddingOffset(); |
| 13157 | return top; |
| 13158 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13159 | |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13160 | /** |
| 13161 | * @hide |
| 13162 | * @param offsetRequired |
| 13163 | */ |
| 13164 | protected int getFadeHeight(boolean offsetRequired) { |
| 13165 | int padding = mPaddingTop; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13166 | if (offsetRequired) padding += getTopPaddingOffset(); |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13167 | return mBottom - mTop - mPaddingBottom - padding; |
| 13168 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13169 | |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13170 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 13171 | * <p>Indicates whether this view is attached to a hardware accelerated |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13172 | * window or not.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13173 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13174 | * <p>Even if this method returns true, it does not mean that every call |
| 13175 | * to {@link #draw(android.graphics.Canvas)} will be made with an hardware |
| 13176 | * accelerated {@link android.graphics.Canvas}. For instance, if this view |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 13177 | * is drawn onto an offscreen {@link android.graphics.Bitmap} and its |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13178 | * window is hardware accelerated, |
| 13179 | * {@link android.graphics.Canvas#isHardwareAccelerated()} will likely |
| 13180 | * return false, and this method will return true.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13181 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13182 | * @return True if the view is attached to a window and the window is |
| 13183 | * hardware accelerated; false in any other case. |
| 13184 | */ |
| 13185 | public boolean isHardwareAccelerated() { |
| 13186 | return mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
| 13187 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13188 | |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13189 | /** |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13190 | * Utility function, called by draw(canvas, parent, drawingTime) to handle the less common |
| 13191 | * case of an active Animation being run on the view. |
| 13192 | */ |
| 13193 | private boolean drawAnimation(ViewGroup parent, long drawingTime, |
| 13194 | Animation a, boolean scalingRequired) { |
| 13195 | Transformation invalidationTransform; |
| 13196 | final int flags = parent.mGroupFlags; |
| 13197 | final boolean initialized = a.isInitialized(); |
| 13198 | if (!initialized) { |
Chet Haase | 1fb8a9e | 2012-04-19 09:22:34 -0700 | [diff] [blame] | 13199 | a.initialize(mRight - mLeft, mBottom - mTop, parent.getWidth(), parent.getHeight()); |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13200 | a.initializeInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop); |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 13201 | if (mAttachInfo != null) a.setListenerHandler(mAttachInfo.mHandler); |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13202 | onAnimationStart(); |
| 13203 | } |
| 13204 | |
| 13205 | boolean more = a.getTransformation(drawingTime, parent.mChildTransformation, 1f); |
| 13206 | if (scalingRequired && mAttachInfo.mApplicationScale != 1f) { |
| 13207 | if (parent.mInvalidationTransformation == null) { |
| 13208 | parent.mInvalidationTransformation = new Transformation(); |
| 13209 | } |
| 13210 | invalidationTransform = parent.mInvalidationTransformation; |
| 13211 | a.getTransformation(drawingTime, invalidationTransform, 1f); |
| 13212 | } else { |
| 13213 | invalidationTransform = parent.mChildTransformation; |
| 13214 | } |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 13215 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13216 | if (more) { |
| 13217 | if (!a.willChangeBounds()) { |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 13218 | if ((flags & (ViewGroup.FLAG_OPTIMIZE_INVALIDATE | ViewGroup.FLAG_ANIMATION_DONE)) == |
| 13219 | ViewGroup.FLAG_OPTIMIZE_INVALIDATE) { |
| 13220 | parent.mGroupFlags |= ViewGroup.FLAG_INVALIDATE_REQUIRED; |
| 13221 | } else if ((flags & ViewGroup.FLAG_INVALIDATE_REQUIRED) == 0) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13222 | // The child need to draw an animation, potentially offscreen, so |
| 13223 | // make sure we do not cancel invalidate requests |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13224 | parent.mPrivateFlags |= PFLAG_DRAW_ANIMATION; |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13225 | parent.invalidate(mLeft, mTop, mRight, mBottom); |
| 13226 | } |
| 13227 | } else { |
| 13228 | if (parent.mInvalidateRegion == null) { |
| 13229 | parent.mInvalidateRegion = new RectF(); |
| 13230 | } |
| 13231 | final RectF region = parent.mInvalidateRegion; |
| 13232 | a.getInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop, region, |
| 13233 | invalidationTransform); |
| 13234 | |
| 13235 | // The child need to draw an animation, potentially offscreen, so |
| 13236 | // make sure we do not cancel invalidate requests |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13237 | parent.mPrivateFlags |= PFLAG_DRAW_ANIMATION; |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13238 | |
| 13239 | final int left = mLeft + (int) region.left; |
| 13240 | final int top = mTop + (int) region.top; |
| 13241 | parent.invalidate(left, top, left + (int) (region.width() + .5f), |
| 13242 | top + (int) (region.height() + .5f)); |
| 13243 | } |
| 13244 | } |
| 13245 | return more; |
| 13246 | } |
| 13247 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13248 | /** |
| 13249 | * This method is called by getDisplayList() when a display list is created or re-rendered. |
| 13250 | * It sets or resets the current value of all properties on that display list (resetting is |
| 13251 | * necessary when a display list is being re-created, because we need to make sure that |
| 13252 | * previously-set transform values |
| 13253 | */ |
| 13254 | void setDisplayListProperties(DisplayList displayList) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 13255 | if (displayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13256 | displayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 13257 | displayList.setHasOverlappingRendering(hasOverlappingRendering()); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13258 | if (mParent instanceof ViewGroup) { |
| 13259 | displayList.setClipChildren( |
| 13260 | (((ViewGroup)mParent).mGroupFlags & ViewGroup.FLAG_CLIP_CHILDREN) != 0); |
| 13261 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13262 | float alpha = 1; |
| 13263 | if (mParent instanceof ViewGroup && (((ViewGroup) mParent).mGroupFlags & |
| 13264 | ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
| 13265 | ViewGroup parentVG = (ViewGroup) mParent; |
| 13266 | final boolean hasTransform = |
| 13267 | parentVG.getChildStaticTransformation(this, parentVG.mChildTransformation); |
| 13268 | if (hasTransform) { |
| 13269 | Transformation transform = parentVG.mChildTransformation; |
| 13270 | final int transformType = parentVG.mChildTransformation.getTransformationType(); |
| 13271 | if (transformType != Transformation.TYPE_IDENTITY) { |
| 13272 | if ((transformType & Transformation.TYPE_ALPHA) != 0) { |
| 13273 | alpha = transform.getAlpha(); |
| 13274 | } |
| 13275 | if ((transformType & Transformation.TYPE_MATRIX) != 0) { |
| 13276 | displayList.setStaticMatrix(transform.getMatrix()); |
| 13277 | } |
| 13278 | } |
| 13279 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13280 | } |
| 13281 | if (mTransformationInfo != null) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13282 | alpha *= mTransformationInfo.mAlpha; |
| 13283 | if (alpha < 1) { |
| 13284 | final int multipliedAlpha = (int) (255 * alpha); |
| 13285 | if (onSetAlpha(multipliedAlpha)) { |
| 13286 | alpha = 1; |
| 13287 | } |
| 13288 | } |
| 13289 | displayList.setTransformationInfo(alpha, |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13290 | mTransformationInfo.mTranslationX, mTransformationInfo.mTranslationY, |
| 13291 | mTransformationInfo.mRotation, mTransformationInfo.mRotationX, |
| 13292 | mTransformationInfo.mRotationY, mTransformationInfo.mScaleX, |
| 13293 | mTransformationInfo.mScaleY); |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 13294 | if (mTransformationInfo.mCamera == null) { |
| 13295 | mTransformationInfo.mCamera = new Camera(); |
| 13296 | mTransformationInfo.matrix3D = new Matrix(); |
| 13297 | } |
| 13298 | displayList.setCameraDistance(mTransformationInfo.mCamera.getLocationZ()); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13299 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == PFLAG_PIVOT_EXPLICITLY_SET) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13300 | displayList.setPivotX(getPivotX()); |
| 13301 | displayList.setPivotY(getPivotY()); |
| 13302 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13303 | } else if (alpha < 1) { |
| 13304 | displayList.setAlpha(alpha); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13305 | } |
| 13306 | } |
| 13307 | } |
| 13308 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13309 | /** |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13310 | * This method is called by ViewGroup.drawChild() to have each child view draw itself. |
| 13311 | * This draw() method is an implementation detail and is not intended to be overridden or |
| 13312 | * to be called from anywhere else other than ViewGroup.drawChild(). |
| 13313 | */ |
| 13314 | boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 13315 | boolean useDisplayListProperties = mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13316 | boolean more = false; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13317 | final boolean childHasIdentityMatrix = hasIdentityMatrix(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13318 | final int flags = parent.mGroupFlags; |
| 13319 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13320 | if ((flags & ViewGroup.FLAG_CLEAR_TRANSFORMATION) == ViewGroup.FLAG_CLEAR_TRANSFORMATION) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13321 | parent.mChildTransformation.clear(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13322 | parent.mGroupFlags &= ~ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13323 | } |
| 13324 | |
| 13325 | Transformation transformToApply = null; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13326 | boolean concatMatrix = false; |
| 13327 | |
| 13328 | boolean scalingRequired = false; |
| 13329 | boolean caching; |
Michael Jurka | ba64974 | 2012-06-28 19:12:58 -0700 | [diff] [blame] | 13330 | int layerType = getLayerType(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13331 | |
| 13332 | final boolean hardwareAccelerated = canvas.isHardwareAccelerated(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13333 | if ((flags & ViewGroup.FLAG_CHILDREN_DRAWN_WITH_CACHE) != 0 || |
| 13334 | (flags & ViewGroup.FLAG_ALWAYS_DRAWN_WITH_CACHE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13335 | caching = true; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13336 | // Auto-scaled apps are not hw-accelerated, no need to set scaling flag on DisplayList |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13337 | if (mAttachInfo != null) scalingRequired = mAttachInfo.mScalingRequired; |
| 13338 | } else { |
| 13339 | caching = (layerType != LAYER_TYPE_NONE) || hardwareAccelerated; |
| 13340 | } |
| 13341 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13342 | final Animation a = getAnimation(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13343 | if (a != null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13344 | more = drawAnimation(parent, drawingTime, a, scalingRequired); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13345 | concatMatrix = a.willChangeTransformationMatrix(); |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13346 | if (concatMatrix) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13347 | mPrivateFlags3 |= PFLAG3_VIEW_IS_ANIMATING_TRANSFORM; |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13348 | } |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13349 | transformToApply = parent.mChildTransformation; |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13350 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13351 | if ((mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_TRANSFORM) == PFLAG3_VIEW_IS_ANIMATING_TRANSFORM && |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13352 | mDisplayList != null) { |
| 13353 | // No longer animating: clear out old animation matrix |
| 13354 | mDisplayList.setAnimationMatrix(null); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13355 | mPrivateFlags3 &= ~PFLAG3_VIEW_IS_ANIMATING_TRANSFORM; |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13356 | } |
| 13357 | if (!useDisplayListProperties && |
| 13358 | (flags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
| 13359 | final boolean hasTransform = |
| 13360 | parent.getChildStaticTransformation(this, parent.mChildTransformation); |
| 13361 | if (hasTransform) { |
| 13362 | final int transformType = parent.mChildTransformation.getTransformationType(); |
| 13363 | transformToApply = transformType != Transformation.TYPE_IDENTITY ? |
| 13364 | parent.mChildTransformation : null; |
| 13365 | concatMatrix = (transformType & Transformation.TYPE_MATRIX) != 0; |
| 13366 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13367 | } |
| 13368 | } |
| 13369 | |
| 13370 | concatMatrix |= !childHasIdentityMatrix; |
| 13371 | |
| 13372 | // Sets the flag as early as possible to allow draw() implementations |
| 13373 | // to call invalidate() successfully when doing animations |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13374 | mPrivateFlags |= PFLAG_DRAWN; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13375 | |
Romain Guy | fbb4321 | 2012-08-30 15:19:27 -0700 | [diff] [blame] | 13376 | if (!concatMatrix && |
| 13377 | (flags & (ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS | |
| 13378 | ViewGroup.FLAG_CLIP_CHILDREN)) == ViewGroup.FLAG_CLIP_CHILDREN && |
Chet Haase | 599913d | 2012-07-23 16:22:05 -0700 | [diff] [blame] | 13379 | canvas.quickReject(mLeft, mTop, mRight, mBottom, Canvas.EdgeType.BW) && |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13380 | (mPrivateFlags & PFLAG_DRAW_ANIMATION) == 0) { |
| 13381 | mPrivateFlags2 |= PFLAG2_VIEW_QUICK_REJECTED; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13382 | return more; |
| 13383 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13384 | mPrivateFlags2 &= ~PFLAG2_VIEW_QUICK_REJECTED; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13385 | |
| 13386 | if (hardwareAccelerated) { |
| 13387 | // Clear INVALIDATED flag to allow invalidation to occur during rendering, but |
| 13388 | // retain the flag's value temporarily in the mRecreateDisplayList flag |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13389 | mRecreateDisplayList = (mPrivateFlags & PFLAG_INVALIDATED) == PFLAG_INVALIDATED; |
| 13390 | mPrivateFlags &= ~PFLAG_INVALIDATED; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13391 | } |
| 13392 | |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13393 | DisplayList displayList = null; |
| 13394 | Bitmap cache = null; |
| 13395 | boolean hasDisplayList = false; |
| 13396 | if (caching) { |
| 13397 | if (!hardwareAccelerated) { |
| 13398 | if (layerType != LAYER_TYPE_NONE) { |
| 13399 | layerType = LAYER_TYPE_SOFTWARE; |
| 13400 | buildDrawingCache(true); |
| 13401 | } |
| 13402 | cache = getDrawingCache(true); |
| 13403 | } else { |
| 13404 | switch (layerType) { |
| 13405 | case LAYER_TYPE_SOFTWARE: |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 13406 | if (useDisplayListProperties) { |
| 13407 | hasDisplayList = canHaveDisplayList(); |
| 13408 | } else { |
| 13409 | buildDrawingCache(true); |
| 13410 | cache = getDrawingCache(true); |
| 13411 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13412 | break; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13413 | case LAYER_TYPE_HARDWARE: |
| 13414 | if (useDisplayListProperties) { |
| 13415 | hasDisplayList = canHaveDisplayList(); |
| 13416 | } |
| 13417 | break; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13418 | case LAYER_TYPE_NONE: |
| 13419 | // Delay getting the display list until animation-driven alpha values are |
| 13420 | // set up and possibly passed on to the view |
| 13421 | hasDisplayList = canHaveDisplayList(); |
| 13422 | break; |
| 13423 | } |
| 13424 | } |
| 13425 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13426 | useDisplayListProperties &= hasDisplayList; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13427 | if (useDisplayListProperties) { |
| 13428 | displayList = getDisplayList(); |
| 13429 | if (!displayList.isValid()) { |
| 13430 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 13431 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 13432 | // try to use it again. |
| 13433 | displayList = null; |
| 13434 | hasDisplayList = false; |
| 13435 | useDisplayListProperties = false; |
| 13436 | } |
| 13437 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13438 | |
Chet Haase | 526057b | 2012-07-12 17:50:41 -0700 | [diff] [blame] | 13439 | int sx = 0; |
| 13440 | int sy = 0; |
| 13441 | if (!hasDisplayList) { |
| 13442 | computeScroll(); |
| 13443 | sx = mScrollX; |
| 13444 | sy = mScrollY; |
| 13445 | } |
| 13446 | |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13447 | final boolean hasNoCache = cache == null || hasDisplayList; |
| 13448 | final boolean offsetForScroll = cache == null && !hasDisplayList && |
| 13449 | layerType != LAYER_TYPE_HARDWARE; |
| 13450 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13451 | int restoreTo = -1; |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 13452 | if (!useDisplayListProperties || transformToApply != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13453 | restoreTo = canvas.save(); |
| 13454 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13455 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13456 | canvas.translate(mLeft - sx, mTop - sy); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13457 | } else { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13458 | if (!useDisplayListProperties) { |
| 13459 | canvas.translate(mLeft, mTop); |
| 13460 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13461 | if (scalingRequired) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13462 | if (useDisplayListProperties) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13463 | // TODO: Might not need this if we put everything inside the DL |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13464 | restoreTo = canvas.save(); |
| 13465 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13466 | // mAttachInfo cannot be null, otherwise scalingRequired == false |
| 13467 | final float scale = 1.0f / mAttachInfo.mApplicationScale; |
| 13468 | canvas.scale(scale, scale); |
| 13469 | } |
| 13470 | } |
| 13471 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13472 | float alpha = useDisplayListProperties ? 1 : getAlpha(); |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13473 | if (transformToApply != null || alpha < 1 || !hasIdentityMatrix() || |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13474 | (mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_ALPHA) == PFLAG3_VIEW_IS_ANIMATING_ALPHA) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13475 | if (transformToApply != null || !childHasIdentityMatrix) { |
| 13476 | int transX = 0; |
| 13477 | int transY = 0; |
| 13478 | |
| 13479 | if (offsetForScroll) { |
| 13480 | transX = -sx; |
| 13481 | transY = -sy; |
| 13482 | } |
| 13483 | |
| 13484 | if (transformToApply != null) { |
| 13485 | if (concatMatrix) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13486 | if (useDisplayListProperties) { |
| 13487 | displayList.setAnimationMatrix(transformToApply.getMatrix()); |
| 13488 | } else { |
| 13489 | // Undo the scroll translation, apply the transformation matrix, |
| 13490 | // then redo the scroll translate to get the correct result. |
| 13491 | canvas.translate(-transX, -transY); |
| 13492 | canvas.concat(transformToApply.getMatrix()); |
| 13493 | canvas.translate(transX, transY); |
| 13494 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13495 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13496 | } |
| 13497 | |
| 13498 | float transformAlpha = transformToApply.getAlpha(); |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13499 | if (transformAlpha < 1) { |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13500 | alpha *= transformAlpha; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13501 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13502 | } |
| 13503 | } |
| 13504 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13505 | if (!childHasIdentityMatrix && !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13506 | canvas.translate(-transX, -transY); |
| 13507 | canvas.concat(getMatrix()); |
| 13508 | canvas.translate(transX, transY); |
| 13509 | } |
| 13510 | } |
| 13511 | |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13512 | // Deal with alpha if it is or used to be <1 |
| 13513 | if (alpha < 1 || |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13514 | (mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_ALPHA) == PFLAG3_VIEW_IS_ANIMATING_ALPHA) { |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13515 | if (alpha < 1) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13516 | mPrivateFlags3 |= PFLAG3_VIEW_IS_ANIMATING_ALPHA; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13517 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13518 | mPrivateFlags3 &= ~PFLAG3_VIEW_IS_ANIMATING_ALPHA; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13519 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13520 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13521 | if (hasNoCache) { |
| 13522 | final int multipliedAlpha = (int) (255 * alpha); |
| 13523 | if (!onSetAlpha(multipliedAlpha)) { |
| 13524 | int layerFlags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13525 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) != 0 || |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13526 | layerType != LAYER_TYPE_NONE) { |
| 13527 | layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG; |
| 13528 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13529 | if (useDisplayListProperties) { |
| 13530 | displayList.setAlpha(alpha * getAlpha()); |
| 13531 | } else if (layerType == LAYER_TYPE_NONE) { |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 13532 | final int scrollX = hasDisplayList ? 0 : sx; |
| 13533 | final int scrollY = hasDisplayList ? 0 : sy; |
| 13534 | canvas.saveLayerAlpha(scrollX, scrollY, scrollX + mRight - mLeft, |
| 13535 | scrollY + mBottom - mTop, multipliedAlpha, layerFlags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13536 | } |
| 13537 | } else { |
| 13538 | // Alpha is handled by the child directly, clobber the layer's alpha |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13539 | mPrivateFlags |= PFLAG_ALPHA_SET; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13540 | } |
| 13541 | } |
| 13542 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13543 | } else if ((mPrivateFlags & PFLAG_ALPHA_SET) == PFLAG_ALPHA_SET) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13544 | onSetAlpha(255); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13545 | mPrivateFlags &= ~PFLAG_ALPHA_SET; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13546 | } |
| 13547 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13548 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) == ViewGroup.FLAG_CLIP_CHILDREN && |
| 13549 | !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13550 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13551 | canvas.clipRect(sx, sy, sx + (mRight - mLeft), sy + (mBottom - mTop)); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13552 | } else { |
| 13553 | if (!scalingRequired || cache == null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13554 | canvas.clipRect(0, 0, mRight - mLeft, mBottom - mTop); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13555 | } else { |
| 13556 | canvas.clipRect(0, 0, cache.getWidth(), cache.getHeight()); |
| 13557 | } |
| 13558 | } |
| 13559 | } |
| 13560 | |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13561 | if (!useDisplayListProperties && hasDisplayList) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13562 | displayList = getDisplayList(); |
| 13563 | if (!displayList.isValid()) { |
| 13564 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 13565 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 13566 | // try to use it again. |
| 13567 | displayList = null; |
| 13568 | hasDisplayList = false; |
| 13569 | } |
| 13570 | } |
| 13571 | |
| 13572 | if (hasNoCache) { |
| 13573 | boolean layerRendered = false; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13574 | if (layerType == LAYER_TYPE_HARDWARE && !useDisplayListProperties) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 13575 | final HardwareLayer layer = getHardwareLayer(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13576 | if (layer != null && layer.isValid()) { |
| 13577 | mLayerPaint.setAlpha((int) (alpha * 255)); |
| 13578 | ((HardwareCanvas) canvas).drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 13579 | layerRendered = true; |
| 13580 | } else { |
| 13581 | final int scrollX = hasDisplayList ? 0 : sx; |
| 13582 | final int scrollY = hasDisplayList ? 0 : sy; |
| 13583 | canvas.saveLayer(scrollX, scrollY, |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13584 | scrollX + mRight - mLeft, scrollY + mBottom - mTop, mLayerPaint, |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13585 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 13586 | } |
| 13587 | } |
| 13588 | |
| 13589 | if (!layerRendered) { |
| 13590 | if (!hasDisplayList) { |
| 13591 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13592 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
| 13593 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13594 | dispatchDraw(canvas); |
| 13595 | } else { |
| 13596 | draw(canvas); |
| 13597 | } |
| 13598 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13599 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 13600 | ((HardwareCanvas) canvas).drawDisplayList(displayList, null, flags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13601 | } |
| 13602 | } |
| 13603 | } else if (cache != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13604 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13605 | Paint cachePaint; |
| 13606 | |
| 13607 | if (layerType == LAYER_TYPE_NONE) { |
| 13608 | cachePaint = parent.mCachePaint; |
| 13609 | if (cachePaint == null) { |
| 13610 | cachePaint = new Paint(); |
| 13611 | cachePaint.setDither(false); |
| 13612 | parent.mCachePaint = cachePaint; |
| 13613 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13614 | if (alpha < 1) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13615 | cachePaint.setAlpha((int) (alpha * 255)); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13616 | parent.mGroupFlags |= ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
| 13617 | } else if ((flags & ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13618 | cachePaint.setAlpha(255); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13619 | parent.mGroupFlags &= ~ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13620 | } |
| 13621 | } else { |
| 13622 | cachePaint = mLayerPaint; |
| 13623 | cachePaint.setAlpha((int) (alpha * 255)); |
| 13624 | } |
| 13625 | canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint); |
| 13626 | } |
| 13627 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13628 | if (restoreTo >= 0) { |
| 13629 | canvas.restoreToCount(restoreTo); |
| 13630 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13631 | |
| 13632 | if (a != null && !more) { |
| 13633 | if (!hardwareAccelerated && !a.getFillAfter()) { |
| 13634 | onSetAlpha(255); |
| 13635 | } |
| 13636 | parent.finishAnimatingView(this, a); |
| 13637 | } |
| 13638 | |
| 13639 | if (more && hardwareAccelerated) { |
| 13640 | // invalidation is the trigger to recreate display lists, so if we're using |
| 13641 | // display lists to render, force an invalidate to allow the animation to |
| 13642 | // continue drawing another frame |
| 13643 | parent.invalidate(true); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13644 | if (a.hasAlpha() && (mPrivateFlags & PFLAG_ALPHA_SET) == PFLAG_ALPHA_SET) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13645 | // alpha animations should cause the child to recreate its display list |
| 13646 | invalidate(true); |
| 13647 | } |
| 13648 | } |
| 13649 | |
| 13650 | mRecreateDisplayList = false; |
| 13651 | |
| 13652 | return more; |
| 13653 | } |
| 13654 | |
| 13655 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13656 | * Manually render this view (and all of its children) to the given Canvas. |
| 13657 | * 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] | 13658 | * called. When implementing a view, implement |
| 13659 | * {@link #onDraw(android.graphics.Canvas)} instead of overriding this method. |
| 13660 | * 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] | 13661 | * |
| 13662 | * @param canvas The Canvas to which the View is rendered. |
| 13663 | */ |
| 13664 | public void draw(Canvas canvas) { |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13665 | final int privateFlags = mPrivateFlags; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13666 | final boolean dirtyOpaque = (privateFlags & PFLAG_DIRTY_MASK) == PFLAG_DIRTY_OPAQUE && |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13667 | (mAttachInfo == null || !mAttachInfo.mIgnoreDirtyState); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13668 | mPrivateFlags = (privateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DRAWN; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13670 | /* |
| 13671 | * Draw traversal performs several drawing steps which must be executed |
| 13672 | * in the appropriate order: |
| 13673 | * |
| 13674 | * 1. Draw the background |
| 13675 | * 2. If necessary, save the canvas' layers to prepare for fading |
| 13676 | * 3. Draw view's content |
| 13677 | * 4. Draw children |
| 13678 | * 5. If necessary, draw the fading edges and restore layers |
| 13679 | * 6. Draw decorations (scrollbars for instance) |
| 13680 | */ |
| 13681 | |
| 13682 | // Step 1, draw the background, if needed |
| 13683 | int saveCount; |
| 13684 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13685 | if (!dirtyOpaque) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13686 | final Drawable background = mBackground; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13687 | if (background != null) { |
| 13688 | final int scrollX = mScrollX; |
| 13689 | final int scrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13690 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13691 | if (mBackgroundSizeChanged) { |
| 13692 | background.setBounds(0, 0, mRight - mLeft, mBottom - mTop); |
| 13693 | mBackgroundSizeChanged = false; |
| 13694 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13695 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13696 | if ((scrollX | scrollY) == 0) { |
| 13697 | background.draw(canvas); |
| 13698 | } else { |
| 13699 | canvas.translate(scrollX, scrollY); |
| 13700 | background.draw(canvas); |
| 13701 | canvas.translate(-scrollX, -scrollY); |
| 13702 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13703 | } |
| 13704 | } |
| 13705 | |
| 13706 | // skip step 2 & 5 if possible (common case) |
| 13707 | final int viewFlags = mViewFlags; |
| 13708 | boolean horizontalEdges = (viewFlags & FADING_EDGE_HORIZONTAL) != 0; |
| 13709 | boolean verticalEdges = (viewFlags & FADING_EDGE_VERTICAL) != 0; |
| 13710 | if (!verticalEdges && !horizontalEdges) { |
| 13711 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13712 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13713 | |
| 13714 | // Step 4, draw the children |
| 13715 | dispatchDraw(canvas); |
| 13716 | |
| 13717 | // Step 6, draw decorations (scrollbars) |
| 13718 | onDrawScrollBars(canvas); |
| 13719 | |
| 13720 | // we're done... |
| 13721 | return; |
| 13722 | } |
| 13723 | |
| 13724 | /* |
| 13725 | * Here we do the full fledged routine... |
| 13726 | * (this is an uncommon case where speed matters less, |
| 13727 | * this is why we repeat some of the tests that have been |
| 13728 | * done above) |
| 13729 | */ |
| 13730 | |
| 13731 | boolean drawTop = false; |
| 13732 | boolean drawBottom = false; |
| 13733 | boolean drawLeft = false; |
| 13734 | boolean drawRight = false; |
| 13735 | |
| 13736 | float topFadeStrength = 0.0f; |
| 13737 | float bottomFadeStrength = 0.0f; |
| 13738 | float leftFadeStrength = 0.0f; |
| 13739 | float rightFadeStrength = 0.0f; |
| 13740 | |
| 13741 | // Step 2, save the canvas' layers |
| 13742 | int paddingLeft = mPaddingLeft; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13743 | |
| 13744 | final boolean offsetRequired = isPaddingOffsetRequired(); |
| 13745 | if (offsetRequired) { |
| 13746 | paddingLeft += getLeftPaddingOffset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13747 | } |
| 13748 | |
| 13749 | int left = mScrollX + paddingLeft; |
| 13750 | int right = left + mRight - mLeft - mPaddingRight - paddingLeft; |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13751 | int top = mScrollY + getFadeTop(offsetRequired); |
| 13752 | int bottom = top + getFadeHeight(offsetRequired); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13753 | |
| 13754 | if (offsetRequired) { |
| 13755 | right += getRightPaddingOffset(); |
| 13756 | bottom += getBottomPaddingOffset(); |
| 13757 | } |
| 13758 | |
| 13759 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13760 | final float fadeHeight = scrollabilityCache.fadingEdgeLength; |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13761 | int length = (int) fadeHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13762 | |
| 13763 | // clip the fade length if top and bottom fades overlap |
| 13764 | // overlapping fades produce odd-looking artifacts |
| 13765 | if (verticalEdges && (top + length > bottom - length)) { |
| 13766 | length = (bottom - top) / 2; |
| 13767 | } |
| 13768 | |
| 13769 | // also clip horizontal fades if necessary |
| 13770 | if (horizontalEdges && (left + length > right - length)) { |
| 13771 | length = (right - left) / 2; |
| 13772 | } |
| 13773 | |
| 13774 | if (verticalEdges) { |
| 13775 | topFadeStrength = Math.max(0.0f, Math.min(1.0f, getTopFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13776 | drawTop = topFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13777 | bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, getBottomFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13778 | drawBottom = bottomFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13779 | } |
| 13780 | |
| 13781 | if (horizontalEdges) { |
| 13782 | leftFadeStrength = Math.max(0.0f, Math.min(1.0f, getLeftFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13783 | drawLeft = leftFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13784 | rightFadeStrength = Math.max(0.0f, Math.min(1.0f, getRightFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13785 | drawRight = rightFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13786 | } |
| 13787 | |
| 13788 | saveCount = canvas.getSaveCount(); |
| 13789 | |
| 13790 | int solidColor = getSolidColor(); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 13791 | if (solidColor == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13792 | final int flags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
| 13793 | |
| 13794 | if (drawTop) { |
| 13795 | canvas.saveLayer(left, top, right, top + length, null, flags); |
| 13796 | } |
| 13797 | |
| 13798 | if (drawBottom) { |
| 13799 | canvas.saveLayer(left, bottom - length, right, bottom, null, flags); |
| 13800 | } |
| 13801 | |
| 13802 | if (drawLeft) { |
| 13803 | canvas.saveLayer(left, top, left + length, bottom, null, flags); |
| 13804 | } |
| 13805 | |
| 13806 | if (drawRight) { |
| 13807 | canvas.saveLayer(right - length, top, right, bottom, null, flags); |
| 13808 | } |
| 13809 | } else { |
| 13810 | scrollabilityCache.setFadeColor(solidColor); |
| 13811 | } |
| 13812 | |
| 13813 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13814 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13815 | |
| 13816 | // Step 4, draw the children |
| 13817 | dispatchDraw(canvas); |
| 13818 | |
| 13819 | // Step 5, draw the fade effect and restore layers |
| 13820 | final Paint p = scrollabilityCache.paint; |
| 13821 | final Matrix matrix = scrollabilityCache.matrix; |
| 13822 | final Shader fade = scrollabilityCache.shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13823 | |
| 13824 | if (drawTop) { |
| 13825 | matrix.setScale(1, fadeHeight * topFadeStrength); |
| 13826 | matrix.postTranslate(left, top); |
| 13827 | fade.setLocalMatrix(matrix); |
| 13828 | canvas.drawRect(left, top, right, top + length, p); |
| 13829 | } |
| 13830 | |
| 13831 | if (drawBottom) { |
| 13832 | matrix.setScale(1, fadeHeight * bottomFadeStrength); |
| 13833 | matrix.postRotate(180); |
| 13834 | matrix.postTranslate(left, bottom); |
| 13835 | fade.setLocalMatrix(matrix); |
| 13836 | canvas.drawRect(left, bottom - length, right, bottom, p); |
| 13837 | } |
| 13838 | |
| 13839 | if (drawLeft) { |
| 13840 | matrix.setScale(1, fadeHeight * leftFadeStrength); |
| 13841 | matrix.postRotate(-90); |
| 13842 | matrix.postTranslate(left, top); |
| 13843 | fade.setLocalMatrix(matrix); |
| 13844 | canvas.drawRect(left, top, left + length, bottom, p); |
| 13845 | } |
| 13846 | |
| 13847 | if (drawRight) { |
| 13848 | matrix.setScale(1, fadeHeight * rightFadeStrength); |
| 13849 | matrix.postRotate(90); |
| 13850 | matrix.postTranslate(right, top); |
| 13851 | fade.setLocalMatrix(matrix); |
| 13852 | canvas.drawRect(right - length, top, right, bottom, p); |
| 13853 | } |
| 13854 | |
| 13855 | canvas.restoreToCount(saveCount); |
| 13856 | |
| 13857 | // Step 6, draw decorations (scrollbars) |
| 13858 | onDrawScrollBars(canvas); |
| 13859 | } |
| 13860 | |
| 13861 | /** |
| 13862 | * Override this if your view is known to always be drawn on top of a solid color background, |
| 13863 | * and needs to draw fading edges. Returning a non-zero color enables the view system to |
| 13864 | * optimize the drawing of the fading edges. If you do return a non-zero color, the alpha |
| 13865 | * should be set to 0xFF. |
| 13866 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13867 | * @see #setVerticalFadingEdgeEnabled(boolean) |
| 13868 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13869 | * |
| 13870 | * @return The known solid color background for this view, or 0 if the color may vary |
| 13871 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13872 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13873 | public int getSolidColor() { |
| 13874 | return 0; |
| 13875 | } |
| 13876 | |
| 13877 | /** |
| 13878 | * Build a human readable string representation of the specified view flags. |
| 13879 | * |
| 13880 | * @param flags the view flags to convert to a string |
| 13881 | * @return a String representing the supplied flags |
| 13882 | */ |
| 13883 | private static String printFlags(int flags) { |
| 13884 | String output = ""; |
| 13885 | int numFlags = 0; |
| 13886 | if ((flags & FOCUSABLE_MASK) == FOCUSABLE) { |
| 13887 | output += "TAKES_FOCUS"; |
| 13888 | numFlags++; |
| 13889 | } |
| 13890 | |
| 13891 | switch (flags & VISIBILITY_MASK) { |
| 13892 | case INVISIBLE: |
| 13893 | if (numFlags > 0) { |
| 13894 | output += " "; |
| 13895 | } |
| 13896 | output += "INVISIBLE"; |
| 13897 | // USELESS HERE numFlags++; |
| 13898 | break; |
| 13899 | case GONE: |
| 13900 | if (numFlags > 0) { |
| 13901 | output += " "; |
| 13902 | } |
| 13903 | output += "GONE"; |
| 13904 | // USELESS HERE numFlags++; |
| 13905 | break; |
| 13906 | default: |
| 13907 | break; |
| 13908 | } |
| 13909 | return output; |
| 13910 | } |
| 13911 | |
| 13912 | /** |
| 13913 | * Build a human readable string representation of the specified private |
| 13914 | * view flags. |
| 13915 | * |
| 13916 | * @param privateFlags the private view flags to convert to a string |
| 13917 | * @return a String representing the supplied flags |
| 13918 | */ |
| 13919 | private static String printPrivateFlags(int privateFlags) { |
| 13920 | String output = ""; |
| 13921 | int numFlags = 0; |
| 13922 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13923 | if ((privateFlags & PFLAG_WANTS_FOCUS) == PFLAG_WANTS_FOCUS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13924 | output += "WANTS_FOCUS"; |
| 13925 | numFlags++; |
| 13926 | } |
| 13927 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13928 | if ((privateFlags & PFLAG_FOCUSED) == PFLAG_FOCUSED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13929 | if (numFlags > 0) { |
| 13930 | output += " "; |
| 13931 | } |
| 13932 | output += "FOCUSED"; |
| 13933 | numFlags++; |
| 13934 | } |
| 13935 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13936 | if ((privateFlags & PFLAG_SELECTED) == PFLAG_SELECTED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13937 | if (numFlags > 0) { |
| 13938 | output += " "; |
| 13939 | } |
| 13940 | output += "SELECTED"; |
| 13941 | numFlags++; |
| 13942 | } |
| 13943 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13944 | if ((privateFlags & PFLAG_IS_ROOT_NAMESPACE) == PFLAG_IS_ROOT_NAMESPACE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13945 | if (numFlags > 0) { |
| 13946 | output += " "; |
| 13947 | } |
| 13948 | output += "IS_ROOT_NAMESPACE"; |
| 13949 | numFlags++; |
| 13950 | } |
| 13951 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13952 | if ((privateFlags & PFLAG_HAS_BOUNDS) == PFLAG_HAS_BOUNDS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13953 | if (numFlags > 0) { |
| 13954 | output += " "; |
| 13955 | } |
| 13956 | output += "HAS_BOUNDS"; |
| 13957 | numFlags++; |
| 13958 | } |
| 13959 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13960 | if ((privateFlags & PFLAG_DRAWN) == PFLAG_DRAWN) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13961 | if (numFlags > 0) { |
| 13962 | output += " "; |
| 13963 | } |
| 13964 | output += "DRAWN"; |
| 13965 | // USELESS HERE numFlags++; |
| 13966 | } |
| 13967 | return output; |
| 13968 | } |
| 13969 | |
| 13970 | /** |
| 13971 | * <p>Indicates whether or not this view's layout will be requested during |
| 13972 | * the next hierarchy layout pass.</p> |
| 13973 | * |
| 13974 | * @return true if the layout will be forced during next layout pass |
| 13975 | */ |
| 13976 | public boolean isLayoutRequested() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13977 | return (mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13978 | } |
| 13979 | |
| 13980 | /** |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 13981 | * Return true if o is a ViewGroup that is laying out using optical bounds. |
| 13982 | * @hide |
| 13983 | */ |
| 13984 | public static boolean isLayoutModeOptical(Object o) { |
| 13985 | return o instanceof ViewGroup && ((ViewGroup) o).isLayoutModeOptical(); |
| 13986 | } |
| 13987 | |
| 13988 | private boolean setOpticalFrame(int left, int top, int right, int bottom) { |
| 13989 | Insets parentInsets = mParent instanceof View ? |
| 13990 | ((View) mParent).getOpticalInsets() : Insets.NONE; |
| 13991 | Insets childInsets = getOpticalInsets(); |
| 13992 | return setFrame( |
| 13993 | left + parentInsets.left - childInsets.left, |
| 13994 | top + parentInsets.top - childInsets.top, |
| 13995 | right + parentInsets.left + childInsets.right, |
| 13996 | bottom + parentInsets.top + childInsets.bottom); |
| 13997 | } |
| 13998 | |
| 13999 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14000 | * Assign a size and position to a view and all of its |
| 14001 | * descendants |
| 14002 | * |
| 14003 | * <p>This is the second phase of the layout mechanism. |
| 14004 | * (The first is measuring). In this phase, each parent calls |
| 14005 | * layout on all of its children to position them. |
| 14006 | * This is typically done using the child measurements |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 14007 | * that were stored in the measure pass().</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14008 | * |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 14009 | * <p>Derived classes should not override this method. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14010 | * Derived classes with children should override |
| 14011 | * onLayout. In that method, they should |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 14012 | * call layout on each of their children.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14013 | * |
| 14014 | * @param l Left position, relative to parent |
| 14015 | * @param t Top position, relative to parent |
| 14016 | * @param r Right position, relative to parent |
| 14017 | * @param b Bottom position, relative to parent |
| 14018 | */ |
Romain Guy | 5429e1d | 2010-09-07 12:38:00 -0700 | [diff] [blame] | 14019 | @SuppressWarnings({"unchecked"}) |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 14020 | public void layout(int l, int t, int r, int b) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 14021 | int oldL = mLeft; |
| 14022 | int oldT = mTop; |
| 14023 | int oldB = mBottom; |
| 14024 | int oldR = mRight; |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 14025 | boolean changed = isLayoutModeOptical(mParent) ? |
| 14026 | setOpticalFrame(l, t, r, b) : setFrame(l, t, r, b); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14027 | if (changed || (mPrivateFlags & PFLAG_LAYOUT_REQUIRED) == PFLAG_LAYOUT_REQUIRED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14028 | onLayout(changed, l, t, r, b); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14029 | mPrivateFlags &= ~PFLAG_LAYOUT_REQUIRED; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 14030 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 14031 | ListenerInfo li = mListenerInfo; |
| 14032 | if (li != null && li.mOnLayoutChangeListeners != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 14033 | ArrayList<OnLayoutChangeListener> listenersCopy = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 14034 | (ArrayList<OnLayoutChangeListener>)li.mOnLayoutChangeListeners.clone(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 14035 | int numListeners = listenersCopy.size(); |
| 14036 | for (int i = 0; i < numListeners; ++i) { |
Chet Haase | 7c608f2 | 2010-10-22 17:54:04 -0700 | [diff] [blame] | 14037 | 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] | 14038 | } |
| 14039 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14040 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14041 | mPrivateFlags &= ~PFLAG_FORCE_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14042 | } |
| 14043 | |
| 14044 | /** |
| 14045 | * Called from layout when this view should |
| 14046 | * assign a size and position to each of its children. |
| 14047 | * |
| 14048 | * Derived classes with children should override |
| 14049 | * this method and call layout on each of |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 14050 | * their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14051 | * @param changed This is a new size or position for this view |
| 14052 | * @param left Left position, relative to parent |
| 14053 | * @param top Top position, relative to parent |
| 14054 | * @param right Right position, relative to parent |
| 14055 | * @param bottom Bottom position, relative to parent |
| 14056 | */ |
| 14057 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 14058 | } |
| 14059 | |
| 14060 | /** |
| 14061 | * Assign a size and position to this view. |
| 14062 | * |
| 14063 | * This is called from layout. |
| 14064 | * |
| 14065 | * @param left Left position, relative to parent |
| 14066 | * @param top Top position, relative to parent |
| 14067 | * @param right Right position, relative to parent |
| 14068 | * @param bottom Bottom position, relative to parent |
| 14069 | * @return true if the new size and position are different than the |
| 14070 | * previous ones |
| 14071 | * {@hide} |
| 14072 | */ |
| 14073 | protected boolean setFrame(int left, int top, int right, int bottom) { |
| 14074 | boolean changed = false; |
| 14075 | |
| 14076 | if (DBG) { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 14077 | Log.d("View", this + " View.setFrame(" + left + "," + top + "," |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14078 | + right + "," + bottom + ")"); |
| 14079 | } |
| 14080 | |
| 14081 | if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) { |
| 14082 | changed = true; |
| 14083 | |
| 14084 | // Remember our drawn bit |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14085 | int drawn = mPrivateFlags & PFLAG_DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14086 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14087 | int oldWidth = mRight - mLeft; |
| 14088 | int oldHeight = mBottom - mTop; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 14089 | int newWidth = right - left; |
| 14090 | int newHeight = bottom - top; |
| 14091 | boolean sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight); |
| 14092 | |
| 14093 | // Invalidate our old position |
| 14094 | invalidate(sizeChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14095 | |
| 14096 | mLeft = left; |
| 14097 | mTop = top; |
| 14098 | mRight = right; |
| 14099 | mBottom = bottom; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 14100 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 14101 | mDisplayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
| 14102 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14103 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14104 | mPrivateFlags |= PFLAG_HAS_BOUNDS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14106 | |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 14107 | if (sizeChanged) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14108 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 14109 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 14110 | if (mTransformationInfo != null) { |
| 14111 | mTransformationInfo.mMatrixDirty = true; |
| 14112 | } |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 14113 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14114 | onSizeChanged(newWidth, newHeight, oldWidth, oldHeight); |
| 14115 | } |
| 14116 | |
| 14117 | if ((mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 14118 | // If we are visible, force the DRAWN bit to on so that |
| 14119 | // this invalidate will go through (at least to our parent). |
| 14120 | // This is because someone may have invalidated this view |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 14121 | // before this call to setFrame came in, thereby clearing |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14122 | // the DRAWN bit. |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14123 | mPrivateFlags |= PFLAG_DRAWN; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 14124 | invalidate(sizeChanged); |
Chet Haase | f28595e | 2011-01-31 18:52:12 -0800 | [diff] [blame] | 14125 | // parent display list may need to be recreated based on a change in the bounds |
| 14126 | // of any child |
| 14127 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14128 | } |
| 14129 | |
| 14130 | // Reset drawn bit to original value (invalidate turns it off) |
| 14131 | mPrivateFlags |= drawn; |
| 14132 | |
| 14133 | mBackgroundSizeChanged = true; |
| 14134 | } |
| 14135 | return changed; |
| 14136 | } |
| 14137 | |
| 14138 | /** |
| 14139 | * Finalize inflating a view from XML. This is called as the last phase |
| 14140 | * of inflation, after all child views have been added. |
| 14141 | * |
| 14142 | * <p>Even if the subclass overrides onFinishInflate, they should always be |
| 14143 | * sure to call the super method, so that we get called. |
| 14144 | */ |
| 14145 | protected void onFinishInflate() { |
| 14146 | } |
| 14147 | |
| 14148 | /** |
| 14149 | * Returns the resources associated with this view. |
| 14150 | * |
| 14151 | * @return Resources object. |
| 14152 | */ |
| 14153 | public Resources getResources() { |
| 14154 | return mResources; |
| 14155 | } |
| 14156 | |
| 14157 | /** |
| 14158 | * Invalidates the specified Drawable. |
| 14159 | * |
| 14160 | * @param drawable the drawable to invalidate |
| 14161 | */ |
| 14162 | public void invalidateDrawable(Drawable drawable) { |
| 14163 | if (verifyDrawable(drawable)) { |
| 14164 | final Rect dirty = drawable.getBounds(); |
| 14165 | final int scrollX = mScrollX; |
| 14166 | final int scrollY = mScrollY; |
| 14167 | |
| 14168 | invalidate(dirty.left + scrollX, dirty.top + scrollY, |
| 14169 | dirty.right + scrollX, dirty.bottom + scrollY); |
| 14170 | } |
| 14171 | } |
| 14172 | |
| 14173 | /** |
| 14174 | * Schedules an action on a drawable to occur at a specified time. |
| 14175 | * |
| 14176 | * @param who the recipient of the action |
| 14177 | * @param what the action to run on the drawable |
| 14178 | * @param when the time at which the action must occur. Uses the |
| 14179 | * {@link SystemClock#uptimeMillis} timebase. |
| 14180 | */ |
| 14181 | public void scheduleDrawable(Drawable who, Runnable what, long when) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14182 | if (verifyDrawable(who) && what != null) { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 14183 | final long delay = when - SystemClock.uptimeMillis(); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14184 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 14185 | mAttachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 14186 | Choreographer.CALLBACK_ANIMATION, what, who, |
| 14187 | Choreographer.subtractFrameDelay(delay)); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14188 | } else { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 14189 | ViewRootImpl.getRunQueue().postDelayed(what, delay); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14190 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14191 | } |
| 14192 | } |
| 14193 | |
| 14194 | /** |
| 14195 | * Cancels a scheduled action on a drawable. |
| 14196 | * |
| 14197 | * @param who the recipient of the action |
| 14198 | * @param what the action to cancel |
| 14199 | */ |
| 14200 | public void unscheduleDrawable(Drawable who, Runnable what) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14201 | if (verifyDrawable(who) && what != null) { |
| 14202 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 14203 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 14204 | Choreographer.CALLBACK_ANIMATION, what, who); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14205 | } else { |
| 14206 | ViewRootImpl.getRunQueue().removeCallbacks(what); |
| 14207 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14208 | } |
| 14209 | } |
| 14210 | |
| 14211 | /** |
| 14212 | * Unschedule any events associated with the given Drawable. This can be |
| 14213 | * used when selecting a new Drawable into a view, so that the previous |
| 14214 | * one is completely unscheduled. |
| 14215 | * |
| 14216 | * @param who The Drawable to unschedule. |
| 14217 | * |
| 14218 | * @see #drawableStateChanged |
| 14219 | */ |
| 14220 | public void unscheduleDrawable(Drawable who) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 14221 | if (mAttachInfo != null && who != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 14222 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 14223 | Choreographer.CALLBACK_ANIMATION, null, who); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14224 | } |
| 14225 | } |
| 14226 | |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 14227 | /** |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14228 | * Resolve the Drawables depending on the layout direction. This is implicitly supposing |
| 14229 | * that the View directionality can and will be resolved before its Drawables. |
| 14230 | * |
| 14231 | * Will call {@link View#onResolveDrawables} when resolution is done. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14232 | * |
| 14233 | * @hide |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14234 | */ |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 14235 | protected void resolveDrawables() { |
Fabrice Di Meglio | 1957d28 | 2012-10-25 17:42:39 -0700 | [diff] [blame] | 14236 | if (canResolveLayoutDirection()) { |
| 14237 | if (mBackground != null) { |
| 14238 | mBackground.setLayoutDirection(getLayoutDirection()); |
| 14239 | } |
| 14240 | mPrivateFlags2 |= PFLAG2_DRAWABLE_RESOLVED; |
| 14241 | onResolveDrawables(getLayoutDirection()); |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14242 | } |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14243 | } |
| 14244 | |
| 14245 | /** |
| 14246 | * Called when layout direction has been resolved. |
| 14247 | * |
| 14248 | * The default implementation does nothing. |
| 14249 | * |
| 14250 | * @param layoutDirection The resolved layout direction. |
| 14251 | * |
Fabrice Di Meglio | 49b0a9b | 2012-09-18 12:06:13 -0700 | [diff] [blame] | 14252 | * @see #LAYOUT_DIRECTION_LTR |
| 14253 | * @see #LAYOUT_DIRECTION_RTL |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14254 | * |
| 14255 | * @hide |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14256 | */ |
| 14257 | public void onResolveDrawables(int layoutDirection) { |
Fabrice Di Meglio | 6a03640 | 2011-05-23 14:43:23 -0700 | [diff] [blame] | 14258 | } |
| 14259 | |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 14260 | /** |
| 14261 | * @hide |
| 14262 | */ |
| 14263 | protected void resetResolvedDrawables() { |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 14264 | mPrivateFlags2 &= ~PFLAG2_DRAWABLE_RESOLVED; |
| 14265 | } |
| 14266 | |
| 14267 | private boolean isDrawablesResolved() { |
| 14268 | return (mPrivateFlags2 & PFLAG2_DRAWABLE_RESOLVED) == PFLAG2_DRAWABLE_RESOLVED; |
| 14269 | } |
| 14270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14271 | /** |
| 14272 | * If your view subclass is displaying its own Drawable objects, it should |
| 14273 | * override this function and return true for any Drawable it is |
| 14274 | * displaying. This allows animations for those drawables to be |
| 14275 | * scheduled. |
| 14276 | * |
| 14277 | * <p>Be sure to call through to the super class when overriding this |
| 14278 | * function. |
| 14279 | * |
| 14280 | * @param who The Drawable to verify. Return true if it is one you are |
| 14281 | * displaying, else return the result of calling through to the |
| 14282 | * super class. |
| 14283 | * |
| 14284 | * @return boolean If true than the Drawable is being displayed in the |
| 14285 | * view; else false and it is not allowed to animate. |
| 14286 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14287 | * @see #unscheduleDrawable(android.graphics.drawable.Drawable) |
| 14288 | * @see #drawableStateChanged() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14289 | */ |
| 14290 | protected boolean verifyDrawable(Drawable who) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14291 | return who == mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14292 | } |
| 14293 | |
| 14294 | /** |
| 14295 | * This function is called whenever the state of the view changes in such |
| 14296 | * a way that it impacts the state of drawables being shown. |
| 14297 | * |
| 14298 | * <p>Be sure to call through to the superclass when overriding this |
| 14299 | * function. |
| 14300 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14301 | * @see Drawable#setState(int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14302 | */ |
| 14303 | protected void drawableStateChanged() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14304 | Drawable d = mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14305 | if (d != null && d.isStateful()) { |
| 14306 | d.setState(getDrawableState()); |
| 14307 | } |
| 14308 | } |
| 14309 | |
| 14310 | /** |
| 14311 | * Call this to force a view to update its drawable state. This will cause |
| 14312 | * drawableStateChanged to be called on this view. Views that are interested |
| 14313 | * in the new state should call getDrawableState. |
| 14314 | * |
| 14315 | * @see #drawableStateChanged |
| 14316 | * @see #getDrawableState |
| 14317 | */ |
| 14318 | public void refreshDrawableState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14319 | mPrivateFlags |= PFLAG_DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14320 | drawableStateChanged(); |
| 14321 | |
| 14322 | ViewParent parent = mParent; |
| 14323 | if (parent != null) { |
| 14324 | parent.childDrawableStateChanged(this); |
| 14325 | } |
| 14326 | } |
| 14327 | |
| 14328 | /** |
| 14329 | * Return an array of resource IDs of the drawable states representing the |
| 14330 | * current state of the view. |
| 14331 | * |
| 14332 | * @return The current drawable state |
| 14333 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14334 | * @see Drawable#setState(int[]) |
| 14335 | * @see #drawableStateChanged() |
| 14336 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14337 | */ |
| 14338 | public final int[] getDrawableState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14339 | if ((mDrawableState != null) && ((mPrivateFlags & PFLAG_DRAWABLE_STATE_DIRTY) == 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14340 | return mDrawableState; |
| 14341 | } else { |
| 14342 | mDrawableState = onCreateDrawableState(0); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14343 | mPrivateFlags &= ~PFLAG_DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14344 | return mDrawableState; |
| 14345 | } |
| 14346 | } |
| 14347 | |
| 14348 | /** |
| 14349 | * Generate the new {@link android.graphics.drawable.Drawable} state for |
| 14350 | * this view. This is called by the view |
| 14351 | * system when the cached Drawable state is determined to be invalid. To |
| 14352 | * retrieve the current state, you should use {@link #getDrawableState}. |
| 14353 | * |
| 14354 | * @param extraSpace if non-zero, this is the number of extra entries you |
| 14355 | * would like in the returned array in which you can place your own |
| 14356 | * states. |
| 14357 | * |
| 14358 | * @return Returns an array holding the current {@link Drawable} state of |
| 14359 | * the view. |
| 14360 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14361 | * @see #mergeDrawableStates(int[], int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14362 | */ |
| 14363 | protected int[] onCreateDrawableState(int extraSpace) { |
| 14364 | if ((mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE && |
| 14365 | mParent instanceof View) { |
| 14366 | return ((View) mParent).onCreateDrawableState(extraSpace); |
| 14367 | } |
| 14368 | |
| 14369 | int[] drawableState; |
| 14370 | |
| 14371 | int privateFlags = mPrivateFlags; |
| 14372 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14373 | int viewStateIndex = 0; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14374 | if ((privateFlags & PFLAG_PRESSED) != 0) viewStateIndex |= VIEW_STATE_PRESSED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14375 | if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= VIEW_STATE_ENABLED; |
| 14376 | if (isFocused()) viewStateIndex |= VIEW_STATE_FOCUSED; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14377 | if ((privateFlags & PFLAG_SELECTED) != 0) viewStateIndex |= VIEW_STATE_SELECTED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14378 | if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14379 | if ((privateFlags & PFLAG_ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED; |
Adam Powell | 5a7e94e | 2011-04-25 15:30:43 -0700 | [diff] [blame] | 14380 | if (mAttachInfo != null && mAttachInfo.mHardwareAccelerationRequested && |
| 14381 | HardwareRenderer.isAvailable()) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 14382 | // This is set if HW acceleration is requested, even if the current |
| 14383 | // process doesn't allow it. This is just to allow app preview |
| 14384 | // windows to better match their app. |
| 14385 | viewStateIndex |= VIEW_STATE_ACCELERATED; |
| 14386 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14387 | if ((privateFlags & PFLAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_HOVERED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14388 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 14389 | final int privateFlags2 = mPrivateFlags2; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14390 | if ((privateFlags2 & PFLAG2_DRAG_CAN_ACCEPT) != 0) viewStateIndex |= VIEW_STATE_DRAG_CAN_ACCEPT; |
| 14391 | if ((privateFlags2 & PFLAG2_DRAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_DRAG_HOVERED; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 14392 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14393 | drawableState = VIEW_STATE_SETS[viewStateIndex]; |
| 14394 | |
| 14395 | //noinspection ConstantIfStatement |
| 14396 | if (false) { |
| 14397 | Log.i("View", "drawableStateIndex=" + viewStateIndex); |
| 14398 | Log.i("View", toString() |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14399 | + " pressed=" + ((privateFlags & PFLAG_PRESSED) != 0) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14400 | + " en=" + ((mViewFlags & ENABLED_MASK) == ENABLED) |
| 14401 | + " fo=" + hasFocus() |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14402 | + " sl=" + ((privateFlags & PFLAG_SELECTED) != 0) |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14403 | + " wf=" + hasWindowFocus() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14404 | + ": " + Arrays.toString(drawableState)); |
| 14405 | } |
| 14406 | |
| 14407 | if (extraSpace == 0) { |
| 14408 | return drawableState; |
| 14409 | } |
| 14410 | |
| 14411 | final int[] fullState; |
| 14412 | if (drawableState != null) { |
| 14413 | fullState = new int[drawableState.length + extraSpace]; |
| 14414 | System.arraycopy(drawableState, 0, fullState, 0, drawableState.length); |
| 14415 | } else { |
| 14416 | fullState = new int[extraSpace]; |
| 14417 | } |
| 14418 | |
| 14419 | return fullState; |
| 14420 | } |
| 14421 | |
| 14422 | /** |
| 14423 | * Merge your own state values in <var>additionalState</var> into the base |
| 14424 | * state values <var>baseState</var> that were returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14425 | * {@link #onCreateDrawableState(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14426 | * |
| 14427 | * @param baseState The base state values returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14428 | * {@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] | 14429 | * own additional state values. |
| 14430 | * |
| 14431 | * @param additionalState The additional state values you would like |
| 14432 | * added to <var>baseState</var>; this array is not modified. |
| 14433 | * |
| 14434 | * @return As a convenience, the <var>baseState</var> array you originally |
| 14435 | * passed into the function is returned. |
| 14436 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14437 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14438 | */ |
| 14439 | protected static int[] mergeDrawableStates(int[] baseState, int[] additionalState) { |
| 14440 | final int N = baseState.length; |
| 14441 | int i = N - 1; |
| 14442 | while (i >= 0 && baseState[i] == 0) { |
| 14443 | i--; |
| 14444 | } |
| 14445 | System.arraycopy(additionalState, 0, baseState, i + 1, additionalState.length); |
| 14446 | return baseState; |
| 14447 | } |
| 14448 | |
| 14449 | /** |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 14450 | * Call {@link Drawable#jumpToCurrentState() Drawable.jumpToCurrentState()} |
| 14451 | * on all Drawable objects associated with this view. |
| 14452 | */ |
| 14453 | public void jumpDrawablesToCurrentState() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14454 | if (mBackground != null) { |
| 14455 | mBackground.jumpToCurrentState(); |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 14456 | } |
| 14457 | } |
| 14458 | |
| 14459 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14460 | * Sets the background color for this view. |
| 14461 | * @param color the color of the background |
| 14462 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 14463 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14464 | public void setBackgroundColor(int color) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14465 | if (mBackground instanceof ColorDrawable) { |
Romain Guy | 5f49c30 | 2012-09-06 16:33:31 -0700 | [diff] [blame] | 14466 | ((ColorDrawable) mBackground.mutate()).setColor(color); |
Romain Guy | 7d3082a | 2012-07-11 17:52:54 -0700 | [diff] [blame] | 14467 | computeOpaqueFlags(); |
Romain Guy | f6ae4b8 | 2012-11-27 13:57:27 -0800 | [diff] [blame] | 14468 | mBackgroundResource = 0; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 14469 | } else { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14470 | setBackground(new ColorDrawable(color)); |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 14471 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14472 | } |
| 14473 | |
| 14474 | /** |
| 14475 | * Set the background to a given resource. The resource should refer to |
Wink Saville | 7cd88e1 | 2009-08-04 14:45:10 -0700 | [diff] [blame] | 14476 | * a Drawable object or 0 to remove the background. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14477 | * @param resid The identifier of the resource. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14478 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14479 | * @attr ref android.R.styleable#View_background |
| 14480 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 14481 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14482 | public void setBackgroundResource(int resid) { |
| 14483 | if (resid != 0 && resid == mBackgroundResource) { |
| 14484 | return; |
| 14485 | } |
| 14486 | |
| 14487 | Drawable d= null; |
| 14488 | if (resid != 0) { |
| 14489 | d = mResources.getDrawable(resid); |
| 14490 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14491 | setBackground(d); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14492 | |
| 14493 | mBackgroundResource = resid; |
| 14494 | } |
| 14495 | |
| 14496 | /** |
| 14497 | * Set the background to a given Drawable, or remove the background. If the |
| 14498 | * background has padding, this View's padding is set to the background's |
| 14499 | * padding. However, when a background is removed, this View's padding isn't |
| 14500 | * touched. If setting the padding is desired, please use |
| 14501 | * {@link #setPadding(int, int, int, int)}. |
| 14502 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14503 | * @param background The Drawable to use as the background, or null to remove the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14504 | * background |
| 14505 | */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14506 | public void setBackground(Drawable background) { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 14507 | //noinspection deprecation |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14508 | setBackgroundDrawable(background); |
| 14509 | } |
| 14510 | |
| 14511 | /** |
| 14512 | * @deprecated use {@link #setBackground(Drawable)} instead |
| 14513 | */ |
| 14514 | @Deprecated |
| 14515 | public void setBackgroundDrawable(Drawable background) { |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 14516 | computeOpaqueFlags(); |
| 14517 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14518 | if (background == mBackground) { |
Adam Powell | 4d36ec1 | 2011-07-17 16:44:16 -0700 | [diff] [blame] | 14519 | return; |
| 14520 | } |
| 14521 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14522 | boolean requestLayout = false; |
| 14523 | |
| 14524 | mBackgroundResource = 0; |
| 14525 | |
| 14526 | /* |
| 14527 | * Regardless of whether we're setting a new background or not, we want |
| 14528 | * to clear the previous drawable. |
| 14529 | */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14530 | if (mBackground != null) { |
| 14531 | mBackground.setCallback(null); |
| 14532 | unscheduleDrawable(mBackground); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14533 | } |
| 14534 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14535 | if (background != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14536 | Rect padding = sThreadLocal.get(); |
| 14537 | if (padding == null) { |
| 14538 | padding = new Rect(); |
| 14539 | sThreadLocal.set(padding); |
| 14540 | } |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 14541 | resetResolvedDrawables(); |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 14542 | background.setLayoutDirection(getLayoutDirection()); |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14543 | if (background.getPadding(padding)) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14544 | resetResolvedPadding(); |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14545 | switch (background.getLayoutDirection()) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14546 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14547 | mUserPaddingLeftInitial = padding.right; |
| 14548 | mUserPaddingRightInitial = padding.left; |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14549 | internalSetPadding(padding.right, padding.top, padding.left, padding.bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14550 | break; |
| 14551 | case LAYOUT_DIRECTION_LTR: |
| 14552 | default: |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14553 | mUserPaddingLeftInitial = padding.left; |
| 14554 | mUserPaddingRightInitial = padding.right; |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14555 | internalSetPadding(padding.left, padding.top, padding.right, padding.bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14556 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14557 | } |
| 14558 | |
| 14559 | // Compare the minimum sizes of the old Drawable and the new. If there isn't an old or |
| 14560 | // if it has a different minimum size, we should layout again |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14561 | if (mBackground == null || mBackground.getMinimumHeight() != background.getMinimumHeight() || |
| 14562 | mBackground.getMinimumWidth() != background.getMinimumWidth()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14563 | requestLayout = true; |
| 14564 | } |
| 14565 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14566 | background.setCallback(this); |
| 14567 | if (background.isStateful()) { |
| 14568 | background.setState(getDrawableState()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14569 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14570 | background.setVisible(getVisibility() == VISIBLE, false); |
| 14571 | mBackground = background; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14572 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14573 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) != 0) { |
| 14574 | mPrivateFlags &= ~PFLAG_SKIP_DRAW; |
| 14575 | mPrivateFlags |= PFLAG_ONLY_DRAWS_BACKGROUND; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14576 | requestLayout = true; |
| 14577 | } |
| 14578 | } else { |
| 14579 | /* Remove the background */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14580 | mBackground = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14581 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14582 | if ((mPrivateFlags & PFLAG_ONLY_DRAWS_BACKGROUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14583 | /* |
| 14584 | * This view ONLY drew the background before and we're removing |
| 14585 | * the background, so now it won't draw anything |
| 14586 | * (hence we SKIP_DRAW) |
| 14587 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14588 | mPrivateFlags &= ~PFLAG_ONLY_DRAWS_BACKGROUND; |
| 14589 | mPrivateFlags |= PFLAG_SKIP_DRAW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14590 | } |
| 14591 | |
| 14592 | /* |
| 14593 | * When the background is set, we try to apply its padding to this |
| 14594 | * View. When the background is removed, we don't touch this View's |
| 14595 | * padding. This is noted in the Javadocs. Hence, we don't need to |
| 14596 | * requestLayout(), the invalidate() below is sufficient. |
| 14597 | */ |
| 14598 | |
| 14599 | // The old background's minimum size could have affected this |
| 14600 | // View's layout, so let's requestLayout |
| 14601 | requestLayout = true; |
| 14602 | } |
| 14603 | |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 14604 | computeOpaqueFlags(); |
| 14605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14606 | if (requestLayout) { |
| 14607 | requestLayout(); |
| 14608 | } |
| 14609 | |
| 14610 | mBackgroundSizeChanged = true; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14611 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14612 | } |
| 14613 | |
| 14614 | /** |
| 14615 | * Gets the background drawable |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14616 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14617 | * @return The drawable used as the background for this view, if any. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14618 | * |
| 14619 | * @see #setBackground(Drawable) |
| 14620 | * |
| 14621 | * @attr ref android.R.styleable#View_background |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14622 | */ |
| 14623 | public Drawable getBackground() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14624 | return mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14625 | } |
| 14626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14627 | /** |
| 14628 | * Sets the padding. The view may add on the space required to display |
| 14629 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 14630 | * So the values returned from {@link #getPaddingLeft}, {@link #getPaddingTop}, |
| 14631 | * {@link #getPaddingRight} and {@link #getPaddingBottom} may be different |
| 14632 | * from the values set in this call. |
| 14633 | * |
| 14634 | * @attr ref android.R.styleable#View_padding |
| 14635 | * @attr ref android.R.styleable#View_paddingBottom |
| 14636 | * @attr ref android.R.styleable#View_paddingLeft |
| 14637 | * @attr ref android.R.styleable#View_paddingRight |
| 14638 | * @attr ref android.R.styleable#View_paddingTop |
| 14639 | * @param left the left padding in pixels |
| 14640 | * @param top the top padding in pixels |
| 14641 | * @param right the right padding in pixels |
| 14642 | * @param bottom the bottom padding in pixels |
| 14643 | */ |
| 14644 | public void setPadding(int left, int top, int right, int bottom) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14645 | resetResolvedPadding(); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14646 | |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14647 | mUserPaddingStart = UNDEFINED_PADDING; |
| 14648 | mUserPaddingEnd = UNDEFINED_PADDING; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14649 | |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14650 | mUserPaddingLeftInitial = left; |
| 14651 | mUserPaddingRightInitial = right; |
| 14652 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14653 | internalSetPadding(left, top, right, bottom); |
| 14654 | } |
| 14655 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14656 | /** |
| 14657 | * @hide |
| 14658 | */ |
| 14659 | protected void internalSetPadding(int left, int top, int right, int bottom) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14660 | mUserPaddingLeft = left; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14661 | mUserPaddingRight = right; |
| 14662 | mUserPaddingBottom = bottom; |
| 14663 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14664 | final int viewFlags = mViewFlags; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14665 | boolean changed = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14666 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14667 | // Common case is there are no scroll bars. |
| 14668 | if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14669 | if ((viewFlags & SCROLLBARS_VERTICAL) != 0) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14670 | final int offset = (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14671 | ? 0 : getVerticalScrollbarWidth(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14672 | switch (mVerticalScrollbarPosition) { |
| 14673 | case SCROLLBAR_POSITION_DEFAULT: |
Fabrice Di Meglio | c91b6ca | 2012-06-22 14:51:15 -0700 | [diff] [blame] | 14674 | if (isLayoutRtl()) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14675 | left += offset; |
| 14676 | } else { |
| 14677 | right += offset; |
| 14678 | } |
| 14679 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14680 | case SCROLLBAR_POSITION_RIGHT: |
| 14681 | right += offset; |
| 14682 | break; |
| 14683 | case SCROLLBAR_POSITION_LEFT: |
| 14684 | left += offset; |
| 14685 | break; |
| 14686 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14687 | } |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14688 | if ((viewFlags & SCROLLBARS_HORIZONTAL) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14689 | bottom += (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
| 14690 | ? 0 : getHorizontalScrollbarHeight(); |
| 14691 | } |
| 14692 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14693 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14694 | if (mPaddingLeft != left) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14695 | changed = true; |
| 14696 | mPaddingLeft = left; |
| 14697 | } |
| 14698 | if (mPaddingTop != top) { |
| 14699 | changed = true; |
| 14700 | mPaddingTop = top; |
| 14701 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14702 | if (mPaddingRight != right) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14703 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14704 | mPaddingRight = right; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14705 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14706 | if (mPaddingBottom != bottom) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14707 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14708 | mPaddingBottom = bottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14709 | } |
| 14710 | |
| 14711 | if (changed) { |
| 14712 | requestLayout(); |
| 14713 | } |
| 14714 | } |
| 14715 | |
| 14716 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14717 | * Sets the relative padding. The view may add on the space required to display |
| 14718 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 14719 | * So the values returned from {@link #getPaddingStart}, {@link #getPaddingTop}, |
| 14720 | * {@link #getPaddingEnd} and {@link #getPaddingBottom} may be different |
| 14721 | * from the values set in this call. |
| 14722 | * |
| 14723 | * @attr ref android.R.styleable#View_padding |
| 14724 | * @attr ref android.R.styleable#View_paddingBottom |
| 14725 | * @attr ref android.R.styleable#View_paddingStart |
| 14726 | * @attr ref android.R.styleable#View_paddingEnd |
| 14727 | * @attr ref android.R.styleable#View_paddingTop |
| 14728 | * @param start the start padding in pixels |
| 14729 | * @param top the top padding in pixels |
| 14730 | * @param end the end padding in pixels |
| 14731 | * @param bottom the bottom padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14732 | */ |
| 14733 | public void setPaddingRelative(int start, int top, int end, int bottom) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14734 | resetResolvedPadding(); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14735 | |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 14736 | mUserPaddingStart = start; |
| 14737 | mUserPaddingEnd = end; |
| 14738 | |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 14739 | switch(getLayoutDirection()) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14740 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14741 | mUserPaddingLeftInitial = end; |
| 14742 | mUserPaddingRightInitial = start; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14743 | internalSetPadding(end, top, start, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14744 | break; |
| 14745 | case LAYOUT_DIRECTION_LTR: |
| 14746 | default: |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14747 | mUserPaddingLeftInitial = start; |
| 14748 | mUserPaddingRightInitial = end; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14749 | internalSetPadding(start, top, end, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14750 | } |
| 14751 | } |
| 14752 | |
| 14753 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14754 | * Returns the top padding of this view. |
| 14755 | * |
| 14756 | * @return the top padding in pixels |
| 14757 | */ |
| 14758 | public int getPaddingTop() { |
| 14759 | return mPaddingTop; |
| 14760 | } |
| 14761 | |
| 14762 | /** |
| 14763 | * Returns the bottom padding of this view. If there are inset and enabled |
| 14764 | * scrollbars, this value may include the space required to display the |
| 14765 | * scrollbars as well. |
| 14766 | * |
| 14767 | * @return the bottom padding in pixels |
| 14768 | */ |
| 14769 | public int getPaddingBottom() { |
| 14770 | return mPaddingBottom; |
| 14771 | } |
| 14772 | |
| 14773 | /** |
| 14774 | * Returns the left padding of this view. If there are inset and enabled |
| 14775 | * scrollbars, this value may include the space required to display the |
| 14776 | * scrollbars as well. |
| 14777 | * |
| 14778 | * @return the left padding in pixels |
| 14779 | */ |
| 14780 | public int getPaddingLeft() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14781 | if (!isPaddingResolved()) { |
| 14782 | resolvePadding(); |
| 14783 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14784 | return mPaddingLeft; |
| 14785 | } |
| 14786 | |
| 14787 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 14788 | * Returns the start padding of this view depending on its resolved layout direction. |
| 14789 | * If there are inset and enabled scrollbars, this value may include the space |
| 14790 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14791 | * |
| 14792 | * @return the start padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14793 | */ |
| 14794 | public int getPaddingStart() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14795 | if (!isPaddingResolved()) { |
| 14796 | resolvePadding(); |
| 14797 | } |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 14798 | return (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14799 | mPaddingRight : mPaddingLeft; |
| 14800 | } |
| 14801 | |
| 14802 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14803 | * Returns the right padding of this view. If there are inset and enabled |
| 14804 | * scrollbars, this value may include the space required to display the |
| 14805 | * scrollbars as well. |
| 14806 | * |
| 14807 | * @return the right padding in pixels |
| 14808 | */ |
| 14809 | public int getPaddingRight() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14810 | if (!isPaddingResolved()) { |
| 14811 | resolvePadding(); |
| 14812 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14813 | return mPaddingRight; |
| 14814 | } |
| 14815 | |
| 14816 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 14817 | * Returns the end padding of this view depending on its resolved layout direction. |
| 14818 | * If there are inset and enabled scrollbars, this value may include the space |
| 14819 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14820 | * |
| 14821 | * @return the end padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14822 | */ |
| 14823 | public int getPaddingEnd() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14824 | if (!isPaddingResolved()) { |
| 14825 | resolvePadding(); |
| 14826 | } |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 14827 | return (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14828 | mPaddingLeft : mPaddingRight; |
| 14829 | } |
| 14830 | |
| 14831 | /** |
| 14832 | * Return if the padding as been set thru relative values |
| 14833 | * {@link #setPaddingRelative(int, int, int, int)} or thru |
| 14834 | * @attr ref android.R.styleable#View_paddingStart or |
| 14835 | * @attr ref android.R.styleable#View_paddingEnd |
| 14836 | * |
| 14837 | * @return true if the padding is relative or false if it is not. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14838 | */ |
| 14839 | public boolean isPaddingRelative() { |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14840 | return (mUserPaddingStart != UNDEFINED_PADDING || mUserPaddingEnd != UNDEFINED_PADDING); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14841 | } |
| 14842 | |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 14843 | Insets computeOpticalInsets() { |
| 14844 | return (mBackground == null) ? Insets.NONE : mBackground.getOpticalInsets(); |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 14845 | } |
| 14846 | |
| 14847 | /** |
| 14848 | * @hide |
| 14849 | */ |
Fabrice Di Meglio | 47fb191 | 2012-09-28 19:50:18 -0700 | [diff] [blame] | 14850 | public void resetPaddingToInitialValues() { |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 14851 | if (isRtlCompatibilityMode()) { |
| 14852 | mPaddingLeft = mUserPaddingLeftInitial; |
| 14853 | mPaddingRight = mUserPaddingRightInitial; |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 14854 | return; |
| 14855 | } |
| 14856 | if (isLayoutRtl()) { |
| 14857 | mPaddingLeft = (mUserPaddingEnd >= 0) ? mUserPaddingEnd : mUserPaddingLeftInitial; |
| 14858 | mPaddingRight = (mUserPaddingStart >= 0) ? mUserPaddingStart : mUserPaddingRightInitial; |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 14859 | } else { |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 14860 | mPaddingLeft = (mUserPaddingStart >= 0) ? mUserPaddingStart : mUserPaddingLeftInitial; |
| 14861 | mPaddingRight = (mUserPaddingEnd >= 0) ? mUserPaddingEnd : mUserPaddingRightInitial; |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 14862 | } |
Fabrice Di Meglio | 47fb191 | 2012-09-28 19:50:18 -0700 | [diff] [blame] | 14863 | } |
| 14864 | |
| 14865 | /** |
| 14866 | * @hide |
| 14867 | */ |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 14868 | public Insets getOpticalInsets() { |
| 14869 | if (mLayoutInsets == null) { |
| 14870 | mLayoutInsets = computeOpticalInsets(); |
| 14871 | } |
| 14872 | return mLayoutInsets; |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 14873 | } |
| 14874 | |
| 14875 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14876 | * Changes the selection state of this view. A view can be selected or not. |
| 14877 | * Note that selection is not the same as focus. Views are typically |
| 14878 | * selected in the context of an AdapterView like ListView or GridView; |
| 14879 | * the selected view is the view that is highlighted. |
| 14880 | * |
| 14881 | * @param selected true if the view must be selected, false otherwise |
| 14882 | */ |
| 14883 | public void setSelected(boolean selected) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14884 | if (((mPrivateFlags & PFLAG_SELECTED) != 0) != selected) { |
| 14885 | mPrivateFlags = (mPrivateFlags & ~PFLAG_SELECTED) | (selected ? PFLAG_SELECTED : 0); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 14886 | if (!selected) resetPressedState(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14887 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14888 | refreshDrawableState(); |
| 14889 | dispatchSetSelected(selected); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 14890 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 14891 | notifyAccessibilityStateChanged(); |
| 14892 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14893 | } |
| 14894 | } |
| 14895 | |
| 14896 | /** |
| 14897 | * Dispatch setSelected to all of this View's children. |
| 14898 | * |
| 14899 | * @see #setSelected(boolean) |
| 14900 | * |
| 14901 | * @param selected The new selected state |
| 14902 | */ |
| 14903 | protected void dispatchSetSelected(boolean selected) { |
| 14904 | } |
| 14905 | |
| 14906 | /** |
| 14907 | * Indicates the selection state of this view. |
| 14908 | * |
| 14909 | * @return true if the view is selected, false otherwise |
| 14910 | */ |
| 14911 | @ViewDebug.ExportedProperty |
| 14912 | public boolean isSelected() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14913 | return (mPrivateFlags & PFLAG_SELECTED) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14914 | } |
| 14915 | |
| 14916 | /** |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14917 | * Changes the activated state of this view. A view can be activated or not. |
| 14918 | * Note that activation is not the same as selection. Selection is |
| 14919 | * a transient property, representing the view (hierarchy) the user is |
| 14920 | * currently interacting with. Activation is a longer-term state that the |
| 14921 | * user can move views in and out of. For example, in a list view with |
| 14922 | * single or multiple selection enabled, the views in the current selection |
| 14923 | * set are activated. (Um, yeah, we are deeply sorry about the terminology |
| 14924 | * here.) The activated state is propagated down to children of the view it |
| 14925 | * is set on. |
| 14926 | * |
| 14927 | * @param activated true if the view must be activated, false otherwise |
| 14928 | */ |
| 14929 | public void setActivated(boolean activated) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14930 | if (((mPrivateFlags & PFLAG_ACTIVATED) != 0) != activated) { |
| 14931 | mPrivateFlags = (mPrivateFlags & ~PFLAG_ACTIVATED) | (activated ? PFLAG_ACTIVATED : 0); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14932 | invalidate(true); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14933 | refreshDrawableState(); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 14934 | dispatchSetActivated(activated); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14935 | } |
| 14936 | } |
| 14937 | |
| 14938 | /** |
| 14939 | * Dispatch setActivated to all of this View's children. |
| 14940 | * |
| 14941 | * @see #setActivated(boolean) |
| 14942 | * |
| 14943 | * @param activated The new activated state |
| 14944 | */ |
| 14945 | protected void dispatchSetActivated(boolean activated) { |
| 14946 | } |
| 14947 | |
| 14948 | /** |
| 14949 | * Indicates the activation state of this view. |
| 14950 | * |
| 14951 | * @return true if the view is activated, false otherwise |
| 14952 | */ |
| 14953 | @ViewDebug.ExportedProperty |
| 14954 | public boolean isActivated() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14955 | return (mPrivateFlags & PFLAG_ACTIVATED) != 0; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14956 | } |
| 14957 | |
| 14958 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14959 | * Returns the ViewTreeObserver for this view's hierarchy. The view tree |
| 14960 | * observer can be used to get notifications when global events, like |
| 14961 | * layout, happen. |
| 14962 | * |
| 14963 | * The returned ViewTreeObserver observer is not guaranteed to remain |
| 14964 | * valid for the lifetime of this View. If the caller of this method keeps |
| 14965 | * a long-lived reference to ViewTreeObserver, it should always check for |
| 14966 | * the return value of {@link ViewTreeObserver#isAlive()}. |
| 14967 | * |
| 14968 | * @return The ViewTreeObserver for this view's hierarchy. |
| 14969 | */ |
| 14970 | public ViewTreeObserver getViewTreeObserver() { |
| 14971 | if (mAttachInfo != null) { |
| 14972 | return mAttachInfo.mTreeObserver; |
| 14973 | } |
| 14974 | if (mFloatingTreeObserver == null) { |
| 14975 | mFloatingTreeObserver = new ViewTreeObserver(); |
| 14976 | } |
| 14977 | return mFloatingTreeObserver; |
| 14978 | } |
| 14979 | |
| 14980 | /** |
| 14981 | * <p>Finds the topmost view in the current view hierarchy.</p> |
| 14982 | * |
| 14983 | * @return the topmost view containing this view |
| 14984 | */ |
| 14985 | public View getRootView() { |
| 14986 | if (mAttachInfo != null) { |
| 14987 | final View v = mAttachInfo.mRootView; |
| 14988 | if (v != null) { |
| 14989 | return v; |
| 14990 | } |
| 14991 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14993 | View parent = this; |
| 14994 | |
| 14995 | while (parent.mParent != null && parent.mParent instanceof View) { |
| 14996 | parent = (View) parent.mParent; |
| 14997 | } |
| 14998 | |
| 14999 | return parent; |
| 15000 | } |
| 15001 | |
| 15002 | /** |
| 15003 | * <p>Computes the coordinates of this view on the screen. The argument |
| 15004 | * must be an array of two integers. After the method returns, the array |
| 15005 | * contains the x and y location in that order.</p> |
| 15006 | * |
| 15007 | * @param location an array of two integers in which to hold the coordinates |
| 15008 | */ |
| 15009 | public void getLocationOnScreen(int[] location) { |
| 15010 | getLocationInWindow(location); |
| 15011 | |
| 15012 | final AttachInfo info = mAttachInfo; |
Romain Guy | 779398e | 2009-06-16 13:17:50 -0700 | [diff] [blame] | 15013 | if (info != null) { |
| 15014 | location[0] += info.mWindowLeft; |
| 15015 | location[1] += info.mWindowTop; |
| 15016 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15017 | } |
| 15018 | |
| 15019 | /** |
| 15020 | * <p>Computes the coordinates of this view in its window. The argument |
| 15021 | * must be an array of two integers. After the method returns, the array |
| 15022 | * contains the x and y location in that order.</p> |
| 15023 | * |
| 15024 | * @param location an array of two integers in which to hold the coordinates |
| 15025 | */ |
| 15026 | public void getLocationInWindow(int[] location) { |
| 15027 | if (location == null || location.length < 2) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15028 | 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] | 15029 | } |
| 15030 | |
Gilles Debunne | 6583ce5 | 2011-12-06 18:09:02 -0800 | [diff] [blame] | 15031 | if (mAttachInfo == null) { |
| 15032 | // When the view is not attached to a window, this method does not make sense |
| 15033 | location[0] = location[1] = 0; |
| 15034 | return; |
| 15035 | } |
| 15036 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15037 | float[] position = mAttachInfo.mTmpTransformLocation; |
| 15038 | position[0] = position[1] = 0.0f; |
| 15039 | |
| 15040 | if (!hasIdentityMatrix()) { |
| 15041 | getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 15042 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15043 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15044 | position[0] += mLeft; |
| 15045 | position[1] += mTop; |
| 15046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15047 | ViewParent viewParent = mParent; |
| 15048 | while (viewParent instanceof View) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15049 | final View view = (View) viewParent; |
| 15050 | |
| 15051 | position[0] -= view.mScrollX; |
| 15052 | position[1] -= view.mScrollY; |
| 15053 | |
| 15054 | if (!view.hasIdentityMatrix()) { |
| 15055 | view.getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 15056 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15057 | |
| 15058 | position[0] += view.mLeft; |
| 15059 | position[1] += view.mTop; |
| 15060 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15061 | viewParent = view.mParent; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 15062 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15063 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 15064 | if (viewParent instanceof ViewRootImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15065 | // *cough* |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15066 | final ViewRootImpl vr = (ViewRootImpl) viewParent; |
| 15067 | position[1] -= vr.mCurScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15068 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15069 | |
| 15070 | location[0] = (int) (position[0] + 0.5f); |
| 15071 | location[1] = (int) (position[1] + 0.5f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15072 | } |
| 15073 | |
| 15074 | /** |
| 15075 | * {@hide} |
| 15076 | * @param id the id of the view to be found |
| 15077 | * @return the view of the specified id, null if cannot be found |
| 15078 | */ |
| 15079 | protected View findViewTraversal(int id) { |
| 15080 | if (id == mID) { |
| 15081 | return this; |
| 15082 | } |
| 15083 | return null; |
| 15084 | } |
| 15085 | |
| 15086 | /** |
| 15087 | * {@hide} |
| 15088 | * @param tag the tag of the view to be found |
| 15089 | * @return the view of specified tag, null if cannot be found |
| 15090 | */ |
| 15091 | protected View findViewWithTagTraversal(Object tag) { |
| 15092 | if (tag != null && tag.equals(mTag)) { |
| 15093 | return this; |
| 15094 | } |
| 15095 | return null; |
| 15096 | } |
| 15097 | |
| 15098 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15099 | * {@hide} |
| 15100 | * @param predicate The predicate to evaluate. |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 15101 | * @param childToSkip If not null, ignores this child during the recursive traversal. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15102 | * @return The first view that matches the predicate or null. |
| 15103 | */ |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 15104 | protected View findViewByPredicateTraversal(Predicate<View> predicate, View childToSkip) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15105 | if (predicate.apply(this)) { |
| 15106 | return this; |
| 15107 | } |
| 15108 | return null; |
| 15109 | } |
| 15110 | |
| 15111 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15112 | * Look for a child view with the given id. If this view has the given |
| 15113 | * id, return this view. |
| 15114 | * |
| 15115 | * @param id The id to search for. |
| 15116 | * @return The view that has the given id in the hierarchy or null |
| 15117 | */ |
| 15118 | public final View findViewById(int id) { |
| 15119 | if (id < 0) { |
| 15120 | return null; |
| 15121 | } |
| 15122 | return findViewTraversal(id); |
| 15123 | } |
| 15124 | |
| 15125 | /** |
Svetoslav Ganov | 2cdedff | 2011-10-03 14:18:42 -0700 | [diff] [blame] | 15126 | * Finds a view by its unuque and stable accessibility id. |
| 15127 | * |
| 15128 | * @param accessibilityId The searched accessibility id. |
| 15129 | * @return The found view. |
| 15130 | */ |
| 15131 | final View findViewByAccessibilityId(int accessibilityId) { |
| 15132 | if (accessibilityId < 0) { |
| 15133 | return null; |
| 15134 | } |
| 15135 | return findViewByAccessibilityIdTraversal(accessibilityId); |
| 15136 | } |
| 15137 | |
| 15138 | /** |
| 15139 | * Performs the traversal to find a view by its unuque and stable accessibility id. |
| 15140 | * |
| 15141 | * <strong>Note:</strong>This method does not stop at the root namespace |
| 15142 | * boundary since the user can touch the screen at an arbitrary location |
| 15143 | * potentially crossing the root namespace bounday which will send an |
| 15144 | * accessibility event to accessibility services and they should be able |
| 15145 | * to obtain the event source. Also accessibility ids are guaranteed to be |
| 15146 | * unique in the window. |
| 15147 | * |
| 15148 | * @param accessibilityId The accessibility id. |
| 15149 | * @return The found view. |
| 15150 | */ |
| 15151 | View findViewByAccessibilityIdTraversal(int accessibilityId) { |
| 15152 | if (getAccessibilityViewId() == accessibilityId) { |
| 15153 | return this; |
| 15154 | } |
| 15155 | return null; |
| 15156 | } |
| 15157 | |
| 15158 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15159 | * Look for a child view with the given tag. If this view has the given |
| 15160 | * tag, return this view. |
| 15161 | * |
| 15162 | * @param tag The tag to search for, using "tag.equals(getTag())". |
| 15163 | * @return The View that has the given tag in the hierarchy or null |
| 15164 | */ |
| 15165 | public final View findViewWithTag(Object tag) { |
| 15166 | if (tag == null) { |
| 15167 | return null; |
| 15168 | } |
| 15169 | return findViewWithTagTraversal(tag); |
| 15170 | } |
| 15171 | |
| 15172 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15173 | * {@hide} |
| 15174 | * Look for a child view that matches the specified predicate. |
| 15175 | * If this view matches the predicate, return this view. |
| 15176 | * |
| 15177 | * @param predicate The predicate to evaluate. |
| 15178 | * @return The first view that matches the predicate or null. |
| 15179 | */ |
| 15180 | public final View findViewByPredicate(Predicate<View> predicate) { |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 15181 | return findViewByPredicateTraversal(predicate, null); |
| 15182 | } |
| 15183 | |
| 15184 | /** |
| 15185 | * {@hide} |
| 15186 | * Look for a child view that matches the specified predicate, |
| 15187 | * starting with the specified view and its descendents and then |
| 15188 | * recusively searching the ancestors and siblings of that view |
| 15189 | * until this view is reached. |
| 15190 | * |
| 15191 | * This method is useful in cases where the predicate does not match |
| 15192 | * a single unique view (perhaps multiple views use the same id) |
| 15193 | * and we are trying to find the view that is "closest" in scope to the |
| 15194 | * starting view. |
| 15195 | * |
| 15196 | * @param start The view to start from. |
| 15197 | * @param predicate The predicate to evaluate. |
| 15198 | * @return The first view that matches the predicate or null. |
| 15199 | */ |
| 15200 | public final View findViewByPredicateInsideOut(View start, Predicate<View> predicate) { |
| 15201 | View childToSkip = null; |
| 15202 | for (;;) { |
| 15203 | View view = start.findViewByPredicateTraversal(predicate, childToSkip); |
| 15204 | if (view != null || start == this) { |
| 15205 | return view; |
| 15206 | } |
| 15207 | |
| 15208 | ViewParent parent = start.getParent(); |
| 15209 | if (parent == null || !(parent instanceof View)) { |
| 15210 | return null; |
| 15211 | } |
| 15212 | |
| 15213 | childToSkip = start; |
| 15214 | start = (View) parent; |
| 15215 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15216 | } |
| 15217 | |
| 15218 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15219 | * Sets the identifier for this view. The identifier does not have to be |
| 15220 | * unique in this view's hierarchy. The identifier should be a positive |
| 15221 | * number. |
| 15222 | * |
| 15223 | * @see #NO_ID |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15224 | * @see #getId() |
| 15225 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15226 | * |
| 15227 | * @param id a number used to identify the view |
| 15228 | * |
| 15229 | * @attr ref android.R.styleable#View_id |
| 15230 | */ |
| 15231 | public void setId(int id) { |
| 15232 | mID = id; |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 15233 | if (mID == View.NO_ID && mLabelForId != View.NO_ID) { |
| 15234 | mID = generateViewId(); |
| 15235 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15236 | } |
| 15237 | |
| 15238 | /** |
| 15239 | * {@hide} |
| 15240 | * |
| 15241 | * @param isRoot true if the view belongs to the root namespace, false |
| 15242 | * otherwise |
| 15243 | */ |
| 15244 | public void setIsRootNamespace(boolean isRoot) { |
| 15245 | if (isRoot) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15246 | mPrivateFlags |= PFLAG_IS_ROOT_NAMESPACE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15247 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15248 | mPrivateFlags &= ~PFLAG_IS_ROOT_NAMESPACE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15249 | } |
| 15250 | } |
| 15251 | |
| 15252 | /** |
| 15253 | * {@hide} |
| 15254 | * |
| 15255 | * @return true if the view belongs to the root namespace, false otherwise |
| 15256 | */ |
| 15257 | public boolean isRootNamespace() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15258 | return (mPrivateFlags&PFLAG_IS_ROOT_NAMESPACE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15259 | } |
| 15260 | |
| 15261 | /** |
| 15262 | * Returns this view's identifier. |
| 15263 | * |
| 15264 | * @return a positive integer used to identify the view or {@link #NO_ID} |
| 15265 | * if the view has no ID |
| 15266 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15267 | * @see #setId(int) |
| 15268 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15269 | * @attr ref android.R.styleable#View_id |
| 15270 | */ |
| 15271 | @ViewDebug.CapturedViewProperty |
| 15272 | public int getId() { |
| 15273 | return mID; |
| 15274 | } |
| 15275 | |
| 15276 | /** |
| 15277 | * Returns this view's tag. |
| 15278 | * |
| 15279 | * @return the Object stored in this view as a tag |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15280 | * |
| 15281 | * @see #setTag(Object) |
| 15282 | * @see #getTag(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15283 | */ |
| 15284 | @ViewDebug.ExportedProperty |
| 15285 | public Object getTag() { |
| 15286 | return mTag; |
| 15287 | } |
| 15288 | |
| 15289 | /** |
| 15290 | * Sets the tag associated with this view. A tag can be used to mark |
| 15291 | * a view in its hierarchy and does not have to be unique within the |
| 15292 | * hierarchy. Tags can also be used to store data within a view without |
| 15293 | * resorting to another data structure. |
| 15294 | * |
| 15295 | * @param tag an Object to tag the view with |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15296 | * |
| 15297 | * @see #getTag() |
| 15298 | * @see #setTag(int, Object) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15299 | */ |
| 15300 | public void setTag(final Object tag) { |
| 15301 | mTag = tag; |
| 15302 | } |
| 15303 | |
| 15304 | /** |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15305 | * Returns the tag associated with this view and the specified key. |
| 15306 | * |
| 15307 | * @param key The key identifying the tag |
| 15308 | * |
| 15309 | * @return the Object stored in this view as a tag |
| 15310 | * |
| 15311 | * @see #setTag(int, Object) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15312 | * @see #getTag() |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15313 | */ |
| 15314 | public Object getTag(int key) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 15315 | if (mKeyedTags != null) return mKeyedTags.get(key); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15316 | return null; |
| 15317 | } |
| 15318 | |
| 15319 | /** |
| 15320 | * Sets a tag associated with this view and a key. A tag can be used |
| 15321 | * to mark a view in its hierarchy and does not have to be unique within |
| 15322 | * the hierarchy. Tags can also be used to store data within a view |
| 15323 | * without resorting to another data structure. |
| 15324 | * |
| 15325 | * 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] | 15326 | * application to ensure it is unique (see the <a |
| 15327 | * href={@docRoot}guide/topics/resources/more-resources.html#Id">ID resource type</a>). |
| 15328 | * Keys identified as belonging to |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15329 | * the Android framework or not associated with any package will cause |
| 15330 | * an {@link IllegalArgumentException} to be thrown. |
| 15331 | * |
| 15332 | * @param key The key identifying the tag |
| 15333 | * @param tag An Object to tag the view with |
| 15334 | * |
| 15335 | * @throws IllegalArgumentException If they specified key is not valid |
| 15336 | * |
| 15337 | * @see #setTag(Object) |
| 15338 | * @see #getTag(int) |
| 15339 | */ |
| 15340 | public void setTag(int key, final Object tag) { |
| 15341 | // If the package id is 0x00 or 0x01, it's either an undefined package |
| 15342 | // or a framework id |
| 15343 | if ((key >>> 24) < 2) { |
| 15344 | throw new IllegalArgumentException("The key must be an application-specific " |
| 15345 | + "resource id."); |
| 15346 | } |
| 15347 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 15348 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15349 | } |
| 15350 | |
| 15351 | /** |
| 15352 | * Variation of {@link #setTag(int, Object)} that enforces the key to be a |
| 15353 | * framework id. |
| 15354 | * |
| 15355 | * @hide |
| 15356 | */ |
| 15357 | public void setTagInternal(int key, Object tag) { |
| 15358 | if ((key >>> 24) != 0x1) { |
| 15359 | throw new IllegalArgumentException("The key must be a framework-specific " |
| 15360 | + "resource id."); |
| 15361 | } |
| 15362 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 15363 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15364 | } |
| 15365 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 15366 | private void setKeyedTag(int key, Object tag) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 15367 | if (mKeyedTags == null) { |
| 15368 | mKeyedTags = new SparseArray<Object>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15369 | } |
| 15370 | |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 15371 | mKeyedTags.put(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15372 | } |
| 15373 | |
| 15374 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15375 | * Prints information about this view in the log output, with the tag |
| 15376 | * {@link #VIEW_LOG_TAG}. |
| 15377 | * |
| 15378 | * @hide |
| 15379 | */ |
| 15380 | public void debug() { |
| 15381 | debug(0); |
| 15382 | } |
| 15383 | |
| 15384 | /** |
| 15385 | * Prints information about this view in the log output, with the tag |
| 15386 | * {@link #VIEW_LOG_TAG}. Each line in the output is preceded with an |
| 15387 | * indentation defined by the <code>depth</code>. |
| 15388 | * |
| 15389 | * @param depth the indentation level |
| 15390 | * |
| 15391 | * @hide |
| 15392 | */ |
| 15393 | protected void debug(int depth) { |
| 15394 | String output = debugIndent(depth - 1); |
| 15395 | |
| 15396 | output += "+ " + this; |
| 15397 | int id = getId(); |
| 15398 | if (id != -1) { |
| 15399 | output += " (id=" + id + ")"; |
| 15400 | } |
| 15401 | Object tag = getTag(); |
| 15402 | if (tag != null) { |
| 15403 | output += " (tag=" + tag + ")"; |
| 15404 | } |
| 15405 | Log.d(VIEW_LOG_TAG, output); |
| 15406 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15407 | if ((mPrivateFlags & PFLAG_FOCUSED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15408 | output = debugIndent(depth) + " FOCUSED"; |
| 15409 | Log.d(VIEW_LOG_TAG, output); |
| 15410 | } |
| 15411 | |
| 15412 | output = debugIndent(depth); |
| 15413 | output += "frame={" + mLeft + ", " + mTop + ", " + mRight |
| 15414 | + ", " + mBottom + "} scroll={" + mScrollX + ", " + mScrollY |
| 15415 | + "} "; |
| 15416 | Log.d(VIEW_LOG_TAG, output); |
| 15417 | |
| 15418 | if (mPaddingLeft != 0 || mPaddingTop != 0 || mPaddingRight != 0 |
| 15419 | || mPaddingBottom != 0) { |
| 15420 | output = debugIndent(depth); |
| 15421 | output += "padding={" + mPaddingLeft + ", " + mPaddingTop |
| 15422 | + ", " + mPaddingRight + ", " + mPaddingBottom + "}"; |
| 15423 | Log.d(VIEW_LOG_TAG, output); |
| 15424 | } |
| 15425 | |
| 15426 | output = debugIndent(depth); |
| 15427 | output += "mMeasureWidth=" + mMeasuredWidth + |
| 15428 | " mMeasureHeight=" + mMeasuredHeight; |
| 15429 | Log.d(VIEW_LOG_TAG, output); |
| 15430 | |
| 15431 | output = debugIndent(depth); |
| 15432 | if (mLayoutParams == null) { |
| 15433 | output += "BAD! no layout params"; |
| 15434 | } else { |
| 15435 | output = mLayoutParams.debug(output); |
| 15436 | } |
| 15437 | Log.d(VIEW_LOG_TAG, output); |
| 15438 | |
| 15439 | output = debugIndent(depth); |
| 15440 | output += "flags={"; |
| 15441 | output += View.printFlags(mViewFlags); |
| 15442 | output += "}"; |
| 15443 | Log.d(VIEW_LOG_TAG, output); |
| 15444 | |
| 15445 | output = debugIndent(depth); |
| 15446 | output += "privateFlags={"; |
| 15447 | output += View.printPrivateFlags(mPrivateFlags); |
| 15448 | output += "}"; |
| 15449 | Log.d(VIEW_LOG_TAG, output); |
| 15450 | } |
| 15451 | |
| 15452 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 15453 | * Creates a string of whitespaces used for indentation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15454 | * |
| 15455 | * @param depth the indentation level |
| 15456 | * @return a String containing (depth * 2 + 3) * 2 white spaces |
| 15457 | * |
| 15458 | * @hide |
| 15459 | */ |
| 15460 | protected static String debugIndent(int depth) { |
| 15461 | StringBuilder spaces = new StringBuilder((depth * 2 + 3) * 2); |
| 15462 | for (int i = 0; i < (depth * 2) + 3; i++) { |
| 15463 | spaces.append(' ').append(' '); |
| 15464 | } |
| 15465 | return spaces.toString(); |
| 15466 | } |
| 15467 | |
| 15468 | /** |
| 15469 | * <p>Return the offset of the widget's text baseline from the widget's top |
| 15470 | * boundary. If this widget does not support baseline alignment, this |
| 15471 | * method returns -1. </p> |
| 15472 | * |
| 15473 | * @return the offset of the baseline within the widget's bounds or -1 |
| 15474 | * if baseline alignment is not supported |
| 15475 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 15476 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15477 | public int getBaseline() { |
| 15478 | return -1; |
| 15479 | } |
| 15480 | |
| 15481 | /** |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 15482 | * Returns whether the view hierarchy is currently undergoing a layout pass. This |
| 15483 | * information is useful to avoid situations such as calling {@link #requestLayout()} during |
| 15484 | * a layout pass. |
| 15485 | * |
| 15486 | * @return whether the view hierarchy is currently undergoing a layout pass |
| 15487 | */ |
| 15488 | public boolean isInLayout() { |
| 15489 | ViewRootImpl viewRoot = getViewRootImpl(); |
| 15490 | return (viewRoot != null && viewRoot.isInLayout()); |
| 15491 | } |
| 15492 | |
| 15493 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15494 | * Call this when something has changed which has invalidated the |
| 15495 | * layout of this view. This will schedule a layout pass of the view |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 15496 | * tree. This should not be called while the view hierarchy is currently in a layout |
| 15497 | * pass ({@link #isInLayout()}. If layout is happening, the request may be honored at the |
| 15498 | * end of the current layout pass (and then layout will run again) or after the current |
| 15499 | * frame is drawn and the next layout occurs. |
| 15500 | * |
| 15501 | * <p>Subclasses which override this method should call the superclass method to |
| 15502 | * handle possible request-during-layout errors correctly.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15503 | */ |
| 15504 | public void requestLayout() { |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 15505 | ViewRootImpl viewRoot = getViewRootImpl(); |
| 15506 | if (viewRoot != null && viewRoot.isInLayout()) { |
| 15507 | viewRoot.requestLayoutDuringLayout(this); |
| 15508 | return; |
| 15509 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15510 | mPrivateFlags |= PFLAG_FORCE_LAYOUT; |
| 15511 | mPrivateFlags |= PFLAG_INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15512 | |
Fabrice Di Meglio | 4a526885 | 2012-03-30 15:56:48 -0700 | [diff] [blame] | 15513 | if (mParent != null && !mParent.isLayoutRequested()) { |
| 15514 | mParent.requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15515 | } |
| 15516 | } |
| 15517 | |
| 15518 | /** |
| 15519 | * Forces this view to be laid out during the next layout pass. |
| 15520 | * This method does not call requestLayout() or forceLayout() |
| 15521 | * on the parent. |
| 15522 | */ |
| 15523 | public void forceLayout() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15524 | mPrivateFlags |= PFLAG_FORCE_LAYOUT; |
| 15525 | mPrivateFlags |= PFLAG_INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15526 | } |
| 15527 | |
| 15528 | /** |
| 15529 | * <p> |
| 15530 | * This is called to find out how big a view should be. The parent |
| 15531 | * supplies constraint information in the width and height parameters. |
| 15532 | * </p> |
| 15533 | * |
| 15534 | * <p> |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 15535 | * The actual measurement work of a view is performed in |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15536 | * {@link #onMeasure(int, int)}, called by this method. Therefore, only |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 15537 | * {@link #onMeasure(int, int)} can and must be overridden by subclasses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15538 | * </p> |
| 15539 | * |
| 15540 | * |
| 15541 | * @param widthMeasureSpec Horizontal space requirements as imposed by the |
| 15542 | * parent |
| 15543 | * @param heightMeasureSpec Vertical space requirements as imposed by the |
| 15544 | * parent |
| 15545 | * |
| 15546 | * @see #onMeasure(int, int) |
| 15547 | */ |
| 15548 | public final void measure(int widthMeasureSpec, int heightMeasureSpec) { |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 15549 | boolean optical = isLayoutModeOptical(this); |
| 15550 | if (optical != isLayoutModeOptical(mParent)) { |
| 15551 | Insets insets = getOpticalInsets(); |
| 15552 | int oWidth = insets.left + insets.right; |
| 15553 | int oHeight = insets.top + insets.bottom; |
| 15554 | widthMeasureSpec = MeasureSpec.adjust(widthMeasureSpec, optical ? -oWidth : oWidth); |
| 15555 | heightMeasureSpec = MeasureSpec.adjust(heightMeasureSpec, optical ? -oHeight : oHeight); |
| 15556 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15557 | if ((mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT || |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15558 | widthMeasureSpec != mOldWidthMeasureSpec || |
| 15559 | heightMeasureSpec != mOldHeightMeasureSpec) { |
| 15560 | |
| 15561 | // first clears the measured dimension flag |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15562 | mPrivateFlags &= ~PFLAG_MEASURED_DIMENSION_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15563 | |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 15564 | resolveRtlPropertiesIfNeeded(); |
Adam Powell | 0090f20 | 2012-08-07 17:15:30 -0700 | [diff] [blame] | 15565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15566 | // measure ourselves, this should set the measured dimension flag back |
| 15567 | onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 15568 | |
| 15569 | // flag not set, setMeasuredDimension() was not invoked, we raise |
| 15570 | // an exception to warn the developer |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15571 | if ((mPrivateFlags & PFLAG_MEASURED_DIMENSION_SET) != PFLAG_MEASURED_DIMENSION_SET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15572 | throw new IllegalStateException("onMeasure() did not set the" |
| 15573 | + " measured dimension by calling" |
| 15574 | + " setMeasuredDimension()"); |
| 15575 | } |
| 15576 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15577 | mPrivateFlags |= PFLAG_LAYOUT_REQUIRED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15578 | } |
| 15579 | |
| 15580 | mOldWidthMeasureSpec = widthMeasureSpec; |
| 15581 | mOldHeightMeasureSpec = heightMeasureSpec; |
| 15582 | } |
| 15583 | |
| 15584 | /** |
| 15585 | * <p> |
| 15586 | * Measure the view and its content to determine the measured width and the |
| 15587 | * measured height. This method is invoked by {@link #measure(int, int)} and |
| 15588 | * should be overriden by subclasses to provide accurate and efficient |
| 15589 | * measurement of their contents. |
| 15590 | * </p> |
| 15591 | * |
| 15592 | * <p> |
| 15593 | * <strong>CONTRACT:</strong> When overriding this method, you |
| 15594 | * <em>must</em> call {@link #setMeasuredDimension(int, int)} to store the |
| 15595 | * measured width and height of this view. Failure to do so will trigger an |
| 15596 | * <code>IllegalStateException</code>, thrown by |
| 15597 | * {@link #measure(int, int)}. Calling the superclass' |
| 15598 | * {@link #onMeasure(int, int)} is a valid use. |
| 15599 | * </p> |
| 15600 | * |
| 15601 | * <p> |
| 15602 | * The base class implementation of measure defaults to the background size, |
| 15603 | * unless a larger size is allowed by the MeasureSpec. Subclasses should |
| 15604 | * override {@link #onMeasure(int, int)} to provide better measurements of |
| 15605 | * their content. |
| 15606 | * </p> |
| 15607 | * |
| 15608 | * <p> |
| 15609 | * If this method is overridden, it is the subclass's responsibility to make |
| 15610 | * sure the measured height and width are at least the view's minimum height |
| 15611 | * and width ({@link #getSuggestedMinimumHeight()} and |
| 15612 | * {@link #getSuggestedMinimumWidth()}). |
| 15613 | * </p> |
| 15614 | * |
| 15615 | * @param widthMeasureSpec horizontal space requirements as imposed by the parent. |
| 15616 | * The requirements are encoded with |
| 15617 | * {@link android.view.View.MeasureSpec}. |
| 15618 | * @param heightMeasureSpec vertical space requirements as imposed by the parent. |
| 15619 | * The requirements are encoded with |
| 15620 | * {@link android.view.View.MeasureSpec}. |
| 15621 | * |
| 15622 | * @see #getMeasuredWidth() |
| 15623 | * @see #getMeasuredHeight() |
| 15624 | * @see #setMeasuredDimension(int, int) |
| 15625 | * @see #getSuggestedMinimumHeight() |
| 15626 | * @see #getSuggestedMinimumWidth() |
| 15627 | * @see android.view.View.MeasureSpec#getMode(int) |
| 15628 | * @see android.view.View.MeasureSpec#getSize(int) |
| 15629 | */ |
| 15630 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 15631 | setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), |
| 15632 | getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); |
| 15633 | } |
| 15634 | |
| 15635 | /** |
| 15636 | * <p>This mehod must be called by {@link #onMeasure(int, int)} to store the |
| 15637 | * measured width and measured height. Failing to do so will trigger an |
| 15638 | * exception at measurement time.</p> |
| 15639 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15640 | * @param measuredWidth The measured width of this view. May be a complex |
| 15641 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 15642 | * {@link #MEASURED_STATE_TOO_SMALL}. |
| 15643 | * @param measuredHeight The measured height of this view. May be a complex |
| 15644 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 15645 | * {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15646 | */ |
| 15647 | protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) { |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 15648 | boolean optical = isLayoutModeOptical(this); |
| 15649 | if (optical != isLayoutModeOptical(mParent)) { |
| 15650 | Insets insets = getOpticalInsets(); |
| 15651 | int opticalWidth = insets.left + insets.right; |
| 15652 | int opticalHeight = insets.top + insets.bottom; |
| 15653 | |
| 15654 | measuredWidth += optical ? opticalWidth : -opticalWidth; |
| 15655 | measuredHeight += optical ? opticalHeight : -opticalHeight; |
| 15656 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15657 | mMeasuredWidth = measuredWidth; |
| 15658 | mMeasuredHeight = measuredHeight; |
| 15659 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15660 | mPrivateFlags |= PFLAG_MEASURED_DIMENSION_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15661 | } |
| 15662 | |
| 15663 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15664 | * Merge two states as returned by {@link #getMeasuredState()}. |
| 15665 | * @param curState The current state as returned from a view or the result |
| 15666 | * of combining multiple views. |
| 15667 | * @param newState The new view state to combine. |
| 15668 | * @return Returns a new integer reflecting the combination of the two |
| 15669 | * states. |
| 15670 | */ |
| 15671 | public static int combineMeasuredStates(int curState, int newState) { |
| 15672 | return curState | newState; |
| 15673 | } |
| 15674 | |
| 15675 | /** |
| 15676 | * Version of {@link #resolveSizeAndState(int, int, int)} |
| 15677 | * returning only the {@link #MEASURED_SIZE_MASK} bits of the result. |
| 15678 | */ |
| 15679 | public static int resolveSize(int size, int measureSpec) { |
| 15680 | return resolveSizeAndState(size, measureSpec, 0) & MEASURED_SIZE_MASK; |
| 15681 | } |
| 15682 | |
| 15683 | /** |
| 15684 | * Utility to reconcile a desired size and state, with constraints imposed |
| 15685 | * by a MeasureSpec. Will take the desired size, unless a different size |
| 15686 | * is imposed by the constraints. The returned value is a compound integer, |
| 15687 | * with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and |
| 15688 | * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting |
| 15689 | * 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] | 15690 | * |
| 15691 | * @param size How big the view wants to be |
| 15692 | * @param measureSpec Constraints imposed by the parent |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15693 | * @return Size information bit mask as defined by |
| 15694 | * {@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] | 15695 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15696 | 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] | 15697 | int result = size; |
| 15698 | int specMode = MeasureSpec.getMode(measureSpec); |
| 15699 | int specSize = MeasureSpec.getSize(measureSpec); |
| 15700 | switch (specMode) { |
| 15701 | case MeasureSpec.UNSPECIFIED: |
| 15702 | result = size; |
| 15703 | break; |
| 15704 | case MeasureSpec.AT_MOST: |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15705 | if (specSize < size) { |
| 15706 | result = specSize | MEASURED_STATE_TOO_SMALL; |
| 15707 | } else { |
| 15708 | result = size; |
| 15709 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15710 | break; |
| 15711 | case MeasureSpec.EXACTLY: |
| 15712 | result = specSize; |
| 15713 | break; |
| 15714 | } |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15715 | return result | (childMeasuredState&MEASURED_STATE_MASK); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15716 | } |
| 15717 | |
| 15718 | /** |
| 15719 | * Utility to return a default size. Uses the supplied size if the |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 15720 | * MeasureSpec imposed no constraints. Will get larger if allowed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15721 | * by the MeasureSpec. |
| 15722 | * |
| 15723 | * @param size Default size for this view |
| 15724 | * @param measureSpec Constraints imposed by the parent |
| 15725 | * @return The size this view should be. |
| 15726 | */ |
| 15727 | public static int getDefaultSize(int size, int measureSpec) { |
| 15728 | int result = size; |
| 15729 | int specMode = MeasureSpec.getMode(measureSpec); |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 15730 | int specSize = MeasureSpec.getSize(measureSpec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15731 | |
| 15732 | switch (specMode) { |
| 15733 | case MeasureSpec.UNSPECIFIED: |
| 15734 | result = size; |
| 15735 | break; |
| 15736 | case MeasureSpec.AT_MOST: |
| 15737 | case MeasureSpec.EXACTLY: |
| 15738 | result = specSize; |
| 15739 | break; |
| 15740 | } |
| 15741 | return result; |
| 15742 | } |
| 15743 | |
| 15744 | /** |
| 15745 | * Returns the suggested minimum height that the view should use. This |
| 15746 | * returns the maximum of the view's minimum height |
| 15747 | * and the background's minimum height |
| 15748 | * ({@link android.graphics.drawable.Drawable#getMinimumHeight()}). |
| 15749 | * <p> |
| 15750 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 15751 | * ensure the returned height is within the requirements of the parent. |
| 15752 | * |
| 15753 | * @return The suggested minimum height of the view. |
| 15754 | */ |
| 15755 | protected int getSuggestedMinimumHeight() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15756 | return (mBackground == null) ? mMinHeight : max(mMinHeight, mBackground.getMinimumHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15758 | } |
| 15759 | |
| 15760 | /** |
| 15761 | * Returns the suggested minimum width that the view should use. This |
| 15762 | * returns the maximum of the view's minimum width) |
| 15763 | * and the background's minimum width |
| 15764 | * ({@link android.graphics.drawable.Drawable#getMinimumWidth()}). |
| 15765 | * <p> |
| 15766 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 15767 | * ensure the returned width is within the requirements of the parent. |
| 15768 | * |
| 15769 | * @return The suggested minimum width of the view. |
| 15770 | */ |
| 15771 | protected int getSuggestedMinimumWidth() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15772 | return (mBackground == null) ? mMinWidth : max(mMinWidth, mBackground.getMinimumWidth()); |
| 15773 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15774 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15775 | /** |
| 15776 | * Returns the minimum height of the view. |
| 15777 | * |
| 15778 | * @return the minimum height the view will try to be. |
| 15779 | * |
| 15780 | * @see #setMinimumHeight(int) |
| 15781 | * |
| 15782 | * @attr ref android.R.styleable#View_minHeight |
| 15783 | */ |
| 15784 | public int getMinimumHeight() { |
| 15785 | return mMinHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15786 | } |
| 15787 | |
| 15788 | /** |
| 15789 | * Sets the minimum height of the view. It is not guaranteed the view will |
| 15790 | * be able to achieve this minimum height (for example, if its parent layout |
| 15791 | * constrains it with less available height). |
| 15792 | * |
| 15793 | * @param minHeight The minimum height the view will try to be. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15794 | * |
| 15795 | * @see #getMinimumHeight() |
| 15796 | * |
| 15797 | * @attr ref android.R.styleable#View_minHeight |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15798 | */ |
| 15799 | public void setMinimumHeight(int minHeight) { |
| 15800 | mMinHeight = minHeight; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15801 | requestLayout(); |
| 15802 | } |
| 15803 | |
| 15804 | /** |
| 15805 | * Returns the minimum width of the view. |
| 15806 | * |
| 15807 | * @return the minimum width the view will try to be. |
| 15808 | * |
| 15809 | * @see #setMinimumWidth(int) |
| 15810 | * |
| 15811 | * @attr ref android.R.styleable#View_minWidth |
| 15812 | */ |
| 15813 | public int getMinimumWidth() { |
| 15814 | return mMinWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15815 | } |
| 15816 | |
| 15817 | /** |
| 15818 | * Sets the minimum width of the view. It is not guaranteed the view will |
| 15819 | * be able to achieve this minimum width (for example, if its parent layout |
| 15820 | * constrains it with less available width). |
| 15821 | * |
| 15822 | * @param minWidth The minimum width the view will try to be. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15823 | * |
| 15824 | * @see #getMinimumWidth() |
| 15825 | * |
| 15826 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15827 | */ |
| 15828 | public void setMinimumWidth(int minWidth) { |
| 15829 | mMinWidth = minWidth; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15830 | requestLayout(); |
| 15831 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15832 | } |
| 15833 | |
| 15834 | /** |
| 15835 | * Get the animation currently associated with this view. |
| 15836 | * |
| 15837 | * @return The animation that is currently playing or |
| 15838 | * scheduled to play for this view. |
| 15839 | */ |
| 15840 | public Animation getAnimation() { |
| 15841 | return mCurrentAnimation; |
| 15842 | } |
| 15843 | |
| 15844 | /** |
| 15845 | * Start the specified animation now. |
| 15846 | * |
| 15847 | * @param animation the animation to start now |
| 15848 | */ |
| 15849 | public void startAnimation(Animation animation) { |
| 15850 | animation.setStartTime(Animation.START_ON_FIRST_FRAME); |
| 15851 | setAnimation(animation); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 15852 | invalidateParentCaches(); |
| 15853 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15854 | } |
| 15855 | |
| 15856 | /** |
| 15857 | * Cancels any animations for this view. |
| 15858 | */ |
| 15859 | public void clearAnimation() { |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 15860 | if (mCurrentAnimation != null) { |
Romain Guy | b4a107d | 2010-02-09 18:50:08 -0800 | [diff] [blame] | 15861 | mCurrentAnimation.detach(); |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 15862 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15863 | mCurrentAnimation = null; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 15864 | invalidateParentIfNeeded(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15865 | } |
| 15866 | |
| 15867 | /** |
| 15868 | * Sets the next animation to play for this view. |
| 15869 | * If you want the animation to play immediately, use |
Chet Haase | 4242893 | 2012-05-11 15:39:07 -0700 | [diff] [blame] | 15870 | * {@link #startAnimation(android.view.animation.Animation)} instead. |
| 15871 | * This method provides allows fine-grained |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15872 | * control over the start time and invalidation, but you |
| 15873 | * must make sure that 1) the animation has a start time set, and |
Chet Haase | 4242893 | 2012-05-11 15:39:07 -0700 | [diff] [blame] | 15874 | * 2) the view's parent (which controls animations on its children) |
| 15875 | * will be invalidated when the animation is supposed to |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15876 | * start. |
| 15877 | * |
| 15878 | * @param animation The next animation, or null. |
| 15879 | */ |
| 15880 | public void setAnimation(Animation animation) { |
| 15881 | mCurrentAnimation = animation; |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 15882 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15883 | if (animation != null) { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 15884 | // If the screen is off assume the animation start time is now instead of |
| 15885 | // the next frame we draw. Keeping the START_ON_FIRST_FRAME start time |
| 15886 | // would cause the animation to start when the screen turns back on |
| 15887 | if (mAttachInfo != null && !mAttachInfo.mScreenOn && |
| 15888 | animation.getStartTime() == Animation.START_ON_FIRST_FRAME) { |
| 15889 | animation.setStartTime(AnimationUtils.currentAnimationTimeMillis()); |
| 15890 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15891 | animation.reset(); |
| 15892 | } |
| 15893 | } |
| 15894 | |
| 15895 | /** |
| 15896 | * Invoked by a parent ViewGroup to notify the start of the animation |
| 15897 | * currently associated with this view. If you override this method, |
| 15898 | * always call super.onAnimationStart(); |
| 15899 | * |
| 15900 | * @see #setAnimation(android.view.animation.Animation) |
| 15901 | * @see #getAnimation() |
| 15902 | */ |
| 15903 | protected void onAnimationStart() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15904 | mPrivateFlags |= PFLAG_ANIMATION_STARTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15905 | } |
| 15906 | |
| 15907 | /** |
| 15908 | * Invoked by a parent ViewGroup to notify the end of the animation |
| 15909 | * currently associated with this view. If you override this method, |
| 15910 | * always call super.onAnimationEnd(); |
| 15911 | * |
| 15912 | * @see #setAnimation(android.view.animation.Animation) |
| 15913 | * @see #getAnimation() |
| 15914 | */ |
| 15915 | protected void onAnimationEnd() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15916 | mPrivateFlags &= ~PFLAG_ANIMATION_STARTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15917 | } |
| 15918 | |
| 15919 | /** |
| 15920 | * Invoked if there is a Transform that involves alpha. Subclass that can |
| 15921 | * draw themselves with the specified alpha should return true, and then |
| 15922 | * respect that alpha when their onDraw() is called. If this returns false |
| 15923 | * then the view may be redirected to draw into an offscreen buffer to |
| 15924 | * fulfill the request, which will look fine, but may be slower than if the |
| 15925 | * subclass handles it internally. The default implementation returns false. |
| 15926 | * |
| 15927 | * @param alpha The alpha (0..255) to apply to the view's drawing |
| 15928 | * @return true if the view can draw with the specified alpha. |
| 15929 | */ |
| 15930 | protected boolean onSetAlpha(int alpha) { |
| 15931 | return false; |
| 15932 | } |
| 15933 | |
| 15934 | /** |
| 15935 | * This is used by the RootView to perform an optimization when |
| 15936 | * the view hierarchy contains one or several SurfaceView. |
| 15937 | * SurfaceView is always considered transparent, but its children are not, |
| 15938 | * therefore all View objects remove themselves from the global transparent |
| 15939 | * region (passed as a parameter to this function). |
| 15940 | * |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 15941 | * @param region The transparent region for this ViewAncestor (window). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15942 | * |
| 15943 | * @return Returns true if the effective visibility of the view at this |
| 15944 | * point is opaque, regardless of the transparent region; returns false |
| 15945 | * if it is possible for underlying windows to be seen behind the view. |
| 15946 | * |
| 15947 | * {@hide} |
| 15948 | */ |
| 15949 | public boolean gatherTransparentRegion(Region region) { |
| 15950 | final AttachInfo attachInfo = mAttachInfo; |
| 15951 | if (region != null && attachInfo != null) { |
| 15952 | final int pflags = mPrivateFlags; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15953 | if ((pflags & PFLAG_SKIP_DRAW) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15954 | // The SKIP_DRAW flag IS NOT set, so this view draws. We need to |
| 15955 | // remove it from the transparent region. |
| 15956 | final int[] location = attachInfo.mTransparentLocation; |
| 15957 | getLocationInWindow(location); |
| 15958 | region.op(location[0], location[1], location[0] + mRight - mLeft, |
| 15959 | location[1] + mBottom - mTop, Region.Op.DIFFERENCE); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15960 | } else if ((pflags & PFLAG_ONLY_DRAWS_BACKGROUND) != 0 && mBackground != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15961 | // The ONLY_DRAWS_BACKGROUND flag IS set and the background drawable |
| 15962 | // exists, so we remove the background drawable's non-transparent |
| 15963 | // parts from this transparent region. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15964 | applyDrawableToTransparentRegion(mBackground, region); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15965 | } |
| 15966 | } |
| 15967 | return true; |
| 15968 | } |
| 15969 | |
| 15970 | /** |
| 15971 | * Play a sound effect for this view. |
| 15972 | * |
| 15973 | * <p>The framework will play sound effects for some built in actions, such as |
| 15974 | * clicking, but you may wish to play these effects in your widget, |
| 15975 | * for instance, for internal navigation. |
| 15976 | * |
| 15977 | * <p>The sound effect will only be played if sound effects are enabled by the user, and |
| 15978 | * {@link #isSoundEffectsEnabled()} is true. |
| 15979 | * |
| 15980 | * @param soundConstant One of the constants defined in {@link SoundEffectConstants} |
| 15981 | */ |
| 15982 | public void playSoundEffect(int soundConstant) { |
| 15983 | if (mAttachInfo == null || mAttachInfo.mRootCallbacks == null || !isSoundEffectsEnabled()) { |
| 15984 | return; |
| 15985 | } |
| 15986 | mAttachInfo.mRootCallbacks.playSoundEffect(soundConstant); |
| 15987 | } |
| 15988 | |
| 15989 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15990 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15991 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15992 | * <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] | 15993 | * |
| 15994 | * <p>The framework will provide haptic feedback for some built in actions, |
| 15995 | * such as long presses, but you may wish to provide feedback for your |
| 15996 | * own widget. |
| 15997 | * |
| 15998 | * <p>The feedback will only be performed if |
| 15999 | * {@link #isHapticFeedbackEnabled()} is true. |
| 16000 | * |
| 16001 | * @param feedbackConstant One of the constants defined in |
| 16002 | * {@link HapticFeedbackConstants} |
| 16003 | */ |
| 16004 | public boolean performHapticFeedback(int feedbackConstant) { |
| 16005 | return performHapticFeedback(feedbackConstant, 0); |
| 16006 | } |
| 16007 | |
| 16008 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 16009 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 16010 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 16011 | * <p>Like {@link #performHapticFeedback(int)}, with additional options. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16012 | * |
| 16013 | * @param feedbackConstant One of the constants defined in |
| 16014 | * {@link HapticFeedbackConstants} |
| 16015 | * @param flags Additional flags as per {@link HapticFeedbackConstants}. |
| 16016 | */ |
| 16017 | public boolean performHapticFeedback(int feedbackConstant, int flags) { |
| 16018 | if (mAttachInfo == null) { |
| 16019 | return false; |
| 16020 | } |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 16021 | //noinspection SimplifiableIfStatement |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 16022 | if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16023 | && !isHapticFeedbackEnabled()) { |
| 16024 | return false; |
| 16025 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 16026 | return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant, |
| 16027 | (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16028 | } |
| 16029 | |
| 16030 | /** |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 16031 | * Request that the visibility of the status bar or other screen/window |
| 16032 | * decorations be changed. |
| 16033 | * |
| 16034 | * <p>This method is used to put the over device UI into temporary modes |
| 16035 | * where the user's attention is focused more on the application content, |
| 16036 | * by dimming or hiding surrounding system affordances. This is typically |
| 16037 | * used in conjunction with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 16038 | * Window.FEATURE_ACTION_BAR_OVERLAY}, allowing the applications content |
| 16039 | * to be placed behind the action bar (and with these flags other system |
| 16040 | * affordances) so that smooth transitions between hiding and showing them |
| 16041 | * can be done. |
| 16042 | * |
| 16043 | * <p>Two representative examples of the use of system UI visibility is |
| 16044 | * implementing a content browsing application (like a magazine reader) |
| 16045 | * and a video playing application. |
| 16046 | * |
| 16047 | * <p>The first code shows a typical implementation of a View in a content |
| 16048 | * browsing application. In this implementation, the application goes |
| 16049 | * into a content-oriented mode by hiding the status bar and action bar, |
| 16050 | * and putting the navigation elements into lights out mode. The user can |
| 16051 | * then interact with content while in this mode. Such an application should |
| 16052 | * provide an easy way for the user to toggle out of the mode (such as to |
| 16053 | * check information in the status bar or access notifications). In the |
| 16054 | * implementation here, this is done simply by tapping on the content. |
| 16055 | * |
| 16056 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/view/ContentBrowserActivity.java |
| 16057 | * content} |
| 16058 | * |
| 16059 | * <p>This second code sample shows a typical implementation of a View |
| 16060 | * in a video playing application. In this situation, while the video is |
| 16061 | * playing the application would like to go into a complete full-screen mode, |
| 16062 | * to use as much of the display as possible for the video. When in this state |
| 16063 | * the user can not interact with the application; the system intercepts |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 16064 | * touching on the screen to pop the UI out of full screen mode. See |
| 16065 | * {@link #fitSystemWindows(Rect)} for a sample layout that goes with this code. |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 16066 | * |
| 16067 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/view/VideoPlayerActivity.java |
| 16068 | * content} |
| 16069 | * |
| 16070 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 16071 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN}, |
| 16072 | * {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, |
| 16073 | * and {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16074 | */ |
| 16075 | public void setSystemUiVisibility(int visibility) { |
Daniel Sandler | 7052406 | 2011-09-21 00:30:47 -0400 | [diff] [blame] | 16076 | if (visibility != mSystemUiVisibility) { |
| 16077 | mSystemUiVisibility = visibility; |
| 16078 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 16079 | mParent.recomputeViewAttributes(this); |
| 16080 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16081 | } |
| 16082 | } |
| 16083 | |
| 16084 | /** |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 16085 | * Returns the last {@link #setSystemUiVisibility(int) that this view has requested. |
| 16086 | * @return Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 16087 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN}, |
| 16088 | * {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, |
| 16089 | * and {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16090 | */ |
Joe Onorato | e595cad | 2011-01-24 09:22:12 -0800 | [diff] [blame] | 16091 | public int getSystemUiVisibility() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16092 | return mSystemUiVisibility; |
| 16093 | } |
| 16094 | |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 16095 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 16096 | * Returns the current system UI visibility that is currently set for |
| 16097 | * the entire window. This is the combination of the |
| 16098 | * {@link #setSystemUiVisibility(int)} values supplied by all of the |
| 16099 | * views in the window. |
| 16100 | */ |
| 16101 | public int getWindowSystemUiVisibility() { |
| 16102 | return mAttachInfo != null ? mAttachInfo.mSystemUiVisibility : 0; |
| 16103 | } |
| 16104 | |
| 16105 | /** |
| 16106 | * Override to find out when the window's requested system UI visibility |
| 16107 | * has changed, that is the value returned by {@link #getWindowSystemUiVisibility()}. |
| 16108 | * This is different from the callbacks recieved through |
| 16109 | * {@link #setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener)} |
| 16110 | * in that this is only telling you about the local request of the window, |
| 16111 | * not the actual values applied by the system. |
| 16112 | */ |
| 16113 | public void onWindowSystemUiVisibilityChanged(int visible) { |
| 16114 | } |
| 16115 | |
| 16116 | /** |
| 16117 | * Dispatch callbacks to {@link #onWindowSystemUiVisibilityChanged(int)} down |
| 16118 | * the view hierarchy. |
| 16119 | */ |
| 16120 | public void dispatchWindowSystemUiVisiblityChanged(int visible) { |
| 16121 | onWindowSystemUiVisibilityChanged(visible); |
| 16122 | } |
| 16123 | |
| 16124 | /** |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 16125 | * Set a listener to receive callbacks when the visibility of the system bar changes. |
| 16126 | * @param l The {@link OnSystemUiVisibilityChangeListener} to receive callbacks. |
| 16127 | */ |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16128 | public void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 16129 | getListenerInfo().mOnSystemUiVisibilityChangeListener = l; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16130 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 16131 | mParent.recomputeViewAttributes(this); |
| 16132 | } |
| 16133 | } |
| 16134 | |
| 16135 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16136 | * Dispatch callbacks to {@link #setOnSystemUiVisibilityChangeListener} down |
| 16137 | * the view hierarchy. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16138 | */ |
| 16139 | public void dispatchSystemUiVisibilityChanged(int visibility) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 16140 | ListenerInfo li = mListenerInfo; |
| 16141 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
| 16142 | li.mOnSystemUiVisibilityChangeListener.onSystemUiVisibilityChange( |
Joe Onorato | 6ab77bd | 2011-01-31 11:21:10 -0800 | [diff] [blame] | 16143 | visibility & PUBLIC_STATUS_BAR_VISIBILITY_MASK); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16144 | } |
| 16145 | } |
| 16146 | |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 16147 | boolean updateLocalSystemUiVisibility(int localValue, int localChanges) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16148 | int val = (mSystemUiVisibility&~localChanges) | (localValue&localChanges); |
| 16149 | if (val != mSystemUiVisibility) { |
| 16150 | setSystemUiVisibility(val); |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 16151 | return true; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16152 | } |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 16153 | return false; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16154 | } |
| 16155 | |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 16156 | /** @hide */ |
| 16157 | public void setDisabledSystemUiVisibility(int flags) { |
| 16158 | if (mAttachInfo != null) { |
| 16159 | if (mAttachInfo.mDisabledSystemUiVisibility != flags) { |
| 16160 | mAttachInfo.mDisabledSystemUiVisibility = flags; |
| 16161 | if (mParent != null) { |
| 16162 | mParent.recomputeViewAttributes(this); |
| 16163 | } |
| 16164 | } |
| 16165 | } |
| 16166 | } |
| 16167 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16168 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16169 | * Creates an image that the system displays during the drag and drop |
| 16170 | * operation. This is called a "drag shadow". The default implementation |
| 16171 | * for a DragShadowBuilder based on a View returns an image that has exactly the same |
| 16172 | * appearance as the given View. The default also positions the center of the drag shadow |
| 16173 | * directly under the touch point. If no View is provided (the constructor with no parameters |
| 16174 | * is used), and {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} and |
| 16175 | * {@link #onDrawShadow(Canvas) onDrawShadow()} are not overriden, then the |
| 16176 | * default is an invisible drag shadow. |
| 16177 | * <p> |
| 16178 | * You are not required to use the View you provide to the constructor as the basis of the |
| 16179 | * drag shadow. The {@link #onDrawShadow(Canvas) onDrawShadow()} method allows you to draw |
| 16180 | * anything you want as the drag shadow. |
| 16181 | * </p> |
| 16182 | * <p> |
| 16183 | * You pass a DragShadowBuilder object to the system when you start the drag. The system |
| 16184 | * calls {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} to get the |
| 16185 | * size and position of the drag shadow. It uses this data to construct a |
| 16186 | * {@link android.graphics.Canvas} object, then it calls {@link #onDrawShadow(Canvas) onDrawShadow()} |
| 16187 | * so that your application can draw the shadow image in the Canvas. |
| 16188 | * </p> |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 16189 | * |
| 16190 | * <div class="special reference"> |
| 16191 | * <h3>Developer Guides</h3> |
| 16192 | * <p>For a guide to implementing drag and drop features, read the |
| 16193 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 16194 | * </div> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16195 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16196 | public static class DragShadowBuilder { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16197 | private final WeakReference<View> mView; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16198 | |
| 16199 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16200 | * Constructs a shadow image builder based on a View. By default, the resulting drag |
| 16201 | * shadow will have the same appearance and dimensions as the View, with the touch point |
| 16202 | * over the center of the View. |
| 16203 | * @param view A View. Any View in scope can be used. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16204 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16205 | public DragShadowBuilder(View view) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16206 | mView = new WeakReference<View>(view); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16207 | } |
| 16208 | |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 16209 | /** |
| 16210 | * Construct a shadow builder object with no associated View. This |
| 16211 | * constructor variant is only useful when the {@link #onProvideShadowMetrics(Point, Point)} |
| 16212 | * and {@link #onDrawShadow(Canvas)} methods are also overridden in order |
| 16213 | * to supply the drag shadow's dimensions and appearance without |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16214 | * reference to any View object. If they are not overridden, then the result is an |
| 16215 | * invisible drag shadow. |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 16216 | */ |
| 16217 | public DragShadowBuilder() { |
| 16218 | mView = new WeakReference<View>(null); |
| 16219 | } |
| 16220 | |
| 16221 | /** |
| 16222 | * Returns the View object that had been passed to the |
| 16223 | * {@link #View.DragShadowBuilder(View)} |
| 16224 | * constructor. If that View parameter was {@code null} or if the |
| 16225 | * {@link #View.DragShadowBuilder()} |
| 16226 | * constructor was used to instantiate the builder object, this method will return |
| 16227 | * null. |
| 16228 | * |
| 16229 | * @return The View object associate with this builder object. |
| 16230 | */ |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 16231 | @SuppressWarnings({"JavadocReference"}) |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 16232 | final public View getView() { |
| 16233 | return mView.get(); |
| 16234 | } |
| 16235 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16236 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16237 | * Provides the metrics for the shadow image. These include the dimensions of |
| 16238 | * the shadow image, and the point within that shadow that should |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16239 | * be centered under the touch location while dragging. |
| 16240 | * <p> |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16241 | * The default implementation sets the dimensions of the shadow to be the |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16242 | * same as the dimensions of the View itself and centers the shadow under |
| 16243 | * the touch point. |
| 16244 | * </p> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16245 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16246 | * @param shadowSize A {@link android.graphics.Point} containing the width and height |
| 16247 | * of the shadow image. Your application must set {@link android.graphics.Point#x} to the |
| 16248 | * desired width and must set {@link android.graphics.Point#y} to the desired height of the |
| 16249 | * image. |
| 16250 | * |
| 16251 | * @param shadowTouchPoint A {@link android.graphics.Point} for the position within the |
| 16252 | * shadow image that should be underneath the touch point during the drag and drop |
| 16253 | * operation. Your application must set {@link android.graphics.Point#x} to the |
| 16254 | * 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] | 16255 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16256 | public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16257 | final View view = mView.get(); |
| 16258 | if (view != null) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16259 | shadowSize.set(view.getWidth(), view.getHeight()); |
| 16260 | shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2); |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16261 | } else { |
| 16262 | Log.e(View.VIEW_LOG_TAG, "Asked for drag thumb metrics but no view"); |
| 16263 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16264 | } |
| 16265 | |
| 16266 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16267 | * Draws the shadow image. The system creates the {@link android.graphics.Canvas} object |
| 16268 | * based on the dimensions it received from the |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16269 | * {@link #onProvideShadowMetrics(Point, Point)} callback. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16270 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16271 | * @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] | 16272 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16273 | public void onDrawShadow(Canvas canvas) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16274 | final View view = mView.get(); |
| 16275 | if (view != null) { |
| 16276 | view.draw(canvas); |
| 16277 | } else { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16278 | 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] | 16279 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16280 | } |
| 16281 | } |
| 16282 | |
| 16283 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16284 | * Starts a drag and drop operation. When your application calls this method, it passes a |
| 16285 | * {@link android.view.View.DragShadowBuilder} object to the system. The |
| 16286 | * system calls this object's {@link DragShadowBuilder#onProvideShadowMetrics(Point, Point)} |
| 16287 | * to get metrics for the drag shadow, and then calls the object's |
| 16288 | * {@link DragShadowBuilder#onDrawShadow(Canvas)} to draw the drag shadow itself. |
| 16289 | * <p> |
| 16290 | * Once the system has the drag shadow, it begins the drag and drop operation by sending |
| 16291 | * drag events to all the View objects in your application that are currently visible. It does |
| 16292 | * this either by calling the View object's drag listener (an implementation of |
| 16293 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent) onDrag()} or by calling the |
| 16294 | * View object's {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} method. |
| 16295 | * Both are passed a {@link android.view.DragEvent} object that has a |
| 16296 | * {@link android.view.DragEvent#getAction()} value of |
| 16297 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED}. |
| 16298 | * </p> |
| 16299 | * <p> |
| 16300 | * Your application can invoke startDrag() on any attached View object. The View object does not |
| 16301 | * need to be the one used in {@link android.view.View.DragShadowBuilder}, nor does it need to |
| 16302 | * be related to the View the user selected for dragging. |
| 16303 | * </p> |
| 16304 | * @param data A {@link android.content.ClipData} object pointing to the data to be |
| 16305 | * transferred by the drag and drop operation. |
| 16306 | * @param shadowBuilder A {@link android.view.View.DragShadowBuilder} object for building the |
| 16307 | * drag shadow. |
| 16308 | * @param myLocalState An {@link java.lang.Object} containing local data about the drag and |
| 16309 | * drop operation. This Object is put into every DragEvent object sent by the system during the |
| 16310 | * current drag. |
| 16311 | * <p> |
| 16312 | * myLocalState is a lightweight mechanism for the sending information from the dragged View |
| 16313 | * to the target Views. For example, it can contain flags that differentiate between a |
| 16314 | * a copy operation and a move operation. |
| 16315 | * </p> |
| 16316 | * @param flags Flags that control the drag and drop operation. No flags are currently defined, |
| 16317 | * so the parameter should be set to 0. |
| 16318 | * @return {@code true} if the method completes successfully, or |
| 16319 | * {@code false} if it fails anywhere. Returning {@code false} means the system was unable to |
| 16320 | * do a drag, and so no drag operation is in progress. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16321 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16322 | public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 16323 | Object myLocalState, int flags) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16324 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 16325 | Log.d(VIEW_LOG_TAG, "startDrag: data=" + data + " flags=" + flags); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16326 | } |
| 16327 | boolean okay = false; |
| 16328 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16329 | Point shadowSize = new Point(); |
| 16330 | Point shadowTouchPoint = new Point(); |
| 16331 | shadowBuilder.onProvideShadowMetrics(shadowSize, shadowTouchPoint); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16332 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16333 | if ((shadowSize.x < 0) || (shadowSize.y < 0) || |
| 16334 | (shadowTouchPoint.x < 0) || (shadowTouchPoint.y < 0)) { |
| 16335 | throw new IllegalStateException("Drag shadow dimensions must not be negative"); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16336 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16337 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 16338 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16339 | Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y |
| 16340 | + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 16341 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16342 | Surface surface = new Surface(); |
| 16343 | try { |
| 16344 | IBinder token = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 16345 | flags, shadowSize.x, shadowSize.y, surface); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16346 | 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] | 16347 | + " surface=" + surface); |
| 16348 | if (token != null) { |
| 16349 | Canvas canvas = surface.lockCanvas(null); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 16350 | try { |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 16351 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16352 | shadowBuilder.onDrawShadow(canvas); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 16353 | } finally { |
| 16354 | surface.unlockCanvasAndPost(canvas); |
| 16355 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16356 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 16357 | final ViewRootImpl root = getViewRootImpl(); |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 16358 | |
| 16359 | // Cache the local state object for delivery with DragEvents |
| 16360 | root.setLocalDragState(myLocalState); |
| 16361 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16362 | // repurpose 'shadowSize' for the last touch point |
| 16363 | root.getLastTouchPoint(shadowSize); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16364 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16365 | okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token, |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16366 | shadowSize.x, shadowSize.y, |
| 16367 | shadowTouchPoint.x, shadowTouchPoint.y, data); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16368 | if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay); |
Christopher Tate | 8f73b5d | 2011-09-12 15:22:12 -0700 | [diff] [blame] | 16369 | |
| 16370 | // Off and running! Release our local surface instance; the drag |
| 16371 | // shadow surface is now managed by the system process. |
| 16372 | surface.release(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16373 | } |
| 16374 | } catch (Exception e) { |
| 16375 | Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e); |
| 16376 | surface.destroy(); |
| 16377 | } |
| 16378 | |
| 16379 | return okay; |
| 16380 | } |
| 16381 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16382 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16383 | * Handles drag events sent by the system following a call to |
| 16384 | * {@link android.view.View#startDrag(ClipData,DragShadowBuilder,Object,int) startDrag()}. |
| 16385 | *<p> |
| 16386 | * When the system calls this method, it passes a |
| 16387 | * {@link android.view.DragEvent} object. A call to |
| 16388 | * {@link android.view.DragEvent#getAction()} returns one of the action type constants defined |
| 16389 | * in DragEvent. The method uses these to determine what is happening in the drag and drop |
| 16390 | * operation. |
| 16391 | * @param event The {@link android.view.DragEvent} sent by the system. |
| 16392 | * The {@link android.view.DragEvent#getAction()} method returns an action type constant defined |
| 16393 | * in DragEvent, indicating the type of drag event represented by this object. |
| 16394 | * @return {@code true} if the method was successful, otherwise {@code false}. |
| 16395 | * <p> |
| 16396 | * The method should return {@code true} in response to an action type of |
| 16397 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED} to receive drag events for the current |
| 16398 | * operation. |
| 16399 | * </p> |
| 16400 | * <p> |
| 16401 | * The method should also return {@code true} in response to an action type of |
| 16402 | * {@link android.view.DragEvent#ACTION_DROP} if it consumed the drop, or |
| 16403 | * {@code false} if it didn't. |
| 16404 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16405 | */ |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 16406 | public boolean onDragEvent(DragEvent event) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16407 | return false; |
| 16408 | } |
| 16409 | |
| 16410 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16411 | * Detects if this View is enabled and has a drag event listener. |
| 16412 | * If both are true, then it calls the drag event listener with the |
| 16413 | * {@link android.view.DragEvent} it received. If the drag event listener returns |
| 16414 | * {@code true}, then dispatchDragEvent() returns {@code true}. |
| 16415 | * <p> |
| 16416 | * For all other cases, the method calls the |
| 16417 | * {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} drag event handler |
| 16418 | * method and returns its result. |
| 16419 | * </p> |
| 16420 | * <p> |
| 16421 | * This ensures that a drag event is always consumed, even if the View does not have a drag |
| 16422 | * event listener. However, if the View has a listener and the listener returns true, then |
| 16423 | * onDragEvent() is not called. |
| 16424 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16425 | */ |
| 16426 | public boolean dispatchDragEvent(DragEvent event) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 16427 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 16428 | ListenerInfo li = mListenerInfo; |
| 16429 | if (li != null && li.mOnDragListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 16430 | && li.mOnDragListener.onDrag(this, event)) { |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 16431 | return true; |
| 16432 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16433 | return onDragEvent(event); |
| 16434 | } |
| 16435 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 16436 | boolean canAcceptDrag() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16437 | return (mPrivateFlags2 & PFLAG2_DRAG_CAN_ACCEPT) != 0; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 16438 | } |
| 16439 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16440 | /** |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 16441 | * This needs to be a better API (NOT ON VIEW) before it is exposed. If |
| 16442 | * it is ever exposed at all. |
Dianne Hackborn | 29e4a3c | 2009-09-30 22:35:40 -0700 | [diff] [blame] | 16443 | * @hide |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 16444 | */ |
| 16445 | public void onCloseSystemDialogs(String reason) { |
| 16446 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16447 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 16448 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16449 | * 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] | 16450 | * update a Region being computed for |
| 16451 | * {@link #gatherTransparentRegion(android.graphics.Region)} so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16452 | * that any non-transparent parts of the Drawable are removed from the |
| 16453 | * given transparent region. |
| 16454 | * |
| 16455 | * @param dr The Drawable whose transparency is to be applied to the region. |
| 16456 | * @param region A Region holding the current transparency information, |
| 16457 | * where any parts of the region that are set are considered to be |
| 16458 | * transparent. On return, this region will be modified to have the |
| 16459 | * transparency information reduced by the corresponding parts of the |
| 16460 | * Drawable that are not transparent. |
| 16461 | * {@hide} |
| 16462 | */ |
| 16463 | public void applyDrawableToTransparentRegion(Drawable dr, Region region) { |
| 16464 | if (DBG) { |
| 16465 | Log.i("View", "Getting transparent region for: " + this); |
| 16466 | } |
| 16467 | final Region r = dr.getTransparentRegion(); |
| 16468 | final Rect db = dr.getBounds(); |
| 16469 | final AttachInfo attachInfo = mAttachInfo; |
| 16470 | if (r != null && attachInfo != null) { |
| 16471 | final int w = getRight()-getLeft(); |
| 16472 | final int h = getBottom()-getTop(); |
| 16473 | if (db.left > 0) { |
| 16474 | //Log.i("VIEW", "Drawable left " + db.left + " > view 0"); |
| 16475 | r.op(0, 0, db.left, h, Region.Op.UNION); |
| 16476 | } |
| 16477 | if (db.right < w) { |
| 16478 | //Log.i("VIEW", "Drawable right " + db.right + " < view " + w); |
| 16479 | r.op(db.right, 0, w, h, Region.Op.UNION); |
| 16480 | } |
| 16481 | if (db.top > 0) { |
| 16482 | //Log.i("VIEW", "Drawable top " + db.top + " > view 0"); |
| 16483 | r.op(0, 0, w, db.top, Region.Op.UNION); |
| 16484 | } |
| 16485 | if (db.bottom < h) { |
| 16486 | //Log.i("VIEW", "Drawable bottom " + db.bottom + " < view " + h); |
| 16487 | r.op(0, db.bottom, w, h, Region.Op.UNION); |
| 16488 | } |
| 16489 | final int[] location = attachInfo.mTransparentLocation; |
| 16490 | getLocationInWindow(location); |
| 16491 | r.translate(location[0], location[1]); |
| 16492 | region.op(r, Region.Op.INTERSECT); |
| 16493 | } else { |
| 16494 | region.op(db, Region.Op.DIFFERENCE); |
| 16495 | } |
| 16496 | } |
| 16497 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 16498 | private void checkForLongClick(int delayOffset) { |
| 16499 | if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) { |
| 16500 | mHasPerformedLongPress = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16501 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 16502 | if (mPendingCheckForLongPress == null) { |
| 16503 | mPendingCheckForLongPress = new CheckForLongPress(); |
| 16504 | } |
| 16505 | mPendingCheckForLongPress.rememberWindowAttachCount(); |
| 16506 | postDelayed(mPendingCheckForLongPress, |
| 16507 | ViewConfiguration.getLongPressTimeout() - delayOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16508 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16509 | } |
| 16510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16511 | /** |
| 16512 | * Inflate a view from an XML resource. This convenience method wraps the {@link |
| 16513 | * LayoutInflater} class, which provides a full range of options for view inflation. |
| 16514 | * |
| 16515 | * @param context The Context object for your activity or application. |
| 16516 | * @param resource The resource ID to inflate |
| 16517 | * @param root A view group that will be the parent. Used to properly inflate the |
| 16518 | * layout_* parameters. |
| 16519 | * @see LayoutInflater |
| 16520 | */ |
| 16521 | public static View inflate(Context context, int resource, ViewGroup root) { |
| 16522 | LayoutInflater factory = LayoutInflater.from(context); |
| 16523 | return factory.inflate(resource, root); |
| 16524 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 16525 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16526 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 16527 | * Scroll the view with standard behavior for scrolling beyond the normal |
| 16528 | * content boundaries. Views that call this method should override |
| 16529 | * {@link #onOverScrolled(int, int, boolean, boolean)} to respond to the |
| 16530 | * results of an over-scroll operation. |
| 16531 | * |
| 16532 | * Views can use this method to handle any touch or fling-based scrolling. |
| 16533 | * |
| 16534 | * @param deltaX Change in X in pixels |
| 16535 | * @param deltaY Change in Y in pixels |
| 16536 | * @param scrollX Current X scroll value in pixels before applying deltaX |
| 16537 | * @param scrollY Current Y scroll value in pixels before applying deltaY |
| 16538 | * @param scrollRangeX Maximum content scroll range along the X axis |
| 16539 | * @param scrollRangeY Maximum content scroll range along the Y axis |
| 16540 | * @param maxOverScrollX Number of pixels to overscroll by in either direction |
| 16541 | * along the X axis. |
| 16542 | * @param maxOverScrollY Number of pixels to overscroll by in either direction |
| 16543 | * along the Y axis. |
| 16544 | * @param isTouchEvent true if this scroll operation is the result of a touch event. |
| 16545 | * @return true if scrolling was clamped to an over-scroll boundary along either |
| 16546 | * axis, false otherwise. |
| 16547 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 16548 | @SuppressWarnings({"UnusedParameters"}) |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 16549 | protected boolean overScrollBy(int deltaX, int deltaY, |
| 16550 | int scrollX, int scrollY, |
| 16551 | int scrollRangeX, int scrollRangeY, |
| 16552 | int maxOverScrollX, int maxOverScrollY, |
| 16553 | boolean isTouchEvent) { |
| 16554 | final int overScrollMode = mOverScrollMode; |
| 16555 | final boolean canScrollHorizontal = |
| 16556 | computeHorizontalScrollRange() > computeHorizontalScrollExtent(); |
| 16557 | final boolean canScrollVertical = |
| 16558 | computeVerticalScrollRange() > computeVerticalScrollExtent(); |
| 16559 | final boolean overScrollHorizontal = overScrollMode == OVER_SCROLL_ALWAYS || |
| 16560 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal); |
| 16561 | final boolean overScrollVertical = overScrollMode == OVER_SCROLL_ALWAYS || |
| 16562 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical); |
| 16563 | |
| 16564 | int newScrollX = scrollX + deltaX; |
| 16565 | if (!overScrollHorizontal) { |
| 16566 | maxOverScrollX = 0; |
| 16567 | } |
| 16568 | |
| 16569 | int newScrollY = scrollY + deltaY; |
| 16570 | if (!overScrollVertical) { |
| 16571 | maxOverScrollY = 0; |
| 16572 | } |
| 16573 | |
| 16574 | // Clamp values if at the limits and record |
| 16575 | final int left = -maxOverScrollX; |
| 16576 | final int right = maxOverScrollX + scrollRangeX; |
| 16577 | final int top = -maxOverScrollY; |
| 16578 | final int bottom = maxOverScrollY + scrollRangeY; |
| 16579 | |
| 16580 | boolean clampedX = false; |
| 16581 | if (newScrollX > right) { |
| 16582 | newScrollX = right; |
| 16583 | clampedX = true; |
| 16584 | } else if (newScrollX < left) { |
| 16585 | newScrollX = left; |
| 16586 | clampedX = true; |
| 16587 | } |
| 16588 | |
| 16589 | boolean clampedY = false; |
| 16590 | if (newScrollY > bottom) { |
| 16591 | newScrollY = bottom; |
| 16592 | clampedY = true; |
| 16593 | } else if (newScrollY < top) { |
| 16594 | newScrollY = top; |
| 16595 | clampedY = true; |
| 16596 | } |
| 16597 | |
| 16598 | onOverScrolled(newScrollX, newScrollY, clampedX, clampedY); |
| 16599 | |
| 16600 | return clampedX || clampedY; |
| 16601 | } |
| 16602 | |
| 16603 | /** |
| 16604 | * Called by {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)} to |
| 16605 | * respond to the results of an over-scroll operation. |
| 16606 | * |
| 16607 | * @param scrollX New X scroll value in pixels |
| 16608 | * @param scrollY New Y scroll value in pixels |
| 16609 | * @param clampedX True if scrollX was clamped to an over-scroll boundary |
| 16610 | * @param clampedY True if scrollY was clamped to an over-scroll boundary |
| 16611 | */ |
| 16612 | protected void onOverScrolled(int scrollX, int scrollY, |
| 16613 | boolean clampedX, boolean clampedY) { |
| 16614 | // Intentionally empty. |
| 16615 | } |
| 16616 | |
| 16617 | /** |
| 16618 | * Returns the over-scroll mode for this view. The result will be |
| 16619 | * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 16620 | * (allow over-scrolling only if the view content is larger than the container), |
| 16621 | * or {@link #OVER_SCROLL_NEVER}. |
| 16622 | * |
| 16623 | * @return This view's over-scroll mode. |
| 16624 | */ |
| 16625 | public int getOverScrollMode() { |
| 16626 | return mOverScrollMode; |
| 16627 | } |
| 16628 | |
| 16629 | /** |
| 16630 | * Set the over-scroll mode for this view. Valid over-scroll modes are |
| 16631 | * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 16632 | * (allow over-scrolling only if the view content is larger than the container), |
| 16633 | * or {@link #OVER_SCROLL_NEVER}. |
| 16634 | * |
| 16635 | * Setting the over-scroll mode of a view will have an effect only if the |
| 16636 | * view is capable of scrolling. |
| 16637 | * |
| 16638 | * @param overScrollMode The new over-scroll mode for this view. |
| 16639 | */ |
| 16640 | public void setOverScrollMode(int overScrollMode) { |
| 16641 | if (overScrollMode != OVER_SCROLL_ALWAYS && |
| 16642 | overScrollMode != OVER_SCROLL_IF_CONTENT_SCROLLS && |
| 16643 | overScrollMode != OVER_SCROLL_NEVER) { |
| 16644 | throw new IllegalArgumentException("Invalid overscroll mode " + overScrollMode); |
| 16645 | } |
| 16646 | mOverScrollMode = overScrollMode; |
| 16647 | } |
| 16648 | |
| 16649 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 16650 | * Gets a scale factor that determines the distance the view should scroll |
| 16651 | * vertically in response to {@link MotionEvent#ACTION_SCROLL}. |
| 16652 | * @return The vertical scroll scale factor. |
| 16653 | * @hide |
| 16654 | */ |
| 16655 | protected float getVerticalScrollFactor() { |
| 16656 | if (mVerticalScrollFactor == 0) { |
| 16657 | TypedValue outValue = new TypedValue(); |
| 16658 | if (!mContext.getTheme().resolveAttribute( |
| 16659 | com.android.internal.R.attr.listPreferredItemHeight, outValue, true)) { |
| 16660 | throw new IllegalStateException( |
| 16661 | "Expected theme to define listPreferredItemHeight."); |
| 16662 | } |
| 16663 | mVerticalScrollFactor = outValue.getDimension( |
| 16664 | mContext.getResources().getDisplayMetrics()); |
| 16665 | } |
| 16666 | return mVerticalScrollFactor; |
| 16667 | } |
| 16668 | |
| 16669 | /** |
| 16670 | * Gets a scale factor that determines the distance the view should scroll |
| 16671 | * horizontally in response to {@link MotionEvent#ACTION_SCROLL}. |
| 16672 | * @return The horizontal scroll scale factor. |
| 16673 | * @hide |
| 16674 | */ |
| 16675 | protected float getHorizontalScrollFactor() { |
| 16676 | // TODO: Should use something else. |
| 16677 | return getVerticalScrollFactor(); |
| 16678 | } |
| 16679 | |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16680 | /** |
| 16681 | * Return the value specifying the text direction or policy that was set with |
| 16682 | * {@link #setTextDirection(int)}. |
| 16683 | * |
| 16684 | * @return the defined text direction. It can be one of: |
| 16685 | * |
| 16686 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 16687 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 16688 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 16689 | * {@link #TEXT_DIRECTION_LTR}, |
| 16690 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16691 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16692 | * |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 16693 | * @attr ref android.R.styleable#View_textDirection |
| 16694 | * |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16695 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16696 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16697 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 16698 | @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), |
| 16699 | @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), |
| 16700 | @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), |
| 16701 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), |
| 16702 | @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), |
| 16703 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") |
| 16704 | }) |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16705 | public int getRawTextDirection() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16706 | return (mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_MASK) >> PFLAG2_TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16707 | } |
| 16708 | |
| 16709 | /** |
| 16710 | * Set the text direction. |
| 16711 | * |
| 16712 | * @param textDirection the direction to set. Should be one of: |
| 16713 | * |
| 16714 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 16715 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 16716 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 16717 | * {@link #TEXT_DIRECTION_LTR}, |
| 16718 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16719 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16720 | * |
| 16721 | * Resolution will be done if the value is set to TEXT_DIRECTION_INHERIT. The resolution |
| 16722 | * proceeds up the parent chain of the view to get the value. If there is no parent, then it will |
| 16723 | * return the default {@link #TEXT_DIRECTION_FIRST_STRONG}. |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 16724 | * |
| 16725 | * @attr ref android.R.styleable#View_textDirection |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16726 | */ |
| 16727 | public void setTextDirection(int textDirection) { |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16728 | if (getRawTextDirection() != textDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 16729 | // Reset the current text direction and the resolved one |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16730 | mPrivateFlags2 &= ~PFLAG2_TEXT_DIRECTION_MASK; |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 16731 | resetResolvedTextDirection(); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16732 | // Set the new text direction |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16733 | mPrivateFlags2 |= ((textDirection << PFLAG2_TEXT_DIRECTION_MASK_SHIFT) & PFLAG2_TEXT_DIRECTION_MASK); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16734 | // Do resolution |
| 16735 | resolveTextDirection(); |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16736 | // Notify change |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 16737 | onRtlPropertiesChanged(getLayoutDirection()); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16738 | // Refresh |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16739 | requestLayout(); |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 16740 | invalidate(true); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16741 | } |
| 16742 | } |
| 16743 | |
| 16744 | /** |
| 16745 | * Return the resolved text direction. |
| 16746 | * |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16747 | * @return the resolved text direction. Returns one of: |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16748 | * |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 16749 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 16750 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16751 | * {@link #TEXT_DIRECTION_LTR}, |
| 16752 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16753 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 16754 | * |
| 16755 | * @attr ref android.R.styleable#View_textDirection |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16756 | */ |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16757 | public int getTextDirection() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16758 | return (mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_RESOLVED_MASK) >> PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16759 | } |
| 16760 | |
| 16761 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16762 | * Resolve the text direction. |
| 16763 | * |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16764 | * @return true if resolution has been done, false otherwise. |
| 16765 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16766 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16767 | */ |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16768 | public boolean resolveTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16769 | // Reset any previous text direction resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16770 | mPrivateFlags2 &= ~(PFLAG2_TEXT_DIRECTION_RESOLVED | PFLAG2_TEXT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16771 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16772 | if (hasRtlSupport()) { |
| 16773 | // Set resolved text direction flag depending on text direction flag |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16774 | final int textDirection = getRawTextDirection(); |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16775 | switch(textDirection) { |
| 16776 | case TEXT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16777 | if (!canResolveTextDirection()) { |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16778 | // We cannot do the resolution if there is no parent, so use the default one |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16779 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16780 | // Resolution will need to happen again later |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16781 | return false; |
| 16782 | } |
| 16783 | |
| 16784 | View parent = ((View) mParent); |
| 16785 | // Parent has not yet resolved, so we still return the default |
| 16786 | if (!parent.isTextDirectionResolved()) { |
| 16787 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 16788 | // Resolution will need to happen again later |
| 16789 | return false; |
| 16790 | } |
| 16791 | |
| 16792 | // Set current resolved direction to the same value as the parent's one |
| 16793 | final int parentResolvedDirection = parent.getTextDirection(); |
| 16794 | switch (parentResolvedDirection) { |
| 16795 | case TEXT_DIRECTION_FIRST_STRONG: |
| 16796 | case TEXT_DIRECTION_ANY_RTL: |
| 16797 | case TEXT_DIRECTION_LTR: |
| 16798 | case TEXT_DIRECTION_RTL: |
| 16799 | case TEXT_DIRECTION_LOCALE: |
| 16800 | mPrivateFlags2 |= |
| 16801 | (parentResolvedDirection << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
| 16802 | break; |
| 16803 | default: |
| 16804 | // Default resolved direction is "first strong" heuristic |
| 16805 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16806 | } |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16807 | break; |
| 16808 | case TEXT_DIRECTION_FIRST_STRONG: |
| 16809 | case TEXT_DIRECTION_ANY_RTL: |
| 16810 | case TEXT_DIRECTION_LTR: |
| 16811 | case TEXT_DIRECTION_RTL: |
| 16812 | case TEXT_DIRECTION_LOCALE: |
| 16813 | // Resolved direction is the same as text direction |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16814 | mPrivateFlags2 |= (textDirection << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16815 | break; |
| 16816 | default: |
| 16817 | // Default resolved direction is "first strong" heuristic |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16818 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16819 | } |
| 16820 | } else { |
| 16821 | // Default resolved direction is "first strong" heuristic |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16822 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16823 | } |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16824 | |
| 16825 | // Set to resolved |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16826 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16827 | return true; |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16828 | } |
| 16829 | |
| 16830 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16831 | * Check if text direction resolution can be done. |
| 16832 | * |
| 16833 | * @return true if text direction resolution can be done otherwise return false. |
| 16834 | */ |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16835 | private boolean canResolveTextDirection() { |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16836 | switch (getRawTextDirection()) { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16837 | case TEXT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16838 | return (mParent != null) && (mParent instanceof View) && |
| 16839 | ((View) mParent).canResolveTextDirection(); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16840 | default: |
| 16841 | return true; |
| 16842 | } |
| 16843 | } |
| 16844 | |
| 16845 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16846 | * Reset resolved text direction. Text direction will be resolved during a call to |
| 16847 | * {@link #onMeasure(int, int)}. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16848 | * |
| 16849 | * @hide |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16850 | */ |
| 16851 | public void resetResolvedTextDirection() { |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16852 | // Reset any previous text direction resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16853 | mPrivateFlags2 &= ~(PFLAG2_TEXT_DIRECTION_RESOLVED | PFLAG2_TEXT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16854 | // Set to default value |
| 16855 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16856 | } |
| 16857 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16858 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16859 | * @return true if text direction is inherited. |
| 16860 | * |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16861 | * @hide |
| 16862 | */ |
| 16863 | public boolean isTextDirectionInherited() { |
| 16864 | return (getRawTextDirection() == TEXT_DIRECTION_INHERIT); |
| 16865 | } |
| 16866 | |
| 16867 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16868 | * @return true if text direction is resolved. |
| 16869 | */ |
| 16870 | private boolean isTextDirectionResolved() { |
| 16871 | return (mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_RESOLVED) == PFLAG2_TEXT_DIRECTION_RESOLVED; |
| 16872 | } |
| 16873 | |
| 16874 | /** |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16875 | * Return the value specifying the text alignment or policy that was set with |
| 16876 | * {@link #setTextAlignment(int)}. |
| 16877 | * |
| 16878 | * @return the defined text alignment. It can be one of: |
| 16879 | * |
| 16880 | * {@link #TEXT_ALIGNMENT_INHERIT}, |
| 16881 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 16882 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 16883 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 16884 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 16885 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 16886 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16887 | * |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 16888 | * @attr ref android.R.styleable#View_textAlignment |
| 16889 | * |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16890 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16891 | */ |
| 16892 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 16893 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), |
| 16894 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_GRAVITY, to = "GRAVITY"), |
| 16895 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_START, to = "TEXT_START"), |
| 16896 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_END, to = "TEXT_END"), |
| 16897 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_CENTER, to = "CENTER"), |
| 16898 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), |
| 16899 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") |
| 16900 | }) |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16901 | public int getRawTextAlignment() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16902 | return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_MASK) >> PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16903 | } |
| 16904 | |
| 16905 | /** |
| 16906 | * Set the text alignment. |
| 16907 | * |
| 16908 | * @param textAlignment The text alignment to set. Should be one of |
| 16909 | * |
| 16910 | * {@link #TEXT_ALIGNMENT_INHERIT}, |
| 16911 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 16912 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 16913 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 16914 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 16915 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 16916 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
| 16917 | * |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16918 | * Resolution will be done if the value is set to TEXT_ALIGNMENT_INHERIT. The resolution |
| 16919 | * proceeds up the parent chain of the view to get the value. If there is no parent, then it |
| 16920 | * will return the default {@link #TEXT_ALIGNMENT_GRAVITY}. |
| 16921 | * |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16922 | * @attr ref android.R.styleable#View_textAlignment |
| 16923 | */ |
| 16924 | public void setTextAlignment(int textAlignment) { |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16925 | if (textAlignment != getRawTextAlignment()) { |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16926 | // Reset the current and resolved text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16927 | mPrivateFlags2 &= ~PFLAG2_TEXT_ALIGNMENT_MASK; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16928 | resetResolvedTextAlignment(); |
| 16929 | // Set the new text alignment |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16930 | mPrivateFlags2 |= |
| 16931 | ((textAlignment << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT) & PFLAG2_TEXT_ALIGNMENT_MASK); |
| 16932 | // Do resolution |
| 16933 | resolveTextAlignment(); |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16934 | // Notify change |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 16935 | onRtlPropertiesChanged(getLayoutDirection()); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16936 | // Refresh |
| 16937 | requestLayout(); |
| 16938 | invalidate(true); |
| 16939 | } |
| 16940 | } |
| 16941 | |
| 16942 | /** |
| 16943 | * Return the resolved text alignment. |
| 16944 | * |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16945 | * @return the resolved text alignment. Returns one of: |
| 16946 | * |
| 16947 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 16948 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 16949 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 16950 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 16951 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 16952 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 16953 | * |
| 16954 | * @attr ref android.R.styleable#View_textAlignment |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16955 | */ |
| 16956 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 16957 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), |
| 16958 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_GRAVITY, to = "GRAVITY"), |
| 16959 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_START, to = "TEXT_START"), |
| 16960 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_END, to = "TEXT_END"), |
| 16961 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_CENTER, to = "CENTER"), |
| 16962 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), |
| 16963 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") |
| 16964 | }) |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16965 | public int getTextAlignment() { |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16966 | return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK) >> |
| 16967 | PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16968 | } |
| 16969 | |
| 16970 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16971 | * Resolve the text alignment. |
| 16972 | * |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16973 | * @return true if resolution has been done, false otherwise. |
| 16974 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16975 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16976 | */ |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16977 | public boolean resolveTextAlignment() { |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16978 | // Reset any previous text alignment resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16979 | mPrivateFlags2 &= ~(PFLAG2_TEXT_ALIGNMENT_RESOLVED | PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16980 | |
| 16981 | if (hasRtlSupport()) { |
| 16982 | // Set resolved text alignment flag depending on text alignment flag |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16983 | final int textAlignment = getRawTextAlignment(); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16984 | switch (textAlignment) { |
| 16985 | case TEXT_ALIGNMENT_INHERIT: |
| 16986 | // Check if we can resolve the text alignment |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16987 | if (!canResolveTextAlignment()) { |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16988 | // We cannot do the resolution if there is no parent so use the default |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16989 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16990 | // Resolution will need to happen again later |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16991 | return false; |
| 16992 | } |
| 16993 | View parent = (View) mParent; |
| 16994 | |
| 16995 | // Parent has not yet resolved, so we still return the default |
| 16996 | if (!parent.isTextAlignmentResolved()) { |
| 16997 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 16998 | // Resolution will need to happen again later |
| 16999 | return false; |
| 17000 | } |
| 17001 | |
| 17002 | final int parentResolvedTextAlignment = parent.getTextAlignment(); |
| 17003 | switch (parentResolvedTextAlignment) { |
| 17004 | case TEXT_ALIGNMENT_GRAVITY: |
| 17005 | case TEXT_ALIGNMENT_TEXT_START: |
| 17006 | case TEXT_ALIGNMENT_TEXT_END: |
| 17007 | case TEXT_ALIGNMENT_CENTER: |
| 17008 | case TEXT_ALIGNMENT_VIEW_START: |
| 17009 | case TEXT_ALIGNMENT_VIEW_END: |
| 17010 | // Resolved text alignment is the same as the parent resolved |
| 17011 | // text alignment |
| 17012 | mPrivateFlags2 |= |
| 17013 | (parentResolvedTextAlignment << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT); |
| 17014 | break; |
| 17015 | default: |
| 17016 | // Use default resolved text alignment |
| 17017 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17018 | } |
| 17019 | break; |
| 17020 | case TEXT_ALIGNMENT_GRAVITY: |
| 17021 | case TEXT_ALIGNMENT_TEXT_START: |
| 17022 | case TEXT_ALIGNMENT_TEXT_END: |
| 17023 | case TEXT_ALIGNMENT_CENTER: |
| 17024 | case TEXT_ALIGNMENT_VIEW_START: |
| 17025 | case TEXT_ALIGNMENT_VIEW_END: |
| 17026 | // Resolved text alignment is the same as text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17027 | mPrivateFlags2 |= (textAlignment << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17028 | break; |
| 17029 | default: |
| 17030 | // Use default resolved text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17031 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17032 | } |
| 17033 | } else { |
| 17034 | // Use default resolved text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17035 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17036 | } |
| 17037 | |
| 17038 | // Set the resolved |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17039 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED; |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 17040 | return true; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17041 | } |
| 17042 | |
| 17043 | /** |
| 17044 | * Check if text alignment resolution can be done. |
| 17045 | * |
| 17046 | * @return true if text alignment resolution can be done otherwise return false. |
| 17047 | */ |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 17048 | private boolean canResolveTextAlignment() { |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 17049 | switch (getRawTextAlignment()) { |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17050 | case TEXT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 17051 | return (mParent != null) && (mParent instanceof View) && |
| 17052 | ((View) mParent).canResolveTextAlignment(); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17053 | default: |
| 17054 | return true; |
| 17055 | } |
| 17056 | } |
| 17057 | |
| 17058 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 17059 | * Reset resolved text alignment. Text alignment will be resolved during a call to |
| 17060 | * {@link #onMeasure(int, int)}. |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17061 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 17062 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17063 | */ |
| 17064 | public void resetResolvedTextAlignment() { |
| 17065 | // Reset any previous text alignment resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17066 | mPrivateFlags2 &= ~(PFLAG2_TEXT_ALIGNMENT_RESOLVED | PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 17067 | // Set to default |
| 17068 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17069 | } |
| 17070 | |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 17071 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 17072 | * @return true if text alignment is inherited. |
| 17073 | * |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 17074 | * @hide |
| 17075 | */ |
| 17076 | public boolean isTextAlignmentInherited() { |
| 17077 | return (getRawTextAlignment() == TEXT_ALIGNMENT_INHERIT); |
| 17078 | } |
| 17079 | |
| 17080 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 17081 | * @return true if text alignment is resolved. |
| 17082 | */ |
| 17083 | private boolean isTextAlignmentResolved() { |
| 17084 | return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_RESOLVED) == PFLAG2_TEXT_ALIGNMENT_RESOLVED; |
| 17085 | } |
| 17086 | |
| 17087 | /** |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 17088 | * Generate a value suitable for use in {@link #setId(int)}. |
| 17089 | * This value will not collide with ID values generated at build time by aapt for R.id. |
| 17090 | * |
| 17091 | * @return a generated ID value |
| 17092 | */ |
| 17093 | public static int generateViewId() { |
| 17094 | for (;;) { |
| 17095 | final int result = sNextGeneratedId.get(); |
| 17096 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that. |
| 17097 | int newValue = result + 1; |
| 17098 | if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. |
| 17099 | if (sNextGeneratedId.compareAndSet(result, newValue)) { |
| 17100 | return result; |
| 17101 | } |
| 17102 | } |
| 17103 | } |
| 17104 | |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17105 | // |
| 17106 | // Properties |
| 17107 | // |
| 17108 | /** |
| 17109 | * A Property wrapper around the <code>alpha</code> functionality handled by the |
| 17110 | * {@link View#setAlpha(float)} and {@link View#getAlpha()} methods. |
| 17111 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17112 | public static final Property<View, Float> ALPHA = new FloatProperty<View>("alpha") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17113 | @Override |
| 17114 | public void setValue(View object, float value) { |
| 17115 | object.setAlpha(value); |
| 17116 | } |
| 17117 | |
| 17118 | @Override |
| 17119 | public Float get(View object) { |
| 17120 | return object.getAlpha(); |
| 17121 | } |
| 17122 | }; |
| 17123 | |
| 17124 | /** |
| 17125 | * A Property wrapper around the <code>translationX</code> functionality handled by the |
| 17126 | * {@link View#setTranslationX(float)} and {@link View#getTranslationX()} methods. |
| 17127 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17128 | public static final Property<View, Float> TRANSLATION_X = new FloatProperty<View>("translationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17129 | @Override |
| 17130 | public void setValue(View object, float value) { |
| 17131 | object.setTranslationX(value); |
| 17132 | } |
| 17133 | |
| 17134 | @Override |
| 17135 | public Float get(View object) { |
| 17136 | return object.getTranslationX(); |
| 17137 | } |
| 17138 | }; |
| 17139 | |
| 17140 | /** |
| 17141 | * A Property wrapper around the <code>translationY</code> functionality handled by the |
| 17142 | * {@link View#setTranslationY(float)} and {@link View#getTranslationY()} methods. |
| 17143 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17144 | public static final Property<View, Float> TRANSLATION_Y = new FloatProperty<View>("translationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17145 | @Override |
| 17146 | public void setValue(View object, float value) { |
| 17147 | object.setTranslationY(value); |
| 17148 | } |
| 17149 | |
| 17150 | @Override |
| 17151 | public Float get(View object) { |
| 17152 | return object.getTranslationY(); |
| 17153 | } |
| 17154 | }; |
| 17155 | |
| 17156 | /** |
| 17157 | * A Property wrapper around the <code>x</code> functionality handled by the |
| 17158 | * {@link View#setX(float)} and {@link View#getX()} methods. |
| 17159 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17160 | public static final Property<View, Float> X = new FloatProperty<View>("x") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17161 | @Override |
| 17162 | public void setValue(View object, float value) { |
| 17163 | object.setX(value); |
| 17164 | } |
| 17165 | |
| 17166 | @Override |
| 17167 | public Float get(View object) { |
| 17168 | return object.getX(); |
| 17169 | } |
| 17170 | }; |
| 17171 | |
| 17172 | /** |
| 17173 | * A Property wrapper around the <code>y</code> functionality handled by the |
| 17174 | * {@link View#setY(float)} and {@link View#getY()} methods. |
| 17175 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17176 | public static final Property<View, Float> Y = new FloatProperty<View>("y") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17177 | @Override |
| 17178 | public void setValue(View object, float value) { |
| 17179 | object.setY(value); |
| 17180 | } |
| 17181 | |
| 17182 | @Override |
| 17183 | public Float get(View object) { |
| 17184 | return object.getY(); |
| 17185 | } |
| 17186 | }; |
| 17187 | |
| 17188 | /** |
| 17189 | * A Property wrapper around the <code>rotation</code> functionality handled by the |
| 17190 | * {@link View#setRotation(float)} and {@link View#getRotation()} methods. |
| 17191 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17192 | public static final Property<View, Float> ROTATION = new FloatProperty<View>("rotation") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17193 | @Override |
| 17194 | public void setValue(View object, float value) { |
| 17195 | object.setRotation(value); |
| 17196 | } |
| 17197 | |
| 17198 | @Override |
| 17199 | public Float get(View object) { |
| 17200 | return object.getRotation(); |
| 17201 | } |
| 17202 | }; |
| 17203 | |
| 17204 | /** |
| 17205 | * A Property wrapper around the <code>rotationX</code> functionality handled by the |
| 17206 | * {@link View#setRotationX(float)} and {@link View#getRotationX()} methods. |
| 17207 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17208 | public static final Property<View, Float> ROTATION_X = new FloatProperty<View>("rotationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17209 | @Override |
| 17210 | public void setValue(View object, float value) { |
| 17211 | object.setRotationX(value); |
| 17212 | } |
| 17213 | |
| 17214 | @Override |
| 17215 | public Float get(View object) { |
| 17216 | return object.getRotationX(); |
| 17217 | } |
| 17218 | }; |
| 17219 | |
| 17220 | /** |
| 17221 | * A Property wrapper around the <code>rotationY</code> functionality handled by the |
| 17222 | * {@link View#setRotationY(float)} and {@link View#getRotationY()} methods. |
| 17223 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17224 | public static final Property<View, Float> ROTATION_Y = new FloatProperty<View>("rotationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17225 | @Override |
| 17226 | public void setValue(View object, float value) { |
| 17227 | object.setRotationY(value); |
| 17228 | } |
| 17229 | |
| 17230 | @Override |
| 17231 | public Float get(View object) { |
| 17232 | return object.getRotationY(); |
| 17233 | } |
| 17234 | }; |
| 17235 | |
| 17236 | /** |
| 17237 | * A Property wrapper around the <code>scaleX</code> functionality handled by the |
| 17238 | * {@link View#setScaleX(float)} and {@link View#getScaleX()} methods. |
| 17239 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17240 | public static final Property<View, Float> SCALE_X = new FloatProperty<View>("scaleX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17241 | @Override |
| 17242 | public void setValue(View object, float value) { |
| 17243 | object.setScaleX(value); |
| 17244 | } |
| 17245 | |
| 17246 | @Override |
| 17247 | public Float get(View object) { |
| 17248 | return object.getScaleX(); |
| 17249 | } |
| 17250 | }; |
| 17251 | |
| 17252 | /** |
| 17253 | * A Property wrapper around the <code>scaleY</code> functionality handled by the |
| 17254 | * {@link View#setScaleY(float)} and {@link View#getScaleY()} methods. |
| 17255 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17256 | public static final Property<View, Float> SCALE_Y = new FloatProperty<View>("scaleY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17257 | @Override |
| 17258 | public void setValue(View object, float value) { |
| 17259 | object.setScaleY(value); |
| 17260 | } |
| 17261 | |
| 17262 | @Override |
| 17263 | public Float get(View object) { |
| 17264 | return object.getScaleY(); |
| 17265 | } |
| 17266 | }; |
| 17267 | |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 17268 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17269 | * A MeasureSpec encapsulates the layout requirements passed from parent to child. |
| 17270 | * Each MeasureSpec represents a requirement for either the width or the height. |
| 17271 | * A MeasureSpec is comprised of a size and a mode. There are three possible |
| 17272 | * modes: |
| 17273 | * <dl> |
| 17274 | * <dt>UNSPECIFIED</dt> |
| 17275 | * <dd> |
| 17276 | * The parent has not imposed any constraint on the child. It can be whatever size |
| 17277 | * it wants. |
| 17278 | * </dd> |
| 17279 | * |
| 17280 | * <dt>EXACTLY</dt> |
| 17281 | * <dd> |
| 17282 | * The parent has determined an exact size for the child. The child is going to be |
| 17283 | * given those bounds regardless of how big it wants to be. |
| 17284 | * </dd> |
| 17285 | * |
| 17286 | * <dt>AT_MOST</dt> |
| 17287 | * <dd> |
| 17288 | * The child can be as large as it wants up to the specified size. |
| 17289 | * </dd> |
| 17290 | * </dl> |
| 17291 | * |
| 17292 | * MeasureSpecs are implemented as ints to reduce object allocation. This class |
| 17293 | * is provided to pack and unpack the <size, mode> tuple into the int. |
| 17294 | */ |
| 17295 | public static class MeasureSpec { |
| 17296 | private static final int MODE_SHIFT = 30; |
| 17297 | private static final int MODE_MASK = 0x3 << MODE_SHIFT; |
| 17298 | |
| 17299 | /** |
| 17300 | * Measure specification mode: The parent has not imposed any constraint |
| 17301 | * on the child. It can be whatever size it wants. |
| 17302 | */ |
| 17303 | public static final int UNSPECIFIED = 0 << MODE_SHIFT; |
| 17304 | |
| 17305 | /** |
| 17306 | * Measure specification mode: The parent has determined an exact size |
| 17307 | * for the child. The child is going to be given those bounds regardless |
| 17308 | * of how big it wants to be. |
| 17309 | */ |
| 17310 | public static final int EXACTLY = 1 << MODE_SHIFT; |
| 17311 | |
| 17312 | /** |
| 17313 | * Measure specification mode: The child can be as large as it wants up |
| 17314 | * to the specified size. |
| 17315 | */ |
| 17316 | public static final int AT_MOST = 2 << MODE_SHIFT; |
| 17317 | |
| 17318 | /** |
| 17319 | * Creates a measure specification based on the supplied size and mode. |
| 17320 | * |
| 17321 | * The mode must always be one of the following: |
| 17322 | * <ul> |
| 17323 | * <li>{@link android.view.View.MeasureSpec#UNSPECIFIED}</li> |
| 17324 | * <li>{@link android.view.View.MeasureSpec#EXACTLY}</li> |
| 17325 | * <li>{@link android.view.View.MeasureSpec#AT_MOST}</li> |
| 17326 | * </ul> |
| 17327 | * |
| 17328 | * @param size the size of the measure specification |
| 17329 | * @param mode the mode of the measure specification |
| 17330 | * @return the measure specification based on size and mode |
| 17331 | */ |
| 17332 | public static int makeMeasureSpec(int size, int mode) { |
Adam Powell | d5edc77 | 2012-09-26 15:21:39 -0700 | [diff] [blame] | 17333 | return (size & ~MODE_MASK) | (mode & MODE_MASK); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17334 | } |
| 17335 | |
| 17336 | /** |
| 17337 | * Extracts the mode from the supplied measure specification. |
| 17338 | * |
| 17339 | * @param measureSpec the measure specification to extract the mode from |
| 17340 | * @return {@link android.view.View.MeasureSpec#UNSPECIFIED}, |
| 17341 | * {@link android.view.View.MeasureSpec#AT_MOST} or |
| 17342 | * {@link android.view.View.MeasureSpec#EXACTLY} |
| 17343 | */ |
| 17344 | public static int getMode(int measureSpec) { |
| 17345 | return (measureSpec & MODE_MASK); |
| 17346 | } |
| 17347 | |
| 17348 | /** |
| 17349 | * Extracts the size from the supplied measure specification. |
| 17350 | * |
| 17351 | * @param measureSpec the measure specification to extract the size from |
| 17352 | * @return the size in pixels defined in the supplied measure specification |
| 17353 | */ |
| 17354 | public static int getSize(int measureSpec) { |
| 17355 | return (measureSpec & ~MODE_MASK); |
| 17356 | } |
| 17357 | |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 17358 | static int adjust(int measureSpec, int delta) { |
| 17359 | return makeMeasureSpec(getSize(measureSpec + delta), getMode(measureSpec)); |
| 17360 | } |
| 17361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17362 | /** |
| 17363 | * Returns a String representation of the specified measure |
| 17364 | * specification. |
| 17365 | * |
| 17366 | * @param measureSpec the measure specification to convert to a String |
| 17367 | * @return a String with the following format: "MeasureSpec: MODE SIZE" |
| 17368 | */ |
| 17369 | public static String toString(int measureSpec) { |
| 17370 | int mode = getMode(measureSpec); |
| 17371 | int size = getSize(measureSpec); |
| 17372 | |
| 17373 | StringBuilder sb = new StringBuilder("MeasureSpec: "); |
| 17374 | |
| 17375 | if (mode == UNSPECIFIED) |
| 17376 | sb.append("UNSPECIFIED "); |
| 17377 | else if (mode == EXACTLY) |
| 17378 | sb.append("EXACTLY "); |
| 17379 | else if (mode == AT_MOST) |
| 17380 | sb.append("AT_MOST "); |
| 17381 | else |
| 17382 | sb.append(mode).append(" "); |
| 17383 | |
| 17384 | sb.append(size); |
| 17385 | return sb.toString(); |
| 17386 | } |
| 17387 | } |
| 17388 | |
| 17389 | class CheckForLongPress implements Runnable { |
| 17390 | |
| 17391 | private int mOriginalWindowAttachCount; |
| 17392 | |
| 17393 | public void run() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 17394 | if (isPressed() && (mParent != null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17395 | && mOriginalWindowAttachCount == mWindowAttachCount) { |
| 17396 | if (performLongClick()) { |
| 17397 | mHasPerformedLongPress = true; |
| 17398 | } |
| 17399 | } |
| 17400 | } |
| 17401 | |
| 17402 | public void rememberWindowAttachCount() { |
| 17403 | mOriginalWindowAttachCount = mWindowAttachCount; |
| 17404 | } |
| 17405 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17406 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 17407 | private final class CheckForTap implements Runnable { |
| 17408 | public void run() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17409 | mPrivateFlags &= ~PFLAG_PREPRESSED; |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 17410 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 17411 | checkForLongClick(ViewConfiguration.getTapTimeout()); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 17412 | } |
| 17413 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17414 | |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 17415 | private final class PerformClick implements Runnable { |
| 17416 | public void run() { |
| 17417 | performClick(); |
| 17418 | } |
| 17419 | } |
| 17420 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 17421 | /** @hide */ |
| 17422 | public void hackTurnOffWindowResizeAnim(boolean off) { |
| 17423 | mAttachInfo.mTurnOffWindowResizeAnim = off; |
| 17424 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17425 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17426 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 17427 | * This method returns a ViewPropertyAnimator object, which can be used to animate |
| 17428 | * specific properties on this View. |
| 17429 | * |
| 17430 | * @return ViewPropertyAnimator The ViewPropertyAnimator associated with this View. |
| 17431 | */ |
| 17432 | public ViewPropertyAnimator animate() { |
| 17433 | if (mAnimator == null) { |
| 17434 | mAnimator = new ViewPropertyAnimator(this); |
| 17435 | } |
| 17436 | return mAnimator; |
| 17437 | } |
| 17438 | |
| 17439 | /** |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 17440 | * Interface definition for a callback to be invoked when a hardware key event is |
| 17441 | * dispatched to this view. The callback will be invoked before the key event is |
| 17442 | * given to the view. This is only useful for hardware keyboards; a software input |
| 17443 | * method has no obligation to trigger this listener. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17444 | */ |
| 17445 | public interface OnKeyListener { |
| 17446 | /** |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 17447 | * Called when a hardware key is dispatched to a view. This allows listeners to |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17448 | * get a chance to respond before the target view. |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 17449 | * <p>Key presses in software keyboards will generally NOT trigger this method, |
| 17450 | * although some may elect to do so in some situations. Do not assume a |
| 17451 | * software input method has to be key-based; even if it is, it may use key presses |
| 17452 | * in a different way than you expect, so there is no way to reliably catch soft |
| 17453 | * input key presses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17454 | * |
| 17455 | * @param v The view the key has been dispatched to. |
| 17456 | * @param keyCode The code for the physical key that was pressed |
| 17457 | * @param event The KeyEvent object containing full information about |
| 17458 | * the event. |
| 17459 | * @return True if the listener has consumed the event, false otherwise. |
| 17460 | */ |
| 17461 | boolean onKey(View v, int keyCode, KeyEvent event); |
| 17462 | } |
| 17463 | |
| 17464 | /** |
| 17465 | * Interface definition for a callback to be invoked when a touch event is |
| 17466 | * dispatched to this view. The callback will be invoked before the touch |
| 17467 | * event is given to the view. |
| 17468 | */ |
| 17469 | public interface OnTouchListener { |
| 17470 | /** |
| 17471 | * Called when a touch event is dispatched to a view. This allows listeners to |
| 17472 | * get a chance to respond before the target view. |
| 17473 | * |
| 17474 | * @param v The view the touch event has been dispatched to. |
| 17475 | * @param event The MotionEvent object containing full information about |
| 17476 | * the event. |
| 17477 | * @return True if the listener has consumed the event, false otherwise. |
| 17478 | */ |
| 17479 | boolean onTouch(View v, MotionEvent event); |
| 17480 | } |
| 17481 | |
| 17482 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 17483 | * Interface definition for a callback to be invoked when a hover event is |
| 17484 | * dispatched to this view. The callback will be invoked before the hover |
| 17485 | * event is given to the view. |
| 17486 | */ |
| 17487 | public interface OnHoverListener { |
| 17488 | /** |
| 17489 | * Called when a hover event is dispatched to a view. This allows listeners to |
| 17490 | * get a chance to respond before the target view. |
| 17491 | * |
| 17492 | * @param v The view the hover event has been dispatched to. |
| 17493 | * @param event The MotionEvent object containing full information about |
| 17494 | * the event. |
| 17495 | * @return True if the listener has consumed the event, false otherwise. |
| 17496 | */ |
| 17497 | boolean onHover(View v, MotionEvent event); |
| 17498 | } |
| 17499 | |
| 17500 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 17501 | * Interface definition for a callback to be invoked when a generic motion event is |
| 17502 | * dispatched to this view. The callback will be invoked before the generic motion |
| 17503 | * event is given to the view. |
| 17504 | */ |
| 17505 | public interface OnGenericMotionListener { |
| 17506 | /** |
| 17507 | * Called when a generic motion event is dispatched to a view. This allows listeners to |
| 17508 | * get a chance to respond before the target view. |
| 17509 | * |
| 17510 | * @param v The view the generic motion event has been dispatched to. |
| 17511 | * @param event The MotionEvent object containing full information about |
| 17512 | * the event. |
| 17513 | * @return True if the listener has consumed the event, false otherwise. |
| 17514 | */ |
| 17515 | boolean onGenericMotion(View v, MotionEvent event); |
| 17516 | } |
| 17517 | |
| 17518 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17519 | * Interface definition for a callback to be invoked when a view has been clicked and held. |
| 17520 | */ |
| 17521 | public interface OnLongClickListener { |
| 17522 | /** |
| 17523 | * Called when a view has been clicked and held. |
| 17524 | * |
| 17525 | * @param v The view that was clicked and held. |
| 17526 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 17527 | * @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] | 17528 | */ |
| 17529 | boolean onLongClick(View v); |
| 17530 | } |
| 17531 | |
| 17532 | /** |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 17533 | * Interface definition for a callback to be invoked when a drag is being dispatched |
| 17534 | * to this view. The callback will be invoked before the hosting view's own |
| 17535 | * onDrag(event) method. If the listener wants to fall back to the hosting view's |
| 17536 | * onDrag(event) behavior, it should return 'false' from this callback. |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 17537 | * |
| 17538 | * <div class="special reference"> |
| 17539 | * <h3>Developer Guides</h3> |
| 17540 | * <p>For a guide to implementing drag and drop features, read the |
| 17541 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 17542 | * </div> |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 17543 | */ |
| 17544 | public interface OnDragListener { |
| 17545 | /** |
| 17546 | * Called when a drag event is dispatched to a view. This allows listeners |
| 17547 | * to get a chance to override base View behavior. |
| 17548 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17549 | * @param v The View that received the drag event. |
| 17550 | * @param event The {@link android.view.DragEvent} object for the drag event. |
| 17551 | * @return {@code true} if the drag event was handled successfully, or {@code false} |
| 17552 | * if the drag event was not handled. Note that {@code false} will trigger the View |
| 17553 | * to call its {@link #onDragEvent(DragEvent) onDragEvent()} handler. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 17554 | */ |
| 17555 | boolean onDrag(View v, DragEvent event); |
| 17556 | } |
| 17557 | |
| 17558 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17559 | * Interface definition for a callback to be invoked when the focus state of |
| 17560 | * a view changed. |
| 17561 | */ |
| 17562 | public interface OnFocusChangeListener { |
| 17563 | /** |
| 17564 | * Called when the focus state of a view has changed. |
| 17565 | * |
| 17566 | * @param v The view whose state has changed. |
| 17567 | * @param hasFocus The new focus state of v. |
| 17568 | */ |
| 17569 | void onFocusChange(View v, boolean hasFocus); |
| 17570 | } |
| 17571 | |
| 17572 | /** |
| 17573 | * Interface definition for a callback to be invoked when a view is clicked. |
| 17574 | */ |
| 17575 | public interface OnClickListener { |
| 17576 | /** |
| 17577 | * Called when a view has been clicked. |
| 17578 | * |
| 17579 | * @param v The view that was clicked. |
| 17580 | */ |
| 17581 | void onClick(View v); |
| 17582 | } |
| 17583 | |
| 17584 | /** |
| 17585 | * Interface definition for a callback to be invoked when the context menu |
| 17586 | * for this view is being built. |
| 17587 | */ |
| 17588 | public interface OnCreateContextMenuListener { |
| 17589 | /** |
| 17590 | * Called when the context menu for this view is being built. It is not |
| 17591 | * safe to hold onto the menu after this method returns. |
| 17592 | * |
| 17593 | * @param menu The context menu that is being built |
| 17594 | * @param v The view for which the context menu is being built |
| 17595 | * @param menuInfo Extra information about the item for which the |
| 17596 | * context menu should be shown. This information will vary |
| 17597 | * depending on the class of v. |
| 17598 | */ |
| 17599 | void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo); |
| 17600 | } |
| 17601 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17602 | /** |
| 17603 | * 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] | 17604 | * visibility. This reports <strong>global</strong> changes to the system UI |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 17605 | * state, not what the application is requesting. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17606 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 17607 | * @see View#setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17608 | */ |
| 17609 | public interface OnSystemUiVisibilityChangeListener { |
| 17610 | /** |
| 17611 | * Called when the status bar changes visibility because of a call to |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 17612 | * {@link View#setSystemUiVisibility(int)}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17613 | * |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 17614 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 17615 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, and {@link #SYSTEM_UI_FLAG_FULLSCREEN}. |
| 17616 | * This tells you the <strong>global</strong> state of these UI visibility |
| 17617 | * flags, not what your app is currently applying. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17618 | */ |
| 17619 | public void onSystemUiVisibilityChange(int visibility); |
| 17620 | } |
| 17621 | |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 17622 | /** |
| 17623 | * Interface definition for a callback to be invoked when this view is attached |
| 17624 | * or detached from its window. |
| 17625 | */ |
| 17626 | public interface OnAttachStateChangeListener { |
| 17627 | /** |
| 17628 | * Called when the view is attached to a window. |
| 17629 | * @param v The view that was attached |
| 17630 | */ |
| 17631 | public void onViewAttachedToWindow(View v); |
| 17632 | /** |
| 17633 | * Called when the view is detached from a window. |
| 17634 | * @param v The view that was detached |
| 17635 | */ |
| 17636 | public void onViewDetachedFromWindow(View v); |
| 17637 | } |
| 17638 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17639 | private final class UnsetPressedState implements Runnable { |
| 17640 | public void run() { |
| 17641 | setPressed(false); |
| 17642 | } |
| 17643 | } |
| 17644 | |
| 17645 | /** |
| 17646 | * Base class for derived classes that want to save and restore their own |
| 17647 | * state in {@link android.view.View#onSaveInstanceState()}. |
| 17648 | */ |
| 17649 | public static class BaseSavedState extends AbsSavedState { |
| 17650 | /** |
| 17651 | * Constructor used when reading from a parcel. Reads the state of the superclass. |
| 17652 | * |
| 17653 | * @param source |
| 17654 | */ |
| 17655 | public BaseSavedState(Parcel source) { |
| 17656 | super(source); |
| 17657 | } |
| 17658 | |
| 17659 | /** |
| 17660 | * Constructor called by derived classes when creating their SavedState objects |
| 17661 | * |
| 17662 | * @param superState The state of the superclass of this view |
| 17663 | */ |
| 17664 | public BaseSavedState(Parcelable superState) { |
| 17665 | super(superState); |
| 17666 | } |
| 17667 | |
| 17668 | public static final Parcelable.Creator<BaseSavedState> CREATOR = |
| 17669 | new Parcelable.Creator<BaseSavedState>() { |
| 17670 | public BaseSavedState createFromParcel(Parcel in) { |
| 17671 | return new BaseSavedState(in); |
| 17672 | } |
| 17673 | |
| 17674 | public BaseSavedState[] newArray(int size) { |
| 17675 | return new BaseSavedState[size]; |
| 17676 | } |
| 17677 | }; |
| 17678 | } |
| 17679 | |
| 17680 | /** |
| 17681 | * A set of information given to a view when it is attached to its parent |
| 17682 | * window. |
| 17683 | */ |
| 17684 | static class AttachInfo { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17685 | interface Callbacks { |
| 17686 | void playSoundEffect(int effectId); |
| 17687 | boolean performHapticFeedback(int effectId, boolean always); |
| 17688 | } |
| 17689 | |
| 17690 | /** |
| 17691 | * InvalidateInfo is used to post invalidate(int, int, int, int) messages |
| 17692 | * to a Handler. This class contains the target (View) to invalidate and |
| 17693 | * the coordinates of the dirty rectangle. |
| 17694 | * |
| 17695 | * For performance purposes, this class also implements a pool of up to |
| 17696 | * POOL_LIMIT objects that get reused. This reduces memory allocations |
| 17697 | * whenever possible. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17698 | */ |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 17699 | static class InvalidateInfo { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17700 | private static final int POOL_LIMIT = 10; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17701 | |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 17702 | private static final SynchronizedPool<InvalidateInfo> sPool = |
| 17703 | new SynchronizedPool<InvalidateInfo>(POOL_LIMIT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17704 | |
| 17705 | View target; |
| 17706 | |
| 17707 | int left; |
| 17708 | int top; |
| 17709 | int right; |
| 17710 | int bottom; |
| 17711 | |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 17712 | public static InvalidateInfo obtain() { |
| 17713 | InvalidateInfo instance = sPool.acquire(); |
| 17714 | return (instance != null) ? instance : new InvalidateInfo(); |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17715 | } |
| 17716 | |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 17717 | public void recycle() { |
| 17718 | target = null; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17719 | sPool.release(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17720 | } |
| 17721 | } |
| 17722 | |
| 17723 | final IWindowSession mSession; |
| 17724 | |
| 17725 | final IWindow mWindow; |
| 17726 | |
| 17727 | final IBinder mWindowToken; |
| 17728 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 17729 | final Display mDisplay; |
| 17730 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17731 | final Callbacks mRootCallbacks; |
| 17732 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 17733 | HardwareCanvas mHardwareCanvas; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 17734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17735 | /** |
| 17736 | * The top view of the hierarchy. |
| 17737 | */ |
| 17738 | View mRootView; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17739 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17740 | IBinder mPanelParentWindowToken; |
| 17741 | Surface mSurface; |
| 17742 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 17743 | boolean mHardwareAccelerated; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 17744 | boolean mHardwareAccelerationRequested; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 17745 | HardwareRenderer mHardwareRenderer; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17746 | |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 17747 | boolean mScreenOn; |
| 17748 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17749 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17750 | * Scale factor used by the compatibility mode |
| 17751 | */ |
| 17752 | float mApplicationScale; |
| 17753 | |
| 17754 | /** |
| 17755 | * Indicates whether the application is in compatibility mode |
| 17756 | */ |
| 17757 | boolean mScalingRequired; |
| 17758 | |
| 17759 | /** |
Romain Guy | 3d1728c | 2012-10-31 20:31:58 -0700 | [diff] [blame] | 17760 | * If set, ViewRootImpl doesn't use its lame animation for when the window resizes. |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 17761 | */ |
| 17762 | boolean mTurnOffWindowResizeAnim; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17763 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 17764 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17765 | * Left position of this view's window |
| 17766 | */ |
| 17767 | int mWindowLeft; |
| 17768 | |
| 17769 | /** |
| 17770 | * Top position of this view's window |
| 17771 | */ |
| 17772 | int mWindowTop; |
| 17773 | |
| 17774 | /** |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 17775 | * Indicates whether views need to use 32-bit drawing caches |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 17776 | */ |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 17777 | boolean mUse32BitDrawingCache; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 17778 | |
| 17779 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17780 | * For windows that are full-screen but using insets to layout inside |
| 17781 | * of the screen decorations, these are the current insets for the |
| 17782 | * content of the window. |
| 17783 | */ |
| 17784 | final Rect mContentInsets = new Rect(); |
| 17785 | |
| 17786 | /** |
| 17787 | * For windows that are full-screen but using insets to layout inside |
| 17788 | * of the screen decorations, these are the current insets for the |
| 17789 | * actual visible parts of the window. |
| 17790 | */ |
| 17791 | final Rect mVisibleInsets = new Rect(); |
| 17792 | |
| 17793 | /** |
| 17794 | * The internal insets given by this window. This value is |
| 17795 | * supplied by the client (through |
| 17796 | * {@link ViewTreeObserver.OnComputeInternalInsetsListener}) and will |
| 17797 | * be given to the window manager when changed to be used in laying |
| 17798 | * out windows behind it. |
| 17799 | */ |
| 17800 | final ViewTreeObserver.InternalInsetsInfo mGivenInternalInsets |
| 17801 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 17802 | |
| 17803 | /** |
| 17804 | * All views in the window's hierarchy that serve as scroll containers, |
| 17805 | * used to determine if the window can be resized or must be panned |
| 17806 | * to adjust for a soft input area. |
| 17807 | */ |
| 17808 | final ArrayList<View> mScrollContainers = new ArrayList<View>(); |
| 17809 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 17810 | final KeyEvent.DispatcherState mKeyDispatchState |
| 17811 | = new KeyEvent.DispatcherState(); |
| 17812 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17813 | /** |
| 17814 | * Indicates whether the view's window currently has the focus. |
| 17815 | */ |
| 17816 | boolean mHasWindowFocus; |
| 17817 | |
| 17818 | /** |
| 17819 | * The current visibility of the window. |
| 17820 | */ |
| 17821 | int mWindowVisibility; |
| 17822 | |
| 17823 | /** |
| 17824 | * Indicates the time at which drawing started to occur. |
| 17825 | */ |
| 17826 | long mDrawingTime; |
| 17827 | |
| 17828 | /** |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 17829 | * Indicates whether or not ignoring the DIRTY_MASK flags. |
| 17830 | */ |
| 17831 | boolean mIgnoreDirtyState; |
| 17832 | |
| 17833 | /** |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 17834 | * This flag tracks when the mIgnoreDirtyState flag is set during draw(), |
| 17835 | * to avoid clearing that flag prematurely. |
| 17836 | */ |
| 17837 | boolean mSetIgnoreDirtyState = false; |
| 17838 | |
| 17839 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17840 | * Indicates whether the view's window is currently in touch mode. |
| 17841 | */ |
| 17842 | boolean mInTouchMode; |
| 17843 | |
| 17844 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 17845 | * Indicates that ViewAncestor should trigger a global layout change |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17846 | * the next time it performs a traversal |
| 17847 | */ |
| 17848 | boolean mRecomputeGlobalAttributes; |
| 17849 | |
| 17850 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 17851 | * Always report new attributes at next traversal. |
| 17852 | */ |
| 17853 | boolean mForceReportNewAttributes; |
| 17854 | |
| 17855 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17856 | * Set during a traveral if any views want to keep the screen on. |
| 17857 | */ |
| 17858 | boolean mKeepScreenOn; |
| 17859 | |
| 17860 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17861 | * Bitwise-or of all of the values that views have passed to setSystemUiVisibility(). |
| 17862 | */ |
| 17863 | int mSystemUiVisibility; |
| 17864 | |
| 17865 | /** |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 17866 | * Hack to force certain system UI visibility flags to be cleared. |
| 17867 | */ |
| 17868 | int mDisabledSystemUiVisibility; |
| 17869 | |
| 17870 | /** |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 17871 | * Last global system UI visibility reported by the window manager. |
| 17872 | */ |
| 17873 | int mGlobalSystemUiVisibility; |
| 17874 | |
| 17875 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17876 | * True if a view in this hierarchy has an OnSystemUiVisibilityChangeListener |
| 17877 | * attached. |
| 17878 | */ |
| 17879 | boolean mHasSystemUiListeners; |
| 17880 | |
| 17881 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17882 | * Set if the visibility of any views has changed. |
| 17883 | */ |
| 17884 | boolean mViewVisibilityChanged; |
| 17885 | |
| 17886 | /** |
| 17887 | * Set to true if a view has been scrolled. |
| 17888 | */ |
| 17889 | boolean mViewScrollChanged; |
| 17890 | |
| 17891 | /** |
| 17892 | * Global to the view hierarchy used as a temporary for dealing with |
| 17893 | * x/y points in the transparent region computations. |
| 17894 | */ |
| 17895 | final int[] mTransparentLocation = new int[2]; |
| 17896 | |
| 17897 | /** |
| 17898 | * Global to the view hierarchy used as a temporary for dealing with |
| 17899 | * x/y points in the ViewGroup.invalidateChild implementation. |
| 17900 | */ |
| 17901 | final int[] mInvalidateChildLocation = new int[2]; |
| 17902 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 17903 | |
| 17904 | /** |
| 17905 | * Global to the view hierarchy used as a temporary for dealing with |
| 17906 | * x/y location when view is transformed. |
| 17907 | */ |
| 17908 | final float[] mTmpTransformLocation = new float[2]; |
| 17909 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17910 | /** |
| 17911 | * The view tree observer used to dispatch global events like |
| 17912 | * layout, pre-draw, touch mode change, etc. |
| 17913 | */ |
| 17914 | final ViewTreeObserver mTreeObserver = new ViewTreeObserver(); |
| 17915 | |
| 17916 | /** |
| 17917 | * A Canvas used by the view hierarchy to perform bitmap caching. |
| 17918 | */ |
| 17919 | Canvas mCanvas; |
| 17920 | |
| 17921 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 17922 | * The view root impl. |
| 17923 | */ |
| 17924 | final ViewRootImpl mViewRootImpl; |
| 17925 | |
| 17926 | /** |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 17927 | * 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] | 17928 | * handler can be used to pump events in the UI events queue. |
| 17929 | */ |
| 17930 | final Handler mHandler; |
| 17931 | |
| 17932 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17933 | * Temporary for use in computing invalidate rectangles while |
| 17934 | * calling up the hierarchy. |
| 17935 | */ |
| 17936 | final Rect mTmpInvalRect = new Rect(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 17937 | |
| 17938 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 17939 | * Temporary for use in computing hit areas with transformed views |
| 17940 | */ |
| 17941 | final RectF mTmpTransformRect = new RectF(); |
| 17942 | |
| 17943 | /** |
Chet Haase | 599913d | 2012-07-23 16:22:05 -0700 | [diff] [blame] | 17944 | * Temporary for use in transforming invalidation rect |
| 17945 | */ |
| 17946 | final Matrix mTmpMatrix = new Matrix(); |
| 17947 | |
| 17948 | /** |
| 17949 | * Temporary for use in transforming invalidation rect |
| 17950 | */ |
| 17951 | final Transformation mTmpTransformation = new Transformation(); |
| 17952 | |
| 17953 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 17954 | * Temporary list for use in collecting focusable descendents of a view. |
| 17955 | */ |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 17956 | final ArrayList<View> mTempArrayList = new ArrayList<View>(24); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 17957 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17958 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 17959 | * The id of the window for accessibility purposes. |
| 17960 | */ |
| 17961 | int mAccessibilityWindowId = View.NO_ID; |
| 17962 | |
| 17963 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 17964 | * Whether to ingore not exposed for accessibility Views when |
| 17965 | * reporting the view tree to accessibility services. |
| 17966 | */ |
| 17967 | boolean mIncludeNotImportantViews; |
| 17968 | |
| 17969 | /** |
| 17970 | * The drawable for highlighting accessibility focus. |
| 17971 | */ |
| 17972 | Drawable mAccessibilityFocusDrawable; |
| 17973 | |
| 17974 | /** |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 17975 | * Show where the margins, bounds and layout bounds are for each view. |
| 17976 | */ |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 17977 | boolean mDebugLayout = SystemProperties.getBoolean(DEBUG_LAYOUT_PROPERTY, false); |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 17978 | |
| 17979 | /** |
Romain Guy | ab4c4f4f | 2012-05-06 13:11:24 -0700 | [diff] [blame] | 17980 | * Point used to compute visible regions. |
| 17981 | */ |
| 17982 | final Point mPoint = new Point(); |
| 17983 | |
| 17984 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17985 | * Creates a new set of attachment information with the specified |
| 17986 | * events handler and thread. |
| 17987 | * |
| 17988 | * @param handler the events handler the view must use |
| 17989 | */ |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 17990 | AttachInfo(IWindowSession session, IWindow window, Display display, |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 17991 | ViewRootImpl viewRootImpl, Handler handler, Callbacks effectPlayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17992 | mSession = session; |
| 17993 | mWindow = window; |
| 17994 | mWindowToken = window.asBinder(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 17995 | mDisplay = display; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 17996 | mViewRootImpl = viewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17997 | mHandler = handler; |
| 17998 | mRootCallbacks = effectPlayer; |
| 17999 | } |
| 18000 | } |
| 18001 | |
| 18002 | /** |
| 18003 | * <p>ScrollabilityCache holds various fields used by a View when scrolling |
| 18004 | * is supported. This avoids keeping too many unused fields in most |
| 18005 | * instances of View.</p> |
| 18006 | */ |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18007 | private static class ScrollabilityCache implements Runnable { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 18008 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18009 | /** |
| 18010 | * Scrollbars are not visible |
| 18011 | */ |
| 18012 | public static final int OFF = 0; |
| 18013 | |
| 18014 | /** |
| 18015 | * Scrollbars are visible |
| 18016 | */ |
| 18017 | public static final int ON = 1; |
| 18018 | |
| 18019 | /** |
| 18020 | * Scrollbars are fading away |
| 18021 | */ |
| 18022 | public static final int FADING = 2; |
| 18023 | |
| 18024 | public boolean fadeScrollBars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 18025 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18026 | public int fadingEdgeLength; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18027 | public int scrollBarDefaultDelayBeforeFade; |
| 18028 | public int scrollBarFadeDuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18029 | |
| 18030 | public int scrollBarSize; |
| 18031 | public ScrollBarDrawable scrollBar; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18032 | public float[] interpolatorValues; |
| 18033 | public View host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18034 | |
| 18035 | public final Paint paint; |
| 18036 | public final Matrix matrix; |
| 18037 | public Shader shader; |
| 18038 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18039 | public final Interpolator scrollBarInterpolator = new Interpolator(1, 2); |
| 18040 | |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 18041 | private static final float[] OPAQUE = { 255 }; |
| 18042 | private static final float[] TRANSPARENT = { 0.0f }; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 18043 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18044 | /** |
| 18045 | * When fading should start. This time moves into the future every time |
| 18046 | * a new scroll happens. Measured based on SystemClock.uptimeMillis() |
| 18047 | */ |
| 18048 | public long fadeStartTime; |
| 18049 | |
| 18050 | |
| 18051 | /** |
| 18052 | * The current state of the scrollbars: ON, OFF, or FADING |
| 18053 | */ |
| 18054 | public int state = OFF; |
| 18055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18056 | private int mLastColor; |
| 18057 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18058 | public ScrollabilityCache(ViewConfiguration configuration, View host) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18059 | fadingEdgeLength = configuration.getScaledFadingEdgeLength(); |
| 18060 | scrollBarSize = configuration.getScaledScrollBarSize(); |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 18061 | scrollBarDefaultDelayBeforeFade = ViewConfiguration.getScrollDefaultDelay(); |
| 18062 | scrollBarFadeDuration = ViewConfiguration.getScrollBarFadeDuration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18063 | |
| 18064 | paint = new Paint(); |
| 18065 | matrix = new Matrix(); |
| 18066 | // use use a height of 1, and then wack the matrix each time we |
| 18067 | // actually use it. |
| 18068 | shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18069 | paint.setShader(shader); |
| 18070 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
Romain Guy | d679b57 | 2012-08-29 21:49:00 -0700 | [diff] [blame] | 18071 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18072 | this.host = host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18073 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 18074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18075 | public void setFadeColor(int color) { |
Romain Guy | d679b57 | 2012-08-29 21:49:00 -0700 | [diff] [blame] | 18076 | if (color != mLastColor) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18077 | mLastColor = color; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 18078 | |
Romain Guy | d679b57 | 2012-08-29 21:49:00 -0700 | [diff] [blame] | 18079 | if (color != 0) { |
| 18080 | shader = new LinearGradient(0, 0, 0, 1, color | 0xFF000000, |
| 18081 | color & 0x00FFFFFF, Shader.TileMode.CLAMP); |
| 18082 | paint.setShader(shader); |
| 18083 | // Restore the default transfer mode (src_over) |
| 18084 | paint.setXfermode(null); |
| 18085 | } else { |
| 18086 | shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP); |
| 18087 | paint.setShader(shader); |
| 18088 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
| 18089 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18090 | } |
| 18091 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 18092 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18093 | public void run() { |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 18094 | long now = AnimationUtils.currentAnimationTimeMillis(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18095 | if (now >= fadeStartTime) { |
| 18096 | |
| 18097 | // the animation fades the scrollbars out by changing |
| 18098 | // the opacity (alpha) from fully opaque to fully |
| 18099 | // transparent |
| 18100 | int nextFrame = (int) now; |
| 18101 | int framesCount = 0; |
| 18102 | |
| 18103 | Interpolator interpolator = scrollBarInterpolator; |
| 18104 | |
| 18105 | // Start opaque |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 18106 | interpolator.setKeyFrame(framesCount++, nextFrame, OPAQUE); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18107 | |
| 18108 | // End transparent |
| 18109 | nextFrame += scrollBarFadeDuration; |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 18110 | interpolator.setKeyFrame(framesCount, nextFrame, TRANSPARENT); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18111 | |
| 18112 | state = FADING; |
| 18113 | |
| 18114 | // Kick off the fade animation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 18115 | host.invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18116 | } |
| 18117 | } |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 18118 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18119 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 18120 | /** |
| 18121 | * Resuable callback for sending |
| 18122 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 18123 | */ |
| 18124 | private class SendViewScrolledAccessibilityEvent implements Runnable { |
| 18125 | public volatile boolean mIsPending; |
| 18126 | |
| 18127 | public void run() { |
| 18128 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED); |
| 18129 | mIsPending = false; |
| 18130 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18131 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 18132 | |
| 18133 | /** |
| 18134 | * <p> |
| 18135 | * This class represents a delegate that can be registered in a {@link View} |
| 18136 | * to enhance accessibility support via composition rather via inheritance. |
| 18137 | * It is specifically targeted to widget developers that extend basic View |
| 18138 | * classes i.e. classes in package android.view, that would like their |
| 18139 | * applications to be backwards compatible. |
| 18140 | * </p> |
Joe Fernandez | e1302ed | 2012-02-06 14:30:15 -0800 | [diff] [blame] | 18141 | * <div class="special reference"> |
| 18142 | * <h3>Developer Guides</h3> |
| 18143 | * <p>For more information about making applications accessible, read the |
| 18144 | * <a href="{@docRoot}guide/topics/ui/accessibility/index.html">Accessibility</a> |
| 18145 | * developer guide.</p> |
| 18146 | * </div> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 18147 | * <p> |
| 18148 | * A scenario in which a developer would like to use an accessibility delegate |
| 18149 | * is overriding a method introduced in a later API version then the minimal API |
| 18150 | * version supported by the application. For example, the method |
| 18151 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} is not available |
| 18152 | * in API version 4 when the accessibility APIs were first introduced. If a |
| 18153 | * developer would like his application to run on API version 4 devices (assuming |
| 18154 | * all other APIs used by the application are version 4 or lower) and take advantage |
| 18155 | * of this method, instead of overriding the method which would break the application's |
| 18156 | * backwards compatibility, he can override the corresponding method in this |
| 18157 | * delegate and register the delegate in the target View if the API version of |
| 18158 | * the system is high enough i.e. the API version is same or higher to the API |
| 18159 | * version that introduced |
| 18160 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)}. |
| 18161 | * </p> |
| 18162 | * <p> |
| 18163 | * Here is an example implementation: |
| 18164 | * </p> |
| 18165 | * <code><pre><p> |
| 18166 | * if (Build.VERSION.SDK_INT >= 14) { |
| 18167 | * // If the API version is equal of higher than the version in |
| 18168 | * // which onInitializeAccessibilityNodeInfo was introduced we |
| 18169 | * // register a delegate with a customized implementation. |
| 18170 | * View view = findViewById(R.id.view_id); |
| 18171 | * view.setAccessibilityDelegate(new AccessibilityDelegate() { |
| 18172 | * public void onInitializeAccessibilityNodeInfo(View host, |
| 18173 | * AccessibilityNodeInfo info) { |
| 18174 | * // Let the default implementation populate the info. |
| 18175 | * super.onInitializeAccessibilityNodeInfo(host, info); |
| 18176 | * // Set some other information. |
| 18177 | * info.setEnabled(host.isEnabled()); |
| 18178 | * } |
| 18179 | * }); |
| 18180 | * } |
| 18181 | * </code></pre></p> |
| 18182 | * <p> |
| 18183 | * This delegate contains methods that correspond to the accessibility methods |
| 18184 | * in View. If a delegate has been specified the implementation in View hands |
| 18185 | * off handling to the corresponding method in this delegate. The default |
| 18186 | * implementation the delegate methods behaves exactly as the corresponding |
| 18187 | * method in View for the case of no accessibility delegate been set. Hence, |
| 18188 | * to customize the behavior of a View method, clients can override only the |
| 18189 | * corresponding delegate method without altering the behavior of the rest |
| 18190 | * accessibility related methods of the host view. |
| 18191 | * </p> |
| 18192 | */ |
| 18193 | public static class AccessibilityDelegate { |
| 18194 | |
| 18195 | /** |
| 18196 | * Sends an accessibility event of the given type. If accessibility is not |
| 18197 | * enabled this method has no effect. |
| 18198 | * <p> |
| 18199 | * The default implementation behaves as {@link View#sendAccessibilityEvent(int) |
| 18200 | * View#sendAccessibilityEvent(int)} for the case of no accessibility delegate |
| 18201 | * been set. |
| 18202 | * </p> |
| 18203 | * |
| 18204 | * @param host The View hosting the delegate. |
| 18205 | * @param eventType The type of the event to send. |
| 18206 | * |
| 18207 | * @see View#sendAccessibilityEvent(int) View#sendAccessibilityEvent(int) |
| 18208 | */ |
| 18209 | public void sendAccessibilityEvent(View host, int eventType) { |
| 18210 | host.sendAccessibilityEventInternal(eventType); |
| 18211 | } |
| 18212 | |
| 18213 | /** |
alanv | 8eeefef | 2012-05-07 16:57:53 -0700 | [diff] [blame] | 18214 | * Performs the specified accessibility action on the view. For |
| 18215 | * possible accessibility actions look at {@link AccessibilityNodeInfo}. |
| 18216 | * <p> |
| 18217 | * The default implementation behaves as |
| 18218 | * {@link View#performAccessibilityAction(int, Bundle) |
| 18219 | * View#performAccessibilityAction(int, Bundle)} for the case of |
| 18220 | * no accessibility delegate been set. |
| 18221 | * </p> |
| 18222 | * |
| 18223 | * @param action The action to perform. |
| 18224 | * @return Whether the action was performed. |
| 18225 | * |
| 18226 | * @see View#performAccessibilityAction(int, Bundle) |
| 18227 | * View#performAccessibilityAction(int, Bundle) |
| 18228 | */ |
| 18229 | public boolean performAccessibilityAction(View host, int action, Bundle args) { |
| 18230 | return host.performAccessibilityActionInternal(action, args); |
| 18231 | } |
| 18232 | |
| 18233 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 18234 | * Sends an accessibility event. This method behaves exactly as |
| 18235 | * {@link #sendAccessibilityEvent(View, int)} but takes as an argument an |
| 18236 | * empty {@link AccessibilityEvent} and does not perform a check whether |
| 18237 | * accessibility is enabled. |
| 18238 | * <p> |
| 18239 | * The default implementation behaves as |
| 18240 | * {@link View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 18241 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent)} for |
| 18242 | * the case of no accessibility delegate been set. |
| 18243 | * </p> |
| 18244 | * |
| 18245 | * @param host The View hosting the delegate. |
| 18246 | * @param event The event to send. |
| 18247 | * |
| 18248 | * @see View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 18249 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 18250 | */ |
| 18251 | public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) { |
| 18252 | host.sendAccessibilityEventUncheckedInternal(event); |
| 18253 | } |
| 18254 | |
| 18255 | /** |
| 18256 | * Dispatches an {@link AccessibilityEvent} to the host {@link View} first and then |
| 18257 | * to its children for adding their text content to the event. |
| 18258 | * <p> |
| 18259 | * The default implementation behaves as |
| 18260 | * {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 18261 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 18262 | * the case of no accessibility delegate been set. |
| 18263 | * </p> |
| 18264 | * |
| 18265 | * @param host The View hosting the delegate. |
| 18266 | * @param event The event. |
| 18267 | * @return True if the event population was completed. |
| 18268 | * |
| 18269 | * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 18270 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 18271 | */ |
| 18272 | public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 18273 | return host.dispatchPopulateAccessibilityEventInternal(event); |
| 18274 | } |
| 18275 | |
| 18276 | /** |
| 18277 | * Gives a chance to the host View to populate the accessibility event with its |
| 18278 | * text content. |
| 18279 | * <p> |
| 18280 | * The default implementation behaves as |
| 18281 | * {@link View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 18282 | * View#onPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 18283 | * the case of no accessibility delegate been set. |
| 18284 | * </p> |
| 18285 | * |
| 18286 | * @param host The View hosting the delegate. |
| 18287 | * @param event The accessibility event which to populate. |
| 18288 | * |
| 18289 | * @see View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 18290 | * View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 18291 | */ |
| 18292 | public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 18293 | host.onPopulateAccessibilityEventInternal(event); |
| 18294 | } |
| 18295 | |
| 18296 | /** |
| 18297 | * Initializes an {@link AccessibilityEvent} with information about the |
| 18298 | * the host View which is the event source. |
| 18299 | * <p> |
| 18300 | * The default implementation behaves as |
| 18301 | * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 18302 | * View#onInitializeAccessibilityEvent(AccessibilityEvent)} for |
| 18303 | * the case of no accessibility delegate been set. |
| 18304 | * </p> |
| 18305 | * |
| 18306 | * @param host The View hosting the delegate. |
| 18307 | * @param event The event to initialize. |
| 18308 | * |
| 18309 | * @see View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 18310 | * View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 18311 | */ |
| 18312 | public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { |
| 18313 | host.onInitializeAccessibilityEventInternal(event); |
| 18314 | } |
| 18315 | |
| 18316 | /** |
| 18317 | * Initializes an {@link AccessibilityNodeInfo} with information about the host view. |
| 18318 | * <p> |
| 18319 | * The default implementation behaves as |
| 18320 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 18321 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} for |
| 18322 | * the case of no accessibility delegate been set. |
| 18323 | * </p> |
| 18324 | * |
| 18325 | * @param host The View hosting the delegate. |
| 18326 | * @param info The instance to initialize. |
| 18327 | * |
| 18328 | * @see View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 18329 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 18330 | */ |
| 18331 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 18332 | host.onInitializeAccessibilityNodeInfoInternal(info); |
| 18333 | } |
| 18334 | |
| 18335 | /** |
| 18336 | * Called when a child of the host View has requested sending an |
| 18337 | * {@link AccessibilityEvent} and gives an opportunity to the parent (the host) |
| 18338 | * to augment the event. |
| 18339 | * <p> |
| 18340 | * The default implementation behaves as |
| 18341 | * {@link ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 18342 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent)} for |
| 18343 | * the case of no accessibility delegate been set. |
| 18344 | * </p> |
| 18345 | * |
| 18346 | * @param host The View hosting the delegate. |
| 18347 | * @param child The child which requests sending the event. |
| 18348 | * @param event The event to be sent. |
| 18349 | * @return True if the event should be sent |
| 18350 | * |
| 18351 | * @see ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 18352 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 18353 | */ |
| 18354 | public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, |
| 18355 | AccessibilityEvent event) { |
| 18356 | return host.onRequestSendAccessibilityEventInternal(child, event); |
| 18357 | } |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 18358 | |
| 18359 | /** |
| 18360 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 18361 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 18362 | * that explore the window content. |
| 18363 | * <p> |
| 18364 | * The default implementation behaves as |
| 18365 | * {@link View#getAccessibilityNodeProvider() View#getAccessibilityNodeProvider()} for |
| 18366 | * the case of no accessibility delegate been set. |
| 18367 | * </p> |
| 18368 | * |
| 18369 | * @return The provider. |
| 18370 | * |
| 18371 | * @see AccessibilityNodeProvider |
| 18372 | */ |
| 18373 | public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) { |
| 18374 | return null; |
| 18375 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 18376 | } |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 18377 | |
| 18378 | private class MatchIdPredicate implements Predicate<View> { |
| 18379 | public int mId; |
| 18380 | |
| 18381 | @Override |
| 18382 | public boolean apply(View view) { |
| 18383 | return (view.mID == mId); |
| 18384 | } |
| 18385 | } |
| 18386 | |
| 18387 | private class MatchLabelForPredicate implements Predicate<View> { |
| 18388 | private int mLabeledId; |
| 18389 | |
| 18390 | @Override |
| 18391 | public boolean apply(View view) { |
| 18392 | return (view.mLabelForId == mLabeledId); |
| 18393 | } |
| 18394 | } |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 18395 | |
| 18396 | /** |
| 18397 | * Dump all private flags in readable format, useful for documentation and |
| 18398 | * sanity checking. |
| 18399 | */ |
| 18400 | private static void dumpFlags() { |
| 18401 | final HashMap<String, String> found = Maps.newHashMap(); |
| 18402 | try { |
| 18403 | for (Field field : View.class.getDeclaredFields()) { |
| 18404 | final int modifiers = field.getModifiers(); |
| 18405 | if (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)) { |
| 18406 | if (field.getType().equals(int.class)) { |
| 18407 | final int value = field.getInt(null); |
| 18408 | dumpFlag(found, field.getName(), value); |
| 18409 | } else if (field.getType().equals(int[].class)) { |
| 18410 | final int[] values = (int[]) field.get(null); |
| 18411 | for (int i = 0; i < values.length; i++) { |
| 18412 | dumpFlag(found, field.getName() + "[" + i + "]", values[i]); |
| 18413 | } |
| 18414 | } |
| 18415 | } |
| 18416 | } |
| 18417 | } catch (IllegalAccessException e) { |
| 18418 | throw new RuntimeException(e); |
| 18419 | } |
| 18420 | |
| 18421 | final ArrayList<String> keys = Lists.newArrayList(); |
| 18422 | keys.addAll(found.keySet()); |
| 18423 | Collections.sort(keys); |
| 18424 | for (String key : keys) { |
| 18425 | Log.d(VIEW_LOG_TAG, found.get(key)); |
| 18426 | } |
| 18427 | } |
| 18428 | |
| 18429 | private static void dumpFlag(HashMap<String, String> found, String name, int value) { |
| 18430 | // Sort flags by prefix, then by bits, always keeping unique keys |
| 18431 | final String bits = String.format("%32s", Integer.toBinaryString(value)).replace('0', ' '); |
| 18432 | final int prefix = name.indexOf('_'); |
| 18433 | final String key = (prefix > 0 ? name.substring(0, prefix) : name) + bits + name; |
| 18434 | final String output = bits + " " + name; |
| 18435 | found.put(key, output); |
| 18436 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18437 | } |