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; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 55 | import android.util.Pool; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 56 | import android.util.Poolable; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 57 | import android.util.PoolableManager; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 58 | import android.util.Pools; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 59 | import android.util.Property; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 60 | import android.util.SparseArray; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 61 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.view.ContextMenu.ContextMenuInfo; |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 63 | import android.view.AccessibilityIterators.TextSegmentIterator; |
| 64 | import android.view.AccessibilityIterators.CharacterTextSegmentIterator; |
| 65 | import android.view.AccessibilityIterators.WordTextSegmentIterator; |
| 66 | import android.view.AccessibilityIterators.ParagraphTextSegmentIterator; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 67 | import android.view.accessibility.AccessibilityEvent; |
| 68 | import android.view.accessibility.AccessibilityEventSource; |
| 69 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 70 | import android.view.accessibility.AccessibilityNodeInfo; |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 71 | import android.view.accessibility.AccessibilityNodeProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.view.animation.Animation; |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 73 | import android.view.animation.AnimationUtils; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 74 | import android.view.animation.Transformation; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 75 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | import android.view.inputmethod.InputConnection; |
| 77 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | import android.widget.ScrollBarDrawable; |
| 79 | |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 80 | import static android.os.Build.VERSION_CODES.*; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 81 | import static java.lang.Math.max; |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 82 | |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 83 | import com.android.internal.R; |
| 84 | import com.android.internal.util.Predicate; |
| 85 | import com.android.internal.view.menu.MenuBuilder; |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 86 | import com.google.android.collect.Lists; |
| 87 | import com.google.android.collect.Maps; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 88 | |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 89 | import java.lang.ref.WeakReference; |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 90 | import java.lang.reflect.Field; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 91 | import java.lang.reflect.InvocationTargetException; |
| 92 | import java.lang.reflect.Method; |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 93 | import java.lang.reflect.Modifier; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import java.util.ArrayList; |
| 95 | import java.util.Arrays; |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 96 | import java.util.Collections; |
| 97 | import java.util.HashMap; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 98 | import java.util.Locale; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 99 | import java.util.concurrent.CopyOnWriteArrayList; |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 100 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * <p> |
| 104 | * This class represents the basic building block for user interface components. A View |
| 105 | * occupies a rectangular area on the screen and is responsible for drawing and |
| 106 | * 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] | 107 | * 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] | 108 | * {@link android.view.ViewGroup} subclass is the base class for <em>layouts</em>, which |
| 109 | * are invisible containers that hold other Views (or other ViewGroups) and define |
| 110 | * their layout properties. |
| 111 | * </p> |
| 112 | * |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 113 | * <div class="special reference"> |
| 114 | * <h3>Developer Guides</h3> |
| 115 | * <p>For information about using this class to develop your application's user interface, |
| 116 | * 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] | 117 | * </div> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 118 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | * <a name="Using"></a> |
| 120 | * <h3>Using Views</h3> |
| 121 | * <p> |
| 122 | * All of the views in a window are arranged in a single tree. You can add views |
| 123 | * either from code or by specifying a tree of views in one or more XML layout |
| 124 | * files. There are many specialized subclasses of views that act as controls or |
| 125 | * are capable of displaying text, images, or other content. |
| 126 | * </p> |
| 127 | * <p> |
| 128 | * Once you have created a tree of views, there are typically a few types of |
| 129 | * common operations you may wish to perform: |
| 130 | * <ul> |
| 131 | * <li><strong>Set properties:</strong> for example setting the text of a |
| 132 | * {@link android.widget.TextView}. The available properties and the methods |
| 133 | * that set them will vary among the different subclasses of views. Note that |
| 134 | * properties that are known at build time can be set in the XML layout |
| 135 | * files.</li> |
| 136 | * <li><strong>Set focus:</strong> The framework will handled moving focus in |
| 137 | * response to user input. To force focus to a specific view, call |
| 138 | * {@link #requestFocus}.</li> |
| 139 | * <li><strong>Set up listeners:</strong> Views allow clients to set listeners |
| 140 | * that will be notified when something interesting happens to the view. For |
| 141 | * example, all views will let you set a listener to be notified when the view |
| 142 | * gains or loses focus. You can register such a listener using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 143 | * {@link #setOnFocusChangeListener(android.view.View.OnFocusChangeListener)}. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 144 | * Other view subclasses offer more specialized listeners. For example, a Button |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 145 | * 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] | 146 | * <li><strong>Set visibility:</strong> You can hide or show views using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 147 | * {@link #setVisibility(int)}.</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | * </ul> |
| 149 | * </p> |
| 150 | * <p><em> |
| 151 | * Note: The Android framework is responsible for measuring, laying out and |
| 152 | * drawing views. You should not call methods that perform these actions on |
| 153 | * views yourself unless you are actually implementing a |
| 154 | * {@link android.view.ViewGroup}. |
| 155 | * </em></p> |
| 156 | * |
| 157 | * <a name="Lifecycle"></a> |
| 158 | * <h3>Implementing a Custom View</h3> |
| 159 | * |
| 160 | * <p> |
| 161 | * To implement a custom view, you will usually begin by providing overrides for |
| 162 | * some of the standard methods that the framework calls on all views. You do |
| 163 | * not need to override all of these methods. In fact, you can start by just |
| 164 | * overriding {@link #onDraw(android.graphics.Canvas)}. |
| 165 | * <table border="2" width="85%" align="center" cellpadding="5"> |
| 166 | * <thead> |
| 167 | * <tr><th>Category</th> <th>Methods</th> <th>Description</th></tr> |
| 168 | * </thead> |
| 169 | * |
| 170 | * <tbody> |
| 171 | * <tr> |
| 172 | * <td rowspan="2">Creation</td> |
| 173 | * <td>Constructors</td> |
| 174 | * <td>There is a form of the constructor that are called when the view |
| 175 | * is created from code and a form that is called when the view is |
| 176 | * inflated from a layout file. The second form should parse and apply |
| 177 | * any attributes defined in the layout file. |
| 178 | * </td> |
| 179 | * </tr> |
| 180 | * <tr> |
| 181 | * <td><code>{@link #onFinishInflate()}</code></td> |
| 182 | * <td>Called after a view and all of its children has been inflated |
| 183 | * from XML.</td> |
| 184 | * </tr> |
| 185 | * |
| 186 | * <tr> |
| 187 | * <td rowspan="3">Layout</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 188 | * <td><code>{@link #onMeasure(int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | * <td>Called to determine the size requirements for this view and all |
| 190 | * of its children. |
| 191 | * </td> |
| 192 | * </tr> |
| 193 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 194 | * <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] | 195 | * <td>Called when this view should assign a size and position to all |
| 196 | * of its children. |
| 197 | * </td> |
| 198 | * </tr> |
| 199 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 200 | * <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] | 201 | * <td>Called when the size of this view has changed. |
| 202 | * </td> |
| 203 | * </tr> |
| 204 | * |
| 205 | * <tr> |
| 206 | * <td>Drawing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 207 | * <td><code>{@link #onDraw(android.graphics.Canvas)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | * <td>Called when the view should render its content. |
| 209 | * </td> |
| 210 | * </tr> |
| 211 | * |
| 212 | * <tr> |
| 213 | * <td rowspan="4">Event processing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 214 | * <td><code>{@link #onKeyDown(int, KeyEvent)}</code></td> |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 215 | * <td>Called when a new hardware key event occurs. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | * </td> |
| 217 | * </tr> |
| 218 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 219 | * <td><code>{@link #onKeyUp(int, KeyEvent)}</code></td> |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 220 | * <td>Called when a hardware key up event occurs. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | * </td> |
| 222 | * </tr> |
| 223 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 224 | * <td><code>{@link #onTrackballEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | * <td>Called when a trackball motion event occurs. |
| 226 | * </td> |
| 227 | * </tr> |
| 228 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 229 | * <td><code>{@link #onTouchEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | * <td>Called when a touch screen motion event occurs. |
| 231 | * </td> |
| 232 | * </tr> |
| 233 | * |
| 234 | * <tr> |
| 235 | * <td rowspan="2">Focus</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 236 | * <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] | 237 | * <td>Called when the view gains or loses focus. |
| 238 | * </td> |
| 239 | * </tr> |
| 240 | * |
| 241 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 242 | * <td><code>{@link #onWindowFocusChanged(boolean)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | * <td>Called when the window containing the view gains or loses focus. |
| 244 | * </td> |
| 245 | * </tr> |
| 246 | * |
| 247 | * <tr> |
| 248 | * <td rowspan="3">Attaching</td> |
| 249 | * <td><code>{@link #onAttachedToWindow()}</code></td> |
| 250 | * <td>Called when the view is attached to a window. |
| 251 | * </td> |
| 252 | * </tr> |
| 253 | * |
| 254 | * <tr> |
| 255 | * <td><code>{@link #onDetachedFromWindow}</code></td> |
| 256 | * <td>Called when the view is detached from its window. |
| 257 | * </td> |
| 258 | * </tr> |
| 259 | * |
| 260 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 261 | * <td><code>{@link #onWindowVisibilityChanged(int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | * <td>Called when the visibility of the window containing the view |
| 263 | * has changed. |
| 264 | * </td> |
| 265 | * </tr> |
| 266 | * </tbody> |
| 267 | * |
| 268 | * </table> |
| 269 | * </p> |
| 270 | * |
| 271 | * <a name="IDs"></a> |
| 272 | * <h3>IDs</h3> |
| 273 | * Views may have an integer id associated with them. These ids are typically |
| 274 | * assigned in the layout XML files, and are used to find specific views within |
| 275 | * the view tree. A common pattern is to: |
| 276 | * <ul> |
| 277 | * <li>Define a Button in the layout file and assign it a unique ID. |
| 278 | * <pre> |
Gilles Debunne | 0243caf | 2010-08-24 23:06:35 -0700 | [diff] [blame] | 279 | * <Button |
| 280 | * android:id="@+id/my_button" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | * android:layout_width="wrap_content" |
| 282 | * android:layout_height="wrap_content" |
| 283 | * android:text="@string/my_button_text"/> |
| 284 | * </pre></li> |
| 285 | * <li>From the onCreate method of an Activity, find the Button |
| 286 | * <pre class="prettyprint"> |
| 287 | * Button myButton = (Button) findViewById(R.id.my_button); |
| 288 | * </pre></li> |
| 289 | * </ul> |
| 290 | * <p> |
| 291 | * View IDs need not be unique throughout the tree, but it is good practice to |
| 292 | * ensure that they are at least unique within the part of the tree you are |
| 293 | * searching. |
| 294 | * </p> |
| 295 | * |
| 296 | * <a name="Position"></a> |
| 297 | * <h3>Position</h3> |
| 298 | * <p> |
| 299 | * The geometry of a view is that of a rectangle. A view has a location, |
| 300 | * expressed as a pair of <em>left</em> and <em>top</em> coordinates, and |
| 301 | * two dimensions, expressed as a width and a height. The unit for location |
| 302 | * and dimensions is the pixel. |
| 303 | * </p> |
| 304 | * |
| 305 | * <p> |
| 306 | * It is possible to retrieve the location of a view by invoking the methods |
| 307 | * {@link #getLeft()} and {@link #getTop()}. The former returns the left, or X, |
| 308 | * coordinate of the rectangle representing the view. The latter returns the |
| 309 | * top, or Y, coordinate of the rectangle representing the view. These methods |
| 310 | * both return the location of the view relative to its parent. For instance, |
| 311 | * when getLeft() returns 20, that means the view is located 20 pixels to the |
| 312 | * right of the left edge of its direct parent. |
| 313 | * </p> |
| 314 | * |
| 315 | * <p> |
| 316 | * In addition, several convenience methods are offered to avoid unnecessary |
| 317 | * computations, namely {@link #getRight()} and {@link #getBottom()}. |
| 318 | * These methods return the coordinates of the right and bottom edges of the |
| 319 | * rectangle representing the view. For instance, calling {@link #getRight()} |
| 320 | * is similar to the following computation: <code>getLeft() + getWidth()</code> |
| 321 | * (see <a href="#SizePaddingMargins">Size</a> for more information about the width.) |
| 322 | * </p> |
| 323 | * |
| 324 | * <a name="SizePaddingMargins"></a> |
| 325 | * <h3>Size, padding and margins</h3> |
| 326 | * <p> |
| 327 | * The size of a view is expressed with a width and a height. A view actually |
| 328 | * possess two pairs of width and height values. |
| 329 | * </p> |
| 330 | * |
| 331 | * <p> |
| 332 | * The first pair is known as <em>measured width</em> and |
| 333 | * <em>measured height</em>. These dimensions define how big a view wants to be |
| 334 | * within its parent (see <a href="#Layout">Layout</a> for more details.) The |
| 335 | * measured dimensions can be obtained by calling {@link #getMeasuredWidth()} |
| 336 | * and {@link #getMeasuredHeight()}. |
| 337 | * </p> |
| 338 | * |
| 339 | * <p> |
| 340 | * The second pair is simply known as <em>width</em> and <em>height</em>, or |
| 341 | * sometimes <em>drawing width</em> and <em>drawing height</em>. These |
| 342 | * dimensions define the actual size of the view on screen, at drawing time and |
| 343 | * after layout. These values may, but do not have to, be different from the |
| 344 | * measured width and height. The width and height can be obtained by calling |
| 345 | * {@link #getWidth()} and {@link #getHeight()}. |
| 346 | * </p> |
| 347 | * |
| 348 | * <p> |
| 349 | * To measure its dimensions, a view takes into account its padding. The padding |
| 350 | * is expressed in pixels for the left, top, right and bottom parts of the view. |
| 351 | * Padding can be used to offset the content of the view by a specific amount of |
| 352 | * pixels. For instance, a left padding of 2 will push the view's content by |
| 353 | * 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] | 354 | * {@link #setPadding(int, int, int, int)} or {@link #setPaddingRelative(int, int, int, int)} |
| 355 | * method and queried by calling {@link #getPaddingLeft()}, {@link #getPaddingTop()}, |
| 356 | * {@link #getPaddingRight()}, {@link #getPaddingBottom()}, {@link #getPaddingStart()}, |
| 357 | * {@link #getPaddingEnd()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | * </p> |
| 359 | * |
| 360 | * <p> |
| 361 | * Even though a view can define a padding, it does not provide any support for |
| 362 | * margins. However, view groups provide such a support. Refer to |
| 363 | * {@link android.view.ViewGroup} and |
| 364 | * {@link android.view.ViewGroup.MarginLayoutParams} for further information. |
| 365 | * </p> |
| 366 | * |
| 367 | * <a name="Layout"></a> |
| 368 | * <h3>Layout</h3> |
| 369 | * <p> |
| 370 | * Layout is a two pass process: a measure pass and a layout pass. The measuring |
| 371 | * pass is implemented in {@link #measure(int, int)} and is a top-down traversal |
| 372 | * of the view tree. Each view pushes dimension specifications down the tree |
| 373 | * during the recursion. At the end of the measure pass, every view has stored |
| 374 | * its measurements. The second pass happens in |
| 375 | * {@link #layout(int,int,int,int)} and is also top-down. During |
| 376 | * this pass each parent is responsible for positioning all of its children |
| 377 | * using the sizes computed in the measure pass. |
| 378 | * </p> |
| 379 | * |
| 380 | * <p> |
| 381 | * When a view's measure() method returns, its {@link #getMeasuredWidth()} and |
| 382 | * {@link #getMeasuredHeight()} values must be set, along with those for all of |
| 383 | * that view's descendants. A view's measured width and measured height values |
| 384 | * must respect the constraints imposed by the view's parents. This guarantees |
| 385 | * that at the end of the measure pass, all parents accept all of their |
| 386 | * children's measurements. A parent view may call measure() more than once on |
| 387 | * its children. For example, the parent may measure each child once with |
| 388 | * unspecified dimensions to find out how big they want to be, then call |
| 389 | * measure() on them again with actual numbers if the sum of all the children's |
| 390 | * unconstrained sizes is too big or too small. |
| 391 | * </p> |
| 392 | * |
| 393 | * <p> |
| 394 | * The measure pass uses two classes to communicate dimensions. The |
| 395 | * {@link MeasureSpec} class is used by views to tell their parents how they |
| 396 | * want to be measured and positioned. The base LayoutParams class just |
| 397 | * describes how big the view wants to be for both width and height. For each |
| 398 | * dimension, it can specify one of: |
| 399 | * <ul> |
| 400 | * <li> an exact number |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 401 | * <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] | 402 | * (minus padding) |
| 403 | * <li> WRAP_CONTENT, which means that the view wants to be just big enough to |
| 404 | * enclose its content (plus padding). |
| 405 | * </ul> |
| 406 | * There are subclasses of LayoutParams for different subclasses of ViewGroup. |
| 407 | * For example, AbsoluteLayout has its own subclass of LayoutParams which adds |
| 408 | * an X and Y value. |
| 409 | * </p> |
| 410 | * |
| 411 | * <p> |
| 412 | * MeasureSpecs are used to push requirements down the tree from parent to |
| 413 | * child. A MeasureSpec can be in one of three modes: |
| 414 | * <ul> |
| 415 | * <li>UNSPECIFIED: This is used by a parent to determine the desired dimension |
| 416 | * of a child view. For example, a LinearLayout may call measure() on its child |
| 417 | * with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how |
| 418 | * tall the child view wants to be given a width of 240 pixels. |
| 419 | * <li>EXACTLY: This is used by the parent to impose an exact size on the |
| 420 | * child. The child must use this size, and guarantee that all of its |
| 421 | * descendants will fit within this size. |
| 422 | * <li>AT_MOST: This is used by the parent to impose a maximum size on the |
| 423 | * child. The child must gurantee that it and all of its descendants will fit |
| 424 | * within this size. |
| 425 | * </ul> |
| 426 | * </p> |
| 427 | * |
| 428 | * <p> |
| 429 | * To intiate a layout, call {@link #requestLayout}. This method is typically |
| 430 | * called by a view on itself when it believes that is can no longer fit within |
| 431 | * its current bounds. |
| 432 | * </p> |
| 433 | * |
| 434 | * <a name="Drawing"></a> |
| 435 | * <h3>Drawing</h3> |
| 436 | * <p> |
| 437 | * Drawing is handled by walking the tree and rendering each view that |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 438 | * 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] | 439 | * this means that parents will draw before (i.e., behind) their children, with |
| 440 | * siblings drawn in the order they appear in the tree. |
| 441 | * If you set a background drawable for a View, then the View will draw it for you |
| 442 | * before calling back to its <code>onDraw()</code> method. |
| 443 | * </p> |
| 444 | * |
| 445 | * <p> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 446 | * 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] | 447 | * </p> |
| 448 | * |
| 449 | * <p> |
| 450 | * To force a view to draw, call {@link #invalidate()}. |
| 451 | * </p> |
| 452 | * |
| 453 | * <a name="EventHandlingThreading"></a> |
| 454 | * <h3>Event Handling and Threading</h3> |
| 455 | * <p> |
| 456 | * The basic cycle of a view is as follows: |
| 457 | * <ol> |
| 458 | * <li>An event comes in and is dispatched to the appropriate view. The view |
| 459 | * handles the event and notifies any listeners.</li> |
| 460 | * <li>If in the course of processing the event, the view's bounds may need |
| 461 | * to be changed, the view will call {@link #requestLayout()}.</li> |
| 462 | * <li>Similarly, if in the course of processing the event the view's appearance |
| 463 | * may need to be changed, the view will call {@link #invalidate()}.</li> |
| 464 | * <li>If either {@link #requestLayout()} or {@link #invalidate()} were called, |
| 465 | * the framework will take care of measuring, laying out, and drawing the tree |
| 466 | * as appropriate.</li> |
| 467 | * </ol> |
| 468 | * </p> |
| 469 | * |
| 470 | * <p><em>Note: The entire view tree is single threaded. You must always be on |
| 471 | * the UI thread when calling any method on any view.</em> |
| 472 | * If you are doing work on other threads and want to update the state of a view |
| 473 | * from that thread, you should use a {@link Handler}. |
| 474 | * </p> |
| 475 | * |
| 476 | * <a name="FocusHandling"></a> |
| 477 | * <h3>Focus Handling</h3> |
| 478 | * <p> |
| 479 | * The framework will handle routine focus movement in response to user input. |
| 480 | * This includes changing the focus as views are removed or hidden, or as new |
| 481 | * views become available. Views indicate their willingness to take focus |
| 482 | * through the {@link #isFocusable} method. To change whether a view can take |
| 483 | * focus, call {@link #setFocusable(boolean)}. When in touch mode (see notes below) |
| 484 | * views indicate whether they still would like focus via {@link #isFocusableInTouchMode} |
| 485 | * and can change this via {@link #setFocusableInTouchMode(boolean)}. |
| 486 | * </p> |
| 487 | * <p> |
| 488 | * Focus movement is based on an algorithm which finds the nearest neighbor in a |
| 489 | * given direction. In rare cases, the default algorithm may not match the |
| 490 | * intended behavior of the developer. In these situations, you can provide |
| 491 | * explicit overrides by using these XML attributes in the layout file: |
| 492 | * <pre> |
| 493 | * nextFocusDown |
| 494 | * nextFocusLeft |
| 495 | * nextFocusRight |
| 496 | * nextFocusUp |
| 497 | * </pre> |
| 498 | * </p> |
| 499 | * |
| 500 | * |
| 501 | * <p> |
| 502 | * To get a particular view to take focus, call {@link #requestFocus()}. |
| 503 | * </p> |
| 504 | * |
| 505 | * <a name="TouchMode"></a> |
| 506 | * <h3>Touch Mode</h3> |
| 507 | * <p> |
| 508 | * When a user is navigating a user interface via directional keys such as a D-pad, it is |
| 509 | * necessary to give focus to actionable items such as buttons so the user can see |
| 510 | * what will take input. If the device has touch capabilities, however, and the user |
| 511 | * begins interacting with the interface by touching it, it is no longer necessary to |
| 512 | * always highlight, or give focus to, a particular view. This motivates a mode |
| 513 | * for interaction named 'touch mode'. |
| 514 | * </p> |
| 515 | * <p> |
| 516 | * For a touch capable device, once the user touches the screen, the device |
| 517 | * will enter touch mode. From this point onward, only views for which |
| 518 | * {@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets. |
| 519 | * Other views that are touchable, like buttons, will not take focus when touched; they will |
| 520 | * only fire the on click listeners. |
| 521 | * </p> |
| 522 | * <p> |
| 523 | * Any time a user hits a directional key, such as a D-pad direction, the view device will |
| 524 | * exit touch mode, and find a view to take focus, so that the user may resume interacting |
| 525 | * with the user interface without touching the screen again. |
| 526 | * </p> |
| 527 | * <p> |
| 528 | * The touch mode state is maintained across {@link android.app.Activity}s. Call |
| 529 | * {@link #isInTouchMode} to see whether the device is currently in touch mode. |
| 530 | * </p> |
| 531 | * |
| 532 | * <a name="Scrolling"></a> |
| 533 | * <h3>Scrolling</h3> |
| 534 | * <p> |
| 535 | * The framework provides basic support for views that wish to internally |
| 536 | * scroll their content. This includes keeping track of the X and Y scroll |
| 537 | * offset as well as mechanisms for drawing scrollbars. See |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 538 | * {@link #scrollBy(int, int)}, {@link #scrollTo(int, int)}, and |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 539 | * {@link #awakenScrollBars()} for more details. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | * </p> |
| 541 | * |
| 542 | * <a name="Tags"></a> |
| 543 | * <h3>Tags</h3> |
| 544 | * <p> |
| 545 | * Unlike IDs, tags are not used to identify views. Tags are essentially an |
| 546 | * extra piece of information that can be associated with a view. They are most |
| 547 | * often used as a convenience to store data related to views in the views |
| 548 | * themselves rather than by putting them in a separate structure. |
| 549 | * </p> |
| 550 | * |
Chet Haase | cb150fe | 2012-05-03 15:15:05 -0700 | [diff] [blame] | 551 | * <a name="Properties"></a> |
| 552 | * <h3>Properties</h3> |
| 553 | * <p> |
| 554 | * The View class exposes an {@link #ALPHA} property, as well as several transform-related |
| 555 | * properties, such as {@link #TRANSLATION_X} and {@link #TRANSLATION_Y}. These properties are |
| 556 | * available both in the {@link Property} form as well as in similarly-named setter/getter |
| 557 | * methods (such as {@link #setAlpha(float)} for {@link #ALPHA}). These properties can |
| 558 | * be used to set persistent state associated with these rendering-related properties on the view. |
| 559 | * The properties and methods can also be used in conjunction with |
| 560 | * {@link android.animation.Animator Animator}-based animations, described more in the |
| 561 | * <a href="#Animation">Animation</a> section. |
| 562 | * </p> |
| 563 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | * <a name="Animation"></a> |
| 565 | * <h3>Animation</h3> |
| 566 | * <p> |
Chet Haase | cb150fe | 2012-05-03 15:15:05 -0700 | [diff] [blame] | 567 | * Starting with Android 3.0, the preferred way of animating views is to use the |
| 568 | * {@link android.animation} package APIs. These {@link android.animation.Animator Animator}-based |
| 569 | * classes change actual properties of the View object, such as {@link #setAlpha(float) alpha} and |
| 570 | * {@link #setTranslationX(float) translationX}. This behavior is contrasted to that of the pre-3.0 |
| 571 | * {@link android.view.animation.Animation Animation}-based classes, which instead animate only |
| 572 | * how the view is drawn on the display. In particular, the {@link ViewPropertyAnimator} class |
| 573 | * makes animating these View properties particularly easy and efficient. |
| 574 | * </p> |
| 575 | * <p> |
| 576 | * 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] | 577 | * You can attach an {@link Animation} object to a view using |
| 578 | * {@link #setAnimation(Animation)} or |
| 579 | * {@link #startAnimation(Animation)}. The animation can alter the scale, |
| 580 | * rotation, translation and alpha of a view over time. If the animation is |
| 581 | * attached to a view that has children, the animation will affect the entire |
| 582 | * subtree rooted by that node. When an animation is started, the framework will |
| 583 | * take care of redrawing the appropriate views until the animation completes. |
| 584 | * </p> |
| 585 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 586 | * <a name="Security"></a> |
| 587 | * <h3>Security</h3> |
| 588 | * <p> |
| 589 | * Sometimes it is essential that an application be able to verify that an action |
| 590 | * is being performed with the full knowledge and consent of the user, such as |
| 591 | * granting a permission request, making a purchase or clicking on an advertisement. |
| 592 | * Unfortunately, a malicious application could try to spoof the user into |
| 593 | * performing these actions, unaware, by concealing the intended purpose of the view. |
| 594 | * As a remedy, the framework offers a touch filtering mechanism that can be used to |
| 595 | * improve the security of views that provide access to sensitive functionality. |
| 596 | * </p><p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 597 | * To enable touch filtering, call {@link #setFilterTouchesWhenObscured(boolean)} or set the |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 598 | * android:filterTouchesWhenObscured layout attribute to true. When enabled, the framework |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 599 | * will discard touches that are received whenever the view's window is obscured by |
| 600 | * another visible window. As a result, the view will not receive touches whenever a |
| 601 | * toast, dialog or other window appears above the view's window. |
| 602 | * </p><p> |
| 603 | * For more fine-grained control over security, consider overriding the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 604 | * {@link #onFilterTouchEventForSecurity(MotionEvent)} method to implement your own |
| 605 | * security policy. See also {@link MotionEvent#FLAG_WINDOW_IS_OBSCURED}. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 606 | * </p> |
| 607 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 608 | * @attr ref android.R.styleable#View_alpha |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 609 | * @attr ref android.R.styleable#View_background |
| 610 | * @attr ref android.R.styleable#View_clickable |
| 611 | * @attr ref android.R.styleable#View_contentDescription |
| 612 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 613 | * @attr ref android.R.styleable#View_duplicateParentState |
| 614 | * @attr ref android.R.styleable#View_id |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 615 | * @attr ref android.R.styleable#View_requiresFadingEdge |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 616 | * @attr ref android.R.styleable#View_fadeScrollbars |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 617 | * @attr ref android.R.styleable#View_fadingEdgeLength |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 618 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 620 | * @attr ref android.R.styleable#View_isScrollContainer |
| 621 | * @attr ref android.R.styleable#View_focusable |
| 622 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 623 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 624 | * @attr ref android.R.styleable#View_keepScreenOn |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 625 | * @attr ref android.R.styleable#View_layerType |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 626 | * @attr ref android.R.styleable#View_longClickable |
| 627 | * @attr ref android.R.styleable#View_minHeight |
| 628 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | * @attr ref android.R.styleable#View_nextFocusDown |
| 630 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 631 | * @attr ref android.R.styleable#View_nextFocusRight |
| 632 | * @attr ref android.R.styleable#View_nextFocusUp |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 633 | * @attr ref android.R.styleable#View_onClick |
| 634 | * @attr ref android.R.styleable#View_padding |
| 635 | * @attr ref android.R.styleable#View_paddingBottom |
| 636 | * @attr ref android.R.styleable#View_paddingLeft |
| 637 | * @attr ref android.R.styleable#View_paddingRight |
| 638 | * @attr ref android.R.styleable#View_paddingTop |
Fabrice Di Meglio | 101d5aa | 2012-02-16 18:36:06 -0800 | [diff] [blame] | 639 | * @attr ref android.R.styleable#View_paddingStart |
| 640 | * @attr ref android.R.styleable#View_paddingEnd |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 641 | * @attr ref android.R.styleable#View_saveEnabled |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 642 | * @attr ref android.R.styleable#View_rotation |
| 643 | * @attr ref android.R.styleable#View_rotationX |
| 644 | * @attr ref android.R.styleable#View_rotationY |
| 645 | * @attr ref android.R.styleable#View_scaleX |
| 646 | * @attr ref android.R.styleable#View_scaleY |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | * @attr ref android.R.styleable#View_scrollX |
| 648 | * @attr ref android.R.styleable#View_scrollY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 649 | * @attr ref android.R.styleable#View_scrollbarSize |
| 650 | * @attr ref android.R.styleable#View_scrollbarStyle |
| 651 | * @attr ref android.R.styleable#View_scrollbars |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 652 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 653 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | * @attr ref android.R.styleable#View_scrollbarTrackHorizontal |
| 655 | * @attr ref android.R.styleable#View_scrollbarThumbHorizontal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 656 | * @attr ref android.R.styleable#View_scrollbarThumbVertical |
| 657 | * @attr ref android.R.styleable#View_scrollbarTrackVertical |
| 658 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawHorizontalTrack |
| 659 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawVerticalTrack |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 660 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 661 | * @attr ref android.R.styleable#View_tag |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 662 | * @attr ref android.R.styleable#View_textAlignment |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 663 | * @attr ref android.R.styleable#View_transformPivotX |
| 664 | * @attr ref android.R.styleable#View_transformPivotY |
| 665 | * @attr ref android.R.styleable#View_translationX |
| 666 | * @attr ref android.R.styleable#View_translationY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 667 | * @attr ref android.R.styleable#View_visibility |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | * |
| 669 | * @see android.view.ViewGroup |
| 670 | */ |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 671 | public class View implements Drawable.Callback, KeyEvent.Callback, |
Adam Powell | 8fc54f9 | 2011-09-07 16:40:45 -0700 | [diff] [blame] | 672 | AccessibilityEventSource { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 673 | private static final boolean DBG = false; |
| 674 | |
| 675 | /** |
| 676 | * The logging tag used by this class with android.util.Log. |
| 677 | */ |
| 678 | protected static final String VIEW_LOG_TAG = "View"; |
| 679 | |
| 680 | /** |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 681 | * When set to true, apps will draw debugging information about their layouts. |
Romain Guy | 4b8c4f8 | 2012-04-27 15:48:35 -0700 | [diff] [blame] | 682 | * |
| 683 | * @hide |
| 684 | */ |
| 685 | public static final String DEBUG_LAYOUT_PROPERTY = "debug.layout"; |
| 686 | |
| 687 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 688 | * Used to mark a View that has no ID. |
| 689 | */ |
| 690 | public static final int NO_ID = -1; |
| 691 | |
| 692 | /** |
| 693 | * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when |
| 694 | * calling setFlags. |
| 695 | */ |
| 696 | private static final int NOT_FOCUSABLE = 0x00000000; |
| 697 | |
| 698 | /** |
| 699 | * This view wants keystrokes. Use with TAKES_FOCUS_MASK when calling |
| 700 | * setFlags. |
| 701 | */ |
| 702 | private static final int FOCUSABLE = 0x00000001; |
| 703 | |
| 704 | /** |
| 705 | * Mask for use with setFlags indicating bits used for focus. |
| 706 | */ |
| 707 | private static final int FOCUSABLE_MASK = 0x00000001; |
| 708 | |
| 709 | /** |
| 710 | * This view will adjust its padding to fit sytem windows (e.g. status bar) |
| 711 | */ |
| 712 | private static final int FITS_SYSTEM_WINDOWS = 0x00000002; |
| 713 | |
| 714 | /** |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 715 | * This view is visible. |
| 716 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 717 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 718 | */ |
| 719 | public static final int VISIBLE = 0x00000000; |
| 720 | |
| 721 | /** |
| 722 | * 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] | 723 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 724 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | */ |
| 726 | public static final int INVISIBLE = 0x00000004; |
| 727 | |
| 728 | /** |
| 729 | * 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] | 730 | * purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 731 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 732 | */ |
| 733 | public static final int GONE = 0x00000008; |
| 734 | |
| 735 | /** |
| 736 | * Mask for use with setFlags indicating bits used for visibility. |
| 737 | * {@hide} |
| 738 | */ |
| 739 | static final int VISIBILITY_MASK = 0x0000000C; |
| 740 | |
| 741 | private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE}; |
| 742 | |
| 743 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 744 | * This view is enabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | * Use with ENABLED_MASK when calling setFlags. |
| 746 | * {@hide} |
| 747 | */ |
| 748 | static final int ENABLED = 0x00000000; |
| 749 | |
| 750 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 751 | * This view is disabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 752 | * Use with ENABLED_MASK when calling setFlags. |
| 753 | * {@hide} |
| 754 | */ |
| 755 | static final int DISABLED = 0x00000020; |
| 756 | |
| 757 | /** |
| 758 | * Mask for use with setFlags indicating bits used for indicating whether |
| 759 | * this view is enabled |
| 760 | * {@hide} |
| 761 | */ |
| 762 | static final int ENABLED_MASK = 0x00000020; |
| 763 | |
| 764 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 765 | * This view won't draw. {@link #onDraw(android.graphics.Canvas)} won't be |
| 766 | * called and further optimizations will be performed. It is okay to have |
| 767 | * 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] | 768 | * {@hide} |
| 769 | */ |
| 770 | static final int WILL_NOT_DRAW = 0x00000080; |
| 771 | |
| 772 | /** |
| 773 | * Mask for use with setFlags indicating bits used for indicating whether |
| 774 | * this view is will draw |
| 775 | * {@hide} |
| 776 | */ |
| 777 | static final int DRAW_MASK = 0x00000080; |
| 778 | |
| 779 | /** |
| 780 | * <p>This view doesn't show scrollbars.</p> |
| 781 | * {@hide} |
| 782 | */ |
| 783 | static final int SCROLLBARS_NONE = 0x00000000; |
| 784 | |
| 785 | /** |
| 786 | * <p>This view shows horizontal scrollbars.</p> |
| 787 | * {@hide} |
| 788 | */ |
| 789 | static final int SCROLLBARS_HORIZONTAL = 0x00000100; |
| 790 | |
| 791 | /** |
| 792 | * <p>This view shows vertical scrollbars.</p> |
| 793 | * {@hide} |
| 794 | */ |
| 795 | static final int SCROLLBARS_VERTICAL = 0x00000200; |
| 796 | |
| 797 | /** |
| 798 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 799 | * scrollbars are enabled.</p> |
| 800 | * {@hide} |
| 801 | */ |
| 802 | static final int SCROLLBARS_MASK = 0x00000300; |
| 803 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 804 | /** |
| 805 | * Indicates that the view should filter touches when its window is obscured. |
| 806 | * Refer to the class comments for more information about this security feature. |
| 807 | * {@hide} |
| 808 | */ |
| 809 | static final int FILTER_TOUCHES_WHEN_OBSCURED = 0x00000400; |
| 810 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 811 | /** |
| 812 | * Set for framework elements that use FITS_SYSTEM_WINDOWS, to indicate |
| 813 | * that they are optional and should be skipped if the window has |
| 814 | * requested system UI flags that ignore those insets for layout. |
| 815 | */ |
| 816 | static final int OPTIONAL_FITS_SYSTEM_WINDOWS = 0x00000800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 | |
| 818 | /** |
| 819 | * <p>This view doesn't show fading edges.</p> |
| 820 | * {@hide} |
| 821 | */ |
| 822 | static final int FADING_EDGE_NONE = 0x00000000; |
| 823 | |
| 824 | /** |
| 825 | * <p>This view shows horizontal fading edges.</p> |
| 826 | * {@hide} |
| 827 | */ |
| 828 | static final int FADING_EDGE_HORIZONTAL = 0x00001000; |
| 829 | |
| 830 | /** |
| 831 | * <p>This view shows vertical fading edges.</p> |
| 832 | * {@hide} |
| 833 | */ |
| 834 | static final int FADING_EDGE_VERTICAL = 0x00002000; |
| 835 | |
| 836 | /** |
| 837 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 838 | * fading edges are enabled.</p> |
| 839 | * {@hide} |
| 840 | */ |
| 841 | static final int FADING_EDGE_MASK = 0x00003000; |
| 842 | |
| 843 | /** |
| 844 | * <p>Indicates this view can be clicked. When clickable, a View reacts |
| 845 | * to clicks by notifying the OnClickListener.<p> |
| 846 | * {@hide} |
| 847 | */ |
| 848 | static final int CLICKABLE = 0x00004000; |
| 849 | |
| 850 | /** |
| 851 | * <p>Indicates this view is caching its drawing into a bitmap.</p> |
| 852 | * {@hide} |
| 853 | */ |
| 854 | static final int DRAWING_CACHE_ENABLED = 0x00008000; |
| 855 | |
| 856 | /** |
| 857 | * <p>Indicates that no icicle should be saved for this view.<p> |
| 858 | * {@hide} |
| 859 | */ |
| 860 | static final int SAVE_DISABLED = 0x000010000; |
| 861 | |
| 862 | /** |
| 863 | * <p>Mask for use with setFlags indicating bits used for the saveEnabled |
| 864 | * property.</p> |
| 865 | * {@hide} |
| 866 | */ |
| 867 | static final int SAVE_DISABLED_MASK = 0x000010000; |
| 868 | |
| 869 | /** |
| 870 | * <p>Indicates that no drawing cache should ever be created for this view.<p> |
| 871 | * {@hide} |
| 872 | */ |
| 873 | static final int WILL_NOT_CACHE_DRAWING = 0x000020000; |
| 874 | |
| 875 | /** |
| 876 | * <p>Indicates this view can take / keep focus when int touch mode.</p> |
| 877 | * {@hide} |
| 878 | */ |
| 879 | static final int FOCUSABLE_IN_TOUCH_MODE = 0x00040000; |
| 880 | |
| 881 | /** |
| 882 | * <p>Enables low quality mode for the drawing cache.</p> |
| 883 | */ |
| 884 | public static final int DRAWING_CACHE_QUALITY_LOW = 0x00080000; |
| 885 | |
| 886 | /** |
| 887 | * <p>Enables high quality mode for the drawing cache.</p> |
| 888 | */ |
| 889 | public static final int DRAWING_CACHE_QUALITY_HIGH = 0x00100000; |
| 890 | |
| 891 | /** |
| 892 | * <p>Enables automatic quality mode for the drawing cache.</p> |
| 893 | */ |
| 894 | public static final int DRAWING_CACHE_QUALITY_AUTO = 0x00000000; |
| 895 | |
| 896 | private static final int[] DRAWING_CACHE_QUALITY_FLAGS = { |
| 897 | DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH |
| 898 | }; |
| 899 | |
| 900 | /** |
| 901 | * <p>Mask for use with setFlags indicating bits used for the cache |
| 902 | * quality property.</p> |
| 903 | * {@hide} |
| 904 | */ |
| 905 | static final int DRAWING_CACHE_QUALITY_MASK = 0x00180000; |
| 906 | |
| 907 | /** |
| 908 | * <p> |
| 909 | * Indicates this view can be long clicked. When long clickable, a View |
| 910 | * reacts to long clicks by notifying the OnLongClickListener or showing a |
| 911 | * context menu. |
| 912 | * </p> |
| 913 | * {@hide} |
| 914 | */ |
| 915 | static final int LONG_CLICKABLE = 0x00200000; |
| 916 | |
| 917 | /** |
| 918 | * <p>Indicates that this view gets its drawable states from its direct parent |
| 919 | * and ignores its original internal states.</p> |
| 920 | * |
| 921 | * @hide |
| 922 | */ |
| 923 | static final int DUPLICATE_PARENT_STATE = 0x00400000; |
| 924 | |
| 925 | /** |
| 926 | * The scrollbar style to display the scrollbars inside the content area, |
| 927 | * without increasing the padding. The scrollbars will be overlaid with |
| 928 | * translucency on the view's content. |
| 929 | */ |
| 930 | public static final int SCROLLBARS_INSIDE_OVERLAY = 0; |
| 931 | |
| 932 | /** |
| 933 | * The scrollbar style to display the scrollbars inside the padded area, |
| 934 | * increasing the padding of the view. The scrollbars will not overlap the |
| 935 | * content area of the view. |
| 936 | */ |
| 937 | public static final int SCROLLBARS_INSIDE_INSET = 0x01000000; |
| 938 | |
| 939 | /** |
| 940 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 941 | * without increasing the padding. The scrollbars will be overlaid with |
| 942 | * translucency. |
| 943 | */ |
| 944 | public static final int SCROLLBARS_OUTSIDE_OVERLAY = 0x02000000; |
| 945 | |
| 946 | /** |
| 947 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 948 | * increasing the padding of the view. The scrollbars will only overlap the |
| 949 | * background, if any. |
| 950 | */ |
| 951 | public static final int SCROLLBARS_OUTSIDE_INSET = 0x03000000; |
| 952 | |
| 953 | /** |
| 954 | * Mask to check if the scrollbar style is overlay or inset. |
| 955 | * {@hide} |
| 956 | */ |
| 957 | static final int SCROLLBARS_INSET_MASK = 0x01000000; |
| 958 | |
| 959 | /** |
| 960 | * Mask to check if the scrollbar style is inside or outside. |
| 961 | * {@hide} |
| 962 | */ |
| 963 | static final int SCROLLBARS_OUTSIDE_MASK = 0x02000000; |
| 964 | |
| 965 | /** |
| 966 | * Mask for scrollbar style. |
| 967 | * {@hide} |
| 968 | */ |
| 969 | static final int SCROLLBARS_STYLE_MASK = 0x03000000; |
| 970 | |
| 971 | /** |
| 972 | * View flag indicating that the screen should remain on while the |
| 973 | * window containing this view is visible to the user. This effectively |
| 974 | * takes care of automatically setting the WindowManager's |
| 975 | * {@link WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON}. |
| 976 | */ |
| 977 | public static final int KEEP_SCREEN_ON = 0x04000000; |
| 978 | |
| 979 | /** |
| 980 | * View flag indicating whether this view should have sound effects enabled |
| 981 | * for events such as clicking and touching. |
| 982 | */ |
| 983 | public static final int SOUND_EFFECTS_ENABLED = 0x08000000; |
| 984 | |
| 985 | /** |
| 986 | * View flag indicating whether this view should have haptic feedback |
| 987 | * enabled for events such as long presses. |
| 988 | */ |
| 989 | public static final int HAPTIC_FEEDBACK_ENABLED = 0x10000000; |
| 990 | |
| 991 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 992 | * <p>Indicates that the view hierarchy should stop saving state when |
| 993 | * it reaches this view. If state saving is initiated immediately at |
| 994 | * the view, it will be allowed. |
| 995 | * {@hide} |
| 996 | */ |
| 997 | static final int PARENT_SAVE_DISABLED = 0x20000000; |
| 998 | |
| 999 | /** |
| 1000 | * <p>Mask for use with setFlags indicating bits used for PARENT_SAVE_DISABLED.</p> |
| 1001 | * {@hide} |
| 1002 | */ |
| 1003 | static final int PARENT_SAVE_DISABLED_MASK = 0x20000000; |
| 1004 | |
| 1005 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1006 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 1007 | * should add all focusable Views regardless if they are focusable in touch mode. |
| 1008 | */ |
| 1009 | public static final int FOCUSABLES_ALL = 0x00000000; |
| 1010 | |
| 1011 | /** |
| 1012 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 1013 | * should add only Views focusable in touch mode. |
| 1014 | */ |
| 1015 | public static final int FOCUSABLES_TOUCH_MODE = 0x00000001; |
| 1016 | |
| 1017 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1018 | * 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] | 1019 | * item. |
| 1020 | */ |
| 1021 | public static final int FOCUS_BACKWARD = 0x00000001; |
| 1022 | |
| 1023 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1024 | * 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] | 1025 | * item. |
| 1026 | */ |
| 1027 | public static final int FOCUS_FORWARD = 0x00000002; |
| 1028 | |
| 1029 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1030 | * 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] | 1031 | */ |
| 1032 | public static final int FOCUS_LEFT = 0x00000011; |
| 1033 | |
| 1034 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1035 | * Use with {@link #focusSearch(int)}. Move focus up. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1036 | */ |
| 1037 | public static final int FOCUS_UP = 0x00000021; |
| 1038 | |
| 1039 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1040 | * 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] | 1041 | */ |
| 1042 | public static final int FOCUS_RIGHT = 0x00000042; |
| 1043 | |
| 1044 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1045 | * Use with {@link #focusSearch(int)}. Move focus down. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | */ |
| 1047 | public static final int FOCUS_DOWN = 0x00000082; |
| 1048 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1049 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1050 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1051 | * {@link #getMeasuredWidthAndState()} that provide the actual measured size. |
| 1052 | */ |
| 1053 | public static final int MEASURED_SIZE_MASK = 0x00ffffff; |
| 1054 | |
| 1055 | /** |
| 1056 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1057 | * {@link #getMeasuredWidthAndState()} that provide the additional state bits. |
| 1058 | */ |
| 1059 | public static final int MEASURED_STATE_MASK = 0xff000000; |
| 1060 | |
| 1061 | /** |
| 1062 | * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits |
| 1063 | * for functions that combine both width and height into a single int, |
| 1064 | * such as {@link #getMeasuredState()} and the childState argument of |
| 1065 | * {@link #resolveSizeAndState(int, int, int)}. |
| 1066 | */ |
| 1067 | public static final int MEASURED_HEIGHT_STATE_SHIFT = 16; |
| 1068 | |
| 1069 | /** |
| 1070 | * Bit of {@link #getMeasuredWidthAndState()} and |
| 1071 | * {@link #getMeasuredWidthAndState()} that indicates the measured size |
| 1072 | * is smaller that the space the view would like to have. |
| 1073 | */ |
| 1074 | public static final int MEASURED_STATE_TOO_SMALL = 0x01000000; |
| 1075 | |
| 1076 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1077 | * Base View state sets |
| 1078 | */ |
| 1079 | // Singles |
| 1080 | /** |
| 1081 | * Indicates the view has no states set. States are used with |
| 1082 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1083 | * view depending on its state. |
| 1084 | * |
| 1085 | * @see android.graphics.drawable.Drawable |
| 1086 | * @see #getDrawableState() |
| 1087 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1088 | protected static final int[] EMPTY_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1089 | /** |
| 1090 | * Indicates the view is enabled. States are used with |
| 1091 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1092 | * view depending on its state. |
| 1093 | * |
| 1094 | * @see android.graphics.drawable.Drawable |
| 1095 | * @see #getDrawableState() |
| 1096 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1097 | protected static final int[] ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1098 | /** |
| 1099 | * Indicates the view is focused. States are used with |
| 1100 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1101 | * view depending on its state. |
| 1102 | * |
| 1103 | * @see android.graphics.drawable.Drawable |
| 1104 | * @see #getDrawableState() |
| 1105 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1106 | protected static final int[] FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | /** |
| 1108 | * Indicates the view is selected. States are used with |
| 1109 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1110 | * view depending on its state. |
| 1111 | * |
| 1112 | * @see android.graphics.drawable.Drawable |
| 1113 | * @see #getDrawableState() |
| 1114 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1115 | protected static final int[] SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | /** |
| 1117 | * Indicates the view is pressed. States are used with |
| 1118 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1119 | * view depending on its state. |
| 1120 | * |
| 1121 | * @see android.graphics.drawable.Drawable |
| 1122 | * @see #getDrawableState() |
| 1123 | * @hide |
| 1124 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1125 | protected static final int[] PRESSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1126 | /** |
| 1127 | * Indicates the view's window has focus. States are used with |
| 1128 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1129 | * view depending on its state. |
| 1130 | * |
| 1131 | * @see android.graphics.drawable.Drawable |
| 1132 | * @see #getDrawableState() |
| 1133 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1134 | protected static final int[] WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1135 | // Doubles |
| 1136 | /** |
| 1137 | * Indicates the view is enabled and has the focus. |
| 1138 | * |
| 1139 | * @see #ENABLED_STATE_SET |
| 1140 | * @see #FOCUSED_STATE_SET |
| 1141 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1142 | protected static final int[] ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | /** |
| 1144 | * Indicates the view is enabled and selected. |
| 1145 | * |
| 1146 | * @see #ENABLED_STATE_SET |
| 1147 | * @see #SELECTED_STATE_SET |
| 1148 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1149 | protected static final int[] ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1150 | /** |
| 1151 | * Indicates the view is enabled and that its window has focus. |
| 1152 | * |
| 1153 | * @see #ENABLED_STATE_SET |
| 1154 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1155 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1156 | protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | /** |
| 1158 | * Indicates the view is focused and selected. |
| 1159 | * |
| 1160 | * @see #FOCUSED_STATE_SET |
| 1161 | * @see #SELECTED_STATE_SET |
| 1162 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1163 | protected static final int[] FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1164 | /** |
| 1165 | * Indicates the view has the focus and that its window has the focus. |
| 1166 | * |
| 1167 | * @see #FOCUSED_STATE_SET |
| 1168 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1169 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1170 | protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1171 | /** |
| 1172 | * Indicates the view is selected and that its window has the focus. |
| 1173 | * |
| 1174 | * @see #SELECTED_STATE_SET |
| 1175 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1176 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1177 | protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1178 | // Triples |
| 1179 | /** |
| 1180 | * Indicates the view is enabled, focused and selected. |
| 1181 | * |
| 1182 | * @see #ENABLED_STATE_SET |
| 1183 | * @see #FOCUSED_STATE_SET |
| 1184 | * @see #SELECTED_STATE_SET |
| 1185 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1186 | protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1187 | /** |
| 1188 | * Indicates the view is enabled, focused and its window has the focus. |
| 1189 | * |
| 1190 | * @see #ENABLED_STATE_SET |
| 1191 | * @see #FOCUSED_STATE_SET |
| 1192 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1193 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1194 | protected static final int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1195 | /** |
| 1196 | * Indicates the view is enabled, selected and its window has the focus. |
| 1197 | * |
| 1198 | * @see #ENABLED_STATE_SET |
| 1199 | * @see #SELECTED_STATE_SET |
| 1200 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1201 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1202 | 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] | 1203 | /** |
| 1204 | * Indicates the view is focused, selected and its window has the focus. |
| 1205 | * |
| 1206 | * @see #FOCUSED_STATE_SET |
| 1207 | * @see #SELECTED_STATE_SET |
| 1208 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1209 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1210 | 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] | 1211 | /** |
| 1212 | * Indicates the view is enabled, focused, selected and its window |
| 1213 | * has the focus. |
| 1214 | * |
| 1215 | * @see #ENABLED_STATE_SET |
| 1216 | * @see #FOCUSED_STATE_SET |
| 1217 | * @see #SELECTED_STATE_SET |
| 1218 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1219 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1220 | 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] | 1221 | /** |
| 1222 | * Indicates the view is pressed and its window has the focus. |
| 1223 | * |
| 1224 | * @see #PRESSED_STATE_SET |
| 1225 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1226 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1227 | protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1228 | /** |
| 1229 | * Indicates the view is pressed and selected. |
| 1230 | * |
| 1231 | * @see #PRESSED_STATE_SET |
| 1232 | * @see #SELECTED_STATE_SET |
| 1233 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1234 | protected static final int[] PRESSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | /** |
| 1236 | * Indicates the view is pressed, selected and its window has the focus. |
| 1237 | * |
| 1238 | * @see #PRESSED_STATE_SET |
| 1239 | * @see #SELECTED_STATE_SET |
| 1240 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1241 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1242 | 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] | 1243 | /** |
| 1244 | * Indicates the view is pressed and focused. |
| 1245 | * |
| 1246 | * @see #PRESSED_STATE_SET |
| 1247 | * @see #FOCUSED_STATE_SET |
| 1248 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1249 | protected static final int[] PRESSED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1250 | /** |
| 1251 | * Indicates the view is pressed, focused and its window has the focus. |
| 1252 | * |
| 1253 | * @see #PRESSED_STATE_SET |
| 1254 | * @see #FOCUSED_STATE_SET |
| 1255 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1256 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1257 | 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] | 1258 | /** |
| 1259 | * Indicates the view is pressed, focused and selected. |
| 1260 | * |
| 1261 | * @see #PRESSED_STATE_SET |
| 1262 | * @see #SELECTED_STATE_SET |
| 1263 | * @see #FOCUSED_STATE_SET |
| 1264 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1265 | protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | /** |
| 1267 | * Indicates the view is pressed, focused, selected and its window has the focus. |
| 1268 | * |
| 1269 | * @see #PRESSED_STATE_SET |
| 1270 | * @see #FOCUSED_STATE_SET |
| 1271 | * @see #SELECTED_STATE_SET |
| 1272 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1273 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1274 | protected static final int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1275 | /** |
| 1276 | * Indicates the view is pressed and enabled. |
| 1277 | * |
| 1278 | * @see #PRESSED_STATE_SET |
| 1279 | * @see #ENABLED_STATE_SET |
| 1280 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1281 | protected static final int[] PRESSED_ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1282 | /** |
| 1283 | * Indicates the view is pressed, enabled and its window has the focus. |
| 1284 | * |
| 1285 | * @see #PRESSED_STATE_SET |
| 1286 | * @see #ENABLED_STATE_SET |
| 1287 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1288 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1289 | 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] | 1290 | /** |
| 1291 | * Indicates the view is pressed, enabled and selected. |
| 1292 | * |
| 1293 | * @see #PRESSED_STATE_SET |
| 1294 | * @see #ENABLED_STATE_SET |
| 1295 | * @see #SELECTED_STATE_SET |
| 1296 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1297 | protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1298 | /** |
| 1299 | * Indicates the view is pressed, enabled, selected and its window has the |
| 1300 | * focus. |
| 1301 | * |
| 1302 | * @see #PRESSED_STATE_SET |
| 1303 | * @see #ENABLED_STATE_SET |
| 1304 | * @see #SELECTED_STATE_SET |
| 1305 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1306 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1307 | 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] | 1308 | /** |
| 1309 | * Indicates the view is pressed, enabled and focused. |
| 1310 | * |
| 1311 | * @see #PRESSED_STATE_SET |
| 1312 | * @see #ENABLED_STATE_SET |
| 1313 | * @see #FOCUSED_STATE_SET |
| 1314 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1315 | protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1316 | /** |
| 1317 | * Indicates the view is pressed, enabled, focused and its window has the |
| 1318 | * focus. |
| 1319 | * |
| 1320 | * @see #PRESSED_STATE_SET |
| 1321 | * @see #ENABLED_STATE_SET |
| 1322 | * @see #FOCUSED_STATE_SET |
| 1323 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1324 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1325 | 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] | 1326 | /** |
| 1327 | * Indicates the view is pressed, enabled, focused and selected. |
| 1328 | * |
| 1329 | * @see #PRESSED_STATE_SET |
| 1330 | * @see #ENABLED_STATE_SET |
| 1331 | * @see #SELECTED_STATE_SET |
| 1332 | * @see #FOCUSED_STATE_SET |
| 1333 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1334 | 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] | 1335 | /** |
| 1336 | * Indicates the view is pressed, enabled, focused, selected and its window |
| 1337 | * has the focus. |
| 1338 | * |
| 1339 | * @see #PRESSED_STATE_SET |
| 1340 | * @see #ENABLED_STATE_SET |
| 1341 | * @see #SELECTED_STATE_SET |
| 1342 | * @see #FOCUSED_STATE_SET |
| 1343 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1344 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1345 | 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] | 1346 | |
| 1347 | /** |
| 1348 | * The order here is very important to {@link #getDrawableState()} |
| 1349 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1350 | private static final int[][] VIEW_STATE_SETS; |
| 1351 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1352 | static final int VIEW_STATE_WINDOW_FOCUSED = 1; |
| 1353 | static final int VIEW_STATE_SELECTED = 1 << 1; |
| 1354 | static final int VIEW_STATE_FOCUSED = 1 << 2; |
| 1355 | static final int VIEW_STATE_ENABLED = 1 << 3; |
| 1356 | static final int VIEW_STATE_PRESSED = 1 << 4; |
| 1357 | static final int VIEW_STATE_ACTIVATED = 1 << 5; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1358 | static final int VIEW_STATE_ACCELERATED = 1 << 6; |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1359 | static final int VIEW_STATE_HOVERED = 1 << 7; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1360 | static final int VIEW_STATE_DRAG_CAN_ACCEPT = 1 << 8; |
| 1361 | static final int VIEW_STATE_DRAG_HOVERED = 1 << 9; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1362 | |
| 1363 | static final int[] VIEW_STATE_IDS = new int[] { |
| 1364 | R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED, |
| 1365 | R.attr.state_selected, VIEW_STATE_SELECTED, |
| 1366 | R.attr.state_focused, VIEW_STATE_FOCUSED, |
| 1367 | R.attr.state_enabled, VIEW_STATE_ENABLED, |
| 1368 | R.attr.state_pressed, VIEW_STATE_PRESSED, |
| 1369 | R.attr.state_activated, VIEW_STATE_ACTIVATED, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1370 | R.attr.state_accelerated, VIEW_STATE_ACCELERATED, |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1371 | R.attr.state_hovered, VIEW_STATE_HOVERED, |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1372 | R.attr.state_drag_can_accept, VIEW_STATE_DRAG_CAN_ACCEPT, |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1373 | R.attr.state_drag_hovered, VIEW_STATE_DRAG_HOVERED |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1374 | }; |
| 1375 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1376 | static { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1377 | if ((VIEW_STATE_IDS.length/2) != R.styleable.ViewDrawableStates.length) { |
| 1378 | throw new IllegalStateException( |
| 1379 | "VIEW_STATE_IDs array length does not match ViewDrawableStates style array"); |
| 1380 | } |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1381 | int[] orderedIds = new int[VIEW_STATE_IDS.length]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1382 | for (int i = 0; i < R.styleable.ViewDrawableStates.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1383 | int viewState = R.styleable.ViewDrawableStates[i]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1384 | for (int j = 0; j<VIEW_STATE_IDS.length; j += 2) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1385 | if (VIEW_STATE_IDS[j] == viewState) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1386 | orderedIds[i * 2] = viewState; |
| 1387 | orderedIds[i * 2 + 1] = VIEW_STATE_IDS[j + 1]; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1388 | } |
| 1389 | } |
| 1390 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1391 | final int NUM_BITS = VIEW_STATE_IDS.length / 2; |
| 1392 | VIEW_STATE_SETS = new int[1 << NUM_BITS][]; |
| 1393 | for (int i = 0; i < VIEW_STATE_SETS.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1394 | int numBits = Integer.bitCount(i); |
| 1395 | int[] set = new int[numBits]; |
| 1396 | int pos = 0; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1397 | for (int j = 0; j < orderedIds.length; j += 2) { |
| 1398 | if ((i & orderedIds[j+1]) != 0) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1399 | set[pos++] = orderedIds[j]; |
| 1400 | } |
| 1401 | } |
| 1402 | VIEW_STATE_SETS[i] = set; |
| 1403 | } |
| 1404 | |
| 1405 | EMPTY_STATE_SET = VIEW_STATE_SETS[0]; |
| 1406 | WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_WINDOW_FOCUSED]; |
| 1407 | SELECTED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_SELECTED]; |
| 1408 | SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1409 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED]; |
| 1410 | FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_FOCUSED]; |
| 1411 | FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1412 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED]; |
| 1413 | FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1414 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED]; |
| 1415 | FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1416 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1417 | | VIEW_STATE_FOCUSED]; |
| 1418 | ENABLED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_ENABLED]; |
| 1419 | ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1420 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED]; |
| 1421 | ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1422 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED]; |
| 1423 | ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1424 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1425 | | VIEW_STATE_ENABLED]; |
| 1426 | ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1427 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED]; |
| 1428 | ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1429 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1430 | | VIEW_STATE_ENABLED]; |
| 1431 | ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1432 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1433 | | VIEW_STATE_ENABLED]; |
| 1434 | ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1435 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1436 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED]; |
| 1437 | |
| 1438 | PRESSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_PRESSED]; |
| 1439 | PRESSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1440 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_PRESSED]; |
| 1441 | PRESSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1442 | VIEW_STATE_SELECTED | VIEW_STATE_PRESSED]; |
| 1443 | PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1444 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1445 | | VIEW_STATE_PRESSED]; |
| 1446 | PRESSED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1447 | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1448 | PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1449 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1450 | | VIEW_STATE_PRESSED]; |
| 1451 | PRESSED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1452 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1453 | | VIEW_STATE_PRESSED]; |
| 1454 | PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1455 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1456 | | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1457 | PRESSED_ENABLED_STATE_SET = VIEW_STATE_SETS[ |
| 1458 | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1459 | PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1460 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED |
| 1461 | | VIEW_STATE_PRESSED]; |
| 1462 | PRESSED_ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1463 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED |
| 1464 | | VIEW_STATE_PRESSED]; |
| 1465 | PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1466 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1467 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1468 | PRESSED_ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1469 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED |
| 1470 | | VIEW_STATE_PRESSED]; |
| 1471 | PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1472 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1473 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1474 | PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1475 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1476 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1477 | PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1478 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1479 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED |
| 1480 | | VIEW_STATE_PRESSED]; |
| 1481 | } |
| 1482 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1483 | /** |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1484 | * Accessibility event types that are dispatched for text population. |
| 1485 | */ |
| 1486 | private static final int POPULATING_ACCESSIBILITY_EVENT_TYPES = |
| 1487 | AccessibilityEvent.TYPE_VIEW_CLICKED |
| 1488 | | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED |
| 1489 | | AccessibilityEvent.TYPE_VIEW_SELECTED |
| 1490 | | AccessibilityEvent.TYPE_VIEW_FOCUSED |
| 1491 | | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED |
| 1492 | | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER |
Svetoslav Ganov | 9920f4f | 2011-10-07 18:39:11 -0700 | [diff] [blame] | 1493 | | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT |
Svetoslav Ganov | 84dd52e | 2011-11-18 10:24:00 -0800 | [diff] [blame] | 1494 | | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1495 | | AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 1496 | | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED |
| 1497 | | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY; |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1498 | |
| 1499 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | * Temporary Rect currently for use in setBackground(). This will probably |
| 1501 | * be extended in the future to hold our own class with more than just |
| 1502 | * a Rect. :) |
| 1503 | */ |
| 1504 | static final ThreadLocal<Rect> sThreadLocal = new ThreadLocal<Rect>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1505 | |
| 1506 | /** |
| 1507 | * Map used to store views' tags. |
| 1508 | */ |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 1509 | private SparseArray<Object> mKeyedTags; |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 1512 | * The next available accessibility id. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1513 | */ |
| 1514 | private static int sNextAccessibilityViewId; |
| 1515 | |
| 1516 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | * The animation currently associated with this view. |
| 1518 | * @hide |
| 1519 | */ |
| 1520 | protected Animation mCurrentAnimation = null; |
| 1521 | |
| 1522 | /** |
| 1523 | * Width as measured during measure pass. |
| 1524 | * {@hide} |
| 1525 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1526 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1527 | int mMeasuredWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | |
| 1529 | /** |
| 1530 | * Height as measured during measure pass. |
| 1531 | * {@hide} |
| 1532 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1533 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1534 | int mMeasuredHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1535 | |
| 1536 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1537 | * Flag to indicate that this view was marked INVALIDATED, or had its display list |
| 1538 | * invalidated, prior to the current drawing iteration. If true, the view must re-draw |
| 1539 | * its display list. This flag, used only when hw accelerated, allows us to clear the |
| 1540 | * flag while retaining this information until it's needed (at getDisplayList() time and |
| 1541 | * in drawChild(), when we decide to draw a view's children's display lists into our own). |
| 1542 | * |
| 1543 | * {@hide} |
| 1544 | */ |
| 1545 | boolean mRecreateDisplayList = false; |
| 1546 | |
| 1547 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1548 | * The view's identifier. |
| 1549 | * {@hide} |
| 1550 | * |
| 1551 | * @see #setId(int) |
| 1552 | * @see #getId() |
| 1553 | */ |
| 1554 | @ViewDebug.ExportedProperty(resolveId = true) |
| 1555 | int mID = NO_ID; |
| 1556 | |
| 1557 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 1558 | * The stable ID of this view for accessibility purposes. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1559 | */ |
| 1560 | int mAccessibilityViewId = NO_ID; |
| 1561 | |
| 1562 | /** |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 1563 | * @hide |
| 1564 | */ |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 1565 | private int mAccessibilityCursorPosition = ACCESSIBILITY_CURSOR_POSITION_UNDEFINED; |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 1566 | |
| 1567 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1568 | * The view's tag. |
| 1569 | * {@hide} |
| 1570 | * |
| 1571 | * @see #setTag(Object) |
| 1572 | * @see #getTag() |
| 1573 | */ |
| 1574 | protected Object mTag; |
| 1575 | |
| 1576 | // for mPrivateFlags: |
| 1577 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1578 | static final int PFLAG_WANTS_FOCUS = 0x00000001; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1579 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1580 | static final int PFLAG_FOCUSED = 0x00000002; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1581 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1582 | static final int PFLAG_SELECTED = 0x00000004; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1583 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1584 | static final int PFLAG_IS_ROOT_NAMESPACE = 0x00000008; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1585 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1586 | static final int PFLAG_HAS_BOUNDS = 0x00000010; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1587 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1588 | static final int PFLAG_DRAWN = 0x00000020; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | /** |
| 1590 | * When this flag is set, this view is running an animation on behalf of its |
| 1591 | * children and should therefore not cancel invalidate requests, even if they |
| 1592 | * lie outside of this view's bounds. |
| 1593 | * |
| 1594 | * {@hide} |
| 1595 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1596 | static final int PFLAG_DRAW_ANIMATION = 0x00000040; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1597 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1598 | static final int PFLAG_SKIP_DRAW = 0x00000080; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1600 | static final int PFLAG_ONLY_DRAWS_BACKGROUND = 0x00000100; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1601 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1602 | static final int PFLAG_REQUEST_TRANSPARENT_REGIONS = 0x00000200; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1603 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1604 | static final int PFLAG_DRAWABLE_STATE_DIRTY = 0x00000400; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1605 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1606 | static final int PFLAG_MEASURED_DIMENSION_SET = 0x00000800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1607 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1608 | static final int PFLAG_FORCE_LAYOUT = 0x00001000; |
Konstantin Lopyrev | c6dc457 | 2010-08-06 15:01:52 -0700 | [diff] [blame] | 1609 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1610 | static final int PFLAG_LAYOUT_REQUIRED = 0x00002000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1611 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1612 | private static final int PFLAG_PRESSED = 0x00004000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1613 | |
| 1614 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1615 | static final int PFLAG_DRAWING_CACHE_VALID = 0x00008000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1616 | /** |
| 1617 | * Flag used to indicate that this view should be drawn once more (and only once |
| 1618 | * more) after its animation has completed. |
| 1619 | * {@hide} |
| 1620 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1621 | static final int PFLAG_ANIMATION_STARTED = 0x00010000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1622 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1623 | private static final int PFLAG_SAVE_STATE_CALLED = 0x00020000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1624 | |
| 1625 | /** |
| 1626 | * Indicates that the View returned true when onSetAlpha() was called and that |
| 1627 | * the alpha must be restored. |
| 1628 | * {@hide} |
| 1629 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1630 | static final int PFLAG_ALPHA_SET = 0x00040000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1631 | |
| 1632 | /** |
| 1633 | * Set by {@link #setScrollContainer(boolean)}. |
| 1634 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1635 | static final int PFLAG_SCROLL_CONTAINER = 0x00080000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1636 | |
| 1637 | /** |
| 1638 | * Set by {@link #setScrollContainer(boolean)}. |
| 1639 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1640 | static final int PFLAG_SCROLL_CONTAINER_ADDED = 0x00100000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1641 | |
| 1642 | /** |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1643 | * View flag indicating whether this view was invalidated (fully or partially.) |
| 1644 | * |
| 1645 | * @hide |
| 1646 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1647 | static final int PFLAG_DIRTY = 0x00200000; |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1648 | |
| 1649 | /** |
| 1650 | * View flag indicating whether this view was invalidated by an opaque |
| 1651 | * invalidate request. |
| 1652 | * |
| 1653 | * @hide |
| 1654 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1655 | static final int PFLAG_DIRTY_OPAQUE = 0x00400000; |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1656 | |
| 1657 | /** |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1658 | * Mask for {@link #PFLAG_DIRTY} and {@link #PFLAG_DIRTY_OPAQUE}. |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1659 | * |
| 1660 | * @hide |
| 1661 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1662 | static final int PFLAG_DIRTY_MASK = 0x00600000; |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1663 | |
| 1664 | /** |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1665 | * Indicates whether the background is opaque. |
| 1666 | * |
| 1667 | * @hide |
| 1668 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1669 | static final int PFLAG_OPAQUE_BACKGROUND = 0x00800000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1670 | |
| 1671 | /** |
| 1672 | * Indicates whether the scrollbars are opaque. |
| 1673 | * |
| 1674 | * @hide |
| 1675 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1676 | static final int PFLAG_OPAQUE_SCROLLBARS = 0x01000000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1677 | |
| 1678 | /** |
| 1679 | * Indicates whether the view is opaque. |
| 1680 | * |
| 1681 | * @hide |
| 1682 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1683 | static final int PFLAG_OPAQUE_MASK = 0x01800000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1684 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1685 | /** |
| 1686 | * Indicates a prepressed state; |
| 1687 | * the short time between ACTION_DOWN and recognizing |
| 1688 | * a 'real' press. Prepressed is used to recognize quick taps |
| 1689 | * even when they are shorter than ViewConfiguration.getTapTimeout(). |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1690 | * |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1691 | * @hide |
| 1692 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1693 | private static final int PFLAG_PREPRESSED = 0x02000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1694 | |
Adam Powell | c9fbaab | 2010-02-16 17:16:19 -0800 | [diff] [blame] | 1695 | /** |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 1696 | * Indicates whether the view is temporarily detached. |
| 1697 | * |
| 1698 | * @hide |
| 1699 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1700 | static final int PFLAG_CANCEL_NEXT_UP_EVENT = 0x04000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1701 | |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1702 | /** |
| 1703 | * Indicates that we should awaken scroll bars once attached |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1704 | * |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1705 | * @hide |
| 1706 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1707 | private static final int PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH = 0x08000000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1708 | |
| 1709 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1710 | * Indicates that the view has received HOVER_ENTER. Cleared on HOVER_EXIT. |
| 1711 | * @hide |
| 1712 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1713 | private static final int PFLAG_HOVERED = 0x10000000; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1714 | |
| 1715 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1716 | * Indicates that pivotX or pivotY were explicitly set and we should not assume the center |
| 1717 | * for transform operations |
| 1718 | * |
| 1719 | * @hide |
| 1720 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1721 | private static final int PFLAG_PIVOT_EXPLICITLY_SET = 0x20000000; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1722 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1723 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1724 | static final int PFLAG_ACTIVATED = 0x40000000; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1725 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1726 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1727 | * Indicates that this view was specifically invalidated, not just dirtied because some |
| 1728 | * child view was invalidated. The flag is used to determine when we need to recreate |
| 1729 | * a view's display list (as opposed to just returning a reference to its existing |
| 1730 | * display list). |
| 1731 | * |
| 1732 | * @hide |
| 1733 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1734 | static final int PFLAG_INVALIDATED = 0x80000000; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1735 | |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 1736 | /** |
| 1737 | * Masks for mPrivateFlags2, as generated by dumpFlags(): |
| 1738 | * |
| 1739 | * -------|-------|-------|-------| |
| 1740 | * PFLAG2_TEXT_ALIGNMENT_FLAGS[0] |
| 1741 | * PFLAG2_TEXT_DIRECTION_FLAGS[0] |
| 1742 | * 1 PFLAG2_DRAG_CAN_ACCEPT |
| 1743 | * 1 PFLAG2_DRAG_HOVERED |
| 1744 | * 1 PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT |
| 1745 | * 11 PFLAG2_TEXT_DIRECTION_MASK_SHIFT |
| 1746 | * 1 1 PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT |
| 1747 | * 11 PFLAG2_LAYOUT_DIRECTION_MASK |
| 1748 | * 11 1 PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT |
| 1749 | * 1 PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL |
| 1750 | * 1 1 PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT |
| 1751 | * 1 1 PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT |
| 1752 | * 1 PFLAG2_LAYOUT_DIRECTION_RESOLVED |
| 1753 | * 11 PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK |
| 1754 | * 1 PFLAG2_TEXT_DIRECTION_FLAGS[1] |
| 1755 | * 1 PFLAG2_TEXT_DIRECTION_FLAGS[2] |
| 1756 | * 11 PFLAG2_TEXT_DIRECTION_FLAGS[3] |
| 1757 | * 1 PFLAG2_TEXT_DIRECTION_FLAGS[4] |
| 1758 | * 1 1 PFLAG2_TEXT_DIRECTION_FLAGS[5] |
| 1759 | * 111 PFLAG2_TEXT_DIRECTION_MASK |
| 1760 | * 1 PFLAG2_TEXT_DIRECTION_RESOLVED |
| 1761 | * 1 PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT |
| 1762 | * 111 PFLAG2_TEXT_DIRECTION_RESOLVED_MASK |
| 1763 | * 1 PFLAG2_TEXT_ALIGNMENT_FLAGS[1] |
| 1764 | * 1 PFLAG2_TEXT_ALIGNMENT_FLAGS[2] |
| 1765 | * 11 PFLAG2_TEXT_ALIGNMENT_FLAGS[3] |
| 1766 | * 1 PFLAG2_TEXT_ALIGNMENT_FLAGS[4] |
| 1767 | * 1 1 PFLAG2_TEXT_ALIGNMENT_FLAGS[5] |
| 1768 | * 11 PFLAG2_TEXT_ALIGNMENT_FLAGS[6] |
| 1769 | * 111 PFLAG2_TEXT_ALIGNMENT_MASK |
| 1770 | * 1 PFLAG2_TEXT_ALIGNMENT_RESOLVED |
| 1771 | * 1 PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT |
| 1772 | * 111 PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK |
| 1773 | * 11 PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK |
| 1774 | * 1 PFLAG2_HAS_TRANSIENT_STATE |
| 1775 | * 1 PFLAG2_ACCESSIBILITY_FOCUSED |
| 1776 | * 1 PFLAG2_ACCESSIBILITY_STATE_CHANGED |
| 1777 | * 1 PFLAG2_VIEW_QUICK_REJECTED |
| 1778 | * 1 PFLAG2_PADDING_RESOLVED |
| 1779 | * -------|-------|-------|-------| |
| 1780 | */ |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1781 | |
| 1782 | /** |
| 1783 | * Indicates that this view has reported that it can accept the current drag's content. |
| 1784 | * Cleared when the drag operation concludes. |
| 1785 | * @hide |
| 1786 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1787 | static final int PFLAG2_DRAG_CAN_ACCEPT = 0x00000001; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1788 | |
| 1789 | /** |
| 1790 | * Indicates that this view is currently directly under the drag location in a |
| 1791 | * drag-and-drop operation involving content that it can accept. Cleared when |
| 1792 | * the drag exits the view, or when the drag operation concludes. |
| 1793 | * @hide |
| 1794 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1795 | static final int PFLAG2_DRAG_HOVERED = 0x00000002; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1796 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1797 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1798 | * Horizontal layout direction of this view is from Left to Right. |
| 1799 | * Use with {@link #setLayoutDirection}. |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1800 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1801 | public static final int LAYOUT_DIRECTION_LTR = 0; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1802 | |
| 1803 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1804 | * Horizontal layout direction of this view is from Right to Left. |
| 1805 | * Use with {@link #setLayoutDirection}. |
| 1806 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1807 | public static final int LAYOUT_DIRECTION_RTL = 1; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1808 | |
| 1809 | /** |
| 1810 | * Horizontal layout direction of this view is inherited from its parent. |
| 1811 | * Use with {@link #setLayoutDirection}. |
| 1812 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1813 | public static final int LAYOUT_DIRECTION_INHERIT = 2; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1814 | |
| 1815 | /** |
| 1816 | * Horizontal layout direction of this view is from deduced from the default language |
| 1817 | * script for the locale. Use with {@link #setLayoutDirection}. |
| 1818 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1819 | public static final int LAYOUT_DIRECTION_LOCALE = 3; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1820 | |
| 1821 | /** |
| 1822 | * 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] | 1823 | * @hide |
| 1824 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1825 | static final int PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT = 2; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1826 | |
| 1827 | /** |
| 1828 | * Mask for use with private flags indicating bits used for horizontal layout direction. |
| 1829 | * @hide |
| 1830 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1831 | 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] | 1832 | |
| 1833 | /** |
| 1834 | * Indicates whether the view horizontal layout direction has been resolved and drawn to the |
| 1835 | * right-to-left direction. |
| 1836 | * @hide |
| 1837 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1838 | 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] | 1839 | |
| 1840 | /** |
| 1841 | * Indicates whether the view horizontal layout direction has been resolved. |
| 1842 | * @hide |
| 1843 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1844 | 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] | 1845 | |
| 1846 | /** |
| 1847 | * Mask for use with private flags indicating bits used for resolved horizontal layout direction. |
| 1848 | * @hide |
| 1849 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1850 | static final int PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK = 0x0000000C |
| 1851 | << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1852 | |
| 1853 | /* |
| 1854 | * Array of horizontal layout direction flags for mapping attribute "layoutDirection" to correct |
| 1855 | * flag value. |
| 1856 | * @hide |
| 1857 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1858 | private static final int[] LAYOUT_DIRECTION_FLAGS = { |
| 1859 | LAYOUT_DIRECTION_LTR, |
| 1860 | LAYOUT_DIRECTION_RTL, |
| 1861 | LAYOUT_DIRECTION_INHERIT, |
| 1862 | LAYOUT_DIRECTION_LOCALE |
| 1863 | }; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1864 | |
| 1865 | /** |
| 1866 | * Default horizontal layout direction. |
| 1867 | * @hide |
| 1868 | */ |
| 1869 | private static final int LAYOUT_DIRECTION_DEFAULT = LAYOUT_DIRECTION_INHERIT; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1870 | |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1871 | /** |
| 1872 | * Indicates that the view is tracking some sort of transient state |
| 1873 | * that the app should not need to be aware of, but that the framework |
| 1874 | * should take special care to preserve. |
| 1875 | * |
| 1876 | * @hide |
| 1877 | */ |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 1878 | static final int PFLAG2_HAS_TRANSIENT_STATE = 0x1 << 22; |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1879 | |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1880 | /** |
| 1881 | * Text direction is inherited thru {@link ViewGroup} |
| 1882 | */ |
| 1883 | public static final int TEXT_DIRECTION_INHERIT = 0; |
| 1884 | |
| 1885 | /** |
| 1886 | * Text direction is using "first strong algorithm". The first strong directional character |
| 1887 | * determines the paragraph direction. If there is no strong directional character, the |
| 1888 | * paragraph direction is the view's resolved layout direction. |
| 1889 | */ |
| 1890 | public static final int TEXT_DIRECTION_FIRST_STRONG = 1; |
| 1891 | |
| 1892 | /** |
| 1893 | * Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains |
| 1894 | * any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. |
| 1895 | * If there are neither, the paragraph direction is the view's resolved layout direction. |
| 1896 | */ |
| 1897 | public static final int TEXT_DIRECTION_ANY_RTL = 2; |
| 1898 | |
| 1899 | /** |
| 1900 | * Text direction is forced to LTR. |
| 1901 | */ |
| 1902 | public static final int TEXT_DIRECTION_LTR = 3; |
| 1903 | |
| 1904 | /** |
| 1905 | * Text direction is forced to RTL. |
| 1906 | */ |
| 1907 | public static final int TEXT_DIRECTION_RTL = 4; |
| 1908 | |
| 1909 | /** |
| 1910 | * Text direction is coming from the system Locale. |
| 1911 | */ |
| 1912 | public static final int TEXT_DIRECTION_LOCALE = 5; |
| 1913 | |
| 1914 | /** |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1915 | * Default text direction is inherited |
| 1916 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1917 | public static int TEXT_DIRECTION_DEFAULT = TEXT_DIRECTION_INHERIT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1918 | |
| 1919 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1920 | * Bit shift to get the horizontal layout direction. (bits after LAYOUT_DIRECTION_RESOLVED) |
| 1921 | * @hide |
| 1922 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1923 | static final int PFLAG2_TEXT_DIRECTION_MASK_SHIFT = 6; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1924 | |
| 1925 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1926 | * Mask for use with private flags indicating bits used for text direction. |
| 1927 | * @hide |
| 1928 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1929 | static final int PFLAG2_TEXT_DIRECTION_MASK = 0x00000007 |
| 1930 | << PFLAG2_TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1931 | |
| 1932 | /** |
| 1933 | * Array of text direction flags for mapping attribute "textDirection" to correct |
| 1934 | * flag value. |
| 1935 | * @hide |
| 1936 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1937 | private static final int[] PFLAG2_TEXT_DIRECTION_FLAGS = { |
| 1938 | TEXT_DIRECTION_INHERIT << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1939 | TEXT_DIRECTION_FIRST_STRONG << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1940 | TEXT_DIRECTION_ANY_RTL << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1941 | TEXT_DIRECTION_LTR << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1942 | TEXT_DIRECTION_RTL << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1943 | TEXT_DIRECTION_LOCALE << PFLAG2_TEXT_DIRECTION_MASK_SHIFT |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1944 | }; |
| 1945 | |
| 1946 | /** |
| 1947 | * Indicates whether the view text direction has been resolved. |
| 1948 | * @hide |
| 1949 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1950 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED = 0x00000008 |
| 1951 | << PFLAG2_TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1952 | |
| 1953 | /** |
| 1954 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 1955 | * @hide |
| 1956 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1957 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT = 10; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1958 | |
| 1959 | /** |
| 1960 | * Mask for use with private flags indicating bits used for resolved text direction. |
| 1961 | * @hide |
| 1962 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1963 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED_MASK = 0x00000007 |
| 1964 | << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1965 | |
| 1966 | /** |
| 1967 | * Indicates whether the view text direction has been resolved to the "first strong" heuristic. |
| 1968 | * @hide |
| 1969 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1970 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT = |
| 1971 | TEXT_DIRECTION_FIRST_STRONG << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1972 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1973 | /* |
| 1974 | * Default text alignment. The text alignment of this View is inherited from its parent. |
| 1975 | * Use with {@link #setTextAlignment(int)} |
| 1976 | */ |
| 1977 | public static final int TEXT_ALIGNMENT_INHERIT = 0; |
| 1978 | |
| 1979 | /** |
| 1980 | * Default for the root view. The gravity determines the text alignment, ALIGN_NORMAL, |
| 1981 | * ALIGN_CENTER, or ALIGN_OPPOSITE, which are relative to each paragraph’s text direction. |
| 1982 | * |
| 1983 | * Use with {@link #setTextAlignment(int)} |
| 1984 | */ |
| 1985 | public static final int TEXT_ALIGNMENT_GRAVITY = 1; |
| 1986 | |
| 1987 | /** |
| 1988 | * Align to the start of the paragraph, e.g. ALIGN_NORMAL. |
| 1989 | * |
| 1990 | * Use with {@link #setTextAlignment(int)} |
| 1991 | */ |
| 1992 | public static final int TEXT_ALIGNMENT_TEXT_START = 2; |
| 1993 | |
| 1994 | /** |
| 1995 | * Align to the end of the paragraph, e.g. ALIGN_OPPOSITE. |
| 1996 | * |
| 1997 | * Use with {@link #setTextAlignment(int)} |
| 1998 | */ |
| 1999 | public static final int TEXT_ALIGNMENT_TEXT_END = 3; |
| 2000 | |
| 2001 | /** |
| 2002 | * Center the paragraph, e.g. ALIGN_CENTER. |
| 2003 | * |
| 2004 | * Use with {@link #setTextAlignment(int)} |
| 2005 | */ |
| 2006 | public static final int TEXT_ALIGNMENT_CENTER = 4; |
| 2007 | |
| 2008 | /** |
| 2009 | * Align to the start of the view, which is ALIGN_LEFT if the view’s resolved |
| 2010 | * layoutDirection is LTR, and ALIGN_RIGHT otherwise. |
| 2011 | * |
| 2012 | * Use with {@link #setTextAlignment(int)} |
| 2013 | */ |
| 2014 | public static final int TEXT_ALIGNMENT_VIEW_START = 5; |
| 2015 | |
| 2016 | /** |
| 2017 | * Align to the end of the view, which is ALIGN_RIGHT if the view’s resolved |
| 2018 | * layoutDirection is LTR, and ALIGN_LEFT otherwise. |
| 2019 | * |
| 2020 | * Use with {@link #setTextAlignment(int)} |
| 2021 | */ |
| 2022 | public static final int TEXT_ALIGNMENT_VIEW_END = 6; |
| 2023 | |
| 2024 | /** |
| 2025 | * Default text alignment is inherited |
| 2026 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2027 | public static int TEXT_ALIGNMENT_DEFAULT = TEXT_ALIGNMENT_GRAVITY; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2028 | |
| 2029 | /** |
| 2030 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 2031 | * @hide |
| 2032 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2033 | static final int PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT = 13; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2034 | |
| 2035 | /** |
| 2036 | * Mask for use with private flags indicating bits used for text alignment. |
| 2037 | * @hide |
| 2038 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2039 | 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] | 2040 | |
| 2041 | /** |
| 2042 | * Array of text direction flags for mapping attribute "textAlignment" to correct |
| 2043 | * flag value. |
| 2044 | * @hide |
| 2045 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2046 | private static final int[] PFLAG2_TEXT_ALIGNMENT_FLAGS = { |
| 2047 | TEXT_ALIGNMENT_INHERIT << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2048 | TEXT_ALIGNMENT_GRAVITY << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2049 | TEXT_ALIGNMENT_TEXT_START << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2050 | TEXT_ALIGNMENT_TEXT_END << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2051 | TEXT_ALIGNMENT_CENTER << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2052 | TEXT_ALIGNMENT_VIEW_START << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2053 | TEXT_ALIGNMENT_VIEW_END << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2054 | }; |
| 2055 | |
| 2056 | /** |
| 2057 | * Indicates whether the view text alignment has been resolved. |
| 2058 | * @hide |
| 2059 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2060 | 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] | 2061 | |
| 2062 | /** |
| 2063 | * Bit shift to get the resolved text alignment. |
| 2064 | * @hide |
| 2065 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2066 | static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT = 17; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2067 | |
| 2068 | /** |
| 2069 | * Mask for use with private flags indicating bits used for text alignment. |
| 2070 | * @hide |
| 2071 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2072 | static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK = 0x00000007 |
| 2073 | << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2074 | |
| 2075 | /** |
| 2076 | * Indicates whether if the view text alignment has been resolved to gravity |
| 2077 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2078 | private static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT = |
| 2079 | TEXT_ALIGNMENT_GRAVITY << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2080 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2081 | // Accessiblity constants for mPrivateFlags2 |
| 2082 | |
| 2083 | /** |
Svetoslav Ganov | f9817f7 | 2012-05-22 18:10:31 -0700 | [diff] [blame] | 2084 | * Shift for the bits in {@link #mPrivateFlags2} related to the |
| 2085 | * "importantForAccessibility" attribute. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2086 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2087 | static final int PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT = 20; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2088 | |
| 2089 | /** |
| 2090 | * Automatically determine whether a view is important for accessibility. |
| 2091 | */ |
| 2092 | public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO = 0x00000000; |
| 2093 | |
| 2094 | /** |
| 2095 | * The view is important for accessibility. |
| 2096 | */ |
| 2097 | public static final int IMPORTANT_FOR_ACCESSIBILITY_YES = 0x00000001; |
| 2098 | |
| 2099 | /** |
| 2100 | * The view is not important for accessibility. |
| 2101 | */ |
| 2102 | public static final int IMPORTANT_FOR_ACCESSIBILITY_NO = 0x00000002; |
| 2103 | |
| 2104 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 2105 | * The default whether the view is important for accessibility. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2106 | */ |
| 2107 | static final int IMPORTANT_FOR_ACCESSIBILITY_DEFAULT = IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
| 2108 | |
| 2109 | /** |
| 2110 | * Mask for obtainig the bits which specify how to determine |
| 2111 | * whether a view is important for accessibility. |
| 2112 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2113 | static final int PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK = (IMPORTANT_FOR_ACCESSIBILITY_AUTO |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2114 | | IMPORTANT_FOR_ACCESSIBILITY_YES | IMPORTANT_FOR_ACCESSIBILITY_NO) |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2115 | << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2116 | |
| 2117 | /** |
| 2118 | * Flag indicating whether a view has accessibility focus. |
| 2119 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2120 | static final int PFLAG2_ACCESSIBILITY_FOCUSED = 0x00000040 << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2121 | |
| 2122 | /** |
| 2123 | * Flag indicating whether a view state for accessibility has changed. |
| 2124 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2125 | static final int PFLAG2_ACCESSIBILITY_STATE_CHANGED = 0x00000080 |
| 2126 | << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 2127 | |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 2128 | /** |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 2129 | * Flag indicating whether a view failed the quickReject() check in draw(). This condition |
| 2130 | * is used to check whether later changes to the view's transform should invalidate the |
| 2131 | * view to force the quickReject test to run again. |
| 2132 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2133 | static final int PFLAG2_VIEW_QUICK_REJECTED = 0x10000000; |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 2134 | |
Adam Powell | 0090f20 | 2012-08-07 17:15:30 -0700 | [diff] [blame] | 2135 | /** |
| 2136 | * Flag indicating that start/end padding has been resolved into left/right padding |
| 2137 | * for use in measurement, layout, drawing, etc. This is set by {@link #resolvePadding()} |
| 2138 | * and checked by {@link #measure(int, int)} to determine if padding needs to be resolved |
| 2139 | * during measurement. In some special cases this is required such as when an adapter-based |
| 2140 | * view measures prospective children without attaching them to a window. |
| 2141 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2142 | static final int PFLAG2_PADDING_RESOLVED = 0x20000000; |
Adam Powell | 0090f20 | 2012-08-07 17:15:30 -0700 | [diff] [blame] | 2143 | |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 2144 | /** |
| 2145 | * Flag indicating that the start/end drawables has been resolved into left/right ones. |
| 2146 | */ |
| 2147 | static final int PFLAG2_DRAWABLE_RESOLVED = 0x40000000; |
| 2148 | |
| 2149 | /** |
| 2150 | * Group of bits indicating that RTL properties resolution is done. |
| 2151 | */ |
| 2152 | static final int ALL_RTL_PROPERTIES_RESOLVED = PFLAG2_LAYOUT_DIRECTION_RESOLVED | |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 2153 | PFLAG2_TEXT_DIRECTION_RESOLVED | |
| 2154 | PFLAG2_TEXT_ALIGNMENT_RESOLVED | |
| 2155 | PFLAG2_PADDING_RESOLVED | |
| 2156 | PFLAG2_DRAWABLE_RESOLVED; |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 2157 | |
Svetoslav Ganov | 27e2da7 | 2012-07-02 18:12:00 -0700 | [diff] [blame] | 2158 | // There are a couple of flags left in mPrivateFlags2 |
Svetoslav Ganov | f9817f7 | 2012-05-22 18:10:31 -0700 | [diff] [blame] | 2159 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2160 | /* End of masks for mPrivateFlags2 */ |
| 2161 | |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2162 | /* Masks for mPrivateFlags3 */ |
| 2163 | |
| 2164 | /** |
| 2165 | * Flag indicating that view has a transform animation set on it. This is used to track whether |
| 2166 | * an animation is cleared between successive frames, in order to tell the associated |
| 2167 | * DisplayList to clear its animation matrix. |
| 2168 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2169 | static final int PFLAG3_VIEW_IS_ANIMATING_TRANSFORM = 0x1; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2170 | |
| 2171 | /** |
| 2172 | * Flag indicating that view has an alpha animation set on it. This is used to track whether an |
| 2173 | * animation is cleared between successive frames, in order to tell the associated |
| 2174 | * DisplayList to restore its alpha value. |
| 2175 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2176 | static final int PFLAG3_VIEW_IS_ANIMATING_ALPHA = 0x2; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2177 | |
| 2178 | |
| 2179 | /* End of masks for mPrivateFlags3 */ |
| 2180 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2181 | static final int DRAG_MASK = PFLAG2_DRAG_CAN_ACCEPT | PFLAG2_DRAG_HOVERED; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2182 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 2183 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2184 | * Always allow a user to over-scroll this view, provided it is a |
| 2185 | * view that can scroll. |
| 2186 | * |
| 2187 | * @see #getOverScrollMode() |
| 2188 | * @see #setOverScrollMode(int) |
| 2189 | */ |
| 2190 | public static final int OVER_SCROLL_ALWAYS = 0; |
| 2191 | |
| 2192 | /** |
| 2193 | * Allow a user to over-scroll this view only if the content is large |
| 2194 | * enough to meaningfully scroll, provided it is a view that can scroll. |
| 2195 | * |
| 2196 | * @see #getOverScrollMode() |
| 2197 | * @see #setOverScrollMode(int) |
| 2198 | */ |
| 2199 | public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; |
| 2200 | |
| 2201 | /** |
| 2202 | * Never allow a user to over-scroll this view. |
| 2203 | * |
| 2204 | * @see #getOverScrollMode() |
| 2205 | * @see #setOverScrollMode(int) |
| 2206 | */ |
| 2207 | public static final int OVER_SCROLL_NEVER = 2; |
| 2208 | |
| 2209 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2210 | * Special constant for {@link #setSystemUiVisibility(int)}: View has |
| 2211 | * requested the system UI (status bar) to be visible (the default). |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2212 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2213 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2214 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2215 | public static final int SYSTEM_UI_FLAG_VISIBLE = 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2216 | |
| 2217 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2218 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested the |
| 2219 | * system UI to enter an unobtrusive "low profile" mode. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2220 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2221 | * <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] | 2222 | * "immersive" application where the usual system chrome is deemed too distracting. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2223 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2224 | * <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] | 2225 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2226 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2227 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2228 | public static final int SYSTEM_UI_FLAG_LOW_PROFILE = 0x00000001; |
| 2229 | |
| 2230 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2231 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested that the |
| 2232 | * system navigation be temporarily hidden. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2233 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2234 | * <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] | 2235 | * {@link #SYSTEM_UI_FLAG_LOW_PROFILE}; on devices that draw essential navigation controls |
| 2236 | * (Home, Back, and the like) on screen, <code>SYSTEM_UI_FLAG_HIDE_NAVIGATION</code> will cause |
| 2237 | * those to disappear. This is useful (in conjunction with the |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2238 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN FLAG_FULLSCREEN} and |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2239 | * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN FLAG_LAYOUT_IN_SCREEN} |
| 2240 | * window flags) for displaying content using every last pixel on the display. |
| 2241 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2242 | * <p>There is a limitation: because navigation controls are so important, the least user |
| 2243 | * interaction will cause them to reappear immediately. When this happens, both |
| 2244 | * this flag and {@link #SYSTEM_UI_FLAG_FULLSCREEN} will be cleared automatically, |
| 2245 | * so that both elements reappear at the same time. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2246 | * |
| 2247 | * @see #setSystemUiVisibility(int) |
| 2248 | */ |
| 2249 | public static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 0x00000002; |
| 2250 | |
| 2251 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2252 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested to go |
| 2253 | * into the normal fullscreen mode so that its content can take over the screen |
| 2254 | * while still allowing the user to interact with the application. |
| 2255 | * |
| 2256 | * <p>This has the same visual effect as |
| 2257 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN |
| 2258 | * WindowManager.LayoutParams.FLAG_FULLSCREEN}, |
| 2259 | * meaning that non-critical screen decorations (such as the status bar) will be |
| 2260 | * hidden while the user is in the View's window, focusing the experience on |
| 2261 | * that content. Unlike the window flag, if you are using ActionBar in |
| 2262 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2263 | * Window.FEATURE_ACTION_BAR_OVERLAY}, then enabling this flag will also |
| 2264 | * hide the action bar. |
| 2265 | * |
| 2266 | * <p>This approach to going fullscreen is best used over the window flag when |
| 2267 | * it is a transient state -- that is, the application does this at certain |
| 2268 | * points in its user interaction where it wants to allow the user to focus |
| 2269 | * on content, but not as a continuous state. For situations where the application |
| 2270 | * would like to simply stay full screen the entire time (such as a game that |
| 2271 | * wants to take over the screen), the |
| 2272 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN window flag} |
| 2273 | * is usually a better approach. The state set here will be removed by the system |
| 2274 | * in various situations (such as the user moving to another application) like |
| 2275 | * the other system UI states. |
| 2276 | * |
| 2277 | * <p>When using this flag, the application should provide some easy facility |
| 2278 | * for the user to go out of it. A common example would be in an e-book |
| 2279 | * reader, where tapping on the screen brings back whatever screen and UI |
| 2280 | * decorations that had been hidden while the user was immersed in reading |
| 2281 | * the book. |
| 2282 | * |
| 2283 | * @see #setSystemUiVisibility(int) |
| 2284 | */ |
| 2285 | public static final int SYSTEM_UI_FLAG_FULLSCREEN = 0x00000004; |
| 2286 | |
| 2287 | /** |
| 2288 | * Flag for {@link #setSystemUiVisibility(int)}: When using other layout |
| 2289 | * flags, we would like a stable view of the content insets given to |
| 2290 | * {@link #fitSystemWindows(Rect)}. This means that the insets seen there |
| 2291 | * will always represent the worst case that the application can expect |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2292 | * as a continuous state. In the stock Android UI this is the space for |
| 2293 | * the system bar, nav bar, and status bar, but not more transient elements |
| 2294 | * such as an input method. |
| 2295 | * |
| 2296 | * The stable layout your UI sees is based on the system UI modes you can |
| 2297 | * switch to. That is, if you specify {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} |
| 2298 | * then you will get a stable layout for changes of the |
| 2299 | * {@link #SYSTEM_UI_FLAG_FULLSCREEN} mode; if you specify |
| 2300 | * {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} and |
| 2301 | * {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, then you can transition |
| 2302 | * to {@link #SYSTEM_UI_FLAG_FULLSCREEN} and {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION} |
| 2303 | * with a stable layout. (Note that you should avoid using |
| 2304 | * {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} by itself.) |
| 2305 | * |
Jeff Smith | a45746e | 2012-07-19 14:19:24 -0500 | [diff] [blame] | 2306 | * If you have set the window flag {@link WindowManager.LayoutParams#FLAG_FULLSCREEN} |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2307 | * to hide the status bar (instead of using {@link #SYSTEM_UI_FLAG_FULLSCREEN}), |
| 2308 | * then a hidden status bar will be considered a "stable" state for purposes |
| 2309 | * here. This allows your UI to continually hide the status bar, while still |
| 2310 | * using the system UI flags to hide the action bar while still retaining |
| 2311 | * a stable layout. Note that changing the window fullscreen flag will never |
| 2312 | * provide a stable layout for a clean transition. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2313 | * |
| 2314 | * <p>If you are using ActionBar in |
| 2315 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2316 | * Window.FEATURE_ACTION_BAR_OVERLAY}, this flag will also impact the |
| 2317 | * insets it adds to those given to the application. |
| 2318 | */ |
| 2319 | public static final int SYSTEM_UI_FLAG_LAYOUT_STABLE = 0x00000100; |
| 2320 | |
| 2321 | /** |
| 2322 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2323 | * to be layed out as if it has requested |
| 2324 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, even if it currently hasn't. This |
| 2325 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2326 | * the expense that some of its user interface may be covered by screen |
| 2327 | * decorations when they are shown. You can perform layout of your inner |
| 2328 | * UI elements to account for the navagation system UI through the |
| 2329 | * {@link #fitSystemWindows(Rect)} method. |
| 2330 | */ |
| 2331 | public static final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 0x00000200; |
| 2332 | |
| 2333 | /** |
| 2334 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2335 | * to be layed out as if it has requested |
| 2336 | * {@link #SYSTEM_UI_FLAG_FULLSCREEN}, even if it currently hasn't. This |
| 2337 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2338 | * the expense that some of its user interface may be covered by screen |
| 2339 | * decorations when they are shown. You can perform layout of your inner |
| 2340 | * UI elements to account for non-fullscreen system UI through the |
| 2341 | * {@link #fitSystemWindows(Rect)} method. |
| 2342 | */ |
| 2343 | public static final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 0x00000400; |
| 2344 | |
| 2345 | /** |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2346 | * @deprecated Use {@link #SYSTEM_UI_FLAG_LOW_PROFILE} instead. |
| 2347 | */ |
| 2348 | public static final int STATUS_BAR_HIDDEN = SYSTEM_UI_FLAG_LOW_PROFILE; |
| 2349 | |
| 2350 | /** |
| 2351 | * @deprecated Use {@link #SYSTEM_UI_FLAG_VISIBLE} instead. |
| 2352 | */ |
| 2353 | public static final int STATUS_BAR_VISIBLE = SYSTEM_UI_FLAG_VISIBLE; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2354 | |
| 2355 | /** |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2356 | * @hide |
| 2357 | * |
| 2358 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2359 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2360 | * |
| 2361 | * Flag to make the status bar not expandable. Unless you also |
| 2362 | * set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show. |
| 2363 | */ |
| 2364 | public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000; |
| 2365 | |
| 2366 | /** |
| 2367 | * @hide |
| 2368 | * |
| 2369 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2370 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2371 | * |
| 2372 | * Flag to hide notification icons and scrolling ticker text. |
| 2373 | */ |
| 2374 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS = 0x00020000; |
| 2375 | |
| 2376 | /** |
| 2377 | * @hide |
| 2378 | * |
| 2379 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2380 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2381 | * |
| 2382 | * Flag to disable incoming notification alerts. This will not block |
| 2383 | * icons, but it will block sound, vibrating and other visual or aural notifications. |
| 2384 | */ |
| 2385 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS = 0x00040000; |
| 2386 | |
| 2387 | /** |
| 2388 | * @hide |
| 2389 | * |
| 2390 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2391 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2392 | * |
| 2393 | * Flag to hide only the scrolling ticker. Note that |
| 2394 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS} implies |
| 2395 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_TICKER}. |
| 2396 | */ |
| 2397 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_TICKER = 0x00080000; |
| 2398 | |
| 2399 | /** |
| 2400 | * @hide |
| 2401 | * |
| 2402 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2403 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2404 | * |
| 2405 | * Flag to hide the center system info area. |
| 2406 | */ |
| 2407 | public static final int STATUS_BAR_DISABLE_SYSTEM_INFO = 0x00100000; |
| 2408 | |
| 2409 | /** |
| 2410 | * @hide |
| 2411 | * |
| 2412 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2413 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2414 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2415 | * Flag to hide only the home button. Don't use this |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2416 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2417 | */ |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2418 | public static final int STATUS_BAR_DISABLE_HOME = 0x00200000; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2419 | |
| 2420 | /** |
| 2421 | * @hide |
| 2422 | * |
| 2423 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2424 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2425 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2426 | * Flag to hide only the back button. Don't use this |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2427 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2428 | */ |
| 2429 | public static final int STATUS_BAR_DISABLE_BACK = 0x00400000; |
| 2430 | |
| 2431 | /** |
| 2432 | * @hide |
| 2433 | * |
| 2434 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2435 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2436 | * |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2437 | * Flag to hide only the clock. You might use this if your activity has |
| 2438 | * its own clock making the status bar's clock redundant. |
| 2439 | */ |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2440 | public static final int STATUS_BAR_DISABLE_CLOCK = 0x00800000; |
| 2441 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2442 | /** |
| 2443 | * @hide |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2444 | * |
| 2445 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2446 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2447 | * |
| 2448 | * Flag to hide only the recent apps button. Don't use this |
| 2449 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2450 | */ |
| 2451 | public static final int STATUS_BAR_DISABLE_RECENT = 0x01000000; |
| 2452 | |
| 2453 | /** |
| 2454 | * @hide |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2455 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2456 | public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x0000FFFF; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2457 | |
| 2458 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2459 | * These are the system UI flags that can be cleared by events outside |
| 2460 | * of an application. Currently this is just the ability to tap on the |
| 2461 | * screen while hiding the navigation bar to have it return. |
| 2462 | * @hide |
| 2463 | */ |
| 2464 | public static final int SYSTEM_UI_CLEARABLE_FLAGS = |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2465 | SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 2466 | | SYSTEM_UI_FLAG_FULLSCREEN; |
| 2467 | |
| 2468 | /** |
| 2469 | * Flags that can impact the layout in relation to system UI. |
| 2470 | */ |
| 2471 | public static final int SYSTEM_UI_LAYOUT_FLAGS = |
| 2472 | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 2473 | | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2474 | |
| 2475 | /** |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 2476 | * Find views that render the specified text. |
| 2477 | * |
| 2478 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2479 | */ |
| 2480 | public static final int FIND_VIEWS_WITH_TEXT = 0x00000001; |
| 2481 | |
| 2482 | /** |
| 2483 | * Find find views that contain the specified content description. |
| 2484 | * |
| 2485 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2486 | */ |
| 2487 | public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 0x00000002; |
| 2488 | |
| 2489 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 2490 | * Find views that contain {@link AccessibilityNodeProvider}. Such |
| 2491 | * a View is a root of virtual view hierarchy and may contain the searched |
| 2492 | * text. If this flag is set Views with providers are automatically |
| 2493 | * added and it is a responsibility of the client to call the APIs of |
| 2494 | * the provider to determine whether the virtual tree rooted at this View |
| 2495 | * contains the text, i.e. getting the list of {@link AccessibilityNodeInfo}s |
| 2496 | * represeting the virtual views with this text. |
| 2497 | * |
| 2498 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2499 | * |
| 2500 | * @hide |
| 2501 | */ |
| 2502 | public static final int FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS = 0x00000004; |
| 2503 | |
| 2504 | /** |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 2505 | * The undefined cursor position. |
| 2506 | */ |
| 2507 | private static final int ACCESSIBILITY_CURSOR_POSITION_UNDEFINED = -1; |
| 2508 | |
| 2509 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2510 | * Indicates that the screen has changed state and is now off. |
| 2511 | * |
| 2512 | * @see #onScreenStateChanged(int) |
| 2513 | */ |
| 2514 | public static final int SCREEN_STATE_OFF = 0x0; |
| 2515 | |
| 2516 | /** |
| 2517 | * Indicates that the screen has changed state and is now on. |
| 2518 | * |
Romain Guy | 1e3d313 | 2012-03-08 15:55:56 -0800 | [diff] [blame] | 2519 | * @see #onScreenStateChanged(int) |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2520 | */ |
| 2521 | public static final int SCREEN_STATE_ON = 0x1; |
| 2522 | |
| 2523 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2524 | * Controls the over-scroll mode for this view. |
| 2525 | * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)}, |
| 2526 | * {@link #OVER_SCROLL_ALWAYS}, {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}, |
| 2527 | * and {@link #OVER_SCROLL_NEVER}. |
| 2528 | */ |
| 2529 | private int mOverScrollMode; |
| 2530 | |
| 2531 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2532 | * The parent this view is attached to. |
| 2533 | * {@hide} |
| 2534 | * |
| 2535 | * @see #getParent() |
| 2536 | */ |
| 2537 | protected ViewParent mParent; |
| 2538 | |
| 2539 | /** |
| 2540 | * {@hide} |
| 2541 | */ |
| 2542 | AttachInfo mAttachInfo; |
| 2543 | |
| 2544 | /** |
| 2545 | * {@hide} |
| 2546 | */ |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2547 | @ViewDebug.ExportedProperty(flagMapping = { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2548 | @ViewDebug.FlagToString(mask = PFLAG_FORCE_LAYOUT, equals = PFLAG_FORCE_LAYOUT, |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2549 | name = "FORCE_LAYOUT"), |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2550 | @ViewDebug.FlagToString(mask = PFLAG_LAYOUT_REQUIRED, equals = PFLAG_LAYOUT_REQUIRED, |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2551 | name = "LAYOUT_REQUIRED"), |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2552 | @ViewDebug.FlagToString(mask = PFLAG_DRAWING_CACHE_VALID, equals = PFLAG_DRAWING_CACHE_VALID, |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 2553 | name = "DRAWING_CACHE_INVALID", outputIf = false), |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2554 | @ViewDebug.FlagToString(mask = PFLAG_DRAWN, equals = PFLAG_DRAWN, name = "DRAWN", outputIf = true), |
| 2555 | @ViewDebug.FlagToString(mask = PFLAG_DRAWN, equals = PFLAG_DRAWN, name = "NOT_DRAWN", outputIf = false), |
| 2556 | @ViewDebug.FlagToString(mask = PFLAG_DIRTY_MASK, equals = PFLAG_DIRTY_OPAQUE, name = "DIRTY_OPAQUE"), |
| 2557 | @ViewDebug.FlagToString(mask = PFLAG_DIRTY_MASK, equals = PFLAG_DIRTY, name = "DIRTY") |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2558 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2559 | int mPrivateFlags; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2560 | int mPrivateFlags2; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2561 | int mPrivateFlags3; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | |
| 2563 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2564 | * This view's request for the visibility of the status bar. |
| 2565 | * @hide |
| 2566 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2567 | @ViewDebug.ExportedProperty(flagMapping = { |
| 2568 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2569 | equals = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2570 | name = "SYSTEM_UI_FLAG_LOW_PROFILE", outputIf = true), |
| 2571 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2572 | equals = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2573 | name = "SYSTEM_UI_FLAG_HIDE_NAVIGATION", outputIf = true), |
| 2574 | @ViewDebug.FlagToString(mask = PUBLIC_STATUS_BAR_VISIBILITY_MASK, |
| 2575 | equals = SYSTEM_UI_FLAG_VISIBLE, |
| 2576 | name = "SYSTEM_UI_FLAG_VISIBLE", outputIf = true) |
| 2577 | }) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2578 | int mSystemUiVisibility; |
| 2579 | |
| 2580 | /** |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 2581 | * Reference count for transient state. |
| 2582 | * @see #setHasTransientState(boolean) |
| 2583 | */ |
| 2584 | int mTransientStateCount = 0; |
| 2585 | |
| 2586 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2587 | * Count of how many windows this view has been attached to. |
| 2588 | */ |
| 2589 | int mWindowAttachCount; |
| 2590 | |
| 2591 | /** |
| 2592 | * The layout parameters associated with this view and used by the parent |
| 2593 | * {@link android.view.ViewGroup} to determine how this view should be |
| 2594 | * laid out. |
| 2595 | * {@hide} |
| 2596 | */ |
| 2597 | protected ViewGroup.LayoutParams mLayoutParams; |
| 2598 | |
| 2599 | /** |
| 2600 | * The view flags hold various views states. |
| 2601 | * {@hide} |
| 2602 | */ |
| 2603 | @ViewDebug.ExportedProperty |
| 2604 | int mViewFlags; |
| 2605 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2606 | static class TransformationInfo { |
| 2607 | /** |
| 2608 | * The transform matrix for the View. This transform is calculated internally |
| 2609 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2610 | * is used by default. Do *not* use this variable directly; instead call |
| 2611 | * getMatrix(), which will automatically recalculate the matrix if necessary |
| 2612 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2613 | */ |
| 2614 | private final Matrix mMatrix = new Matrix(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2615 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 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 | * getInverseMatrix(), 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 Matrix mInverseMatrix; |
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 | * An internal variable that tracks whether we need to recalculate the |
| 2627 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2628 | * have changed since the matrix was last calculated. |
| 2629 | */ |
| 2630 | boolean mMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2631 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2632 | /** |
| 2633 | * An internal variable that tracks whether we need to recalculate the |
| 2634 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2635 | * have changed since the matrix was last calculated. |
| 2636 | */ |
| 2637 | private boolean mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2638 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2639 | /** |
| 2640 | * A variable that tracks whether we need to recalculate the |
| 2641 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2642 | * have changed since the matrix was last calculated. This variable |
| 2643 | * is only valid after a call to updateMatrix() or to a function that |
| 2644 | * calls it such as getMatrix(), hasIdentityMatrix() and getInverseMatrix(). |
| 2645 | */ |
| 2646 | private boolean mMatrixIsIdentity = 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 | * The Camera object is used to compute a 3D matrix when rotationX or rotationY are set. |
| 2650 | */ |
| 2651 | private Camera mCamera = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2652 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2653 | /** |
| 2654 | * This matrix is used when computing the matrix for 3D rotations. |
| 2655 | */ |
| 2656 | private Matrix matrix3D = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2657 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2658 | /** |
| 2659 | * These prev values are used to recalculate a centered pivot point when necessary. The |
| 2660 | * pivot point is only used in matrix operations (when rotation, scale, or translation are |
| 2661 | * set), so thes values are only used then as well. |
| 2662 | */ |
| 2663 | private int mPrevWidth = -1; |
| 2664 | private int mPrevHeight = -1; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2665 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2666 | /** |
| 2667 | * The degrees rotation around the vertical axis through the pivot point. |
| 2668 | */ |
| 2669 | @ViewDebug.ExportedProperty |
| 2670 | float mRotationY = 0f; |
| 2671 | |
| 2672 | /** |
| 2673 | * The degrees rotation around the horizontal axis through the pivot point. |
| 2674 | */ |
| 2675 | @ViewDebug.ExportedProperty |
| 2676 | float mRotationX = 0f; |
| 2677 | |
| 2678 | /** |
| 2679 | * The degrees rotation around the pivot point. |
| 2680 | */ |
| 2681 | @ViewDebug.ExportedProperty |
| 2682 | float mRotation = 0f; |
| 2683 | |
| 2684 | /** |
| 2685 | * The amount of translation of the object away from its left property (post-layout). |
| 2686 | */ |
| 2687 | @ViewDebug.ExportedProperty |
| 2688 | float mTranslationX = 0f; |
| 2689 | |
| 2690 | /** |
| 2691 | * The amount of translation of the object away from its top property (post-layout). |
| 2692 | */ |
| 2693 | @ViewDebug.ExportedProperty |
| 2694 | float mTranslationY = 0f; |
| 2695 | |
| 2696 | /** |
| 2697 | * The amount of scale in the x direction around the pivot point. A |
| 2698 | * value of 1 means no scaling is applied. |
| 2699 | */ |
| 2700 | @ViewDebug.ExportedProperty |
| 2701 | float mScaleX = 1f; |
| 2702 | |
| 2703 | /** |
| 2704 | * The amount of scale in the y direction around the pivot point. A |
| 2705 | * value of 1 means no scaling is applied. |
| 2706 | */ |
| 2707 | @ViewDebug.ExportedProperty |
| 2708 | float mScaleY = 1f; |
| 2709 | |
| 2710 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2711 | * 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] | 2712 | */ |
| 2713 | @ViewDebug.ExportedProperty |
| 2714 | float mPivotX = 0f; |
| 2715 | |
| 2716 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2717 | * 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] | 2718 | */ |
| 2719 | @ViewDebug.ExportedProperty |
| 2720 | float mPivotY = 0f; |
| 2721 | |
| 2722 | /** |
| 2723 | * The opacity of the View. This is a value from 0 to 1, where 0 means |
| 2724 | * completely transparent and 1 means completely opaque. |
| 2725 | */ |
| 2726 | @ViewDebug.ExportedProperty |
| 2727 | float mAlpha = 1f; |
| 2728 | } |
| 2729 | |
| 2730 | TransformationInfo mTransformationInfo; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2731 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2732 | private boolean mLastIsOpaque; |
| 2733 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2734 | /** |
| 2735 | * Convenience value to check for float values that are close enough to zero to be considered |
| 2736 | * zero. |
| 2737 | */ |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 2738 | private static final float NONZERO_EPSILON = .001f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2739 | |
| 2740 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2741 | * The distance in pixels from the left edge of this view's parent |
| 2742 | * to the left edge of this view. |
| 2743 | * {@hide} |
| 2744 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2745 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2746 | protected int mLeft; |
| 2747 | /** |
| 2748 | * The distance in pixels from the left edge of this view's parent |
| 2749 | * to the right edge of this view. |
| 2750 | * {@hide} |
| 2751 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2752 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2753 | protected int mRight; |
| 2754 | /** |
| 2755 | * The distance in pixels from the top edge of this view's parent |
| 2756 | * to the top edge of this view. |
| 2757 | * {@hide} |
| 2758 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2759 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2760 | protected int mTop; |
| 2761 | /** |
| 2762 | * The distance in pixels from the top edge of this view's parent |
| 2763 | * to the bottom edge of this view. |
| 2764 | * {@hide} |
| 2765 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2766 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2767 | protected int mBottom; |
| 2768 | |
| 2769 | /** |
| 2770 | * The offset, in pixels, by which the content of this view is scrolled |
| 2771 | * horizontally. |
| 2772 | * {@hide} |
| 2773 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2774 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2775 | protected int mScrollX; |
| 2776 | /** |
| 2777 | * The offset, in pixels, by which the content of this view is scrolled |
| 2778 | * vertically. |
| 2779 | * {@hide} |
| 2780 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2781 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2782 | protected int mScrollY; |
| 2783 | |
| 2784 | /** |
| 2785 | * The left padding in pixels, that is the distance in pixels between the |
| 2786 | * left edge of this view and the left edge of its content. |
| 2787 | * {@hide} |
| 2788 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2789 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 75aefb8 | 2012-09-27 19:55:18 -0700 | [diff] [blame] | 2790 | protected int mPaddingLeft = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2791 | /** |
| 2792 | * The right padding in pixels, that is the distance in pixels between the |
| 2793 | * right edge of this view and the right edge of its content. |
| 2794 | * {@hide} |
| 2795 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2796 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 75aefb8 | 2012-09-27 19:55:18 -0700 | [diff] [blame] | 2797 | protected int mPaddingRight = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2798 | /** |
| 2799 | * The top padding in pixels, that is the distance in pixels between the |
| 2800 | * top edge of this view and the top edge of its content. |
| 2801 | * {@hide} |
| 2802 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2803 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2804 | protected int mPaddingTop; |
| 2805 | /** |
| 2806 | * The bottom padding in pixels, that is the distance in pixels between the |
| 2807 | * bottom edge of this view and the bottom edge of its content. |
| 2808 | * {@hide} |
| 2809 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2810 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2811 | protected int mPaddingBottom; |
| 2812 | |
| 2813 | /** |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 2814 | * The layout insets in pixels, that is the distance in pixels between the |
| 2815 | * visible edges of this view its bounds. |
| 2816 | */ |
| 2817 | private Insets mLayoutInsets; |
| 2818 | |
| 2819 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2820 | * Briefly describes the view and is primarily used for accessibility support. |
| 2821 | */ |
| 2822 | private CharSequence mContentDescription; |
| 2823 | |
| 2824 | /** |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 2825 | * Specifies the id of a view for which this view serves as a label for |
| 2826 | * accessibility purposes. |
| 2827 | */ |
| 2828 | private int mLabelForId = View.NO_ID; |
| 2829 | |
| 2830 | /** |
| 2831 | * Predicate for matching labeled view id with its label for |
| 2832 | * accessibility purposes. |
| 2833 | */ |
| 2834 | private MatchLabelForPredicate mMatchLabelForPredicate; |
| 2835 | |
| 2836 | /** |
| 2837 | * Predicate for matching a view by its id. |
| 2838 | */ |
| 2839 | private MatchIdPredicate mMatchIdPredicate; |
| 2840 | |
| 2841 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2842 | * 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] | 2843 | * |
| 2844 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2845 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2846 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2847 | protected int mUserPaddingRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2848 | |
| 2849 | /** |
| 2850 | * 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] | 2851 | * |
| 2852 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2854 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2855 | protected int mUserPaddingBottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2856 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2857 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2858 | * 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] | 2859 | * |
| 2860 | * @hide |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2861 | */ |
| 2862 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2863 | protected int mUserPaddingLeft; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2864 | |
| 2865 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2866 | * Cache the paddingStart set by the user to append to the scrollbar's size. |
| 2867 | * |
| 2868 | */ |
| 2869 | @ViewDebug.ExportedProperty(category = "padding") |
| 2870 | int mUserPaddingStart; |
| 2871 | |
| 2872 | /** |
| 2873 | * Cache the paddingEnd set by the user to append to the scrollbar's size. |
| 2874 | * |
| 2875 | */ |
| 2876 | @ViewDebug.ExportedProperty(category = "padding") |
| 2877 | int mUserPaddingEnd; |
| 2878 | |
| 2879 | /** |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 2880 | * Cache initial left padding. |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 2881 | * |
| 2882 | * @hide |
| 2883 | */ |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 2884 | int mUserPaddingLeftInitial = 0; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 2885 | |
| 2886 | /** |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 2887 | * Cache initial right padding. |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 2888 | * |
| 2889 | * @hide |
| 2890 | */ |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 2891 | int mUserPaddingRightInitial = 0; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 2892 | |
| 2893 | /** |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 2894 | * Default undefined padding |
| 2895 | */ |
| 2896 | private static final int UNDEFINED_PADDING = Integer.MIN_VALUE; |
| 2897 | |
| 2898 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2899 | * @hide |
| 2900 | */ |
| 2901 | int mOldWidthMeasureSpec = Integer.MIN_VALUE; |
| 2902 | /** |
| 2903 | * @hide |
| 2904 | */ |
| 2905 | int mOldHeightMeasureSpec = Integer.MIN_VALUE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame^] | 2907 | @ViewDebug.ExportedProperty(deepExport = true, prefix = "bg_") |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2908 | private Drawable mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2909 | |
| 2910 | private int mBackgroundResource; |
| 2911 | private boolean mBackgroundSizeChanged; |
| 2912 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2913 | static class ListenerInfo { |
| 2914 | /** |
| 2915 | * Listener used to dispatch focus change events. |
| 2916 | * This field should be made private, so it is hidden from the SDK. |
| 2917 | * {@hide} |
| 2918 | */ |
| 2919 | protected OnFocusChangeListener mOnFocusChangeListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2920 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2921 | /** |
| 2922 | * Listeners for layout change events. |
| 2923 | */ |
| 2924 | private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 2925 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2926 | /** |
| 2927 | * Listeners for attach events. |
| 2928 | */ |
| 2929 | private CopyOnWriteArrayList<OnAttachStateChangeListener> mOnAttachStateChangeListeners; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 2930 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2931 | /** |
| 2932 | * Listener used to dispatch click events. |
| 2933 | * This field should be made private, so it is hidden from the SDK. |
| 2934 | * {@hide} |
| 2935 | */ |
| 2936 | public OnClickListener mOnClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2937 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2938 | /** |
| 2939 | * Listener used to dispatch long click events. |
| 2940 | * This field should be made private, so it is hidden from the SDK. |
| 2941 | * {@hide} |
| 2942 | */ |
| 2943 | protected OnLongClickListener mOnLongClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2944 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2945 | /** |
| 2946 | * Listener used to build the context menu. |
| 2947 | * This field should be made private, so it is hidden from the SDK. |
| 2948 | * {@hide} |
| 2949 | */ |
| 2950 | protected OnCreateContextMenuListener mOnCreateContextMenuListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2951 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2952 | private OnKeyListener mOnKeyListener; |
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 | private OnTouchListener mOnTouchListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2955 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2956 | private OnHoverListener mOnHoverListener; |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2957 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2958 | private OnGenericMotionListener mOnGenericMotionListener; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2959 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2960 | private OnDragListener mOnDragListener; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 2961 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2962 | private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener; |
| 2963 | } |
| 2964 | |
| 2965 | ListenerInfo mListenerInfo; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2966 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2967 | /** |
| 2968 | * The application environment this view lives in. |
| 2969 | * This field should be made private, so it is hidden from the SDK. |
| 2970 | * {@hide} |
| 2971 | */ |
| 2972 | protected Context mContext; |
| 2973 | |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 2974 | private final Resources mResources; |
| 2975 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2976 | private ScrollabilityCache mScrollCache; |
| 2977 | |
| 2978 | private int[] mDrawableState = null; |
| 2979 | |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2980 | /** |
| 2981 | * Set to true when drawing cache is enabled and cannot be created. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2982 | * |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2983 | * @hide |
| 2984 | */ |
| 2985 | public boolean mCachingFailed; |
| 2986 | |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 2987 | private Bitmap mDrawingCache; |
| 2988 | private Bitmap mUnscaledDrawingCache; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 2989 | private HardwareLayer mHardwareLayer; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2990 | DisplayList mDisplayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2991 | |
| 2992 | /** |
| 2993 | * When this view has focus and the next focus is {@link #FOCUS_LEFT}, |
| 2994 | * the user may specify which view to go to next. |
| 2995 | */ |
| 2996 | private int mNextFocusLeftId = View.NO_ID; |
| 2997 | |
| 2998 | /** |
| 2999 | * When this view has focus and the next focus is {@link #FOCUS_RIGHT}, |
| 3000 | * the user may specify which view to go to next. |
| 3001 | */ |
| 3002 | private int mNextFocusRightId = View.NO_ID; |
| 3003 | |
| 3004 | /** |
| 3005 | * When this view has focus and the next focus is {@link #FOCUS_UP}, |
| 3006 | * the user may specify which view to go to next. |
| 3007 | */ |
| 3008 | private int mNextFocusUpId = View.NO_ID; |
| 3009 | |
| 3010 | /** |
| 3011 | * When this view has focus and the next focus is {@link #FOCUS_DOWN}, |
| 3012 | * the user may specify which view to go to next. |
| 3013 | */ |
| 3014 | private int mNextFocusDownId = View.NO_ID; |
| 3015 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3016 | /** |
| 3017 | * When this view has focus and the next focus is {@link #FOCUS_FORWARD}, |
| 3018 | * the user may specify which view to go to next. |
| 3019 | */ |
| 3020 | int mNextFocusForwardId = View.NO_ID; |
| 3021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3022 | private CheckForLongPress mPendingCheckForLongPress; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 3023 | private CheckForTap mPendingCheckForTap = null; |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 3024 | private PerformClick mPerformClick; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 3025 | private SendViewScrolledAccessibilityEvent mSendViewScrolledAccessibilityEvent; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3026 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3027 | private UnsetPressedState mUnsetPressedState; |
| 3028 | |
| 3029 | /** |
| 3030 | * Whether the long press's action has been invoked. The tap's action is invoked on the |
| 3031 | * up event while a long press is invoked as soon as the long press duration is reached, so |
| 3032 | * a long press could be performed before the tap is checked, in which case the tap's action |
| 3033 | * should not be invoked. |
| 3034 | */ |
| 3035 | private boolean mHasPerformedLongPress; |
| 3036 | |
| 3037 | /** |
| 3038 | * The minimum height of the view. We'll try our best to have the height |
| 3039 | * of this view to at least this amount. |
| 3040 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 3041 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3042 | private int mMinHeight; |
| 3043 | |
| 3044 | /** |
| 3045 | * The minimum width of the view. We'll try our best to have the width |
| 3046 | * of this view to at least this amount. |
| 3047 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 3048 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3049 | private int mMinWidth; |
| 3050 | |
| 3051 | /** |
| 3052 | * The delegate to handle touch events that are physically in this view |
| 3053 | * but should be handled by another view. |
| 3054 | */ |
| 3055 | private TouchDelegate mTouchDelegate = null; |
| 3056 | |
| 3057 | /** |
| 3058 | * Solid color to use as a background when creating the drawing cache. Enables |
| 3059 | * the cache to use 16 bit bitmaps instead of 32 bit. |
| 3060 | */ |
| 3061 | private int mDrawingCacheBackgroundColor = 0; |
| 3062 | |
| 3063 | /** |
| 3064 | * Special tree observer used when mAttachInfo is null. |
| 3065 | */ |
| 3066 | private ViewTreeObserver mFloatingTreeObserver; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3067 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 3068 | /** |
| 3069 | * Cache the touch slop from the context that created the view. |
| 3070 | */ |
| 3071 | private int mTouchSlop; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3072 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3073 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 3074 | * Object that handles automatic animation of view properties. |
| 3075 | */ |
| 3076 | private ViewPropertyAnimator mAnimator = null; |
| 3077 | |
| 3078 | /** |
Christopher Tate | 251602f | 2011-01-28 17:54:12 -0800 | [diff] [blame] | 3079 | * Flag indicating that a drag can cross window boundaries. When |
| 3080 | * {@link #startDrag(ClipData, DragShadowBuilder, Object, int)} is called |
| 3081 | * with this flag set, all visible applications will be able to participate |
| 3082 | * in the drag operation and receive the dragged content. |
Christopher Tate | 7f9ff9d | 2011-02-14 17:31:13 -0800 | [diff] [blame] | 3083 | * |
| 3084 | * @hide |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 3085 | */ |
| 3086 | public static final int DRAG_FLAG_GLOBAL = 1; |
| 3087 | |
| 3088 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3089 | * Vertical scroll factor cached by {@link #getVerticalScrollFactor}. |
| 3090 | */ |
| 3091 | private float mVerticalScrollFactor; |
| 3092 | |
| 3093 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3094 | * Position of the vertical scroll bar. |
| 3095 | */ |
| 3096 | private int mVerticalScrollbarPosition; |
| 3097 | |
| 3098 | /** |
| 3099 | * Position the scroll bar at the default position as determined by the system. |
| 3100 | */ |
| 3101 | public static final int SCROLLBAR_POSITION_DEFAULT = 0; |
| 3102 | |
| 3103 | /** |
| 3104 | * Position the scroll bar along the left edge. |
| 3105 | */ |
| 3106 | public static final int SCROLLBAR_POSITION_LEFT = 1; |
| 3107 | |
| 3108 | /** |
| 3109 | * Position the scroll bar along the right edge. |
| 3110 | */ |
| 3111 | public static final int SCROLLBAR_POSITION_RIGHT = 2; |
| 3112 | |
| 3113 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3114 | * Indicates that the view does not have a layer. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3115 | * |
| 3116 | * @see #getLayerType() |
| 3117 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3118 | * @see #LAYER_TYPE_SOFTWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3119 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3120 | */ |
| 3121 | public static final int LAYER_TYPE_NONE = 0; |
| 3122 | |
| 3123 | /** |
| 3124 | * <p>Indicates that the view has a software layer. A software layer is backed |
| 3125 | * by a bitmap and causes the view to be rendered using Android's software |
| 3126 | * rendering pipeline, even if hardware acceleration is enabled.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3127 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3128 | * <p>Software layers have various usages:</p> |
| 3129 | * <p>When the application is not using hardware acceleration, a software layer |
| 3130 | * is useful to apply a specific color filter and/or blending mode and/or |
| 3131 | * translucency to a view and all its children.</p> |
| 3132 | * <p>When the application is using hardware acceleration, a software layer |
| 3133 | * is useful to render drawing primitives not supported by the hardware |
| 3134 | * accelerated pipeline. It can also be used to cache a complex view tree |
| 3135 | * into a texture and reduce the complexity of drawing operations. For instance, |
| 3136 | * when animating a complex view tree with a translation, a software layer can |
| 3137 | * be used to render the view tree only once.</p> |
| 3138 | * <p>Software layers should be avoided when the affected view tree updates |
| 3139 | * often. Every update will require to re-render the software layer, which can |
| 3140 | * potentially be slow (particularly when hardware acceleration is turned on |
| 3141 | * since the layer will have to be uploaded into a hardware texture after every |
| 3142 | * update.)</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3143 | * |
| 3144 | * @see #getLayerType() |
| 3145 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3146 | * @see #LAYER_TYPE_NONE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3147 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3148 | */ |
| 3149 | public static final int LAYER_TYPE_SOFTWARE = 1; |
| 3150 | |
| 3151 | /** |
| 3152 | * <p>Indicates that the view has a hardware layer. A hardware layer is backed |
| 3153 | * by a hardware specific texture (generally Frame Buffer Objects or FBO on |
| 3154 | * OpenGL hardware) and causes the view to be rendered using Android's hardware |
| 3155 | * rendering pipeline, but only if hardware acceleration is turned on for the |
| 3156 | * view hierarchy. When hardware acceleration is turned off, hardware layers |
| 3157 | * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3158 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3159 | * <p>A hardware layer is useful to apply a specific color filter and/or |
| 3160 | * 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] | 3161 | * <p>A hardware layer can be used to cache a complex view tree into a |
| 3162 | * texture and reduce the complexity of drawing operations. For instance, |
| 3163 | * when animating a complex view tree with a translation, a hardware layer can |
| 3164 | * be used to render the view tree only once.</p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3165 | * <p>A hardware layer can also be used to increase the rendering quality when |
| 3166 | * rotation transformations are applied on a view. It can also be used to |
| 3167 | * prevent potential clipping issues when applying 3D transforms on a view.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3168 | * |
| 3169 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3170 | * @see #setLayerType(int, android.graphics.Paint) |
| 3171 | * @see #LAYER_TYPE_NONE |
| 3172 | * @see #LAYER_TYPE_SOFTWARE |
| 3173 | */ |
| 3174 | public static final int LAYER_TYPE_HARDWARE = 2; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3175 | |
Romain Guy | 3aaff3a | 2011-01-12 14:18:47 -0800 | [diff] [blame] | 3176 | @ViewDebug.ExportedProperty(category = "drawing", mapping = { |
| 3177 | @ViewDebug.IntToString(from = LAYER_TYPE_NONE, to = "NONE"), |
| 3178 | @ViewDebug.IntToString(from = LAYER_TYPE_SOFTWARE, to = "SOFTWARE"), |
| 3179 | @ViewDebug.IntToString(from = LAYER_TYPE_HARDWARE, to = "HARDWARE") |
| 3180 | }) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3181 | int mLayerType = LAYER_TYPE_NONE; |
| 3182 | Paint mLayerPaint; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 3183 | Rect mLocalDirtyRect; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3184 | |
| 3185 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 3186 | * Set to true when the view is sending hover accessibility events because it |
| 3187 | * is the innermost hovered view. |
| 3188 | */ |
| 3189 | private boolean mSendingHoverAccessibilityEvents; |
| 3190 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3191 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 3192 | * Delegate for injecting accessibility functionality. |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3193 | */ |
| 3194 | AccessibilityDelegate mAccessibilityDelegate; |
| 3195 | |
| 3196 | /** |
| 3197 | * Consistency verifier for debugging purposes. |
| 3198 | * @hide |
| 3199 | */ |
| 3200 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 3201 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 3202 | new InputEventConsistencyVerifier(this, 0) : null; |
| 3203 | |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 3204 | private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); |
| 3205 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 3206 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3207 | * Simple constructor to use when creating a view from code. |
| 3208 | * |
| 3209 | * @param context The Context the view is running in, through which it can |
| 3210 | * access the current theme, resources, etc. |
| 3211 | */ |
| 3212 | public View(Context context) { |
| 3213 | mContext = context; |
| 3214 | mResources = context != null ? context.getResources() : null; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3215 | mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3216 | // Set layout and text direction defaults |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 3217 | mPrivateFlags2 = |
| 3218 | (LAYOUT_DIRECTION_DEFAULT << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3219 | (TEXT_DIRECTION_DEFAULT << PFLAG2_TEXT_DIRECTION_MASK_SHIFT) | |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 3220 | (PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT) | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3221 | (TEXT_ALIGNMENT_DEFAULT << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT) | |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 3222 | (PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT) | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3223 | (IMPORTANT_FOR_ACCESSIBILITY_DEFAULT << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 3224 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3225 | setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS); |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3226 | mUserPaddingStart = UNDEFINED_PADDING; |
| 3227 | mUserPaddingEnd = UNDEFINED_PADDING; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3228 | } |
| 3229 | |
| 3230 | /** |
| 3231 | * Constructor that is called when inflating a view from XML. This is called |
| 3232 | * when a view is being constructed from an XML file, supplying attributes |
| 3233 | * that were specified in the XML file. This version uses a default style of |
| 3234 | * 0, so the only attribute values applied are those in the Context's Theme |
| 3235 | * and the given AttributeSet. |
| 3236 | * |
| 3237 | * <p> |
| 3238 | * The method onFinishInflate() will be called after all children have been |
| 3239 | * added. |
| 3240 | * |
| 3241 | * @param context The Context the view is running in, through which it can |
| 3242 | * access the current theme, resources, etc. |
| 3243 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 3244 | * @see #View(Context, AttributeSet, int) |
| 3245 | */ |
| 3246 | public View(Context context, AttributeSet attrs) { |
| 3247 | this(context, attrs, 0); |
| 3248 | } |
| 3249 | |
| 3250 | /** |
| 3251 | * Perform inflation from XML and apply a class-specific base style. This |
| 3252 | * constructor of View allows subclasses to use their own base style when |
| 3253 | * they are inflating. For example, a Button class's constructor would call |
| 3254 | * this version of the super class constructor and supply |
| 3255 | * <code>R.attr.buttonStyle</code> for <var>defStyle</var>; this allows |
| 3256 | * the theme's button style to modify all of the base view attributes (in |
| 3257 | * particular its background) as well as the Button class's attributes. |
| 3258 | * |
| 3259 | * @param context The Context the view is running in, through which it can |
| 3260 | * access the current theme, resources, etc. |
| 3261 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 3262 | * @param defStyle The default style to apply to this view. If 0, no style |
| 3263 | * will be applied (beyond what is included in the theme). This may |
| 3264 | * either be an attribute resource, whose value will be retrieved |
| 3265 | * from the current theme, or an explicit style resource. |
| 3266 | * @see #View(Context, AttributeSet) |
| 3267 | */ |
| 3268 | public View(Context context, AttributeSet attrs, int defStyle) { |
| 3269 | this(context); |
| 3270 | |
| 3271 | TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View, |
| 3272 | defStyle, 0); |
| 3273 | |
| 3274 | Drawable background = null; |
| 3275 | |
| 3276 | int leftPadding = -1; |
| 3277 | int topPadding = -1; |
| 3278 | int rightPadding = -1; |
| 3279 | int bottomPadding = -1; |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3280 | int startPadding = UNDEFINED_PADDING; |
| 3281 | int endPadding = UNDEFINED_PADDING; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3282 | |
| 3283 | int padding = -1; |
| 3284 | |
| 3285 | int viewFlagValues = 0; |
| 3286 | int viewFlagMasks = 0; |
| 3287 | |
| 3288 | boolean setScrollContainer = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3289 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3290 | int x = 0; |
| 3291 | int y = 0; |
| 3292 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3293 | float tx = 0; |
| 3294 | float ty = 0; |
| 3295 | float rotation = 0; |
| 3296 | float rotationX = 0; |
| 3297 | float rotationY = 0; |
| 3298 | float sx = 1f; |
| 3299 | float sy = 1f; |
| 3300 | boolean transformSet = false; |
| 3301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3302 | int scrollbarStyle = SCROLLBARS_INSIDE_OVERLAY; |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3303 | int overScrollMode = mOverScrollMode; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3304 | boolean initializeScrollbars = false; |
| 3305 | |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3306 | boolean leftPaddingDefined = false; |
| 3307 | boolean rightPaddingDefined = false; |
| 3308 | boolean startPaddingDefined = false; |
| 3309 | boolean endPaddingDefined = false; |
| 3310 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3311 | final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion; |
| 3312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3313 | final int N = a.getIndexCount(); |
| 3314 | for (int i = 0; i < N; i++) { |
| 3315 | int attr = a.getIndex(i); |
| 3316 | switch (attr) { |
| 3317 | case com.android.internal.R.styleable.View_background: |
| 3318 | background = a.getDrawable(attr); |
| 3319 | break; |
| 3320 | case com.android.internal.R.styleable.View_padding: |
| 3321 | padding = a.getDimensionPixelSize(attr, -1); |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 3322 | mUserPaddingLeftInitial = padding; |
| 3323 | mUserPaddingRightInitial = padding; |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3324 | leftPaddingDefined = true; |
| 3325 | rightPaddingDefined = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3326 | break; |
| 3327 | case com.android.internal.R.styleable.View_paddingLeft: |
| 3328 | leftPadding = a.getDimensionPixelSize(attr, -1); |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 3329 | mUserPaddingLeftInitial = leftPadding; |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3330 | leftPaddingDefined = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3331 | break; |
| 3332 | case com.android.internal.R.styleable.View_paddingTop: |
| 3333 | topPadding = a.getDimensionPixelSize(attr, -1); |
| 3334 | break; |
| 3335 | case com.android.internal.R.styleable.View_paddingRight: |
| 3336 | rightPadding = a.getDimensionPixelSize(attr, -1); |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 3337 | mUserPaddingRightInitial = rightPadding; |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3338 | rightPaddingDefined = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3339 | break; |
| 3340 | case com.android.internal.R.styleable.View_paddingBottom: |
| 3341 | bottomPadding = a.getDimensionPixelSize(attr, -1); |
| 3342 | break; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3343 | case com.android.internal.R.styleable.View_paddingStart: |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3344 | startPadding = a.getDimensionPixelSize(attr, UNDEFINED_PADDING); |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3345 | startPaddingDefined = true; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3346 | break; |
| 3347 | case com.android.internal.R.styleable.View_paddingEnd: |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3348 | endPadding = a.getDimensionPixelSize(attr, UNDEFINED_PADDING); |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3349 | endPaddingDefined = true; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3350 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3351 | case com.android.internal.R.styleable.View_scrollX: |
| 3352 | x = a.getDimensionPixelOffset(attr, 0); |
| 3353 | break; |
| 3354 | case com.android.internal.R.styleable.View_scrollY: |
| 3355 | y = a.getDimensionPixelOffset(attr, 0); |
| 3356 | break; |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3357 | case com.android.internal.R.styleable.View_alpha: |
| 3358 | setAlpha(a.getFloat(attr, 1f)); |
| 3359 | break; |
| 3360 | case com.android.internal.R.styleable.View_transformPivotX: |
| 3361 | setPivotX(a.getDimensionPixelOffset(attr, 0)); |
| 3362 | break; |
| 3363 | case com.android.internal.R.styleable.View_transformPivotY: |
| 3364 | setPivotY(a.getDimensionPixelOffset(attr, 0)); |
| 3365 | break; |
| 3366 | case com.android.internal.R.styleable.View_translationX: |
| 3367 | tx = a.getDimensionPixelOffset(attr, 0); |
| 3368 | transformSet = true; |
| 3369 | break; |
| 3370 | case com.android.internal.R.styleable.View_translationY: |
| 3371 | ty = a.getDimensionPixelOffset(attr, 0); |
| 3372 | transformSet = true; |
| 3373 | break; |
| 3374 | case com.android.internal.R.styleable.View_rotation: |
| 3375 | rotation = a.getFloat(attr, 0); |
| 3376 | transformSet = true; |
| 3377 | break; |
| 3378 | case com.android.internal.R.styleable.View_rotationX: |
| 3379 | rotationX = a.getFloat(attr, 0); |
| 3380 | transformSet = true; |
| 3381 | break; |
| 3382 | case com.android.internal.R.styleable.View_rotationY: |
| 3383 | rotationY = a.getFloat(attr, 0); |
| 3384 | transformSet = true; |
| 3385 | break; |
| 3386 | case com.android.internal.R.styleable.View_scaleX: |
| 3387 | sx = a.getFloat(attr, 1f); |
| 3388 | transformSet = true; |
| 3389 | break; |
| 3390 | case com.android.internal.R.styleable.View_scaleY: |
| 3391 | sy = a.getFloat(attr, 1f); |
| 3392 | transformSet = true; |
| 3393 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3394 | case com.android.internal.R.styleable.View_id: |
| 3395 | mID = a.getResourceId(attr, NO_ID); |
| 3396 | break; |
| 3397 | case com.android.internal.R.styleable.View_tag: |
| 3398 | mTag = a.getText(attr); |
| 3399 | break; |
| 3400 | case com.android.internal.R.styleable.View_fitsSystemWindows: |
| 3401 | if (a.getBoolean(attr, false)) { |
| 3402 | viewFlagValues |= FITS_SYSTEM_WINDOWS; |
| 3403 | viewFlagMasks |= FITS_SYSTEM_WINDOWS; |
| 3404 | } |
| 3405 | break; |
| 3406 | case com.android.internal.R.styleable.View_focusable: |
| 3407 | if (a.getBoolean(attr, false)) { |
| 3408 | viewFlagValues |= FOCUSABLE; |
| 3409 | viewFlagMasks |= FOCUSABLE_MASK; |
| 3410 | } |
| 3411 | break; |
| 3412 | case com.android.internal.R.styleable.View_focusableInTouchMode: |
| 3413 | if (a.getBoolean(attr, false)) { |
| 3414 | viewFlagValues |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE; |
| 3415 | viewFlagMasks |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE_MASK; |
| 3416 | } |
| 3417 | break; |
| 3418 | case com.android.internal.R.styleable.View_clickable: |
| 3419 | if (a.getBoolean(attr, false)) { |
| 3420 | viewFlagValues |= CLICKABLE; |
| 3421 | viewFlagMasks |= CLICKABLE; |
| 3422 | } |
| 3423 | break; |
| 3424 | case com.android.internal.R.styleable.View_longClickable: |
| 3425 | if (a.getBoolean(attr, false)) { |
| 3426 | viewFlagValues |= LONG_CLICKABLE; |
| 3427 | viewFlagMasks |= LONG_CLICKABLE; |
| 3428 | } |
| 3429 | break; |
| 3430 | case com.android.internal.R.styleable.View_saveEnabled: |
| 3431 | if (!a.getBoolean(attr, true)) { |
| 3432 | viewFlagValues |= SAVE_DISABLED; |
| 3433 | viewFlagMasks |= SAVE_DISABLED_MASK; |
| 3434 | } |
| 3435 | break; |
| 3436 | case com.android.internal.R.styleable.View_duplicateParentState: |
| 3437 | if (a.getBoolean(attr, false)) { |
| 3438 | viewFlagValues |= DUPLICATE_PARENT_STATE; |
| 3439 | viewFlagMasks |= DUPLICATE_PARENT_STATE; |
| 3440 | } |
| 3441 | break; |
| 3442 | case com.android.internal.R.styleable.View_visibility: |
| 3443 | final int visibility = a.getInt(attr, 0); |
| 3444 | if (visibility != 0) { |
| 3445 | viewFlagValues |= VISIBILITY_FLAGS[visibility]; |
| 3446 | viewFlagMasks |= VISIBILITY_MASK; |
| 3447 | } |
| 3448 | break; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 3449 | case com.android.internal.R.styleable.View_layoutDirection: |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3450 | // Clear any layout direction flags (included resolved bits) already set |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 3451 | mPrivateFlags2 &= |
| 3452 | ~(PFLAG2_LAYOUT_DIRECTION_MASK | PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3453 | // 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] | 3454 | final int layoutDirection = a.getInt(attr, -1); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3455 | final int value = (layoutDirection != -1) ? |
| 3456 | LAYOUT_DIRECTION_FLAGS[layoutDirection] : LAYOUT_DIRECTION_DEFAULT; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3457 | mPrivateFlags2 |= (value << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT); |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 3458 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3459 | case com.android.internal.R.styleable.View_drawingCacheQuality: |
| 3460 | final int cacheQuality = a.getInt(attr, 0); |
| 3461 | if (cacheQuality != 0) { |
| 3462 | viewFlagValues |= DRAWING_CACHE_QUALITY_FLAGS[cacheQuality]; |
| 3463 | viewFlagMasks |= DRAWING_CACHE_QUALITY_MASK; |
| 3464 | } |
| 3465 | break; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3466 | case com.android.internal.R.styleable.View_contentDescription: |
Svetoslav Ganov | e47957a | 2012-06-05 14:46:50 -0700 | [diff] [blame] | 3467 | setContentDescription(a.getString(attr)); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3468 | break; |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 3469 | case com.android.internal.R.styleable.View_labelFor: |
| 3470 | setLabelFor(a.getResourceId(attr, NO_ID)); |
| 3471 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3472 | case com.android.internal.R.styleable.View_soundEffectsEnabled: |
| 3473 | if (!a.getBoolean(attr, true)) { |
| 3474 | viewFlagValues &= ~SOUND_EFFECTS_ENABLED; |
| 3475 | viewFlagMasks |= SOUND_EFFECTS_ENABLED; |
| 3476 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3477 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3478 | case com.android.internal.R.styleable.View_hapticFeedbackEnabled: |
| 3479 | if (!a.getBoolean(attr, true)) { |
| 3480 | viewFlagValues &= ~HAPTIC_FEEDBACK_ENABLED; |
| 3481 | viewFlagMasks |= HAPTIC_FEEDBACK_ENABLED; |
| 3482 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3483 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3484 | case R.styleable.View_scrollbars: |
| 3485 | final int scrollbars = a.getInt(attr, SCROLLBARS_NONE); |
| 3486 | if (scrollbars != SCROLLBARS_NONE) { |
| 3487 | viewFlagValues |= scrollbars; |
| 3488 | viewFlagMasks |= SCROLLBARS_MASK; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3489 | initializeScrollbars = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3490 | } |
| 3491 | break; |
Romain Guy | 2a9fa89 | 2011-09-28 16:50:02 -0700 | [diff] [blame] | 3492 | //noinspection deprecation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3493 | case R.styleable.View_fadingEdge: |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3494 | if (targetSdkVersion >= ICE_CREAM_SANDWICH) { |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 3495 | // Ignore the attribute starting with ICS |
| 3496 | break; |
| 3497 | } |
| 3498 | // With builds < ICS, fall through and apply fading edges |
| 3499 | case R.styleable.View_requiresFadingEdge: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3500 | final int fadingEdge = a.getInt(attr, FADING_EDGE_NONE); |
| 3501 | if (fadingEdge != FADING_EDGE_NONE) { |
| 3502 | viewFlagValues |= fadingEdge; |
| 3503 | viewFlagMasks |= FADING_EDGE_MASK; |
| 3504 | initializeFadingEdge(a); |
| 3505 | } |
| 3506 | break; |
| 3507 | case R.styleable.View_scrollbarStyle: |
| 3508 | scrollbarStyle = a.getInt(attr, SCROLLBARS_INSIDE_OVERLAY); |
| 3509 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3510 | viewFlagValues |= scrollbarStyle & SCROLLBARS_STYLE_MASK; |
| 3511 | viewFlagMasks |= SCROLLBARS_STYLE_MASK; |
| 3512 | } |
| 3513 | break; |
| 3514 | case R.styleable.View_isScrollContainer: |
| 3515 | setScrollContainer = true; |
| 3516 | if (a.getBoolean(attr, false)) { |
| 3517 | setScrollContainer(true); |
| 3518 | } |
| 3519 | break; |
| 3520 | case com.android.internal.R.styleable.View_keepScreenOn: |
| 3521 | if (a.getBoolean(attr, false)) { |
| 3522 | viewFlagValues |= KEEP_SCREEN_ON; |
| 3523 | viewFlagMasks |= KEEP_SCREEN_ON; |
| 3524 | } |
| 3525 | break; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 3526 | case R.styleable.View_filterTouchesWhenObscured: |
| 3527 | if (a.getBoolean(attr, false)) { |
| 3528 | viewFlagValues |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3529 | viewFlagMasks |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3530 | } |
| 3531 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3532 | case R.styleable.View_nextFocusLeft: |
| 3533 | mNextFocusLeftId = a.getResourceId(attr, View.NO_ID); |
| 3534 | break; |
| 3535 | case R.styleable.View_nextFocusRight: |
| 3536 | mNextFocusRightId = a.getResourceId(attr, View.NO_ID); |
| 3537 | break; |
| 3538 | case R.styleable.View_nextFocusUp: |
| 3539 | mNextFocusUpId = a.getResourceId(attr, View.NO_ID); |
| 3540 | break; |
| 3541 | case R.styleable.View_nextFocusDown: |
| 3542 | mNextFocusDownId = a.getResourceId(attr, View.NO_ID); |
| 3543 | break; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3544 | case R.styleable.View_nextFocusForward: |
| 3545 | mNextFocusForwardId = a.getResourceId(attr, View.NO_ID); |
| 3546 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3547 | case R.styleable.View_minWidth: |
| 3548 | mMinWidth = a.getDimensionPixelSize(attr, 0); |
| 3549 | break; |
| 3550 | case R.styleable.View_minHeight: |
| 3551 | mMinHeight = a.getDimensionPixelSize(attr, 0); |
| 3552 | break; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3553 | case R.styleable.View_onClick: |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3554 | if (context.isRestricted()) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3555 | throw new IllegalStateException("The android:onClick attribute cannot " |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3556 | + "be used within a restricted context"); |
| 3557 | } |
| 3558 | |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3559 | final String handlerName = a.getString(attr); |
| 3560 | if (handlerName != null) { |
| 3561 | setOnClickListener(new OnClickListener() { |
| 3562 | private Method mHandler; |
| 3563 | |
| 3564 | public void onClick(View v) { |
| 3565 | if (mHandler == null) { |
| 3566 | try { |
| 3567 | mHandler = getContext().getClass().getMethod(handlerName, |
| 3568 | View.class); |
| 3569 | } catch (NoSuchMethodException e) { |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3570 | int id = getId(); |
| 3571 | String idText = id == NO_ID ? "" : " with id '" |
| 3572 | + getContext().getResources().getResourceEntryName( |
| 3573 | id) + "'"; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3574 | throw new IllegalStateException("Could not find a method " + |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3575 | handlerName + "(View) in the activity " |
| 3576 | + getContext().getClass() + " for onClick handler" |
| 3577 | + " on view " + View.this.getClass() + idText, e); |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3578 | } |
| 3579 | } |
| 3580 | |
| 3581 | try { |
| 3582 | mHandler.invoke(getContext(), View.this); |
| 3583 | } catch (IllegalAccessException e) { |
| 3584 | throw new IllegalStateException("Could not execute non " |
| 3585 | + "public method of the activity", e); |
| 3586 | } catch (InvocationTargetException e) { |
| 3587 | throw new IllegalStateException("Could not execute " |
| 3588 | + "method of the activity", e); |
| 3589 | } |
| 3590 | } |
| 3591 | }); |
| 3592 | } |
| 3593 | break; |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3594 | case R.styleable.View_overScrollMode: |
| 3595 | overScrollMode = a.getInt(attr, OVER_SCROLL_IF_CONTENT_SCROLLS); |
| 3596 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3597 | case R.styleable.View_verticalScrollbarPosition: |
| 3598 | mVerticalScrollbarPosition = a.getInt(attr, SCROLLBAR_POSITION_DEFAULT); |
| 3599 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3600 | case R.styleable.View_layerType: |
| 3601 | setLayerType(a.getInt(attr, LAYER_TYPE_NONE), null); |
| 3602 | break; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3603 | case R.styleable.View_textDirection: |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3604 | // Clear any text direction flag already set |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3605 | mPrivateFlags2 &= ~PFLAG2_TEXT_DIRECTION_MASK; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3606 | // Set the text direction flags depending on the value of the attribute |
| 3607 | final int textDirection = a.getInt(attr, -1); |
| 3608 | if (textDirection != -1) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3609 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_FLAGS[textDirection]; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3610 | } |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3611 | break; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3612 | case R.styleable.View_textAlignment: |
| 3613 | // Clear any text alignment flag already set |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3614 | mPrivateFlags2 &= ~PFLAG2_TEXT_ALIGNMENT_MASK; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3615 | // Set the text alignment flag depending on the value of the attribute |
| 3616 | final int textAlignment = a.getInt(attr, TEXT_ALIGNMENT_DEFAULT); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3617 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_FLAGS[textAlignment]; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3618 | break; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3619 | case R.styleable.View_importantForAccessibility: |
| 3620 | setImportantForAccessibility(a.getInt(attr, |
| 3621 | IMPORTANT_FOR_ACCESSIBILITY_DEFAULT)); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 3622 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3623 | } |
| 3624 | } |
| 3625 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3626 | setOverScrollMode(overScrollMode); |
| 3627 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3628 | // Cache start/end user padding as we cannot fully resolve padding here (we dont have yet |
| 3629 | // the resolved layout direction). Those cached values will be used later during padding |
| 3630 | // resolution. |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 3631 | mUserPaddingStart = startPadding; |
| 3632 | mUserPaddingEnd = endPadding; |
| 3633 | |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3634 | if (background != null) { |
| 3635 | setBackground(background); |
| 3636 | } |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 3637 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3638 | if (padding >= 0) { |
| 3639 | leftPadding = padding; |
| 3640 | topPadding = padding; |
| 3641 | rightPadding = padding; |
| 3642 | bottomPadding = padding; |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 3643 | mUserPaddingLeftInitial = padding; |
| 3644 | mUserPaddingRightInitial = padding; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3645 | } |
| 3646 | |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3647 | if (isRtlCompatibilityMode()) { |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 3648 | // RTL compatibility mode: pre Jelly Bean MR1 case OR no RTL support case. |
| 3649 | // left / right padding are used if defined (meaning here nothing to do). If they are not |
| 3650 | // defined and start / end padding are defined (e.g. in Frameworks resources), then we use |
| 3651 | // start / end and resolve them as left / right (layout direction is not taken into account). |
| 3652 | // Padding from the background drawable is stored at this point in mUserPaddingLeftInitial |
| 3653 | // and mUserPaddingRightInitial) so drawable padding will be used as ultimate default if |
| 3654 | // defined. |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3655 | if (!leftPaddingDefined && startPaddingDefined) { |
| 3656 | leftPadding = startPadding; |
| 3657 | } |
Fabrice Di Meglio | 6e6d781 | 2012-10-01 15:32:01 -0700 | [diff] [blame] | 3658 | mUserPaddingLeftInitial = (leftPadding >= 0) ? leftPadding : mUserPaddingLeftInitial; |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3659 | if (!rightPaddingDefined && endPaddingDefined) { |
| 3660 | rightPadding = endPadding; |
| 3661 | } |
Fabrice Di Meglio | 6e6d781 | 2012-10-01 15:32:01 -0700 | [diff] [blame] | 3662 | mUserPaddingRightInitial = (rightPadding >= 0) ? rightPadding : mUserPaddingRightInitial; |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 3663 | } else { |
| 3664 | // Jelly Bean MR1 and after case: if start/end defined, they will override any left/right |
| 3665 | // values defined. Otherwise, left /right values are used. |
| 3666 | // Padding from the background drawable is stored at this point in mUserPaddingLeftInitial |
| 3667 | // and mUserPaddingRightInitial) so drawable padding will be used as ultimate default if |
| 3668 | // defined. |
| 3669 | if (startPaddingDefined) { |
| 3670 | mUserPaddingLeftInitial = startPadding; |
| 3671 | } else if (leftPaddingDefined) { |
| 3672 | mUserPaddingLeftInitial = leftPadding; |
| 3673 | } |
| 3674 | if (endPaddingDefined) { |
| 3675 | mUserPaddingRightInitial = endPadding; |
| 3676 | } |
| 3677 | else if (rightPaddingDefined) { |
| 3678 | mUserPaddingRightInitial = rightPadding; |
| 3679 | } |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3680 | } |
| 3681 | |
Fabrice Di Meglio | 3e27c34 | 2012-09-20 17:56:58 -0700 | [diff] [blame] | 3682 | internalSetPadding( |
Fabrice Di Meglio | 75aefb8 | 2012-09-27 19:55:18 -0700 | [diff] [blame] | 3683 | mUserPaddingLeftInitial, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3684 | topPadding >= 0 ? topPadding : mPaddingTop, |
Fabrice Di Meglio | 75aefb8 | 2012-09-27 19:55:18 -0700 | [diff] [blame] | 3685 | mUserPaddingRightInitial, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3686 | bottomPadding >= 0 ? bottomPadding : mPaddingBottom); |
| 3687 | |
| 3688 | if (viewFlagMasks != 0) { |
| 3689 | setFlags(viewFlagValues, viewFlagMasks); |
| 3690 | } |
| 3691 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3692 | if (initializeScrollbars) { |
| 3693 | initializeScrollbars(a); |
| 3694 | } |
| 3695 | |
| 3696 | a.recycle(); |
| 3697 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3698 | // Needs to be called after mViewFlags is set |
| 3699 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3700 | recomputePadding(); |
| 3701 | } |
| 3702 | |
| 3703 | if (x != 0 || y != 0) { |
| 3704 | scrollTo(x, y); |
| 3705 | } |
| 3706 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3707 | if (transformSet) { |
| 3708 | setTranslationX(tx); |
| 3709 | setTranslationY(ty); |
| 3710 | setRotation(rotation); |
| 3711 | setRotationX(rotationX); |
| 3712 | setRotationY(rotationY); |
| 3713 | setScaleX(sx); |
| 3714 | setScaleY(sy); |
| 3715 | } |
| 3716 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3717 | if (!setScrollContainer && (viewFlagValues&SCROLLBARS_VERTICAL) != 0) { |
| 3718 | setScrollContainer(true); |
| 3719 | } |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 3720 | |
| 3721 | computeOpaqueFlags(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | /** |
| 3725 | * Non-public constructor for use in testing |
| 3726 | */ |
| 3727 | View() { |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 3728 | mResources = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3729 | } |
| 3730 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3731 | public String toString() { |
| 3732 | StringBuilder out = new StringBuilder(128); |
| 3733 | out.append(getClass().getName()); |
| 3734 | out.append('{'); |
| 3735 | out.append(Integer.toHexString(System.identityHashCode(this))); |
| 3736 | out.append(' '); |
| 3737 | switch (mViewFlags&VISIBILITY_MASK) { |
| 3738 | case VISIBLE: out.append('V'); break; |
| 3739 | case INVISIBLE: out.append('I'); break; |
| 3740 | case GONE: out.append('G'); break; |
| 3741 | default: out.append('.'); break; |
| 3742 | } |
| 3743 | out.append((mViewFlags&FOCUSABLE_MASK) == FOCUSABLE ? 'F' : '.'); |
| 3744 | out.append((mViewFlags&ENABLED_MASK) == ENABLED ? 'E' : '.'); |
| 3745 | out.append((mViewFlags&DRAW_MASK) == WILL_NOT_DRAW ? '.' : 'D'); |
| 3746 | out.append((mViewFlags&SCROLLBARS_HORIZONTAL) != 0 ? 'H' : '.'); |
| 3747 | out.append((mViewFlags&SCROLLBARS_VERTICAL) != 0 ? 'V' : '.'); |
| 3748 | out.append((mViewFlags&CLICKABLE) != 0 ? 'C' : '.'); |
| 3749 | out.append((mViewFlags&LONG_CLICKABLE) != 0 ? 'L' : '.'); |
| 3750 | out.append(' '); |
| 3751 | out.append((mPrivateFlags&PFLAG_IS_ROOT_NAMESPACE) != 0 ? 'R' : '.'); |
| 3752 | out.append((mPrivateFlags&PFLAG_FOCUSED) != 0 ? 'F' : '.'); |
| 3753 | out.append((mPrivateFlags&PFLAG_SELECTED) != 0 ? 'S' : '.'); |
| 3754 | if ((mPrivateFlags&PFLAG_PREPRESSED) != 0) { |
| 3755 | out.append('p'); |
| 3756 | } else { |
| 3757 | out.append((mPrivateFlags&PFLAG_PRESSED) != 0 ? 'P' : '.'); |
| 3758 | } |
| 3759 | out.append((mPrivateFlags&PFLAG_HOVERED) != 0 ? 'H' : '.'); |
| 3760 | out.append((mPrivateFlags&PFLAG_ACTIVATED) != 0 ? 'A' : '.'); |
| 3761 | out.append((mPrivateFlags&PFLAG_INVALIDATED) != 0 ? 'I' : '.'); |
| 3762 | out.append((mPrivateFlags&PFLAG_DIRTY_MASK) != 0 ? 'D' : '.'); |
| 3763 | out.append(' '); |
| 3764 | out.append(mLeft); |
| 3765 | out.append(','); |
| 3766 | out.append(mTop); |
| 3767 | out.append('-'); |
| 3768 | out.append(mRight); |
| 3769 | out.append(','); |
| 3770 | out.append(mBottom); |
| 3771 | final int id = getId(); |
| 3772 | if (id != NO_ID) { |
| 3773 | out.append(" #"); |
| 3774 | out.append(Integer.toHexString(id)); |
| 3775 | final Resources r = mResources; |
| 3776 | if (id != 0 && r != null) { |
| 3777 | try { |
| 3778 | String pkgname; |
| 3779 | switch (id&0xff000000) { |
| 3780 | case 0x7f000000: |
| 3781 | pkgname="app"; |
| 3782 | break; |
| 3783 | case 0x01000000: |
| 3784 | pkgname="android"; |
| 3785 | break; |
| 3786 | default: |
| 3787 | pkgname = r.getResourcePackageName(id); |
| 3788 | break; |
| 3789 | } |
| 3790 | String typename = r.getResourceTypeName(id); |
| 3791 | String entryname = r.getResourceEntryName(id); |
| 3792 | out.append(" "); |
| 3793 | out.append(pkgname); |
| 3794 | out.append(":"); |
| 3795 | out.append(typename); |
| 3796 | out.append("/"); |
| 3797 | out.append(entryname); |
| 3798 | } catch (Resources.NotFoundException e) { |
| 3799 | } |
| 3800 | } |
| 3801 | } |
| 3802 | out.append("}"); |
| 3803 | return out.toString(); |
| 3804 | } |
| 3805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3806 | /** |
| 3807 | * <p> |
| 3808 | * Initializes the fading edges from a given set of styled attributes. This |
| 3809 | * method should be called by subclasses that need fading edges and when an |
| 3810 | * instance of these subclasses is created programmatically rather than |
| 3811 | * being inflated from XML. This method is automatically called when the XML |
| 3812 | * is inflated. |
| 3813 | * </p> |
| 3814 | * |
| 3815 | * @param a the styled attributes set to initialize the fading edges from |
| 3816 | */ |
| 3817 | protected void initializeFadingEdge(TypedArray a) { |
| 3818 | initScrollCache(); |
| 3819 | |
| 3820 | mScrollCache.fadingEdgeLength = a.getDimensionPixelSize( |
| 3821 | R.styleable.View_fadingEdgeLength, |
| 3822 | ViewConfiguration.get(mContext).getScaledFadingEdgeLength()); |
| 3823 | } |
| 3824 | |
| 3825 | /** |
| 3826 | * Returns the size of the vertical faded edges used to indicate that more |
| 3827 | * content in this view is visible. |
| 3828 | * |
| 3829 | * @return The size in pixels of the vertical faded edge or 0 if vertical |
| 3830 | * faded edges are not enabled for this view. |
| 3831 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3832 | */ |
| 3833 | public int getVerticalFadingEdgeLength() { |
| 3834 | if (isVerticalFadingEdgeEnabled()) { |
| 3835 | ScrollabilityCache cache = mScrollCache; |
| 3836 | if (cache != null) { |
| 3837 | return cache.fadingEdgeLength; |
| 3838 | } |
| 3839 | } |
| 3840 | return 0; |
| 3841 | } |
| 3842 | |
| 3843 | /** |
| 3844 | * Set the size of the faded edge used to indicate that more content in this |
| 3845 | * 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] | 3846 | * {@link #setVerticalFadingEdgeEnabled(boolean)} or |
| 3847 | * {@link #setHorizontalFadingEdgeEnabled(boolean)} to enable the fading edge |
| 3848 | * for the vertical or horizontal fading edges. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3849 | * |
| 3850 | * @param length The size in pixels of the faded edge used to indicate that more |
| 3851 | * content in this view is visible. |
| 3852 | */ |
| 3853 | public void setFadingEdgeLength(int length) { |
| 3854 | initScrollCache(); |
| 3855 | mScrollCache.fadingEdgeLength = length; |
| 3856 | } |
| 3857 | |
| 3858 | /** |
| 3859 | * Returns the size of the horizontal faded edges used to indicate that more |
| 3860 | * content in this view is visible. |
| 3861 | * |
| 3862 | * @return The size in pixels of the horizontal faded edge or 0 if horizontal |
| 3863 | * faded edges are not enabled for this view. |
| 3864 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3865 | */ |
| 3866 | public int getHorizontalFadingEdgeLength() { |
| 3867 | if (isHorizontalFadingEdgeEnabled()) { |
| 3868 | ScrollabilityCache cache = mScrollCache; |
| 3869 | if (cache != null) { |
| 3870 | return cache.fadingEdgeLength; |
| 3871 | } |
| 3872 | } |
| 3873 | return 0; |
| 3874 | } |
| 3875 | |
| 3876 | /** |
| 3877 | * Returns the width of the vertical scrollbar. |
| 3878 | * |
| 3879 | * @return The width in pixels of the vertical scrollbar or 0 if there |
| 3880 | * is no vertical scrollbar. |
| 3881 | */ |
| 3882 | public int getVerticalScrollbarWidth() { |
| 3883 | ScrollabilityCache cache = mScrollCache; |
| 3884 | if (cache != null) { |
| 3885 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3886 | if (scrollBar != null) { |
| 3887 | int size = scrollBar.getSize(true); |
| 3888 | if (size <= 0) { |
| 3889 | size = cache.scrollBarSize; |
| 3890 | } |
| 3891 | return size; |
| 3892 | } |
| 3893 | return 0; |
| 3894 | } |
| 3895 | return 0; |
| 3896 | } |
| 3897 | |
| 3898 | /** |
| 3899 | * Returns the height of the horizontal scrollbar. |
| 3900 | * |
| 3901 | * @return The height in pixels of the horizontal scrollbar or 0 if |
| 3902 | * there is no horizontal scrollbar. |
| 3903 | */ |
| 3904 | protected int getHorizontalScrollbarHeight() { |
| 3905 | ScrollabilityCache cache = mScrollCache; |
| 3906 | if (cache != null) { |
| 3907 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3908 | if (scrollBar != null) { |
| 3909 | int size = scrollBar.getSize(false); |
| 3910 | if (size <= 0) { |
| 3911 | size = cache.scrollBarSize; |
| 3912 | } |
| 3913 | return size; |
| 3914 | } |
| 3915 | return 0; |
| 3916 | } |
| 3917 | return 0; |
| 3918 | } |
| 3919 | |
| 3920 | /** |
| 3921 | * <p> |
| 3922 | * Initializes the scrollbars from a given set of styled attributes. This |
| 3923 | * method should be called by subclasses that need scrollbars and when an |
| 3924 | * instance of these subclasses is created programmatically rather than |
| 3925 | * being inflated from XML. This method is automatically called when the XML |
| 3926 | * is inflated. |
| 3927 | * </p> |
| 3928 | * |
| 3929 | * @param a the styled attributes set to initialize the scrollbars from |
| 3930 | */ |
| 3931 | protected void initializeScrollbars(TypedArray a) { |
| 3932 | initScrollCache(); |
| 3933 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3934 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3935 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3936 | if (scrollabilityCache.scrollBar == null) { |
| 3937 | scrollabilityCache.scrollBar = new ScrollBarDrawable(); |
| 3938 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3939 | |
Romain Guy | 8bda248 | 2010-03-02 11:42:11 -0800 | [diff] [blame] | 3940 | 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] | 3941 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3942 | if (!fadeScrollbars) { |
| 3943 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 3944 | } |
| 3945 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3946 | |
| 3947 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3948 | scrollabilityCache.scrollBarFadeDuration = a.getInt( |
| 3949 | R.styleable.View_scrollbarFadeDuration, ViewConfiguration |
| 3950 | .getScrollBarFadeDuration()); |
| 3951 | scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt( |
| 3952 | R.styleable.View_scrollbarDefaultDelayBeforeFade, |
| 3953 | ViewConfiguration.getScrollDefaultDelay()); |
| 3954 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3955 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3956 | scrollabilityCache.scrollBarSize = a.getDimensionPixelSize( |
| 3957 | com.android.internal.R.styleable.View_scrollbarSize, |
| 3958 | ViewConfiguration.get(mContext).getScaledScrollBarSize()); |
| 3959 | |
| 3960 | Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal); |
| 3961 | scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track); |
| 3962 | |
| 3963 | Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal); |
| 3964 | if (thumb != null) { |
| 3965 | scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb); |
| 3966 | } |
| 3967 | |
| 3968 | boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack, |
| 3969 | false); |
| 3970 | if (alwaysDraw) { |
| 3971 | scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true); |
| 3972 | } |
| 3973 | |
| 3974 | track = a.getDrawable(R.styleable.View_scrollbarTrackVertical); |
| 3975 | scrollabilityCache.scrollBar.setVerticalTrackDrawable(track); |
| 3976 | |
| 3977 | thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical); |
| 3978 | if (thumb != null) { |
| 3979 | scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb); |
| 3980 | } |
| 3981 | |
| 3982 | alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack, |
| 3983 | false); |
| 3984 | if (alwaysDraw) { |
| 3985 | scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true); |
| 3986 | } |
| 3987 | |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 3988 | // Apply layout direction to the new Drawables if needed |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 3989 | final int layoutDirection = getLayoutDirection(); |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 3990 | if (track != null) { |
| 3991 | track.setLayoutDirection(layoutDirection); |
| 3992 | } |
| 3993 | if (thumb != null) { |
| 3994 | thumb.setLayoutDirection(layoutDirection); |
| 3995 | } |
| 3996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3997 | // Re-apply user/background padding so that scrollbar(s) get added |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3998 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3999 | } |
| 4000 | |
| 4001 | /** |
| 4002 | * <p> |
| 4003 | * Initalizes the scrollability cache if necessary. |
| 4004 | * </p> |
| 4005 | */ |
| 4006 | private void initScrollCache() { |
| 4007 | if (mScrollCache == null) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 4008 | mScrollCache = new ScrollabilityCache(ViewConfiguration.get(mContext), this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4009 | } |
| 4010 | } |
| 4011 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 4012 | private ScrollabilityCache getScrollCache() { |
| 4013 | initScrollCache(); |
| 4014 | return mScrollCache; |
| 4015 | } |
| 4016 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4017 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 4018 | * Set the position of the vertical scroll bar. Should be one of |
| 4019 | * {@link #SCROLLBAR_POSITION_DEFAULT}, {@link #SCROLLBAR_POSITION_LEFT} or |
| 4020 | * {@link #SCROLLBAR_POSITION_RIGHT}. |
| 4021 | * |
| 4022 | * @param position Where the vertical scroll bar should be positioned. |
| 4023 | */ |
| 4024 | public void setVerticalScrollbarPosition(int position) { |
| 4025 | if (mVerticalScrollbarPosition != position) { |
| 4026 | mVerticalScrollbarPosition = position; |
| 4027 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 4028 | resolvePadding(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 4029 | } |
| 4030 | } |
| 4031 | |
| 4032 | /** |
| 4033 | * @return The position where the vertical scroll bar will show, if applicable. |
| 4034 | * @see #setVerticalScrollbarPosition(int) |
| 4035 | */ |
| 4036 | public int getVerticalScrollbarPosition() { |
| 4037 | return mVerticalScrollbarPosition; |
| 4038 | } |
| 4039 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4040 | ListenerInfo getListenerInfo() { |
| 4041 | if (mListenerInfo != null) { |
| 4042 | return mListenerInfo; |
| 4043 | } |
| 4044 | mListenerInfo = new ListenerInfo(); |
| 4045 | return mListenerInfo; |
| 4046 | } |
| 4047 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 4048 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4049 | * Register a callback to be invoked when focus of this view changed. |
| 4050 | * |
| 4051 | * @param l The callback that will run. |
| 4052 | */ |
| 4053 | public void setOnFocusChangeListener(OnFocusChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4054 | getListenerInfo().mOnFocusChangeListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4055 | } |
| 4056 | |
| 4057 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4058 | * Add a listener that will be called when the bounds of the view change due to |
| 4059 | * layout processing. |
| 4060 | * |
| 4061 | * @param listener The listener that will be called when layout bounds change. |
| 4062 | */ |
| 4063 | public void addOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4064 | ListenerInfo li = getListenerInfo(); |
| 4065 | if (li.mOnLayoutChangeListeners == null) { |
| 4066 | li.mOnLayoutChangeListeners = new ArrayList<OnLayoutChangeListener>(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4067 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4068 | if (!li.mOnLayoutChangeListeners.contains(listener)) { |
| 4069 | li.mOnLayoutChangeListeners.add(listener); |
Chet Haase | 1a76dcd | 2011-10-06 11:16:40 -0700 | [diff] [blame] | 4070 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4071 | } |
| 4072 | |
| 4073 | /** |
| 4074 | * Remove a listener for layout changes. |
| 4075 | * |
| 4076 | * @param listener The listener for layout bounds change. |
| 4077 | */ |
| 4078 | public void removeOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4079 | ListenerInfo li = mListenerInfo; |
| 4080 | if (li == null || li.mOnLayoutChangeListeners == null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4081 | return; |
| 4082 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4083 | li.mOnLayoutChangeListeners.remove(listener); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | /** |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4087 | * Add a listener for attach state changes. |
| 4088 | * |
| 4089 | * This listener will be called whenever this view is attached or detached |
| 4090 | * from a window. Remove the listener using |
| 4091 | * {@link #removeOnAttachStateChangeListener(OnAttachStateChangeListener)}. |
| 4092 | * |
| 4093 | * @param listener Listener to attach |
| 4094 | * @see #removeOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 4095 | */ |
| 4096 | public void addOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4097 | ListenerInfo li = getListenerInfo(); |
| 4098 | if (li.mOnAttachStateChangeListeners == null) { |
| 4099 | li.mOnAttachStateChangeListeners |
| 4100 | = new CopyOnWriteArrayList<OnAttachStateChangeListener>(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4101 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4102 | li.mOnAttachStateChangeListeners.add(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4103 | } |
| 4104 | |
| 4105 | /** |
| 4106 | * Remove a listener for attach state changes. The listener will receive no further |
| 4107 | * notification of window attach/detach events. |
| 4108 | * |
| 4109 | * @param listener Listener to remove |
| 4110 | * @see #addOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 4111 | */ |
| 4112 | public void removeOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4113 | ListenerInfo li = mListenerInfo; |
| 4114 | if (li == null || li.mOnAttachStateChangeListeners == null) { |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4115 | return; |
| 4116 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4117 | li.mOnAttachStateChangeListeners.remove(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4118 | } |
| 4119 | |
| 4120 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4121 | * Returns the focus-change callback registered for this view. |
| 4122 | * |
| 4123 | * @return The callback, or null if one is not registered. |
| 4124 | */ |
| 4125 | public OnFocusChangeListener getOnFocusChangeListener() { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4126 | ListenerInfo li = mListenerInfo; |
| 4127 | return li != null ? li.mOnFocusChangeListener : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4128 | } |
| 4129 | |
| 4130 | /** |
| 4131 | * Register a callback to be invoked when this view is clicked. If this view is not |
| 4132 | * clickable, it becomes clickable. |
| 4133 | * |
| 4134 | * @param l The callback that will run |
| 4135 | * |
| 4136 | * @see #setClickable(boolean) |
| 4137 | */ |
| 4138 | public void setOnClickListener(OnClickListener l) { |
| 4139 | if (!isClickable()) { |
| 4140 | setClickable(true); |
| 4141 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4142 | getListenerInfo().mOnClickListener = l; |
| 4143 | } |
| 4144 | |
| 4145 | /** |
| 4146 | * Return whether this view has an attached OnClickListener. Returns |
| 4147 | * true if there is a listener, false if there is none. |
| 4148 | */ |
| 4149 | public boolean hasOnClickListeners() { |
| 4150 | ListenerInfo li = mListenerInfo; |
| 4151 | return (li != null && li.mOnClickListener != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4152 | } |
| 4153 | |
| 4154 | /** |
| 4155 | * Register a callback to be invoked when this view is clicked and held. If this view is not |
| 4156 | * long clickable, it becomes long clickable. |
| 4157 | * |
| 4158 | * @param l The callback that will run |
| 4159 | * |
| 4160 | * @see #setLongClickable(boolean) |
| 4161 | */ |
| 4162 | public void setOnLongClickListener(OnLongClickListener l) { |
| 4163 | if (!isLongClickable()) { |
| 4164 | setLongClickable(true); |
| 4165 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4166 | getListenerInfo().mOnLongClickListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | /** |
| 4170 | * Register a callback to be invoked when the context menu for this view is |
| 4171 | * being built. If this view is not long clickable, it becomes long clickable. |
| 4172 | * |
| 4173 | * @param l The callback that will run |
| 4174 | * |
| 4175 | */ |
| 4176 | public void setOnCreateContextMenuListener(OnCreateContextMenuListener l) { |
| 4177 | if (!isLongClickable()) { |
| 4178 | setLongClickable(true); |
| 4179 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4180 | getListenerInfo().mOnCreateContextMenuListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4184 | * Call this view's OnClickListener, if it is defined. Performs all normal |
| 4185 | * actions associated with clicking: reporting accessibility event, playing |
| 4186 | * a sound, etc. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4187 | * |
| 4188 | * @return True there was an assigned OnClickListener that was called, false |
| 4189 | * otherwise is returned. |
| 4190 | */ |
| 4191 | public boolean performClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4192 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); |
| 4193 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4194 | ListenerInfo li = mListenerInfo; |
| 4195 | if (li != null && li.mOnClickListener != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4196 | playSoundEffect(SoundEffectConstants.CLICK); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4197 | li.mOnClickListener.onClick(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4198 | return true; |
| 4199 | } |
| 4200 | |
| 4201 | return false; |
| 4202 | } |
| 4203 | |
| 4204 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4205 | * Directly call any attached OnClickListener. Unlike {@link #performClick()}, |
| 4206 | * this only calls the listener, and does not do any associated clicking |
| 4207 | * actions like reporting an accessibility event. |
| 4208 | * |
| 4209 | * @return True there was an assigned OnClickListener that was called, false |
| 4210 | * otherwise is returned. |
| 4211 | */ |
| 4212 | public boolean callOnClick() { |
| 4213 | ListenerInfo li = mListenerInfo; |
| 4214 | if (li != null && li.mOnClickListener != null) { |
| 4215 | li.mOnClickListener.onClick(this); |
| 4216 | return true; |
| 4217 | } |
| 4218 | return false; |
| 4219 | } |
| 4220 | |
| 4221 | /** |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 4222 | * Call this view's OnLongClickListener, if it is defined. Invokes the context menu if the |
| 4223 | * OnLongClickListener did not consume the event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4224 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 4225 | * @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] | 4226 | */ |
| 4227 | public boolean performLongClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4228 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 4229 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4230 | boolean handled = false; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4231 | ListenerInfo li = mListenerInfo; |
| 4232 | if (li != null && li.mOnLongClickListener != null) { |
| 4233 | handled = li.mOnLongClickListener.onLongClick(View.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4234 | } |
| 4235 | if (!handled) { |
| 4236 | handled = showContextMenu(); |
| 4237 | } |
| 4238 | if (handled) { |
| 4239 | performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); |
| 4240 | } |
| 4241 | return handled; |
| 4242 | } |
| 4243 | |
| 4244 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4245 | * Performs button-related actions during a touch down event. |
| 4246 | * |
| 4247 | * @param event The event. |
| 4248 | * @return True if the down was consumed. |
| 4249 | * |
| 4250 | * @hide |
| 4251 | */ |
| 4252 | protected boolean performButtonActionOnTouchDown(MotionEvent event) { |
| 4253 | if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) { |
| 4254 | if (showContextMenu(event.getX(), event.getY(), event.getMetaState())) { |
| 4255 | return true; |
| 4256 | } |
| 4257 | } |
| 4258 | return false; |
| 4259 | } |
| 4260 | |
| 4261 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4262 | * Bring up the context menu for this view. |
| 4263 | * |
| 4264 | * @return Whether a context menu was displayed. |
| 4265 | */ |
| 4266 | public boolean showContextMenu() { |
| 4267 | return getParent().showContextMenuForChild(this); |
| 4268 | } |
| 4269 | |
| 4270 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4271 | * Bring up the context menu for this view, referring to the item under the specified point. |
| 4272 | * |
| 4273 | * @param x The referenced x coordinate. |
| 4274 | * @param y The referenced y coordinate. |
| 4275 | * @param metaState The keyboard modifiers that were pressed. |
| 4276 | * @return Whether a context menu was displayed. |
| 4277 | * |
| 4278 | * @hide |
| 4279 | */ |
| 4280 | public boolean showContextMenu(float x, float y, int metaState) { |
| 4281 | return showContextMenu(); |
| 4282 | } |
| 4283 | |
| 4284 | /** |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 4285 | * Start an action mode. |
| 4286 | * |
| 4287 | * @param callback Callback that will control the lifecycle of the action mode |
| 4288 | * @return The new action mode if it is started, null otherwise |
| 4289 | * |
| 4290 | * @see ActionMode |
| 4291 | */ |
| 4292 | public ActionMode startActionMode(ActionMode.Callback callback) { |
John Reck | 5160e2a | 2012-02-22 09:35:12 -0800 | [diff] [blame] | 4293 | ViewParent parent = getParent(); |
| 4294 | if (parent == null) return null; |
| 4295 | return parent.startActionModeForChild(this, callback); |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 4296 | } |
| 4297 | |
| 4298 | /** |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 4299 | * Register a callback to be invoked when a hardware key is pressed in this view. |
| 4300 | * Key presses in software input methods will generally not trigger the methods of |
| 4301 | * this listener. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4302 | * @param l the key listener to attach to this view |
| 4303 | */ |
| 4304 | public void setOnKeyListener(OnKeyListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4305 | getListenerInfo().mOnKeyListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4306 | } |
| 4307 | |
| 4308 | /** |
| 4309 | * Register a callback to be invoked when a touch event is sent to this view. |
| 4310 | * @param l the touch listener to attach to this view |
| 4311 | */ |
| 4312 | public void setOnTouchListener(OnTouchListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4313 | getListenerInfo().mOnTouchListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4314 | } |
| 4315 | |
| 4316 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 4317 | * Register a callback to be invoked when a generic motion event is sent to this view. |
| 4318 | * @param l the generic motion listener to attach to this view |
| 4319 | */ |
| 4320 | public void setOnGenericMotionListener(OnGenericMotionListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4321 | getListenerInfo().mOnGenericMotionListener = l; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 4322 | } |
| 4323 | |
| 4324 | /** |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 4325 | * Register a callback to be invoked when a hover event is sent to this view. |
| 4326 | * @param l the hover listener to attach to this view |
| 4327 | */ |
| 4328 | public void setOnHoverListener(OnHoverListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4329 | getListenerInfo().mOnHoverListener = l; |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 4330 | } |
| 4331 | |
| 4332 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 4333 | * Register a drag event listener callback object for this View. The parameter is |
| 4334 | * an implementation of {@link android.view.View.OnDragListener}. To send a drag event to a |
| 4335 | * View, the system calls the |
| 4336 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent)} method. |
| 4337 | * @param l An implementation of {@link android.view.View.OnDragListener}. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 4338 | */ |
| 4339 | public void setOnDragListener(OnDragListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4340 | getListenerInfo().mOnDragListener = l; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 4344 | * Give this view focus. This will cause |
| 4345 | * {@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] | 4346 | * |
| 4347 | * Note: this does not check whether this {@link View} should get focus, it just |
| 4348 | * gives it focus no matter what. It should only be called internally by framework |
| 4349 | * code that knows what it is doing, namely {@link #requestFocus(int, Rect)}. |
| 4350 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 4351 | * @param direction values are {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN}, |
| 4352 | * {@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] | 4353 | * focus moved when requestFocus() is called. It may not always |
| 4354 | * apply, in which case use the default View.FOCUS_DOWN. |
| 4355 | * @param previouslyFocusedRect The rectangle of the view that had focus |
| 4356 | * prior in this View's coordinate system. |
| 4357 | */ |
| 4358 | void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) { |
| 4359 | if (DBG) { |
| 4360 | System.out.println(this + " requestFocus()"); |
| 4361 | } |
| 4362 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4363 | if ((mPrivateFlags & PFLAG_FOCUSED) == 0) { |
| 4364 | mPrivateFlags |= PFLAG_FOCUSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4365 | |
| 4366 | if (mParent != null) { |
| 4367 | mParent.requestChildFocus(this, this); |
| 4368 | } |
| 4369 | |
| 4370 | onFocusChanged(true, direction, previouslyFocusedRect); |
| 4371 | refreshDrawableState(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4372 | |
| 4373 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4374 | notifyAccessibilityStateChanged(); |
| 4375 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4376 | } |
| 4377 | } |
| 4378 | |
| 4379 | /** |
| 4380 | * Request that a rectangle of this view be visible on the screen, |
| 4381 | * scrolling if necessary just enough. |
| 4382 | * |
| 4383 | * <p>A View should call this if it maintains some notion of which part |
| 4384 | * of its content is interesting. For example, a text editing view |
| 4385 | * should call this when its cursor moves. |
| 4386 | * |
| 4387 | * @param rectangle The rectangle. |
| 4388 | * @return Whether any parent scrolled. |
| 4389 | */ |
| 4390 | public boolean requestRectangleOnScreen(Rect rectangle) { |
| 4391 | return requestRectangleOnScreen(rectangle, false); |
| 4392 | } |
| 4393 | |
| 4394 | /** |
| 4395 | * Request that a rectangle of this view be visible on the screen, |
| 4396 | * scrolling if necessary just enough. |
| 4397 | * |
| 4398 | * <p>A View should call this if it maintains some notion of which part |
| 4399 | * of its content is interesting. For example, a text editing view |
| 4400 | * should call this when its cursor moves. |
| 4401 | * |
| 4402 | * <p>When <code>immediate</code> is set to true, scrolling will not be |
| 4403 | * animated. |
| 4404 | * |
| 4405 | * @param rectangle The rectangle. |
| 4406 | * @param immediate True to forbid animated scrolling, false otherwise |
| 4407 | * @return Whether any parent scrolled. |
| 4408 | */ |
| 4409 | public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) { |
Svetoslav Ganov | 989ae75 | 2012-09-25 15:16:48 -0700 | [diff] [blame] | 4410 | if (mParent == null) { |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4411 | return false; |
| 4412 | } |
| 4413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4414 | View child = this; |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4415 | |
Svetoslav Ganov | 989ae75 | 2012-09-25 15:16:48 -0700 | [diff] [blame] | 4416 | RectF position = (mAttachInfo != null) ? mAttachInfo.mTmpTransformRect : new RectF(); |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4417 | position.set(rectangle); |
| 4418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4419 | ViewParent parent = mParent; |
| 4420 | boolean scrolled = false; |
| 4421 | while (parent != null) { |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4422 | rectangle.set((int) position.left, (int) position.top, |
| 4423 | (int) position.right, (int) position.bottom); |
| 4424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4425 | scrolled |= parent.requestChildRectangleOnScreen(child, |
| 4426 | rectangle, immediate); |
| 4427 | |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4428 | if (!child.hasIdentityMatrix()) { |
| 4429 | child.getMatrix().mapRect(position); |
| 4430 | } |
| 4431 | |
| 4432 | position.offset(child.mLeft, child.mTop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4433 | |
| 4434 | if (!(parent instanceof View)) { |
| 4435 | break; |
| 4436 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4437 | |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4438 | View parentView = (View) parent; |
| 4439 | |
| 4440 | position.offset(-parentView.getScrollX(), -parentView.getScrollY()); |
| 4441 | |
| 4442 | child = parentView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4443 | parent = child.getParent(); |
| 4444 | } |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4446 | return scrolled; |
| 4447 | } |
| 4448 | |
| 4449 | /** |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 4450 | * Called when this view wants to give up focus. If focus is cleared |
| 4451 | * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} is called. |
| 4452 | * <p> |
| 4453 | * <strong>Note:</strong> When a View clears focus the framework is trying |
| 4454 | * 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] | 4455 | * View is the first from the top that can take focus, then all callbacks |
| 4456 | * related to clearing focus will be invoked after wich the framework will |
| 4457 | * give focus to this view. |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 4458 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4459 | */ |
| 4460 | public void clearFocus() { |
| 4461 | if (DBG) { |
| 4462 | System.out.println(this + " clearFocus()"); |
| 4463 | } |
| 4464 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4465 | if ((mPrivateFlags & PFLAG_FOCUSED) != 0) { |
| 4466 | mPrivateFlags &= ~PFLAG_FOCUSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4467 | |
| 4468 | if (mParent != null) { |
| 4469 | mParent.clearChildFocus(this); |
| 4470 | } |
| 4471 | |
| 4472 | onFocusChanged(false, 0, null); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4473 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4474 | refreshDrawableState(); |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame] | 4475 | |
| 4476 | ensureInputFocusOnFirstFocusable(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4477 | |
| 4478 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4479 | notifyAccessibilityStateChanged(); |
| 4480 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4481 | } |
| 4482 | } |
| 4483 | |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame] | 4484 | void ensureInputFocusOnFirstFocusable() { |
| 4485 | View root = getRootView(); |
| 4486 | if (root != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4487 | root.requestFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4488 | } |
| 4489 | } |
| 4490 | |
| 4491 | /** |
| 4492 | * Called internally by the view system when a new view is getting focus. |
| 4493 | * This is what clears the old focus. |
| 4494 | */ |
| 4495 | void unFocus() { |
| 4496 | if (DBG) { |
| 4497 | System.out.println(this + " unFocus()"); |
| 4498 | } |
| 4499 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4500 | if ((mPrivateFlags & PFLAG_FOCUSED) != 0) { |
| 4501 | mPrivateFlags &= ~PFLAG_FOCUSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4502 | |
| 4503 | onFocusChanged(false, 0, null); |
| 4504 | refreshDrawableState(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4505 | |
| 4506 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4507 | notifyAccessibilityStateChanged(); |
| 4508 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4509 | } |
| 4510 | } |
| 4511 | |
| 4512 | /** |
| 4513 | * Returns true if this view has focus iteself, or is the ancestor of the |
| 4514 | * view that has focus. |
| 4515 | * |
| 4516 | * @return True if this view has or contains focus, false otherwise. |
| 4517 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4518 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4519 | public boolean hasFocus() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4520 | return (mPrivateFlags & PFLAG_FOCUSED) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | /** |
| 4524 | * Returns true if this view is focusable or if it contains a reachable View |
| 4525 | * for which {@link #hasFocusable()} returns true. A "reachable hasFocusable()" |
| 4526 | * is a View whose parents do not block descendants focus. |
| 4527 | * |
| 4528 | * Only {@link #VISIBLE} views are considered focusable. |
| 4529 | * |
| 4530 | * @return True if the view is focusable or if the view contains a focusable |
| 4531 | * View, false otherwise. |
| 4532 | * |
| 4533 | * @see ViewGroup#FOCUS_BLOCK_DESCENDANTS |
| 4534 | */ |
| 4535 | public boolean hasFocusable() { |
| 4536 | return (mViewFlags & VISIBILITY_MASK) == VISIBLE && isFocusable(); |
| 4537 | } |
| 4538 | |
| 4539 | /** |
| 4540 | * Called by the view system when the focus state of this view changes. |
| 4541 | * When the focus change event is caused by directional navigation, direction |
| 4542 | * and previouslyFocusedRect provide insight into where the focus is coming from. |
| 4543 | * When overriding, be sure to call up through to the super class so that |
| 4544 | * the standard focus handling will occur. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4545 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4546 | * @param gainFocus True if the View has focus; false otherwise. |
| 4547 | * @param direction The direction focus has moved when requestFocus() |
| 4548 | * is called to give this view focus. Values are |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4549 | * {@link #FOCUS_UP}, {@link #FOCUS_DOWN}, {@link #FOCUS_LEFT}, |
| 4550 | * {@link #FOCUS_RIGHT}, {@link #FOCUS_FORWARD}, or {@link #FOCUS_BACKWARD}. |
| 4551 | * 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] | 4552 | * @param previouslyFocusedRect The rectangle, in this view's coordinate |
| 4553 | * system, of the previously focused view. If applicable, this will be |
| 4554 | * passed in as finer grained information about where the focus is coming |
| 4555 | * from (in addition to direction). Will be <code>null</code> otherwise. |
| 4556 | */ |
| 4557 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4558 | if (gainFocus) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4559 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4560 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4561 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4562 | } |
| 4563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4564 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4565 | if (!gainFocus) { |
| 4566 | if (isPressed()) { |
| 4567 | setPressed(false); |
| 4568 | } |
| 4569 | if (imm != null && mAttachInfo != null |
| 4570 | && mAttachInfo.mHasWindowFocus) { |
| 4571 | imm.focusOut(this); |
| 4572 | } |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4573 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4574 | } else if (imm != null && mAttachInfo != null |
| 4575 | && mAttachInfo.mHasWindowFocus) { |
| 4576 | imm.focusIn(this); |
| 4577 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4578 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 4579 | invalidate(true); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4580 | ListenerInfo li = mListenerInfo; |
| 4581 | if (li != null && li.mOnFocusChangeListener != null) { |
| 4582 | li.mOnFocusChangeListener.onFocusChange(this, gainFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4583 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 4584 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 4585 | if (mAttachInfo != null) { |
| 4586 | mAttachInfo.mKeyDispatchState.reset(this); |
| 4587 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4588 | } |
| 4589 | |
| 4590 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 4591 | * Sends an accessibility event of the given type. If accessibility is |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4592 | * not enabled this method has no effect. The default implementation calls |
| 4593 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first |
| 4594 | * to populate information about the event source (this View), then calls |
| 4595 | * {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} to |
| 4596 | * populate the text content of the event source including its descendants, |
| 4597 | * and last calls |
| 4598 | * {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)} |
| 4599 | * on its parent to resuest sending of the event to interested parties. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4600 | * <p> |
| 4601 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4602 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4603 | * {@link AccessibilityDelegate#sendAccessibilityEvent(View, int)} is |
| 4604 | * responsible for handling this call. |
| 4605 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4606 | * |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4607 | * @param eventType The type of the event to send, as defined by several types from |
| 4608 | * {@link android.view.accessibility.AccessibilityEvent}, such as |
| 4609 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED} or |
| 4610 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4611 | * |
| 4612 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4613 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4614 | * @see ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent) |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4615 | * @see AccessibilityDelegate |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4616 | */ |
| 4617 | public void sendAccessibilityEvent(int eventType) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4618 | if (mAccessibilityDelegate != null) { |
| 4619 | mAccessibilityDelegate.sendAccessibilityEvent(this, eventType); |
| 4620 | } else { |
| 4621 | sendAccessibilityEventInternal(eventType); |
| 4622 | } |
| 4623 | } |
| 4624 | |
| 4625 | /** |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4626 | * Convenience method for sending a {@link AccessibilityEvent#TYPE_ANNOUNCEMENT} |
| 4627 | * {@link AccessibilityEvent} to make an announcement which is related to some |
| 4628 | * sort of a context change for which none of the events representing UI transitions |
| 4629 | * is a good fit. For example, announcing a new page in a book. If accessibility |
| 4630 | * is not enabled this method does nothing. |
| 4631 | * |
| 4632 | * @param text The announcement text. |
| 4633 | */ |
| 4634 | public void announceForAccessibility(CharSequence text) { |
Svetoslav Ganov | 7a82b2b | 2012-07-02 18:33:23 -0700 | [diff] [blame] | 4635 | if (AccessibilityManager.getInstance(mContext).isEnabled() && mParent != null) { |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4636 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 4637 | AccessibilityEvent.TYPE_ANNOUNCEMENT); |
Svetoslav Ganov | 7a82b2b | 2012-07-02 18:33:23 -0700 | [diff] [blame] | 4638 | onInitializeAccessibilityEvent(event); |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4639 | event.getText().add(text); |
Svetoslav Ganov | 7a82b2b | 2012-07-02 18:33:23 -0700 | [diff] [blame] | 4640 | event.setContentDescription(null); |
| 4641 | mParent.requestSendAccessibilityEvent(this, event); |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4642 | } |
| 4643 | } |
| 4644 | |
| 4645 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4646 | * @see #sendAccessibilityEvent(int) |
| 4647 | * |
| 4648 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4649 | */ |
| 4650 | void sendAccessibilityEventInternal(int eventType) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4651 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4652 | sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType)); |
| 4653 | } |
| 4654 | } |
| 4655 | |
| 4656 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4657 | * This method behaves exactly as {@link #sendAccessibilityEvent(int)} but |
| 4658 | * takes as an argument an empty {@link AccessibilityEvent} and does not |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4659 | * perform a check whether accessibility is enabled. |
| 4660 | * <p> |
| 4661 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4662 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4663 | * {@link AccessibilityDelegate#sendAccessibilityEventUnchecked(View, AccessibilityEvent)} |
| 4664 | * is responsible for handling this call. |
| 4665 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4666 | * |
| 4667 | * @param event The event to send. |
| 4668 | * |
| 4669 | * @see #sendAccessibilityEvent(int) |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4670 | */ |
| 4671 | public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4672 | if (mAccessibilityDelegate != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4673 | mAccessibilityDelegate.sendAccessibilityEventUnchecked(this, event); |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4674 | } else { |
| 4675 | sendAccessibilityEventUncheckedInternal(event); |
| 4676 | } |
| 4677 | } |
| 4678 | |
| 4679 | /** |
| 4680 | * @see #sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 4681 | * |
| 4682 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4683 | */ |
| 4684 | void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 9cd1eca | 2011-01-13 14:24:02 -0800 | [diff] [blame] | 4685 | if (!isShown()) { |
| 4686 | return; |
| 4687 | } |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4688 | onInitializeAccessibilityEvent(event); |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4689 | // Only a subset of accessibility events populates text content. |
| 4690 | if ((event.getEventType() & POPULATING_ACCESSIBILITY_EVENT_TYPES) != 0) { |
| 4691 | dispatchPopulateAccessibilityEvent(event); |
| 4692 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4693 | // In the beginning we called #isShown(), so we know that getParent() is not null. |
| 4694 | getParent().requestSendAccessibilityEvent(this, event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4695 | } |
| 4696 | |
| 4697 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4698 | * Dispatches an {@link AccessibilityEvent} to the {@link View} first and then |
| 4699 | * to its children for adding their text content to the event. Note that the |
| 4700 | * event text is populated in a separate dispatch path since we add to the |
| 4701 | * 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] | 4702 | * A typical implementation will call |
| 4703 | * {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} on the this view |
| 4704 | * and then call the {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
| 4705 | * on each child. Override this method if custom population of the event text |
| 4706 | * content is required. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4707 | * <p> |
| 4708 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4709 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4710 | * {@link AccessibilityDelegate#dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4711 | * is responsible for handling this call. |
| 4712 | * </p> |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4713 | * <p> |
| 4714 | * <em>Note:</em> Accessibility events of certain types are not dispatched for |
| 4715 | * populating the event text via this method. For details refer to {@link AccessibilityEvent}. |
| 4716 | * </p> |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4717 | * |
| 4718 | * @param event The event. |
| 4719 | * |
| 4720 | * @return True if the event population was completed. |
| 4721 | */ |
| 4722 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4723 | if (mAccessibilityDelegate != null) { |
| 4724 | return mAccessibilityDelegate.dispatchPopulateAccessibilityEvent(this, event); |
| 4725 | } else { |
| 4726 | return dispatchPopulateAccessibilityEventInternal(event); |
| 4727 | } |
| 4728 | } |
| 4729 | |
| 4730 | /** |
| 4731 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4732 | * |
| 4733 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4734 | */ |
| 4735 | boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4736 | onPopulateAccessibilityEvent(event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4737 | return false; |
| 4738 | } |
| 4739 | |
| 4740 | /** |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4741 | * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4742 | * 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] | 4743 | * text content. While this method is free to modify event |
| 4744 | * attributes other than text content, doing so should normally be performed in |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4745 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}. |
| 4746 | * <p> |
| 4747 | * Example: Adding formatted date string to an accessibility event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4748 | * to the text added by the super implementation: |
| 4749 | * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4750 | * super.onPopulateAccessibilityEvent(event); |
| 4751 | * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; |
| 4752 | * String selectedDateUtterance = DateUtils.formatDateTime(mContext, |
| 4753 | * mCurrentDate.getTimeInMillis(), flags); |
| 4754 | * event.getText().add(selectedDateUtterance); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4755 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4756 | * <p> |
| 4757 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4758 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4759 | * {@link AccessibilityDelegate#onPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4760 | * is responsible for handling this call. |
| 4761 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4762 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4763 | * information to the event, in case the default implementation has basic information to add. |
| 4764 | * </p> |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4765 | * |
| 4766 | * @param event The accessibility event which to populate. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4767 | * |
| 4768 | * @see #sendAccessibilityEvent(int) |
| 4769 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4770 | */ |
| 4771 | public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4772 | if (mAccessibilityDelegate != null) { |
| 4773 | mAccessibilityDelegate.onPopulateAccessibilityEvent(this, event); |
| 4774 | } else { |
| 4775 | onPopulateAccessibilityEventInternal(event); |
| 4776 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4780 | * @see #onPopulateAccessibilityEvent(AccessibilityEvent) |
| 4781 | * |
| 4782 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4783 | */ |
| 4784 | void onPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
| 4785 | |
| 4786 | } |
| 4787 | |
| 4788 | /** |
| 4789 | * Initializes an {@link AccessibilityEvent} with information about |
| 4790 | * this View which is the event source. In other words, the source of |
| 4791 | * an accessibility event is the view whose state change triggered firing |
| 4792 | * the event. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4793 | * <p> |
| 4794 | * Example: Setting the password property of an event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4795 | * to properties set by the super implementation: |
| 4796 | * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 4797 | * super.onInitializeAccessibilityEvent(event); |
| 4798 | * event.setPassword(true); |
| 4799 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4800 | * <p> |
| 4801 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4802 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4803 | * {@link AccessibilityDelegate#onInitializeAccessibilityEvent(View, AccessibilityEvent)} |
| 4804 | * is responsible for handling this call. |
| 4805 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4806 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4807 | * information to the event, in case the default implementation has basic information to add. |
| 4808 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4809 | * @param event The event to initialize. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4810 | * |
| 4811 | * @see #sendAccessibilityEvent(int) |
| 4812 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4813 | */ |
| 4814 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4815 | if (mAccessibilityDelegate != null) { |
| 4816 | mAccessibilityDelegate.onInitializeAccessibilityEvent(this, event); |
| 4817 | } else { |
| 4818 | onInitializeAccessibilityEventInternal(event); |
| 4819 | } |
| 4820 | } |
| 4821 | |
| 4822 | /** |
| 4823 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4824 | * |
| 4825 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4826 | */ |
| 4827 | void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4828 | event.setSource(this); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4829 | event.setClassName(View.class.getName()); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4830 | event.setPackageName(getContext().getPackageName()); |
| 4831 | event.setEnabled(isEnabled()); |
| 4832 | event.setContentDescription(mContentDescription); |
| 4833 | |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4834 | if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && mAttachInfo != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4835 | ArrayList<View> focusablesTempList = mAttachInfo.mTempArrayList; |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4836 | getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, |
| 4837 | FOCUSABLES_ALL); |
| 4838 | event.setItemCount(focusablesTempList.size()); |
| 4839 | event.setCurrentItemIndex(focusablesTempList.indexOf(this)); |
| 4840 | focusablesTempList.clear(); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4841 | } |
| 4842 | } |
| 4843 | |
| 4844 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4845 | * Returns an {@link AccessibilityNodeInfo} representing this view from the |
| 4846 | * point of view of an {@link android.accessibilityservice.AccessibilityService}. |
| 4847 | * This method is responsible for obtaining an accessibility node info from a |
| 4848 | * pool of reusable instances and calling |
| 4849 | * {@link #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} on this view to |
| 4850 | * initialize the former. |
| 4851 | * <p> |
| 4852 | * Note: The client is responsible for recycling the obtained instance by calling |
| 4853 | * {@link AccessibilityNodeInfo#recycle()} to minimize object creation. |
| 4854 | * </p> |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4855 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4856 | * @return A populated {@link AccessibilityNodeInfo}. |
| 4857 | * |
| 4858 | * @see AccessibilityNodeInfo |
| 4859 | */ |
| 4860 | public AccessibilityNodeInfo createAccessibilityNodeInfo() { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4861 | AccessibilityNodeProvider provider = getAccessibilityNodeProvider(); |
| 4862 | if (provider != null) { |
| 4863 | return provider.createAccessibilityNodeInfo(View.NO_ID); |
| 4864 | } else { |
| 4865 | AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this); |
| 4866 | onInitializeAccessibilityNodeInfo(info); |
| 4867 | return info; |
| 4868 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | /** |
| 4872 | * Initializes an {@link AccessibilityNodeInfo} with information about this view. |
| 4873 | * The base implementation sets: |
| 4874 | * <ul> |
| 4875 | * <li>{@link AccessibilityNodeInfo#setParent(View)},</li> |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4876 | * <li>{@link AccessibilityNodeInfo#setBoundsInParent(Rect)},</li> |
| 4877 | * <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li> |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4878 | * <li>{@link AccessibilityNodeInfo#setPackageName(CharSequence)},</li> |
| 4879 | * <li>{@link AccessibilityNodeInfo#setClassName(CharSequence)},</li> |
| 4880 | * <li>{@link AccessibilityNodeInfo#setContentDescription(CharSequence)},</li> |
| 4881 | * <li>{@link AccessibilityNodeInfo#setEnabled(boolean)},</li> |
| 4882 | * <li>{@link AccessibilityNodeInfo#setClickable(boolean)},</li> |
| 4883 | * <li>{@link AccessibilityNodeInfo#setFocusable(boolean)},</li> |
| 4884 | * <li>{@link AccessibilityNodeInfo#setFocused(boolean)},</li> |
| 4885 | * <li>{@link AccessibilityNodeInfo#setLongClickable(boolean)},</li> |
| 4886 | * <li>{@link AccessibilityNodeInfo#setSelected(boolean)},</li> |
| 4887 | * </ul> |
| 4888 | * <p> |
| 4889 | * Subclasses should override this method, call the super implementation, |
| 4890 | * and set additional attributes. |
| 4891 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4892 | * <p> |
| 4893 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4894 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4895 | * {@link AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)} |
| 4896 | * is responsible for handling this call. |
| 4897 | * </p> |
| 4898 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4899 | * @param info The instance to initialize. |
| 4900 | */ |
| 4901 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4902 | if (mAccessibilityDelegate != null) { |
| 4903 | mAccessibilityDelegate.onInitializeAccessibilityNodeInfo(this, info); |
| 4904 | } else { |
| 4905 | onInitializeAccessibilityNodeInfoInternal(info); |
| 4906 | } |
| 4907 | } |
| 4908 | |
| 4909 | /** |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4910 | * Gets the location of this view in screen coordintates. |
| 4911 | * |
| 4912 | * @param outRect The output location |
| 4913 | */ |
| 4914 | private void getBoundsOnScreen(Rect outRect) { |
| 4915 | if (mAttachInfo == null) { |
| 4916 | return; |
| 4917 | } |
| 4918 | |
| 4919 | RectF position = mAttachInfo.mTmpTransformRect; |
Svetoslav Ganov | 14b2b74 | 2012-05-08 16:36:34 -0700 | [diff] [blame] | 4920 | position.set(0, 0, mRight - mLeft, mBottom - mTop); |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4921 | |
| 4922 | if (!hasIdentityMatrix()) { |
| 4923 | getMatrix().mapRect(position); |
| 4924 | } |
| 4925 | |
Svetoslav Ganov | 14b2b74 | 2012-05-08 16:36:34 -0700 | [diff] [blame] | 4926 | position.offset(mLeft, mTop); |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4927 | |
| 4928 | ViewParent parent = mParent; |
| 4929 | while (parent instanceof View) { |
| 4930 | View parentView = (View) parent; |
| 4931 | |
| 4932 | position.offset(-parentView.mScrollX, -parentView.mScrollY); |
| 4933 | |
| 4934 | if (!parentView.hasIdentityMatrix()) { |
| 4935 | parentView.getMatrix().mapRect(position); |
| 4936 | } |
| 4937 | |
| 4938 | position.offset(parentView.mLeft, parentView.mTop); |
| 4939 | |
| 4940 | parent = parentView.mParent; |
| 4941 | } |
| 4942 | |
| 4943 | if (parent instanceof ViewRootImpl) { |
| 4944 | ViewRootImpl viewRootImpl = (ViewRootImpl) parent; |
| 4945 | position.offset(0, -viewRootImpl.mCurScrollY); |
| 4946 | } |
| 4947 | |
| 4948 | position.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
| 4949 | |
| 4950 | outRect.set((int) (position.left + 0.5f), (int) (position.top + 0.5f), |
| 4951 | (int) (position.right + 0.5f), (int) (position.bottom + 0.5f)); |
| 4952 | } |
| 4953 | |
| 4954 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4955 | * @see #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 4956 | * |
| 4957 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4958 | */ |
| 4959 | void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4960 | Rect bounds = mAttachInfo.mTmpInvalRect; |
Svetoslav Ganov | 983119a | 2012-07-03 21:04:10 -0700 | [diff] [blame] | 4961 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4962 | getDrawingRect(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4963 | info.setBoundsInParent(bounds); |
| 4964 | |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4965 | getBoundsOnScreen(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4966 | info.setBoundsInScreen(bounds); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4967 | |
Svetoslav Ganov | c406be9 | 2012-05-11 16:12:32 -0700 | [diff] [blame] | 4968 | ViewParent parent = getParentForAccessibility(); |
| 4969 | if (parent instanceof View) { |
| 4970 | info.setParent((View) parent); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4971 | } |
| 4972 | |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 4973 | if (mID != View.NO_ID) { |
| 4974 | View rootView = getRootView(); |
| 4975 | if (rootView == null) { |
| 4976 | rootView = this; |
| 4977 | } |
| 4978 | View label = rootView.findLabelForView(this, mID); |
| 4979 | if (label != null) { |
| 4980 | info.setLabeledBy(label); |
| 4981 | } |
| 4982 | } |
| 4983 | |
| 4984 | if (mLabelForId != View.NO_ID) { |
| 4985 | View rootView = getRootView(); |
| 4986 | if (rootView == null) { |
| 4987 | rootView = this; |
| 4988 | } |
| 4989 | View labeled = rootView.findViewInsideOutShouldExist(this, mLabelForId); |
| 4990 | if (labeled != null) { |
| 4991 | info.setLabelFor(labeled); |
| 4992 | } |
| 4993 | } |
| 4994 | |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4995 | info.setVisibleToUser(isVisibleToUser()); |
| 4996 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4997 | info.setPackageName(mContext.getPackageName()); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4998 | info.setClassName(View.class.getName()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4999 | info.setContentDescription(getContentDescription()); |
| 5000 | |
| 5001 | info.setEnabled(isEnabled()); |
| 5002 | info.setClickable(isClickable()); |
| 5003 | info.setFocusable(isFocusable()); |
| 5004 | info.setFocused(isFocused()); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5005 | info.setAccessibilityFocused(isAccessibilityFocused()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5006 | info.setSelected(isSelected()); |
| 5007 | info.setLongClickable(isLongClickable()); |
| 5008 | |
| 5009 | // 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] | 5010 | // views can be selected. Maybe from accessibility perspective |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5011 | // we should report as selectable view in an AdapterView. |
| 5012 | info.addAction(AccessibilityNodeInfo.ACTION_SELECT); |
| 5013 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION); |
| 5014 | |
| 5015 | if (isFocusable()) { |
| 5016 | if (isFocused()) { |
| 5017 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS); |
| 5018 | } else { |
| 5019 | info.addAction(AccessibilityNodeInfo.ACTION_FOCUS); |
| 5020 | } |
| 5021 | } |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5022 | |
Svetoslav Ganov | 02afe2c | 2012-05-07 17:51:59 -0700 | [diff] [blame] | 5023 | if (!isAccessibilityFocused()) { |
Svetoslav Ganov | 27e2da7 | 2012-07-02 18:12:00 -0700 | [diff] [blame] | 5024 | info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS); |
Svetoslav Ganov | 02afe2c | 2012-05-07 17:51:59 -0700 | [diff] [blame] | 5025 | } else { |
| 5026 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS); |
| 5027 | } |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5028 | |
Svetoslav Ganov | fb1e80a | 2012-05-16 17:33:19 -0700 | [diff] [blame] | 5029 | if (isClickable() && isEnabled()) { |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5030 | info.addAction(AccessibilityNodeInfo.ACTION_CLICK); |
| 5031 | } |
| 5032 | |
Svetoslav Ganov | fb1e80a | 2012-05-16 17:33:19 -0700 | [diff] [blame] | 5033 | if (isLongClickable() && isEnabled()) { |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5034 | info.addAction(AccessibilityNodeInfo.ACTION_LONG_CLICK); |
| 5035 | } |
| 5036 | |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 5037 | if (mContentDescription != null && mContentDescription.length() > 0) { |
Svetoslav Ganov | 2b435aa | 2012-05-04 17:16:37 -0700 | [diff] [blame] | 5038 | info.addAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY); |
| 5039 | info.addAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY); |
| 5040 | info.setMovementGranularities(AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 5041 | | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD |
| 5042 | | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH); |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5043 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5044 | } |
| 5045 | |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 5046 | private View findLabelForView(View view, int labeledId) { |
| 5047 | if (mMatchLabelForPredicate == null) { |
| 5048 | mMatchLabelForPredicate = new MatchLabelForPredicate(); |
| 5049 | } |
| 5050 | mMatchLabelForPredicate.mLabeledId = labeledId; |
| 5051 | return findViewByPredicateInsideOut(view, mMatchLabelForPredicate); |
| 5052 | } |
| 5053 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5054 | /** |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 5055 | * Computes whether this view is visible to the user. Such a view is |
| 5056 | * attached, visible, all its predecessors are visible, it is not clipped |
| 5057 | * entirely by its predecessors, and has an alpha greater than zero. |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 5058 | * |
| 5059 | * @return Whether the view is visible on the screen. |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 5060 | * |
| 5061 | * @hide |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 5062 | */ |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 5063 | protected boolean isVisibleToUser() { |
| 5064 | return isVisibleToUser(null); |
| 5065 | } |
| 5066 | |
| 5067 | /** |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5068 | * Computes whether the given portion of this view is visible to the user. |
| 5069 | * Such a view is attached, visible, all its predecessors are visible, |
| 5070 | * has an alpha greater than zero, and the specified portion is not |
| 5071 | * clipped entirely by its predecessors. |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 5072 | * |
| 5073 | * @param boundInView the portion of the view to test; coordinates should be relative; may be |
| 5074 | * <code>null</code>, and the entire view will be tested in this case. |
| 5075 | * When <code>true</code> is returned by the function, the actual visible |
| 5076 | * region will be stored in this parameter; that is, if boundInView is fully |
| 5077 | * contained within the view, no modification will be made, otherwise regions |
| 5078 | * outside of the visible area of the view will be clipped. |
| 5079 | * |
| 5080 | * @return Whether the specified portion of the view is visible on the screen. |
| 5081 | * |
| 5082 | * @hide |
| 5083 | */ |
| 5084 | protected boolean isVisibleToUser(Rect boundInView) { |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5085 | if (mAttachInfo != null) { |
| 5086 | Rect visibleRect = mAttachInfo.mTmpInvalRect; |
| 5087 | Point offset = mAttachInfo.mPoint; |
| 5088 | // The first two checks are made also made by isShown() which |
| 5089 | // however traverses the tree up to the parent to catch that. |
| 5090 | // Therefore, we do some fail fast check to minimize the up |
| 5091 | // tree traversal. |
| 5092 | boolean isVisible = mAttachInfo.mWindowVisibility == View.VISIBLE |
| 5093 | && getAlpha() > 0 |
| 5094 | && isShown() |
| 5095 | && getGlobalVisibleRect(visibleRect, offset); |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 5096 | if (isVisible && boundInView != null) { |
| 5097 | visibleRect.offset(-offset.x, -offset.y); |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5098 | // isVisible is always true here, use a simple assignment |
| 5099 | isVisible = boundInView.intersect(visibleRect); |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 5100 | } |
| 5101 | return isVisible; |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5102 | } |
| 5103 | |
| 5104 | return false; |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | /** |
alanv | b72fe7a | 2012-08-27 16:44:25 -0700 | [diff] [blame] | 5108 | * Returns the delegate for implementing accessibility support via |
| 5109 | * composition. For more details see {@link AccessibilityDelegate}. |
| 5110 | * |
| 5111 | * @return The delegate, or null if none set. |
| 5112 | * |
| 5113 | * @hide |
| 5114 | */ |
| 5115 | public AccessibilityDelegate getAccessibilityDelegate() { |
| 5116 | return mAccessibilityDelegate; |
| 5117 | } |
| 5118 | |
| 5119 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 5120 | * Sets a delegate for implementing accessibility support via composition as |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 5121 | * opposed to inheritance. The delegate's primary use is for implementing |
| 5122 | * backwards compatible widgets. For more details see {@link AccessibilityDelegate}. |
| 5123 | * |
| 5124 | * @param delegate The delegate instance. |
| 5125 | * |
| 5126 | * @see AccessibilityDelegate |
| 5127 | */ |
| 5128 | public void setAccessibilityDelegate(AccessibilityDelegate delegate) { |
| 5129 | mAccessibilityDelegate = delegate; |
| 5130 | } |
| 5131 | |
| 5132 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5133 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 5134 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 5135 | * that explore the window content. |
| 5136 | * <p> |
| 5137 | * If this method returns an instance, this instance is responsible for managing |
| 5138 | * {@link AccessibilityNodeInfo}s describing the virtual sub-tree rooted at this |
| 5139 | * View including the one representing the View itself. Similarly the returned |
| 5140 | * instance is responsible for performing accessibility actions on any virtual |
| 5141 | * view or the root view itself. |
| 5142 | * </p> |
| 5143 | * <p> |
| 5144 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 5145 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 5146 | * {@link AccessibilityDelegate#getAccessibilityNodeProvider(View)} |
| 5147 | * is responsible for handling this call. |
| 5148 | * </p> |
| 5149 | * |
| 5150 | * @return The provider. |
| 5151 | * |
| 5152 | * @see AccessibilityNodeProvider |
| 5153 | */ |
| 5154 | public AccessibilityNodeProvider getAccessibilityNodeProvider() { |
| 5155 | if (mAccessibilityDelegate != null) { |
| 5156 | return mAccessibilityDelegate.getAccessibilityNodeProvider(this); |
| 5157 | } else { |
| 5158 | return null; |
| 5159 | } |
| 5160 | } |
| 5161 | |
| 5162 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5163 | * Gets the unique identifier of this view on the screen for accessibility purposes. |
| 5164 | * If this {@link View} is not attached to any window, {@value #NO_ID} is returned. |
| 5165 | * |
| 5166 | * @return The view accessibility id. |
| 5167 | * |
| 5168 | * @hide |
| 5169 | */ |
| 5170 | public int getAccessibilityViewId() { |
| 5171 | if (mAccessibilityViewId == NO_ID) { |
| 5172 | mAccessibilityViewId = sNextAccessibilityViewId++; |
| 5173 | } |
| 5174 | return mAccessibilityViewId; |
| 5175 | } |
| 5176 | |
| 5177 | /** |
| 5178 | * Gets the unique identifier of the window in which this View reseides. |
| 5179 | * |
| 5180 | * @return The window accessibility id. |
| 5181 | * |
| 5182 | * @hide |
| 5183 | */ |
| 5184 | public int getAccessibilityWindowId() { |
| 5185 | return mAttachInfo != null ? mAttachInfo.mAccessibilityWindowId : NO_ID; |
| 5186 | } |
| 5187 | |
| 5188 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5189 | * Gets the {@link View} description. It briefly describes the view and is |
| 5190 | * primarily used for accessibility support. Set this property to enable |
| 5191 | * better accessibility support for your application. This is especially |
| 5192 | * true for views that do not have textual representation (For example, |
| 5193 | * ImageButton). |
| 5194 | * |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5195 | * @return The content description. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5196 | * |
| 5197 | * @attr ref android.R.styleable#View_contentDescription |
| 5198 | */ |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5199 | @ViewDebug.ExportedProperty(category = "accessibility") |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5200 | public CharSequence getContentDescription() { |
| 5201 | return mContentDescription; |
| 5202 | } |
| 5203 | |
| 5204 | /** |
| 5205 | * Sets the {@link View} description. It briefly describes the view and is |
| 5206 | * primarily used for accessibility support. Set this property to enable |
| 5207 | * better accessibility support for your application. This is especially |
| 5208 | * true for views that do not have textual representation (For example, |
| 5209 | * ImageButton). |
| 5210 | * |
| 5211 | * @param contentDescription The content description. |
| 5212 | * |
| 5213 | * @attr ref android.R.styleable#View_contentDescription |
| 5214 | */ |
Svetoslav Ganov | e261e28 | 2011-10-18 17:47:04 -0700 | [diff] [blame] | 5215 | @RemotableViewMethod |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5216 | public void setContentDescription(CharSequence contentDescription) { |
| 5217 | mContentDescription = contentDescription; |
Svetoslav Ganov | e47957a | 2012-06-05 14:46:50 -0700 | [diff] [blame] | 5218 | final boolean nonEmptyDesc = contentDescription != null && contentDescription.length() > 0; |
| 5219 | if (nonEmptyDesc && getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 5220 | setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 5221 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5222 | } |
| 5223 | |
| 5224 | /** |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 5225 | * Gets the id of a view for which this view serves as a label for |
| 5226 | * accessibility purposes. |
| 5227 | * |
| 5228 | * @return The labeled view id. |
| 5229 | */ |
| 5230 | @ViewDebug.ExportedProperty(category = "accessibility") |
| 5231 | public int getLabelFor() { |
| 5232 | return mLabelForId; |
| 5233 | } |
| 5234 | |
| 5235 | /** |
| 5236 | * Sets the id of a view for which this view serves as a label for |
| 5237 | * accessibility purposes. |
| 5238 | * |
| 5239 | * @param id The labeled view id. |
| 5240 | */ |
| 5241 | @RemotableViewMethod |
| 5242 | public void setLabelFor(int id) { |
| 5243 | mLabelForId = id; |
| 5244 | if (mLabelForId != View.NO_ID |
| 5245 | && mID == View.NO_ID) { |
| 5246 | mID = generateViewId(); |
| 5247 | } |
| 5248 | } |
| 5249 | |
| 5250 | /** |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5251 | * Invoked whenever this view loses focus, either by losing window focus or by losing |
| 5252 | * focus within its window. This method can be used to clear any state tied to the |
| 5253 | * focus. For instance, if a button is held pressed with the trackball and the window |
| 5254 | * loses focus, this method can be used to cancel the press. |
| 5255 | * |
| 5256 | * Subclasses of View overriding this method should always call super.onFocusLost(). |
| 5257 | * |
| 5258 | * @see #onFocusChanged(boolean, int, android.graphics.Rect) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5259 | * @see #onWindowFocusChanged(boolean) |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5260 | * |
| 5261 | * @hide pending API council approval |
| 5262 | */ |
| 5263 | protected void onFocusLost() { |
| 5264 | resetPressedState(); |
| 5265 | } |
| 5266 | |
| 5267 | private void resetPressedState() { |
| 5268 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 5269 | return; |
| 5270 | } |
| 5271 | |
| 5272 | if (isPressed()) { |
| 5273 | setPressed(false); |
| 5274 | |
| 5275 | if (!mHasPerformedLongPress) { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 5276 | removeLongPressCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5277 | } |
| 5278 | } |
| 5279 | } |
| 5280 | |
| 5281 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5282 | * Returns true if this view has focus |
| 5283 | * |
| 5284 | * @return True if this view has focus, false otherwise. |
| 5285 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5286 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5287 | public boolean isFocused() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5288 | return (mPrivateFlags & PFLAG_FOCUSED) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5289 | } |
| 5290 | |
| 5291 | /** |
| 5292 | * Find the view in the hierarchy rooted at this view that currently has |
| 5293 | * focus. |
| 5294 | * |
| 5295 | * @return The view that currently has focus, or null if no focused view can |
| 5296 | * be found. |
| 5297 | */ |
| 5298 | public View findFocus() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5299 | return (mPrivateFlags & PFLAG_FOCUSED) != 0 ? this : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5300 | } |
| 5301 | |
| 5302 | /** |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5303 | * Indicates whether this view is one of the set of scrollable containers in |
| 5304 | * its window. |
| 5305 | * |
| 5306 | * @return whether this view is one of the set of scrollable containers in |
| 5307 | * its window |
| 5308 | * |
| 5309 | * @attr ref android.R.styleable#View_isScrollContainer |
| 5310 | */ |
| 5311 | public boolean isScrollContainer() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5312 | return (mPrivateFlags & PFLAG_SCROLL_CONTAINER_ADDED) != 0; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5316 | * Change whether this view is one of the set of scrollable containers in |
| 5317 | * its window. This will be used to determine whether the window can |
| 5318 | * resize or must pan when a soft input area is open -- scrollable |
| 5319 | * containers allow the window to use resize mode since the container |
| 5320 | * will appropriately shrink. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5321 | * |
| 5322 | * @attr ref android.R.styleable#View_isScrollContainer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5323 | */ |
| 5324 | public void setScrollContainer(boolean isScrollContainer) { |
| 5325 | if (isScrollContainer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5326 | if (mAttachInfo != null && (mPrivateFlags&PFLAG_SCROLL_CONTAINER_ADDED) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5327 | mAttachInfo.mScrollContainers.add(this); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5328 | mPrivateFlags |= PFLAG_SCROLL_CONTAINER_ADDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5329 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5330 | mPrivateFlags |= PFLAG_SCROLL_CONTAINER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5331 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5332 | if ((mPrivateFlags&PFLAG_SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5333 | mAttachInfo.mScrollContainers.remove(this); |
| 5334 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5335 | mPrivateFlags &= ~(PFLAG_SCROLL_CONTAINER|PFLAG_SCROLL_CONTAINER_ADDED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5336 | } |
| 5337 | } |
| 5338 | |
| 5339 | /** |
| 5340 | * Returns the quality of the drawing cache. |
| 5341 | * |
| 5342 | * @return One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 5343 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 5344 | * |
| 5345 | * @see #setDrawingCacheQuality(int) |
| 5346 | * @see #setDrawingCacheEnabled(boolean) |
| 5347 | * @see #isDrawingCacheEnabled() |
| 5348 | * |
| 5349 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 5350 | */ |
| 5351 | public int getDrawingCacheQuality() { |
| 5352 | return mViewFlags & DRAWING_CACHE_QUALITY_MASK; |
| 5353 | } |
| 5354 | |
| 5355 | /** |
| 5356 | * Set the drawing cache quality of this view. This value is used only when the |
| 5357 | * drawing cache is enabled |
| 5358 | * |
| 5359 | * @param quality One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 5360 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 5361 | * |
| 5362 | * @see #getDrawingCacheQuality() |
| 5363 | * @see #setDrawingCacheEnabled(boolean) |
| 5364 | * @see #isDrawingCacheEnabled() |
| 5365 | * |
| 5366 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 5367 | */ |
| 5368 | public void setDrawingCacheQuality(int quality) { |
| 5369 | setFlags(quality, DRAWING_CACHE_QUALITY_MASK); |
| 5370 | } |
| 5371 | |
| 5372 | /** |
| 5373 | * Returns whether the screen should remain on, corresponding to the current |
| 5374 | * value of {@link #KEEP_SCREEN_ON}. |
| 5375 | * |
| 5376 | * @return Returns true if {@link #KEEP_SCREEN_ON} is set. |
| 5377 | * |
| 5378 | * @see #setKeepScreenOn(boolean) |
| 5379 | * |
| 5380 | * @attr ref android.R.styleable#View_keepScreenOn |
| 5381 | */ |
| 5382 | public boolean getKeepScreenOn() { |
| 5383 | return (mViewFlags & KEEP_SCREEN_ON) != 0; |
| 5384 | } |
| 5385 | |
| 5386 | /** |
| 5387 | * Controls whether the screen should remain on, modifying the |
| 5388 | * value of {@link #KEEP_SCREEN_ON}. |
| 5389 | * |
| 5390 | * @param keepScreenOn Supply true to set {@link #KEEP_SCREEN_ON}. |
| 5391 | * |
| 5392 | * @see #getKeepScreenOn() |
| 5393 | * |
| 5394 | * @attr ref android.R.styleable#View_keepScreenOn |
| 5395 | */ |
| 5396 | public void setKeepScreenOn(boolean keepScreenOn) { |
| 5397 | setFlags(keepScreenOn ? KEEP_SCREEN_ON : 0, KEEP_SCREEN_ON); |
| 5398 | } |
| 5399 | |
| 5400 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5401 | * Gets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 5402 | * @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] | 5403 | * |
| 5404 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 5405 | */ |
| 5406 | public int getNextFocusLeftId() { |
| 5407 | return mNextFocusLeftId; |
| 5408 | } |
| 5409 | |
| 5410 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5411 | * Sets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 5412 | * @param nextFocusLeftId The next focus ID, or {@link #NO_ID} if the framework should |
| 5413 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5414 | * |
| 5415 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 5416 | */ |
| 5417 | public void setNextFocusLeftId(int nextFocusLeftId) { |
| 5418 | mNextFocusLeftId = nextFocusLeftId; |
| 5419 | } |
| 5420 | |
| 5421 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5422 | * Gets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 5423 | * @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] | 5424 | * |
| 5425 | * @attr ref android.R.styleable#View_nextFocusRight |
| 5426 | */ |
| 5427 | public int getNextFocusRightId() { |
| 5428 | return mNextFocusRightId; |
| 5429 | } |
| 5430 | |
| 5431 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5432 | * Sets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 5433 | * @param nextFocusRightId The next focus ID, or {@link #NO_ID} if the framework should |
| 5434 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5435 | * |
| 5436 | * @attr ref android.R.styleable#View_nextFocusRight |
| 5437 | */ |
| 5438 | public void setNextFocusRightId(int nextFocusRightId) { |
| 5439 | mNextFocusRightId = nextFocusRightId; |
| 5440 | } |
| 5441 | |
| 5442 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5443 | * Gets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 5444 | * @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] | 5445 | * |
| 5446 | * @attr ref android.R.styleable#View_nextFocusUp |
| 5447 | */ |
| 5448 | public int getNextFocusUpId() { |
| 5449 | return mNextFocusUpId; |
| 5450 | } |
| 5451 | |
| 5452 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5453 | * Sets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 5454 | * @param nextFocusUpId The next focus ID, or {@link #NO_ID} if the framework should |
| 5455 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5456 | * |
| 5457 | * @attr ref android.R.styleable#View_nextFocusUp |
| 5458 | */ |
| 5459 | public void setNextFocusUpId(int nextFocusUpId) { |
| 5460 | mNextFocusUpId = nextFocusUpId; |
| 5461 | } |
| 5462 | |
| 5463 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5464 | * Gets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 5465 | * @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] | 5466 | * |
| 5467 | * @attr ref android.R.styleable#View_nextFocusDown |
| 5468 | */ |
| 5469 | public int getNextFocusDownId() { |
| 5470 | return mNextFocusDownId; |
| 5471 | } |
| 5472 | |
| 5473 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5474 | * Sets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 5475 | * @param nextFocusDownId The next focus ID, or {@link #NO_ID} if the framework should |
| 5476 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5477 | * |
| 5478 | * @attr ref android.R.styleable#View_nextFocusDown |
| 5479 | */ |
| 5480 | public void setNextFocusDownId(int nextFocusDownId) { |
| 5481 | mNextFocusDownId = nextFocusDownId; |
| 5482 | } |
| 5483 | |
| 5484 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5485 | * Gets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 5486 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
| 5487 | * |
| 5488 | * @attr ref android.R.styleable#View_nextFocusForward |
| 5489 | */ |
| 5490 | public int getNextFocusForwardId() { |
| 5491 | return mNextFocusForwardId; |
| 5492 | } |
| 5493 | |
| 5494 | /** |
| 5495 | * Sets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 5496 | * @param nextFocusForwardId The next focus ID, or {@link #NO_ID} if the framework should |
| 5497 | * decide automatically. |
| 5498 | * |
| 5499 | * @attr ref android.R.styleable#View_nextFocusForward |
| 5500 | */ |
| 5501 | public void setNextFocusForwardId(int nextFocusForwardId) { |
| 5502 | mNextFocusForwardId = nextFocusForwardId; |
| 5503 | } |
| 5504 | |
| 5505 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5506 | * Returns the visibility of this view and all of its ancestors |
| 5507 | * |
| 5508 | * @return True if this view and all of its ancestors are {@link #VISIBLE} |
| 5509 | */ |
| 5510 | public boolean isShown() { |
| 5511 | View current = this; |
| 5512 | //noinspection ConstantConditions |
| 5513 | do { |
| 5514 | if ((current.mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 5515 | return false; |
| 5516 | } |
| 5517 | ViewParent parent = current.mParent; |
| 5518 | if (parent == null) { |
| 5519 | return false; // We are not attached to the view root |
| 5520 | } |
| 5521 | if (!(parent instanceof View)) { |
| 5522 | return true; |
| 5523 | } |
| 5524 | current = (View) parent; |
| 5525 | } while (current != null); |
| 5526 | |
| 5527 | return false; |
| 5528 | } |
| 5529 | |
| 5530 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5531 | * Called by the view hierarchy when the content insets for a window have |
| 5532 | * changed, to allow it to adjust its content to fit within those windows. |
| 5533 | * The content insets tell you the space that the status bar, input method, |
| 5534 | * 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] | 5535 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5536 | * <p>You do not normally need to deal with this function, since the default |
| 5537 | * window decoration given to applications takes care of applying it to the |
| 5538 | * content of the window. If you use {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} |
| 5539 | * or {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} this will not be the case, |
| 5540 | * and your content can be placed under those system elements. You can then |
| 5541 | * use this method within your view hierarchy if you have parts of your UI |
| 5542 | * 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] | 5543 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5544 | * <p>The default implementation of this method simply applies the content |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5545 | * inset's to the view's padding, consuming that content (modifying the |
| 5546 | * insets to be 0), and returning true. This behavior is off by default, but can |
| 5547 | * be enabled through {@link #setFitsSystemWindows(boolean)}. |
| 5548 | * |
| 5549 | * <p>This function's traversal down the hierarchy is depth-first. The same content |
| 5550 | * insets object is propagated down the hierarchy, so any changes made to it will |
| 5551 | * be seen by all following views (including potentially ones above in |
| 5552 | * the hierarchy since this is a depth-first traversal). The first view |
| 5553 | * that returns true will abort the entire traversal. |
| 5554 | * |
| 5555 | * <p>The default implementation works well for a situation where it is |
| 5556 | * used with a container that covers the entire window, allowing it to |
| 5557 | * apply the appropriate insets to its content on all edges. If you need |
| 5558 | * a more complicated layout (such as two different views fitting system |
| 5559 | * windows, one on the top of the window, and one on the bottom), |
| 5560 | * you can override the method and handle the insets however you would like. |
| 5561 | * Note that the insets provided by the framework are always relative to the |
| 5562 | * far edges of the window, not accounting for the location of the called view |
| 5563 | * 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] | 5564 | * where the layout will place the view, as it is done before layout happens.) |
| 5565 | * |
| 5566 | * <p>Note: unlike many View methods, there is no dispatch phase to this |
| 5567 | * call. If you are overriding it in a ViewGroup and want to allow the |
| 5568 | * call to continue to your children, you must be sure to call the super |
| 5569 | * implementation. |
| 5570 | * |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5571 | * <p>Here is a sample layout that makes use of fitting system windows |
| 5572 | * to have controls for a video view placed inside of the window decorations |
| 5573 | * that it hides and shows. This can be used with code like the second |
| 5574 | * sample (video player) shown in {@link #setSystemUiVisibility(int)}. |
| 5575 | * |
| 5576 | * {@sample development/samples/ApiDemos/res/layout/video_player.xml complete} |
| 5577 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5578 | * @param insets Current content insets of the window. Prior to |
| 5579 | * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} you must not modify |
| 5580 | * the insets or else you and Android will be unhappy. |
| 5581 | * |
| 5582 | * @return Return true if this view applied the insets and it should not |
| 5583 | * continue propagating further down the hierarchy, false otherwise. |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5584 | * @see #getFitsSystemWindows() |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5585 | * @see #setFitsSystemWindows(boolean) |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5586 | * @see #setSystemUiVisibility(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5587 | */ |
| 5588 | protected boolean fitSystemWindows(Rect insets) { |
| 5589 | if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) { |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 5590 | mUserPaddingStart = UNDEFINED_PADDING; |
| 5591 | mUserPaddingEnd = UNDEFINED_PADDING; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5592 | if ((mViewFlags & OPTIONAL_FITS_SYSTEM_WINDOWS) == 0 |
| 5593 | || mAttachInfo == null |
| 5594 | || (mAttachInfo.mSystemUiVisibility & SYSTEM_UI_LAYOUT_FLAGS) == 0) { |
| 5595 | internalSetPadding(insets.left, insets.top, insets.right, insets.bottom); |
| 5596 | return true; |
| 5597 | } else { |
| 5598 | internalSetPadding(0, 0, 0, 0); |
| 5599 | return false; |
| 5600 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5601 | } |
| 5602 | return false; |
| 5603 | } |
| 5604 | |
| 5605 | /** |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5606 | * Sets whether or not this view should account for system screen decorations |
| 5607 | * such as the status bar and inset its content; that is, controlling whether |
| 5608 | * the default implementation of {@link #fitSystemWindows(Rect)} will be |
| 5609 | * executed. See that method for more details. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5610 | * |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5611 | * <p>Note that if you are providing your own implementation of |
| 5612 | * {@link #fitSystemWindows(Rect)}, then there is no need to set this |
| 5613 | * flag to true -- your implementation will be overriding the default |
| 5614 | * implementation that checks this flag. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5615 | * |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5616 | * @param fitSystemWindows If true, then the default implementation of |
| 5617 | * {@link #fitSystemWindows(Rect)} will be executed. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5618 | * |
| 5619 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5620 | * @see #getFitsSystemWindows() |
| 5621 | * @see #fitSystemWindows(Rect) |
| 5622 | * @see #setSystemUiVisibility(int) |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5623 | */ |
| 5624 | public void setFitsSystemWindows(boolean fitSystemWindows) { |
| 5625 | setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS); |
| 5626 | } |
| 5627 | |
| 5628 | /** |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5629 | * Check for state of {@link #setFitsSystemWindows(boolean). If this method |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5630 | * returns true, the default implementation of {@link #fitSystemWindows(Rect)} |
| 5631 | * will be executed. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5632 | * |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5633 | * @return Returns true if the default implementation of |
| 5634 | * {@link #fitSystemWindows(Rect)} will be executed. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5635 | * |
| 5636 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5637 | * @see #setFitsSystemWindows() |
| 5638 | * @see #fitSystemWindows(Rect) |
| 5639 | * @see #setSystemUiVisibility(int) |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5640 | */ |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5641 | public boolean getFitsSystemWindows() { |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5642 | return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS; |
| 5643 | } |
| 5644 | |
Dianne Hackborn | b1b55e6 | 2012-05-10 16:25:54 -0700 | [diff] [blame] | 5645 | /** @hide */ |
| 5646 | public boolean fitsSystemWindows() { |
| 5647 | return getFitsSystemWindows(); |
| 5648 | } |
| 5649 | |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5650 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5651 | * Ask that a new dispatch of {@link #fitSystemWindows(Rect)} be performed. |
| 5652 | */ |
| 5653 | public void requestFitSystemWindows() { |
| 5654 | if (mParent != null) { |
| 5655 | mParent.requestFitSystemWindows(); |
| 5656 | } |
| 5657 | } |
| 5658 | |
| 5659 | /** |
| 5660 | * For use by PhoneWindow to make its own system window fitting optional. |
| 5661 | * @hide |
| 5662 | */ |
| 5663 | public void makeOptionalFitsSystemWindows() { |
| 5664 | setFlags(OPTIONAL_FITS_SYSTEM_WINDOWS, OPTIONAL_FITS_SYSTEM_WINDOWS); |
| 5665 | } |
| 5666 | |
| 5667 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5668 | * Returns the visibility status for this view. |
| 5669 | * |
| 5670 | * @return One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 5671 | * @attr ref android.R.styleable#View_visibility |
| 5672 | */ |
| 5673 | @ViewDebug.ExportedProperty(mapping = { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5674 | @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), |
| 5675 | @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), |
| 5676 | @ViewDebug.IntToString(from = GONE, to = "GONE") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5677 | }) |
| 5678 | public int getVisibility() { |
| 5679 | return mViewFlags & VISIBILITY_MASK; |
| 5680 | } |
| 5681 | |
| 5682 | /** |
| 5683 | * Set the enabled state of this view. |
| 5684 | * |
| 5685 | * @param visibility One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 5686 | * @attr ref android.R.styleable#View_visibility |
| 5687 | */ |
| 5688 | @RemotableViewMethod |
| 5689 | public void setVisibility(int visibility) { |
| 5690 | setFlags(visibility, VISIBILITY_MASK); |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5691 | if (mBackground != null) mBackground.setVisible(visibility == VISIBLE, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5692 | } |
| 5693 | |
| 5694 | /** |
| 5695 | * Returns the enabled status for this view. The interpretation of the |
| 5696 | * enabled state varies by subclass. |
| 5697 | * |
| 5698 | * @return True if this view is enabled, false otherwise. |
| 5699 | */ |
| 5700 | @ViewDebug.ExportedProperty |
| 5701 | public boolean isEnabled() { |
| 5702 | return (mViewFlags & ENABLED_MASK) == ENABLED; |
| 5703 | } |
| 5704 | |
| 5705 | /** |
| 5706 | * Set the enabled state of this view. The interpretation of the enabled |
| 5707 | * state varies by subclass. |
| 5708 | * |
| 5709 | * @param enabled True if this view is enabled, false otherwise. |
| 5710 | */ |
Jeff Sharkey | 2b95c24 | 2010-02-08 17:40:30 -0800 | [diff] [blame] | 5711 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5712 | public void setEnabled(boolean enabled) { |
Amith Yamasani | a2ef00b | 2009-07-30 16:14:34 -0700 | [diff] [blame] | 5713 | if (enabled == isEnabled()) return; |
| 5714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5715 | setFlags(enabled ? ENABLED : DISABLED, ENABLED_MASK); |
| 5716 | |
| 5717 | /* |
| 5718 | * The View most likely has to change its appearance, so refresh |
| 5719 | * the drawable state. |
| 5720 | */ |
| 5721 | refreshDrawableState(); |
| 5722 | |
| 5723 | // Invalidate too, since the default behavior for views is to be |
| 5724 | // be drawn at 50% alpha rather than to change the drawable. |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 5725 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5726 | } |
| 5727 | |
| 5728 | /** |
| 5729 | * Set whether this view can receive the focus. |
| 5730 | * |
| 5731 | * Setting this to false will also ensure that this view is not focusable |
| 5732 | * in touch mode. |
| 5733 | * |
| 5734 | * @param focusable If true, this view can receive the focus. |
| 5735 | * |
| 5736 | * @see #setFocusableInTouchMode(boolean) |
| 5737 | * @attr ref android.R.styleable#View_focusable |
| 5738 | */ |
| 5739 | public void setFocusable(boolean focusable) { |
| 5740 | if (!focusable) { |
| 5741 | setFlags(0, FOCUSABLE_IN_TOUCH_MODE); |
| 5742 | } |
| 5743 | setFlags(focusable ? FOCUSABLE : NOT_FOCUSABLE, FOCUSABLE_MASK); |
| 5744 | } |
| 5745 | |
| 5746 | /** |
| 5747 | * Set whether this view can receive focus while in touch mode. |
| 5748 | * |
| 5749 | * Setting this to true will also ensure that this view is focusable. |
| 5750 | * |
| 5751 | * @param focusableInTouchMode If true, this view can receive the focus while |
| 5752 | * in touch mode. |
| 5753 | * |
| 5754 | * @see #setFocusable(boolean) |
| 5755 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 5756 | */ |
| 5757 | public void setFocusableInTouchMode(boolean focusableInTouchMode) { |
| 5758 | // Focusable in touch mode should always be set before the focusable flag |
| 5759 | // otherwise, setting the focusable flag will trigger a focusableViewAvailable() |
| 5760 | // which, in touch mode, will not successfully request focus on this view |
| 5761 | // because the focusable in touch mode flag is not set |
| 5762 | setFlags(focusableInTouchMode ? FOCUSABLE_IN_TOUCH_MODE : 0, FOCUSABLE_IN_TOUCH_MODE); |
| 5763 | if (focusableInTouchMode) { |
| 5764 | setFlags(FOCUSABLE, FOCUSABLE_MASK); |
| 5765 | } |
| 5766 | } |
| 5767 | |
| 5768 | /** |
| 5769 | * Set whether this view should have sound effects enabled for events such as |
| 5770 | * clicking and touching. |
| 5771 | * |
| 5772 | * <p>You may wish to disable sound effects for a view if you already play sounds, |
| 5773 | * for instance, a dial key that plays dtmf tones. |
| 5774 | * |
| 5775 | * @param soundEffectsEnabled whether sound effects are enabled for this view. |
| 5776 | * @see #isSoundEffectsEnabled() |
| 5777 | * @see #playSoundEffect(int) |
| 5778 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5779 | */ |
| 5780 | public void setSoundEffectsEnabled(boolean soundEffectsEnabled) { |
| 5781 | setFlags(soundEffectsEnabled ? SOUND_EFFECTS_ENABLED: 0, SOUND_EFFECTS_ENABLED); |
| 5782 | } |
| 5783 | |
| 5784 | /** |
| 5785 | * @return whether this view should have sound effects enabled for events such as |
| 5786 | * clicking and touching. |
| 5787 | * |
| 5788 | * @see #setSoundEffectsEnabled(boolean) |
| 5789 | * @see #playSoundEffect(int) |
| 5790 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5791 | */ |
| 5792 | @ViewDebug.ExportedProperty |
| 5793 | public boolean isSoundEffectsEnabled() { |
| 5794 | return SOUND_EFFECTS_ENABLED == (mViewFlags & SOUND_EFFECTS_ENABLED); |
| 5795 | } |
| 5796 | |
| 5797 | /** |
| 5798 | * Set whether this view should have haptic feedback for events such as |
| 5799 | * long presses. |
| 5800 | * |
| 5801 | * <p>You may wish to disable haptic feedback if your view already controls |
| 5802 | * its own haptic feedback. |
| 5803 | * |
| 5804 | * @param hapticFeedbackEnabled whether haptic feedback enabled for this view. |
| 5805 | * @see #isHapticFeedbackEnabled() |
| 5806 | * @see #performHapticFeedback(int) |
| 5807 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5808 | */ |
| 5809 | public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) { |
| 5810 | setFlags(hapticFeedbackEnabled ? HAPTIC_FEEDBACK_ENABLED: 0, HAPTIC_FEEDBACK_ENABLED); |
| 5811 | } |
| 5812 | |
| 5813 | /** |
| 5814 | * @return whether this view should have haptic feedback enabled for events |
| 5815 | * long presses. |
| 5816 | * |
| 5817 | * @see #setHapticFeedbackEnabled(boolean) |
| 5818 | * @see #performHapticFeedback(int) |
| 5819 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5820 | */ |
| 5821 | @ViewDebug.ExportedProperty |
| 5822 | public boolean isHapticFeedbackEnabled() { |
| 5823 | return HAPTIC_FEEDBACK_ENABLED == (mViewFlags & HAPTIC_FEEDBACK_ENABLED); |
| 5824 | } |
| 5825 | |
| 5826 | /** |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5827 | * Returns the layout direction for this view. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5828 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5829 | * @return One of {@link #LAYOUT_DIRECTION_LTR}, |
| 5830 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5831 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 5832 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
| 5833 | * @attr ref android.R.styleable#View_layoutDirection |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5834 | * |
| 5835 | * @hide |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5836 | */ |
Fabrice Di Meglio | bce84d2 | 2011-06-02 15:57:01 -0700 | [diff] [blame] | 5837 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5838 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "LTR"), |
| 5839 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RTL"), |
| 5840 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"), |
| 5841 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE") |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5842 | }) |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5843 | public int getRawLayoutDirection() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5844 | return (mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >> PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5845 | } |
| 5846 | |
| 5847 | /** |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5848 | * Set the layout direction for this view. This will propagate a reset of layout direction |
| 5849 | * 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] | 5850 | * |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5851 | * @param layoutDirection the layout direction to set. Should be one of: |
| 5852 | * |
| 5853 | * {@link #LAYOUT_DIRECTION_LTR}, |
| 5854 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5855 | * {@link #LAYOUT_DIRECTION_INHERIT}, |
| 5856 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
| 5857 | * |
| 5858 | * Resolution will be done if the value is set to LAYOUT_DIRECTION_INHERIT. The resolution |
| 5859 | * proceeds up the parent chain of the view to get the value. If there is no parent, then it |
| 5860 | * will return the default {@link #LAYOUT_DIRECTION_LTR}. |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5861 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5862 | * @attr ref android.R.styleable#View_layoutDirection |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5863 | */ |
| 5864 | @RemotableViewMethod |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5865 | public void setLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 5866 | if (getRawLayoutDirection() != layoutDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 5867 | // Reset the current layout direction and the resolved one |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5868 | mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_MASK; |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 5869 | resetRtlProperties(); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 5870 | // Set the new layout direction (filtered) |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5871 | mPrivateFlags2 |= |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5872 | ((layoutDirection << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) & PFLAG2_LAYOUT_DIRECTION_MASK); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5873 | // We need to resolve all RTL properties as they all depend on layout direction |
| 5874 | resolveRtlPropertiesIfNeeded(); |
Fabrice Di Meglio | acb1c12 | 2012-10-02 14:18:55 -0700 | [diff] [blame] | 5875 | requestLayout(); |
| 5876 | invalidate(true); |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5877 | } |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5878 | } |
| 5879 | |
| 5880 | /** |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5881 | * Returns the resolved layout direction for this view. |
| 5882 | * |
| 5883 | * @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] | 5884 | * {@link #LAYOUT_DIRECTION_LTR} if the layout direction is not RTL. |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5885 | * |
| 5886 | * For compatibility, this will return {@link #LAYOUT_DIRECTION_LTR} if API version |
| 5887 | * is lower than {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}. |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5888 | */ |
| 5889 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5890 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"), |
| 5891 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL") |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5892 | }) |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 5893 | public int getLayoutDirection() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 5894 | final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion; |
| 5895 | if (targetSdkVersion < JELLY_BEAN_MR1) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5896 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 5897 | return LAYOUT_DIRECTION_LTR; |
| 5898 | } |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5899 | return ((mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL) == |
| 5900 | PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL) ? LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5901 | } |
| 5902 | |
| 5903 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5904 | * Indicates whether or not this view's layout is right-to-left. This is resolved from |
| 5905 | * layout attribute and/or the inherited value from the parent |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5906 | * |
| 5907 | * @return true if the layout is right-to-left. |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 5908 | * |
| 5909 | * @hide |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5910 | */ |
| 5911 | @ViewDebug.ExportedProperty(category = "layout") |
| 5912 | public boolean isLayoutRtl() { |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 5913 | return (getLayoutDirection() == LAYOUT_DIRECTION_RTL); |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5914 | } |
| 5915 | |
| 5916 | /** |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5917 | * Indicates whether the view is currently tracking transient state that the |
| 5918 | * app should not need to concern itself with saving and restoring, but that |
| 5919 | * the framework should take special note to preserve when possible. |
| 5920 | * |
Adam Powell | 785c447 | 2012-05-02 21:25:39 -0700 | [diff] [blame] | 5921 | * <p>A view with transient state cannot be trivially rebound from an external |
| 5922 | * data source, such as an adapter binding item views in a list. This may be |
| 5923 | * because the view is performing an animation, tracking user selection |
| 5924 | * of content, or similar.</p> |
| 5925 | * |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5926 | * @return true if the view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5927 | */ |
| 5928 | @ViewDebug.ExportedProperty(category = "layout") |
| 5929 | public boolean hasTransientState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5930 | return (mPrivateFlags2 & PFLAG2_HAS_TRANSIENT_STATE) == PFLAG2_HAS_TRANSIENT_STATE; |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5931 | } |
| 5932 | |
| 5933 | /** |
| 5934 | * Set whether this view is currently tracking transient state that the |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 5935 | * framework should attempt to preserve when possible. This flag is reference counted, |
| 5936 | * so every call to setHasTransientState(true) should be paired with a later call |
| 5937 | * to setHasTransientState(false). |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5938 | * |
Adam Powell | 785c447 | 2012-05-02 21:25:39 -0700 | [diff] [blame] | 5939 | * <p>A view with transient state cannot be trivially rebound from an external |
| 5940 | * data source, such as an adapter binding item views in a list. This may be |
| 5941 | * because the view is performing an animation, tracking user selection |
| 5942 | * of content, or similar.</p> |
| 5943 | * |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5944 | * @param hasTransientState true if this view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5945 | */ |
| 5946 | public void setHasTransientState(boolean hasTransientState) { |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 5947 | mTransientStateCount = hasTransientState ? mTransientStateCount + 1 : |
| 5948 | mTransientStateCount - 1; |
| 5949 | if (mTransientStateCount < 0) { |
| 5950 | mTransientStateCount = 0; |
| 5951 | Log.e(VIEW_LOG_TAG, "hasTransientState decremented below 0: " + |
| 5952 | "unmatched pair of setHasTransientState calls"); |
| 5953 | } |
| 5954 | if ((hasTransientState && mTransientStateCount == 1) || |
Adam Powell | 057a585 | 2012-05-11 10:28:38 -0700 | [diff] [blame] | 5955 | (!hasTransientState && mTransientStateCount == 0)) { |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 5956 | // 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] | 5957 | mPrivateFlags2 = (mPrivateFlags2 & ~PFLAG2_HAS_TRANSIENT_STATE) | |
| 5958 | (hasTransientState ? PFLAG2_HAS_TRANSIENT_STATE : 0); |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 5959 | if (mParent != null) { |
| 5960 | try { |
| 5961 | mParent.childHasTransientStateChanged(this, hasTransientState); |
| 5962 | } catch (AbstractMethodError e) { |
| 5963 | Log.e(VIEW_LOG_TAG, mParent.getClass().getSimpleName() + |
| 5964 | " does not fully implement ViewParent", e); |
| 5965 | } |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5966 | } |
| 5967 | } |
| 5968 | } |
| 5969 | |
| 5970 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5971 | * If this view doesn't do any drawing on its own, set this flag to |
| 5972 | * allow further optimizations. By default, this flag is not set on |
| 5973 | * View, but could be set on some View subclasses such as ViewGroup. |
| 5974 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5975 | * Typically, if you override {@link #onDraw(android.graphics.Canvas)} |
| 5976 | * you should clear this flag. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5977 | * |
| 5978 | * @param willNotDraw whether or not this View draw on its own |
| 5979 | */ |
| 5980 | public void setWillNotDraw(boolean willNotDraw) { |
| 5981 | setFlags(willNotDraw ? WILL_NOT_DRAW : 0, DRAW_MASK); |
| 5982 | } |
| 5983 | |
| 5984 | /** |
| 5985 | * Returns whether or not this View draws on its own. |
| 5986 | * |
| 5987 | * @return true if this view has nothing to draw, false otherwise |
| 5988 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5989 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5990 | public boolean willNotDraw() { |
| 5991 | return (mViewFlags & DRAW_MASK) == WILL_NOT_DRAW; |
| 5992 | } |
| 5993 | |
| 5994 | /** |
| 5995 | * When a View's drawing cache is enabled, drawing is redirected to an |
| 5996 | * offscreen bitmap. Some views, like an ImageView, must be able to |
| 5997 | * bypass this mechanism if they already draw a single bitmap, to avoid |
| 5998 | * unnecessary usage of the memory. |
| 5999 | * |
| 6000 | * @param willNotCacheDrawing true if this view does not cache its |
| 6001 | * drawing, false otherwise |
| 6002 | */ |
| 6003 | public void setWillNotCacheDrawing(boolean willNotCacheDrawing) { |
| 6004 | setFlags(willNotCacheDrawing ? WILL_NOT_CACHE_DRAWING : 0, WILL_NOT_CACHE_DRAWING); |
| 6005 | } |
| 6006 | |
| 6007 | /** |
| 6008 | * Returns whether or not this View can cache its drawing or not. |
| 6009 | * |
| 6010 | * @return true if this view does not cache its drawing, false otherwise |
| 6011 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 6012 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6013 | public boolean willNotCacheDrawing() { |
| 6014 | return (mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING; |
| 6015 | } |
| 6016 | |
| 6017 | /** |
| 6018 | * Indicates whether this view reacts to click events or not. |
| 6019 | * |
| 6020 | * @return true if the view is clickable, false otherwise |
| 6021 | * |
| 6022 | * @see #setClickable(boolean) |
| 6023 | * @attr ref android.R.styleable#View_clickable |
| 6024 | */ |
| 6025 | @ViewDebug.ExportedProperty |
| 6026 | public boolean isClickable() { |
| 6027 | return (mViewFlags & CLICKABLE) == CLICKABLE; |
| 6028 | } |
| 6029 | |
| 6030 | /** |
| 6031 | * Enables or disables click events for this view. When a view |
| 6032 | * is clickable it will change its state to "pressed" on every click. |
| 6033 | * Subclasses should set the view clickable to visually react to |
| 6034 | * user's clicks. |
| 6035 | * |
| 6036 | * @param clickable true to make the view clickable, false otherwise |
| 6037 | * |
| 6038 | * @see #isClickable() |
| 6039 | * @attr ref android.R.styleable#View_clickable |
| 6040 | */ |
| 6041 | public void setClickable(boolean clickable) { |
| 6042 | setFlags(clickable ? CLICKABLE : 0, CLICKABLE); |
| 6043 | } |
| 6044 | |
| 6045 | /** |
| 6046 | * Indicates whether this view reacts to long click events or not. |
| 6047 | * |
| 6048 | * @return true if the view is long clickable, false otherwise |
| 6049 | * |
| 6050 | * @see #setLongClickable(boolean) |
| 6051 | * @attr ref android.R.styleable#View_longClickable |
| 6052 | */ |
| 6053 | public boolean isLongClickable() { |
| 6054 | return (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 6055 | } |
| 6056 | |
| 6057 | /** |
| 6058 | * Enables or disables long click events for this view. When a view is long |
| 6059 | * clickable it reacts to the user holding down the button for a longer |
| 6060 | * duration than a tap. This event can either launch the listener or a |
| 6061 | * context menu. |
| 6062 | * |
| 6063 | * @param longClickable true to make the view long clickable, false otherwise |
| 6064 | * @see #isLongClickable() |
| 6065 | * @attr ref android.R.styleable#View_longClickable |
| 6066 | */ |
| 6067 | public void setLongClickable(boolean longClickable) { |
| 6068 | setFlags(longClickable ? LONG_CLICKABLE : 0, LONG_CLICKABLE); |
| 6069 | } |
| 6070 | |
| 6071 | /** |
Chet Haase | 49afa5b | 2010-08-23 11:39:53 -0700 | [diff] [blame] | 6072 | * Sets the pressed state for this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6073 | * |
| 6074 | * @see #isClickable() |
| 6075 | * @see #setClickable(boolean) |
| 6076 | * |
| 6077 | * @param pressed Pass true to set the View's internal state to "pressed", or false to reverts |
| 6078 | * the View's internal state from a previously set "pressed" state. |
| 6079 | */ |
| 6080 | public void setPressed(boolean pressed) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6081 | final boolean needsRefresh = pressed != ((mPrivateFlags & PFLAG_PRESSED) == PFLAG_PRESSED); |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 6082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6083 | if (pressed) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6084 | mPrivateFlags |= PFLAG_PRESSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6085 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6086 | mPrivateFlags &= ~PFLAG_PRESSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6087 | } |
Adam Powell | 035a1fc | 2012-02-27 15:23:50 -0800 | [diff] [blame] | 6088 | |
| 6089 | if (needsRefresh) { |
| 6090 | refreshDrawableState(); |
| 6091 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6092 | dispatchSetPressed(pressed); |
| 6093 | } |
| 6094 | |
| 6095 | /** |
| 6096 | * Dispatch setPressed to all of this View's children. |
| 6097 | * |
| 6098 | * @see #setPressed(boolean) |
| 6099 | * |
| 6100 | * @param pressed The new pressed state |
| 6101 | */ |
| 6102 | protected void dispatchSetPressed(boolean pressed) { |
| 6103 | } |
| 6104 | |
| 6105 | /** |
| 6106 | * Indicates whether the view is currently in pressed state. Unless |
| 6107 | * {@link #setPressed(boolean)} is explicitly called, only clickable views can enter |
| 6108 | * the pressed state. |
| 6109 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 6110 | * @see #setPressed(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6111 | * @see #isClickable() |
| 6112 | * @see #setClickable(boolean) |
| 6113 | * |
| 6114 | * @return true if the view is currently pressed, false otherwise |
| 6115 | */ |
| 6116 | public boolean isPressed() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6117 | return (mPrivateFlags & PFLAG_PRESSED) == PFLAG_PRESSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6118 | } |
| 6119 | |
| 6120 | /** |
| 6121 | * Indicates whether this view will save its state (that is, |
| 6122 | * whether its {@link #onSaveInstanceState} method will be called). |
| 6123 | * |
| 6124 | * @return Returns true if the view state saving is enabled, else false. |
| 6125 | * |
| 6126 | * @see #setSaveEnabled(boolean) |
| 6127 | * @attr ref android.R.styleable#View_saveEnabled |
| 6128 | */ |
| 6129 | public boolean isSaveEnabled() { |
| 6130 | return (mViewFlags & SAVE_DISABLED_MASK) != SAVE_DISABLED; |
| 6131 | } |
| 6132 | |
| 6133 | /** |
| 6134 | * Controls whether the saving of this view's state is |
| 6135 | * enabled (that is, whether its {@link #onSaveInstanceState} method |
| 6136 | * will be called). Note that even if freezing is enabled, the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6137 | * 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] | 6138 | * for its state to be saved. This flag can only disable the |
| 6139 | * saving of this view; any child views may still have their state saved. |
| 6140 | * |
| 6141 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 6142 | * (the default) to allow it. |
| 6143 | * |
| 6144 | * @see #isSaveEnabled() |
| 6145 | * @see #setId(int) |
| 6146 | * @see #onSaveInstanceState() |
| 6147 | * @attr ref android.R.styleable#View_saveEnabled |
| 6148 | */ |
| 6149 | public void setSaveEnabled(boolean enabled) { |
| 6150 | setFlags(enabled ? 0 : SAVE_DISABLED, SAVE_DISABLED_MASK); |
| 6151 | } |
| 6152 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6153 | /** |
| 6154 | * Gets whether the framework should discard touches when the view's |
| 6155 | * window is obscured by another visible window. |
| 6156 | * Refer to the {@link View} security documentation for more details. |
| 6157 | * |
| 6158 | * @return True if touch filtering is enabled. |
| 6159 | * |
| 6160 | * @see #setFilterTouchesWhenObscured(boolean) |
| 6161 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 6162 | */ |
| 6163 | @ViewDebug.ExportedProperty |
| 6164 | public boolean getFilterTouchesWhenObscured() { |
| 6165 | return (mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0; |
| 6166 | } |
| 6167 | |
| 6168 | /** |
| 6169 | * Sets whether the framework should discard touches when the view's |
| 6170 | * window is obscured by another visible window. |
| 6171 | * Refer to the {@link View} security documentation for more details. |
| 6172 | * |
| 6173 | * @param enabled True if touch filtering should be enabled. |
| 6174 | * |
| 6175 | * @see #getFilterTouchesWhenObscured |
| 6176 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 6177 | */ |
| 6178 | public void setFilterTouchesWhenObscured(boolean enabled) { |
| 6179 | setFlags(enabled ? 0 : FILTER_TOUCHES_WHEN_OBSCURED, |
| 6180 | FILTER_TOUCHES_WHEN_OBSCURED); |
| 6181 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6182 | |
| 6183 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 6184 | * Indicates whether the entire hierarchy under this view will save its |
| 6185 | * state when a state saving traversal occurs from its parent. The default |
| 6186 | * is true; if false, these views will not be saved unless |
| 6187 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 6188 | * |
| 6189 | * @return Returns true if the view state saving from parent is enabled, else false. |
| 6190 | * |
| 6191 | * @see #setSaveFromParentEnabled(boolean) |
| 6192 | */ |
| 6193 | public boolean isSaveFromParentEnabled() { |
| 6194 | return (mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED; |
| 6195 | } |
| 6196 | |
| 6197 | /** |
| 6198 | * Controls whether the entire hierarchy under this view will save its |
| 6199 | * state when a state saving traversal occurs from its parent. The default |
| 6200 | * is true; if false, these views will not be saved unless |
| 6201 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 6202 | * |
| 6203 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 6204 | * (the default) to allow it. |
| 6205 | * |
| 6206 | * @see #isSaveFromParentEnabled() |
| 6207 | * @see #setId(int) |
| 6208 | * @see #onSaveInstanceState() |
| 6209 | */ |
| 6210 | public void setSaveFromParentEnabled(boolean enabled) { |
| 6211 | setFlags(enabled ? 0 : PARENT_SAVE_DISABLED, PARENT_SAVE_DISABLED_MASK); |
| 6212 | } |
| 6213 | |
| 6214 | |
| 6215 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6216 | * Returns whether this View is able to take focus. |
| 6217 | * |
| 6218 | * @return True if this view can take focus, or false otherwise. |
| 6219 | * @attr ref android.R.styleable#View_focusable |
| 6220 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 6221 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6222 | public final boolean isFocusable() { |
| 6223 | return FOCUSABLE == (mViewFlags & FOCUSABLE_MASK); |
| 6224 | } |
| 6225 | |
| 6226 | /** |
| 6227 | * When a view is focusable, it may not want to take focus when in touch mode. |
| 6228 | * For example, a button would like focus when the user is navigating via a D-pad |
| 6229 | * so that the user can click on it, but once the user starts touching the screen, |
| 6230 | * the button shouldn't take focus |
| 6231 | * @return Whether the view is focusable in touch mode. |
| 6232 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 6233 | */ |
| 6234 | @ViewDebug.ExportedProperty |
| 6235 | public final boolean isFocusableInTouchMode() { |
| 6236 | return FOCUSABLE_IN_TOUCH_MODE == (mViewFlags & FOCUSABLE_IN_TOUCH_MODE); |
| 6237 | } |
| 6238 | |
| 6239 | /** |
| 6240 | * Find the nearest view in the specified direction that can take focus. |
| 6241 | * This does not actually give focus to that view. |
| 6242 | * |
| 6243 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6244 | * |
| 6245 | * @return The nearest focusable in the specified direction, or null if none |
| 6246 | * can be found. |
| 6247 | */ |
| 6248 | public View focusSearch(int direction) { |
| 6249 | if (mParent != null) { |
| 6250 | return mParent.focusSearch(this, direction); |
| 6251 | } else { |
| 6252 | return null; |
| 6253 | } |
| 6254 | } |
| 6255 | |
| 6256 | /** |
| 6257 | * This method is the last chance for the focused view and its ancestors to |
| 6258 | * respond to an arrow key. This is called when the focused view did not |
| 6259 | * consume the key internally, nor could the view system find a new view in |
| 6260 | * the requested direction to give focus to. |
| 6261 | * |
| 6262 | * @param focused The currently focused view. |
| 6263 | * @param direction The direction focus wants to move. One of FOCUS_UP, |
| 6264 | * FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. |
| 6265 | * @return True if the this view consumed this unhandled move. |
| 6266 | */ |
| 6267 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 6268 | return false; |
| 6269 | } |
| 6270 | |
| 6271 | /** |
| 6272 | * 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] | 6273 | * use the root to look up the view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6274 | * @param root The root view of the hierarchy containing this view. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6275 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, |
| 6276 | * or FOCUS_BACKWARD. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6277 | * @return The user specified next view, or null if there is none. |
| 6278 | */ |
| 6279 | View findUserSetNextFocus(View root, int direction) { |
| 6280 | switch (direction) { |
| 6281 | case FOCUS_LEFT: |
| 6282 | if (mNextFocusLeftId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6283 | return findViewInsideOutShouldExist(root, mNextFocusLeftId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6284 | case FOCUS_RIGHT: |
| 6285 | if (mNextFocusRightId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6286 | return findViewInsideOutShouldExist(root, mNextFocusRightId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6287 | case FOCUS_UP: |
| 6288 | if (mNextFocusUpId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6289 | return findViewInsideOutShouldExist(root, mNextFocusUpId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6290 | case FOCUS_DOWN: |
| 6291 | if (mNextFocusDownId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6292 | return findViewInsideOutShouldExist(root, mNextFocusDownId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6293 | case FOCUS_FORWARD: |
| 6294 | if (mNextFocusForwardId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6295 | return findViewInsideOutShouldExist(root, mNextFocusForwardId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6296 | case FOCUS_BACKWARD: { |
John Reck | 1ecebbb | 2012-03-06 16:08:54 -0800 | [diff] [blame] | 6297 | if (mID == View.NO_ID) return null; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6298 | final int id = mID; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6299 | return root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6300 | @Override |
| 6301 | public boolean apply(View t) { |
| 6302 | return t.mNextFocusForwardId == id; |
| 6303 | } |
| 6304 | }); |
| 6305 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6306 | } |
| 6307 | return null; |
| 6308 | } |
| 6309 | |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 6310 | private View findViewInsideOutShouldExist(View root, int id) { |
| 6311 | if (mMatchIdPredicate == null) { |
| 6312 | mMatchIdPredicate = new MatchIdPredicate(); |
| 6313 | } |
| 6314 | mMatchIdPredicate.mId = id; |
| 6315 | View result = root.findViewByPredicateInsideOut(this, mMatchIdPredicate); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6316 | if (result == null) { |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 6317 | 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] | 6318 | } |
| 6319 | return result; |
| 6320 | } |
| 6321 | |
| 6322 | /** |
| 6323 | * Find and return all focusable views that are descendants of this view, |
| 6324 | * possibly including this view if it is focusable itself. |
| 6325 | * |
| 6326 | * @param direction The direction of the focus |
| 6327 | * @return A list of focusable views |
| 6328 | */ |
| 6329 | public ArrayList<View> getFocusables(int direction) { |
| 6330 | ArrayList<View> result = new ArrayList<View>(24); |
| 6331 | addFocusables(result, direction); |
| 6332 | return result; |
| 6333 | } |
| 6334 | |
| 6335 | /** |
| 6336 | * Add any focusable views that are descendants of this view (possibly |
| 6337 | * including this view if it is focusable itself) to views. If we are in touch mode, |
| 6338 | * only add views that are also focusable in touch mode. |
| 6339 | * |
| 6340 | * @param views Focusable views found so far |
| 6341 | * @param direction The direction of the focus |
| 6342 | */ |
| 6343 | public void addFocusables(ArrayList<View> views, int direction) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6344 | addFocusables(views, direction, FOCUSABLES_TOUCH_MODE); |
| 6345 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6346 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6347 | /** |
| 6348 | * Adds any focusable views that are descendants of this view (possibly |
| 6349 | * including this view if it is focusable itself) to views. This method |
| 6350 | * adds all focusable views regardless if we are in touch mode or |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6351 | * only views focusable in touch mode if we are in touch mode or |
| 6352 | * only views that can take accessibility focus if accessibility is enabeld |
| 6353 | * depending on the focusable mode paramater. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6354 | * |
| 6355 | * @param views Focusable views found so far or null if all we are interested is |
| 6356 | * the number of focusables. |
| 6357 | * @param direction The direction of the focus. |
| 6358 | * @param focusableMode The type of focusables to be added. |
| 6359 | * |
| 6360 | * @see #FOCUSABLES_ALL |
| 6361 | * @see #FOCUSABLES_TOUCH_MODE |
| 6362 | */ |
| 6363 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6364 | if (views == null) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6365 | return; |
| 6366 | } |
Svetoslav Ganov | 3cb889c | 2012-04-16 19:10:30 -0700 | [diff] [blame] | 6367 | if (!isFocusable()) { |
| 6368 | return; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6369 | } |
Svetoslav Ganov | 3cb889c | 2012-04-16 19:10:30 -0700 | [diff] [blame] | 6370 | if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE |
| 6371 | && isInTouchMode() && !isFocusableInTouchMode()) { |
| 6372 | return; |
| 6373 | } |
| 6374 | views.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6375 | } |
| 6376 | |
| 6377 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6378 | * Finds the Views that contain given text. The containment is case insensitive. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6379 | * The search is performed by either the text that the View renders or the content |
| 6380 | * description that describes the view for accessibility purposes and the view does |
| 6381 | * not render or both. Clients can specify how the search is to be performed via |
| 6382 | * passing the {@link #FIND_VIEWS_WITH_TEXT} and |
| 6383 | * {@link #FIND_VIEWS_WITH_CONTENT_DESCRIPTION} flags. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6384 | * |
| 6385 | * @param outViews The output list of matching Views. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6386 | * @param searched The text to match against. |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 6387 | * |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6388 | * @see #FIND_VIEWS_WITH_TEXT |
| 6389 | * @see #FIND_VIEWS_WITH_CONTENT_DESCRIPTION |
| 6390 | * @see #setContentDescription(CharSequence) |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6391 | */ |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6392 | public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 6393 | if (getAccessibilityNodeProvider() != null) { |
| 6394 | if ((flags & FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS) != 0) { |
| 6395 | outViews.add(this); |
| 6396 | } |
| 6397 | } else if ((flags & FIND_VIEWS_WITH_CONTENT_DESCRIPTION) != 0 |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6398 | && (searched != null && searched.length() > 0) |
| 6399 | && (mContentDescription != null && mContentDescription.length() > 0)) { |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6400 | String searchedLowerCase = searched.toString().toLowerCase(); |
| 6401 | String contentDescriptionLowerCase = mContentDescription.toString().toLowerCase(); |
| 6402 | if (contentDescriptionLowerCase.contains(searchedLowerCase)) { |
| 6403 | outViews.add(this); |
| 6404 | } |
| 6405 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6406 | } |
| 6407 | |
| 6408 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6409 | * Find and return all touchable views that are descendants of this view, |
| 6410 | * possibly including this view if it is touchable itself. |
| 6411 | * |
| 6412 | * @return A list of touchable views |
| 6413 | */ |
| 6414 | public ArrayList<View> getTouchables() { |
| 6415 | ArrayList<View> result = new ArrayList<View>(); |
| 6416 | addTouchables(result); |
| 6417 | return result; |
| 6418 | } |
| 6419 | |
| 6420 | /** |
| 6421 | * Add any touchable views that are descendants of this view (possibly |
| 6422 | * including this view if it is touchable itself) to views. |
| 6423 | * |
| 6424 | * @param views Touchable views found so far |
| 6425 | */ |
| 6426 | public void addTouchables(ArrayList<View> views) { |
| 6427 | final int viewFlags = mViewFlags; |
| 6428 | |
| 6429 | if (((viewFlags & CLICKABLE) == CLICKABLE || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) |
| 6430 | && (viewFlags & ENABLED_MASK) == ENABLED) { |
| 6431 | views.add(this); |
| 6432 | } |
| 6433 | } |
| 6434 | |
| 6435 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6436 | * Returns whether this View is accessibility focused. |
| 6437 | * |
| 6438 | * @return True if this View is accessibility focused. |
| 6439 | */ |
| 6440 | boolean isAccessibilityFocused() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6441 | return (mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6442 | } |
| 6443 | |
| 6444 | /** |
| 6445 | * Call this to try to give accessibility focus to this view. |
| 6446 | * |
| 6447 | * A view will not actually take focus if {@link AccessibilityManager#isEnabled()} |
| 6448 | * returns false or the view is no visible or the view already has accessibility |
| 6449 | * focus. |
| 6450 | * |
| 6451 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
| 6452 | * have focus, and you want your parent to look for the next one. |
| 6453 | * |
| 6454 | * @return Whether this view actually took accessibility focus. |
| 6455 | * |
| 6456 | * @hide |
| 6457 | */ |
| 6458 | public boolean requestAccessibilityFocus() { |
Svetoslav Ganov | 07b726c | 2012-04-30 12:24:57 -0700 | [diff] [blame] | 6459 | AccessibilityManager manager = AccessibilityManager.getInstance(mContext); |
| 6460 | if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6461 | return false; |
| 6462 | } |
| 6463 | if ((mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 6464 | return false; |
| 6465 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6466 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) == 0) { |
| 6467 | mPrivateFlags2 |= PFLAG2_ACCESSIBILITY_FOCUSED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6468 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 6469 | if (viewRootImpl != null) { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6470 | viewRootImpl.setAccessibilityFocus(this, null); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6471 | } |
| 6472 | invalidate(); |
| 6473 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED); |
| 6474 | notifyAccessibilityStateChanged(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6475 | return true; |
| 6476 | } |
| 6477 | return false; |
| 6478 | } |
| 6479 | |
| 6480 | /** |
| 6481 | * Call this to try to clear accessibility focus of this view. |
| 6482 | * |
| 6483 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
| 6484 | * have focus, and you want your parent to look for the next one. |
| 6485 | * |
| 6486 | * @hide |
| 6487 | */ |
| 6488 | public void clearAccessibilityFocus() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6489 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0) { |
| 6490 | mPrivateFlags2 &= ~PFLAG2_ACCESSIBILITY_FOCUSED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6491 | invalidate(); |
| 6492 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED); |
| 6493 | notifyAccessibilityStateChanged(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6494 | } |
Svetoslav Ganov | c00d008 | 2012-05-22 18:37:49 -0700 | [diff] [blame] | 6495 | // Clear the global reference of accessibility focus if this |
| 6496 | // view or any of its descendants had accessibility focus. |
| 6497 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 6498 | if (viewRootImpl != null) { |
| 6499 | View focusHost = viewRootImpl.getAccessibilityFocusedHost(); |
| 6500 | if (focusHost != null && ViewRootImpl.isViewDescendantOf(focusHost, this)) { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6501 | viewRootImpl.setAccessibilityFocus(null, null); |
Svetoslav Ganov | c00d008 | 2012-05-22 18:37:49 -0700 | [diff] [blame] | 6502 | } |
| 6503 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6504 | } |
| 6505 | |
Svetoslav Ganov | 8ffe8b3 | 2012-06-15 10:31:31 -0700 | [diff] [blame] | 6506 | private void sendAccessibilityHoverEvent(int eventType) { |
| 6507 | // Since we are not delivering to a client accessibility events from not |
| 6508 | // important views (unless the clinet request that) we need to fire the |
| 6509 | // event from the deepest view exposed to the client. As a consequence if |
| 6510 | // the user crosses a not exposed view the client will see enter and exit |
| 6511 | // of the exposed predecessor followed by and enter and exit of that same |
| 6512 | // predecessor when entering and exiting the not exposed descendant. This |
| 6513 | // is fine since the client has a clear idea which view is hovered at the |
| 6514 | // price of a couple more events being sent. This is a simple and |
| 6515 | // working solution. |
| 6516 | View source = this; |
| 6517 | while (true) { |
| 6518 | if (source.includeForAccessibility()) { |
| 6519 | source.sendAccessibilityEvent(eventType); |
| 6520 | return; |
| 6521 | } |
| 6522 | ViewParent parent = source.getParent(); |
| 6523 | if (parent instanceof View) { |
| 6524 | source = (View) parent; |
| 6525 | } else { |
| 6526 | return; |
| 6527 | } |
| 6528 | } |
| 6529 | } |
| 6530 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6531 | /** |
| 6532 | * Clears accessibility focus without calling any callback methods |
| 6533 | * normally invoked in {@link #clearAccessibilityFocus()}. This method |
| 6534 | * is used for clearing accessibility focus when giving this focus to |
| 6535 | * another view. |
| 6536 | */ |
| 6537 | void clearAccessibilityFocusNoCallbacks() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6538 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0) { |
| 6539 | mPrivateFlags2 &= ~PFLAG2_ACCESSIBILITY_FOCUSED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6540 | invalidate(); |
| 6541 | } |
| 6542 | } |
| 6543 | |
| 6544 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6545 | * Call this to try to give focus to a specific view or to one of its |
| 6546 | * descendants. |
| 6547 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6548 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6549 | * false), or if it is focusable and it is not focusable in touch mode |
| 6550 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6551 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6552 | * 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] | 6553 | * have focus, and you want your parent to look for the next one. |
| 6554 | * |
| 6555 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with arguments |
| 6556 | * {@link #FOCUS_DOWN} and <code>null</code>. |
| 6557 | * |
| 6558 | * @return Whether this view or one of its descendants actually took focus. |
| 6559 | */ |
| 6560 | public final boolean requestFocus() { |
| 6561 | return requestFocus(View.FOCUS_DOWN); |
| 6562 | } |
| 6563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6564 | /** |
| 6565 | * Call this to try to give focus to a specific view or to one of its |
| 6566 | * descendants and give it a hint about what direction focus is heading. |
| 6567 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6568 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6569 | * false), or if it is focusable and it is not focusable in touch mode |
| 6570 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6571 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6572 | * 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] | 6573 | * have focus, and you want your parent to look for the next one. |
| 6574 | * |
| 6575 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with |
| 6576 | * <code>null</code> set for the previously focused rectangle. |
| 6577 | * |
| 6578 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6579 | * @return Whether this view or one of its descendants actually took focus. |
| 6580 | */ |
| 6581 | public final boolean requestFocus(int direction) { |
| 6582 | return requestFocus(direction, null); |
| 6583 | } |
| 6584 | |
| 6585 | /** |
| 6586 | * Call this to try to give focus to a specific view or to one of its descendants |
| 6587 | * and give it hints about the direction and a specific rectangle that the focus |
| 6588 | * is coming from. The rectangle can help give larger views a finer grained hint |
| 6589 | * about where focus is coming from, and therefore, where to show selection, or |
| 6590 | * forward focus change internally. |
| 6591 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6592 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6593 | * false), or if it is focusable and it is not focusable in touch mode |
| 6594 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6595 | * |
| 6596 | * A View will not take focus if it is not visible. |
| 6597 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6598 | * A View will not take focus if one of its parents has |
| 6599 | * {@link android.view.ViewGroup#getDescendantFocusability()} equal to |
| 6600 | * {@link ViewGroup#FOCUS_BLOCK_DESCENDANTS}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6601 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6602 | * 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] | 6603 | * have focus, and you want your parent to look for the next one. |
| 6604 | * |
| 6605 | * You may wish to override this method if your custom {@link View} has an internal |
| 6606 | * {@link View} that it wishes to forward the request to. |
| 6607 | * |
| 6608 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6609 | * @param previouslyFocusedRect The rectangle (in this View's coordinate system) |
| 6610 | * to give a finer grained hint about where focus is coming from. May be null |
| 6611 | * if there is no hint. |
| 6612 | * @return Whether this view or one of its descendants actually took focus. |
| 6613 | */ |
| 6614 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6615 | return requestFocusNoSearch(direction, previouslyFocusedRect); |
| 6616 | } |
| 6617 | |
| 6618 | private boolean requestFocusNoSearch(int direction, Rect previouslyFocusedRect) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6619 | // need to be focusable |
| 6620 | if ((mViewFlags & FOCUSABLE_MASK) != FOCUSABLE || |
| 6621 | (mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 6622 | return false; |
| 6623 | } |
| 6624 | |
| 6625 | // need to be focusable in touch mode if in touch mode |
| 6626 | if (isInTouchMode() && |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6627 | (FOCUSABLE_IN_TOUCH_MODE != (mViewFlags & FOCUSABLE_IN_TOUCH_MODE))) { |
| 6628 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6629 | } |
| 6630 | |
| 6631 | // need to not have any parents blocking us |
| 6632 | if (hasAncestorThatBlocksDescendantFocus()) { |
| 6633 | return false; |
| 6634 | } |
| 6635 | |
| 6636 | handleFocusGainInternal(direction, previouslyFocusedRect); |
| 6637 | return true; |
| 6638 | } |
| 6639 | |
| 6640 | /** |
| 6641 | * Call this to try to give focus to a specific view or to one of its descendants. This is a |
| 6642 | * special variant of {@link #requestFocus() } that will allow views that are not focuable in |
| 6643 | * touch mode to request focus when they are touched. |
| 6644 | * |
| 6645 | * @return Whether this view or one of its descendants actually took focus. |
| 6646 | * |
| 6647 | * @see #isInTouchMode() |
| 6648 | * |
| 6649 | */ |
| 6650 | public final boolean requestFocusFromTouch() { |
| 6651 | // Leave touch mode if we need to |
| 6652 | if (isInTouchMode()) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6653 | ViewRootImpl viewRoot = getViewRootImpl(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6654 | if (viewRoot != null) { |
| 6655 | viewRoot.ensureTouchMode(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6656 | } |
| 6657 | } |
| 6658 | return requestFocus(View.FOCUS_DOWN); |
| 6659 | } |
| 6660 | |
| 6661 | /** |
| 6662 | * @return Whether any ancestor of this view blocks descendant focus. |
| 6663 | */ |
| 6664 | private boolean hasAncestorThatBlocksDescendantFocus() { |
| 6665 | ViewParent ancestor = mParent; |
| 6666 | while (ancestor instanceof ViewGroup) { |
| 6667 | final ViewGroup vgAncestor = (ViewGroup) ancestor; |
| 6668 | if (vgAncestor.getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS) { |
| 6669 | return true; |
| 6670 | } else { |
| 6671 | ancestor = vgAncestor.getParent(); |
| 6672 | } |
| 6673 | } |
| 6674 | return false; |
| 6675 | } |
| 6676 | |
| 6677 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6678 | * Gets the mode for determining whether this View is important for accessibility |
| 6679 | * which is if it fires accessibility events and if it is reported to |
| 6680 | * accessibility services that query the screen. |
| 6681 | * |
| 6682 | * @return The mode for determining whether a View is important for accessibility. |
| 6683 | * |
| 6684 | * @attr ref android.R.styleable#View_importantForAccessibility |
| 6685 | * |
| 6686 | * @see #IMPORTANT_FOR_ACCESSIBILITY_YES |
| 6687 | * @see #IMPORTANT_FOR_ACCESSIBILITY_NO |
| 6688 | * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 6689 | */ |
| 6690 | @ViewDebug.ExportedProperty(category = "accessibility", mapping = { |
Svetoslav Ganov | f9817f7 | 2012-05-22 18:10:31 -0700 | [diff] [blame] | 6691 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_AUTO, to = "auto"), |
| 6692 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_YES, to = "yes"), |
| 6693 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_NO, to = "no") |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6694 | }) |
| 6695 | public int getImportantForAccessibility() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6696 | return (mPrivateFlags2 & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK) |
| 6697 | >> PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6698 | } |
| 6699 | |
| 6700 | /** |
| 6701 | * Sets how to determine whether this view is important for accessibility |
| 6702 | * which is if it fires accessibility events and if it is reported to |
| 6703 | * accessibility services that query the screen. |
| 6704 | * |
| 6705 | * @param mode How to determine whether this view is important for accessibility. |
| 6706 | * |
| 6707 | * @attr ref android.R.styleable#View_importantForAccessibility |
| 6708 | * |
| 6709 | * @see #IMPORTANT_FOR_ACCESSIBILITY_YES |
| 6710 | * @see #IMPORTANT_FOR_ACCESSIBILITY_NO |
| 6711 | * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 6712 | */ |
| 6713 | public void setImportantForAccessibility(int mode) { |
| 6714 | if (mode != getImportantForAccessibility()) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6715 | mPrivateFlags2 &= ~PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK; |
| 6716 | mPrivateFlags2 |= (mode << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT) |
| 6717 | & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6718 | notifyAccessibilityStateChanged(); |
| 6719 | } |
| 6720 | } |
| 6721 | |
| 6722 | /** |
| 6723 | * Gets whether this view should be exposed for accessibility. |
| 6724 | * |
| 6725 | * @return Whether the view is exposed for accessibility. |
| 6726 | * |
| 6727 | * @hide |
| 6728 | */ |
| 6729 | public boolean isImportantForAccessibility() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6730 | final int mode = (mPrivateFlags2 & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK) |
| 6731 | >> PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6732 | switch (mode) { |
| 6733 | case IMPORTANT_FOR_ACCESSIBILITY_YES: |
| 6734 | return true; |
| 6735 | case IMPORTANT_FOR_ACCESSIBILITY_NO: |
| 6736 | return false; |
| 6737 | case IMPORTANT_FOR_ACCESSIBILITY_AUTO: |
Svetoslav Ganov | 34caec9 | 2012-07-19 18:07:58 -0700 | [diff] [blame] | 6738 | return isActionableForAccessibility() || hasListenersForAccessibility() |
| 6739 | || getAccessibilityNodeProvider() != null; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6740 | default: |
| 6741 | throw new IllegalArgumentException("Unknow important for accessibility mode: " |
| 6742 | + mode); |
| 6743 | } |
| 6744 | } |
| 6745 | |
| 6746 | /** |
| 6747 | * Gets the parent for accessibility purposes. Note that the parent for |
| 6748 | * accessibility is not necessary the immediate parent. It is the first |
| 6749 | * predecessor that is important for accessibility. |
| 6750 | * |
| 6751 | * @return The parent for accessibility purposes. |
| 6752 | */ |
| 6753 | public ViewParent getParentForAccessibility() { |
| 6754 | if (mParent instanceof View) { |
| 6755 | View parentView = (View) mParent; |
| 6756 | if (parentView.includeForAccessibility()) { |
| 6757 | return mParent; |
| 6758 | } else { |
| 6759 | return mParent.getParentForAccessibility(); |
| 6760 | } |
| 6761 | } |
| 6762 | return null; |
| 6763 | } |
| 6764 | |
| 6765 | /** |
| 6766 | * Adds the children of a given View for accessibility. Since some Views are |
| 6767 | * not important for accessibility the children for accessibility are not |
| 6768 | * necessarily direct children of the riew, rather they are the first level of |
| 6769 | * descendants important for accessibility. |
| 6770 | * |
| 6771 | * @param children The list of children for accessibility. |
| 6772 | */ |
| 6773 | public void addChildrenForAccessibility(ArrayList<View> children) { |
| 6774 | if (includeForAccessibility()) { |
| 6775 | children.add(this); |
| 6776 | } |
| 6777 | } |
| 6778 | |
| 6779 | /** |
| 6780 | * Whether to regard this view for accessibility. A view is regarded for |
| 6781 | * accessibility if it is important for accessibility or the querying |
| 6782 | * accessibility service has explicitly requested that view not |
| 6783 | * important for accessibility are regarded. |
| 6784 | * |
| 6785 | * @return Whether to regard the view for accessibility. |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6786 | * |
| 6787 | * @hide |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6788 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6789 | public boolean includeForAccessibility() { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6790 | if (mAttachInfo != null) { |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 6791 | return mAttachInfo.mIncludeNotImportantViews || isImportantForAccessibility(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6792 | } |
| 6793 | return false; |
| 6794 | } |
| 6795 | |
| 6796 | /** |
| 6797 | * Returns whether the View is considered actionable from |
| 6798 | * accessibility perspective. Such view are important for |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 6799 | * accessibility. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6800 | * |
| 6801 | * @return True if the view is actionable for accessibility. |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6802 | * |
| 6803 | * @hide |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6804 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6805 | public boolean isActionableForAccessibility() { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6806 | return (isClickable() || isLongClickable() || isFocusable()); |
| 6807 | } |
| 6808 | |
| 6809 | /** |
| 6810 | * Returns whether the View has registered callbacks wich makes it |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 6811 | * important for accessibility. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6812 | * |
| 6813 | * @return True if the view is actionable for accessibility. |
| 6814 | */ |
| 6815 | private boolean hasListenersForAccessibility() { |
| 6816 | ListenerInfo info = getListenerInfo(); |
| 6817 | return mTouchDelegate != null || info.mOnKeyListener != null |
| 6818 | || info.mOnTouchListener != null || info.mOnGenericMotionListener != null |
| 6819 | || info.mOnHoverListener != null || info.mOnDragListener != null; |
| 6820 | } |
| 6821 | |
| 6822 | /** |
| 6823 | * Notifies accessibility services that some view's important for |
| 6824 | * accessibility state has changed. Note that such notifications |
| 6825 | * are made at most once every |
| 6826 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()} |
| 6827 | * to avoid unnecessary load to the system. Also once a view has |
| 6828 | * made a notifucation this method is a NOP until the notification has |
| 6829 | * been sent to clients. |
| 6830 | * |
| 6831 | * @hide |
| 6832 | * |
| 6833 | * TODO: Makse sure this method is called for any view state change |
| 6834 | * that is interesting for accessilility purposes. |
| 6835 | */ |
| 6836 | public void notifyAccessibilityStateChanged() { |
Svetoslav Ganov | c406be9 | 2012-05-11 16:12:32 -0700 | [diff] [blame] | 6837 | if (!AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 6838 | return; |
| 6839 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6840 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_STATE_CHANGED) == 0) { |
| 6841 | mPrivateFlags2 |= PFLAG2_ACCESSIBILITY_STATE_CHANGED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6842 | if (mParent != null) { |
| 6843 | mParent.childAccessibilityStateChanged(this); |
| 6844 | } |
| 6845 | } |
| 6846 | } |
| 6847 | |
| 6848 | /** |
| 6849 | * Reset the state indicating the this view has requested clients |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 6850 | * interested in its accessibility state to be notified. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6851 | * |
| 6852 | * @hide |
| 6853 | */ |
| 6854 | public void resetAccessibilityStateChanged() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6855 | mPrivateFlags2 &= ~PFLAG2_ACCESSIBILITY_STATE_CHANGED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6856 | } |
| 6857 | |
| 6858 | /** |
| 6859 | * Performs the specified accessibility action on the view. For |
| 6860 | * possible accessibility actions look at {@link AccessibilityNodeInfo}. |
alanv | 8eeefef | 2012-05-07 16:57:53 -0700 | [diff] [blame] | 6861 | * <p> |
| 6862 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 6863 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 6864 | * {@link AccessibilityDelegate#performAccessibilityAction(View, int, Bundle)} |
| 6865 | * is responsible for handling this call. |
| 6866 | * </p> |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6867 | * |
| 6868 | * @param action The action to perform. |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6869 | * @param arguments Optional action arguments. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6870 | * @return Whether the action was performed. |
| 6871 | */ |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6872 | public boolean performAccessibilityAction(int action, Bundle arguments) { |
alanv | 8eeefef | 2012-05-07 16:57:53 -0700 | [diff] [blame] | 6873 | if (mAccessibilityDelegate != null) { |
| 6874 | return mAccessibilityDelegate.performAccessibilityAction(this, action, arguments); |
| 6875 | } else { |
| 6876 | return performAccessibilityActionInternal(action, arguments); |
| 6877 | } |
| 6878 | } |
| 6879 | |
| 6880 | /** |
| 6881 | * @see #performAccessibilityAction(int, Bundle) |
| 6882 | * |
| 6883 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 6884 | */ |
| 6885 | boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6886 | switch (action) { |
| 6887 | case AccessibilityNodeInfo.ACTION_CLICK: { |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6888 | if (isClickable()) { |
Svetoslav Ganov | 773f262 | 2012-05-05 19:59:42 -0700 | [diff] [blame] | 6889 | return performClick(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6890 | } |
| 6891 | } break; |
| 6892 | case AccessibilityNodeInfo.ACTION_LONG_CLICK: { |
| 6893 | if (isLongClickable()) { |
Svetoslav Ganov | 773f262 | 2012-05-05 19:59:42 -0700 | [diff] [blame] | 6894 | return performLongClick(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6895 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6896 | } break; |
| 6897 | case AccessibilityNodeInfo.ACTION_FOCUS: { |
| 6898 | if (!hasFocus()) { |
| 6899 | // Get out of touch mode since accessibility |
| 6900 | // wants to move focus around. |
| 6901 | getViewRootImpl().ensureTouchMode(false); |
| 6902 | return requestFocus(); |
| 6903 | } |
| 6904 | } break; |
| 6905 | case AccessibilityNodeInfo.ACTION_CLEAR_FOCUS: { |
| 6906 | if (hasFocus()) { |
| 6907 | clearFocus(); |
| 6908 | return !isFocused(); |
| 6909 | } |
| 6910 | } break; |
| 6911 | case AccessibilityNodeInfo.ACTION_SELECT: { |
| 6912 | if (!isSelected()) { |
| 6913 | setSelected(true); |
| 6914 | return isSelected(); |
| 6915 | } |
| 6916 | } break; |
| 6917 | case AccessibilityNodeInfo.ACTION_CLEAR_SELECTION: { |
| 6918 | if (isSelected()) { |
| 6919 | setSelected(false); |
| 6920 | return !isSelected(); |
| 6921 | } |
| 6922 | } break; |
| 6923 | case AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS: { |
Svetoslav Ganov | 27e2da7 | 2012-07-02 18:12:00 -0700 | [diff] [blame] | 6924 | if (!isAccessibilityFocused()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6925 | return requestAccessibilityFocus(); |
| 6926 | } |
| 6927 | } break; |
| 6928 | case AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS: { |
| 6929 | if (isAccessibilityFocused()) { |
| 6930 | clearAccessibilityFocus(); |
| 6931 | return true; |
| 6932 | } |
| 6933 | } break; |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6934 | case AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY: { |
| 6935 | if (arguments != null) { |
| 6936 | final int granularity = arguments.getInt( |
| 6937 | AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT); |
| 6938 | return nextAtGranularity(granularity); |
| 6939 | } |
| 6940 | } break; |
| 6941 | case AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY: { |
| 6942 | if (arguments != null) { |
| 6943 | final int granularity = arguments.getInt( |
| 6944 | AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT); |
| 6945 | return previousAtGranularity(granularity); |
| 6946 | } |
| 6947 | } break; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6948 | } |
| 6949 | return false; |
| 6950 | } |
| 6951 | |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6952 | private boolean nextAtGranularity(int granularity) { |
| 6953 | CharSequence text = getIterableTextForAccessibility(); |
Svetoslav Ganov | 64899e5 | 2012-05-15 21:09:30 -0700 | [diff] [blame] | 6954 | if (text == null || text.length() == 0) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6955 | return false; |
| 6956 | } |
| 6957 | TextSegmentIterator iterator = getIteratorForGranularity(granularity); |
| 6958 | if (iterator == null) { |
| 6959 | return false; |
| 6960 | } |
| 6961 | final int current = getAccessibilityCursorPosition(); |
| 6962 | final int[] range = iterator.following(current); |
| 6963 | if (range == null) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6964 | return false; |
| 6965 | } |
| 6966 | final int start = range[0]; |
| 6967 | final int end = range[1]; |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 6968 | setAccessibilityCursorPosition(end); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6969 | sendViewTextTraversedAtGranularityEvent( |
| 6970 | AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, |
| 6971 | granularity, start, end); |
| 6972 | return true; |
| 6973 | } |
| 6974 | |
| 6975 | private boolean previousAtGranularity(int granularity) { |
| 6976 | CharSequence text = getIterableTextForAccessibility(); |
Svetoslav Ganov | 64899e5 | 2012-05-15 21:09:30 -0700 | [diff] [blame] | 6977 | if (text == null || text.length() == 0) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6978 | return false; |
| 6979 | } |
| 6980 | TextSegmentIterator iterator = getIteratorForGranularity(granularity); |
| 6981 | if (iterator == null) { |
| 6982 | return false; |
| 6983 | } |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 6984 | int current = getAccessibilityCursorPosition(); |
| 6985 | if (current == ACCESSIBILITY_CURSOR_POSITION_UNDEFINED) { |
| 6986 | current = text.length(); |
| 6987 | } else if (granularity == AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER) { |
| 6988 | // When traversing by character we always put the cursor after the character |
| 6989 | // to ease edit and have to compensate before asking the for previous segment. |
| 6990 | current--; |
| 6991 | } |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6992 | final int[] range = iterator.preceding(current); |
| 6993 | if (range == null) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6994 | return false; |
| 6995 | } |
| 6996 | final int start = range[0]; |
| 6997 | final int end = range[1]; |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 6998 | // Always put the cursor after the character to ease edit. |
| 6999 | if (granularity == AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER) { |
| 7000 | setAccessibilityCursorPosition(end); |
| 7001 | } else { |
| 7002 | setAccessibilityCursorPosition(start); |
| 7003 | } |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7004 | sendViewTextTraversedAtGranularityEvent( |
| 7005 | AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, |
| 7006 | granularity, start, end); |
| 7007 | return true; |
| 7008 | } |
| 7009 | |
| 7010 | /** |
| 7011 | * Gets the text reported for accessibility purposes. |
| 7012 | * |
| 7013 | * @return The accessibility text. |
| 7014 | * |
| 7015 | * @hide |
| 7016 | */ |
| 7017 | public CharSequence getIterableTextForAccessibility() { |
Svetoslav Ganov | 05282aa | 2012-09-06 18:59:29 -0700 | [diff] [blame] | 7018 | return getContentDescription(); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7019 | } |
| 7020 | |
| 7021 | /** |
| 7022 | * @hide |
| 7023 | */ |
| 7024 | public int getAccessibilityCursorPosition() { |
| 7025 | return mAccessibilityCursorPosition; |
| 7026 | } |
| 7027 | |
| 7028 | /** |
| 7029 | * @hide |
| 7030 | */ |
| 7031 | public void setAccessibilityCursorPosition(int position) { |
| 7032 | mAccessibilityCursorPosition = position; |
| 7033 | } |
| 7034 | |
| 7035 | private void sendViewTextTraversedAtGranularityEvent(int action, int granularity, |
| 7036 | int fromIndex, int toIndex) { |
| 7037 | if (mParent == null) { |
| 7038 | return; |
| 7039 | } |
| 7040 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 7041 | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY); |
| 7042 | onInitializeAccessibilityEvent(event); |
| 7043 | onPopulateAccessibilityEvent(event); |
| 7044 | event.setFromIndex(fromIndex); |
| 7045 | event.setToIndex(toIndex); |
| 7046 | event.setAction(action); |
| 7047 | event.setMovementGranularity(granularity); |
| 7048 | mParent.requestSendAccessibilityEvent(this, event); |
| 7049 | } |
| 7050 | |
| 7051 | /** |
| 7052 | * @hide |
| 7053 | */ |
| 7054 | public TextSegmentIterator getIteratorForGranularity(int granularity) { |
| 7055 | switch (granularity) { |
| 7056 | case AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER: { |
| 7057 | CharSequence text = getIterableTextForAccessibility(); |
| 7058 | if (text != null && text.length() > 0) { |
| 7059 | CharacterTextSegmentIterator iterator = |
Svetoslav Ganov | bbd3155 | 2012-06-11 12:08:18 -0700 | [diff] [blame] | 7060 | CharacterTextSegmentIterator.getInstance( |
| 7061 | mContext.getResources().getConfiguration().locale); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7062 | iterator.initialize(text.toString()); |
| 7063 | return iterator; |
| 7064 | } |
| 7065 | } break; |
| 7066 | case AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD: { |
| 7067 | CharSequence text = getIterableTextForAccessibility(); |
| 7068 | if (text != null && text.length() > 0) { |
| 7069 | WordTextSegmentIterator iterator = |
Svetoslav Ganov | bbd3155 | 2012-06-11 12:08:18 -0700 | [diff] [blame] | 7070 | WordTextSegmentIterator.getInstance( |
| 7071 | mContext.getResources().getConfiguration().locale); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7072 | iterator.initialize(text.toString()); |
| 7073 | return iterator; |
| 7074 | } |
| 7075 | } break; |
| 7076 | case AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH: { |
| 7077 | CharSequence text = getIterableTextForAccessibility(); |
| 7078 | if (text != null && text.length() > 0) { |
| 7079 | ParagraphTextSegmentIterator iterator = |
| 7080 | ParagraphTextSegmentIterator.getInstance(); |
| 7081 | iterator.initialize(text.toString()); |
| 7082 | return iterator; |
| 7083 | } |
| 7084 | } break; |
| 7085 | } |
| 7086 | return null; |
| 7087 | } |
| 7088 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7089 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7090 | * @hide |
| 7091 | */ |
| 7092 | public void dispatchStartTemporaryDetach() { |
Svetoslav Ganov | 961bf0e | 2012-05-08 09:40:03 -0700 | [diff] [blame] | 7093 | clearAccessibilityFocus(); |
Romain Guy | 38c2ece | 2012-05-24 14:20:56 -0700 | [diff] [blame] | 7094 | clearDisplayList(); |
| 7095 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7096 | onStartTemporaryDetach(); |
| 7097 | } |
| 7098 | |
| 7099 | /** |
| 7100 | * 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] | 7101 | * {@link ViewGroup#detachViewFromParent(View) ViewGroup.detachViewFromParent}. |
| 7102 | * It will either be followed by {@link #onFinishTemporaryDetach()} or |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7103 | * {@link #onDetachedFromWindow()} when the container is done. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7104 | */ |
| 7105 | public void onStartTemporaryDetach() { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7106 | removeUnsetPressCallback(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7107 | mPrivateFlags |= PFLAG_CANCEL_NEXT_UP_EVENT; |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7108 | } |
| 7109 | |
| 7110 | /** |
| 7111 | * @hide |
| 7112 | */ |
| 7113 | public void dispatchFinishTemporaryDetach() { |
| 7114 | onFinishTemporaryDetach(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7115 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7117 | /** |
| 7118 | * Called after {@link #onStartTemporaryDetach} when the container is done |
| 7119 | * changing the view. |
| 7120 | */ |
| 7121 | public void onFinishTemporaryDetach() { |
| 7122 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7123 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7124 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7125 | * Return the global {@link KeyEvent.DispatcherState KeyEvent.DispatcherState} |
| 7126 | * for this view's window. Returns null if the view is not currently attached |
| 7127 | * 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] | 7128 | * just use the standard high-level event callbacks like |
| 7129 | * {@link #onKeyDown(int, KeyEvent)}. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7130 | */ |
| 7131 | public KeyEvent.DispatcherState getKeyDispatcherState() { |
| 7132 | return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null; |
| 7133 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7134 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7135 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7136 | * Dispatch a key event before it is processed by any input method |
| 7137 | * associated with the view hierarchy. This can be used to intercept |
| 7138 | * key events in special situations before the IME consumes them; a |
| 7139 | * typical example would be handling the BACK key to update the application's |
| 7140 | * UI instead of allowing the IME to see it and close itself. |
| 7141 | * |
| 7142 | * @param event The key event to be dispatched. |
| 7143 | * @return True if the event was handled, false otherwise. |
| 7144 | */ |
| 7145 | public boolean dispatchKeyEventPreIme(KeyEvent event) { |
| 7146 | return onKeyPreIme(event.getKeyCode(), event); |
| 7147 | } |
| 7148 | |
| 7149 | /** |
| 7150 | * Dispatch a key event to the next view on the focus path. This path runs |
| 7151 | * from the top of the view tree down to the currently focused view. If this |
| 7152 | * view has focus, it will dispatch to itself. Otherwise it will dispatch |
| 7153 | * the next node down the focus path. This method also fires any key |
| 7154 | * listeners. |
| 7155 | * |
| 7156 | * @param event The key event to be dispatched. |
| 7157 | * @return True if the event was handled, false otherwise. |
| 7158 | */ |
| 7159 | public boolean dispatchKeyEvent(KeyEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7160 | if (mInputEventConsistencyVerifier != null) { |
| 7161 | mInputEventConsistencyVerifier.onKeyEvent(event, 0); |
| 7162 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7163 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7164 | // Give any attached key listener a first crack at the event. |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 7165 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7166 | ListenerInfo li = mListenerInfo; |
| 7167 | if (li != null && li.mOnKeyListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 7168 | && li.mOnKeyListener.onKey(this, event.getKeyCode(), event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7169 | return true; |
| 7170 | } |
| 7171 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7172 | if (event.dispatch(this, mAttachInfo != null |
| 7173 | ? mAttachInfo.mKeyDispatchState : null, this)) { |
| 7174 | return true; |
| 7175 | } |
| 7176 | |
| 7177 | if (mInputEventConsistencyVerifier != null) { |
| 7178 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 7179 | } |
| 7180 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7181 | } |
| 7182 | |
| 7183 | /** |
| 7184 | * Dispatches a key shortcut event. |
| 7185 | * |
| 7186 | * @param event The key event to be dispatched. |
| 7187 | * @return True if the event was handled by the view, false otherwise. |
| 7188 | */ |
| 7189 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 7190 | return onKeyShortcut(event.getKeyCode(), event); |
| 7191 | } |
| 7192 | |
| 7193 | /** |
| 7194 | * Pass the touch screen motion event down to the target view, or this |
| 7195 | * view if it is the target. |
| 7196 | * |
| 7197 | * @param event The motion event to be dispatched. |
| 7198 | * @return True if the event was handled by the view, false otherwise. |
| 7199 | */ |
| 7200 | public boolean dispatchTouchEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7201 | if (mInputEventConsistencyVerifier != null) { |
| 7202 | mInputEventConsistencyVerifier.onTouchEvent(event, 0); |
| 7203 | } |
| 7204 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7205 | if (onFilterTouchEventForSecurity(event)) { |
| 7206 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7207 | ListenerInfo li = mListenerInfo; |
| 7208 | if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 7209 | && li.mOnTouchListener.onTouch(this, event)) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7210 | return true; |
| 7211 | } |
| 7212 | |
| 7213 | if (onTouchEvent(event)) { |
| 7214 | return true; |
| 7215 | } |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7216 | } |
| 7217 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7218 | if (mInputEventConsistencyVerifier != null) { |
| 7219 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7220 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7221 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7222 | } |
| 7223 | |
| 7224 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7225 | * Filter the touch event to apply security policies. |
| 7226 | * |
| 7227 | * @param event The motion event to be filtered. |
| 7228 | * @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] | 7229 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7230 | * @see #getFilterTouchesWhenObscured |
| 7231 | */ |
| 7232 | public boolean onFilterTouchEventForSecurity(MotionEvent event) { |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 7233 | //noinspection RedundantIfStatement |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7234 | if ((mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0 |
| 7235 | && (event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) { |
| 7236 | // Window is obscured, drop this touch. |
| 7237 | return false; |
| 7238 | } |
| 7239 | return true; |
| 7240 | } |
| 7241 | |
| 7242 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7243 | * Pass a trackball motion event down to the focused view. |
| 7244 | * |
| 7245 | * @param event The motion event to be dispatched. |
| 7246 | * @return True if the event was handled by the view, false otherwise. |
| 7247 | */ |
| 7248 | public boolean dispatchTrackballEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7249 | if (mInputEventConsistencyVerifier != null) { |
| 7250 | mInputEventConsistencyVerifier.onTrackballEvent(event, 0); |
| 7251 | } |
| 7252 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 7253 | return onTrackballEvent(event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7254 | } |
| 7255 | |
| 7256 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7257 | * Dispatch a generic motion event. |
| 7258 | * <p> |
| 7259 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 7260 | * 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] | 7261 | * 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] | 7262 | * to {@link #onHoverEvent(MotionEvent)}. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7263 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7264 | * |
| 7265 | * @param event The motion event to be dispatched. |
| 7266 | * @return True if the event was handled by the view, false otherwise. |
| 7267 | */ |
| 7268 | public boolean dispatchGenericMotionEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7269 | if (mInputEventConsistencyVerifier != null) { |
| 7270 | mInputEventConsistencyVerifier.onGenericMotionEvent(event, 0); |
| 7271 | } |
| 7272 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7273 | final int source = event.getSource(); |
| 7274 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 7275 | final int action = event.getAction(); |
| 7276 | if (action == MotionEvent.ACTION_HOVER_ENTER |
| 7277 | || action == MotionEvent.ACTION_HOVER_MOVE |
| 7278 | || action == MotionEvent.ACTION_HOVER_EXIT) { |
| 7279 | if (dispatchHoverEvent(event)) { |
| 7280 | return true; |
| 7281 | } |
| 7282 | } else if (dispatchGenericPointerEvent(event)) { |
| 7283 | return true; |
| 7284 | } |
| 7285 | } else if (dispatchGenericFocusedEvent(event)) { |
| 7286 | return true; |
| 7287 | } |
| 7288 | |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7289 | if (dispatchGenericMotionEventInternal(event)) { |
| 7290 | return true; |
| 7291 | } |
| 7292 | |
| 7293 | if (mInputEventConsistencyVerifier != null) { |
| 7294 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 7295 | } |
| 7296 | return false; |
| 7297 | } |
| 7298 | |
| 7299 | private boolean dispatchGenericMotionEventInternal(MotionEvent event) { |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 7300 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7301 | ListenerInfo li = mListenerInfo; |
| 7302 | if (li != null && li.mOnGenericMotionListener != null |
| 7303 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 7304 | && li.mOnGenericMotionListener.onGenericMotion(this, event)) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7305 | return true; |
| 7306 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7307 | |
| 7308 | if (onGenericMotionEvent(event)) { |
| 7309 | return true; |
| 7310 | } |
| 7311 | |
| 7312 | if (mInputEventConsistencyVerifier != null) { |
| 7313 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 7314 | } |
| 7315 | return false; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7316 | } |
| 7317 | |
| 7318 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7319 | * Dispatch a hover event. |
| 7320 | * <p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7321 | * Do not call this method directly. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7322 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7323 | * </p> |
| 7324 | * |
| 7325 | * @param event The motion event to be dispatched. |
| 7326 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7327 | */ |
| 7328 | protected boolean dispatchHoverEvent(MotionEvent event) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 7329 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7330 | ListenerInfo li = mListenerInfo; |
| 7331 | if (li != null && li.mOnHoverListener != null |
| 7332 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 7333 | && li.mOnHoverListener.onHover(this, event)) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7334 | return true; |
| 7335 | } |
| 7336 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7337 | return onHoverEvent(event); |
| 7338 | } |
| 7339 | |
| 7340 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 7341 | * Returns true if the view has a child to which it has recently sent |
| 7342 | * {@link MotionEvent#ACTION_HOVER_ENTER}. If this view is hovered and |
| 7343 | * it does not have a hovered child, then it must be the innermost hovered view. |
| 7344 | * @hide |
| 7345 | */ |
| 7346 | protected boolean hasHoveredChild() { |
| 7347 | return false; |
| 7348 | } |
| 7349 | |
| 7350 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7351 | * Dispatch a generic motion event to the view under the first pointer. |
| 7352 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7353 | * Do not call this method directly. |
| 7354 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7355 | * </p> |
| 7356 | * |
| 7357 | * @param event The motion event to be dispatched. |
| 7358 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7359 | */ |
| 7360 | protected boolean dispatchGenericPointerEvent(MotionEvent event) { |
| 7361 | return false; |
| 7362 | } |
| 7363 | |
| 7364 | /** |
| 7365 | * Dispatch a generic motion event to the currently focused view. |
| 7366 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7367 | * Do not call this method directly. |
| 7368 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7369 | * </p> |
| 7370 | * |
| 7371 | * @param event The motion event to be dispatched. |
| 7372 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7373 | */ |
| 7374 | protected boolean dispatchGenericFocusedEvent(MotionEvent event) { |
| 7375 | return false; |
| 7376 | } |
| 7377 | |
| 7378 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7379 | * Dispatch a pointer event. |
| 7380 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7381 | * Dispatches touch related pointer events to {@link #onTouchEvent(MotionEvent)} and all |
| 7382 | * other events to {@link #onGenericMotionEvent(MotionEvent)}. This separation of concerns |
| 7383 | * reinforces the invariant that {@link #onTouchEvent(MotionEvent)} is really about touches |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7384 | * and should not be expected to handle other pointing device features. |
| 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. |
| 7389 | * @hide |
| 7390 | */ |
| 7391 | public final boolean dispatchPointerEvent(MotionEvent event) { |
| 7392 | if (event.isTouchEvent()) { |
| 7393 | return dispatchTouchEvent(event); |
| 7394 | } else { |
| 7395 | return dispatchGenericMotionEvent(event); |
| 7396 | } |
| 7397 | } |
| 7398 | |
| 7399 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7400 | * Called when the window containing this view gains or loses window focus. |
| 7401 | * ViewGroups should override to route to their children. |
| 7402 | * |
| 7403 | * @param hasFocus True if the window containing this view now has focus, |
| 7404 | * false otherwise. |
| 7405 | */ |
| 7406 | public void dispatchWindowFocusChanged(boolean hasFocus) { |
| 7407 | onWindowFocusChanged(hasFocus); |
| 7408 | } |
| 7409 | |
| 7410 | /** |
| 7411 | * Called when the window containing this view gains or loses focus. Note |
| 7412 | * that this is separate from view focus: to receive key events, both |
| 7413 | * your view and its window must have focus. If a window is displayed |
| 7414 | * on top of yours that takes input focus, then your own window will lose |
| 7415 | * focus but the view focus will remain unchanged. |
| 7416 | * |
| 7417 | * @param hasWindowFocus True if the window containing this view now has |
| 7418 | * focus, false otherwise. |
| 7419 | */ |
| 7420 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 7421 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 7422 | if (!hasWindowFocus) { |
| 7423 | if (isPressed()) { |
| 7424 | setPressed(false); |
| 7425 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7426 | if (imm != null && (mPrivateFlags & PFLAG_FOCUSED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7427 | imm.focusOut(this); |
| 7428 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7429 | removeLongPressCallback(); |
Tony Wu | 26edf20 | 2010-09-13 19:54:00 +0800 | [diff] [blame] | 7430 | removeTapCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 7431 | onFocusLost(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7432 | } else if (imm != null && (mPrivateFlags & PFLAG_FOCUSED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7433 | imm.focusIn(this); |
| 7434 | } |
| 7435 | refreshDrawableState(); |
| 7436 | } |
| 7437 | |
| 7438 | /** |
| 7439 | * Returns true if this view is in a window that currently has window focus. |
| 7440 | * Note that this is not the same as the view itself having focus. |
| 7441 | * |
| 7442 | * @return True if this view is in a window that currently has window focus. |
| 7443 | */ |
| 7444 | public boolean hasWindowFocus() { |
| 7445 | return mAttachInfo != null && mAttachInfo.mHasWindowFocus; |
| 7446 | } |
| 7447 | |
| 7448 | /** |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7449 | * Dispatch a view visibility change down the view hierarchy. |
| 7450 | * ViewGroups should override to route to their children. |
| 7451 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 7452 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7453 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 7454 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7455 | */ |
| 7456 | protected void dispatchVisibilityChanged(View changedView, int visibility) { |
| 7457 | onVisibilityChanged(changedView, visibility); |
| 7458 | } |
| 7459 | |
| 7460 | /** |
| 7461 | * Called when the visibility of the view or an ancestor of the view is changed. |
| 7462 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 7463 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7464 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 7465 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7466 | */ |
| 7467 | protected void onVisibilityChanged(View changedView, int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 7468 | if (visibility == VISIBLE) { |
| 7469 | if (mAttachInfo != null) { |
| 7470 | initialAwakenScrollBars(); |
| 7471 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7472 | mPrivateFlags |= PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH; |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 7473 | } |
| 7474 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7475 | } |
| 7476 | |
| 7477 | /** |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7478 | * Dispatch a hint about whether this view is displayed. For instance, when |
| 7479 | * a View moves out of the screen, it might receives a display hint indicating |
| 7480 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 7481 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7482 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7483 | * @param hint A hint about whether or not this view is displayed: |
| 7484 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 7485 | */ |
| 7486 | public void dispatchDisplayHint(int hint) { |
| 7487 | onDisplayHint(hint); |
| 7488 | } |
| 7489 | |
| 7490 | /** |
| 7491 | * Gives this view a hint about whether is displayed or not. For instance, when |
| 7492 | * a View moves out of the screen, it might receives a display hint indicating |
| 7493 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 7494 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7495 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7496 | * @param hint A hint about whether or not this view is displayed: |
| 7497 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 7498 | */ |
| 7499 | protected void onDisplayHint(int hint) { |
| 7500 | } |
| 7501 | |
| 7502 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7503 | * Dispatch a window visibility change down the view hierarchy. |
| 7504 | * ViewGroups should override to route to their children. |
| 7505 | * |
| 7506 | * @param visibility The new visibility of the window. |
| 7507 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7508 | * @see #onWindowVisibilityChanged(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7509 | */ |
| 7510 | public void dispatchWindowVisibilityChanged(int visibility) { |
| 7511 | onWindowVisibilityChanged(visibility); |
| 7512 | } |
| 7513 | |
| 7514 | /** |
| 7515 | * Called when the window containing has change its visibility |
| 7516 | * (between {@link #GONE}, {@link #INVISIBLE}, and {@link #VISIBLE}). Note |
| 7517 | * that this tells you whether or not your window is being made visible |
| 7518 | * to the window manager; this does <em>not</em> tell you whether or not |
| 7519 | * your window is obscured by other windows on the screen, even if it |
| 7520 | * is itself visible. |
| 7521 | * |
| 7522 | * @param visibility The new visibility of the window. |
| 7523 | */ |
| 7524 | protected void onWindowVisibilityChanged(int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 7525 | if (visibility == VISIBLE) { |
| 7526 | initialAwakenScrollBars(); |
| 7527 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7528 | } |
| 7529 | |
| 7530 | /** |
| 7531 | * Returns the current visibility of the window this view is attached to |
| 7532 | * (either {@link #GONE}, {@link #INVISIBLE}, or {@link #VISIBLE}). |
| 7533 | * |
| 7534 | * @return Returns the current visibility of the view's window. |
| 7535 | */ |
| 7536 | public int getWindowVisibility() { |
| 7537 | return mAttachInfo != null ? mAttachInfo.mWindowVisibility : GONE; |
| 7538 | } |
| 7539 | |
| 7540 | /** |
| 7541 | * Retrieve the overall visible display size in which the window this view is |
| 7542 | * attached to has been positioned in. This takes into account screen |
| 7543 | * decorations above the window, for both cases where the window itself |
| 7544 | * is being position inside of them or the window is being placed under |
| 7545 | * then and covered insets are used for the window to position its content |
| 7546 | * inside. In effect, this tells you the available area where content can |
| 7547 | * be placed and remain visible to users. |
| 7548 | * |
| 7549 | * <p>This function requires an IPC back to the window manager to retrieve |
| 7550 | * the requested information, so should not be used in performance critical |
| 7551 | * code like drawing. |
| 7552 | * |
| 7553 | * @param outRect Filled in with the visible display frame. If the view |
| 7554 | * is not attached to a window, this is simply the raw display size. |
| 7555 | */ |
| 7556 | public void getWindowVisibleDisplayFrame(Rect outRect) { |
| 7557 | if (mAttachInfo != null) { |
| 7558 | try { |
| 7559 | mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect); |
| 7560 | } catch (RemoteException e) { |
| 7561 | return; |
| 7562 | } |
| 7563 | // XXX This is really broken, and probably all needs to be done |
| 7564 | // in the window manager, and we need to know more about whether |
| 7565 | // we want the area behind or in front of the IME. |
| 7566 | final Rect insets = mAttachInfo.mVisibleInsets; |
| 7567 | outRect.left += insets.left; |
| 7568 | outRect.top += insets.top; |
| 7569 | outRect.right -= insets.right; |
| 7570 | outRect.bottom -= insets.bottom; |
| 7571 | return; |
| 7572 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 7573 | // The view is not attached to a display so we don't have a context. |
| 7574 | // Make a best guess about the display size. |
| 7575 | Display d = DisplayManagerGlobal.getInstance().getRealDisplay(Display.DEFAULT_DISPLAY); |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 7576 | d.getRectSize(outRect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7577 | } |
| 7578 | |
| 7579 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7580 | * Dispatch a notification about a resource configuration change down |
| 7581 | * the view hierarchy. |
| 7582 | * ViewGroups should override to route to their children. |
| 7583 | * |
| 7584 | * @param newConfig The new resource configuration. |
| 7585 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7586 | * @see #onConfigurationChanged(android.content.res.Configuration) |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7587 | */ |
| 7588 | public void dispatchConfigurationChanged(Configuration newConfig) { |
| 7589 | onConfigurationChanged(newConfig); |
| 7590 | } |
| 7591 | |
| 7592 | /** |
| 7593 | * Called when the current configuration of the resources being used |
| 7594 | * by the application have changed. You can use this to decide when |
| 7595 | * to reload resources that can changed based on orientation and other |
| 7596 | * configuration characterstics. You only need to use this if you are |
| 7597 | * not relying on the normal {@link android.app.Activity} mechanism of |
| 7598 | * recreating the activity instance upon a configuration change. |
| 7599 | * |
| 7600 | * @param newConfig The new resource configuration. |
| 7601 | */ |
| 7602 | protected void onConfigurationChanged(Configuration newConfig) { |
| 7603 | } |
| 7604 | |
| 7605 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7606 | * Private function to aggregate all per-view attributes in to the view |
| 7607 | * root. |
| 7608 | */ |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7609 | void dispatchCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 7610 | performCollectViewAttributes(attachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7611 | } |
| 7612 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7613 | void performCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 7614 | if ((visibility & VISIBILITY_MASK) == VISIBLE) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7615 | if ((mViewFlags & KEEP_SCREEN_ON) == KEEP_SCREEN_ON) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7616 | attachInfo.mKeepScreenOn = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7617 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7618 | attachInfo.mSystemUiVisibility |= mSystemUiVisibility; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7619 | ListenerInfo li = mListenerInfo; |
| 7620 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7621 | attachInfo.mHasSystemUiListeners = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7622 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7623 | } |
| 7624 | } |
| 7625 | |
| 7626 | void needGlobalAttributesUpdate(boolean force) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7627 | final AttachInfo ai = mAttachInfo; |
Craig Mautner | 7eac0f5 | 2012-09-13 13:14:14 -0700 | [diff] [blame] | 7628 | if (ai != null && !ai.mRecomputeGlobalAttributes) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7629 | if (force || ai.mKeepScreenOn || (ai.mSystemUiVisibility != 0) |
| 7630 | || ai.mHasSystemUiListeners) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7631 | ai.mRecomputeGlobalAttributes = true; |
| 7632 | } |
| 7633 | } |
| 7634 | } |
| 7635 | |
| 7636 | /** |
| 7637 | * Returns whether the device is currently in touch mode. Touch mode is entered |
| 7638 | * once the user begins interacting with the device by touch, and affects various |
| 7639 | * things like whether focus is always visible to the user. |
| 7640 | * |
| 7641 | * @return Whether the device is in touch mode. |
| 7642 | */ |
| 7643 | @ViewDebug.ExportedProperty |
| 7644 | public boolean isInTouchMode() { |
| 7645 | if (mAttachInfo != null) { |
| 7646 | return mAttachInfo.mInTouchMode; |
| 7647 | } else { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7648 | return ViewRootImpl.isInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7649 | } |
| 7650 | } |
| 7651 | |
| 7652 | /** |
| 7653 | * Returns the context the view is running in, through which it can |
| 7654 | * access the current theme, resources, etc. |
| 7655 | * |
| 7656 | * @return The view's Context. |
| 7657 | */ |
| 7658 | @ViewDebug.CapturedViewProperty |
| 7659 | public final Context getContext() { |
| 7660 | return mContext; |
| 7661 | } |
| 7662 | |
| 7663 | /** |
| 7664 | * Handle a key event before it is processed by any input method |
| 7665 | * associated with the view hierarchy. This can be used to intercept |
| 7666 | * key events in special situations before the IME consumes them; a |
| 7667 | * typical example would be handling the BACK key to update the application's |
| 7668 | * UI instead of allowing the IME to see it and close itself. |
| 7669 | * |
| 7670 | * @param keyCode The value in event.getKeyCode(). |
| 7671 | * @param event Description of the key event. |
| 7672 | * @return If you handled the event, return true. If you want to allow the |
| 7673 | * event to be handled by the next receiver, return false. |
| 7674 | */ |
| 7675 | public boolean onKeyPreIme(int keyCode, KeyEvent event) { |
| 7676 | return false; |
| 7677 | } |
| 7678 | |
| 7679 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 7680 | * Default implementation of {@link KeyEvent.Callback#onKeyDown(int, KeyEvent) |
| 7681 | * KeyEvent.Callback.onKeyDown()}: perform press of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7682 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or {@link KeyEvent#KEYCODE_ENTER} |
| 7683 | * is released, if the view is enabled and clickable. |
| 7684 | * |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7685 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7686 | * although some may elect to do so in some situations. Do not rely on this to |
| 7687 | * catch software key presses. |
| 7688 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7689 | * @param keyCode A key code that represents the button pressed, from |
| 7690 | * {@link android.view.KeyEvent}. |
| 7691 | * @param event The KeyEvent object that defines the button action. |
| 7692 | */ |
| 7693 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 7694 | boolean result = false; |
| 7695 | |
| 7696 | switch (keyCode) { |
| 7697 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 7698 | case KeyEvent.KEYCODE_ENTER: { |
| 7699 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 7700 | return true; |
| 7701 | } |
| 7702 | // Long clickable items don't necessarily have to be clickable |
| 7703 | if (((mViewFlags & CLICKABLE) == CLICKABLE || |
| 7704 | (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) && |
| 7705 | (event.getRepeatCount() == 0)) { |
| 7706 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7707 | checkForLongClick(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7708 | return true; |
| 7709 | } |
| 7710 | break; |
| 7711 | } |
| 7712 | } |
| 7713 | return result; |
| 7714 | } |
| 7715 | |
| 7716 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7717 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 7718 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 7719 | * the event). |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7720 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7721 | * although some may elect to do so in some situations. Do not rely on this to |
| 7722 | * catch software key presses. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7723 | */ |
| 7724 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 7725 | return false; |
| 7726 | } |
| 7727 | |
| 7728 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 7729 | * Default implementation of {@link KeyEvent.Callback#onKeyUp(int, KeyEvent) |
| 7730 | * KeyEvent.Callback.onKeyUp()}: perform clicking of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7731 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or |
| 7732 | * {@link KeyEvent#KEYCODE_ENTER} is released. |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7733 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7734 | * although some may elect to do so in some situations. Do not rely on this to |
| 7735 | * catch software key presses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7736 | * |
| 7737 | * @param keyCode A key code that represents the button pressed, from |
| 7738 | * {@link android.view.KeyEvent}. |
| 7739 | * @param event The KeyEvent object that defines the button action. |
| 7740 | */ |
| 7741 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 7742 | boolean result = false; |
| 7743 | |
| 7744 | switch (keyCode) { |
| 7745 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 7746 | case KeyEvent.KEYCODE_ENTER: { |
| 7747 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 7748 | return true; |
| 7749 | } |
| 7750 | if ((mViewFlags & CLICKABLE) == CLICKABLE && isPressed()) { |
| 7751 | setPressed(false); |
| 7752 | |
| 7753 | if (!mHasPerformedLongPress) { |
| 7754 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7755 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7756 | |
| 7757 | result = performClick(); |
| 7758 | } |
| 7759 | } |
| 7760 | break; |
| 7761 | } |
| 7762 | } |
| 7763 | return result; |
| 7764 | } |
| 7765 | |
| 7766 | /** |
| 7767 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 7768 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 7769 | * the event). |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7770 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7771 | * although some may elect to do so in some situations. Do not rely on this to |
| 7772 | * catch software key presses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7773 | * |
| 7774 | * @param keyCode A key code that represents the button pressed, from |
| 7775 | * {@link android.view.KeyEvent}. |
| 7776 | * @param repeatCount The number of times the action was made. |
| 7777 | * @param event The KeyEvent object that defines the button action. |
| 7778 | */ |
| 7779 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 7780 | return false; |
| 7781 | } |
| 7782 | |
| 7783 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 7784 | * Called on the focused view when a key shortcut event is not handled. |
| 7785 | * Override this method to implement local key shortcuts for the View. |
| 7786 | * Key shortcuts can also be implemented by setting the |
| 7787 | * {@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] | 7788 | * |
| 7789 | * @param keyCode The value in event.getKeyCode(). |
| 7790 | * @param event Description of the key event. |
| 7791 | * @return If you handled the event, return true. If you want to allow the |
| 7792 | * event to be handled by the next receiver, return false. |
| 7793 | */ |
| 7794 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 7795 | return false; |
| 7796 | } |
| 7797 | |
| 7798 | /** |
| 7799 | * Check whether the called view is a text editor, in which case it |
| 7800 | * would make sense to automatically display a soft input window for |
| 7801 | * it. Subclasses should override this if they implement |
| 7802 | * {@link #onCreateInputConnection(EditorInfo)} to return true if |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7803 | * a call on that method would return a non-null InputConnection, and |
| 7804 | * they are really a first-class editor that the user would normally |
| 7805 | * start typing on when the go into a window containing your view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7806 | * |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7807 | * <p>The default implementation always returns false. This does |
| 7808 | * <em>not</em> mean that its {@link #onCreateInputConnection(EditorInfo)} |
| 7809 | * will not be called or the user can not otherwise perform edits on your |
| 7810 | * view; it is just a hint to the system that this is not the primary |
| 7811 | * purpose of this view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7812 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7813 | * @return Returns true if this view is a text editor, else false. |
| 7814 | */ |
| 7815 | public boolean onCheckIsTextEditor() { |
| 7816 | return false; |
| 7817 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7818 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7819 | /** |
| 7820 | * Create a new InputConnection for an InputMethod to interact |
| 7821 | * with the view. The default implementation returns null, since it doesn't |
| 7822 | * support input methods. You can override this to implement such support. |
| 7823 | * This is only needed for views that take focus and text input. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7824 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7825 | * <p>When implementing this, you probably also want to implement |
| 7826 | * {@link #onCheckIsTextEditor()} to indicate you will return a |
| 7827 | * non-null InputConnection. |
| 7828 | * |
| 7829 | * @param outAttrs Fill in with attribute information about the connection. |
| 7830 | */ |
| 7831 | public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
| 7832 | return null; |
| 7833 | } |
| 7834 | |
| 7835 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7836 | * Called by the {@link android.view.inputmethod.InputMethodManager} |
| 7837 | * when a view who is not the current |
| 7838 | * input connection target is trying to make a call on the manager. The |
| 7839 | * default implementation returns false; you can override this to return |
| 7840 | * true for certain views if you are performing InputConnection proxying |
| 7841 | * to them. |
| 7842 | * @param view The View that is making the InputMethodManager call. |
| 7843 | * @return Return true to allow the call, false to reject. |
| 7844 | */ |
| 7845 | public boolean checkInputConnectionProxy(View view) { |
| 7846 | return false; |
| 7847 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7848 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7849 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7850 | * Show the context menu for this view. It is not safe to hold on to the |
| 7851 | * menu after returning from this method. |
| 7852 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 7853 | * You should normally not overload this method. Overload |
| 7854 | * {@link #onCreateContextMenu(ContextMenu)} or define an |
| 7855 | * {@link OnCreateContextMenuListener} to add items to the context menu. |
| 7856 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7857 | * @param menu The context menu to populate |
| 7858 | */ |
| 7859 | public void createContextMenu(ContextMenu menu) { |
| 7860 | ContextMenuInfo menuInfo = getContextMenuInfo(); |
| 7861 | |
| 7862 | // Sets the current menu info so all items added to menu will have |
| 7863 | // my extra info set. |
| 7864 | ((MenuBuilder)menu).setCurrentMenuInfo(menuInfo); |
| 7865 | |
| 7866 | onCreateContextMenu(menu); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7867 | ListenerInfo li = mListenerInfo; |
| 7868 | if (li != null && li.mOnCreateContextMenuListener != null) { |
| 7869 | li.mOnCreateContextMenuListener.onCreateContextMenu(menu, this, menuInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7870 | } |
| 7871 | |
| 7872 | // Clear the extra information so subsequent items that aren't mine don't |
| 7873 | // have my extra info. |
| 7874 | ((MenuBuilder)menu).setCurrentMenuInfo(null); |
| 7875 | |
| 7876 | if (mParent != null) { |
| 7877 | mParent.createContextMenu(menu); |
| 7878 | } |
| 7879 | } |
| 7880 | |
| 7881 | /** |
| 7882 | * Views should implement this if they have extra information to associate |
| 7883 | * with the context menu. The return result is supplied as a parameter to |
| 7884 | * the {@link OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} |
| 7885 | * callback. |
| 7886 | * |
| 7887 | * @return Extra information about the item for which the context menu |
| 7888 | * should be shown. This information will vary across different |
| 7889 | * subclasses of View. |
| 7890 | */ |
| 7891 | protected ContextMenuInfo getContextMenuInfo() { |
| 7892 | return null; |
| 7893 | } |
| 7894 | |
| 7895 | /** |
| 7896 | * Views should implement this if the view itself is going to add items to |
| 7897 | * the context menu. |
| 7898 | * |
| 7899 | * @param menu the context menu to populate |
| 7900 | */ |
| 7901 | protected void onCreateContextMenu(ContextMenu menu) { |
| 7902 | } |
| 7903 | |
| 7904 | /** |
| 7905 | * Implement this method to handle trackball motion events. The |
| 7906 | * <em>relative</em> movement of the trackball since the last event |
| 7907 | * can be retrieve with {@link MotionEvent#getX MotionEvent.getX()} and |
| 7908 | * {@link MotionEvent#getY MotionEvent.getY()}. These are normalized so |
| 7909 | * that a movement of 1 corresponds to the user pressing one DPAD key (so |
| 7910 | * they will often be fractional values, representing the more fine-grained |
| 7911 | * movement information available from a trackball). |
| 7912 | * |
| 7913 | * @param event The motion event. |
| 7914 | * @return True if the event was handled, false otherwise. |
| 7915 | */ |
| 7916 | public boolean onTrackballEvent(MotionEvent event) { |
| 7917 | return false; |
| 7918 | } |
| 7919 | |
| 7920 | /** |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7921 | * Implement this method to handle generic motion events. |
| 7922 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7923 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 7924 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7925 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 7926 | * the class of input that was received. Implementations of this method |
| 7927 | * must examine the bits in the source before processing the event. |
| 7928 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7929 | * </p><p> |
| 7930 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 7931 | * are delivered to the view under the pointer. All other generic motion events are |
| 7932 | * delivered to the focused view. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7933 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 7934 | * <pre> public boolean onGenericMotionEvent(MotionEvent event) { |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7935 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7936 | * if (event.getAction() == MotionEvent.ACTION_MOVE) { |
| 7937 | * // process the joystick movement... |
| 7938 | * return true; |
| 7939 | * } |
| 7940 | * } |
| 7941 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 7942 | * switch (event.getAction()) { |
| 7943 | * case MotionEvent.ACTION_HOVER_MOVE: |
| 7944 | * // process the mouse hover movement... |
| 7945 | * return true; |
| 7946 | * case MotionEvent.ACTION_SCROLL: |
| 7947 | * // process the scroll wheel movement... |
| 7948 | * return true; |
| 7949 | * } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7950 | * } |
| 7951 | * return super.onGenericMotionEvent(event); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 7952 | * }</pre> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7953 | * |
| 7954 | * @param event The generic motion event being processed. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7955 | * @return True if the event was handled, false otherwise. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7956 | */ |
| 7957 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 7958 | return false; |
| 7959 | } |
| 7960 | |
| 7961 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7962 | * Implement this method to handle hover events. |
| 7963 | * <p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7964 | * This method is called whenever a pointer is hovering into, over, or out of the |
| 7965 | * bounds of a view and the view is not currently being touched. |
| 7966 | * Hover events are represented as pointer events with action |
| 7967 | * {@link MotionEvent#ACTION_HOVER_ENTER}, {@link MotionEvent#ACTION_HOVER_MOVE}, |
| 7968 | * or {@link MotionEvent#ACTION_HOVER_EXIT}. |
| 7969 | * </p> |
| 7970 | * <ul> |
| 7971 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_ENTER} |
| 7972 | * when the pointer enters the bounds of the view.</li> |
| 7973 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_MOVE} |
| 7974 | * when the pointer has already entered the bounds of the view and has moved.</li> |
| 7975 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_EXIT} |
| 7976 | * when the pointer has exited the bounds of the view or when the pointer is |
| 7977 | * about to go down due to a button click, tap, or similar user action that |
| 7978 | * causes the view to be touched.</li> |
| 7979 | * </ul> |
| 7980 | * <p> |
| 7981 | * The view should implement this method to return true to indicate that it is |
| 7982 | * handling the hover event, such as by changing its drawable state. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7983 | * </p><p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7984 | * The default implementation calls {@link #setHovered} to update the hovered state |
| 7985 | * 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] | 7986 | * is enabled and is clickable. The default implementation also sends hover |
| 7987 | * accessibility events. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7988 | * </p> |
| 7989 | * |
| 7990 | * @param event The motion event that describes the hover. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7991 | * @return True if the view handled the hover event. |
| 7992 | * |
| 7993 | * @see #isHovered |
| 7994 | * @see #setHovered |
| 7995 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7996 | */ |
| 7997 | public boolean onHoverEvent(MotionEvent event) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7998 | // The root view may receive hover (or touch) events that are outside the bounds of |
| 7999 | // the window. This code ensures that we only send accessibility events for |
| 8000 | // hovers that are actually within the bounds of the root view. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8001 | final int action = event.getActionMasked(); |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8002 | if (!mSendingHoverAccessibilityEvents) { |
| 8003 | if ((action == MotionEvent.ACTION_HOVER_ENTER |
| 8004 | || action == MotionEvent.ACTION_HOVER_MOVE) |
| 8005 | && !hasHoveredChild() |
| 8006 | && pointInView(event.getX(), event.getY())) { |
Svetoslav Ganov | 8ffe8b3 | 2012-06-15 10:31:31 -0700 | [diff] [blame] | 8007 | sendAccessibilityHoverEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8008 | mSendingHoverAccessibilityEvents = true; |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8009 | } |
| 8010 | } else { |
| 8011 | if (action == MotionEvent.ACTION_HOVER_EXIT |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8012 | || (action == MotionEvent.ACTION_MOVE |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8013 | && !pointInView(event.getX(), event.getY()))) { |
| 8014 | mSendingHoverAccessibilityEvents = false; |
Svetoslav Ganov | 8ffe8b3 | 2012-06-15 10:31:31 -0700 | [diff] [blame] | 8015 | sendAccessibilityHoverEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8016 | // If the window does not have input focus we take away accessibility |
| 8017 | // focus as soon as the user stop hovering over the view. |
Jeff Brown | 59a422e | 2012-04-19 15:19:19 -0700 | [diff] [blame] | 8018 | if (mAttachInfo != null && !mAttachInfo.mHasWindowFocus) { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 8019 | getViewRootImpl().setAccessibilityFocus(null, null); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8020 | } |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8021 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 8022 | } |
| 8023 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 8024 | if (isHoverable()) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8025 | switch (action) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8026 | case MotionEvent.ACTION_HOVER_ENTER: |
| 8027 | setHovered(true); |
| 8028 | break; |
| 8029 | case MotionEvent.ACTION_HOVER_EXIT: |
| 8030 | setHovered(false); |
| 8031 | break; |
| 8032 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 8033 | |
| 8034 | // Dispatch the event to onGenericMotionEvent before returning true. |
| 8035 | // This is to provide compatibility with existing applications that |
| 8036 | // handled HOVER_MOVE events in onGenericMotionEvent and that would |
| 8037 | // break because of the new default handling for hoverable views |
| 8038 | // in onHoverEvent. |
| 8039 | // Note that onGenericMotionEvent will be called by default when |
| 8040 | // onHoverEvent returns false (refer to dispatchGenericMotionEvent). |
| 8041 | dispatchGenericMotionEventInternal(event); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8042 | return true; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8043 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8044 | |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 8045 | return false; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8046 | } |
| 8047 | |
| 8048 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 8049 | * Returns true if the view should handle {@link #onHoverEvent} |
| 8050 | * by calling {@link #setHovered} to change its hovered state. |
| 8051 | * |
| 8052 | * @return True if the view is hoverable. |
| 8053 | */ |
| 8054 | private boolean isHoverable() { |
| 8055 | final int viewFlags = mViewFlags; |
| 8056 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
| 8057 | return false; |
| 8058 | } |
| 8059 | |
| 8060 | return (viewFlags & CLICKABLE) == CLICKABLE |
| 8061 | || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 8062 | } |
| 8063 | |
| 8064 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8065 | * Returns true if the view is currently hovered. |
| 8066 | * |
| 8067 | * @return True if the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8068 | * |
| 8069 | * @see #setHovered |
| 8070 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8071 | */ |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8072 | @ViewDebug.ExportedProperty |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8073 | public boolean isHovered() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8074 | return (mPrivateFlags & PFLAG_HOVERED) != 0; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8075 | } |
| 8076 | |
| 8077 | /** |
| 8078 | * Sets whether the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8079 | * <p> |
| 8080 | * Calling this method also changes the drawable state of the view. This |
| 8081 | * enables the view to react to hover by using different drawable resources |
| 8082 | * to change its appearance. |
| 8083 | * </p><p> |
| 8084 | * The {@link #onHoverChanged} method is called when the hovered state changes. |
| 8085 | * </p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8086 | * |
| 8087 | * @param hovered True if the view is hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8088 | * |
| 8089 | * @see #isHovered |
| 8090 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8091 | */ |
| 8092 | public void setHovered(boolean hovered) { |
| 8093 | if (hovered) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8094 | if ((mPrivateFlags & PFLAG_HOVERED) == 0) { |
| 8095 | mPrivateFlags |= PFLAG_HOVERED; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8096 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8097 | onHoverChanged(true); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8098 | } |
| 8099 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8100 | if ((mPrivateFlags & PFLAG_HOVERED) != 0) { |
| 8101 | mPrivateFlags &= ~PFLAG_HOVERED; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8102 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8103 | onHoverChanged(false); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8104 | } |
| 8105 | } |
| 8106 | } |
| 8107 | |
| 8108 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8109 | * Implement this method to handle hover state changes. |
| 8110 | * <p> |
| 8111 | * This method is called whenever the hover state changes as a result of a |
| 8112 | * call to {@link #setHovered}. |
| 8113 | * </p> |
| 8114 | * |
| 8115 | * @param hovered The current hover state, as returned by {@link #isHovered}. |
| 8116 | * |
| 8117 | * @see #isHovered |
| 8118 | * @see #setHovered |
| 8119 | */ |
| 8120 | public void onHoverChanged(boolean hovered) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8121 | } |
| 8122 | |
| 8123 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8124 | * Implement this method to handle touch screen motion events. |
| 8125 | * |
| 8126 | * @param event The motion event. |
| 8127 | * @return True if the event was handled, false otherwise. |
| 8128 | */ |
| 8129 | public boolean onTouchEvent(MotionEvent event) { |
| 8130 | final int viewFlags = mViewFlags; |
| 8131 | |
| 8132 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8133 | if (event.getAction() == MotionEvent.ACTION_UP && (mPrivateFlags & PFLAG_PRESSED) != 0) { |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8134 | setPressed(false); |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 8135 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8136 | // A disabled view that is clickable still consumes the touch |
| 8137 | // events, it just doesn't respond to them. |
| 8138 | return (((viewFlags & CLICKABLE) == CLICKABLE || |
| 8139 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)); |
| 8140 | } |
| 8141 | |
| 8142 | if (mTouchDelegate != null) { |
| 8143 | if (mTouchDelegate.onTouchEvent(event)) { |
| 8144 | return true; |
| 8145 | } |
| 8146 | } |
| 8147 | |
| 8148 | if (((viewFlags & CLICKABLE) == CLICKABLE || |
| 8149 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)) { |
| 8150 | switch (event.getAction()) { |
| 8151 | case MotionEvent.ACTION_UP: |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8152 | boolean prepressed = (mPrivateFlags & PFLAG_PREPRESSED) != 0; |
| 8153 | if ((mPrivateFlags & PFLAG_PRESSED) != 0 || prepressed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8154 | // take focus if we don't have it already and we should in |
| 8155 | // touch mode. |
| 8156 | boolean focusTaken = false; |
| 8157 | if (isFocusable() && isFocusableInTouchMode() && !isFocused()) { |
| 8158 | focusTaken = requestFocus(); |
| 8159 | } |
| 8160 | |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 8161 | if (prepressed) { |
| 8162 | // The button is being released before we actually |
| 8163 | // showed it as pressed. Make it show the pressed |
| 8164 | // state now (before scheduling the click) to ensure |
| 8165 | // the user sees it. |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8166 | setPressed(true); |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 8167 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8169 | if (!mHasPerformedLongPress) { |
| 8170 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8171 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8172 | |
| 8173 | // Only perform take click actions if we were in the pressed state |
| 8174 | if (!focusTaken) { |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 8175 | // Use a Runnable and post this rather than calling |
| 8176 | // performClick directly. This lets other visual state |
| 8177 | // of the view update before click actions start. |
| 8178 | if (mPerformClick == null) { |
| 8179 | mPerformClick = new PerformClick(); |
| 8180 | } |
| 8181 | if (!post(mPerformClick)) { |
| 8182 | performClick(); |
| 8183 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8184 | } |
| 8185 | } |
| 8186 | |
| 8187 | if (mUnsetPressedState == null) { |
| 8188 | mUnsetPressedState = new UnsetPressedState(); |
| 8189 | } |
| 8190 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8191 | if (prepressed) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8192 | postDelayed(mUnsetPressedState, |
| 8193 | ViewConfiguration.getPressedStateDuration()); |
| 8194 | } else if (!post(mUnsetPressedState)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8195 | // If the post failed, unpress right now |
| 8196 | mUnsetPressedState.run(); |
| 8197 | } |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8198 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8199 | } |
| 8200 | break; |
| 8201 | |
| 8202 | case MotionEvent.ACTION_DOWN: |
Adam Powell | 3b02339 | 2010-03-11 16:30:28 -0800 | [diff] [blame] | 8203 | mHasPerformedLongPress = false; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8204 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 8205 | if (performButtonActionOnTouchDown(event)) { |
| 8206 | break; |
| 8207 | } |
| 8208 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8209 | // 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] | 8210 | boolean isInScrollingContainer = isInScrollingContainer(); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8211 | |
| 8212 | // For views inside a scrolling container, delay the pressed feedback for |
| 8213 | // a short period in case this is a scroll. |
| 8214 | if (isInScrollingContainer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8215 | mPrivateFlags |= PFLAG_PREPRESSED; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8216 | if (mPendingCheckForTap == null) { |
| 8217 | mPendingCheckForTap = new CheckForTap(); |
| 8218 | } |
| 8219 | postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); |
| 8220 | } else { |
| 8221 | // Not inside a scrolling container, so show the feedback right away |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8222 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8223 | checkForLongClick(0); |
| 8224 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8225 | break; |
| 8226 | |
| 8227 | case MotionEvent.ACTION_CANCEL: |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8228 | setPressed(false); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8229 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8230 | break; |
| 8231 | |
| 8232 | case MotionEvent.ACTION_MOVE: |
| 8233 | final int x = (int) event.getX(); |
| 8234 | final int y = (int) event.getY(); |
| 8235 | |
| 8236 | // Be lenient about moving outside of buttons |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8237 | if (!pointInView(x, y, mTouchSlop)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8238 | // Outside button |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8239 | removeTapCallback(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8240 | if ((mPrivateFlags & PFLAG_PRESSED) != 0) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8241 | // Remove any future long press/tap checks |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8242 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8243 | |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8244 | setPressed(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8245 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8246 | } |
| 8247 | break; |
| 8248 | } |
| 8249 | return true; |
| 8250 | } |
| 8251 | |
| 8252 | return false; |
| 8253 | } |
| 8254 | |
| 8255 | /** |
Adam Powell | 1029866 | 2011-08-14 18:26:30 -0700 | [diff] [blame] | 8256 | * @hide |
| 8257 | */ |
| 8258 | public boolean isInScrollingContainer() { |
| 8259 | ViewParent p = getParent(); |
| 8260 | while (p != null && p instanceof ViewGroup) { |
| 8261 | if (((ViewGroup) p).shouldDelayChildPressedState()) { |
| 8262 | return true; |
| 8263 | } |
| 8264 | p = p.getParent(); |
| 8265 | } |
| 8266 | return false; |
| 8267 | } |
| 8268 | |
| 8269 | /** |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8270 | * Remove the longpress detection timer. |
| 8271 | */ |
| 8272 | private void removeLongPressCallback() { |
| 8273 | if (mPendingCheckForLongPress != null) { |
| 8274 | removeCallbacks(mPendingCheckForLongPress); |
| 8275 | } |
| 8276 | } |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 8277 | |
| 8278 | /** |
| 8279 | * Remove the pending click action |
| 8280 | */ |
| 8281 | private void removePerformClickCallback() { |
| 8282 | if (mPerformClick != null) { |
| 8283 | removeCallbacks(mPerformClick); |
| 8284 | } |
| 8285 | } |
| 8286 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8287 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 8288 | * Remove the prepress detection timer. |
| 8289 | */ |
| 8290 | private void removeUnsetPressCallback() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8291 | if ((mPrivateFlags & PFLAG_PRESSED) != 0 && mUnsetPressedState != null) { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 8292 | setPressed(false); |
| 8293 | removeCallbacks(mUnsetPressedState); |
| 8294 | } |
| 8295 | } |
| 8296 | |
| 8297 | /** |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8298 | * Remove the tap detection timer. |
| 8299 | */ |
| 8300 | private void removeTapCallback() { |
| 8301 | if (mPendingCheckForTap != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8302 | mPrivateFlags &= ~PFLAG_PREPRESSED; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8303 | removeCallbacks(mPendingCheckForTap); |
| 8304 | } |
| 8305 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8306 | |
| 8307 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8308 | * Cancels a pending long press. Your subclass can use this if you |
| 8309 | * want the context menu to come up if the user presses and holds |
| 8310 | * at the same place, but you don't want it to come up if they press |
| 8311 | * and then move around enough to cause scrolling. |
| 8312 | */ |
| 8313 | public void cancelLongPress() { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8314 | removeLongPressCallback(); |
Adam Powell | 732ebb1 | 2010-02-02 15:28:14 -0800 | [diff] [blame] | 8315 | |
| 8316 | /* |
| 8317 | * The prepressed state handled by the tap callback is a display |
| 8318 | * construct, but the tap callback will post a long press callback |
| 8319 | * less its own timeout. Remove it here. |
| 8320 | */ |
| 8321 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8322 | } |
| 8323 | |
| 8324 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8325 | * Remove the pending callback for sending a |
| 8326 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 8327 | */ |
| 8328 | private void removeSendViewScrolledAccessibilityEventCallback() { |
| 8329 | if (mSendViewScrolledAccessibilityEvent != null) { |
| 8330 | removeCallbacks(mSendViewScrolledAccessibilityEvent); |
Svetoslav Ganov | 4a812ae | 2012-05-29 16:46:10 -0700 | [diff] [blame] | 8331 | mSendViewScrolledAccessibilityEvent.mIsPending = false; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8332 | } |
| 8333 | } |
| 8334 | |
| 8335 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8336 | * Sets the TouchDelegate for this View. |
| 8337 | */ |
| 8338 | public void setTouchDelegate(TouchDelegate delegate) { |
| 8339 | mTouchDelegate = delegate; |
| 8340 | } |
| 8341 | |
| 8342 | /** |
| 8343 | * Gets the TouchDelegate for this View. |
| 8344 | */ |
| 8345 | public TouchDelegate getTouchDelegate() { |
| 8346 | return mTouchDelegate; |
| 8347 | } |
| 8348 | |
| 8349 | /** |
| 8350 | * Set flags controlling behavior of this view. |
| 8351 | * |
| 8352 | * @param flags Constant indicating the value which should be set |
| 8353 | * @param mask Constant indicating the bit range that should be changed |
| 8354 | */ |
| 8355 | void setFlags(int flags, int mask) { |
| 8356 | int old = mViewFlags; |
| 8357 | mViewFlags = (mViewFlags & ~mask) | (flags & mask); |
| 8358 | |
| 8359 | int changed = mViewFlags ^ old; |
| 8360 | if (changed == 0) { |
| 8361 | return; |
| 8362 | } |
| 8363 | int privateFlags = mPrivateFlags; |
| 8364 | |
| 8365 | /* Check if the FOCUSABLE bit has changed */ |
| 8366 | if (((changed & FOCUSABLE_MASK) != 0) && |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8367 | ((privateFlags & PFLAG_HAS_BOUNDS) !=0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8368 | if (((old & FOCUSABLE_MASK) == FOCUSABLE) |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8369 | && ((privateFlags & PFLAG_FOCUSED) != 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8370 | /* Give up focus if we are no longer focusable */ |
| 8371 | clearFocus(); |
| 8372 | } else if (((old & FOCUSABLE_MASK) == NOT_FOCUSABLE) |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8373 | && ((privateFlags & PFLAG_FOCUSED) == 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8374 | /* |
| 8375 | * Tell the view system that we are now available to take focus |
| 8376 | * if no one else already has it. |
| 8377 | */ |
| 8378 | if (mParent != null) mParent.focusableViewAvailable(this); |
| 8379 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8380 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 8381 | notifyAccessibilityStateChanged(); |
| 8382 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8383 | } |
| 8384 | |
| 8385 | if ((flags & VISIBILITY_MASK) == VISIBLE) { |
| 8386 | if ((changed & VISIBILITY_MASK) != 0) { |
| 8387 | /* |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 8388 | * 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] | 8389 | * it was not visible. Marking it drawn ensures that the invalidation will |
| 8390 | * go through. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8391 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8392 | mPrivateFlags |= PFLAG_DRAWN; |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 8393 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8394 | |
| 8395 | needGlobalAttributesUpdate(true); |
| 8396 | |
| 8397 | // a view becoming visible is worth notifying the parent |
| 8398 | // about in case nothing has focus. even if this specific view |
| 8399 | // isn't focusable, it may contain something that is, so let |
| 8400 | // the root view try to give this focus if nothing else does. |
| 8401 | if ((mParent != null) && (mBottom > mTop) && (mRight > mLeft)) { |
| 8402 | mParent.focusableViewAvailable(this); |
| 8403 | } |
| 8404 | } |
| 8405 | } |
| 8406 | |
| 8407 | /* Check if the GONE bit has changed */ |
| 8408 | if ((changed & GONE) != 0) { |
| 8409 | needGlobalAttributesUpdate(false); |
| 8410 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8411 | |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 8412 | if (((mViewFlags & VISIBILITY_MASK) == GONE)) { |
| 8413 | if (hasFocus()) clearFocus(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8414 | clearAccessibilityFocus(); |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 8415 | destroyDrawingCache(); |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8416 | if (mParent instanceof View) { |
| 8417 | // GONE views noop invalidation, so invalidate the parent |
| 8418 | ((View) mParent).invalidate(true); |
| 8419 | } |
| 8420 | // Mark the view drawn to ensure that it gets invalidated properly the next |
| 8421 | // time it is visible and gets invalidated |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8422 | mPrivateFlags |= PFLAG_DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8423 | } |
| 8424 | if (mAttachInfo != null) { |
| 8425 | mAttachInfo.mViewVisibilityChanged = true; |
| 8426 | } |
| 8427 | } |
| 8428 | |
| 8429 | /* Check if the VISIBLE bit has changed */ |
| 8430 | if ((changed & INVISIBLE) != 0) { |
| 8431 | needGlobalAttributesUpdate(false); |
Chet Haase | c8a9a70 | 2011-06-17 12:13:42 -0700 | [diff] [blame] | 8432 | /* |
| 8433 | * If this view is becoming invisible, set the DRAWN flag so that |
| 8434 | * the next invalidate() will not be skipped. |
| 8435 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8436 | mPrivateFlags |= PFLAG_DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8437 | |
| 8438 | if (((mViewFlags & VISIBILITY_MASK) == INVISIBLE) && hasFocus()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8439 | // 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] | 8440 | if (getRootView() != this) { |
| 8441 | clearFocus(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8442 | clearAccessibilityFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8443 | } |
| 8444 | } |
| 8445 | if (mAttachInfo != null) { |
| 8446 | mAttachInfo.mViewVisibilityChanged = true; |
| 8447 | } |
| 8448 | } |
| 8449 | |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 8450 | if ((changed & VISIBILITY_MASK) != 0) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 8451 | if (mParent instanceof ViewGroup) { |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 8452 | ((ViewGroup) mParent).onChildVisibilityChanged(this, |
| 8453 | (changed & VISIBILITY_MASK), (flags & VISIBILITY_MASK)); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8454 | ((View) mParent).invalidate(true); |
Chet Haase | e4e6e20 | 2011-08-29 14:34:30 -0700 | [diff] [blame] | 8455 | } else if (mParent != null) { |
| 8456 | mParent.invalidateChild(this, null); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 8457 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 8458 | dispatchVisibilityChanged(this, (flags & VISIBILITY_MASK)); |
| 8459 | } |
| 8460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8461 | if ((changed & WILL_NOT_CACHE_DRAWING) != 0) { |
| 8462 | destroyDrawingCache(); |
| 8463 | } |
| 8464 | |
| 8465 | if ((changed & DRAWING_CACHE_ENABLED) != 0) { |
| 8466 | destroyDrawingCache(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8467 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8468 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8469 | } |
| 8470 | |
| 8471 | if ((changed & DRAWING_CACHE_QUALITY_MASK) != 0) { |
| 8472 | destroyDrawingCache(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8473 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8474 | } |
| 8475 | |
| 8476 | if ((changed & DRAW_MASK) != 0) { |
| 8477 | if ((mViewFlags & WILL_NOT_DRAW) != 0) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8478 | if (mBackground != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8479 | mPrivateFlags &= ~PFLAG_SKIP_DRAW; |
| 8480 | mPrivateFlags |= PFLAG_ONLY_DRAWS_BACKGROUND; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8481 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8482 | mPrivateFlags |= PFLAG_SKIP_DRAW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8483 | } |
| 8484 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8485 | mPrivateFlags &= ~PFLAG_SKIP_DRAW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8486 | } |
| 8487 | requestLayout(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8488 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8489 | } |
| 8490 | |
| 8491 | if ((changed & KEEP_SCREEN_ON) != 0) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8492 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8493 | mParent.recomputeViewAttributes(this); |
| 8494 | } |
| 8495 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8496 | |
| 8497 | if (AccessibilityManager.getInstance(mContext).isEnabled() |
| 8498 | && ((changed & FOCUSABLE) != 0 || (changed & CLICKABLE) != 0 |
| 8499 | || (changed & LONG_CLICKABLE) != 0 || (changed & ENABLED) != 0)) { |
| 8500 | notifyAccessibilityStateChanged(); |
| 8501 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8502 | } |
| 8503 | |
| 8504 | /** |
| 8505 | * Change the view's z order in the tree, so it's on top of other sibling |
| 8506 | * views |
| 8507 | */ |
| 8508 | public void bringToFront() { |
| 8509 | if (mParent != null) { |
| 8510 | mParent.bringChildToFront(this); |
| 8511 | } |
| 8512 | } |
| 8513 | |
| 8514 | /** |
| 8515 | * This is called in response to an internal scroll in this view (i.e., the |
| 8516 | * view scrolled its own contents). This is typically as a result of |
| 8517 | * {@link #scrollBy(int, int)} or {@link #scrollTo(int, int)} having been |
| 8518 | * called. |
| 8519 | * |
| 8520 | * @param l Current horizontal scroll origin. |
| 8521 | * @param t Current vertical scroll origin. |
| 8522 | * @param oldl Previous horizontal scroll origin. |
| 8523 | * @param oldt Previous vertical scroll origin. |
| 8524 | */ |
| 8525 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8526 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 8527 | postSendViewScrolledAccessibilityEventCallback(); |
| 8528 | } |
| 8529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8530 | mBackgroundSizeChanged = true; |
| 8531 | |
| 8532 | final AttachInfo ai = mAttachInfo; |
| 8533 | if (ai != null) { |
| 8534 | ai.mViewScrollChanged = true; |
| 8535 | } |
| 8536 | } |
| 8537 | |
| 8538 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8539 | * Interface definition for a callback to be invoked when the layout bounds of a view |
| 8540 | * changes due to layout processing. |
| 8541 | */ |
| 8542 | public interface OnLayoutChangeListener { |
| 8543 | /** |
| 8544 | * Called when the focus state of a view has changed. |
| 8545 | * |
| 8546 | * @param v The view whose state has changed. |
| 8547 | * @param left The new value of the view's left property. |
| 8548 | * @param top The new value of the view's top property. |
| 8549 | * @param right The new value of the view's right property. |
| 8550 | * @param bottom The new value of the view's bottom property. |
| 8551 | * @param oldLeft The previous value of the view's left property. |
| 8552 | * @param oldTop The previous value of the view's top property. |
| 8553 | * @param oldRight The previous value of the view's right property. |
| 8554 | * @param oldBottom The previous value of the view's bottom property. |
| 8555 | */ |
| 8556 | void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 8557 | int oldLeft, int oldTop, int oldRight, int oldBottom); |
| 8558 | } |
| 8559 | |
| 8560 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8561 | * This is called during layout when the size of this view has changed. If |
| 8562 | * you were just added to the view hierarchy, you're called with the old |
| 8563 | * values of 0. |
| 8564 | * |
| 8565 | * @param w Current width of this view. |
| 8566 | * @param h Current height of this view. |
| 8567 | * @param oldw Old width of this view. |
| 8568 | * @param oldh Old height of this view. |
| 8569 | */ |
| 8570 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 8571 | } |
| 8572 | |
| 8573 | /** |
| 8574 | * Called by draw to draw the child views. This may be overridden |
| 8575 | * by derived classes to gain control just before its children are drawn |
| 8576 | * (but after its own view has been drawn). |
| 8577 | * @param canvas the canvas on which to draw the view |
| 8578 | */ |
| 8579 | protected void dispatchDraw(Canvas canvas) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8581 | } |
| 8582 | |
| 8583 | /** |
| 8584 | * Gets the parent of this view. Note that the parent is a |
| 8585 | * ViewParent and not necessarily a View. |
| 8586 | * |
| 8587 | * @return Parent of this view. |
| 8588 | */ |
| 8589 | public final ViewParent getParent() { |
| 8590 | return mParent; |
| 8591 | } |
| 8592 | |
| 8593 | /** |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 8594 | * Set the horizontal scrolled position of your view. This will cause a call to |
| 8595 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8596 | * invalidated. |
| 8597 | * @param value the x position to scroll to |
| 8598 | */ |
| 8599 | public void setScrollX(int value) { |
| 8600 | scrollTo(value, mScrollY); |
| 8601 | } |
| 8602 | |
| 8603 | /** |
| 8604 | * Set the vertical scrolled position of your view. This will cause a call to |
| 8605 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8606 | * invalidated. |
| 8607 | * @param value the y position to scroll to |
| 8608 | */ |
| 8609 | public void setScrollY(int value) { |
| 8610 | scrollTo(mScrollX, value); |
| 8611 | } |
| 8612 | |
| 8613 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8614 | * Return the scrolled left position of this view. This is the left edge of |
| 8615 | * the displayed part of your view. You do not need to draw any pixels |
| 8616 | * farther left, since those are outside of the frame of your view on |
| 8617 | * screen. |
| 8618 | * |
| 8619 | * @return The left edge of the displayed part of your view, in pixels. |
| 8620 | */ |
| 8621 | public final int getScrollX() { |
| 8622 | return mScrollX; |
| 8623 | } |
| 8624 | |
| 8625 | /** |
| 8626 | * Return the scrolled top position of this view. This is the top edge of |
| 8627 | * the displayed part of your view. You do not need to draw any pixels above |
| 8628 | * it, since those are outside of the frame of your view on screen. |
| 8629 | * |
| 8630 | * @return The top edge of the displayed part of your view, in pixels. |
| 8631 | */ |
| 8632 | public final int getScrollY() { |
| 8633 | return mScrollY; |
| 8634 | } |
| 8635 | |
| 8636 | /** |
| 8637 | * Return the width of the your view. |
| 8638 | * |
| 8639 | * @return The width of your view, in pixels. |
| 8640 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 8641 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8642 | public final int getWidth() { |
| 8643 | return mRight - mLeft; |
| 8644 | } |
| 8645 | |
| 8646 | /** |
| 8647 | * Return the height of your view. |
| 8648 | * |
| 8649 | * @return The height of your view, in pixels. |
| 8650 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 8651 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8652 | public final int getHeight() { |
| 8653 | return mBottom - mTop; |
| 8654 | } |
| 8655 | |
| 8656 | /** |
| 8657 | * Return the visible drawing bounds of your view. Fills in the output |
| 8658 | * rectangle with the values from getScrollX(), getScrollY(), |
| 8659 | * getWidth(), and getHeight(). |
| 8660 | * |
| 8661 | * @param outRect The (scrolled) drawing bounds of the view. |
| 8662 | */ |
| 8663 | public void getDrawingRect(Rect outRect) { |
| 8664 | outRect.left = mScrollX; |
| 8665 | outRect.top = mScrollY; |
| 8666 | outRect.right = mScrollX + (mRight - mLeft); |
| 8667 | outRect.bottom = mScrollY + (mBottom - mTop); |
| 8668 | } |
| 8669 | |
| 8670 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8671 | * Like {@link #getMeasuredWidthAndState()}, but only returns the |
| 8672 | * raw width component (that is the result is masked by |
| 8673 | * {@link #MEASURED_SIZE_MASK}). |
| 8674 | * |
| 8675 | * @return The raw measured width of this view. |
| 8676 | */ |
| 8677 | public final int getMeasuredWidth() { |
| 8678 | return mMeasuredWidth & MEASURED_SIZE_MASK; |
| 8679 | } |
| 8680 | |
| 8681 | /** |
| 8682 | * Return the full width measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8683 | * 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] | 8684 | * 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] | 8685 | * This should be used during measurement and layout calculations only. Use |
| 8686 | * {@link #getWidth()} to see how wide a view is after layout. |
| 8687 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8688 | * @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] | 8689 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8690 | public final int getMeasuredWidthAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8691 | return mMeasuredWidth; |
| 8692 | } |
| 8693 | |
| 8694 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8695 | * Like {@link #getMeasuredHeightAndState()}, but only returns the |
| 8696 | * raw width component (that is the result is masked by |
| 8697 | * {@link #MEASURED_SIZE_MASK}). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8698 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8699 | * @return The raw measured height of this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8700 | */ |
| 8701 | public final int getMeasuredHeight() { |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8702 | return mMeasuredHeight & MEASURED_SIZE_MASK; |
| 8703 | } |
| 8704 | |
| 8705 | /** |
| 8706 | * Return the full height measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8707 | * 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] | 8708 | * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
| 8709 | * This should be used during measurement and layout calculations only. Use |
| 8710 | * {@link #getHeight()} to see how wide a view is after layout. |
| 8711 | * |
| 8712 | * @return The measured width of this view as a bit mask. |
| 8713 | */ |
| 8714 | public final int getMeasuredHeightAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8715 | return mMeasuredHeight; |
| 8716 | } |
| 8717 | |
| 8718 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8719 | * Return only the state bits of {@link #getMeasuredWidthAndState()} |
| 8720 | * and {@link #getMeasuredHeightAndState()}, combined into one integer. |
| 8721 | * The width component is in the regular bits {@link #MEASURED_STATE_MASK} |
| 8722 | * and the height component is at the shifted bits |
| 8723 | * {@link #MEASURED_HEIGHT_STATE_SHIFT}>>{@link #MEASURED_STATE_MASK}. |
| 8724 | */ |
| 8725 | public final int getMeasuredState() { |
| 8726 | return (mMeasuredWidth&MEASURED_STATE_MASK) |
| 8727 | | ((mMeasuredHeight>>MEASURED_HEIGHT_STATE_SHIFT) |
| 8728 | & (MEASURED_STATE_MASK>>MEASURED_HEIGHT_STATE_SHIFT)); |
| 8729 | } |
| 8730 | |
| 8731 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8732 | * The transform matrix of this view, which is calculated based on the current |
| 8733 | * roation, scale, and pivot properties. |
| 8734 | * |
| 8735 | * @see #getRotation() |
| 8736 | * @see #getScaleX() |
| 8737 | * @see #getScaleY() |
| 8738 | * @see #getPivotX() |
| 8739 | * @see #getPivotY() |
| 8740 | * @return The current transform matrix for the view |
| 8741 | */ |
| 8742 | public Matrix getMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8743 | if (mTransformationInfo != null) { |
| 8744 | updateMatrix(); |
| 8745 | return mTransformationInfo.mMatrix; |
| 8746 | } |
| 8747 | return Matrix.IDENTITY_MATRIX; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8748 | } |
| 8749 | |
| 8750 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8751 | * Utility function to determine if the value is far enough away from zero to be |
| 8752 | * considered non-zero. |
| 8753 | * @param value A floating point value to check for zero-ness |
| 8754 | * @return whether the passed-in value is far enough away from zero to be considered non-zero |
| 8755 | */ |
| 8756 | private static boolean nonzero(float value) { |
| 8757 | return (value < -NONZERO_EPSILON || value > NONZERO_EPSILON); |
| 8758 | } |
| 8759 | |
| 8760 | /** |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8761 | * Returns true if the transform matrix is the identity matrix. |
| 8762 | * Recomputes the matrix if necessary. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8763 | * |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8764 | * @return True if the transform matrix is the identity matrix, false otherwise. |
| 8765 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8766 | final boolean hasIdentityMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8767 | if (mTransformationInfo != null) { |
| 8768 | updateMatrix(); |
| 8769 | return mTransformationInfo.mMatrixIsIdentity; |
| 8770 | } |
| 8771 | return true; |
| 8772 | } |
| 8773 | |
| 8774 | void ensureTransformationInfo() { |
| 8775 | if (mTransformationInfo == null) { |
| 8776 | mTransformationInfo = new TransformationInfo(); |
| 8777 | } |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8778 | } |
| 8779 | |
| 8780 | /** |
| 8781 | * Recomputes the transform matrix if necessary. |
| 8782 | */ |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8783 | private void updateMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8784 | final TransformationInfo info = mTransformationInfo; |
| 8785 | if (info == null) { |
| 8786 | return; |
| 8787 | } |
| 8788 | if (info.mMatrixDirty) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8789 | // transform-related properties have changed since the last time someone |
| 8790 | // asked for the matrix; recalculate it with the current values |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8791 | |
| 8792 | // Figure out if we need to update the pivot point |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8793 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8794 | if ((mRight - mLeft) != info.mPrevWidth || (mBottom - mTop) != info.mPrevHeight) { |
| 8795 | info.mPrevWidth = mRight - mLeft; |
| 8796 | info.mPrevHeight = mBottom - mTop; |
| 8797 | info.mPivotX = info.mPrevWidth / 2f; |
| 8798 | info.mPivotY = info.mPrevHeight / 2f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8799 | } |
| 8800 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8801 | info.mMatrix.reset(); |
| 8802 | if (!nonzero(info.mRotationX) && !nonzero(info.mRotationY)) { |
| 8803 | info.mMatrix.setTranslate(info.mTranslationX, info.mTranslationY); |
| 8804 | info.mMatrix.preRotate(info.mRotation, info.mPivotX, info.mPivotY); |
| 8805 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8806 | } else { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8807 | if (info.mCamera == null) { |
| 8808 | info.mCamera = new Camera(); |
| 8809 | info.matrix3D = new Matrix(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8810 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8811 | info.mCamera.save(); |
| 8812 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
| 8813 | info.mCamera.rotate(info.mRotationX, info.mRotationY, -info.mRotation); |
| 8814 | info.mCamera.getMatrix(info.matrix3D); |
| 8815 | info.matrix3D.preTranslate(-info.mPivotX, -info.mPivotY); |
| 8816 | info.matrix3D.postTranslate(info.mPivotX + info.mTranslationX, |
| 8817 | info.mPivotY + info.mTranslationY); |
| 8818 | info.mMatrix.postConcat(info.matrix3D); |
| 8819 | info.mCamera.restore(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8820 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8821 | info.mMatrixDirty = false; |
| 8822 | info.mMatrixIsIdentity = info.mMatrix.isIdentity(); |
| 8823 | info.mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8824 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8825 | } |
| 8826 | |
Tobias Dubois | defdb1e | 2010-12-15 11:35:30 +0100 | [diff] [blame] | 8827 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8828 | * Utility method to retrieve the inverse of the current mMatrix property. |
| 8829 | * We cache the matrix to avoid recalculating it when transform properties |
| 8830 | * have not changed. |
| 8831 | * |
| 8832 | * @return The inverse of the current matrix of this view. |
| 8833 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8834 | final Matrix getInverseMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8835 | final TransformationInfo info = mTransformationInfo; |
| 8836 | if (info != null) { |
| 8837 | updateMatrix(); |
| 8838 | if (info.mInverseMatrixDirty) { |
| 8839 | if (info.mInverseMatrix == null) { |
| 8840 | info.mInverseMatrix = new Matrix(); |
| 8841 | } |
| 8842 | info.mMatrix.invert(info.mInverseMatrix); |
| 8843 | info.mInverseMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8844 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8845 | return info.mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8846 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8847 | return Matrix.IDENTITY_MATRIX; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8848 | } |
| 8849 | |
| 8850 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8851 | * Gets the distance along the Z axis from the camera to this view. |
| 8852 | * |
| 8853 | * @see #setCameraDistance(float) |
| 8854 | * |
| 8855 | * @return The distance along the Z axis. |
| 8856 | */ |
| 8857 | public float getCameraDistance() { |
| 8858 | ensureTransformationInfo(); |
| 8859 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
| 8860 | final TransformationInfo info = mTransformationInfo; |
| 8861 | if (info.mCamera == null) { |
| 8862 | info.mCamera = new Camera(); |
| 8863 | info.matrix3D = new Matrix(); |
| 8864 | } |
| 8865 | return -(info.mCamera.getLocationZ() * dpi); |
| 8866 | } |
| 8867 | |
| 8868 | /** |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8869 | * <p>Sets the distance along the Z axis (orthogonal to the X/Y plane on which |
| 8870 | * views are drawn) from the camera to this view. The camera's distance |
| 8871 | * affects 3D transformations, for instance rotations around the X and Y |
| 8872 | * 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] | 8873 | * 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] | 8874 | * use a camera distance that's greater than the height (X axis rotation) or |
| 8875 | * the width (Y axis rotation) of this view.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8876 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8877 | * <p>The distance of the camera from the view plane can have an affect on the |
| 8878 | * perspective distortion of the view when it is rotated around the x or y axis. |
| 8879 | * For example, a large distance will result in a large viewing angle, and there |
| 8880 | * 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] | 8881 | * distance may cause much more perspective distortion upon rotation, and can |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8882 | * also result in some drawing artifacts if the rotated view ends up partially |
| 8883 | * behind the camera (which is why the recommendation is to use a distance at |
| 8884 | * 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] | 8885 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8886 | * <p>The distance is expressed in "depth pixels." The default distance depends |
| 8887 | * on the screen density. For instance, on a medium density display, the |
| 8888 | * default distance is 1280. On a high density display, the default distance |
| 8889 | * is 1920.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8890 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8891 | * <p>If you want to specify a distance that leads to visually consistent |
| 8892 | * results across various densities, use the following formula:</p> |
| 8893 | * <pre> |
| 8894 | * float scale = context.getResources().getDisplayMetrics().density; |
| 8895 | * view.setCameraDistance(distance * scale); |
| 8896 | * </pre> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8897 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8898 | * <p>The density scale factor of a high density display is 1.5, |
| 8899 | * and 1920 = 1280 * 1.5.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8900 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8901 | * @param distance The distance in "depth pixels", if negative the opposite |
| 8902 | * value is used |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8903 | * |
| 8904 | * @see #setRotationX(float) |
| 8905 | * @see #setRotationY(float) |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8906 | */ |
| 8907 | public void setCameraDistance(float distance) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8908 | invalidateViewProperty(true, false); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8909 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8910 | ensureTransformationInfo(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8911 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8912 | final TransformationInfo info = mTransformationInfo; |
| 8913 | if (info.mCamera == null) { |
| 8914 | info.mCamera = new Camera(); |
| 8915 | info.matrix3D = new Matrix(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8916 | } |
| 8917 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8918 | info.mCamera.setLocation(0.0f, 0.0f, -Math.abs(distance) / dpi); |
| 8919 | info.mMatrixDirty = true; |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8920 | |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8921 | invalidateViewProperty(false, false); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8922 | if (mDisplayList != null) { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 8923 | mDisplayList.setCameraDistance(-Math.abs(distance) / dpi); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8924 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8925 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 8926 | // View was rejected last time it was drawn by its parent; this may have changed |
| 8927 | invalidateParentIfNeeded(); |
| 8928 | } |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8929 | } |
| 8930 | |
| 8931 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8932 | * The degrees that the view is rotated around the pivot point. |
| 8933 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8934 | * @see #setRotation(float) |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8935 | * @see #getPivotX() |
| 8936 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8937 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8938 | * @return The degrees of rotation. |
| 8939 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8940 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8941 | public float getRotation() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8942 | return mTransformationInfo != null ? mTransformationInfo.mRotation : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8943 | } |
| 8944 | |
| 8945 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8946 | * Sets the degrees that the view is rotated around the pivot point. Increasing values |
| 8947 | * result in clockwise rotation. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8948 | * |
| 8949 | * @param rotation The degrees of rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8950 | * |
| 8951 | * @see #getRotation() |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8952 | * @see #getPivotX() |
| 8953 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8954 | * @see #setRotationX(float) |
| 8955 | * @see #setRotationY(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8956 | * |
| 8957 | * @attr ref android.R.styleable#View_rotation |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8958 | */ |
| 8959 | public void setRotation(float rotation) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8960 | ensureTransformationInfo(); |
| 8961 | final TransformationInfo info = mTransformationInfo; |
| 8962 | if (info.mRotation != rotation) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8963 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8964 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8965 | info.mRotation = rotation; |
| 8966 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8967 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8968 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8969 | mDisplayList.setRotation(rotation); |
| 8970 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8971 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 8972 | // View was rejected last time it was drawn by its parent; this may have changed |
| 8973 | invalidateParentIfNeeded(); |
| 8974 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8975 | } |
| 8976 | } |
| 8977 | |
| 8978 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8979 | * The degrees that the view is rotated around the vertical axis through the pivot point. |
| 8980 | * |
| 8981 | * @see #getPivotX() |
| 8982 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8983 | * @see #setRotationY(float) |
| 8984 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8985 | * @return The degrees of Y rotation. |
| 8986 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8987 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8988 | public float getRotationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8989 | return mTransformationInfo != null ? mTransformationInfo.mRotationY : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8990 | } |
| 8991 | |
| 8992 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8993 | * Sets the degrees that the view is rotated around the vertical axis through the pivot point. |
| 8994 | * Increasing values result in counter-clockwise rotation from the viewpoint of looking |
| 8995 | * down the y axis. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8996 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8997 | * When rotating large views, it is recommended to adjust the camera distance |
| 8998 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8999 | * |
| 9000 | * @param rotationY The degrees of Y rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9001 | * |
| 9002 | * @see #getRotationY() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9003 | * @see #getPivotX() |
| 9004 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9005 | * @see #setRotation(float) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9006 | * @see #setRotationX(float) |
| 9007 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9008 | * |
| 9009 | * @attr ref android.R.styleable#View_rotationY |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9010 | */ |
| 9011 | public void setRotationY(float rotationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9012 | ensureTransformationInfo(); |
| 9013 | final TransformationInfo info = mTransformationInfo; |
| 9014 | if (info.mRotationY != rotationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9015 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9016 | info.mRotationY = rotationY; |
| 9017 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9018 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9019 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9020 | mDisplayList.setRotationY(rotationY); |
| 9021 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9022 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9023 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9024 | invalidateParentIfNeeded(); |
| 9025 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9026 | } |
| 9027 | } |
| 9028 | |
| 9029 | /** |
| 9030 | * The degrees that the view is rotated around the horizontal axis through the pivot point. |
| 9031 | * |
| 9032 | * @see #getPivotX() |
| 9033 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9034 | * @see #setRotationX(float) |
| 9035 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9036 | * @return The degrees of X rotation. |
| 9037 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9038 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9039 | public float getRotationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9040 | return mTransformationInfo != null ? mTransformationInfo.mRotationX : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9041 | } |
| 9042 | |
| 9043 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 9044 | * Sets the degrees that the view is rotated around the horizontal axis through the pivot point. |
| 9045 | * Increasing values result in clockwise rotation from the viewpoint of looking down the |
| 9046 | * x axis. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9047 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9048 | * When rotating large views, it is recommended to adjust the camera distance |
| 9049 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9050 | * |
| 9051 | * @param rotationX The degrees of X rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9052 | * |
| 9053 | * @see #getRotationX() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9054 | * @see #getPivotX() |
| 9055 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9056 | * @see #setRotation(float) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9057 | * @see #setRotationY(float) |
| 9058 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9059 | * |
| 9060 | * @attr ref android.R.styleable#View_rotationX |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9061 | */ |
| 9062 | public void setRotationX(float rotationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9063 | ensureTransformationInfo(); |
| 9064 | final TransformationInfo info = mTransformationInfo; |
| 9065 | if (info.mRotationX != rotationX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9066 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9067 | info.mRotationX = rotationX; |
| 9068 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9069 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9070 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9071 | mDisplayList.setRotationX(rotationX); |
| 9072 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9073 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9074 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9075 | invalidateParentIfNeeded(); |
| 9076 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9077 | } |
| 9078 | } |
| 9079 | |
| 9080 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9081 | * The amount that the view is scaled in x around the pivot point, as a proportion of |
| 9082 | * the view's unscaled width. A value of 1, the default, means that no scaling is applied. |
| 9083 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 9084 | * <p>By default, this is 1.0f. |
| 9085 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9086 | * @see #getPivotX() |
| 9087 | * @see #getPivotY() |
| 9088 | * @return The scaling factor. |
| 9089 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9090 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9091 | public float getScaleX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9092 | return mTransformationInfo != null ? mTransformationInfo.mScaleX : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9093 | } |
| 9094 | |
| 9095 | /** |
| 9096 | * Sets the amount that the view is scaled in x around the pivot point, as a proportion of |
| 9097 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 9098 | * |
| 9099 | * @param scaleX The scaling factor. |
| 9100 | * @see #getPivotX() |
| 9101 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9102 | * |
| 9103 | * @attr ref android.R.styleable#View_scaleX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9104 | */ |
| 9105 | public void setScaleX(float scaleX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9106 | ensureTransformationInfo(); |
| 9107 | final TransformationInfo info = mTransformationInfo; |
| 9108 | if (info.mScaleX != scaleX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9109 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9110 | info.mScaleX = scaleX; |
| 9111 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9112 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9113 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9114 | mDisplayList.setScaleX(scaleX); |
| 9115 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9116 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9117 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9118 | invalidateParentIfNeeded(); |
| 9119 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9120 | } |
| 9121 | } |
| 9122 | |
| 9123 | /** |
| 9124 | * The amount that the view is scaled in y around the pivot point, as a proportion of |
| 9125 | * the view's unscaled height. A value of 1, the default, means that no scaling is applied. |
| 9126 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 9127 | * <p>By default, this is 1.0f. |
| 9128 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9129 | * @see #getPivotX() |
| 9130 | * @see #getPivotY() |
| 9131 | * @return The scaling factor. |
| 9132 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9133 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9134 | public float getScaleY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9135 | return mTransformationInfo != null ? mTransformationInfo.mScaleY : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9136 | } |
| 9137 | |
| 9138 | /** |
| 9139 | * Sets the amount that the view is scaled in Y around the pivot point, as a proportion of |
| 9140 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 9141 | * |
| 9142 | * @param scaleY The scaling factor. |
| 9143 | * @see #getPivotX() |
| 9144 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9145 | * |
| 9146 | * @attr ref android.R.styleable#View_scaleY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9147 | */ |
| 9148 | public void setScaleY(float scaleY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9149 | ensureTransformationInfo(); |
| 9150 | final TransformationInfo info = mTransformationInfo; |
| 9151 | if (info.mScaleY != scaleY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9152 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9153 | info.mScaleY = scaleY; |
| 9154 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9155 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9156 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9157 | mDisplayList.setScaleY(scaleY); |
| 9158 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9159 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9160 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9161 | invalidateParentIfNeeded(); |
| 9162 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9163 | } |
| 9164 | } |
| 9165 | |
| 9166 | /** |
| 9167 | * The x location of the point around which the view is {@link #setRotation(float) rotated} |
| 9168 | * and {@link #setScaleX(float) scaled}. |
| 9169 | * |
| 9170 | * @see #getRotation() |
| 9171 | * @see #getScaleX() |
| 9172 | * @see #getScaleY() |
| 9173 | * @see #getPivotY() |
| 9174 | * @return The x location of the pivot point. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9175 | * |
| 9176 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9177 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9178 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9179 | public float getPivotX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9180 | return mTransformationInfo != null ? mTransformationInfo.mPivotX : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9181 | } |
| 9182 | |
| 9183 | /** |
| 9184 | * Sets the x location of the point around which the view is |
| 9185 | * {@link #setRotation(float) rotated} and {@link #setScaleX(float) scaled}. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9186 | * By default, the pivot point is centered on the object. |
| 9187 | * Setting this property disables this behavior and causes the view to use only the |
| 9188 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9189 | * |
| 9190 | * @param pivotX The x location of the pivot point. |
| 9191 | * @see #getRotation() |
| 9192 | * @see #getScaleX() |
| 9193 | * @see #getScaleY() |
| 9194 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9195 | * |
| 9196 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9197 | */ |
| 9198 | public void setPivotX(float pivotX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9199 | ensureTransformationInfo(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9200 | mPrivateFlags |= PFLAG_PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9201 | final TransformationInfo info = mTransformationInfo; |
| 9202 | if (info.mPivotX != pivotX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9203 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9204 | info.mPivotX = pivotX; |
| 9205 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9206 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9207 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9208 | mDisplayList.setPivotX(pivotX); |
| 9209 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9210 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9211 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9212 | invalidateParentIfNeeded(); |
| 9213 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9214 | } |
| 9215 | } |
| 9216 | |
| 9217 | /** |
| 9218 | * The y location of the point around which the view is {@link #setRotation(float) rotated} |
| 9219 | * and {@link #setScaleY(float) scaled}. |
| 9220 | * |
| 9221 | * @see #getRotation() |
| 9222 | * @see #getScaleX() |
| 9223 | * @see #getScaleY() |
| 9224 | * @see #getPivotY() |
| 9225 | * @return The y location of the pivot point. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9226 | * |
| 9227 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9228 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9229 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9230 | public float getPivotY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9231 | return mTransformationInfo != null ? mTransformationInfo.mPivotY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9232 | } |
| 9233 | |
| 9234 | /** |
| 9235 | * 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] | 9236 | * and {@link #setScaleY(float) scaled}. By default, the pivot point is centered on the object. |
| 9237 | * Setting this property disables this behavior and causes the view to use only the |
| 9238 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9239 | * |
| 9240 | * @param pivotY The y location of the pivot point. |
| 9241 | * @see #getRotation() |
| 9242 | * @see #getScaleX() |
| 9243 | * @see #getScaleY() |
| 9244 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9245 | * |
| 9246 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9247 | */ |
| 9248 | public void setPivotY(float pivotY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9249 | ensureTransformationInfo(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9250 | mPrivateFlags |= PFLAG_PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9251 | final TransformationInfo info = mTransformationInfo; |
| 9252 | if (info.mPivotY != pivotY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9253 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9254 | info.mPivotY = pivotY; |
| 9255 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9256 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9257 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9258 | mDisplayList.setPivotY(pivotY); |
| 9259 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9260 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9261 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9262 | invalidateParentIfNeeded(); |
| 9263 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9264 | } |
| 9265 | } |
| 9266 | |
| 9267 | /** |
| 9268 | * The opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 9269 | * completely transparent and 1 means the view is completely opaque. |
| 9270 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 9271 | * <p>By default this is 1.0f. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9272 | * @return The opacity of the view. |
| 9273 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9274 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9275 | public float getAlpha() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9276 | return mTransformationInfo != null ? mTransformationInfo.mAlpha : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9277 | } |
| 9278 | |
| 9279 | /** |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 9280 | * Returns whether this View has content which overlaps. This function, intended to be |
| 9281 | * overridden by specific View types, is an optimization when alpha is set on a view. If |
| 9282 | * rendering overlaps in a view with alpha < 1, that view is drawn to an offscreen buffer |
| 9283 | * and then composited it into place, which can be expensive. If the view has no overlapping |
| 9284 | * rendering, the view can draw each primitive with the appropriate alpha value directly. |
| 9285 | * An example of overlapping rendering is a TextView with a background image, such as a |
| 9286 | * Button. An example of non-overlapping rendering is a TextView with no background, or |
| 9287 | * an ImageView with only the foreground image. The default implementation returns true; |
| 9288 | * subclasses should override if they have cases which can be optimized. |
| 9289 | * |
| 9290 | * @return true if the content in this view might overlap, false otherwise. |
| 9291 | */ |
| 9292 | public boolean hasOverlappingRendering() { |
| 9293 | return true; |
| 9294 | } |
| 9295 | |
| 9296 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9297 | * <p>Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 9298 | * completely transparent and 1 means the view is completely opaque.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9299 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9300 | * <p>If this view overrides {@link #onSetAlpha(int)} to return true, then this view is |
| 9301 | * responsible for applying the opacity itself. Otherwise, calling this method is |
| 9302 | * equivalent to calling {@link #setLayerType(int, android.graphics.Paint)} and |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9303 | * setting a hardware layer.</p> |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9304 | * |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9305 | * <p>Note that setting alpha to a translucent value (0 < alpha < 1) may have |
| 9306 | * performance implications. It is generally best to use the alpha property sparingly and |
| 9307 | * transiently, as in the case of fading animations.</p> |
| 9308 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9309 | * @param alpha The opacity of the view. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9310 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9311 | * @see #setLayerType(int, android.graphics.Paint) |
| 9312 | * |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9313 | * @attr ref android.R.styleable#View_alpha |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9314 | */ |
| 9315 | public void setAlpha(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9316 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9317 | if (mTransformationInfo.mAlpha != alpha) { |
| 9318 | mTransformationInfo.mAlpha = alpha; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9319 | if (onSetAlpha((int) (alpha * 255))) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9320 | mPrivateFlags |= PFLAG_ALPHA_SET; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9321 | // subclass is handling alpha - don't optimize rendering cache invalidation |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9322 | invalidateParentCaches(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9323 | invalidate(true); |
| 9324 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9325 | mPrivateFlags &= ~PFLAG_ALPHA_SET; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9326 | invalidateViewProperty(true, false); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9327 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9328 | mDisplayList.setAlpha(alpha); |
| 9329 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9330 | } |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9331 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9332 | } |
| 9333 | |
| 9334 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 9335 | * Faster version of setAlpha() which performs the same steps except there are |
| 9336 | * no calls to invalidate(). The caller of this function should perform proper invalidation |
| 9337 | * on the parent and this object. The return value indicates whether the subclass handles |
| 9338 | * alpha (the return value for onSetAlpha()). |
| 9339 | * |
| 9340 | * @param alpha The new value for the alpha property |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9341 | * @return true if the View subclass handles alpha (the return value for onSetAlpha()) and |
| 9342 | * 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] | 9343 | */ |
| 9344 | boolean setAlphaNoInvalidation(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9345 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9346 | if (mTransformationInfo.mAlpha != alpha) { |
| 9347 | mTransformationInfo.mAlpha = alpha; |
| 9348 | boolean subclassHandlesAlpha = onSetAlpha((int) (alpha * 255)); |
| 9349 | if (subclassHandlesAlpha) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9350 | mPrivateFlags |= PFLAG_ALPHA_SET; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9351 | return true; |
| 9352 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9353 | mPrivateFlags &= ~PFLAG_ALPHA_SET; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9354 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9355 | mDisplayList.setAlpha(alpha); |
| 9356 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9357 | } |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 9358 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9359 | return false; |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 9360 | } |
| 9361 | |
| 9362 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9363 | * Top position of this view relative to its parent. |
| 9364 | * |
| 9365 | * @return The top of this view, in pixels. |
| 9366 | */ |
| 9367 | @ViewDebug.CapturedViewProperty |
| 9368 | public final int getTop() { |
| 9369 | return mTop; |
| 9370 | } |
| 9371 | |
| 9372 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9373 | * Sets the top position of this view relative to its parent. This method is meant to be called |
| 9374 | * by the layout system and should not generally be called otherwise, because the property |
| 9375 | * may be changed at any time by the layout. |
| 9376 | * |
| 9377 | * @param top The top of this view, in pixels. |
| 9378 | */ |
| 9379 | public final void setTop(int top) { |
| 9380 | if (top != mTop) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9381 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9382 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9383 | || mTransformationInfo.mMatrixIsIdentity; |
| 9384 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9385 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9386 | int minTop; |
| 9387 | int yLoc; |
| 9388 | if (top < mTop) { |
| 9389 | minTop = top; |
| 9390 | yLoc = top - mTop; |
| 9391 | } else { |
| 9392 | minTop = mTop; |
| 9393 | yLoc = 0; |
| 9394 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9395 | invalidate(0, yLoc, mRight - mLeft, mBottom - minTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9396 | } |
| 9397 | } else { |
| 9398 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9399 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9400 | } |
| 9401 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9402 | int width = mRight - mLeft; |
| 9403 | int oldHeight = mBottom - mTop; |
| 9404 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9405 | mTop = top; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9406 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9407 | mDisplayList.setTop(mTop); |
| 9408 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9409 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9410 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 9411 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9412 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9413 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9414 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9415 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9416 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9417 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9418 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9419 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9420 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9421 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9422 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9423 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9424 | invalidateParentIfNeeded(); |
| 9425 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9426 | } |
| 9427 | } |
| 9428 | |
| 9429 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9430 | * Bottom position of this view relative to its parent. |
| 9431 | * |
| 9432 | * @return The bottom of this view, in pixels. |
| 9433 | */ |
| 9434 | @ViewDebug.CapturedViewProperty |
| 9435 | public final int getBottom() { |
| 9436 | return mBottom; |
| 9437 | } |
| 9438 | |
| 9439 | /** |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 9440 | * True if this view has changed since the last time being drawn. |
| 9441 | * |
| 9442 | * @return The dirty state of this view. |
| 9443 | */ |
| 9444 | public boolean isDirty() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9445 | return (mPrivateFlags & PFLAG_DIRTY_MASK) != 0; |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 9446 | } |
| 9447 | |
| 9448 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9449 | * Sets the bottom position of this view relative to its parent. This method is meant to be |
| 9450 | * called by the layout system and should not generally be called otherwise, because the |
| 9451 | * property may be changed at any time by the layout. |
| 9452 | * |
| 9453 | * @param bottom The bottom of this view, in pixels. |
| 9454 | */ |
| 9455 | public final void setBottom(int bottom) { |
| 9456 | if (bottom != mBottom) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9457 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9458 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9459 | || mTransformationInfo.mMatrixIsIdentity; |
| 9460 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9461 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9462 | int maxBottom; |
| 9463 | if (bottom < mBottom) { |
| 9464 | maxBottom = mBottom; |
| 9465 | } else { |
| 9466 | maxBottom = bottom; |
| 9467 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9468 | invalidate(0, 0, mRight - mLeft, maxBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9469 | } |
| 9470 | } else { |
| 9471 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9472 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9473 | } |
| 9474 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9475 | int width = mRight - mLeft; |
| 9476 | int oldHeight = mBottom - mTop; |
| 9477 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9478 | mBottom = bottom; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9479 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9480 | mDisplayList.setBottom(mBottom); |
| 9481 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9482 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9483 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 9484 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9485 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9486 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9487 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9488 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9489 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9490 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9491 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9492 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9493 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9494 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9495 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9496 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9497 | invalidateParentIfNeeded(); |
| 9498 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9499 | } |
| 9500 | } |
| 9501 | |
| 9502 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9503 | * Left position of this view relative to its parent. |
| 9504 | * |
| 9505 | * @return The left edge of this view, in pixels. |
| 9506 | */ |
| 9507 | @ViewDebug.CapturedViewProperty |
| 9508 | public final int getLeft() { |
| 9509 | return mLeft; |
| 9510 | } |
| 9511 | |
| 9512 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9513 | * Sets the left position of this view relative to its parent. This method is meant to be called |
| 9514 | * by the layout system and should not generally be called otherwise, because the property |
| 9515 | * may be changed at any time by the layout. |
| 9516 | * |
| 9517 | * @param left The bottom of this view, in pixels. |
| 9518 | */ |
| 9519 | public final void setLeft(int left) { |
| 9520 | if (left != mLeft) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9521 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9522 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9523 | || mTransformationInfo.mMatrixIsIdentity; |
| 9524 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9525 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9526 | int minLeft; |
| 9527 | int xLoc; |
| 9528 | if (left < mLeft) { |
| 9529 | minLeft = left; |
| 9530 | xLoc = left - mLeft; |
| 9531 | } else { |
| 9532 | minLeft = mLeft; |
| 9533 | xLoc = 0; |
| 9534 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9535 | invalidate(xLoc, 0, mRight - minLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9536 | } |
| 9537 | } else { |
| 9538 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9539 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9540 | } |
| 9541 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9542 | int oldWidth = mRight - mLeft; |
| 9543 | int height = mBottom - mTop; |
| 9544 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9545 | mLeft = left; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9546 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9547 | mDisplayList.setLeft(left); |
| 9548 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9549 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9550 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 9551 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9552 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9553 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9554 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9555 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9556 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9557 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9558 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9559 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9560 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9561 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9562 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9563 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9564 | invalidateParentIfNeeded(); |
| 9565 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9566 | } |
| 9567 | } |
| 9568 | |
| 9569 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9570 | * Right position of this view relative to its parent. |
| 9571 | * |
| 9572 | * @return The right edge of this view, in pixels. |
| 9573 | */ |
| 9574 | @ViewDebug.CapturedViewProperty |
| 9575 | public final int getRight() { |
| 9576 | return mRight; |
| 9577 | } |
| 9578 | |
| 9579 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9580 | * Sets the right position of this view relative to its parent. This method is meant to be called |
| 9581 | * by the layout system and should not generally be called otherwise, because the property |
| 9582 | * may be changed at any time by the layout. |
| 9583 | * |
| 9584 | * @param right The bottom of this view, in pixels. |
| 9585 | */ |
| 9586 | public final void setRight(int right) { |
| 9587 | if (right != mRight) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9588 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9589 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9590 | || mTransformationInfo.mMatrixIsIdentity; |
| 9591 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9592 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9593 | int maxRight; |
| 9594 | if (right < mRight) { |
| 9595 | maxRight = mRight; |
| 9596 | } else { |
| 9597 | maxRight = right; |
| 9598 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9599 | invalidate(0, 0, maxRight - mLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9600 | } |
| 9601 | } else { |
| 9602 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9603 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9604 | } |
| 9605 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9606 | int oldWidth = mRight - mLeft; |
| 9607 | int height = mBottom - mTop; |
| 9608 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9609 | mRight = right; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9610 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9611 | mDisplayList.setRight(mRight); |
| 9612 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9613 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9614 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 9615 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9616 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9617 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9618 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9619 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9620 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9621 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9622 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9623 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9624 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9625 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9626 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9627 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9628 | invalidateParentIfNeeded(); |
| 9629 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9630 | } |
| 9631 | } |
| 9632 | |
| 9633 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9634 | * The visual x position of this view, in pixels. This is equivalent to the |
| 9635 | * {@link #setTranslationX(float) translationX} property plus the current |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9636 | * {@link #getLeft() left} property. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9637 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9638 | * @return The visual x position of this view, in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9639 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9640 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9641 | public float getX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9642 | return mLeft + (mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9643 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9644 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9645 | /** |
| 9646 | * Sets the visual x position of this view, in pixels. This is equivalent to setting the |
| 9647 | * {@link #setTranslationX(float) translationX} property to be the difference between |
| 9648 | * the x value passed in and the current {@link #getLeft() left} property. |
| 9649 | * |
| 9650 | * @param x The visual x position of this view, in pixels. |
| 9651 | */ |
| 9652 | public void setX(float x) { |
| 9653 | setTranslationX(x - mLeft); |
| 9654 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9655 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9656 | /** |
| 9657 | * The visual y position of this view, in pixels. This is equivalent to the |
| 9658 | * {@link #setTranslationY(float) translationY} property plus the current |
| 9659 | * {@link #getTop() top} property. |
| 9660 | * |
| 9661 | * @return The visual y position of this view, in pixels. |
| 9662 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9663 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9664 | public float getY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9665 | return mTop + (mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9666 | } |
| 9667 | |
| 9668 | /** |
| 9669 | * Sets the visual y position of this view, in pixels. This is equivalent to setting the |
| 9670 | * {@link #setTranslationY(float) translationY} property to be the difference between |
| 9671 | * the y value passed in and the current {@link #getTop() top} property. |
| 9672 | * |
| 9673 | * @param y The visual y position of this view, in pixels. |
| 9674 | */ |
| 9675 | public void setY(float y) { |
| 9676 | setTranslationY(y - mTop); |
| 9677 | } |
| 9678 | |
| 9679 | |
| 9680 | /** |
| 9681 | * The horizontal location of this view relative to its {@link #getLeft() left} position. |
| 9682 | * This position is post-layout, in addition to wherever the object's |
| 9683 | * layout placed it. |
| 9684 | * |
| 9685 | * @return The horizontal position of this view relative to its left position, in pixels. |
| 9686 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9687 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9688 | public float getTranslationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9689 | return mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9690 | } |
| 9691 | |
| 9692 | /** |
| 9693 | * Sets the horizontal location of this view relative to its {@link #getLeft() left} position. |
| 9694 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 9695 | * layout placed it. |
| 9696 | * |
| 9697 | * @param translationX The horizontal position of this view relative to its left position, |
| 9698 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9699 | * |
| 9700 | * @attr ref android.R.styleable#View_translationX |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9701 | */ |
| 9702 | public void setTranslationX(float translationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9703 | ensureTransformationInfo(); |
| 9704 | final TransformationInfo info = mTransformationInfo; |
| 9705 | if (info.mTranslationX != translationX) { |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9706 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9707 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9708 | info.mTranslationX = translationX; |
| 9709 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9710 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9711 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9712 | mDisplayList.setTranslationX(translationX); |
| 9713 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9714 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9715 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9716 | invalidateParentIfNeeded(); |
| 9717 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9718 | } |
| 9719 | } |
| 9720 | |
| 9721 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9722 | * The horizontal location of this view relative to its {@link #getTop() top} position. |
| 9723 | * This position is post-layout, in addition to wherever the object's |
| 9724 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9725 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9726 | * @return The vertical position of this view relative to its top position, |
| 9727 | * in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9728 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9729 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9730 | public float getTranslationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9731 | return mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9732 | } |
| 9733 | |
| 9734 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9735 | * Sets the vertical location of this view relative to its {@link #getTop() top} position. |
| 9736 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 9737 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9738 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9739 | * @param translationY The vertical position of this view relative to its top position, |
| 9740 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9741 | * |
| 9742 | * @attr ref android.R.styleable#View_translationY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9743 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9744 | public void setTranslationY(float translationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9745 | ensureTransformationInfo(); |
| 9746 | final TransformationInfo info = mTransformationInfo; |
| 9747 | if (info.mTranslationY != translationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9748 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9749 | info.mTranslationY = translationY; |
| 9750 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9751 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9752 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9753 | mDisplayList.setTranslationY(translationY); |
| 9754 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9755 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9756 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9757 | invalidateParentIfNeeded(); |
| 9758 | } |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9759 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9760 | } |
| 9761 | |
| 9762 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9763 | * Hit rectangle in parent's coordinates |
| 9764 | * |
| 9765 | * @param outRect The hit rectangle of the view. |
| 9766 | */ |
| 9767 | public void getHitRect(Rect outRect) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9768 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9769 | final TransformationInfo info = mTransformationInfo; |
| 9770 | if (info == null || info.mMatrixIsIdentity || mAttachInfo == null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9771 | outRect.set(mLeft, mTop, mRight, mBottom); |
| 9772 | } else { |
| 9773 | final RectF tmpRect = mAttachInfo.mTmpTransformRect; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9774 | tmpRect.set(-info.mPivotX, -info.mPivotY, |
| 9775 | getWidth() - info.mPivotX, getHeight() - info.mPivotY); |
| 9776 | info.mMatrix.mapRect(tmpRect); |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9777 | outRect.set((int) tmpRect.left + mLeft, (int) tmpRect.top + mTop, |
| 9778 | (int) tmpRect.right + mLeft, (int) tmpRect.bottom + mTop); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9779 | } |
| 9780 | } |
| 9781 | |
| 9782 | /** |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 9783 | * Determines whether the given point, in local coordinates is inside the view. |
| 9784 | */ |
| 9785 | /*package*/ final boolean pointInView(float localX, float localY) { |
| 9786 | return localX >= 0 && localX < (mRight - mLeft) |
| 9787 | && localY >= 0 && localY < (mBottom - mTop); |
| 9788 | } |
| 9789 | |
| 9790 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9791 | * Utility method to determine whether the given point, in local coordinates, |
| 9792 | * is inside the view, where the area of the view is expanded by the slop factor. |
| 9793 | * This method is called while processing touch-move events to determine if the event |
| 9794 | * is still within the view. |
| 9795 | */ |
| 9796 | private boolean pointInView(float localX, float localY, float slop) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 9797 | return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) && |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9798 | localY < ((mBottom - mTop) + slop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9799 | } |
| 9800 | |
| 9801 | /** |
| 9802 | * When a view has focus and the user navigates away from it, the next view is searched for |
| 9803 | * starting from the rectangle filled in by this method. |
| 9804 | * |
Fabrice Di Meglio | c11f77f | 2012-09-18 15:33:07 -0700 | [diff] [blame] | 9805 | * By default, the rectangle is the {@link #getDrawingRect(android.graphics.Rect)}) |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9806 | * of the view. However, if your view maintains some idea of internal selection, |
| 9807 | * such as a cursor, or a selected row or column, you should override this method and |
| 9808 | * fill in a more specific rectangle. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9809 | * |
| 9810 | * @param r The rectangle to fill in, in this view's coordinates. |
| 9811 | */ |
| 9812 | public void getFocusedRect(Rect r) { |
| 9813 | getDrawingRect(r); |
| 9814 | } |
| 9815 | |
| 9816 | /** |
| 9817 | * If some part of this view is not clipped by any of its parents, then |
| 9818 | * 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] | 9819 | * coordinates (without taking possible View rotations into account), offset |
| 9820 | * it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)). |
| 9821 | * 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] | 9822 | * |
| 9823 | * @param r If true is returned, r holds the global coordinates of the |
| 9824 | * visible portion of this view. |
| 9825 | * @param globalOffset If true is returned, globalOffset holds the dx,dy |
| 9826 | * between this view and its root. globalOffet may be null. |
| 9827 | * @return true if r is non-empty (i.e. part of the view is visible at the |
| 9828 | * root level. |
| 9829 | */ |
| 9830 | public boolean getGlobalVisibleRect(Rect r, Point globalOffset) { |
| 9831 | int width = mRight - mLeft; |
| 9832 | int height = mBottom - mTop; |
| 9833 | if (width > 0 && height > 0) { |
| 9834 | r.set(0, 0, width, height); |
| 9835 | if (globalOffset != null) { |
| 9836 | globalOffset.set(-mScrollX, -mScrollY); |
| 9837 | } |
| 9838 | return mParent == null || mParent.getChildVisibleRect(this, r, globalOffset); |
| 9839 | } |
| 9840 | return false; |
| 9841 | } |
| 9842 | |
| 9843 | public final boolean getGlobalVisibleRect(Rect r) { |
| 9844 | return getGlobalVisibleRect(r, null); |
| 9845 | } |
| 9846 | |
| 9847 | public final boolean getLocalVisibleRect(Rect r) { |
Romain Guy | ab4c4f4f | 2012-05-06 13:11:24 -0700 | [diff] [blame] | 9848 | final Point offset = mAttachInfo != null ? mAttachInfo.mPoint : new Point(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9849 | if (getGlobalVisibleRect(r, offset)) { |
| 9850 | r.offset(-offset.x, -offset.y); // make r local |
| 9851 | return true; |
| 9852 | } |
| 9853 | return false; |
| 9854 | } |
| 9855 | |
| 9856 | /** |
| 9857 | * Offset this view's vertical location by the specified number of pixels. |
| 9858 | * |
| 9859 | * @param offset the number of pixels to offset the view by |
| 9860 | */ |
| 9861 | public void offsetTopAndBottom(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9862 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9863 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9864 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9865 | || mTransformationInfo.mMatrixIsIdentity; |
| 9866 | if (matrixIsIdentity) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9867 | if (mDisplayList != null) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9868 | invalidateViewProperty(false, false); |
| 9869 | } else { |
| 9870 | final ViewParent p = mParent; |
| 9871 | if (p != null && mAttachInfo != null) { |
| 9872 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 9873 | int minTop; |
| 9874 | int maxBottom; |
| 9875 | int yLoc; |
| 9876 | if (offset < 0) { |
| 9877 | minTop = mTop + offset; |
| 9878 | maxBottom = mBottom; |
| 9879 | yLoc = offset; |
| 9880 | } else { |
| 9881 | minTop = mTop; |
| 9882 | maxBottom = mBottom + offset; |
| 9883 | yLoc = 0; |
| 9884 | } |
| 9885 | r.set(0, yLoc, mRight - mLeft, maxBottom - minTop); |
| 9886 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 9887 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9888 | } |
| 9889 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9890 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9891 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9892 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9893 | mTop += offset; |
| 9894 | mBottom += offset; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9895 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9896 | mDisplayList.offsetTopBottom(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9897 | invalidateViewProperty(false, false); |
| 9898 | } else { |
| 9899 | if (!matrixIsIdentity) { |
| 9900 | invalidateViewProperty(false, true); |
| 9901 | } |
| 9902 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9903 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9904 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9905 | } |
| 9906 | |
| 9907 | /** |
| 9908 | * Offset this view's horizontal location by the specified amount of pixels. |
| 9909 | * |
| 9910 | * @param offset the numer of pixels to offset the view by |
| 9911 | */ |
| 9912 | public void offsetLeftAndRight(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9913 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9914 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9915 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9916 | || mTransformationInfo.mMatrixIsIdentity; |
| 9917 | if (matrixIsIdentity) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9918 | if (mDisplayList != null) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9919 | invalidateViewProperty(false, false); |
| 9920 | } else { |
| 9921 | final ViewParent p = mParent; |
| 9922 | if (p != null && mAttachInfo != null) { |
| 9923 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 9924 | int minLeft; |
| 9925 | int maxRight; |
| 9926 | if (offset < 0) { |
| 9927 | minLeft = mLeft + offset; |
| 9928 | maxRight = mRight; |
| 9929 | } else { |
| 9930 | minLeft = mLeft; |
| 9931 | maxRight = mRight + offset; |
| 9932 | } |
| 9933 | r.set(0, 0, maxRight - minLeft, mBottom - mTop); |
| 9934 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 9935 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9936 | } |
| 9937 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9938 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9939 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9940 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9941 | mLeft += offset; |
| 9942 | mRight += offset; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9943 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9944 | mDisplayList.offsetLeftRight(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9945 | invalidateViewProperty(false, false); |
| 9946 | } else { |
| 9947 | if (!matrixIsIdentity) { |
| 9948 | invalidateViewProperty(false, true); |
| 9949 | } |
| 9950 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9951 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9952 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9953 | } |
| 9954 | |
| 9955 | /** |
| 9956 | * Get the LayoutParams associated with this view. All views should have |
| 9957 | * layout parameters. These supply parameters to the <i>parent</i> of this |
| 9958 | * view specifying how it should be arranged. There are many subclasses of |
| 9959 | * ViewGroup.LayoutParams, and these correspond to the different subclasses |
| 9960 | * of ViewGroup that are responsible for arranging their children. |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 9961 | * |
| 9962 | * This method may return null if this View is not attached to a parent |
| 9963 | * ViewGroup or {@link #setLayoutParams(android.view.ViewGroup.LayoutParams)} |
| 9964 | * was not invoked successfully. When a View is attached to a parent |
| 9965 | * ViewGroup, this method must not return null. |
| 9966 | * |
| 9967 | * @return The LayoutParams associated with this view, or null if no |
| 9968 | * parameters have been set yet |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9969 | */ |
Konstantin Lopyrev | 91a7f5f | 2010-08-10 18:54:54 -0700 | [diff] [blame] | 9970 | @ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9971 | public ViewGroup.LayoutParams getLayoutParams() { |
| 9972 | return mLayoutParams; |
| 9973 | } |
| 9974 | |
| 9975 | /** |
| 9976 | * Set the layout parameters associated with this view. These supply |
| 9977 | * parameters to the <i>parent</i> of this view specifying how it should be |
| 9978 | * arranged. There are many subclasses of ViewGroup.LayoutParams, and these |
| 9979 | * correspond to the different subclasses of ViewGroup that are responsible |
| 9980 | * for arranging their children. |
| 9981 | * |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 9982 | * @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] | 9983 | */ |
| 9984 | public void setLayoutParams(ViewGroup.LayoutParams params) { |
| 9985 | if (params == null) { |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 9986 | throw new NullPointerException("Layout parameters cannot be null"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9987 | } |
| 9988 | mLayoutParams = params; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 9989 | resolveLayoutParams(); |
Philip Milne | d7dd890 | 2012-01-26 16:55:30 -0800 | [diff] [blame] | 9990 | if (mParent instanceof ViewGroup) { |
| 9991 | ((ViewGroup) mParent).onSetLayoutParams(this, params); |
| 9992 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9993 | requestLayout(); |
| 9994 | } |
| 9995 | |
| 9996 | /** |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 9997 | * Resolve the layout parameters depending on the resolved layout direction |
| 9998 | */ |
| 9999 | private void resolveLayoutParams() { |
| 10000 | if (mLayoutParams != null) { |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 10001 | mLayoutParams.onResolveLayoutDirection(getLayoutDirection()); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 10002 | } |
| 10003 | } |
| 10004 | |
| 10005 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10006 | * Set the scrolled position of your view. This will cause a call to |
| 10007 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 10008 | * invalidated. |
| 10009 | * @param x the x position to scroll to |
| 10010 | * @param y the y position to scroll to |
| 10011 | */ |
| 10012 | public void scrollTo(int x, int y) { |
| 10013 | if (mScrollX != x || mScrollY != y) { |
| 10014 | int oldX = mScrollX; |
| 10015 | int oldY = mScrollY; |
| 10016 | mScrollX = x; |
| 10017 | mScrollY = y; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10018 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10019 | onScrollChanged(mScrollX, mScrollY, oldX, oldY); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10020 | if (!awakenScrollBars()) { |
Adam Powell | df3ae4f | 2012-04-10 18:55:22 -0700 | [diff] [blame] | 10021 | postInvalidateOnAnimation(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10022 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10023 | } |
| 10024 | } |
| 10025 | |
| 10026 | /** |
| 10027 | * Move the scrolled position of your view. This will cause a call to |
| 10028 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 10029 | * invalidated. |
| 10030 | * @param x the amount of pixels to scroll by horizontally |
| 10031 | * @param y the amount of pixels to scroll by vertically |
| 10032 | */ |
| 10033 | public void scrollBy(int x, int y) { |
| 10034 | scrollTo(mScrollX + x, mScrollY + y); |
| 10035 | } |
| 10036 | |
| 10037 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10038 | * <p>Trigger the scrollbars to draw. When invoked this method starts an |
| 10039 | * animation to fade the scrollbars out after a default delay. If a subclass |
| 10040 | * provides animated scrolling, the start delay should equal the duration |
| 10041 | * of the scrolling animation.</p> |
| 10042 | * |
| 10043 | * <p>The animation starts only if at least one of the scrollbars is |
| 10044 | * enabled, as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 10045 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 10046 | * this method returns true, and false otherwise. If the animation is |
| 10047 | * started, this method calls {@link #invalidate()}; in that case the |
| 10048 | * caller should not call {@link #invalidate()}.</p> |
| 10049 | * |
| 10050 | * <p>This method should be invoked every time a subclass directly updates |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10051 | * the scroll parameters.</p> |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10052 | * |
| 10053 | * <p>This method is automatically invoked by {@link #scrollBy(int, int)} |
| 10054 | * and {@link #scrollTo(int, int)}.</p> |
| 10055 | * |
| 10056 | * @return true if the animation is played, false otherwise |
| 10057 | * |
| 10058 | * @see #awakenScrollBars(int) |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10059 | * @see #scrollBy(int, int) |
| 10060 | * @see #scrollTo(int, int) |
| 10061 | * @see #isHorizontalScrollBarEnabled() |
| 10062 | * @see #isVerticalScrollBarEnabled() |
| 10063 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 10064 | * @see #setVerticalScrollBarEnabled(boolean) |
| 10065 | */ |
| 10066 | protected boolean awakenScrollBars() { |
| 10067 | return mScrollCache != null && |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10068 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade, true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10069 | } |
| 10070 | |
| 10071 | /** |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 10072 | * Trigger the scrollbars to draw. |
| 10073 | * This method differs from awakenScrollBars() only in its default duration. |
| 10074 | * initialAwakenScrollBars() will show the scroll bars for longer than |
| 10075 | * usual to give the user more of a chance to notice them. |
| 10076 | * |
| 10077 | * @return true if the animation is played, false otherwise. |
| 10078 | */ |
| 10079 | private boolean initialAwakenScrollBars() { |
| 10080 | return mScrollCache != null && |
| 10081 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade * 4, true); |
| 10082 | } |
| 10083 | |
| 10084 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10085 | * <p> |
| 10086 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 10087 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 10088 | * provides animated scrolling, the start delay should equal the duration of |
| 10089 | * the scrolling animation. |
| 10090 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10091 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10092 | * <p> |
| 10093 | * The animation starts only if at least one of the scrollbars is enabled, |
| 10094 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 10095 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 10096 | * this method returns true, and false otherwise. If the animation is |
| 10097 | * started, this method calls {@link #invalidate()}; in that case the caller |
| 10098 | * should not call {@link #invalidate()}. |
| 10099 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10100 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10101 | * <p> |
| 10102 | * This method should be invoked everytime a subclass directly updates the |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10103 | * scroll parameters. |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10104 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10105 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10106 | * @param startDelay the delay, in milliseconds, after which the animation |
| 10107 | * should start; when the delay is 0, the animation starts |
| 10108 | * immediately |
| 10109 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10110 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10111 | * @see #scrollBy(int, int) |
| 10112 | * @see #scrollTo(int, int) |
| 10113 | * @see #isHorizontalScrollBarEnabled() |
| 10114 | * @see #isVerticalScrollBarEnabled() |
| 10115 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 10116 | * @see #setVerticalScrollBarEnabled(boolean) |
| 10117 | */ |
| 10118 | protected boolean awakenScrollBars(int startDelay) { |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10119 | return awakenScrollBars(startDelay, true); |
| 10120 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10121 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10122 | /** |
| 10123 | * <p> |
| 10124 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 10125 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 10126 | * provides animated scrolling, the start delay should equal the duration of |
| 10127 | * the scrolling animation. |
| 10128 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10129 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10130 | * <p> |
| 10131 | * The animation starts only if at least one of the scrollbars is enabled, |
| 10132 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 10133 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 10134 | * this method returns true, and false otherwise. If the animation is |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10135 | * started, this method calls {@link #invalidate()} if the invalidate parameter |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10136 | * is set to true; in that case the caller |
| 10137 | * should not call {@link #invalidate()}. |
| 10138 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10139 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10140 | * <p> |
| 10141 | * This method should be invoked everytime a subclass directly updates the |
| 10142 | * scroll parameters. |
| 10143 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10144 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10145 | * @param startDelay the delay, in milliseconds, after which the animation |
| 10146 | * should start; when the delay is 0, the animation starts |
| 10147 | * immediately |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10148 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10149 | * @param invalidate Wheter this method should call invalidate |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10150 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10151 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10152 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10153 | * @see #scrollBy(int, int) |
| 10154 | * @see #scrollTo(int, int) |
| 10155 | * @see #isHorizontalScrollBarEnabled() |
| 10156 | * @see #isVerticalScrollBarEnabled() |
| 10157 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 10158 | * @see #setVerticalScrollBarEnabled(boolean) |
| 10159 | */ |
| 10160 | protected boolean awakenScrollBars(int startDelay, boolean invalidate) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10161 | final ScrollabilityCache scrollCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10162 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10163 | if (scrollCache == null || !scrollCache.fadeScrollBars) { |
| 10164 | return false; |
| 10165 | } |
| 10166 | |
| 10167 | if (scrollCache.scrollBar == null) { |
| 10168 | scrollCache.scrollBar = new ScrollBarDrawable(); |
| 10169 | } |
| 10170 | |
| 10171 | if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) { |
| 10172 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10173 | if (invalidate) { |
| 10174 | // Invalidate to show the scrollbars |
Adam Powell | df3ae4f | 2012-04-10 18:55:22 -0700 | [diff] [blame] | 10175 | postInvalidateOnAnimation(); |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10176 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10177 | |
| 10178 | if (scrollCache.state == ScrollabilityCache.OFF) { |
| 10179 | // FIXME: this is copied from WindowManagerService. |
| 10180 | // We should get this value from the system when it |
| 10181 | // is possible to do so. |
| 10182 | final int KEY_REPEAT_FIRST_DELAY = 750; |
| 10183 | startDelay = Math.max(KEY_REPEAT_FIRST_DELAY, startDelay); |
| 10184 | } |
| 10185 | |
| 10186 | // Tell mScrollCache when we should start fading. This may |
| 10187 | // extend the fade start time if one was already scheduled |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 10188 | long fadeStartTime = AnimationUtils.currentAnimationTimeMillis() + startDelay; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10189 | scrollCache.fadeStartTime = fadeStartTime; |
| 10190 | scrollCache.state = ScrollabilityCache.ON; |
| 10191 | |
| 10192 | // Schedule our fader to run, unscheduling any old ones first |
| 10193 | if (mAttachInfo != null) { |
| 10194 | mAttachInfo.mHandler.removeCallbacks(scrollCache); |
| 10195 | mAttachInfo.mHandler.postAtTime(scrollCache, fadeStartTime); |
| 10196 | } |
| 10197 | |
| 10198 | return true; |
| 10199 | } |
| 10200 | |
| 10201 | return false; |
| 10202 | } |
| 10203 | |
| 10204 | /** |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10205 | * Do not invalidate views which are not visible and which are not running an animation. They |
| 10206 | * will not get drawn and they should not set dirty flags as if they will be drawn |
| 10207 | */ |
| 10208 | private boolean skipInvalidate() { |
| 10209 | return (mViewFlags & VISIBILITY_MASK) != VISIBLE && mCurrentAnimation == null && |
| 10210 | (!(mParent instanceof ViewGroup) || |
| 10211 | !((ViewGroup) mParent).isViewTransitioning(this)); |
| 10212 | } |
| 10213 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 10214 | * 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] | 10215 | * visible, {@link #onDraw(android.graphics.Canvas)} will be called at some point |
| 10216 | * in the future. This must be called from a UI thread. To call from a non-UI |
| 10217 | * thread, call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10218 | * |
| 10219 | * WARNING: This method is destructive to dirty. |
| 10220 | * @param dirty the rectangle representing the bounds of the dirty region |
| 10221 | */ |
| 10222 | public void invalidate(Rect dirty) { |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10223 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 10224 | return; |
| 10225 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10226 | if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_HAS_BOUNDS)) == (PFLAG_DRAWN | PFLAG_HAS_BOUNDS) || |
| 10227 | (mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == PFLAG_DRAWING_CACHE_VALID || |
| 10228 | (mPrivateFlags & PFLAG_INVALIDATED) != PFLAG_INVALIDATED) { |
| 10229 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
| 10230 | mPrivateFlags |= PFLAG_INVALIDATED; |
| 10231 | mPrivateFlags |= PFLAG_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10232 | final ViewParent p = mParent; |
| 10233 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10234 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 10235 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 10236 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 10237 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 10238 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10239 | p.invalidateChild(this, null); |
| 10240 | return; |
| 10241 | } |
Romain Guy | af636eb | 2010-12-09 17:47:21 -0800 | [diff] [blame] | 10242 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10243 | if (p != null && ai != null) { |
| 10244 | final int scrollX = mScrollX; |
| 10245 | final int scrollY = mScrollY; |
| 10246 | final Rect r = ai.mTmpInvalRect; |
| 10247 | r.set(dirty.left - scrollX, dirty.top - scrollY, |
| 10248 | dirty.right - scrollX, dirty.bottom - scrollY); |
| 10249 | mParent.invalidateChild(this, r); |
| 10250 | } |
| 10251 | } |
| 10252 | } |
| 10253 | |
| 10254 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 10255 | * 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] | 10256 | * The coordinates of the dirty rect are relative to the view. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10257 | * If the view is visible, {@link #onDraw(android.graphics.Canvas)} |
| 10258 | * will be called at some point in the future. This must be called from |
| 10259 | * 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] | 10260 | * @param l the left position of the dirty region |
| 10261 | * @param t the top position of the dirty region |
| 10262 | * @param r the right position of the dirty region |
| 10263 | * @param b the bottom position of the dirty region |
| 10264 | */ |
| 10265 | public void invalidate(int l, int t, int r, int b) { |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10266 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 10267 | return; |
| 10268 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10269 | if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_HAS_BOUNDS)) == (PFLAG_DRAWN | PFLAG_HAS_BOUNDS) || |
| 10270 | (mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == PFLAG_DRAWING_CACHE_VALID || |
| 10271 | (mPrivateFlags & PFLAG_INVALIDATED) != PFLAG_INVALIDATED) { |
| 10272 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
| 10273 | mPrivateFlags |= PFLAG_INVALIDATED; |
| 10274 | mPrivateFlags |= PFLAG_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10275 | final ViewParent p = mParent; |
| 10276 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10277 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 10278 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 10279 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 10280 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 10281 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10282 | p.invalidateChild(this, null); |
| 10283 | return; |
| 10284 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 10285 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10286 | if (p != null && ai != null && l < r && t < b) { |
| 10287 | final int scrollX = mScrollX; |
| 10288 | final int scrollY = mScrollY; |
| 10289 | final Rect tmpr = ai.mTmpInvalRect; |
| 10290 | tmpr.set(l - scrollX, t - scrollY, r - scrollX, b - scrollY); |
| 10291 | p.invalidateChild(this, tmpr); |
| 10292 | } |
| 10293 | } |
| 10294 | } |
| 10295 | |
| 10296 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10297 | * Invalidate the whole view. If the view is visible, |
| 10298 | * {@link #onDraw(android.graphics.Canvas)} will be called at some point in |
| 10299 | * the future. This must be called from a UI thread. To call from a non-UI thread, |
| 10300 | * call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10301 | */ |
| 10302 | public void invalidate() { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10303 | invalidate(true); |
| 10304 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10305 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10306 | /** |
| 10307 | * This is where the invalidate() work actually happens. A full invalidate() |
| 10308 | * causes the drawing cache to be invalidated, but this function can be called with |
| 10309 | * invalidateCache set to false to skip that invalidation step for cases that do not |
| 10310 | * need it (for example, a component that remains at the same dimensions with the same |
| 10311 | * content). |
| 10312 | * |
| 10313 | * @param invalidateCache Whether the drawing cache for this view should be invalidated as |
| 10314 | * well. This is usually true for a full invalidate, but may be set to false if the |
| 10315 | * View's contents or dimensions have not changed. |
| 10316 | */ |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 10317 | void invalidate(boolean invalidateCache) { |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10318 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 10319 | return; |
| 10320 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10321 | if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_HAS_BOUNDS)) == (PFLAG_DRAWN | PFLAG_HAS_BOUNDS) || |
| 10322 | (invalidateCache && (mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == PFLAG_DRAWING_CACHE_VALID) || |
| 10323 | (mPrivateFlags & PFLAG_INVALIDATED) != PFLAG_INVALIDATED || isOpaque() != mLastIsOpaque) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10324 | mLastIsOpaque = isOpaque(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10325 | mPrivateFlags &= ~PFLAG_DRAWN; |
| 10326 | mPrivateFlags |= PFLAG_DIRTY; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10327 | if (invalidateCache) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10328 | mPrivateFlags |= PFLAG_INVALIDATED; |
| 10329 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10330 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10331 | final AttachInfo ai = mAttachInfo; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 10332 | final ViewParent p = mParent; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10333 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 10334 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 10335 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 10336 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 10337 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10338 | p.invalidateChild(this, null); |
| 10339 | return; |
| 10340 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 10341 | } |
Michael Jurka | ebefea4 | 2010-11-15 16:04:01 -0800 | [diff] [blame] | 10342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10343 | if (p != null && ai != null) { |
| 10344 | final Rect r = ai.mTmpInvalRect; |
| 10345 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 10346 | // Don't call invalidate -- we don't want to internally scroll |
| 10347 | // our own bounds |
| 10348 | p.invalidateChild(this, r); |
| 10349 | } |
| 10350 | } |
| 10351 | } |
| 10352 | |
| 10353 | /** |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10354 | * Quick invalidation for View property changes (alpha, translationXY, etc.). We don't want to |
| 10355 | * set any flags or handle all of the cases handled by the default invalidation methods. |
| 10356 | * Instead, we just want to schedule a traversal in ViewRootImpl with the appropriate |
| 10357 | * dirty rect. This method calls into fast invalidation methods in ViewGroup that |
| 10358 | * walk up the hierarchy, transforming the dirty rect as necessary. |
| 10359 | * |
| 10360 | * The method also handles normal invalidation logic if display list properties are not |
| 10361 | * being used in this view. The invalidateParent and forceRedraw flags are used by that |
| 10362 | * backup approach, to handle these cases used in the various property-setting methods. |
| 10363 | * |
| 10364 | * @param invalidateParent Force a call to invalidateParentCaches() if display list properties |
| 10365 | * are not being used in this view |
| 10366 | * @param forceRedraw Mark the view as DRAWN to force the invalidation to propagate, if display |
| 10367 | * list properties are not being used in this view |
| 10368 | */ |
| 10369 | void invalidateViewProperty(boolean invalidateParent, boolean forceRedraw) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10370 | if (mDisplayList == null || (mPrivateFlags & PFLAG_DRAW_ANIMATION) == PFLAG_DRAW_ANIMATION) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10371 | if (invalidateParent) { |
| 10372 | invalidateParentCaches(); |
| 10373 | } |
| 10374 | if (forceRedraw) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10375 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10376 | } |
| 10377 | invalidate(false); |
| 10378 | } else { |
| 10379 | final AttachInfo ai = mAttachInfo; |
| 10380 | final ViewParent p = mParent; |
| 10381 | if (p != null && ai != null) { |
| 10382 | final Rect r = ai.mTmpInvalRect; |
| 10383 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 10384 | if (mParent instanceof ViewGroup) { |
| 10385 | ((ViewGroup) mParent).invalidateChildFast(this, r); |
| 10386 | } else { |
| 10387 | mParent.invalidateChild(this, r); |
| 10388 | } |
| 10389 | } |
| 10390 | } |
| 10391 | } |
| 10392 | |
| 10393 | /** |
| 10394 | * Utility method to transform a given Rect by the current matrix of this view. |
| 10395 | */ |
| 10396 | void transformRect(final Rect rect) { |
| 10397 | if (!getMatrix().isIdentity()) { |
| 10398 | RectF boundingRect = mAttachInfo.mTmpTransformRect; |
| 10399 | boundingRect.set(rect); |
| 10400 | getMatrix().mapRect(boundingRect); |
| 10401 | rect.set((int) (boundingRect.left - 0.5f), |
| 10402 | (int) (boundingRect.top - 0.5f), |
| 10403 | (int) (boundingRect.right + 0.5f), |
| 10404 | (int) (boundingRect.bottom + 0.5f)); |
| 10405 | } |
| 10406 | } |
| 10407 | |
| 10408 | /** |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10409 | * 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] | 10410 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 10411 | * 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] | 10412 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method only |
| 10413 | * clears the parent caches and does not causes an invalidate event. |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10414 | * |
| 10415 | * @hide |
| 10416 | */ |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10417 | protected void invalidateParentCaches() { |
| 10418 | if (mParent instanceof View) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10419 | ((View) mParent).mPrivateFlags |= PFLAG_INVALIDATED; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10420 | } |
| 10421 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10422 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10423 | /** |
| 10424 | * Used to indicate that the parent of this view should be invalidated. This functionality |
| 10425 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 10426 | * which is necessary when various parent-managed properties of the view change, such as |
| 10427 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method will propagate |
| 10428 | * an invalidation event to the parent. |
| 10429 | * |
| 10430 | * @hide |
| 10431 | */ |
| 10432 | protected void invalidateParentIfNeeded() { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10433 | if (isHardwareAccelerated() && mParent instanceof View) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10434 | ((View) mParent).invalidate(true); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10435 | } |
| 10436 | } |
| 10437 | |
| 10438 | /** |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10439 | * Indicates whether this View is opaque. An opaque View guarantees that it will |
| 10440 | * draw all the pixels overlapping its bounds using a fully opaque color. |
| 10441 | * |
| 10442 | * Subclasses of View should override this method whenever possible to indicate |
| 10443 | * whether an instance is opaque. Opaque Views are treated in a special way by |
| 10444 | * the View hierarchy, possibly allowing it to perform optimizations during |
| 10445 | * invalidate/draw passes. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10446 | * |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10447 | * @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] | 10448 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 10449 | @ViewDebug.ExportedProperty(category = "drawing") |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10450 | public boolean isOpaque() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10451 | return (mPrivateFlags & PFLAG_OPAQUE_MASK) == PFLAG_OPAQUE_MASK && |
Romain Guy | f877308 | 2012-07-12 18:01:00 -0700 | [diff] [blame] | 10452 | ((mTransformationInfo != null ? mTransformationInfo.mAlpha : 1.0f) >= 1.0f); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10453 | } |
| 10454 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 10455 | /** |
| 10456 | * @hide |
| 10457 | */ |
| 10458 | protected void computeOpaqueFlags() { |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10459 | // Opaque if: |
| 10460 | // - Has a background |
| 10461 | // - Background is opaque |
| 10462 | // - Doesn't have scrollbars or scrollbars are inside overlay |
| 10463 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10464 | if (mBackground != null && mBackground.getOpacity() == PixelFormat.OPAQUE) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10465 | mPrivateFlags |= PFLAG_OPAQUE_BACKGROUND; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10466 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10467 | mPrivateFlags &= ~PFLAG_OPAQUE_BACKGROUND; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10468 | } |
| 10469 | |
| 10470 | final int flags = mViewFlags; |
| 10471 | if (((flags & SCROLLBARS_VERTICAL) == 0 && (flags & SCROLLBARS_HORIZONTAL) == 0) || |
| 10472 | (flags & SCROLLBARS_STYLE_MASK) == SCROLLBARS_INSIDE_OVERLAY) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10473 | mPrivateFlags |= PFLAG_OPAQUE_SCROLLBARS; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10474 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10475 | mPrivateFlags &= ~PFLAG_OPAQUE_SCROLLBARS; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10476 | } |
| 10477 | } |
| 10478 | |
| 10479 | /** |
| 10480 | * @hide |
| 10481 | */ |
| 10482 | protected boolean hasOpaqueScrollbars() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10483 | return (mPrivateFlags & PFLAG_OPAQUE_SCROLLBARS) == PFLAG_OPAQUE_SCROLLBARS; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10484 | } |
| 10485 | |
| 10486 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10487 | * @return A handler associated with the thread running the View. This |
| 10488 | * handler can be used to pump events in the UI events queue. |
| 10489 | */ |
| 10490 | public Handler getHandler() { |
| 10491 | if (mAttachInfo != null) { |
| 10492 | return mAttachInfo.mHandler; |
| 10493 | } |
| 10494 | return null; |
| 10495 | } |
| 10496 | |
| 10497 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10498 | * Gets the view root associated with the View. |
| 10499 | * @return The view root, or null if none. |
| 10500 | * @hide |
| 10501 | */ |
| 10502 | public ViewRootImpl getViewRootImpl() { |
| 10503 | if (mAttachInfo != null) { |
| 10504 | return mAttachInfo.mViewRootImpl; |
| 10505 | } |
| 10506 | return null; |
| 10507 | } |
| 10508 | |
| 10509 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10510 | * <p>Causes the Runnable to be added to the message queue. |
| 10511 | * The runnable will be run on the user interface thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10512 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10513 | * <p>This method can be invoked from outside of the UI thread |
| 10514 | * 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] | 10515 | * |
| 10516 | * @param action The Runnable that will be executed. |
| 10517 | * |
| 10518 | * @return Returns true if the Runnable was successfully placed in to the |
| 10519 | * message queue. Returns false on failure, usually because the |
| 10520 | * looper processing the message queue is exiting. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10521 | * |
| 10522 | * @see #postDelayed |
| 10523 | * @see #removeCallbacks |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10524 | */ |
| 10525 | public boolean post(Runnable action) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10526 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10527 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10528 | return attachInfo.mHandler.post(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10529 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10530 | // Assume that post will succeed later |
| 10531 | ViewRootImpl.getRunQueue().post(action); |
| 10532 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10533 | } |
| 10534 | |
| 10535 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10536 | * <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] | 10537 | * after the specified amount of time elapses. |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10538 | * The runnable will be run on the user interface thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10539 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10540 | * <p>This method can be invoked from outside of the UI thread |
| 10541 | * 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] | 10542 | * |
| 10543 | * @param action The Runnable that will be executed. |
| 10544 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 10545 | * will be executed. |
| 10546 | * |
| 10547 | * @return true if the Runnable was successfully placed in to the |
| 10548 | * message queue. Returns false on failure, usually because the |
| 10549 | * looper processing the message queue is exiting. Note that a |
| 10550 | * result of true does not mean the Runnable will be processed -- |
| 10551 | * if the looper is quit before the delivery time of the message |
| 10552 | * occurs then the message will be dropped. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10553 | * |
| 10554 | * @see #post |
| 10555 | * @see #removeCallbacks |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10556 | */ |
| 10557 | public boolean postDelayed(Runnable action, long delayMillis) { |
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.postDelayed(action, delayMillis); |
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().postDelayed(action, delayMillis); |
| 10564 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10565 | } |
| 10566 | |
| 10567 | /** |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10568 | * <p>Causes the Runnable to execute on the next animation time step. |
| 10569 | * The runnable will be run on the user interface thread.</p> |
| 10570 | * |
| 10571 | * <p>This method can be invoked from outside of the UI thread |
| 10572 | * only when this View is attached to a window.</p> |
| 10573 | * |
| 10574 | * @param action The Runnable that will be executed. |
| 10575 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10576 | * @see #postOnAnimationDelayed |
| 10577 | * @see #removeCallbacks |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10578 | */ |
| 10579 | public void postOnAnimation(Runnable action) { |
| 10580 | final AttachInfo attachInfo = mAttachInfo; |
| 10581 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 10582 | attachInfo.mViewRootImpl.mChoreographer.postCallback( |
| 10583 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10584 | } else { |
| 10585 | // Assume that post will succeed later |
| 10586 | ViewRootImpl.getRunQueue().post(action); |
| 10587 | } |
| 10588 | } |
| 10589 | |
| 10590 | /** |
| 10591 | * <p>Causes the Runnable to execute on the next animation time step, |
| 10592 | * after the specified amount of time elapses. |
| 10593 | * The runnable will be run on the user interface thread.</p> |
| 10594 | * |
| 10595 | * <p>This method can be invoked from outside of the UI thread |
| 10596 | * only when this View is attached to a window.</p> |
| 10597 | * |
| 10598 | * @param action The Runnable that will be executed. |
| 10599 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 10600 | * will be executed. |
| 10601 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10602 | * @see #postOnAnimation |
| 10603 | * @see #removeCallbacks |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10604 | */ |
| 10605 | public void postOnAnimationDelayed(Runnable action, long delayMillis) { |
| 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.postCallbackDelayed( |
| 10609 | Choreographer.CALLBACK_ANIMATION, action, null, delayMillis); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10610 | } else { |
| 10611 | // Assume that post will succeed later |
| 10612 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 10613 | } |
| 10614 | } |
| 10615 | |
| 10616 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10617 | * <p>Removes the specified Runnable from the message queue.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10618 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10619 | * <p>This method can be invoked from outside of the UI thread |
| 10620 | * 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] | 10621 | * |
| 10622 | * @param action The Runnable to remove from the message handling queue |
| 10623 | * |
| 10624 | * @return true if this view could ask the Handler to remove the Runnable, |
| 10625 | * false otherwise. When the returned value is true, the Runnable |
| 10626 | * may or may not have been actually removed from the message queue |
| 10627 | * (for instance, if the Runnable was not in the queue already.) |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10628 | * |
| 10629 | * @see #post |
| 10630 | * @see #postDelayed |
| 10631 | * @see #postOnAnimation |
| 10632 | * @see #postOnAnimationDelayed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10633 | */ |
| 10634 | public boolean removeCallbacks(Runnable action) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 10635 | if (action != null) { |
| 10636 | final AttachInfo attachInfo = mAttachInfo; |
| 10637 | if (attachInfo != null) { |
| 10638 | attachInfo.mHandler.removeCallbacks(action); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 10639 | attachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 10640 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 10641 | } else { |
| 10642 | // Assume that post will succeed later |
| 10643 | ViewRootImpl.getRunQueue().removeCallbacks(action); |
| 10644 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10645 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10646 | return true; |
| 10647 | } |
| 10648 | |
| 10649 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10650 | * <p>Cause an invalidate to happen on a subsequent cycle through the event loop. |
| 10651 | * 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] | 10652 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10653 | * <p>This method can be invoked from outside of the UI thread |
| 10654 | * only when this View is attached to a window.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10655 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10656 | * @see #invalidate() |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10657 | * @see #postInvalidateDelayed(long) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10658 | */ |
| 10659 | public void postInvalidate() { |
| 10660 | postInvalidateDelayed(0); |
| 10661 | } |
| 10662 | |
| 10663 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10664 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 10665 | * 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] | 10666 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10667 | * <p>This method can be invoked from outside of the UI thread |
| 10668 | * 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] | 10669 | * |
| 10670 | * @param left The left coordinate of the rectangle to invalidate. |
| 10671 | * @param top The top coordinate of the rectangle to invalidate. |
| 10672 | * @param right The right coordinate of the rectangle to invalidate. |
| 10673 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 10674 | * |
| 10675 | * @see #invalidate(int, int, int, int) |
| 10676 | * @see #invalidate(Rect) |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10677 | * @see #postInvalidateDelayed(long, int, int, int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10678 | */ |
| 10679 | public void postInvalidate(int left, int top, int right, int bottom) { |
| 10680 | postInvalidateDelayed(0, left, top, right, bottom); |
| 10681 | } |
| 10682 | |
| 10683 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10684 | * <p>Cause an invalidate to happen on a subsequent cycle through the event |
| 10685 | * loop. Waits for the specified amount of time.</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 delayMilliseconds the duration in milliseconds to delay the |
| 10691 | * invalidation by |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10692 | * |
| 10693 | * @see #invalidate() |
| 10694 | * @see #postInvalidate() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10695 | */ |
| 10696 | public void postInvalidateDelayed(long delayMilliseconds) { |
| 10697 | // We try only with the AttachInfo because there's no point in invalidating |
| 10698 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10699 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10700 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10701 | attachInfo.mViewRootImpl.dispatchInvalidateDelayed(this, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10702 | } |
| 10703 | } |
| 10704 | |
| 10705 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10706 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 10707 | * through the event loop. Waits for the specified amount of time.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10708 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10709 | * <p>This method can be invoked from outside of the UI thread |
| 10710 | * 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] | 10711 | * |
| 10712 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 10713 | * invalidation by |
| 10714 | * @param left The left coordinate of the rectangle to invalidate. |
| 10715 | * @param top The top coordinate of the rectangle to invalidate. |
| 10716 | * @param right The right coordinate of the rectangle to invalidate. |
| 10717 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10718 | * |
| 10719 | * @see #invalidate(int, int, int, int) |
| 10720 | * @see #invalidate(Rect) |
| 10721 | * @see #postInvalidate(int, int, int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10722 | */ |
| 10723 | public void postInvalidateDelayed(long delayMilliseconds, int left, int top, |
| 10724 | int right, int bottom) { |
| 10725 | |
| 10726 | // We try only with the AttachInfo because there's no point in invalidating |
| 10727 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10728 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10729 | if (attachInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10730 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 10731 | info.target = this; |
| 10732 | info.left = left; |
| 10733 | info.top = top; |
| 10734 | info.right = right; |
| 10735 | info.bottom = bottom; |
| 10736 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10737 | attachInfo.mViewRootImpl.dispatchInvalidateRectDelayed(info, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10738 | } |
| 10739 | } |
| 10740 | |
| 10741 | /** |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10742 | * <p>Cause an invalidate to happen on the next animation time step, typically the |
| 10743 | * next display frame.</p> |
| 10744 | * |
| 10745 | * <p>This method can be invoked from outside of the UI thread |
| 10746 | * only when this View is attached to a window.</p> |
| 10747 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10748 | * @see #invalidate() |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10749 | */ |
| 10750 | public void postInvalidateOnAnimation() { |
| 10751 | // We try only with the AttachInfo because there's no point in invalidating |
| 10752 | // if we are not attached to our window |
| 10753 | final AttachInfo attachInfo = mAttachInfo; |
| 10754 | if (attachInfo != null) { |
| 10755 | attachInfo.mViewRootImpl.dispatchInvalidateOnAnimation(this); |
| 10756 | } |
| 10757 | } |
| 10758 | |
| 10759 | /** |
| 10760 | * <p>Cause an invalidate of the specified area to happen on the next animation |
| 10761 | * time step, typically the next display frame.</p> |
| 10762 | * |
| 10763 | * <p>This method can be invoked from outside of the UI thread |
| 10764 | * only when this View is attached to a window.</p> |
| 10765 | * |
| 10766 | * @param left The left coordinate of the rectangle to invalidate. |
| 10767 | * @param top The top coordinate of the rectangle to invalidate. |
| 10768 | * @param right The right coordinate of the rectangle to invalidate. |
| 10769 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 10770 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10771 | * @see #invalidate(int, int, int, int) |
| 10772 | * @see #invalidate(Rect) |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10773 | */ |
| 10774 | public void postInvalidateOnAnimation(int left, int top, int right, int bottom) { |
| 10775 | // We try only with the AttachInfo because there's no point in invalidating |
| 10776 | // if we are not attached to our window |
| 10777 | final AttachInfo attachInfo = mAttachInfo; |
| 10778 | if (attachInfo != null) { |
| 10779 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 10780 | info.target = this; |
| 10781 | info.left = left; |
| 10782 | info.top = top; |
| 10783 | info.right = right; |
| 10784 | info.bottom = bottom; |
| 10785 | |
| 10786 | attachInfo.mViewRootImpl.dispatchInvalidateRectOnAnimation(info); |
| 10787 | } |
| 10788 | } |
| 10789 | |
| 10790 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 10791 | * Post a callback to send a {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} event. |
| 10792 | * This event is sent at most once every |
| 10793 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
| 10794 | */ |
| 10795 | private void postSendViewScrolledAccessibilityEventCallback() { |
| 10796 | if (mSendViewScrolledAccessibilityEvent == null) { |
| 10797 | mSendViewScrolledAccessibilityEvent = new SendViewScrolledAccessibilityEvent(); |
| 10798 | } |
| 10799 | if (!mSendViewScrolledAccessibilityEvent.mIsPending) { |
| 10800 | mSendViewScrolledAccessibilityEvent.mIsPending = true; |
| 10801 | postDelayed(mSendViewScrolledAccessibilityEvent, |
| 10802 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval()); |
| 10803 | } |
| 10804 | } |
| 10805 | |
| 10806 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10807 | * Called by a parent to request that a child update its values for mScrollX |
| 10808 | * and mScrollY if necessary. This will typically be done if the child is |
| 10809 | * animating a scroll using a {@link android.widget.Scroller Scroller} |
| 10810 | * object. |
| 10811 | */ |
| 10812 | public void computeScroll() { |
| 10813 | } |
| 10814 | |
| 10815 | /** |
| 10816 | * <p>Indicate whether the horizontal edges are faded when the view is |
| 10817 | * scrolled horizontally.</p> |
| 10818 | * |
| 10819 | * @return true if the horizontal edges should are faded on scroll, false |
| 10820 | * otherwise |
| 10821 | * |
| 10822 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10823 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10824 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10825 | */ |
| 10826 | public boolean isHorizontalFadingEdgeEnabled() { |
| 10827 | return (mViewFlags & FADING_EDGE_HORIZONTAL) == FADING_EDGE_HORIZONTAL; |
| 10828 | } |
| 10829 | |
| 10830 | /** |
| 10831 | * <p>Define whether the horizontal edges should be faded when this view |
| 10832 | * is scrolled horizontally.</p> |
| 10833 | * |
| 10834 | * @param horizontalFadingEdgeEnabled true if the horizontal edges should |
| 10835 | * be faded when the view is scrolled |
| 10836 | * horizontally |
| 10837 | * |
| 10838 | * @see #isHorizontalFadingEdgeEnabled() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10839 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10840 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10841 | */ |
| 10842 | public void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled) { |
| 10843 | if (isHorizontalFadingEdgeEnabled() != horizontalFadingEdgeEnabled) { |
| 10844 | if (horizontalFadingEdgeEnabled) { |
| 10845 | initScrollCache(); |
| 10846 | } |
| 10847 | |
| 10848 | mViewFlags ^= FADING_EDGE_HORIZONTAL; |
| 10849 | } |
| 10850 | } |
| 10851 | |
| 10852 | /** |
| 10853 | * <p>Indicate whether the vertical edges are faded when the view is |
| 10854 | * scrolled horizontally.</p> |
| 10855 | * |
| 10856 | * @return true if the vertical edges should are faded on scroll, false |
| 10857 | * otherwise |
| 10858 | * |
| 10859 | * @see #setVerticalFadingEdgeEnabled(boolean) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10860 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10861 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10862 | */ |
| 10863 | public boolean isVerticalFadingEdgeEnabled() { |
| 10864 | return (mViewFlags & FADING_EDGE_VERTICAL) == FADING_EDGE_VERTICAL; |
| 10865 | } |
| 10866 | |
| 10867 | /** |
| 10868 | * <p>Define whether the vertical edges should be faded when this view |
| 10869 | * is scrolled vertically.</p> |
| 10870 | * |
| 10871 | * @param verticalFadingEdgeEnabled true if the vertical edges should |
| 10872 | * be faded when the view is scrolled |
| 10873 | * vertically |
| 10874 | * |
| 10875 | * @see #isVerticalFadingEdgeEnabled() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10876 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10877 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10878 | */ |
| 10879 | public void setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled) { |
| 10880 | if (isVerticalFadingEdgeEnabled() != verticalFadingEdgeEnabled) { |
| 10881 | if (verticalFadingEdgeEnabled) { |
| 10882 | initScrollCache(); |
| 10883 | } |
| 10884 | |
| 10885 | mViewFlags ^= FADING_EDGE_VERTICAL; |
| 10886 | } |
| 10887 | } |
| 10888 | |
| 10889 | /** |
| 10890 | * Returns the strength, or intensity, of the top faded edge. The strength is |
| 10891 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10892 | * returns 0.0 or 1.0 but no value in between. |
| 10893 | * |
| 10894 | * Subclasses should override this method to provide a smoother fade transition |
| 10895 | * when scrolling occurs. |
| 10896 | * |
| 10897 | * @return the intensity of the top fade as a float between 0.0f and 1.0f |
| 10898 | */ |
| 10899 | protected float getTopFadingEdgeStrength() { |
| 10900 | return computeVerticalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 10901 | } |
| 10902 | |
| 10903 | /** |
| 10904 | * Returns the strength, or intensity, of the bottom faded edge. The strength is |
| 10905 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10906 | * returns 0.0 or 1.0 but no value in between. |
| 10907 | * |
| 10908 | * Subclasses should override this method to provide a smoother fade transition |
| 10909 | * when scrolling occurs. |
| 10910 | * |
| 10911 | * @return the intensity of the bottom fade as a float between 0.0f and 1.0f |
| 10912 | */ |
| 10913 | protected float getBottomFadingEdgeStrength() { |
| 10914 | return computeVerticalScrollOffset() + computeVerticalScrollExtent() < |
| 10915 | computeVerticalScrollRange() ? 1.0f : 0.0f; |
| 10916 | } |
| 10917 | |
| 10918 | /** |
| 10919 | * Returns the strength, or intensity, of the left faded edge. The strength is |
| 10920 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10921 | * returns 0.0 or 1.0 but no value in between. |
| 10922 | * |
| 10923 | * Subclasses should override this method to provide a smoother fade transition |
| 10924 | * when scrolling occurs. |
| 10925 | * |
| 10926 | * @return the intensity of the left fade as a float between 0.0f and 1.0f |
| 10927 | */ |
| 10928 | protected float getLeftFadingEdgeStrength() { |
| 10929 | return computeHorizontalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 10930 | } |
| 10931 | |
| 10932 | /** |
| 10933 | * Returns the strength, or intensity, of the right faded edge. The strength is |
| 10934 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10935 | * returns 0.0 or 1.0 but no value in between. |
| 10936 | * |
| 10937 | * Subclasses should override this method to provide a smoother fade transition |
| 10938 | * when scrolling occurs. |
| 10939 | * |
| 10940 | * @return the intensity of the right fade as a float between 0.0f and 1.0f |
| 10941 | */ |
| 10942 | protected float getRightFadingEdgeStrength() { |
| 10943 | return computeHorizontalScrollOffset() + computeHorizontalScrollExtent() < |
| 10944 | computeHorizontalScrollRange() ? 1.0f : 0.0f; |
| 10945 | } |
| 10946 | |
| 10947 | /** |
| 10948 | * <p>Indicate whether the horizontal scrollbar should be drawn or not. The |
| 10949 | * scrollbar is not drawn by default.</p> |
| 10950 | * |
| 10951 | * @return true if the horizontal scrollbar should be painted, false |
| 10952 | * otherwise |
| 10953 | * |
| 10954 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 10955 | */ |
| 10956 | public boolean isHorizontalScrollBarEnabled() { |
| 10957 | return (mViewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 10958 | } |
| 10959 | |
| 10960 | /** |
| 10961 | * <p>Define whether the horizontal scrollbar should be drawn or not. The |
| 10962 | * scrollbar is not drawn by default.</p> |
| 10963 | * |
| 10964 | * @param horizontalScrollBarEnabled true if the horizontal scrollbar should |
| 10965 | * be painted |
| 10966 | * |
| 10967 | * @see #isHorizontalScrollBarEnabled() |
| 10968 | */ |
| 10969 | public void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled) { |
| 10970 | if (isHorizontalScrollBarEnabled() != horizontalScrollBarEnabled) { |
| 10971 | mViewFlags ^= SCROLLBARS_HORIZONTAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10972 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10973 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10974 | } |
| 10975 | } |
| 10976 | |
| 10977 | /** |
| 10978 | * <p>Indicate whether the vertical scrollbar should be drawn or not. The |
| 10979 | * scrollbar is not drawn by default.</p> |
| 10980 | * |
| 10981 | * @return true if the vertical scrollbar should be painted, false |
| 10982 | * otherwise |
| 10983 | * |
| 10984 | * @see #setVerticalScrollBarEnabled(boolean) |
| 10985 | */ |
| 10986 | public boolean isVerticalScrollBarEnabled() { |
| 10987 | return (mViewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL; |
| 10988 | } |
| 10989 | |
| 10990 | /** |
| 10991 | * <p>Define whether the vertical scrollbar should be drawn or not. The |
| 10992 | * scrollbar is not drawn by default.</p> |
| 10993 | * |
| 10994 | * @param verticalScrollBarEnabled true if the vertical scrollbar should |
| 10995 | * be painted |
| 10996 | * |
| 10997 | * @see #isVerticalScrollBarEnabled() |
| 10998 | */ |
| 10999 | public void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled) { |
| 11000 | if (isVerticalScrollBarEnabled() != verticalScrollBarEnabled) { |
| 11001 | mViewFlags ^= SCROLLBARS_VERTICAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 11002 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11003 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11004 | } |
| 11005 | } |
| 11006 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11007 | /** |
| 11008 | * @hide |
| 11009 | */ |
| 11010 | protected void recomputePadding() { |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 11011 | internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11012 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11013 | |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 11014 | /** |
| 11015 | * Define whether scrollbars will fade when the view is not scrolling. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11016 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 11017 | * @param fadeScrollbars wheter to enable fading |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11018 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11019 | * @attr ref android.R.styleable#View_fadeScrollbars |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 11020 | */ |
| 11021 | public void setScrollbarFadingEnabled(boolean fadeScrollbars) { |
| 11022 | initScrollCache(); |
| 11023 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
| 11024 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11025 | if (fadeScrollbars) { |
| 11026 | scrollabilityCache.state = ScrollabilityCache.OFF; |
| 11027 | } else { |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 11028 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 11029 | } |
| 11030 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11031 | |
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 | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11034 | * Returns true if scrollbars will fade when this view is not scrolling |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11035 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11036 | * @return true if scrollbar fading is enabled |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11037 | * |
| 11038 | * @attr ref android.R.styleable#View_fadeScrollbars |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11039 | */ |
| 11040 | public boolean isScrollbarFadingEnabled() { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11041 | return mScrollCache != null && mScrollCache.fadeScrollBars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11042 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11043 | |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11044 | /** |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11045 | * |
| 11046 | * Returns the delay before scrollbars fade. |
| 11047 | * |
| 11048 | * @return the delay before scrollbars fade |
| 11049 | * |
| 11050 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 11051 | */ |
| 11052 | public int getScrollBarDefaultDelayBeforeFade() { |
| 11053 | return mScrollCache == null ? ViewConfiguration.getScrollDefaultDelay() : |
| 11054 | mScrollCache.scrollBarDefaultDelayBeforeFade; |
| 11055 | } |
| 11056 | |
| 11057 | /** |
| 11058 | * Define the delay before scrollbars fade. |
| 11059 | * |
| 11060 | * @param scrollBarDefaultDelayBeforeFade - the delay before scrollbars fade |
| 11061 | * |
| 11062 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 11063 | */ |
| 11064 | public void setScrollBarDefaultDelayBeforeFade(int scrollBarDefaultDelayBeforeFade) { |
| 11065 | getScrollCache().scrollBarDefaultDelayBeforeFade = scrollBarDefaultDelayBeforeFade; |
| 11066 | } |
| 11067 | |
| 11068 | /** |
| 11069 | * |
| 11070 | * Returns the scrollbar fade duration. |
| 11071 | * |
| 11072 | * @return the scrollbar fade duration |
| 11073 | * |
| 11074 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
| 11075 | */ |
| 11076 | public int getScrollBarFadeDuration() { |
| 11077 | return mScrollCache == null ? ViewConfiguration.getScrollBarFadeDuration() : |
| 11078 | mScrollCache.scrollBarFadeDuration; |
| 11079 | } |
| 11080 | |
| 11081 | /** |
| 11082 | * Define the scrollbar fade duration. |
| 11083 | * |
| 11084 | * @param scrollBarFadeDuration - the scrollbar fade duration |
| 11085 | * |
| 11086 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
| 11087 | */ |
| 11088 | public void setScrollBarFadeDuration(int scrollBarFadeDuration) { |
| 11089 | getScrollCache().scrollBarFadeDuration = scrollBarFadeDuration; |
| 11090 | } |
| 11091 | |
| 11092 | /** |
| 11093 | * |
| 11094 | * Returns the scrollbar size. |
| 11095 | * |
| 11096 | * @return the scrollbar size |
| 11097 | * |
| 11098 | * @attr ref android.R.styleable#View_scrollbarSize |
| 11099 | */ |
| 11100 | public int getScrollBarSize() { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 11101 | return mScrollCache == null ? ViewConfiguration.get(mContext).getScaledScrollBarSize() : |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11102 | mScrollCache.scrollBarSize; |
| 11103 | } |
| 11104 | |
| 11105 | /** |
| 11106 | * Define the scrollbar size. |
| 11107 | * |
| 11108 | * @param scrollBarSize - the scrollbar size |
| 11109 | * |
| 11110 | * @attr ref android.R.styleable#View_scrollbarSize |
| 11111 | */ |
| 11112 | public void setScrollBarSize(int scrollBarSize) { |
| 11113 | getScrollCache().scrollBarSize = scrollBarSize; |
| 11114 | } |
| 11115 | |
| 11116 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11117 | * <p>Specify the style of the scrollbars. The scrollbars can be overlaid or |
| 11118 | * inset. When inset, they add to the padding of the view. And the scrollbars |
| 11119 | * can be drawn inside the padding area or on the edge of the view. For example, |
| 11120 | * if a view has a background drawable and you want to draw the scrollbars |
| 11121 | * inside the padding specified by the drawable, you can use |
| 11122 | * SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to |
| 11123 | * appear at the edge of the view, ignoring the padding, then you can use |
| 11124 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.</p> |
| 11125 | * @param style the style of the scrollbars. Should be one of |
| 11126 | * SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, |
| 11127 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. |
| 11128 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 11129 | * @see #SCROLLBARS_INSIDE_INSET |
| 11130 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 11131 | * @see #SCROLLBARS_OUTSIDE_INSET |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11132 | * |
| 11133 | * @attr ref android.R.styleable#View_scrollbarStyle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11134 | */ |
| 11135 | public void setScrollBarStyle(int style) { |
| 11136 | if (style != (mViewFlags & SCROLLBARS_STYLE_MASK)) { |
| 11137 | mViewFlags = (mViewFlags & ~SCROLLBARS_STYLE_MASK) | (style & SCROLLBARS_STYLE_MASK); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 11138 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11139 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11140 | } |
| 11141 | } |
| 11142 | |
| 11143 | /** |
| 11144 | * <p>Returns the current scrollbar style.</p> |
| 11145 | * @return the current scrollbar style |
| 11146 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 11147 | * @see #SCROLLBARS_INSIDE_INSET |
| 11148 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 11149 | * @see #SCROLLBARS_OUTSIDE_INSET |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11150 | * |
| 11151 | * @attr ref android.R.styleable#View_scrollbarStyle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11152 | */ |
Jeff Sharkey | 010d7e5 | 2011-08-08 21:05:02 -0700 | [diff] [blame] | 11153 | @ViewDebug.ExportedProperty(mapping = { |
| 11154 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_OVERLAY, to = "INSIDE_OVERLAY"), |
| 11155 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_INSET, to = "INSIDE_INSET"), |
| 11156 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_OVERLAY, to = "OUTSIDE_OVERLAY"), |
| 11157 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_INSET, to = "OUTSIDE_INSET") |
| 11158 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11159 | public int getScrollBarStyle() { |
| 11160 | return mViewFlags & SCROLLBARS_STYLE_MASK; |
| 11161 | } |
| 11162 | |
| 11163 | /** |
| 11164 | * <p>Compute the horizontal range that the horizontal scrollbar |
| 11165 | * represents.</p> |
| 11166 | * |
| 11167 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11168 | * units used by {@link #computeHorizontalScrollExtent()} and |
| 11169 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 11170 | * |
| 11171 | * <p>The default range is the drawing width of this view.</p> |
| 11172 | * |
| 11173 | * @return the total horizontal range represented by the horizontal |
| 11174 | * scrollbar |
| 11175 | * |
| 11176 | * @see #computeHorizontalScrollExtent() |
| 11177 | * @see #computeHorizontalScrollOffset() |
| 11178 | * @see android.widget.ScrollBarDrawable |
| 11179 | */ |
| 11180 | protected int computeHorizontalScrollRange() { |
| 11181 | return getWidth(); |
| 11182 | } |
| 11183 | |
| 11184 | /** |
| 11185 | * <p>Compute the horizontal offset of the horizontal scrollbar's thumb |
| 11186 | * within the horizontal range. This value is used to compute the position |
| 11187 | * of the thumb within the scrollbar's track.</p> |
| 11188 | * |
| 11189 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11190 | * units used by {@link #computeHorizontalScrollRange()} and |
| 11191 | * {@link #computeHorizontalScrollExtent()}.</p> |
| 11192 | * |
| 11193 | * <p>The default offset is the scroll offset of this view.</p> |
| 11194 | * |
| 11195 | * @return the horizontal offset of the scrollbar's thumb |
| 11196 | * |
| 11197 | * @see #computeHorizontalScrollRange() |
| 11198 | * @see #computeHorizontalScrollExtent() |
| 11199 | * @see android.widget.ScrollBarDrawable |
| 11200 | */ |
| 11201 | protected int computeHorizontalScrollOffset() { |
| 11202 | return mScrollX; |
| 11203 | } |
| 11204 | |
| 11205 | /** |
| 11206 | * <p>Compute the horizontal extent of the horizontal scrollbar's thumb |
| 11207 | * within the horizontal range. This value is used to compute the length |
| 11208 | * of the thumb within the scrollbar's track.</p> |
| 11209 | * |
| 11210 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11211 | * units used by {@link #computeHorizontalScrollRange()} and |
| 11212 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 11213 | * |
| 11214 | * <p>The default extent is the drawing width of this view.</p> |
| 11215 | * |
| 11216 | * @return the horizontal extent of the scrollbar's thumb |
| 11217 | * |
| 11218 | * @see #computeHorizontalScrollRange() |
| 11219 | * @see #computeHorizontalScrollOffset() |
| 11220 | * @see android.widget.ScrollBarDrawable |
| 11221 | */ |
| 11222 | protected int computeHorizontalScrollExtent() { |
| 11223 | return getWidth(); |
| 11224 | } |
| 11225 | |
| 11226 | /** |
| 11227 | * <p>Compute the vertical range that the vertical scrollbar represents.</p> |
| 11228 | * |
| 11229 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11230 | * units used by {@link #computeVerticalScrollExtent()} and |
| 11231 | * {@link #computeVerticalScrollOffset()}.</p> |
| 11232 | * |
| 11233 | * @return the total vertical range represented by the vertical scrollbar |
| 11234 | * |
| 11235 | * <p>The default range is the drawing height of this view.</p> |
| 11236 | * |
| 11237 | * @see #computeVerticalScrollExtent() |
| 11238 | * @see #computeVerticalScrollOffset() |
| 11239 | * @see android.widget.ScrollBarDrawable |
| 11240 | */ |
| 11241 | protected int computeVerticalScrollRange() { |
| 11242 | return getHeight(); |
| 11243 | } |
| 11244 | |
| 11245 | /** |
| 11246 | * <p>Compute the vertical offset of the vertical scrollbar's thumb |
| 11247 | * within the horizontal range. This value is used to compute the position |
| 11248 | * of the thumb within the scrollbar's track.</p> |
| 11249 | * |
| 11250 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11251 | * units used by {@link #computeVerticalScrollRange()} and |
| 11252 | * {@link #computeVerticalScrollExtent()}.</p> |
| 11253 | * |
| 11254 | * <p>The default offset is the scroll offset of this view.</p> |
| 11255 | * |
| 11256 | * @return the vertical offset of the scrollbar's thumb |
| 11257 | * |
| 11258 | * @see #computeVerticalScrollRange() |
| 11259 | * @see #computeVerticalScrollExtent() |
| 11260 | * @see android.widget.ScrollBarDrawable |
| 11261 | */ |
| 11262 | protected int computeVerticalScrollOffset() { |
| 11263 | return mScrollY; |
| 11264 | } |
| 11265 | |
| 11266 | /** |
| 11267 | * <p>Compute the vertical extent of the horizontal scrollbar's thumb |
| 11268 | * within the vertical range. This value is used to compute the length |
| 11269 | * of the thumb within the scrollbar's track.</p> |
| 11270 | * |
| 11271 | * <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] | 11272 | * units used by {@link #computeVerticalScrollRange()} and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11273 | * {@link #computeVerticalScrollOffset()}.</p> |
| 11274 | * |
| 11275 | * <p>The default extent is the drawing height of this view.</p> |
| 11276 | * |
| 11277 | * @return the vertical extent of the scrollbar's thumb |
| 11278 | * |
| 11279 | * @see #computeVerticalScrollRange() |
| 11280 | * @see #computeVerticalScrollOffset() |
| 11281 | * @see android.widget.ScrollBarDrawable |
| 11282 | */ |
| 11283 | protected int computeVerticalScrollExtent() { |
| 11284 | return getHeight(); |
| 11285 | } |
| 11286 | |
| 11287 | /** |
Adam Powell | 6915944 | 2011-06-13 17:53:06 -0700 | [diff] [blame] | 11288 | * Check if this view can be scrolled horizontally in a certain direction. |
| 11289 | * |
| 11290 | * @param direction Negative to check scrolling left, positive to check scrolling right. |
| 11291 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 11292 | */ |
| 11293 | public boolean canScrollHorizontally(int direction) { |
| 11294 | final int offset = computeHorizontalScrollOffset(); |
| 11295 | final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent(); |
| 11296 | if (range == 0) return false; |
| 11297 | if (direction < 0) { |
| 11298 | return offset > 0; |
| 11299 | } else { |
| 11300 | return offset < range - 1; |
| 11301 | } |
| 11302 | } |
| 11303 | |
| 11304 | /** |
| 11305 | * Check if this view can be scrolled vertically in a certain direction. |
| 11306 | * |
| 11307 | * @param direction Negative to check scrolling up, positive to check scrolling down. |
| 11308 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 11309 | */ |
| 11310 | public boolean canScrollVertically(int direction) { |
| 11311 | final int offset = computeVerticalScrollOffset(); |
| 11312 | final int range = computeVerticalScrollRange() - computeVerticalScrollExtent(); |
| 11313 | if (range == 0) return false; |
| 11314 | if (direction < 0) { |
| 11315 | return offset > 0; |
| 11316 | } else { |
| 11317 | return offset < range - 1; |
| 11318 | } |
| 11319 | } |
| 11320 | |
| 11321 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11322 | * <p>Request the drawing of the horizontal and the vertical scrollbar. The |
| 11323 | * scrollbars are painted only if they have been awakened first.</p> |
| 11324 | * |
| 11325 | * @param canvas the canvas on which to draw the scrollbars |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11326 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11327 | * @see #awakenScrollBars(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11328 | */ |
Romain Guy | 1d5b3a6 | 2009-11-05 18:44:12 -0800 | [diff] [blame] | 11329 | protected final void onDrawScrollBars(Canvas canvas) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11330 | // scrollbars are drawn only when the animation is running |
| 11331 | final ScrollabilityCache cache = mScrollCache; |
| 11332 | if (cache != null) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11333 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11334 | int state = cache.state; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11335 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11336 | if (state == ScrollabilityCache.OFF) { |
| 11337 | return; |
| 11338 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11339 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11340 | boolean invalidate = false; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11341 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11342 | if (state == ScrollabilityCache.FADING) { |
| 11343 | // We're fading -- get our fade interpolation |
| 11344 | if (cache.interpolatorValues == null) { |
| 11345 | cache.interpolatorValues = new float[1]; |
| 11346 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11347 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11348 | float[] values = cache.interpolatorValues; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11349 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11350 | // Stops the animation if we're done |
| 11351 | if (cache.scrollBarInterpolator.timeToValues(values) == |
| 11352 | Interpolator.Result.FREEZE_END) { |
| 11353 | cache.state = ScrollabilityCache.OFF; |
| 11354 | } else { |
| 11355 | cache.scrollBar.setAlpha(Math.round(values[0])); |
| 11356 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11357 | |
| 11358 | // This will make the scroll bars inval themselves after |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11359 | // drawing. We only want this when we're fading so that |
| 11360 | // we prevent excessive redraws |
| 11361 | invalidate = true; |
| 11362 | } else { |
| 11363 | // We're just on -- but we may have been fading before so |
| 11364 | // reset alpha |
| 11365 | cache.scrollBar.setAlpha(255); |
| 11366 | } |
| 11367 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11369 | final int viewFlags = mViewFlags; |
| 11370 | |
| 11371 | final boolean drawHorizontalScrollBar = |
| 11372 | (viewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 11373 | final boolean drawVerticalScrollBar = |
| 11374 | (viewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL |
| 11375 | && !isVerticalScrollBarHidden(); |
| 11376 | |
| 11377 | if (drawVerticalScrollBar || drawHorizontalScrollBar) { |
| 11378 | final int width = mRight - mLeft; |
| 11379 | final int height = mBottom - mTop; |
| 11380 | |
| 11381 | final ScrollBarDrawable scrollBar = cache.scrollBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11382 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11383 | final int scrollX = mScrollX; |
| 11384 | final int scrollY = mScrollY; |
| 11385 | final int inside = (viewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0; |
| 11386 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11387 | int left, top, right, bottom; |
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 | if (drawHorizontalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 11390 | int size = scrollBar.getSize(false); |
| 11391 | if (size <= 0) { |
| 11392 | size = cache.scrollBarSize; |
| 11393 | } |
| 11394 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11395 | scrollBar.setParameters(computeHorizontalScrollRange(), |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11396 | computeHorizontalScrollOffset(), |
| 11397 | computeHorizontalScrollExtent(), false); |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11398 | final int verticalScrollBarGap = drawVerticalScrollBar ? |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11399 | getVerticalScrollbarWidth() : 0; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11400 | top = scrollY + height - size - (mUserPaddingBottom & inside); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11401 | left = scrollX + (mPaddingLeft & inside); |
| 11402 | right = scrollX + width - (mUserPaddingRight & inside) - verticalScrollBarGap; |
| 11403 | bottom = top + size; |
| 11404 | onDrawHorizontalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 11405 | if (invalidate) { |
| 11406 | invalidate(left, top, right, bottom); |
| 11407 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11408 | } |
| 11409 | |
| 11410 | if (drawVerticalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 11411 | int size = scrollBar.getSize(true); |
| 11412 | if (size <= 0) { |
| 11413 | size = cache.scrollBarSize; |
| 11414 | } |
| 11415 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11416 | scrollBar.setParameters(computeVerticalScrollRange(), |
| 11417 | computeVerticalScrollOffset(), |
| 11418 | computeVerticalScrollExtent(), true); |
Fabrice Di Meglio | c91b6ca | 2012-06-22 14:51:15 -0700 | [diff] [blame] | 11419 | int verticalScrollbarPosition = mVerticalScrollbarPosition; |
| 11420 | if (verticalScrollbarPosition == SCROLLBAR_POSITION_DEFAULT) { |
| 11421 | verticalScrollbarPosition = isLayoutRtl() ? |
| 11422 | SCROLLBAR_POSITION_LEFT : SCROLLBAR_POSITION_RIGHT; |
| 11423 | } |
| 11424 | switch (verticalScrollbarPosition) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11425 | default: |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11426 | case SCROLLBAR_POSITION_RIGHT: |
| 11427 | left = scrollX + width - size - (mUserPaddingRight & inside); |
| 11428 | break; |
| 11429 | case SCROLLBAR_POSITION_LEFT: |
| 11430 | left = scrollX + (mUserPaddingLeft & inside); |
| 11431 | break; |
| 11432 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11433 | top = scrollY + (mPaddingTop & inside); |
| 11434 | right = left + size; |
| 11435 | bottom = scrollY + height - (mUserPaddingBottom & inside); |
| 11436 | onDrawVerticalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 11437 | if (invalidate) { |
| 11438 | invalidate(left, top, right, bottom); |
| 11439 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11440 | } |
| 11441 | } |
| 11442 | } |
| 11443 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11445 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11446 | * 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] | 11447 | * FastScroller is visible. |
| 11448 | * @return whether to temporarily hide the vertical scrollbar |
| 11449 | * @hide |
| 11450 | */ |
| 11451 | protected boolean isVerticalScrollBarHidden() { |
| 11452 | return false; |
| 11453 | } |
| 11454 | |
| 11455 | /** |
| 11456 | * <p>Draw the horizontal scrollbar if |
| 11457 | * {@link #isHorizontalScrollBarEnabled()} returns true.</p> |
| 11458 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11459 | * @param canvas the canvas on which to draw the scrollbar |
| 11460 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11461 | * |
| 11462 | * @see #isHorizontalScrollBarEnabled() |
| 11463 | * @see #computeHorizontalScrollRange() |
| 11464 | * @see #computeHorizontalScrollExtent() |
| 11465 | * @see #computeHorizontalScrollOffset() |
| 11466 | * @see android.widget.ScrollBarDrawable |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11467 | * @hide |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11468 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 11469 | protected void onDrawHorizontalScrollBar(Canvas canvas, Drawable scrollBar, |
| 11470 | int l, int t, int r, int b) { |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11471 | scrollBar.setBounds(l, t, r, b); |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11472 | scrollBar.draw(canvas); |
| 11473 | } |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11474 | |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11475 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11476 | * <p>Draw the vertical scrollbar if {@link #isVerticalScrollBarEnabled()} |
| 11477 | * 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 #isVerticalScrollBarEnabled() |
| 11483 | * @see #computeVerticalScrollRange() |
| 11484 | * @see #computeVerticalScrollExtent() |
| 11485 | * @see #computeVerticalScrollOffset() |
| 11486 | * @see android.widget.ScrollBarDrawable |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11487 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11488 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 11489 | protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, |
| 11490 | int l, int t, int r, int b) { |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11491 | scrollBar.setBounds(l, t, r, b); |
| 11492 | scrollBar.draw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11493 | } |
| 11494 | |
| 11495 | /** |
| 11496 | * Implement this to do your drawing. |
| 11497 | * |
| 11498 | * @param canvas the canvas on which the background will be drawn |
| 11499 | */ |
| 11500 | protected void onDraw(Canvas canvas) { |
| 11501 | } |
| 11502 | |
| 11503 | /* |
| 11504 | * Caller is responsible for calling requestLayout if necessary. |
| 11505 | * (This allows addViewInLayout to not request a new layout.) |
| 11506 | */ |
| 11507 | void assignParent(ViewParent parent) { |
| 11508 | if (mParent == null) { |
| 11509 | mParent = parent; |
| 11510 | } else if (parent == null) { |
| 11511 | mParent = null; |
| 11512 | } else { |
| 11513 | throw new RuntimeException("view " + this + " being added, but" |
| 11514 | + " it already has a parent"); |
| 11515 | } |
| 11516 | } |
| 11517 | |
| 11518 | /** |
| 11519 | * This is called when the view is attached to a window. At this point it |
| 11520 | * has a Surface and will start drawing. Note that this function is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11521 | * guaranteed to be called before {@link #onDraw(android.graphics.Canvas)}, |
| 11522 | * however it may be called any time before the first onDraw -- including |
| 11523 | * before or after {@link #onMeasure(int, int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11524 | * |
| 11525 | * @see #onDetachedFromWindow() |
| 11526 | */ |
| 11527 | protected void onAttachedToWindow() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11528 | if ((mPrivateFlags & PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11529 | mParent.requestTransparentRegion(this); |
| 11530 | } |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11531 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11532 | if ((mPrivateFlags & PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH) != 0) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 11533 | initialAwakenScrollBars(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11534 | mPrivateFlags &= ~PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH; |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 11535 | } |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11536 | |
Chet Haase | a9b61ac | 2010-12-20 07:40:25 -0800 | [diff] [blame] | 11537 | jumpDrawablesToCurrentState(); |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11538 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 11539 | clearAccessibilityFocus(); |
Amith Yamasani | 4503c8d | 2011-06-17 12:36:14 -0700 | [diff] [blame] | 11540 | if (isFocused()) { |
| 11541 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 11542 | imm.focusIn(this); |
| 11543 | } |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11544 | |
| 11545 | if (mAttachInfo != null && mDisplayList != null) { |
| 11546 | mAttachInfo.mViewRootImpl.dequeueDisplayList(mDisplayList); |
| 11547 | } |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 11548 | } |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 11549 | |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11550 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11551 | * Resolve all RTL related properties. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11552 | */ |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11553 | void resolveRtlPropertiesIfNeeded() { |
| 11554 | if (!needRtlPropertiesResolution()) return; |
| 11555 | |
| 11556 | // Order is important here: LayoutDirection MUST be resolved first |
| 11557 | if (!isLayoutDirectionResolved()) { |
| 11558 | resolveLayoutDirection(); |
| 11559 | resolveLayoutParams(); |
| 11560 | } |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11561 | // ... 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] | 11562 | if (!isTextDirectionResolved()) { |
| 11563 | resolveTextDirection(); |
| 11564 | } |
| 11565 | if (!isTextAlignmentResolved()) { |
| 11566 | resolveTextAlignment(); |
| 11567 | } |
| 11568 | if (!isPaddingResolved()) { |
| 11569 | resolvePadding(); |
| 11570 | } |
| 11571 | if (!isDrawablesResolved()) { |
| 11572 | resolveDrawables(); |
| 11573 | } |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 11574 | onRtlPropertiesChanged(getLayoutDirection()); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11575 | } |
| 11576 | |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11577 | // Reset resolution of all RTL related properties. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11578 | void resetRtlProperties() { |
| 11579 | resetResolvedLayoutDirection(); |
| 11580 | resetResolvedTextDirection(); |
| 11581 | resetResolvedTextAlignment(); |
| 11582 | resetResolvedPadding(); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11583 | resetResolvedDrawables(); |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11584 | } |
| 11585 | |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 11586 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 11587 | * @see #onScreenStateChanged(int) |
| 11588 | */ |
| 11589 | void dispatchScreenStateChanged(int screenState) { |
| 11590 | onScreenStateChanged(screenState); |
| 11591 | } |
| 11592 | |
| 11593 | /** |
| 11594 | * This method is called whenever the state of the screen this view is |
| 11595 | * attached to changes. A state change will usually occurs when the screen |
| 11596 | * turns on or off (whether it happens automatically or the user does it |
| 11597 | * manually.) |
| 11598 | * |
| 11599 | * @param screenState The new state of the screen. Can be either |
| 11600 | * {@link #SCREEN_STATE_ON} or {@link #SCREEN_STATE_OFF} |
| 11601 | */ |
| 11602 | public void onScreenStateChanged(int screenState) { |
| 11603 | } |
| 11604 | |
| 11605 | /** |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11606 | * Return true if the application tag in the AndroidManifest has set "supportRtl" to true |
| 11607 | */ |
| 11608 | private boolean hasRtlSupport() { |
| 11609 | return mContext.getApplicationInfo().hasRtlSupport(); |
| 11610 | } |
| 11611 | |
| 11612 | /** |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 11613 | * Return true if we are in RTL compatibility mode (either before Jelly Bean MR1 or |
| 11614 | * RTL not supported) |
| 11615 | */ |
| 11616 | private boolean isRtlCompatibilityMode() { |
| 11617 | final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion; |
| 11618 | return targetSdkVersion < JELLY_BEAN_MR1 || !hasRtlSupport(); |
| 11619 | } |
| 11620 | |
| 11621 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11622 | * @return true if RTL properties need resolution. |
| 11623 | */ |
| 11624 | private boolean needRtlPropertiesResolution() { |
| 11625 | return (mPrivateFlags2 & ALL_RTL_PROPERTIES_RESOLVED) != ALL_RTL_PROPERTIES_RESOLVED; |
| 11626 | } |
| 11627 | |
| 11628 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11629 | * Called when any RTL property (layout direction or text direction or text alignment) has |
| 11630 | * been changed. |
| 11631 | * |
| 11632 | * Subclasses need to override this method to take care of cached information that depends on the |
| 11633 | * resolved layout direction, or to inform child views that inherit their layout direction. |
| 11634 | * |
| 11635 | * The default implementation does nothing. |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 11636 | * |
| 11637 | * @param layoutDirection the direction of the layout |
| 11638 | * |
| 11639 | * @see #LAYOUT_DIRECTION_LTR |
| 11640 | * @see #LAYOUT_DIRECTION_RTL |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11641 | */ |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 11642 | public void onRtlPropertiesChanged(int layoutDirection) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11643 | } |
| 11644 | |
| 11645 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11646 | * Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing |
| 11647 | * 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] | 11648 | * |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11649 | * @return true if resolution has been done, false otherwise. |
| 11650 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11651 | * @hide |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 11652 | */ |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11653 | public boolean resolveLayoutDirection() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11654 | // Clear any previous layout direction resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11655 | mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11656 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11657 | if (hasRtlSupport()) { |
| 11658 | // Set resolved depending on layout direction |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 11659 | switch ((mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >> |
| 11660 | PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) { |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11661 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | b93911f | 2012-06-26 19:43:15 -0700 | [diff] [blame] | 11662 | // We cannot resolve yet. LTR is by default and let the resolution happen again |
| 11663 | // later to get the correct resolved value |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11664 | if (!canResolveLayoutDirection()) return false; |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 11665 | |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11666 | View parent = ((View) mParent); |
| 11667 | // Parent has not yet resolved, LTR is still the default |
| 11668 | if (!parent.isLayoutDirectionResolved()) return false; |
Fabrice Di Meglio | b93911f | 2012-06-26 19:43:15 -0700 | [diff] [blame] | 11669 | |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11670 | if (parent.getLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11671 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11672 | } |
| 11673 | break; |
| 11674 | case LAYOUT_DIRECTION_RTL: |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11675 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11676 | break; |
| 11677 | case LAYOUT_DIRECTION_LOCALE: |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11678 | if((LAYOUT_DIRECTION_RTL == |
| 11679 | TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()))) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11680 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 11681 | } |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11682 | break; |
| 11683 | default: |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 11684 | // Nothing to do, LTR by default |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11685 | } |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 11686 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11687 | |
| 11688 | // Set to resolved |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11689 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11690 | return true; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11691 | } |
| 11692 | |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 11693 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11694 | * Check if layout direction resolution can be done. |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11695 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11696 | * @return true if layout direction resolution can be done otherwise return false. |
| 11697 | * |
| 11698 | * @hide |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11699 | */ |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11700 | public boolean canResolveLayoutDirection() { |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11701 | switch (getRawLayoutDirection()) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11702 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11703 | return (mParent != null) && (mParent instanceof ViewGroup) && |
| 11704 | ((ViewGroup) mParent).canResolveLayoutDirection(); |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11705 | default: |
| 11706 | return true; |
| 11707 | } |
| 11708 | } |
| 11709 | |
| 11710 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11711 | * Reset the resolved layout direction. Layout direction will be resolved during a call to |
| 11712 | * {@link #onMeasure(int, int)}. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11713 | * |
| 11714 | * @hide |
| 11715 | */ |
| 11716 | public void resetResolvedLayoutDirection() { |
| 11717 | // Reset the current resolved bits |
| 11718 | mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11719 | } |
| 11720 | |
| 11721 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11722 | * @return true if the layout direction is inherited. |
| 11723 | * |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 11724 | * @hide |
| 11725 | */ |
| 11726 | public boolean isLayoutDirectionInherited() { |
| 11727 | return (getRawLayoutDirection() == LAYOUT_DIRECTION_INHERIT); |
| 11728 | } |
| 11729 | |
| 11730 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11731 | * @return true if layout direction has been resolved. |
| 11732 | */ |
| 11733 | private boolean isLayoutDirectionResolved() { |
| 11734 | return (mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_RESOLVED) == PFLAG2_LAYOUT_DIRECTION_RESOLVED; |
| 11735 | } |
| 11736 | |
| 11737 | /** |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11738 | * Return if padding has been resolved |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11739 | * |
| 11740 | * @hide |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11741 | */ |
| 11742 | boolean isPaddingResolved() { |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11743 | return (mPrivateFlags2 & PFLAG2_PADDING_RESOLVED) == PFLAG2_PADDING_RESOLVED; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11744 | } |
| 11745 | |
| 11746 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11747 | * Resolve padding depending on layout direction. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11748 | * |
| 11749 | * @hide |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 11750 | */ |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 11751 | public void resolvePadding() { |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 11752 | if (!isRtlCompatibilityMode()) { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11753 | // Post Jelly Bean MR1 case: we need to take the resolved layout direction into account. |
| 11754 | // If start / end padding are defined, they will be resolved (hence overriding) to |
| 11755 | // left / right or right / left depending on the resolved layout direction. |
| 11756 | // 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] | 11757 | int resolvedLayoutDirection = getLayoutDirection(); |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 11758 | // Set user padding to initial values ... |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 11759 | mUserPaddingLeft = mUserPaddingLeftInitial; |
| 11760 | mUserPaddingRight = mUserPaddingRightInitial; |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 11761 | // ... then resolve it. |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11762 | switch (resolvedLayoutDirection) { |
| 11763 | case LAYOUT_DIRECTION_RTL: |
| 11764 | if (mUserPaddingStart != UNDEFINED_PADDING) { |
| 11765 | mUserPaddingRight = mUserPaddingStart; |
| 11766 | } |
| 11767 | if (mUserPaddingEnd != UNDEFINED_PADDING) { |
| 11768 | mUserPaddingLeft = mUserPaddingEnd; |
| 11769 | } |
| 11770 | break; |
| 11771 | case LAYOUT_DIRECTION_LTR: |
| 11772 | default: |
| 11773 | if (mUserPaddingStart != UNDEFINED_PADDING) { |
| 11774 | mUserPaddingLeft = mUserPaddingStart; |
| 11775 | } |
| 11776 | if (mUserPaddingEnd != UNDEFINED_PADDING) { |
| 11777 | mUserPaddingRight = mUserPaddingEnd; |
| 11778 | } |
| 11779 | } |
| 11780 | |
| 11781 | mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom; |
| 11782 | |
| 11783 | internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, |
| 11784 | mUserPaddingBottom); |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 11785 | onRtlPropertiesChanged(resolvedLayoutDirection); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11786 | } |
| 11787 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11788 | mPrivateFlags2 |= PFLAG2_PADDING_RESOLVED; |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 11789 | } |
| 11790 | |
| 11791 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11792 | * Reset the resolved layout direction. |
| 11793 | * |
| 11794 | * @hide |
| 11795 | */ |
| 11796 | public void resetResolvedPadding() { |
| 11797 | mPrivateFlags2 &= ~PFLAG2_PADDING_RESOLVED; |
| 11798 | } |
| 11799 | |
| 11800 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11801 | * This is called when the view is detached from a window. At this point it |
| 11802 | * no longer has a surface for drawing. |
| 11803 | * |
| 11804 | * @see #onAttachedToWindow() |
| 11805 | */ |
| 11806 | protected void onDetachedFromWindow() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11807 | mPrivateFlags &= ~PFLAG_CANCEL_NEXT_UP_EVENT; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11808 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 11809 | removeUnsetPressCallback(); |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 11810 | removeLongPressCallback(); |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 11811 | removePerformClickCallback(); |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 11812 | removeSendViewScrolledAccessibilityEventCallback(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11813 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11814 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11815 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11816 | destroyLayer(false); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 11817 | |
| 11818 | if (mAttachInfo != null) { |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11819 | if (mDisplayList != null) { |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11820 | mAttachInfo.mViewRootImpl.enqueueDisplayList(mDisplayList); |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11821 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 11822 | mAttachInfo.mViewRootImpl.cancelInvalidate(this); |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11823 | } else { |
Romain Guy | 38c2ece | 2012-05-24 14:20:56 -0700 | [diff] [blame] | 11824 | // Should never happen |
| 11825 | clearDisplayList(); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 11826 | } |
| 11827 | |
Patrick Dubroy | ec84c3a | 2011-01-13 17:55:37 -0800 | [diff] [blame] | 11828 | mCurrentAnimation = null; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 11829 | |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11830 | resetRtlProperties(); |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 11831 | onRtlPropertiesChanged(LAYOUT_DIRECTION_DEFAULT); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 11832 | resetAccessibilityStateChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11833 | } |
| 11834 | |
| 11835 | /** |
| 11836 | * @return The number of times this view has been attached to a window |
| 11837 | */ |
| 11838 | protected int getWindowAttachCount() { |
| 11839 | return mWindowAttachCount; |
| 11840 | } |
| 11841 | |
| 11842 | /** |
| 11843 | * Retrieve a unique token identifying the window this view is attached to. |
| 11844 | * @return Return the window's token for use in |
| 11845 | * {@link WindowManager.LayoutParams#token WindowManager.LayoutParams.token}. |
| 11846 | */ |
| 11847 | public IBinder getWindowToken() { |
| 11848 | return mAttachInfo != null ? mAttachInfo.mWindowToken : null; |
| 11849 | } |
| 11850 | |
| 11851 | /** |
| 11852 | * Retrieve a unique token identifying the top-level "real" window of |
| 11853 | * the window that this view is attached to. That is, this is like |
| 11854 | * {@link #getWindowToken}, except if the window this view in is a panel |
| 11855 | * window (attached to another containing window), then the token of |
| 11856 | * the containing window is returned instead. |
| 11857 | * |
| 11858 | * @return Returns the associated window token, either |
| 11859 | * {@link #getWindowToken()} or the containing window's token. |
| 11860 | */ |
| 11861 | public IBinder getApplicationWindowToken() { |
| 11862 | AttachInfo ai = mAttachInfo; |
| 11863 | if (ai != null) { |
| 11864 | IBinder appWindowToken = ai.mPanelParentWindowToken; |
| 11865 | if (appWindowToken == null) { |
| 11866 | appWindowToken = ai.mWindowToken; |
| 11867 | } |
| 11868 | return appWindowToken; |
| 11869 | } |
| 11870 | return null; |
| 11871 | } |
| 11872 | |
| 11873 | /** |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 11874 | * Gets the logical display to which the view's window has been attached. |
| 11875 | * |
| 11876 | * @return The logical display, or null if the view is not currently attached to a window. |
| 11877 | */ |
| 11878 | public Display getDisplay() { |
| 11879 | return mAttachInfo != null ? mAttachInfo.mDisplay : null; |
| 11880 | } |
| 11881 | |
| 11882 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11883 | * Retrieve private session object this view hierarchy is using to |
| 11884 | * communicate with the window manager. |
| 11885 | * @return the session object to communicate with the window manager |
| 11886 | */ |
| 11887 | /*package*/ IWindowSession getWindowSession() { |
| 11888 | return mAttachInfo != null ? mAttachInfo.mSession : null; |
| 11889 | } |
| 11890 | |
| 11891 | /** |
| 11892 | * @param info the {@link android.view.View.AttachInfo} to associated with |
| 11893 | * this view |
| 11894 | */ |
| 11895 | void dispatchAttachedToWindow(AttachInfo info, int visibility) { |
| 11896 | //System.out.println("Attached! " + this); |
| 11897 | mAttachInfo = info; |
| 11898 | mWindowAttachCount++; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 11899 | // We will need to evaluate the drawable state at least once. |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11900 | mPrivateFlags |= PFLAG_DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11901 | if (mFloatingTreeObserver != null) { |
| 11902 | info.mTreeObserver.merge(mFloatingTreeObserver); |
| 11903 | mFloatingTreeObserver = null; |
| 11904 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11905 | if ((mPrivateFlags&PFLAG_SCROLL_CONTAINER) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11906 | mAttachInfo.mScrollContainers.add(this); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11907 | mPrivateFlags |= PFLAG_SCROLL_CONTAINER_ADDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11908 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 11909 | performCollectViewAttributes(mAttachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11910 | onAttachedToWindow(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11911 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11912 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11913 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11914 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11915 | if (listeners != null && listeners.size() > 0) { |
| 11916 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 11917 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 11918 | // could mutate the list by calling the various add/remove methods. This prevents |
| 11919 | // the array from being modified while we iterate it. |
| 11920 | for (OnAttachStateChangeListener listener : listeners) { |
| 11921 | listener.onViewAttachedToWindow(this); |
| 11922 | } |
| 11923 | } |
| 11924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11925 | int vis = info.mWindowVisibility; |
| 11926 | if (vis != GONE) { |
| 11927 | onWindowVisibilityChanged(vis); |
| 11928 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11929 | if ((mPrivateFlags&PFLAG_DRAWABLE_STATE_DIRTY) != 0) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 11930 | // If nobody has evaluated the drawable state yet, then do it now. |
| 11931 | refreshDrawableState(); |
| 11932 | } |
Craig Mautner | 7eac0f5 | 2012-09-13 13:14:14 -0700 | [diff] [blame] | 11933 | needGlobalAttributesUpdate(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11934 | } |
| 11935 | |
| 11936 | void dispatchDetachedFromWindow() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11937 | AttachInfo info = mAttachInfo; |
| 11938 | if (info != null) { |
| 11939 | int vis = info.mWindowVisibility; |
| 11940 | if (vis != GONE) { |
| 11941 | onWindowVisibilityChanged(GONE); |
| 11942 | } |
| 11943 | } |
| 11944 | |
| 11945 | onDetachedFromWindow(); |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 11946 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11947 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11948 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11949 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11950 | if (listeners != null && listeners.size() > 0) { |
| 11951 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 11952 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 11953 | // could mutate the list by calling the various add/remove methods. This prevents |
| 11954 | // the array from being modified while we iterate it. |
| 11955 | for (OnAttachStateChangeListener listener : listeners) { |
| 11956 | listener.onViewDetachedFromWindow(this); |
| 11957 | } |
| 11958 | } |
| 11959 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11960 | if ((mPrivateFlags & PFLAG_SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11961 | mAttachInfo.mScrollContainers.remove(this); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11962 | mPrivateFlags &= ~PFLAG_SCROLL_CONTAINER_ADDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11963 | } |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 11964 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11965 | mAttachInfo = null; |
| 11966 | } |
| 11967 | |
| 11968 | /** |
| 11969 | * Store this view hierarchy's frozen state into the given container. |
| 11970 | * |
| 11971 | * @param container The SparseArray in which to save the view's state. |
| 11972 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11973 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 11974 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 11975 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11976 | */ |
| 11977 | public void saveHierarchyState(SparseArray<Parcelable> container) { |
| 11978 | dispatchSaveInstanceState(container); |
| 11979 | } |
| 11980 | |
| 11981 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11982 | * Called by {@link #saveHierarchyState(android.util.SparseArray)} to store the state for |
| 11983 | * this view and its children. May be overridden to modify how freezing happens to a |
| 11984 | * 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] | 11985 | * |
| 11986 | * @param container The SparseArray in which to save the view's state. |
| 11987 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11988 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 11989 | * @see #saveHierarchyState(android.util.SparseArray) |
| 11990 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11991 | */ |
| 11992 | protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 11993 | if (mID != NO_ID && (mViewFlags & SAVE_DISABLED_MASK) == 0) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11994 | mPrivateFlags &= ~PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11995 | Parcelable state = onSaveInstanceState(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11996 | if ((mPrivateFlags & PFLAG_SAVE_STATE_CALLED) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11997 | throw new IllegalStateException( |
| 11998 | "Derived class did not call super.onSaveInstanceState()"); |
| 11999 | } |
| 12000 | if (state != null) { |
| 12001 | // Log.i("View", "Freezing #" + Integer.toHexString(mID) |
| 12002 | // + ": " + state); |
| 12003 | container.put(mID, state); |
| 12004 | } |
| 12005 | } |
| 12006 | } |
| 12007 | |
| 12008 | /** |
| 12009 | * Hook allowing a view to generate a representation of its internal state |
| 12010 | * that can later be used to create a new instance with that same state. |
| 12011 | * This state should only contain information that is not persistent or can |
| 12012 | * not be reconstructed later. For example, you will never store your |
| 12013 | * current position on screen because that will be computed again when a |
| 12014 | * new instance of the view is placed in its view hierarchy. |
| 12015 | * <p> |
| 12016 | * Some examples of things you may store here: the current cursor position |
| 12017 | * in a text view (but usually not the text itself since that is stored in a |
| 12018 | * content provider or other persistent storage), the currently selected |
| 12019 | * item in a list view. |
| 12020 | * |
| 12021 | * @return Returns a Parcelable object containing the view's current dynamic |
| 12022 | * state, or null if there is nothing interesting to save. The |
| 12023 | * default implementation returns null. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12024 | * @see #onRestoreInstanceState(android.os.Parcelable) |
| 12025 | * @see #saveHierarchyState(android.util.SparseArray) |
| 12026 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12027 | * @see #setSaveEnabled(boolean) |
| 12028 | */ |
| 12029 | protected Parcelable onSaveInstanceState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12030 | mPrivateFlags |= PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12031 | return BaseSavedState.EMPTY_STATE; |
| 12032 | } |
| 12033 | |
| 12034 | /** |
| 12035 | * Restore this view hierarchy's frozen state from the given container. |
| 12036 | * |
| 12037 | * @param container The SparseArray which holds previously frozen states. |
| 12038 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12039 | * @see #saveHierarchyState(android.util.SparseArray) |
| 12040 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 12041 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12042 | */ |
| 12043 | public void restoreHierarchyState(SparseArray<Parcelable> container) { |
| 12044 | dispatchRestoreInstanceState(container); |
| 12045 | } |
| 12046 | |
| 12047 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12048 | * Called by {@link #restoreHierarchyState(android.util.SparseArray)} to retrieve the |
| 12049 | * state for this view and its children. May be overridden to modify how restoring |
| 12050 | * happens to a view's children; for example, some views may want to not store state |
| 12051 | * for their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12052 | * |
| 12053 | * @param container The SparseArray which holds previously saved state. |
| 12054 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12055 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 12056 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 12057 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12058 | */ |
| 12059 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 12060 | if (mID != NO_ID) { |
| 12061 | Parcelable state = container.get(mID); |
| 12062 | if (state != null) { |
| 12063 | // Log.i("View", "Restoreing #" + Integer.toHexString(mID) |
| 12064 | // + ": " + state); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12065 | mPrivateFlags &= ~PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12066 | onRestoreInstanceState(state); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12067 | if ((mPrivateFlags & PFLAG_SAVE_STATE_CALLED) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12068 | throw new IllegalStateException( |
| 12069 | "Derived class did not call super.onRestoreInstanceState()"); |
| 12070 | } |
| 12071 | } |
| 12072 | } |
| 12073 | } |
| 12074 | |
| 12075 | /** |
| 12076 | * Hook allowing a view to re-apply a representation of its internal state that had previously |
| 12077 | * been generated by {@link #onSaveInstanceState}. This function will never be called with a |
| 12078 | * null state. |
| 12079 | * |
| 12080 | * @param state The frozen state that had previously been returned by |
| 12081 | * {@link #onSaveInstanceState}. |
| 12082 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12083 | * @see #onSaveInstanceState() |
| 12084 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 12085 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12086 | */ |
| 12087 | protected void onRestoreInstanceState(Parcelable state) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12088 | mPrivateFlags |= PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12089 | if (state != BaseSavedState.EMPTY_STATE && state != null) { |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 12090 | throw new IllegalArgumentException("Wrong state class, expecting View State but " |
| 12091 | + "received " + state.getClass().toString() + " instead. This usually happens " |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12092 | + "when two views of different type have the same id in the same hierarchy. " |
| 12093 | + "This view's id is " + ViewDebug.resolveId(mContext, getId()) + ". Make sure " |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 12094 | + "other views do not use the same id."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12095 | } |
| 12096 | } |
| 12097 | |
| 12098 | /** |
| 12099 | * <p>Return the time at which the drawing of the view hierarchy started.</p> |
| 12100 | * |
| 12101 | * @return the drawing start time in milliseconds |
| 12102 | */ |
| 12103 | public long getDrawingTime() { |
| 12104 | return mAttachInfo != null ? mAttachInfo.mDrawingTime : 0; |
| 12105 | } |
| 12106 | |
| 12107 | /** |
| 12108 | * <p>Enables or disables the duplication of the parent's state into this view. When |
| 12109 | * duplication is enabled, this view gets its drawable state from its parent rather |
| 12110 | * than from its own internal properties.</p> |
| 12111 | * |
| 12112 | * <p>Note: in the current implementation, setting this property to true after the |
| 12113 | * view was added to a ViewGroup might have no effect at all. This property should |
| 12114 | * always be used from XML or set to true before adding this view to a ViewGroup.</p> |
| 12115 | * |
| 12116 | * <p>Note: if this view's parent addStateFromChildren property is enabled and this |
| 12117 | * property is enabled, an exception will be thrown.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12118 | * |
Gilles Debunne | fb81703 | 2011-01-13 13:52:49 -0800 | [diff] [blame] | 12119 | * <p>Note: if the child view uses and updates additionnal states which are unknown to the |
| 12120 | * 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] | 12121 | * |
| 12122 | * @param enabled True to enable duplication of the parent's drawable state, false |
| 12123 | * to disable it. |
| 12124 | * |
| 12125 | * @see #getDrawableState() |
| 12126 | * @see #isDuplicateParentStateEnabled() |
| 12127 | */ |
| 12128 | public void setDuplicateParentStateEnabled(boolean enabled) { |
| 12129 | setFlags(enabled ? DUPLICATE_PARENT_STATE : 0, DUPLICATE_PARENT_STATE); |
| 12130 | } |
| 12131 | |
| 12132 | /** |
| 12133 | * <p>Indicates whether this duplicates its drawable state from its parent.</p> |
| 12134 | * |
| 12135 | * @return True if this view's drawable state is duplicated from the parent, |
| 12136 | * false otherwise |
| 12137 | * |
| 12138 | * @see #getDrawableState() |
| 12139 | * @see #setDuplicateParentStateEnabled(boolean) |
| 12140 | */ |
| 12141 | public boolean isDuplicateParentStateEnabled() { |
| 12142 | return (mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE; |
| 12143 | } |
| 12144 | |
| 12145 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12146 | * <p>Specifies the type of layer backing this view. The layer can be |
| 12147 | * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or |
| 12148 | * {@link #LAYER_TYPE_HARDWARE hardware}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12149 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12150 | * <p>A layer is associated with an optional {@link android.graphics.Paint} |
| 12151 | * instance that controls how the layer is composed on screen. The following |
| 12152 | * properties of the paint are taken into account when composing the layer:</p> |
| 12153 | * <ul> |
| 12154 | * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> |
| 12155 | * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> |
| 12156 | * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> |
| 12157 | * </ul> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12158 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12159 | * <p>If this view has an alpha value set to < 1.0 by calling |
| 12160 | * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by |
| 12161 | * this view's alpha value. Calling {@link #setAlpha(float)} is therefore |
| 12162 | * 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] | 12163 | * the desired alpha value.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12164 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12165 | * <p>Refer to the documentation of {@link #LAYER_TYPE_NONE disabled}, |
| 12166 | * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware} |
| 12167 | * for more information on when and how to use layers.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12168 | * |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 12169 | * @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] | 12170 | * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 12171 | * {@link #LAYER_TYPE_HARDWARE} |
| 12172 | * @param paint The paint used to compose the layer. This argument is optional |
| 12173 | * and can be null. It is ignored when the layer type is |
| 12174 | * {@link #LAYER_TYPE_NONE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12175 | * |
| 12176 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12177 | * @see #LAYER_TYPE_NONE |
| 12178 | * @see #LAYER_TYPE_SOFTWARE |
| 12179 | * @see #LAYER_TYPE_HARDWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12180 | * @see #setAlpha(float) |
| 12181 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12182 | * @attr ref android.R.styleable#View_layerType |
| 12183 | */ |
| 12184 | public void setLayerType(int layerType, Paint paint) { |
| 12185 | if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12186 | 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] | 12187 | + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE"); |
| 12188 | } |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12189 | |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 12190 | if (layerType == mLayerType) { |
| 12191 | if (layerType != LAYER_TYPE_NONE && paint != mLayerPaint) { |
| 12192 | mLayerPaint = paint == null ? new Paint() : paint; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 12193 | invalidateParentCaches(); |
| 12194 | invalidate(true); |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 12195 | } |
| 12196 | return; |
| 12197 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12198 | |
| 12199 | // Destroy any previous software drawing cache if needed |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12200 | switch (mLayerType) { |
Chet Haase | 6f33e81 | 2011-05-17 12:42:19 -0700 | [diff] [blame] | 12201 | case LAYER_TYPE_HARDWARE: |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12202 | destroyLayer(false); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12203 | // fall through - non-accelerated views may use software layer mechanism instead |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12204 | case LAYER_TYPE_SOFTWARE: |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12205 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12206 | break; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12207 | default: |
| 12208 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12209 | } |
| 12210 | |
| 12211 | mLayerType = layerType; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 12212 | final boolean layerDisabled = mLayerType == LAYER_TYPE_NONE; |
| 12213 | mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint); |
| 12214 | mLocalDirtyRect = layerDisabled ? null : new Rect(); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12215 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 12216 | invalidateParentCaches(); |
| 12217 | invalidate(true); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12218 | } |
| 12219 | |
| 12220 | /** |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 12221 | * Updates the {@link Paint} object used with the current layer (used only if the current |
| 12222 | * layer type is not set to {@link #LAYER_TYPE_NONE}). Changed properties of the Paint |
| 12223 | * provided to {@link #setLayerType(int, android.graphics.Paint)} will be used the next time |
| 12224 | * the View is redrawn, but {@link #setLayerPaint(android.graphics.Paint)} must be called to |
| 12225 | * ensure that the view gets redrawn immediately. |
| 12226 | * |
| 12227 | * <p>A layer is associated with an optional {@link android.graphics.Paint} |
| 12228 | * instance that controls how the layer is composed on screen. The following |
| 12229 | * properties of the paint are taken into account when composing the layer:</p> |
| 12230 | * <ul> |
| 12231 | * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> |
| 12232 | * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> |
| 12233 | * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> |
| 12234 | * </ul> |
| 12235 | * |
| 12236 | * <p>If this view has an alpha value set to < 1.0 by calling |
| 12237 | * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by |
| 12238 | * this view's alpha value. Calling {@link #setAlpha(float)} is therefore |
| 12239 | * equivalent to setting a hardware layer on this view and providing a paint with |
| 12240 | * the desired alpha value.</p> |
| 12241 | * |
| 12242 | * @param paint The paint used to compose the layer. This argument is optional |
| 12243 | * and can be null. It is ignored when the layer type is |
| 12244 | * {@link #LAYER_TYPE_NONE} |
| 12245 | * |
| 12246 | * @see #setLayerType(int, android.graphics.Paint) |
| 12247 | */ |
| 12248 | public void setLayerPaint(Paint paint) { |
| 12249 | int layerType = getLayerType(); |
| 12250 | if (layerType != LAYER_TYPE_NONE) { |
| 12251 | mLayerPaint = paint == null ? new Paint() : paint; |
| 12252 | if (layerType == LAYER_TYPE_HARDWARE) { |
| 12253 | HardwareLayer layer = getHardwareLayer(); |
| 12254 | if (layer != null) { |
| 12255 | layer.setLayerPaint(paint); |
| 12256 | } |
| 12257 | invalidateViewProperty(false, false); |
| 12258 | } else { |
| 12259 | invalidate(); |
| 12260 | } |
| 12261 | } |
| 12262 | } |
| 12263 | |
| 12264 | /** |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 12265 | * Indicates whether this view has a static layer. A view with layer type |
| 12266 | * {@link #LAYER_TYPE_NONE} is a static layer. Other types of layers are |
| 12267 | * dynamic. |
| 12268 | */ |
| 12269 | boolean hasStaticLayer() { |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 12270 | return true; |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 12271 | } |
| 12272 | |
| 12273 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12274 | * Indicates what type of layer is currently associated with this view. By default |
| 12275 | * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}. |
| 12276 | * Refer to the documentation of {@link #setLayerType(int, android.graphics.Paint)} |
| 12277 | * for more information on the different types of layers. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12278 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12279 | * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 12280 | * {@link #LAYER_TYPE_HARDWARE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12281 | * |
| 12282 | * @see #setLayerType(int, android.graphics.Paint) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12283 | * @see #buildLayer() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12284 | * @see #LAYER_TYPE_NONE |
| 12285 | * @see #LAYER_TYPE_SOFTWARE |
| 12286 | * @see #LAYER_TYPE_HARDWARE |
| 12287 | */ |
| 12288 | public int getLayerType() { |
| 12289 | return mLayerType; |
| 12290 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12291 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12292 | /** |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12293 | * Forces this view's layer to be created and this view to be rendered |
| 12294 | * into its layer. If this view's layer type is set to {@link #LAYER_TYPE_NONE}, |
| 12295 | * invoking this method will have no effect. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12296 | * |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12297 | * This method can for instance be used to render a view into its layer before |
| 12298 | * starting an animation. If this view is complex, rendering into the layer |
| 12299 | * before starting the animation will avoid skipping frames. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12300 | * |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12301 | * @throws IllegalStateException If this view is not attached to a window |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12302 | * |
| 12303 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12304 | */ |
| 12305 | public void buildLayer() { |
| 12306 | if (mLayerType == LAYER_TYPE_NONE) return; |
| 12307 | |
| 12308 | if (mAttachInfo == null) { |
| 12309 | throw new IllegalStateException("This view must be attached to a window first"); |
| 12310 | } |
| 12311 | |
| 12312 | switch (mLayerType) { |
| 12313 | case LAYER_TYPE_HARDWARE: |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 12314 | if (mAttachInfo.mHardwareRenderer != null && |
| 12315 | mAttachInfo.mHardwareRenderer.isEnabled() && |
| 12316 | mAttachInfo.mHardwareRenderer.validate()) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12317 | getHardwareLayer(); |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 12318 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12319 | break; |
| 12320 | case LAYER_TYPE_SOFTWARE: |
| 12321 | buildDrawingCache(true); |
| 12322 | break; |
| 12323 | } |
| 12324 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12325 | |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12326 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12327 | * <p>Returns a hardware layer that can be used to draw this view again |
| 12328 | * without executing its draw method.</p> |
| 12329 | * |
| 12330 | * @return A HardwareLayer ready to render, or null if an error occurred. |
| 12331 | */ |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12332 | HardwareLayer getHardwareLayer() { |
Romain Guy | ea83503 | 2011-07-28 19:24:37 -0700 | [diff] [blame] | 12333 | if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null || |
| 12334 | !mAttachInfo.mHardwareRenderer.isEnabled()) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12335 | return null; |
| 12336 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12337 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12338 | if (!mAttachInfo.mHardwareRenderer.validate()) return null; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12339 | |
| 12340 | final int width = mRight - mLeft; |
| 12341 | final int height = mBottom - mTop; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12342 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12343 | if (width == 0 || height == 0) { |
| 12344 | return null; |
| 12345 | } |
| 12346 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12347 | if ((mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == 0 || mHardwareLayer == null) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12348 | if (mHardwareLayer == null) { |
| 12349 | mHardwareLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer( |
| 12350 | width, height, isOpaque()); |
Michael Jurka | 952e02b | 2012-03-13 18:34:35 -0700 | [diff] [blame] | 12351 | mLocalDirtyRect.set(0, 0, width, height); |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 12352 | } else { |
| 12353 | if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) { |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 12354 | if (mHardwareLayer.resize(width, height)) { |
| 12355 | mLocalDirtyRect.set(0, 0, width, height); |
| 12356 | } |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 12357 | } |
| 12358 | |
| 12359 | // This should not be necessary but applications that change |
| 12360 | // the parameters of their background drawable without calling |
| 12361 | // this.setBackground(Drawable) can leave the view in a bad state |
| 12362 | // (for instance isOpaque() returns true, but the background is |
| 12363 | // not opaque.) |
| 12364 | computeOpaqueFlags(); |
| 12365 | |
| 12366 | final boolean opaque = isOpaque(); |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 12367 | if (mHardwareLayer.isValid() && mHardwareLayer.isOpaque() != opaque) { |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 12368 | mHardwareLayer.setOpaque(opaque); |
| 12369 | mLocalDirtyRect.set(0, 0, width, height); |
| 12370 | } |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12371 | } |
| 12372 | |
Romain Guy | 5cd5c3f | 2011-10-17 17:10:02 -0700 | [diff] [blame] | 12373 | // The layer is not valid if the underlying GPU resources cannot be allocated |
| 12374 | if (!mHardwareLayer.isValid()) { |
| 12375 | return null; |
| 12376 | } |
| 12377 | |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 12378 | mHardwareLayer.setLayerPaint(mLayerPaint); |
| 12379 | mHardwareLayer.redrawLater(getHardwareLayerDisplayList(mHardwareLayer), mLocalDirtyRect); |
| 12380 | ViewRootImpl viewRoot = getViewRootImpl(); |
| 12381 | if (viewRoot != null) viewRoot.pushHardwareLayerUpdate(mHardwareLayer); |
| 12382 | |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12383 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12384 | } |
| 12385 | |
| 12386 | return mHardwareLayer; |
| 12387 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12388 | |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 12389 | /** |
| 12390 | * Destroys this View's hardware layer if possible. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12391 | * |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 12392 | * @return True if the layer was destroyed, false otherwise. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12393 | * |
| 12394 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 12395 | * @see #LAYER_TYPE_HARDWARE |
| 12396 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12397 | boolean destroyLayer(boolean valid) { |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12398 | if (mHardwareLayer != null) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12399 | AttachInfo info = mAttachInfo; |
| 12400 | if (info != null && info.mHardwareRenderer != null && |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12401 | info.mHardwareRenderer.isEnabled() && |
| 12402 | (valid || info.mHardwareRenderer.validate())) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12403 | mHardwareLayer.destroy(); |
| 12404 | mHardwareLayer = null; |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12405 | |
Chet Haase | 6a2d17f | 2012-09-30 12:14:13 -0700 | [diff] [blame] | 12406 | if (mDisplayList != null) { |
| 12407 | mDisplayList.reset(); |
| 12408 | } |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12409 | invalidate(true); |
| 12410 | invalidateParentCaches(); |
| 12411 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 12412 | return true; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12413 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 12414 | return false; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12415 | } |
| 12416 | |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12417 | /** |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12418 | * Destroys all hardware rendering resources. This method is invoked |
| 12419 | * when the system needs to reclaim resources. Upon execution of this |
| 12420 | * method, you should free any OpenGL resources created by the view. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12421 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12422 | * Note: you <strong>must</strong> call |
| 12423 | * <code>super.destroyHardwareResources()</code> when overriding |
| 12424 | * this method. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12425 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12426 | * @hide |
| 12427 | */ |
| 12428 | protected void destroyHardwareResources() { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12429 | destroyLayer(true); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12430 | } |
| 12431 | |
| 12432 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12433 | * <p>Enables or disables the drawing cache. When the drawing cache is enabled, the next call |
| 12434 | * to {@link #getDrawingCache()} or {@link #buildDrawingCache()} will draw the view in a |
| 12435 | * bitmap. Calling {@link #draw(android.graphics.Canvas)} will not draw from the cache when |
| 12436 | * the cache is enabled. To benefit from the cache, you must request the drawing cache by |
| 12437 | * calling {@link #getDrawingCache()} and draw it on screen if the returned bitmap is not |
| 12438 | * null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12439 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12440 | * <p>Enabling the drawing cache is similar to |
| 12441 | * {@link #setLayerType(int, android.graphics.Paint) setting a layer} when hardware |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12442 | * acceleration is turned off. When hardware acceleration is turned on, enabling the |
| 12443 | * drawing cache has no effect on rendering because the system uses a different mechanism |
| 12444 | * for acceleration which ignores the flag. If you want to use a Bitmap for the view, even |
| 12445 | * when hardware acceleration is enabled, see {@link #setLayerType(int, android.graphics.Paint)} |
| 12446 | * for information on how to enable software and hardware layers.</p> |
| 12447 | * |
| 12448 | * <p>This API can be used to manually generate |
| 12449 | * a bitmap copy of this view, by setting the flag to <code>true</code> and calling |
| 12450 | * {@link #getDrawingCache()}.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12451 | * |
| 12452 | * @param enabled true to enable the drawing cache, false otherwise |
| 12453 | * |
| 12454 | * @see #isDrawingCacheEnabled() |
| 12455 | * @see #getDrawingCache() |
| 12456 | * @see #buildDrawingCache() |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12457 | * @see #setLayerType(int, android.graphics.Paint) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12458 | */ |
| 12459 | public void setDrawingCacheEnabled(boolean enabled) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12460 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12461 | setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED); |
| 12462 | } |
| 12463 | |
| 12464 | /** |
| 12465 | * <p>Indicates whether the drawing cache is enabled for this view.</p> |
| 12466 | * |
| 12467 | * @return true if the drawing cache is enabled |
| 12468 | * |
| 12469 | * @see #setDrawingCacheEnabled(boolean) |
| 12470 | * @see #getDrawingCache() |
| 12471 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 12472 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12473 | public boolean isDrawingCacheEnabled() { |
| 12474 | return (mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED; |
| 12475 | } |
| 12476 | |
| 12477 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12478 | * Debugging utility which recursively outputs the dirty state of a view and its |
| 12479 | * descendants. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12480 | * |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12481 | * @hide |
| 12482 | */ |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12483 | @SuppressWarnings({"UnusedDeclaration"}) |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12484 | public void outputDirtyFlags(String indent, boolean clear, int clearMask) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12485 | Log.d("View", indent + this + " DIRTY(" + (mPrivateFlags & View.PFLAG_DIRTY_MASK) + |
| 12486 | ") DRAWN(" + (mPrivateFlags & PFLAG_DRAWN) + ")" + " CACHE_VALID(" + |
| 12487 | (mPrivateFlags & View.PFLAG_DRAWING_CACHE_VALID) + |
| 12488 | ") INVALIDATED(" + (mPrivateFlags & PFLAG_INVALIDATED) + ")"); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12489 | if (clear) { |
| 12490 | mPrivateFlags &= clearMask; |
| 12491 | } |
| 12492 | if (this instanceof ViewGroup) { |
| 12493 | ViewGroup parent = (ViewGroup) this; |
| 12494 | final int count = parent.getChildCount(); |
| 12495 | for (int i = 0; i < count; i++) { |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 12496 | final View child = parent.getChildAt(i); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12497 | child.outputDirtyFlags(indent + " ", clear, clearMask); |
| 12498 | } |
| 12499 | } |
| 12500 | } |
| 12501 | |
| 12502 | /** |
| 12503 | * This method is used by ViewGroup to cause its children to restore or recreate their |
| 12504 | * display lists. It is called by getDisplayList() when the parent ViewGroup does not need |
| 12505 | * to recreate its own display list, which would happen if it went through the normal |
| 12506 | * draw/dispatchDraw mechanisms. |
| 12507 | * |
| 12508 | * @hide |
| 12509 | */ |
| 12510 | protected void dispatchGetDisplayList() {} |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 12511 | |
| 12512 | /** |
| 12513 | * A view that is not attached or hardware accelerated cannot create a display list. |
| 12514 | * This method checks these conditions and returns the appropriate result. |
| 12515 | * |
| 12516 | * @return true if view has the ability to create a display list, false otherwise. |
| 12517 | * |
| 12518 | * @hide |
| 12519 | */ |
| 12520 | public boolean canHaveDisplayList() { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12521 | return !(mAttachInfo == null || mAttachInfo.mHardwareRenderer == null); |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 12522 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12523 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12524 | /** |
Gilles Debunne | b35ab7b | 2011-12-05 15:54:00 -0800 | [diff] [blame] | 12525 | * @return The HardwareRenderer associated with that view or null if hardware rendering |
| 12526 | * is not supported or this this has not been attached to a window. |
| 12527 | * |
| 12528 | * @hide |
| 12529 | */ |
| 12530 | public HardwareRenderer getHardwareRenderer() { |
| 12531 | if (mAttachInfo != null) { |
| 12532 | return mAttachInfo.mHardwareRenderer; |
| 12533 | } |
| 12534 | return null; |
| 12535 | } |
| 12536 | |
| 12537 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12538 | * Returns a DisplayList. If the incoming displayList is null, one will be created. |
| 12539 | * Otherwise, the same display list will be returned (after having been rendered into |
| 12540 | * along the way, depending on the invalidation state of the view). |
| 12541 | * |
| 12542 | * @param displayList The previous version of this displayList, could be null. |
| 12543 | * @param isLayer Whether the requester of the display list is a layer. If so, |
| 12544 | * the view will avoid creating a layer inside the resulting display list. |
| 12545 | * @return A new or reused DisplayList object. |
| 12546 | */ |
| 12547 | private DisplayList getDisplayList(DisplayList displayList, boolean isLayer) { |
| 12548 | if (!canHaveDisplayList()) { |
| 12549 | return null; |
| 12550 | } |
| 12551 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12552 | if (((mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == 0 || |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12553 | displayList == null || !displayList.isValid() || |
| 12554 | (!isLayer && mRecreateDisplayList))) { |
| 12555 | // Don't need to recreate the display list, just need to tell our |
| 12556 | // children to restore/recreate theirs |
| 12557 | if (displayList != null && displayList.isValid() && |
| 12558 | !isLayer && !mRecreateDisplayList) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12559 | mPrivateFlags |= PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID; |
| 12560 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12561 | dispatchGetDisplayList(); |
| 12562 | |
| 12563 | return displayList; |
| 12564 | } |
| 12565 | |
| 12566 | if (!isLayer) { |
| 12567 | // If we got here, we're recreating it. Mark it as such to ensure that |
| 12568 | // we copy in child display lists into ours in drawChild() |
| 12569 | mRecreateDisplayList = true; |
| 12570 | } |
| 12571 | if (displayList == null) { |
| 12572 | final String name = getClass().getSimpleName(); |
| 12573 | displayList = mAttachInfo.mHardwareRenderer.createDisplayList(name); |
| 12574 | // If we're creating a new display list, make sure our parent gets invalidated |
| 12575 | // since they will need to recreate their display list to account for this |
| 12576 | // new child display list. |
| 12577 | invalidateParentCaches(); |
| 12578 | } |
| 12579 | |
| 12580 | boolean caching = false; |
| 12581 | final HardwareCanvas canvas = displayList.start(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12582 | int width = mRight - mLeft; |
| 12583 | int height = mBottom - mTop; |
| 12584 | |
| 12585 | try { |
| 12586 | canvas.setViewport(width, height); |
| 12587 | // The dirty rect should always be null for a display list |
| 12588 | canvas.onPreDraw(null); |
Michael Jurka | ba64974 | 2012-06-28 19:12:58 -0700 | [diff] [blame] | 12589 | int layerType = getLayerType(); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 12590 | if (!isLayer && layerType != LAYER_TYPE_NONE) { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 12591 | if (layerType == LAYER_TYPE_HARDWARE) { |
| 12592 | final HardwareLayer layer = getHardwareLayer(); |
| 12593 | if (layer != null && layer.isValid()) { |
| 12594 | canvas.drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 12595 | } else { |
| 12596 | canvas.saveLayer(0, 0, mRight - mLeft, mBottom - mTop, mLayerPaint, |
| 12597 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | |
| 12598 | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 12599 | } |
| 12600 | caching = true; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12601 | } else { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 12602 | buildDrawingCache(true); |
| 12603 | Bitmap cache = getDrawingCache(true); |
| 12604 | if (cache != null) { |
| 12605 | canvas.drawBitmap(cache, 0, 0, mLayerPaint); |
| 12606 | caching = true; |
| 12607 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12608 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12609 | } else { |
| 12610 | |
| 12611 | computeScroll(); |
| 12612 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12613 | canvas.translate(-mScrollX, -mScrollY); |
| 12614 | if (!isLayer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12615 | mPrivateFlags |= PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID; |
| 12616 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12617 | } |
| 12618 | |
| 12619 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12620 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12621 | dispatchDraw(canvas); |
| 12622 | } else { |
| 12623 | draw(canvas); |
| 12624 | } |
| 12625 | } |
| 12626 | } finally { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12627 | canvas.onPostDraw(); |
| 12628 | |
| 12629 | displayList.end(); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 12630 | displayList.setCaching(caching); |
| 12631 | if (isLayer) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12632 | displayList.setLeftTopRightBottom(0, 0, width, height); |
| 12633 | } else { |
| 12634 | setDisplayListProperties(displayList); |
| 12635 | } |
| 12636 | } |
| 12637 | } else if (!isLayer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12638 | mPrivateFlags |= PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID; |
| 12639 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12640 | } |
| 12641 | |
| 12642 | return displayList; |
| 12643 | } |
| 12644 | |
| 12645 | /** |
| 12646 | * Get the DisplayList for the HardwareLayer |
| 12647 | * |
| 12648 | * @param layer The HardwareLayer whose DisplayList we want |
| 12649 | * @return A DisplayList fopr the specified HardwareLayer |
| 12650 | */ |
| 12651 | private DisplayList getHardwareLayerDisplayList(HardwareLayer layer) { |
| 12652 | DisplayList displayList = getDisplayList(layer.getDisplayList(), true); |
| 12653 | layer.setDisplayList(displayList); |
| 12654 | return displayList; |
| 12655 | } |
| 12656 | |
| 12657 | |
| 12658 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12659 | * <p>Returns a display list that can be used to draw this view again |
| 12660 | * without executing its draw method.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12661 | * |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12662 | * @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] | 12663 | * |
| 12664 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12665 | */ |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12666 | public DisplayList getDisplayList() { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12667 | mDisplayList = getDisplayList(mDisplayList, false); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12668 | return mDisplayList; |
| 12669 | } |
| 12670 | |
Romain Guy | 38c2ece | 2012-05-24 14:20:56 -0700 | [diff] [blame] | 12671 | private void clearDisplayList() { |
| 12672 | if (mDisplayList != null) { |
| 12673 | mDisplayList.invalidate(); |
| 12674 | mDisplayList.clear(); |
| 12675 | } |
| 12676 | } |
| 12677 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12678 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12679 | * <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] | 12680 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12681 | * @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] | 12682 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12683 | * @see #getDrawingCache(boolean) |
| 12684 | */ |
| 12685 | public Bitmap getDrawingCache() { |
| 12686 | return getDrawingCache(false); |
| 12687 | } |
| 12688 | |
| 12689 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12690 | * <p>Returns the bitmap in which this view drawing is cached. The returned bitmap |
| 12691 | * is null when caching is disabled. If caching is enabled and the cache is not ready, |
| 12692 | * this method will create it. Calling {@link #draw(android.graphics.Canvas)} will not |
| 12693 | * draw from the cache when the cache is enabled. To benefit from the cache, you must |
| 12694 | * request the drawing cache by calling this method and draw it on screen if the |
| 12695 | * returned bitmap is not null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12696 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12697 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 12698 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 12699 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 12700 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 12701 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 12702 | * size than the view. This implies that your application must be able to handle this |
| 12703 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12704 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12705 | * @param autoScale Indicates whether the generated bitmap should be scaled based on |
| 12706 | * the current density of the screen when the application is in compatibility |
| 12707 | * mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12708 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12709 | * @return A bitmap representing this view or null if cache is disabled. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12710 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12711 | * @see #setDrawingCacheEnabled(boolean) |
| 12712 | * @see #isDrawingCacheEnabled() |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12713 | * @see #buildDrawingCache(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12714 | * @see #destroyDrawingCache() |
| 12715 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12716 | public Bitmap getDrawingCache(boolean autoScale) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12717 | if ((mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING) { |
| 12718 | return null; |
| 12719 | } |
| 12720 | if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12721 | buildDrawingCache(autoScale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12722 | } |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12723 | return autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12724 | } |
| 12725 | |
| 12726 | /** |
| 12727 | * <p>Frees the resources used by the drawing cache. If you call |
| 12728 | * {@link #buildDrawingCache()} manually without calling |
| 12729 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 12730 | * should cleanup the cache with this method afterwards.</p> |
| 12731 | * |
| 12732 | * @see #setDrawingCacheEnabled(boolean) |
| 12733 | * @see #buildDrawingCache() |
| 12734 | * @see #getDrawingCache() |
| 12735 | */ |
| 12736 | public void destroyDrawingCache() { |
| 12737 | if (mDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12738 | mDrawingCache.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12739 | mDrawingCache = null; |
| 12740 | } |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12741 | if (mUnscaledDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12742 | mUnscaledDrawingCache.recycle(); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12743 | mUnscaledDrawingCache = null; |
| 12744 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12745 | } |
| 12746 | |
| 12747 | /** |
| 12748 | * 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] | 12749 | * 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] | 12750 | * view will always be drawn on top of a solid color. |
| 12751 | * |
| 12752 | * @param color The background color to use for the drawing cache's bitmap |
| 12753 | * |
| 12754 | * @see #setDrawingCacheEnabled(boolean) |
| 12755 | * @see #buildDrawingCache() |
| 12756 | * @see #getDrawingCache() |
| 12757 | */ |
| 12758 | public void setDrawingCacheBackgroundColor(int color) { |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 12759 | if (color != mDrawingCacheBackgroundColor) { |
| 12760 | mDrawingCacheBackgroundColor = color; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12761 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 12762 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12763 | } |
| 12764 | |
| 12765 | /** |
| 12766 | * @see #setDrawingCacheBackgroundColor(int) |
| 12767 | * |
| 12768 | * @return The background color to used for the drawing cache's bitmap |
| 12769 | */ |
| 12770 | public int getDrawingCacheBackgroundColor() { |
| 12771 | return mDrawingCacheBackgroundColor; |
| 12772 | } |
| 12773 | |
| 12774 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12775 | * <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] | 12776 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12777 | * @see #buildDrawingCache(boolean) |
| 12778 | */ |
| 12779 | public void buildDrawingCache() { |
| 12780 | buildDrawingCache(false); |
| 12781 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 12782 | |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12783 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12784 | * <p>Forces the drawing cache to be built if the drawing cache is invalid.</p> |
| 12785 | * |
| 12786 | * <p>If you call {@link #buildDrawingCache()} manually without calling |
| 12787 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 12788 | * should cleanup the cache by calling {@link #destroyDrawingCache()} afterwards.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12789 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12790 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 12791 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 12792 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 12793 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 12794 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 12795 | * size than the view. This implies that your application must be able to handle this |
| 12796 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12797 | * |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 12798 | * <p>You should avoid calling this method when hardware acceleration is enabled. If |
| 12799 | * 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] | 12800 | * 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] | 12801 | * performance.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12802 | * |
| 12803 | * @see #getDrawingCache() |
| 12804 | * @see #destroyDrawingCache() |
| 12805 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12806 | public void buildDrawingCache(boolean autoScale) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12807 | if ((mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == 0 || (autoScale ? |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12808 | mDrawingCache == null : mUnscaledDrawingCache == null)) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12809 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12810 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12811 | int width = mRight - mLeft; |
| 12812 | int height = mBottom - mTop; |
| 12813 | |
| 12814 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12815 | final boolean scalingRequired = attachInfo != null && attachInfo.mScalingRequired; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12816 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12817 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12818 | width = (int) ((width * attachInfo.mApplicationScale) + 0.5f); |
| 12819 | height = (int) ((height * attachInfo.mApplicationScale) + 0.5f); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12820 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12821 | |
| 12822 | final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 12823 | final boolean opaque = drawingCacheBackgroundColor != 0 || isOpaque(); |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 12824 | final boolean use32BitCache = attachInfo != null && attachInfo.mUse32BitDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12825 | |
Romain Guy | af61cc4 | 2012-09-30 10:49:15 -0700 | [diff] [blame] | 12826 | final long projectedBitmapSize = width * height * (opaque && !use32BitCache ? 2 : 4); |
| 12827 | final long drawingCacheSize = |
Chris Craik | 10e9d1d | 2012-09-06 14:42:44 -0700 | [diff] [blame] | 12828 | ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize(); |
| 12829 | if (width <= 0 || height <= 0 || projectedBitmapSize > drawingCacheSize) { |
Chris Craik | 3667aa3 | 2012-09-06 14:56:39 -0700 | [diff] [blame] | 12830 | if (width > 0 && height > 0) { |
| 12831 | Log.w(VIEW_LOG_TAG, "View too large to fit into drawing cache, needs " |
| 12832 | + projectedBitmapSize + " bytes, only " |
| 12833 | + drawingCacheSize + " available"); |
| 12834 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12835 | destroyDrawingCache(); |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12836 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12837 | return; |
| 12838 | } |
| 12839 | |
| 12840 | boolean clear = true; |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12841 | Bitmap bitmap = autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12842 | |
| 12843 | if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12844 | Bitmap.Config quality; |
| 12845 | if (!opaque) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12846 | // Never pick ARGB_4444 because it looks awful |
| 12847 | // 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] | 12848 | switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) { |
| 12849 | case DRAWING_CACHE_QUALITY_AUTO: |
| 12850 | quality = Bitmap.Config.ARGB_8888; |
| 12851 | break; |
| 12852 | case DRAWING_CACHE_QUALITY_LOW: |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12853 | quality = Bitmap.Config.ARGB_8888; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12854 | break; |
| 12855 | case DRAWING_CACHE_QUALITY_HIGH: |
| 12856 | quality = Bitmap.Config.ARGB_8888; |
| 12857 | break; |
| 12858 | default: |
| 12859 | quality = Bitmap.Config.ARGB_8888; |
| 12860 | break; |
| 12861 | } |
| 12862 | } else { |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 12863 | // Optimization for translucent windows |
| 12864 | // 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] | 12865 | 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] | 12866 | } |
| 12867 | |
| 12868 | // Try to cleanup memory |
| 12869 | if (bitmap != null) bitmap.recycle(); |
| 12870 | |
| 12871 | try { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 12872 | bitmap = Bitmap.createBitmap(mResources.getDisplayMetrics(), |
| 12873 | width, height, quality); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 12874 | bitmap.setDensity(getResources().getDisplayMetrics().densityDpi); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12875 | if (autoScale) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12876 | mDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12877 | } else { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12878 | mUnscaledDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12879 | } |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 12880 | if (opaque && use32BitCache) bitmap.setHasAlpha(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12881 | } catch (OutOfMemoryError e) { |
| 12882 | // If there is not enough memory to create the bitmap cache, just |
| 12883 | // ignore the issue as bitmap caches are not required to draw the |
| 12884 | // view hierarchy |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12885 | if (autoScale) { |
| 12886 | mDrawingCache = null; |
| 12887 | } else { |
| 12888 | mUnscaledDrawingCache = null; |
| 12889 | } |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12890 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12891 | return; |
| 12892 | } |
| 12893 | |
| 12894 | clear = drawingCacheBackgroundColor != 0; |
| 12895 | } |
| 12896 | |
| 12897 | Canvas canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12898 | if (attachInfo != null) { |
| 12899 | canvas = attachInfo.mCanvas; |
| 12900 | if (canvas == null) { |
| 12901 | canvas = new Canvas(); |
| 12902 | } |
| 12903 | canvas.setBitmap(bitmap); |
| 12904 | // Temporarily clobber the cached Canvas in case one of our children |
| 12905 | // is also using a drawing cache. Without this, the children would |
| 12906 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 12907 | // thing would happen (invisible views, corrupted drawings, etc.) |
| 12908 | attachInfo.mCanvas = null; |
| 12909 | } else { |
| 12910 | // This case should hopefully never or seldom happen |
| 12911 | canvas = new Canvas(bitmap); |
| 12912 | } |
| 12913 | |
| 12914 | if (clear) { |
| 12915 | bitmap.eraseColor(drawingCacheBackgroundColor); |
| 12916 | } |
| 12917 | |
| 12918 | computeScroll(); |
| 12919 | final int restoreCount = canvas.save(); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12920 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12921 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12922 | final float scale = attachInfo.mApplicationScale; |
| 12923 | canvas.scale(scale, scale); |
| 12924 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12926 | canvas.translate(-mScrollX, -mScrollY); |
| 12927 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12928 | mPrivateFlags |= PFLAG_DRAWN; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12929 | if (mAttachInfo == null || !mAttachInfo.mHardwareAccelerated || |
| 12930 | mLayerType != LAYER_TYPE_NONE) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12931 | mPrivateFlags |= PFLAG_DRAWING_CACHE_VALID; |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 12932 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12933 | |
| 12934 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12935 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
| 12936 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12937 | dispatchDraw(canvas); |
| 12938 | } else { |
| 12939 | draw(canvas); |
| 12940 | } |
| 12941 | |
| 12942 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 12943 | canvas.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12944 | |
| 12945 | if (attachInfo != null) { |
| 12946 | // Restore the cached Canvas for our siblings |
| 12947 | attachInfo.mCanvas = canvas; |
| 12948 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12949 | } |
| 12950 | } |
| 12951 | |
| 12952 | /** |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12953 | * Create a snapshot of the view into a bitmap. We should probably make |
| 12954 | * some form of this public, but should think about the API. |
| 12955 | */ |
Romain Guy | 223ff5c | 2010-03-02 17:07:47 -0800 | [diff] [blame] | 12956 | Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) { |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12957 | int width = mRight - mLeft; |
| 12958 | int height = mBottom - mTop; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12959 | |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12960 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 12961 | final float scale = attachInfo != null ? attachInfo.mApplicationScale : 1.0f; |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12962 | width = (int) ((width * scale) + 0.5f); |
| 12963 | height = (int) ((height * scale) + 0.5f); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12964 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 12965 | Bitmap bitmap = Bitmap.createBitmap(mResources.getDisplayMetrics(), |
| 12966 | width > 0 ? width : 1, height > 0 ? height : 1, quality); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12967 | if (bitmap == null) { |
| 12968 | throw new OutOfMemoryError(); |
| 12969 | } |
| 12970 | |
Romain Guy | c529d8d | 2011-09-06 15:01:39 -0700 | [diff] [blame] | 12971 | Resources resources = getResources(); |
| 12972 | if (resources != null) { |
| 12973 | bitmap.setDensity(resources.getDisplayMetrics().densityDpi); |
| 12974 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12975 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12976 | Canvas canvas; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12977 | if (attachInfo != null) { |
| 12978 | canvas = attachInfo.mCanvas; |
| 12979 | if (canvas == null) { |
| 12980 | canvas = new Canvas(); |
| 12981 | } |
| 12982 | canvas.setBitmap(bitmap); |
| 12983 | // Temporarily clobber the cached Canvas in case one of our children |
| 12984 | // is also using a drawing cache. Without this, the children would |
| 12985 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 12986 | // things would happen (invisible views, corrupted drawings, etc.) |
| 12987 | attachInfo.mCanvas = null; |
| 12988 | } else { |
| 12989 | // This case should hopefully never or seldom happen |
| 12990 | canvas = new Canvas(bitmap); |
| 12991 | } |
| 12992 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12993 | if ((backgroundColor & 0xff000000) != 0) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12994 | bitmap.eraseColor(backgroundColor); |
| 12995 | } |
| 12996 | |
| 12997 | computeScroll(); |
| 12998 | final int restoreCount = canvas.save(); |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12999 | canvas.scale(scale, scale); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13000 | canvas.translate(-mScrollX, -mScrollY); |
| 13001 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13002 | // Temporarily remove the dirty mask |
| 13003 | int flags = mPrivateFlags; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13004 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13005 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13006 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13007 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13008 | dispatchDraw(canvas); |
| 13009 | } else { |
| 13010 | draw(canvas); |
| 13011 | } |
| 13012 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13013 | mPrivateFlags = flags; |
| 13014 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13015 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 13016 | canvas.setBitmap(null); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13017 | |
| 13018 | if (attachInfo != null) { |
| 13019 | // Restore the cached Canvas for our siblings |
| 13020 | attachInfo.mCanvas = canvas; |
| 13021 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13022 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13023 | return bitmap; |
| 13024 | } |
| 13025 | |
| 13026 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13027 | * Indicates whether this View is currently in edit mode. A View is usually |
| 13028 | * in edit mode when displayed within a developer tool. For instance, if |
| 13029 | * this View is being drawn by a visual user interface builder, this method |
| 13030 | * should return true. |
| 13031 | * |
| 13032 | * Subclasses should check the return value of this method to provide |
| 13033 | * different behaviors if their normal behavior might interfere with the |
| 13034 | * host environment. For instance: the class spawns a thread in its |
| 13035 | * constructor, the drawing code relies on device-specific features, etc. |
| 13036 | * |
| 13037 | * This method is usually checked in the drawing code of custom widgets. |
| 13038 | * |
| 13039 | * @return True if this View is in edit mode, false otherwise. |
| 13040 | */ |
| 13041 | public boolean isInEditMode() { |
| 13042 | return false; |
| 13043 | } |
| 13044 | |
| 13045 | /** |
| 13046 | * If the View draws content inside its padding and enables fading edges, |
| 13047 | * it needs to support padding offsets. Padding offsets are added to the |
| 13048 | * fading edges to extend the length of the fade so that it covers pixels |
| 13049 | * drawn inside the padding. |
| 13050 | * |
| 13051 | * Subclasses of this class should override this method if they need |
| 13052 | * to draw content inside the padding. |
| 13053 | * |
| 13054 | * @return True if padding offset must be applied, false otherwise. |
| 13055 | * |
| 13056 | * @see #getLeftPaddingOffset() |
| 13057 | * @see #getRightPaddingOffset() |
| 13058 | * @see #getTopPaddingOffset() |
| 13059 | * @see #getBottomPaddingOffset() |
| 13060 | * |
| 13061 | * @since CURRENT |
| 13062 | */ |
| 13063 | protected boolean isPaddingOffsetRequired() { |
| 13064 | return false; |
| 13065 | } |
| 13066 | |
| 13067 | /** |
| 13068 | * Amount by which to extend the left fading region. Called only when |
| 13069 | * {@link #isPaddingOffsetRequired()} returns true. |
| 13070 | * |
| 13071 | * @return The left padding offset in pixels. |
| 13072 | * |
| 13073 | * @see #isPaddingOffsetRequired() |
| 13074 | * |
| 13075 | * @since CURRENT |
| 13076 | */ |
| 13077 | protected int getLeftPaddingOffset() { |
| 13078 | return 0; |
| 13079 | } |
| 13080 | |
| 13081 | /** |
| 13082 | * Amount by which to extend the right fading region. Called only when |
| 13083 | * {@link #isPaddingOffsetRequired()} returns true. |
| 13084 | * |
| 13085 | * @return The right padding offset in pixels. |
| 13086 | * |
| 13087 | * @see #isPaddingOffsetRequired() |
| 13088 | * |
| 13089 | * @since CURRENT |
| 13090 | */ |
| 13091 | protected int getRightPaddingOffset() { |
| 13092 | return 0; |
| 13093 | } |
| 13094 | |
| 13095 | /** |
| 13096 | * Amount by which to extend the top fading region. Called only when |
| 13097 | * {@link #isPaddingOffsetRequired()} returns true. |
| 13098 | * |
| 13099 | * @return The top padding offset in pixels. |
| 13100 | * |
| 13101 | * @see #isPaddingOffsetRequired() |
| 13102 | * |
| 13103 | * @since CURRENT |
| 13104 | */ |
| 13105 | protected int getTopPaddingOffset() { |
| 13106 | return 0; |
| 13107 | } |
| 13108 | |
| 13109 | /** |
| 13110 | * Amount by which to extend the bottom fading region. Called only when |
| 13111 | * {@link #isPaddingOffsetRequired()} returns true. |
| 13112 | * |
| 13113 | * @return The bottom padding offset in pixels. |
| 13114 | * |
| 13115 | * @see #isPaddingOffsetRequired() |
| 13116 | * |
| 13117 | * @since CURRENT |
| 13118 | */ |
| 13119 | protected int getBottomPaddingOffset() { |
| 13120 | return 0; |
| 13121 | } |
| 13122 | |
| 13123 | /** |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13124 | * @hide |
| 13125 | * @param offsetRequired |
| 13126 | */ |
| 13127 | protected int getFadeTop(boolean offsetRequired) { |
| 13128 | int top = mPaddingTop; |
| 13129 | if (offsetRequired) top += getTopPaddingOffset(); |
| 13130 | return top; |
| 13131 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13132 | |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13133 | /** |
| 13134 | * @hide |
| 13135 | * @param offsetRequired |
| 13136 | */ |
| 13137 | protected int getFadeHeight(boolean offsetRequired) { |
| 13138 | int padding = mPaddingTop; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13139 | if (offsetRequired) padding += getTopPaddingOffset(); |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13140 | return mBottom - mTop - mPaddingBottom - padding; |
| 13141 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13142 | |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13143 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 13144 | * <p>Indicates whether this view is attached to a hardware accelerated |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13145 | * window or not.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13146 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13147 | * <p>Even if this method returns true, it does not mean that every call |
| 13148 | * to {@link #draw(android.graphics.Canvas)} will be made with an hardware |
| 13149 | * accelerated {@link android.graphics.Canvas}. For instance, if this view |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 13150 | * is drawn onto an offscreen {@link android.graphics.Bitmap} and its |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13151 | * window is hardware accelerated, |
| 13152 | * {@link android.graphics.Canvas#isHardwareAccelerated()} will likely |
| 13153 | * return false, and this method will return true.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13154 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13155 | * @return True if the view is attached to a window and the window is |
| 13156 | * hardware accelerated; false in any other case. |
| 13157 | */ |
| 13158 | public boolean isHardwareAccelerated() { |
| 13159 | return mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
| 13160 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13161 | |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13162 | /** |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13163 | * Utility function, called by draw(canvas, parent, drawingTime) to handle the less common |
| 13164 | * case of an active Animation being run on the view. |
| 13165 | */ |
| 13166 | private boolean drawAnimation(ViewGroup parent, long drawingTime, |
| 13167 | Animation a, boolean scalingRequired) { |
| 13168 | Transformation invalidationTransform; |
| 13169 | final int flags = parent.mGroupFlags; |
| 13170 | final boolean initialized = a.isInitialized(); |
| 13171 | if (!initialized) { |
Chet Haase | 1fb8a9e | 2012-04-19 09:22:34 -0700 | [diff] [blame] | 13172 | a.initialize(mRight - mLeft, mBottom - mTop, parent.getWidth(), parent.getHeight()); |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13173 | a.initializeInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop); |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 13174 | if (mAttachInfo != null) a.setListenerHandler(mAttachInfo.mHandler); |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13175 | onAnimationStart(); |
| 13176 | } |
| 13177 | |
| 13178 | boolean more = a.getTransformation(drawingTime, parent.mChildTransformation, 1f); |
| 13179 | if (scalingRequired && mAttachInfo.mApplicationScale != 1f) { |
| 13180 | if (parent.mInvalidationTransformation == null) { |
| 13181 | parent.mInvalidationTransformation = new Transformation(); |
| 13182 | } |
| 13183 | invalidationTransform = parent.mInvalidationTransformation; |
| 13184 | a.getTransformation(drawingTime, invalidationTransform, 1f); |
| 13185 | } else { |
| 13186 | invalidationTransform = parent.mChildTransformation; |
| 13187 | } |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 13188 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13189 | if (more) { |
| 13190 | if (!a.willChangeBounds()) { |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 13191 | if ((flags & (ViewGroup.FLAG_OPTIMIZE_INVALIDATE | ViewGroup.FLAG_ANIMATION_DONE)) == |
| 13192 | ViewGroup.FLAG_OPTIMIZE_INVALIDATE) { |
| 13193 | parent.mGroupFlags |= ViewGroup.FLAG_INVALIDATE_REQUIRED; |
| 13194 | } else if ((flags & ViewGroup.FLAG_INVALIDATE_REQUIRED) == 0) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13195 | // The child need to draw an animation, potentially offscreen, so |
| 13196 | // make sure we do not cancel invalidate requests |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13197 | parent.mPrivateFlags |= PFLAG_DRAW_ANIMATION; |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13198 | parent.invalidate(mLeft, mTop, mRight, mBottom); |
| 13199 | } |
| 13200 | } else { |
| 13201 | if (parent.mInvalidateRegion == null) { |
| 13202 | parent.mInvalidateRegion = new RectF(); |
| 13203 | } |
| 13204 | final RectF region = parent.mInvalidateRegion; |
| 13205 | a.getInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop, region, |
| 13206 | invalidationTransform); |
| 13207 | |
| 13208 | // The child need to draw an animation, potentially offscreen, so |
| 13209 | // make sure we do not cancel invalidate requests |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13210 | parent.mPrivateFlags |= PFLAG_DRAW_ANIMATION; |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13211 | |
| 13212 | final int left = mLeft + (int) region.left; |
| 13213 | final int top = mTop + (int) region.top; |
| 13214 | parent.invalidate(left, top, left + (int) (region.width() + .5f), |
| 13215 | top + (int) (region.height() + .5f)); |
| 13216 | } |
| 13217 | } |
| 13218 | return more; |
| 13219 | } |
| 13220 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13221 | /** |
| 13222 | * This method is called by getDisplayList() when a display list is created or re-rendered. |
| 13223 | * It sets or resets the current value of all properties on that display list (resetting is |
| 13224 | * necessary when a display list is being re-created, because we need to make sure that |
| 13225 | * previously-set transform values |
| 13226 | */ |
| 13227 | void setDisplayListProperties(DisplayList displayList) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 13228 | if (displayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13229 | displayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 13230 | displayList.setHasOverlappingRendering(hasOverlappingRendering()); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13231 | if (mParent instanceof ViewGroup) { |
| 13232 | displayList.setClipChildren( |
| 13233 | (((ViewGroup)mParent).mGroupFlags & ViewGroup.FLAG_CLIP_CHILDREN) != 0); |
| 13234 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13235 | float alpha = 1; |
| 13236 | if (mParent instanceof ViewGroup && (((ViewGroup) mParent).mGroupFlags & |
| 13237 | ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
| 13238 | ViewGroup parentVG = (ViewGroup) mParent; |
| 13239 | final boolean hasTransform = |
| 13240 | parentVG.getChildStaticTransformation(this, parentVG.mChildTransformation); |
| 13241 | if (hasTransform) { |
| 13242 | Transformation transform = parentVG.mChildTransformation; |
| 13243 | final int transformType = parentVG.mChildTransformation.getTransformationType(); |
| 13244 | if (transformType != Transformation.TYPE_IDENTITY) { |
| 13245 | if ((transformType & Transformation.TYPE_ALPHA) != 0) { |
| 13246 | alpha = transform.getAlpha(); |
| 13247 | } |
| 13248 | if ((transformType & Transformation.TYPE_MATRIX) != 0) { |
| 13249 | displayList.setStaticMatrix(transform.getMatrix()); |
| 13250 | } |
| 13251 | } |
| 13252 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13253 | } |
| 13254 | if (mTransformationInfo != null) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13255 | alpha *= mTransformationInfo.mAlpha; |
| 13256 | if (alpha < 1) { |
| 13257 | final int multipliedAlpha = (int) (255 * alpha); |
| 13258 | if (onSetAlpha(multipliedAlpha)) { |
| 13259 | alpha = 1; |
| 13260 | } |
| 13261 | } |
| 13262 | displayList.setTransformationInfo(alpha, |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13263 | mTransformationInfo.mTranslationX, mTransformationInfo.mTranslationY, |
| 13264 | mTransformationInfo.mRotation, mTransformationInfo.mRotationX, |
| 13265 | mTransformationInfo.mRotationY, mTransformationInfo.mScaleX, |
| 13266 | mTransformationInfo.mScaleY); |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 13267 | if (mTransformationInfo.mCamera == null) { |
| 13268 | mTransformationInfo.mCamera = new Camera(); |
| 13269 | mTransformationInfo.matrix3D = new Matrix(); |
| 13270 | } |
| 13271 | displayList.setCameraDistance(mTransformationInfo.mCamera.getLocationZ()); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13272 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == PFLAG_PIVOT_EXPLICITLY_SET) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13273 | displayList.setPivotX(getPivotX()); |
| 13274 | displayList.setPivotY(getPivotY()); |
| 13275 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13276 | } else if (alpha < 1) { |
| 13277 | displayList.setAlpha(alpha); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13278 | } |
| 13279 | } |
| 13280 | } |
| 13281 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13282 | /** |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13283 | * This method is called by ViewGroup.drawChild() to have each child view draw itself. |
| 13284 | * This draw() method is an implementation detail and is not intended to be overridden or |
| 13285 | * to be called from anywhere else other than ViewGroup.drawChild(). |
| 13286 | */ |
| 13287 | boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 13288 | boolean useDisplayListProperties = mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13289 | boolean more = false; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13290 | final boolean childHasIdentityMatrix = hasIdentityMatrix(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13291 | final int flags = parent.mGroupFlags; |
| 13292 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13293 | if ((flags & ViewGroup.FLAG_CLEAR_TRANSFORMATION) == ViewGroup.FLAG_CLEAR_TRANSFORMATION) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13294 | parent.mChildTransformation.clear(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13295 | parent.mGroupFlags &= ~ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13296 | } |
| 13297 | |
| 13298 | Transformation transformToApply = null; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13299 | boolean concatMatrix = false; |
| 13300 | |
| 13301 | boolean scalingRequired = false; |
| 13302 | boolean caching; |
Michael Jurka | ba64974 | 2012-06-28 19:12:58 -0700 | [diff] [blame] | 13303 | int layerType = getLayerType(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13304 | |
| 13305 | final boolean hardwareAccelerated = canvas.isHardwareAccelerated(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13306 | if ((flags & ViewGroup.FLAG_CHILDREN_DRAWN_WITH_CACHE) != 0 || |
| 13307 | (flags & ViewGroup.FLAG_ALWAYS_DRAWN_WITH_CACHE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13308 | caching = true; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13309 | // 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] | 13310 | if (mAttachInfo != null) scalingRequired = mAttachInfo.mScalingRequired; |
| 13311 | } else { |
| 13312 | caching = (layerType != LAYER_TYPE_NONE) || hardwareAccelerated; |
| 13313 | } |
| 13314 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13315 | final Animation a = getAnimation(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13316 | if (a != null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13317 | more = drawAnimation(parent, drawingTime, a, scalingRequired); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13318 | concatMatrix = a.willChangeTransformationMatrix(); |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13319 | if (concatMatrix) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13320 | mPrivateFlags3 |= PFLAG3_VIEW_IS_ANIMATING_TRANSFORM; |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13321 | } |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13322 | transformToApply = parent.mChildTransformation; |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13323 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13324 | if ((mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_TRANSFORM) == PFLAG3_VIEW_IS_ANIMATING_TRANSFORM && |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13325 | mDisplayList != null) { |
| 13326 | // No longer animating: clear out old animation matrix |
| 13327 | mDisplayList.setAnimationMatrix(null); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13328 | mPrivateFlags3 &= ~PFLAG3_VIEW_IS_ANIMATING_TRANSFORM; |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13329 | } |
| 13330 | if (!useDisplayListProperties && |
| 13331 | (flags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
| 13332 | final boolean hasTransform = |
| 13333 | parent.getChildStaticTransformation(this, parent.mChildTransformation); |
| 13334 | if (hasTransform) { |
| 13335 | final int transformType = parent.mChildTransformation.getTransformationType(); |
| 13336 | transformToApply = transformType != Transformation.TYPE_IDENTITY ? |
| 13337 | parent.mChildTransformation : null; |
| 13338 | concatMatrix = (transformType & Transformation.TYPE_MATRIX) != 0; |
| 13339 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13340 | } |
| 13341 | } |
| 13342 | |
| 13343 | concatMatrix |= !childHasIdentityMatrix; |
| 13344 | |
| 13345 | // Sets the flag as early as possible to allow draw() implementations |
| 13346 | // to call invalidate() successfully when doing animations |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13347 | mPrivateFlags |= PFLAG_DRAWN; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13348 | |
Romain Guy | fbb4321 | 2012-08-30 15:19:27 -0700 | [diff] [blame] | 13349 | if (!concatMatrix && |
| 13350 | (flags & (ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS | |
| 13351 | ViewGroup.FLAG_CLIP_CHILDREN)) == ViewGroup.FLAG_CLIP_CHILDREN && |
Chet Haase | 599913d | 2012-07-23 16:22:05 -0700 | [diff] [blame] | 13352 | canvas.quickReject(mLeft, mTop, mRight, mBottom, Canvas.EdgeType.BW) && |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13353 | (mPrivateFlags & PFLAG_DRAW_ANIMATION) == 0) { |
| 13354 | mPrivateFlags2 |= PFLAG2_VIEW_QUICK_REJECTED; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13355 | return more; |
| 13356 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13357 | mPrivateFlags2 &= ~PFLAG2_VIEW_QUICK_REJECTED; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13358 | |
| 13359 | if (hardwareAccelerated) { |
| 13360 | // Clear INVALIDATED flag to allow invalidation to occur during rendering, but |
| 13361 | // retain the flag's value temporarily in the mRecreateDisplayList flag |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13362 | mRecreateDisplayList = (mPrivateFlags & PFLAG_INVALIDATED) == PFLAG_INVALIDATED; |
| 13363 | mPrivateFlags &= ~PFLAG_INVALIDATED; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13364 | } |
| 13365 | |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13366 | DisplayList displayList = null; |
| 13367 | Bitmap cache = null; |
| 13368 | boolean hasDisplayList = false; |
| 13369 | if (caching) { |
| 13370 | if (!hardwareAccelerated) { |
| 13371 | if (layerType != LAYER_TYPE_NONE) { |
| 13372 | layerType = LAYER_TYPE_SOFTWARE; |
| 13373 | buildDrawingCache(true); |
| 13374 | } |
| 13375 | cache = getDrawingCache(true); |
| 13376 | } else { |
| 13377 | switch (layerType) { |
| 13378 | case LAYER_TYPE_SOFTWARE: |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 13379 | if (useDisplayListProperties) { |
| 13380 | hasDisplayList = canHaveDisplayList(); |
| 13381 | } else { |
| 13382 | buildDrawingCache(true); |
| 13383 | cache = getDrawingCache(true); |
| 13384 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13385 | break; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13386 | case LAYER_TYPE_HARDWARE: |
| 13387 | if (useDisplayListProperties) { |
| 13388 | hasDisplayList = canHaveDisplayList(); |
| 13389 | } |
| 13390 | break; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13391 | case LAYER_TYPE_NONE: |
| 13392 | // Delay getting the display list until animation-driven alpha values are |
| 13393 | // set up and possibly passed on to the view |
| 13394 | hasDisplayList = canHaveDisplayList(); |
| 13395 | break; |
| 13396 | } |
| 13397 | } |
| 13398 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13399 | useDisplayListProperties &= hasDisplayList; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13400 | if (useDisplayListProperties) { |
| 13401 | displayList = getDisplayList(); |
| 13402 | if (!displayList.isValid()) { |
| 13403 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 13404 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 13405 | // try to use it again. |
| 13406 | displayList = null; |
| 13407 | hasDisplayList = false; |
| 13408 | useDisplayListProperties = false; |
| 13409 | } |
| 13410 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13411 | |
Chet Haase | 526057b | 2012-07-12 17:50:41 -0700 | [diff] [blame] | 13412 | int sx = 0; |
| 13413 | int sy = 0; |
| 13414 | if (!hasDisplayList) { |
| 13415 | computeScroll(); |
| 13416 | sx = mScrollX; |
| 13417 | sy = mScrollY; |
| 13418 | } |
| 13419 | |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13420 | final boolean hasNoCache = cache == null || hasDisplayList; |
| 13421 | final boolean offsetForScroll = cache == null && !hasDisplayList && |
| 13422 | layerType != LAYER_TYPE_HARDWARE; |
| 13423 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13424 | int restoreTo = -1; |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 13425 | if (!useDisplayListProperties || transformToApply != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13426 | restoreTo = canvas.save(); |
| 13427 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13428 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13429 | canvas.translate(mLeft - sx, mTop - sy); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13430 | } else { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13431 | if (!useDisplayListProperties) { |
| 13432 | canvas.translate(mLeft, mTop); |
| 13433 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13434 | if (scalingRequired) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13435 | if (useDisplayListProperties) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13436 | // TODO: Might not need this if we put everything inside the DL |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13437 | restoreTo = canvas.save(); |
| 13438 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13439 | // mAttachInfo cannot be null, otherwise scalingRequired == false |
| 13440 | final float scale = 1.0f / mAttachInfo.mApplicationScale; |
| 13441 | canvas.scale(scale, scale); |
| 13442 | } |
| 13443 | } |
| 13444 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13445 | float alpha = useDisplayListProperties ? 1 : getAlpha(); |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13446 | if (transformToApply != null || alpha < 1 || !hasIdentityMatrix() || |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13447 | (mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_ALPHA) == PFLAG3_VIEW_IS_ANIMATING_ALPHA) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13448 | if (transformToApply != null || !childHasIdentityMatrix) { |
| 13449 | int transX = 0; |
| 13450 | int transY = 0; |
| 13451 | |
| 13452 | if (offsetForScroll) { |
| 13453 | transX = -sx; |
| 13454 | transY = -sy; |
| 13455 | } |
| 13456 | |
| 13457 | if (transformToApply != null) { |
| 13458 | if (concatMatrix) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13459 | if (useDisplayListProperties) { |
| 13460 | displayList.setAnimationMatrix(transformToApply.getMatrix()); |
| 13461 | } else { |
| 13462 | // Undo the scroll translation, apply the transformation matrix, |
| 13463 | // then redo the scroll translate to get the correct result. |
| 13464 | canvas.translate(-transX, -transY); |
| 13465 | canvas.concat(transformToApply.getMatrix()); |
| 13466 | canvas.translate(transX, transY); |
| 13467 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13468 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13469 | } |
| 13470 | |
| 13471 | float transformAlpha = transformToApply.getAlpha(); |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13472 | if (transformAlpha < 1) { |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13473 | alpha *= transformAlpha; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13474 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13475 | } |
| 13476 | } |
| 13477 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13478 | if (!childHasIdentityMatrix && !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13479 | canvas.translate(-transX, -transY); |
| 13480 | canvas.concat(getMatrix()); |
| 13481 | canvas.translate(transX, transY); |
| 13482 | } |
| 13483 | } |
| 13484 | |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13485 | // Deal with alpha if it is or used to be <1 |
| 13486 | if (alpha < 1 || |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13487 | (mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_ALPHA) == PFLAG3_VIEW_IS_ANIMATING_ALPHA) { |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13488 | if (alpha < 1) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13489 | mPrivateFlags3 |= PFLAG3_VIEW_IS_ANIMATING_ALPHA; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13490 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13491 | mPrivateFlags3 &= ~PFLAG3_VIEW_IS_ANIMATING_ALPHA; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13492 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13493 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13494 | if (hasNoCache) { |
| 13495 | final int multipliedAlpha = (int) (255 * alpha); |
| 13496 | if (!onSetAlpha(multipliedAlpha)) { |
| 13497 | int layerFlags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13498 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) != 0 || |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13499 | layerType != LAYER_TYPE_NONE) { |
| 13500 | layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG; |
| 13501 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13502 | if (useDisplayListProperties) { |
| 13503 | displayList.setAlpha(alpha * getAlpha()); |
| 13504 | } else if (layerType == LAYER_TYPE_NONE) { |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 13505 | final int scrollX = hasDisplayList ? 0 : sx; |
| 13506 | final int scrollY = hasDisplayList ? 0 : sy; |
| 13507 | canvas.saveLayerAlpha(scrollX, scrollY, scrollX + mRight - mLeft, |
| 13508 | scrollY + mBottom - mTop, multipliedAlpha, layerFlags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13509 | } |
| 13510 | } else { |
| 13511 | // Alpha is handled by the child directly, clobber the layer's alpha |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13512 | mPrivateFlags |= PFLAG_ALPHA_SET; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13513 | } |
| 13514 | } |
| 13515 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13516 | } else if ((mPrivateFlags & PFLAG_ALPHA_SET) == PFLAG_ALPHA_SET) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13517 | onSetAlpha(255); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13518 | mPrivateFlags &= ~PFLAG_ALPHA_SET; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13519 | } |
| 13520 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13521 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) == ViewGroup.FLAG_CLIP_CHILDREN && |
| 13522 | !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13523 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13524 | canvas.clipRect(sx, sy, sx + (mRight - mLeft), sy + (mBottom - mTop)); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13525 | } else { |
| 13526 | if (!scalingRequired || cache == null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13527 | canvas.clipRect(0, 0, mRight - mLeft, mBottom - mTop); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13528 | } else { |
| 13529 | canvas.clipRect(0, 0, cache.getWidth(), cache.getHeight()); |
| 13530 | } |
| 13531 | } |
| 13532 | } |
| 13533 | |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13534 | if (!useDisplayListProperties && hasDisplayList) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13535 | displayList = getDisplayList(); |
| 13536 | if (!displayList.isValid()) { |
| 13537 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 13538 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 13539 | // try to use it again. |
| 13540 | displayList = null; |
| 13541 | hasDisplayList = false; |
| 13542 | } |
| 13543 | } |
| 13544 | |
| 13545 | if (hasNoCache) { |
| 13546 | boolean layerRendered = false; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13547 | if (layerType == LAYER_TYPE_HARDWARE && !useDisplayListProperties) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 13548 | final HardwareLayer layer = getHardwareLayer(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13549 | if (layer != null && layer.isValid()) { |
| 13550 | mLayerPaint.setAlpha((int) (alpha * 255)); |
| 13551 | ((HardwareCanvas) canvas).drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 13552 | layerRendered = true; |
| 13553 | } else { |
| 13554 | final int scrollX = hasDisplayList ? 0 : sx; |
| 13555 | final int scrollY = hasDisplayList ? 0 : sy; |
| 13556 | canvas.saveLayer(scrollX, scrollY, |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13557 | scrollX + mRight - mLeft, scrollY + mBottom - mTop, mLayerPaint, |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13558 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 13559 | } |
| 13560 | } |
| 13561 | |
| 13562 | if (!layerRendered) { |
| 13563 | if (!hasDisplayList) { |
| 13564 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13565 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
| 13566 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13567 | dispatchDraw(canvas); |
| 13568 | } else { |
| 13569 | draw(canvas); |
| 13570 | } |
| 13571 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13572 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 13573 | ((HardwareCanvas) canvas).drawDisplayList(displayList, null, flags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13574 | } |
| 13575 | } |
| 13576 | } else if (cache != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13577 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13578 | Paint cachePaint; |
| 13579 | |
| 13580 | if (layerType == LAYER_TYPE_NONE) { |
| 13581 | cachePaint = parent.mCachePaint; |
| 13582 | if (cachePaint == null) { |
| 13583 | cachePaint = new Paint(); |
| 13584 | cachePaint.setDither(false); |
| 13585 | parent.mCachePaint = cachePaint; |
| 13586 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13587 | if (alpha < 1) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13588 | cachePaint.setAlpha((int) (alpha * 255)); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13589 | parent.mGroupFlags |= ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
| 13590 | } else if ((flags & ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13591 | cachePaint.setAlpha(255); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13592 | parent.mGroupFlags &= ~ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13593 | } |
| 13594 | } else { |
| 13595 | cachePaint = mLayerPaint; |
| 13596 | cachePaint.setAlpha((int) (alpha * 255)); |
| 13597 | } |
| 13598 | canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint); |
| 13599 | } |
| 13600 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13601 | if (restoreTo >= 0) { |
| 13602 | canvas.restoreToCount(restoreTo); |
| 13603 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13604 | |
| 13605 | if (a != null && !more) { |
| 13606 | if (!hardwareAccelerated && !a.getFillAfter()) { |
| 13607 | onSetAlpha(255); |
| 13608 | } |
| 13609 | parent.finishAnimatingView(this, a); |
| 13610 | } |
| 13611 | |
| 13612 | if (more && hardwareAccelerated) { |
| 13613 | // invalidation is the trigger to recreate display lists, so if we're using |
| 13614 | // display lists to render, force an invalidate to allow the animation to |
| 13615 | // continue drawing another frame |
| 13616 | parent.invalidate(true); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13617 | if (a.hasAlpha() && (mPrivateFlags & PFLAG_ALPHA_SET) == PFLAG_ALPHA_SET) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13618 | // alpha animations should cause the child to recreate its display list |
| 13619 | invalidate(true); |
| 13620 | } |
| 13621 | } |
| 13622 | |
| 13623 | mRecreateDisplayList = false; |
| 13624 | |
| 13625 | return more; |
| 13626 | } |
| 13627 | |
| 13628 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13629 | * Manually render this view (and all of its children) to the given Canvas. |
| 13630 | * 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] | 13631 | * called. When implementing a view, implement |
| 13632 | * {@link #onDraw(android.graphics.Canvas)} instead of overriding this method. |
| 13633 | * 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] | 13634 | * |
| 13635 | * @param canvas The Canvas to which the View is rendered. |
| 13636 | */ |
| 13637 | public void draw(Canvas canvas) { |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13638 | final int privateFlags = mPrivateFlags; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13639 | final boolean dirtyOpaque = (privateFlags & PFLAG_DIRTY_MASK) == PFLAG_DIRTY_OPAQUE && |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13640 | (mAttachInfo == null || !mAttachInfo.mIgnoreDirtyState); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13641 | mPrivateFlags = (privateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DRAWN; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13643 | /* |
| 13644 | * Draw traversal performs several drawing steps which must be executed |
| 13645 | * in the appropriate order: |
| 13646 | * |
| 13647 | * 1. Draw the background |
| 13648 | * 2. If necessary, save the canvas' layers to prepare for fading |
| 13649 | * 3. Draw view's content |
| 13650 | * 4. Draw children |
| 13651 | * 5. If necessary, draw the fading edges and restore layers |
| 13652 | * 6. Draw decorations (scrollbars for instance) |
| 13653 | */ |
| 13654 | |
| 13655 | // Step 1, draw the background, if needed |
| 13656 | int saveCount; |
| 13657 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13658 | if (!dirtyOpaque) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13659 | final Drawable background = mBackground; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13660 | if (background != null) { |
| 13661 | final int scrollX = mScrollX; |
| 13662 | final int scrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13663 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13664 | if (mBackgroundSizeChanged) { |
| 13665 | background.setBounds(0, 0, mRight - mLeft, mBottom - mTop); |
| 13666 | mBackgroundSizeChanged = false; |
| 13667 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13668 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13669 | if ((scrollX | scrollY) == 0) { |
| 13670 | background.draw(canvas); |
| 13671 | } else { |
| 13672 | canvas.translate(scrollX, scrollY); |
| 13673 | background.draw(canvas); |
| 13674 | canvas.translate(-scrollX, -scrollY); |
| 13675 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13676 | } |
| 13677 | } |
| 13678 | |
| 13679 | // skip step 2 & 5 if possible (common case) |
| 13680 | final int viewFlags = mViewFlags; |
| 13681 | boolean horizontalEdges = (viewFlags & FADING_EDGE_HORIZONTAL) != 0; |
| 13682 | boolean verticalEdges = (viewFlags & FADING_EDGE_VERTICAL) != 0; |
| 13683 | if (!verticalEdges && !horizontalEdges) { |
| 13684 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13685 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13686 | |
| 13687 | // Step 4, draw the children |
| 13688 | dispatchDraw(canvas); |
| 13689 | |
| 13690 | // Step 6, draw decorations (scrollbars) |
| 13691 | onDrawScrollBars(canvas); |
| 13692 | |
| 13693 | // we're done... |
| 13694 | return; |
| 13695 | } |
| 13696 | |
| 13697 | /* |
| 13698 | * Here we do the full fledged routine... |
| 13699 | * (this is an uncommon case where speed matters less, |
| 13700 | * this is why we repeat some of the tests that have been |
| 13701 | * done above) |
| 13702 | */ |
| 13703 | |
| 13704 | boolean drawTop = false; |
| 13705 | boolean drawBottom = false; |
| 13706 | boolean drawLeft = false; |
| 13707 | boolean drawRight = false; |
| 13708 | |
| 13709 | float topFadeStrength = 0.0f; |
| 13710 | float bottomFadeStrength = 0.0f; |
| 13711 | float leftFadeStrength = 0.0f; |
| 13712 | float rightFadeStrength = 0.0f; |
| 13713 | |
| 13714 | // Step 2, save the canvas' layers |
| 13715 | int paddingLeft = mPaddingLeft; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13716 | |
| 13717 | final boolean offsetRequired = isPaddingOffsetRequired(); |
| 13718 | if (offsetRequired) { |
| 13719 | paddingLeft += getLeftPaddingOffset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13720 | } |
| 13721 | |
| 13722 | int left = mScrollX + paddingLeft; |
| 13723 | int right = left + mRight - mLeft - mPaddingRight - paddingLeft; |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13724 | int top = mScrollY + getFadeTop(offsetRequired); |
| 13725 | int bottom = top + getFadeHeight(offsetRequired); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13726 | |
| 13727 | if (offsetRequired) { |
| 13728 | right += getRightPaddingOffset(); |
| 13729 | bottom += getBottomPaddingOffset(); |
| 13730 | } |
| 13731 | |
| 13732 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13733 | final float fadeHeight = scrollabilityCache.fadingEdgeLength; |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13734 | int length = (int) fadeHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13735 | |
| 13736 | // clip the fade length if top and bottom fades overlap |
| 13737 | // overlapping fades produce odd-looking artifacts |
| 13738 | if (verticalEdges && (top + length > bottom - length)) { |
| 13739 | length = (bottom - top) / 2; |
| 13740 | } |
| 13741 | |
| 13742 | // also clip horizontal fades if necessary |
| 13743 | if (horizontalEdges && (left + length > right - length)) { |
| 13744 | length = (right - left) / 2; |
| 13745 | } |
| 13746 | |
| 13747 | if (verticalEdges) { |
| 13748 | topFadeStrength = Math.max(0.0f, Math.min(1.0f, getTopFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13749 | drawTop = topFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13750 | bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, getBottomFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13751 | drawBottom = bottomFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13752 | } |
| 13753 | |
| 13754 | if (horizontalEdges) { |
| 13755 | leftFadeStrength = Math.max(0.0f, Math.min(1.0f, getLeftFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13756 | drawLeft = leftFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13757 | rightFadeStrength = Math.max(0.0f, Math.min(1.0f, getRightFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13758 | drawRight = rightFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13759 | } |
| 13760 | |
| 13761 | saveCount = canvas.getSaveCount(); |
| 13762 | |
| 13763 | int solidColor = getSolidColor(); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 13764 | if (solidColor == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13765 | final int flags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
| 13766 | |
| 13767 | if (drawTop) { |
| 13768 | canvas.saveLayer(left, top, right, top + length, null, flags); |
| 13769 | } |
| 13770 | |
| 13771 | if (drawBottom) { |
| 13772 | canvas.saveLayer(left, bottom - length, right, bottom, null, flags); |
| 13773 | } |
| 13774 | |
| 13775 | if (drawLeft) { |
| 13776 | canvas.saveLayer(left, top, left + length, bottom, null, flags); |
| 13777 | } |
| 13778 | |
| 13779 | if (drawRight) { |
| 13780 | canvas.saveLayer(right - length, top, right, bottom, null, flags); |
| 13781 | } |
| 13782 | } else { |
| 13783 | scrollabilityCache.setFadeColor(solidColor); |
| 13784 | } |
| 13785 | |
| 13786 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13787 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13788 | |
| 13789 | // Step 4, draw the children |
| 13790 | dispatchDraw(canvas); |
| 13791 | |
| 13792 | // Step 5, draw the fade effect and restore layers |
| 13793 | final Paint p = scrollabilityCache.paint; |
| 13794 | final Matrix matrix = scrollabilityCache.matrix; |
| 13795 | final Shader fade = scrollabilityCache.shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13796 | |
| 13797 | if (drawTop) { |
| 13798 | matrix.setScale(1, fadeHeight * topFadeStrength); |
| 13799 | matrix.postTranslate(left, top); |
| 13800 | fade.setLocalMatrix(matrix); |
| 13801 | canvas.drawRect(left, top, right, top + length, p); |
| 13802 | } |
| 13803 | |
| 13804 | if (drawBottom) { |
| 13805 | matrix.setScale(1, fadeHeight * bottomFadeStrength); |
| 13806 | matrix.postRotate(180); |
| 13807 | matrix.postTranslate(left, bottom); |
| 13808 | fade.setLocalMatrix(matrix); |
| 13809 | canvas.drawRect(left, bottom - length, right, bottom, p); |
| 13810 | } |
| 13811 | |
| 13812 | if (drawLeft) { |
| 13813 | matrix.setScale(1, fadeHeight * leftFadeStrength); |
| 13814 | matrix.postRotate(-90); |
| 13815 | matrix.postTranslate(left, top); |
| 13816 | fade.setLocalMatrix(matrix); |
| 13817 | canvas.drawRect(left, top, left + length, bottom, p); |
| 13818 | } |
| 13819 | |
| 13820 | if (drawRight) { |
| 13821 | matrix.setScale(1, fadeHeight * rightFadeStrength); |
| 13822 | matrix.postRotate(90); |
| 13823 | matrix.postTranslate(right, top); |
| 13824 | fade.setLocalMatrix(matrix); |
| 13825 | canvas.drawRect(right - length, top, right, bottom, p); |
| 13826 | } |
| 13827 | |
| 13828 | canvas.restoreToCount(saveCount); |
| 13829 | |
| 13830 | // Step 6, draw decorations (scrollbars) |
| 13831 | onDrawScrollBars(canvas); |
| 13832 | } |
| 13833 | |
| 13834 | /** |
| 13835 | * Override this if your view is known to always be drawn on top of a solid color background, |
| 13836 | * and needs to draw fading edges. Returning a non-zero color enables the view system to |
| 13837 | * optimize the drawing of the fading edges. If you do return a non-zero color, the alpha |
| 13838 | * should be set to 0xFF. |
| 13839 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13840 | * @see #setVerticalFadingEdgeEnabled(boolean) |
| 13841 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13842 | * |
| 13843 | * @return The known solid color background for this view, or 0 if the color may vary |
| 13844 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13845 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13846 | public int getSolidColor() { |
| 13847 | return 0; |
| 13848 | } |
| 13849 | |
| 13850 | /** |
| 13851 | * Build a human readable string representation of the specified view flags. |
| 13852 | * |
| 13853 | * @param flags the view flags to convert to a string |
| 13854 | * @return a String representing the supplied flags |
| 13855 | */ |
| 13856 | private static String printFlags(int flags) { |
| 13857 | String output = ""; |
| 13858 | int numFlags = 0; |
| 13859 | if ((flags & FOCUSABLE_MASK) == FOCUSABLE) { |
| 13860 | output += "TAKES_FOCUS"; |
| 13861 | numFlags++; |
| 13862 | } |
| 13863 | |
| 13864 | switch (flags & VISIBILITY_MASK) { |
| 13865 | case INVISIBLE: |
| 13866 | if (numFlags > 0) { |
| 13867 | output += " "; |
| 13868 | } |
| 13869 | output += "INVISIBLE"; |
| 13870 | // USELESS HERE numFlags++; |
| 13871 | break; |
| 13872 | case GONE: |
| 13873 | if (numFlags > 0) { |
| 13874 | output += " "; |
| 13875 | } |
| 13876 | output += "GONE"; |
| 13877 | // USELESS HERE numFlags++; |
| 13878 | break; |
| 13879 | default: |
| 13880 | break; |
| 13881 | } |
| 13882 | return output; |
| 13883 | } |
| 13884 | |
| 13885 | /** |
| 13886 | * Build a human readable string representation of the specified private |
| 13887 | * view flags. |
| 13888 | * |
| 13889 | * @param privateFlags the private view flags to convert to a string |
| 13890 | * @return a String representing the supplied flags |
| 13891 | */ |
| 13892 | private static String printPrivateFlags(int privateFlags) { |
| 13893 | String output = ""; |
| 13894 | int numFlags = 0; |
| 13895 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13896 | if ((privateFlags & PFLAG_WANTS_FOCUS) == PFLAG_WANTS_FOCUS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13897 | output += "WANTS_FOCUS"; |
| 13898 | numFlags++; |
| 13899 | } |
| 13900 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13901 | if ((privateFlags & PFLAG_FOCUSED) == PFLAG_FOCUSED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13902 | if (numFlags > 0) { |
| 13903 | output += " "; |
| 13904 | } |
| 13905 | output += "FOCUSED"; |
| 13906 | numFlags++; |
| 13907 | } |
| 13908 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13909 | if ((privateFlags & PFLAG_SELECTED) == PFLAG_SELECTED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13910 | if (numFlags > 0) { |
| 13911 | output += " "; |
| 13912 | } |
| 13913 | output += "SELECTED"; |
| 13914 | numFlags++; |
| 13915 | } |
| 13916 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13917 | 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] | 13918 | if (numFlags > 0) { |
| 13919 | output += " "; |
| 13920 | } |
| 13921 | output += "IS_ROOT_NAMESPACE"; |
| 13922 | numFlags++; |
| 13923 | } |
| 13924 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13925 | if ((privateFlags & PFLAG_HAS_BOUNDS) == PFLAG_HAS_BOUNDS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13926 | if (numFlags > 0) { |
| 13927 | output += " "; |
| 13928 | } |
| 13929 | output += "HAS_BOUNDS"; |
| 13930 | numFlags++; |
| 13931 | } |
| 13932 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13933 | if ((privateFlags & PFLAG_DRAWN) == PFLAG_DRAWN) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13934 | if (numFlags > 0) { |
| 13935 | output += " "; |
| 13936 | } |
| 13937 | output += "DRAWN"; |
| 13938 | // USELESS HERE numFlags++; |
| 13939 | } |
| 13940 | return output; |
| 13941 | } |
| 13942 | |
| 13943 | /** |
| 13944 | * <p>Indicates whether or not this view's layout will be requested during |
| 13945 | * the next hierarchy layout pass.</p> |
| 13946 | * |
| 13947 | * @return true if the layout will be forced during next layout pass |
| 13948 | */ |
| 13949 | public boolean isLayoutRequested() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13950 | return (mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13951 | } |
| 13952 | |
| 13953 | /** |
| 13954 | * Assign a size and position to a view and all of its |
| 13955 | * descendants |
| 13956 | * |
| 13957 | * <p>This is the second phase of the layout mechanism. |
| 13958 | * (The first is measuring). In this phase, each parent calls |
| 13959 | * layout on all of its children to position them. |
| 13960 | * This is typically done using the child measurements |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13961 | * that were stored in the measure pass().</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13962 | * |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13963 | * <p>Derived classes should not override this method. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13964 | * Derived classes with children should override |
| 13965 | * onLayout. In that method, they should |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13966 | * call layout on each of their children.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13967 | * |
| 13968 | * @param l Left position, relative to parent |
| 13969 | * @param t Top position, relative to parent |
| 13970 | * @param r Right position, relative to parent |
| 13971 | * @param b Bottom position, relative to parent |
| 13972 | */ |
Romain Guy | 5429e1d | 2010-09-07 12:38:00 -0700 | [diff] [blame] | 13973 | @SuppressWarnings({"unchecked"}) |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13974 | public void layout(int l, int t, int r, int b) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13975 | int oldL = mLeft; |
| 13976 | int oldT = mTop; |
| 13977 | int oldB = mBottom; |
| 13978 | int oldR = mRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13979 | boolean changed = setFrame(l, t, r, b); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13980 | if (changed || (mPrivateFlags & PFLAG_LAYOUT_REQUIRED) == PFLAG_LAYOUT_REQUIRED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13981 | onLayout(changed, l, t, r, b); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13982 | mPrivateFlags &= ~PFLAG_LAYOUT_REQUIRED; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13983 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 13984 | ListenerInfo li = mListenerInfo; |
| 13985 | if (li != null && li.mOnLayoutChangeListeners != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13986 | ArrayList<OnLayoutChangeListener> listenersCopy = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 13987 | (ArrayList<OnLayoutChangeListener>)li.mOnLayoutChangeListeners.clone(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13988 | int numListeners = listenersCopy.size(); |
| 13989 | for (int i = 0; i < numListeners; ++i) { |
Chet Haase | 7c608f2 | 2010-10-22 17:54:04 -0700 | [diff] [blame] | 13990 | 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] | 13991 | } |
| 13992 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13993 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13994 | mPrivateFlags &= ~PFLAG_FORCE_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13995 | } |
| 13996 | |
| 13997 | /** |
| 13998 | * Called from layout when this view should |
| 13999 | * assign a size and position to each of its children. |
| 14000 | * |
| 14001 | * Derived classes with children should override |
| 14002 | * this method and call layout on each of |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 14003 | * their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14004 | * @param changed This is a new size or position for this view |
| 14005 | * @param left Left position, relative to parent |
| 14006 | * @param top Top position, relative to parent |
| 14007 | * @param right Right position, relative to parent |
| 14008 | * @param bottom Bottom position, relative to parent |
| 14009 | */ |
| 14010 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 14011 | } |
| 14012 | |
| 14013 | /** |
| 14014 | * Assign a size and position to this view. |
| 14015 | * |
| 14016 | * This is called from layout. |
| 14017 | * |
| 14018 | * @param left Left position, relative to parent |
| 14019 | * @param top Top position, relative to parent |
| 14020 | * @param right Right position, relative to parent |
| 14021 | * @param bottom Bottom position, relative to parent |
| 14022 | * @return true if the new size and position are different than the |
| 14023 | * previous ones |
| 14024 | * {@hide} |
| 14025 | */ |
| 14026 | protected boolean setFrame(int left, int top, int right, int bottom) { |
| 14027 | boolean changed = false; |
| 14028 | |
| 14029 | if (DBG) { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 14030 | Log.d("View", this + " View.setFrame(" + left + "," + top + "," |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14031 | + right + "," + bottom + ")"); |
| 14032 | } |
| 14033 | |
| 14034 | if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) { |
| 14035 | changed = true; |
| 14036 | |
| 14037 | // Remember our drawn bit |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14038 | int drawn = mPrivateFlags & PFLAG_DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14040 | int oldWidth = mRight - mLeft; |
| 14041 | int oldHeight = mBottom - mTop; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 14042 | int newWidth = right - left; |
| 14043 | int newHeight = bottom - top; |
| 14044 | boolean sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight); |
| 14045 | |
| 14046 | // Invalidate our old position |
| 14047 | invalidate(sizeChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14048 | |
| 14049 | mLeft = left; |
| 14050 | mTop = top; |
| 14051 | mRight = right; |
| 14052 | mBottom = bottom; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 14053 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 14054 | mDisplayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
| 14055 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14056 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14057 | mPrivateFlags |= PFLAG_HAS_BOUNDS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14058 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14059 | |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 14060 | if (sizeChanged) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14061 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 14062 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 14063 | if (mTransformationInfo != null) { |
| 14064 | mTransformationInfo.mMatrixDirty = true; |
| 14065 | } |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 14066 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14067 | onSizeChanged(newWidth, newHeight, oldWidth, oldHeight); |
| 14068 | } |
| 14069 | |
| 14070 | if ((mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 14071 | // If we are visible, force the DRAWN bit to on so that |
| 14072 | // this invalidate will go through (at least to our parent). |
| 14073 | // This is because someone may have invalidated this view |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 14074 | // before this call to setFrame came in, thereby clearing |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14075 | // the DRAWN bit. |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14076 | mPrivateFlags |= PFLAG_DRAWN; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 14077 | invalidate(sizeChanged); |
Chet Haase | f28595e | 2011-01-31 18:52:12 -0800 | [diff] [blame] | 14078 | // parent display list may need to be recreated based on a change in the bounds |
| 14079 | // of any child |
| 14080 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14081 | } |
| 14082 | |
| 14083 | // Reset drawn bit to original value (invalidate turns it off) |
| 14084 | mPrivateFlags |= drawn; |
| 14085 | |
| 14086 | mBackgroundSizeChanged = true; |
| 14087 | } |
| 14088 | return changed; |
| 14089 | } |
| 14090 | |
| 14091 | /** |
| 14092 | * Finalize inflating a view from XML. This is called as the last phase |
| 14093 | * of inflation, after all child views have been added. |
| 14094 | * |
| 14095 | * <p>Even if the subclass overrides onFinishInflate, they should always be |
| 14096 | * sure to call the super method, so that we get called. |
| 14097 | */ |
| 14098 | protected void onFinishInflate() { |
| 14099 | } |
| 14100 | |
| 14101 | /** |
| 14102 | * Returns the resources associated with this view. |
| 14103 | * |
| 14104 | * @return Resources object. |
| 14105 | */ |
| 14106 | public Resources getResources() { |
| 14107 | return mResources; |
| 14108 | } |
| 14109 | |
| 14110 | /** |
| 14111 | * Invalidates the specified Drawable. |
| 14112 | * |
| 14113 | * @param drawable the drawable to invalidate |
| 14114 | */ |
| 14115 | public void invalidateDrawable(Drawable drawable) { |
| 14116 | if (verifyDrawable(drawable)) { |
| 14117 | final Rect dirty = drawable.getBounds(); |
| 14118 | final int scrollX = mScrollX; |
| 14119 | final int scrollY = mScrollY; |
| 14120 | |
| 14121 | invalidate(dirty.left + scrollX, dirty.top + scrollY, |
| 14122 | dirty.right + scrollX, dirty.bottom + scrollY); |
| 14123 | } |
| 14124 | } |
| 14125 | |
| 14126 | /** |
| 14127 | * Schedules an action on a drawable to occur at a specified time. |
| 14128 | * |
| 14129 | * @param who the recipient of the action |
| 14130 | * @param what the action to run on the drawable |
| 14131 | * @param when the time at which the action must occur. Uses the |
| 14132 | * {@link SystemClock#uptimeMillis} timebase. |
| 14133 | */ |
| 14134 | public void scheduleDrawable(Drawable who, Runnable what, long when) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14135 | if (verifyDrawable(who) && what != null) { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 14136 | final long delay = when - SystemClock.uptimeMillis(); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14137 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 14138 | mAttachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 14139 | Choreographer.CALLBACK_ANIMATION, what, who, |
| 14140 | Choreographer.subtractFrameDelay(delay)); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14141 | } else { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 14142 | ViewRootImpl.getRunQueue().postDelayed(what, delay); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14143 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14144 | } |
| 14145 | } |
| 14146 | |
| 14147 | /** |
| 14148 | * Cancels a scheduled action on a drawable. |
| 14149 | * |
| 14150 | * @param who the recipient of the action |
| 14151 | * @param what the action to cancel |
| 14152 | */ |
| 14153 | public void unscheduleDrawable(Drawable who, Runnable what) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14154 | if (verifyDrawable(who) && what != null) { |
| 14155 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 14156 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 14157 | Choreographer.CALLBACK_ANIMATION, what, who); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14158 | } else { |
| 14159 | ViewRootImpl.getRunQueue().removeCallbacks(what); |
| 14160 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14161 | } |
| 14162 | } |
| 14163 | |
| 14164 | /** |
| 14165 | * Unschedule any events associated with the given Drawable. This can be |
| 14166 | * used when selecting a new Drawable into a view, so that the previous |
| 14167 | * one is completely unscheduled. |
| 14168 | * |
| 14169 | * @param who The Drawable to unschedule. |
| 14170 | * |
| 14171 | * @see #drawableStateChanged |
| 14172 | */ |
| 14173 | public void unscheduleDrawable(Drawable who) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 14174 | if (mAttachInfo != null && who != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 14175 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 14176 | Choreographer.CALLBACK_ANIMATION, null, who); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14177 | } |
| 14178 | } |
| 14179 | |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 14180 | /** |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14181 | * Resolve the Drawables depending on the layout direction. This is implicitly supposing |
| 14182 | * that the View directionality can and will be resolved before its Drawables. |
| 14183 | * |
| 14184 | * Will call {@link View#onResolveDrawables} when resolution is done. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14185 | * |
| 14186 | * @hide |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14187 | */ |
| 14188 | public void resolveDrawables() { |
| 14189 | if (mBackground != null) { |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 14190 | mBackground.setLayoutDirection(getLayoutDirection()); |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14191 | } |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 14192 | mPrivateFlags2 |= PFLAG2_DRAWABLE_RESOLVED; |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 14193 | onResolveDrawables(getLayoutDirection()); |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14194 | } |
| 14195 | |
| 14196 | /** |
| 14197 | * Called when layout direction has been resolved. |
| 14198 | * |
| 14199 | * The default implementation does nothing. |
| 14200 | * |
| 14201 | * @param layoutDirection The resolved layout direction. |
| 14202 | * |
Fabrice Di Meglio | 49b0a9b | 2012-09-18 12:06:13 -0700 | [diff] [blame] | 14203 | * @see #LAYOUT_DIRECTION_LTR |
| 14204 | * @see #LAYOUT_DIRECTION_RTL |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14205 | * |
| 14206 | * @hide |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14207 | */ |
| 14208 | public void onResolveDrawables(int layoutDirection) { |
Fabrice Di Meglio | 6a03640 | 2011-05-23 14:43:23 -0700 | [diff] [blame] | 14209 | } |
| 14210 | |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 14211 | private void resetResolvedDrawables() { |
| 14212 | mPrivateFlags2 &= ~PFLAG2_DRAWABLE_RESOLVED; |
| 14213 | } |
| 14214 | |
| 14215 | private boolean isDrawablesResolved() { |
| 14216 | return (mPrivateFlags2 & PFLAG2_DRAWABLE_RESOLVED) == PFLAG2_DRAWABLE_RESOLVED; |
| 14217 | } |
| 14218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14219 | /** |
| 14220 | * If your view subclass is displaying its own Drawable objects, it should |
| 14221 | * override this function and return true for any Drawable it is |
| 14222 | * displaying. This allows animations for those drawables to be |
| 14223 | * scheduled. |
| 14224 | * |
| 14225 | * <p>Be sure to call through to the super class when overriding this |
| 14226 | * function. |
| 14227 | * |
| 14228 | * @param who The Drawable to verify. Return true if it is one you are |
| 14229 | * displaying, else return the result of calling through to the |
| 14230 | * super class. |
| 14231 | * |
| 14232 | * @return boolean If true than the Drawable is being displayed in the |
| 14233 | * view; else false and it is not allowed to animate. |
| 14234 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14235 | * @see #unscheduleDrawable(android.graphics.drawable.Drawable) |
| 14236 | * @see #drawableStateChanged() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14237 | */ |
| 14238 | protected boolean verifyDrawable(Drawable who) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14239 | return who == mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14240 | } |
| 14241 | |
| 14242 | /** |
| 14243 | * This function is called whenever the state of the view changes in such |
| 14244 | * a way that it impacts the state of drawables being shown. |
| 14245 | * |
| 14246 | * <p>Be sure to call through to the superclass when overriding this |
| 14247 | * function. |
| 14248 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14249 | * @see Drawable#setState(int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14250 | */ |
| 14251 | protected void drawableStateChanged() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14252 | Drawable d = mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14253 | if (d != null && d.isStateful()) { |
| 14254 | d.setState(getDrawableState()); |
| 14255 | } |
| 14256 | } |
| 14257 | |
| 14258 | /** |
| 14259 | * Call this to force a view to update its drawable state. This will cause |
| 14260 | * drawableStateChanged to be called on this view. Views that are interested |
| 14261 | * in the new state should call getDrawableState. |
| 14262 | * |
| 14263 | * @see #drawableStateChanged |
| 14264 | * @see #getDrawableState |
| 14265 | */ |
| 14266 | public void refreshDrawableState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14267 | mPrivateFlags |= PFLAG_DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14268 | drawableStateChanged(); |
| 14269 | |
| 14270 | ViewParent parent = mParent; |
| 14271 | if (parent != null) { |
| 14272 | parent.childDrawableStateChanged(this); |
| 14273 | } |
| 14274 | } |
| 14275 | |
| 14276 | /** |
| 14277 | * Return an array of resource IDs of the drawable states representing the |
| 14278 | * current state of the view. |
| 14279 | * |
| 14280 | * @return The current drawable state |
| 14281 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14282 | * @see Drawable#setState(int[]) |
| 14283 | * @see #drawableStateChanged() |
| 14284 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14285 | */ |
| 14286 | public final int[] getDrawableState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14287 | if ((mDrawableState != null) && ((mPrivateFlags & PFLAG_DRAWABLE_STATE_DIRTY) == 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14288 | return mDrawableState; |
| 14289 | } else { |
| 14290 | mDrawableState = onCreateDrawableState(0); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14291 | mPrivateFlags &= ~PFLAG_DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14292 | return mDrawableState; |
| 14293 | } |
| 14294 | } |
| 14295 | |
| 14296 | /** |
| 14297 | * Generate the new {@link android.graphics.drawable.Drawable} state for |
| 14298 | * this view. This is called by the view |
| 14299 | * system when the cached Drawable state is determined to be invalid. To |
| 14300 | * retrieve the current state, you should use {@link #getDrawableState}. |
| 14301 | * |
| 14302 | * @param extraSpace if non-zero, this is the number of extra entries you |
| 14303 | * would like in the returned array in which you can place your own |
| 14304 | * states. |
| 14305 | * |
| 14306 | * @return Returns an array holding the current {@link Drawable} state of |
| 14307 | * the view. |
| 14308 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14309 | * @see #mergeDrawableStates(int[], int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14310 | */ |
| 14311 | protected int[] onCreateDrawableState(int extraSpace) { |
| 14312 | if ((mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE && |
| 14313 | mParent instanceof View) { |
| 14314 | return ((View) mParent).onCreateDrawableState(extraSpace); |
| 14315 | } |
| 14316 | |
| 14317 | int[] drawableState; |
| 14318 | |
| 14319 | int privateFlags = mPrivateFlags; |
| 14320 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14321 | int viewStateIndex = 0; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14322 | if ((privateFlags & PFLAG_PRESSED) != 0) viewStateIndex |= VIEW_STATE_PRESSED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14323 | if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= VIEW_STATE_ENABLED; |
| 14324 | if (isFocused()) viewStateIndex |= VIEW_STATE_FOCUSED; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14325 | if ((privateFlags & PFLAG_SELECTED) != 0) viewStateIndex |= VIEW_STATE_SELECTED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14326 | if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14327 | if ((privateFlags & PFLAG_ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED; |
Adam Powell | 5a7e94e | 2011-04-25 15:30:43 -0700 | [diff] [blame] | 14328 | if (mAttachInfo != null && mAttachInfo.mHardwareAccelerationRequested && |
| 14329 | HardwareRenderer.isAvailable()) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 14330 | // This is set if HW acceleration is requested, even if the current |
| 14331 | // process doesn't allow it. This is just to allow app preview |
| 14332 | // windows to better match their app. |
| 14333 | viewStateIndex |= VIEW_STATE_ACCELERATED; |
| 14334 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14335 | if ((privateFlags & PFLAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_HOVERED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14336 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 14337 | final int privateFlags2 = mPrivateFlags2; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14338 | if ((privateFlags2 & PFLAG2_DRAG_CAN_ACCEPT) != 0) viewStateIndex |= VIEW_STATE_DRAG_CAN_ACCEPT; |
| 14339 | if ((privateFlags2 & PFLAG2_DRAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_DRAG_HOVERED; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 14340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14341 | drawableState = VIEW_STATE_SETS[viewStateIndex]; |
| 14342 | |
| 14343 | //noinspection ConstantIfStatement |
| 14344 | if (false) { |
| 14345 | Log.i("View", "drawableStateIndex=" + viewStateIndex); |
| 14346 | Log.i("View", toString() |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14347 | + " pressed=" + ((privateFlags & PFLAG_PRESSED) != 0) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14348 | + " en=" + ((mViewFlags & ENABLED_MASK) == ENABLED) |
| 14349 | + " fo=" + hasFocus() |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14350 | + " sl=" + ((privateFlags & PFLAG_SELECTED) != 0) |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14351 | + " wf=" + hasWindowFocus() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14352 | + ": " + Arrays.toString(drawableState)); |
| 14353 | } |
| 14354 | |
| 14355 | if (extraSpace == 0) { |
| 14356 | return drawableState; |
| 14357 | } |
| 14358 | |
| 14359 | final int[] fullState; |
| 14360 | if (drawableState != null) { |
| 14361 | fullState = new int[drawableState.length + extraSpace]; |
| 14362 | System.arraycopy(drawableState, 0, fullState, 0, drawableState.length); |
| 14363 | } else { |
| 14364 | fullState = new int[extraSpace]; |
| 14365 | } |
| 14366 | |
| 14367 | return fullState; |
| 14368 | } |
| 14369 | |
| 14370 | /** |
| 14371 | * Merge your own state values in <var>additionalState</var> into the base |
| 14372 | * state values <var>baseState</var> that were returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14373 | * {@link #onCreateDrawableState(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14374 | * |
| 14375 | * @param baseState The base state values returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14376 | * {@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] | 14377 | * own additional state values. |
| 14378 | * |
| 14379 | * @param additionalState The additional state values you would like |
| 14380 | * added to <var>baseState</var>; this array is not modified. |
| 14381 | * |
| 14382 | * @return As a convenience, the <var>baseState</var> array you originally |
| 14383 | * passed into the function is returned. |
| 14384 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14385 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14386 | */ |
| 14387 | protected static int[] mergeDrawableStates(int[] baseState, int[] additionalState) { |
| 14388 | final int N = baseState.length; |
| 14389 | int i = N - 1; |
| 14390 | while (i >= 0 && baseState[i] == 0) { |
| 14391 | i--; |
| 14392 | } |
| 14393 | System.arraycopy(additionalState, 0, baseState, i + 1, additionalState.length); |
| 14394 | return baseState; |
| 14395 | } |
| 14396 | |
| 14397 | /** |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 14398 | * Call {@link Drawable#jumpToCurrentState() Drawable.jumpToCurrentState()} |
| 14399 | * on all Drawable objects associated with this view. |
| 14400 | */ |
| 14401 | public void jumpDrawablesToCurrentState() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14402 | if (mBackground != null) { |
| 14403 | mBackground.jumpToCurrentState(); |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 14404 | } |
| 14405 | } |
| 14406 | |
| 14407 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14408 | * Sets the background color for this view. |
| 14409 | * @param color the color of the background |
| 14410 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 14411 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14412 | public void setBackgroundColor(int color) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14413 | if (mBackground instanceof ColorDrawable) { |
Romain Guy | 5f49c30 | 2012-09-06 16:33:31 -0700 | [diff] [blame] | 14414 | ((ColorDrawable) mBackground.mutate()).setColor(color); |
Romain Guy | 7d3082a | 2012-07-11 17:52:54 -0700 | [diff] [blame] | 14415 | computeOpaqueFlags(); |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 14416 | } else { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14417 | setBackground(new ColorDrawable(color)); |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 14418 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14419 | } |
| 14420 | |
| 14421 | /** |
| 14422 | * Set the background to a given resource. The resource should refer to |
Wink Saville | 7cd88e1 | 2009-08-04 14:45:10 -0700 | [diff] [blame] | 14423 | * a Drawable object or 0 to remove the background. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14424 | * @param resid The identifier of the resource. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14425 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14426 | * @attr ref android.R.styleable#View_background |
| 14427 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 14428 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14429 | public void setBackgroundResource(int resid) { |
| 14430 | if (resid != 0 && resid == mBackgroundResource) { |
| 14431 | return; |
| 14432 | } |
| 14433 | |
| 14434 | Drawable d= null; |
| 14435 | if (resid != 0) { |
| 14436 | d = mResources.getDrawable(resid); |
| 14437 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14438 | setBackground(d); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14439 | |
| 14440 | mBackgroundResource = resid; |
| 14441 | } |
| 14442 | |
| 14443 | /** |
| 14444 | * Set the background to a given Drawable, or remove the background. If the |
| 14445 | * background has padding, this View's padding is set to the background's |
| 14446 | * padding. However, when a background is removed, this View's padding isn't |
| 14447 | * touched. If setting the padding is desired, please use |
| 14448 | * {@link #setPadding(int, int, int, int)}. |
| 14449 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14450 | * @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] | 14451 | * background |
| 14452 | */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14453 | public void setBackground(Drawable background) { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 14454 | //noinspection deprecation |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14455 | setBackgroundDrawable(background); |
| 14456 | } |
| 14457 | |
| 14458 | /** |
| 14459 | * @deprecated use {@link #setBackground(Drawable)} instead |
| 14460 | */ |
| 14461 | @Deprecated |
| 14462 | public void setBackgroundDrawable(Drawable background) { |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 14463 | computeOpaqueFlags(); |
| 14464 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14465 | if (background == mBackground) { |
Adam Powell | 4d36ec1 | 2011-07-17 16:44:16 -0700 | [diff] [blame] | 14466 | return; |
| 14467 | } |
| 14468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14469 | boolean requestLayout = false; |
| 14470 | |
| 14471 | mBackgroundResource = 0; |
| 14472 | |
| 14473 | /* |
| 14474 | * Regardless of whether we're setting a new background or not, we want |
| 14475 | * to clear the previous drawable. |
| 14476 | */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14477 | if (mBackground != null) { |
| 14478 | mBackground.setCallback(null); |
| 14479 | unscheduleDrawable(mBackground); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14480 | } |
| 14481 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14482 | if (background != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14483 | Rect padding = sThreadLocal.get(); |
| 14484 | if (padding == null) { |
| 14485 | padding = new Rect(); |
| 14486 | sThreadLocal.set(padding); |
| 14487 | } |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 14488 | resetResolvedDrawables(); |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 14489 | background.setLayoutDirection(getLayoutDirection()); |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14490 | if (background.getPadding(padding)) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14491 | resetResolvedPadding(); |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14492 | switch (background.getLayoutDirection()) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14493 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14494 | mUserPaddingLeftInitial = padding.right; |
| 14495 | mUserPaddingRightInitial = padding.left; |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14496 | internalSetPadding(padding.right, padding.top, padding.left, padding.bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14497 | break; |
| 14498 | case LAYOUT_DIRECTION_LTR: |
| 14499 | default: |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14500 | mUserPaddingLeftInitial = padding.left; |
| 14501 | mUserPaddingRightInitial = padding.right; |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14502 | internalSetPadding(padding.left, padding.top, padding.right, padding.bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14503 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14504 | } |
| 14505 | |
| 14506 | // Compare the minimum sizes of the old Drawable and the new. If there isn't an old or |
| 14507 | // if it has a different minimum size, we should layout again |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14508 | if (mBackground == null || mBackground.getMinimumHeight() != background.getMinimumHeight() || |
| 14509 | mBackground.getMinimumWidth() != background.getMinimumWidth()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14510 | requestLayout = true; |
| 14511 | } |
| 14512 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14513 | background.setCallback(this); |
| 14514 | if (background.isStateful()) { |
| 14515 | background.setState(getDrawableState()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14516 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14517 | background.setVisible(getVisibility() == VISIBLE, false); |
| 14518 | mBackground = background; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14519 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14520 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) != 0) { |
| 14521 | mPrivateFlags &= ~PFLAG_SKIP_DRAW; |
| 14522 | mPrivateFlags |= PFLAG_ONLY_DRAWS_BACKGROUND; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14523 | requestLayout = true; |
| 14524 | } |
| 14525 | } else { |
| 14526 | /* Remove the background */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14527 | mBackground = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14528 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14529 | if ((mPrivateFlags & PFLAG_ONLY_DRAWS_BACKGROUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14530 | /* |
| 14531 | * This view ONLY drew the background before and we're removing |
| 14532 | * the background, so now it won't draw anything |
| 14533 | * (hence we SKIP_DRAW) |
| 14534 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14535 | mPrivateFlags &= ~PFLAG_ONLY_DRAWS_BACKGROUND; |
| 14536 | mPrivateFlags |= PFLAG_SKIP_DRAW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14537 | } |
| 14538 | |
| 14539 | /* |
| 14540 | * When the background is set, we try to apply its padding to this |
| 14541 | * View. When the background is removed, we don't touch this View's |
| 14542 | * padding. This is noted in the Javadocs. Hence, we don't need to |
| 14543 | * requestLayout(), the invalidate() below is sufficient. |
| 14544 | */ |
| 14545 | |
| 14546 | // The old background's minimum size could have affected this |
| 14547 | // View's layout, so let's requestLayout |
| 14548 | requestLayout = true; |
| 14549 | } |
| 14550 | |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 14551 | computeOpaqueFlags(); |
| 14552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14553 | if (requestLayout) { |
| 14554 | requestLayout(); |
| 14555 | } |
| 14556 | |
| 14557 | mBackgroundSizeChanged = true; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14558 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14559 | } |
| 14560 | |
| 14561 | /** |
| 14562 | * Gets the background drawable |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14563 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14564 | * @return The drawable used as the background for this view, if any. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14565 | * |
| 14566 | * @see #setBackground(Drawable) |
| 14567 | * |
| 14568 | * @attr ref android.R.styleable#View_background |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14569 | */ |
| 14570 | public Drawable getBackground() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14571 | return mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14572 | } |
| 14573 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14574 | /** |
| 14575 | * Sets the padding. The view may add on the space required to display |
| 14576 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 14577 | * So the values returned from {@link #getPaddingLeft}, {@link #getPaddingTop}, |
| 14578 | * {@link #getPaddingRight} and {@link #getPaddingBottom} may be different |
| 14579 | * from the values set in this call. |
| 14580 | * |
| 14581 | * @attr ref android.R.styleable#View_padding |
| 14582 | * @attr ref android.R.styleable#View_paddingBottom |
| 14583 | * @attr ref android.R.styleable#View_paddingLeft |
| 14584 | * @attr ref android.R.styleable#View_paddingRight |
| 14585 | * @attr ref android.R.styleable#View_paddingTop |
| 14586 | * @param left the left padding in pixels |
| 14587 | * @param top the top padding in pixels |
| 14588 | * @param right the right padding in pixels |
| 14589 | * @param bottom the bottom padding in pixels |
| 14590 | */ |
| 14591 | public void setPadding(int left, int top, int right, int bottom) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14592 | resetResolvedPadding(); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14593 | |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14594 | mUserPaddingStart = UNDEFINED_PADDING; |
| 14595 | mUserPaddingEnd = UNDEFINED_PADDING; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14596 | |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14597 | mUserPaddingLeftInitial = left; |
| 14598 | mUserPaddingRightInitial = right; |
| 14599 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14600 | internalSetPadding(left, top, right, bottom); |
| 14601 | } |
| 14602 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14603 | /** |
| 14604 | * @hide |
| 14605 | */ |
| 14606 | protected void internalSetPadding(int left, int top, int right, int bottom) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14607 | mUserPaddingLeft = left; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14608 | mUserPaddingRight = right; |
| 14609 | mUserPaddingBottom = bottom; |
| 14610 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14611 | final int viewFlags = mViewFlags; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14612 | boolean changed = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14613 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14614 | // Common case is there are no scroll bars. |
| 14615 | if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14616 | if ((viewFlags & SCROLLBARS_VERTICAL) != 0) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14617 | final int offset = (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14618 | ? 0 : getVerticalScrollbarWidth(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14619 | switch (mVerticalScrollbarPosition) { |
| 14620 | case SCROLLBAR_POSITION_DEFAULT: |
Fabrice Di Meglio | c91b6ca | 2012-06-22 14:51:15 -0700 | [diff] [blame] | 14621 | if (isLayoutRtl()) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14622 | left += offset; |
| 14623 | } else { |
| 14624 | right += offset; |
| 14625 | } |
| 14626 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14627 | case SCROLLBAR_POSITION_RIGHT: |
| 14628 | right += offset; |
| 14629 | break; |
| 14630 | case SCROLLBAR_POSITION_LEFT: |
| 14631 | left += offset; |
| 14632 | break; |
| 14633 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14634 | } |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14635 | if ((viewFlags & SCROLLBARS_HORIZONTAL) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14636 | bottom += (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
| 14637 | ? 0 : getHorizontalScrollbarHeight(); |
| 14638 | } |
| 14639 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14640 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14641 | if (mPaddingLeft != left) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14642 | changed = true; |
| 14643 | mPaddingLeft = left; |
| 14644 | } |
| 14645 | if (mPaddingTop != top) { |
| 14646 | changed = true; |
| 14647 | mPaddingTop = top; |
| 14648 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14649 | if (mPaddingRight != right) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14650 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14651 | mPaddingRight = right; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14652 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14653 | if (mPaddingBottom != bottom) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14654 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14655 | mPaddingBottom = bottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14656 | } |
| 14657 | |
| 14658 | if (changed) { |
| 14659 | requestLayout(); |
| 14660 | } |
| 14661 | } |
| 14662 | |
| 14663 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14664 | * Sets the relative padding. The view may add on the space required to display |
| 14665 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 14666 | * So the values returned from {@link #getPaddingStart}, {@link #getPaddingTop}, |
| 14667 | * {@link #getPaddingEnd} and {@link #getPaddingBottom} may be different |
| 14668 | * from the values set in this call. |
| 14669 | * |
| 14670 | * @attr ref android.R.styleable#View_padding |
| 14671 | * @attr ref android.R.styleable#View_paddingBottom |
| 14672 | * @attr ref android.R.styleable#View_paddingStart |
| 14673 | * @attr ref android.R.styleable#View_paddingEnd |
| 14674 | * @attr ref android.R.styleable#View_paddingTop |
| 14675 | * @param start the start padding in pixels |
| 14676 | * @param top the top padding in pixels |
| 14677 | * @param end the end padding in pixels |
| 14678 | * @param bottom the bottom padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14679 | */ |
| 14680 | public void setPaddingRelative(int start, int top, int end, int bottom) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14681 | resetResolvedPadding(); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14682 | |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 14683 | mUserPaddingStart = start; |
| 14684 | mUserPaddingEnd = end; |
| 14685 | |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 14686 | switch(getLayoutDirection()) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14687 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14688 | mUserPaddingLeftInitial = end; |
| 14689 | mUserPaddingRightInitial = start; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14690 | internalSetPadding(end, top, start, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14691 | break; |
| 14692 | case LAYOUT_DIRECTION_LTR: |
| 14693 | default: |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14694 | mUserPaddingLeftInitial = start; |
| 14695 | mUserPaddingRightInitial = end; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14696 | internalSetPadding(start, top, end, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14697 | } |
| 14698 | } |
| 14699 | |
| 14700 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14701 | * Returns the top padding of this view. |
| 14702 | * |
| 14703 | * @return the top padding in pixels |
| 14704 | */ |
| 14705 | public int getPaddingTop() { |
| 14706 | return mPaddingTop; |
| 14707 | } |
| 14708 | |
| 14709 | /** |
| 14710 | * Returns the bottom padding of this view. If there are inset and enabled |
| 14711 | * scrollbars, this value may include the space required to display the |
| 14712 | * scrollbars as well. |
| 14713 | * |
| 14714 | * @return the bottom padding in pixels |
| 14715 | */ |
| 14716 | public int getPaddingBottom() { |
| 14717 | return mPaddingBottom; |
| 14718 | } |
| 14719 | |
| 14720 | /** |
| 14721 | * Returns the left padding of this view. If there are inset and enabled |
| 14722 | * scrollbars, this value may include the space required to display the |
| 14723 | * scrollbars as well. |
| 14724 | * |
| 14725 | * @return the left padding in pixels |
| 14726 | */ |
| 14727 | public int getPaddingLeft() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14728 | if (!isPaddingResolved()) { |
| 14729 | resolvePadding(); |
| 14730 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14731 | return mPaddingLeft; |
| 14732 | } |
| 14733 | |
| 14734 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 14735 | * Returns the start padding of this view depending on its resolved layout direction. |
| 14736 | * If there are inset and enabled scrollbars, this value may include the space |
| 14737 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14738 | * |
| 14739 | * @return the start padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14740 | */ |
| 14741 | public int getPaddingStart() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14742 | if (!isPaddingResolved()) { |
| 14743 | resolvePadding(); |
| 14744 | } |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 14745 | return (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14746 | mPaddingRight : mPaddingLeft; |
| 14747 | } |
| 14748 | |
| 14749 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14750 | * Returns the right padding of this view. If there are inset and enabled |
| 14751 | * scrollbars, this value may include the space required to display the |
| 14752 | * scrollbars as well. |
| 14753 | * |
| 14754 | * @return the right padding in pixels |
| 14755 | */ |
| 14756 | public int getPaddingRight() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14757 | if (!isPaddingResolved()) { |
| 14758 | resolvePadding(); |
| 14759 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14760 | return mPaddingRight; |
| 14761 | } |
| 14762 | |
| 14763 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 14764 | * Returns the end padding of this view depending on its resolved layout direction. |
| 14765 | * If there are inset and enabled scrollbars, this value may include the space |
| 14766 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14767 | * |
| 14768 | * @return the end padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14769 | */ |
| 14770 | public int getPaddingEnd() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14771 | if (!isPaddingResolved()) { |
| 14772 | resolvePadding(); |
| 14773 | } |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 14774 | return (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14775 | mPaddingLeft : mPaddingRight; |
| 14776 | } |
| 14777 | |
| 14778 | /** |
| 14779 | * Return if the padding as been set thru relative values |
| 14780 | * {@link #setPaddingRelative(int, int, int, int)} or thru |
| 14781 | * @attr ref android.R.styleable#View_paddingStart or |
| 14782 | * @attr ref android.R.styleable#View_paddingEnd |
| 14783 | * |
| 14784 | * @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] | 14785 | */ |
| 14786 | public boolean isPaddingRelative() { |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14787 | return (mUserPaddingStart != UNDEFINED_PADDING || mUserPaddingEnd != UNDEFINED_PADDING); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14788 | } |
| 14789 | |
| 14790 | /** |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 14791 | * @hide |
| 14792 | */ |
Fabrice Di Meglio | 47fb191 | 2012-09-28 19:50:18 -0700 | [diff] [blame] | 14793 | public void resetPaddingToInitialValues() { |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 14794 | if (isRtlCompatibilityMode()) { |
| 14795 | mPaddingLeft = mUserPaddingLeftInitial; |
| 14796 | mPaddingRight = mUserPaddingRightInitial; |
| 14797 | } else { |
| 14798 | if (isLayoutRtl()) { |
| 14799 | mPaddingLeft = mUserPaddingRightInitial; |
| 14800 | mPaddingRight = mUserPaddingLeftInitial; |
| 14801 | } else { |
| 14802 | mPaddingLeft = mUserPaddingLeftInitial; |
| 14803 | mPaddingRight = mUserPaddingRightInitial; |
| 14804 | } |
| 14805 | } |
Fabrice Di Meglio | 47fb191 | 2012-09-28 19:50:18 -0700 | [diff] [blame] | 14806 | } |
| 14807 | |
| 14808 | /** |
| 14809 | * @hide |
| 14810 | */ |
Philip Milne | 7a23b49 | 2012-04-24 22:12:36 -0700 | [diff] [blame] | 14811 | public Insets getOpticalInsets() { |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 14812 | if (mLayoutInsets == null) { |
Philip Milne | bbd51f1 | 2012-04-18 15:09:05 -0700 | [diff] [blame] | 14813 | mLayoutInsets = (mBackground == null) ? Insets.NONE : mBackground.getLayoutInsets(); |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 14814 | } |
| 14815 | return mLayoutInsets; |
| 14816 | } |
| 14817 | |
| 14818 | /** |
| 14819 | * @hide |
| 14820 | */ |
| 14821 | public void setLayoutInsets(Insets layoutInsets) { |
| 14822 | mLayoutInsets = layoutInsets; |
| 14823 | } |
| 14824 | |
| 14825 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14826 | * Changes the selection state of this view. A view can be selected or not. |
| 14827 | * Note that selection is not the same as focus. Views are typically |
| 14828 | * selected in the context of an AdapterView like ListView or GridView; |
| 14829 | * the selected view is the view that is highlighted. |
| 14830 | * |
| 14831 | * @param selected true if the view must be selected, false otherwise |
| 14832 | */ |
| 14833 | public void setSelected(boolean selected) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14834 | if (((mPrivateFlags & PFLAG_SELECTED) != 0) != selected) { |
| 14835 | mPrivateFlags = (mPrivateFlags & ~PFLAG_SELECTED) | (selected ? PFLAG_SELECTED : 0); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 14836 | if (!selected) resetPressedState(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14837 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14838 | refreshDrawableState(); |
| 14839 | dispatchSetSelected(selected); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 14840 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 14841 | notifyAccessibilityStateChanged(); |
| 14842 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14843 | } |
| 14844 | } |
| 14845 | |
| 14846 | /** |
| 14847 | * Dispatch setSelected to all of this View's children. |
| 14848 | * |
| 14849 | * @see #setSelected(boolean) |
| 14850 | * |
| 14851 | * @param selected The new selected state |
| 14852 | */ |
| 14853 | protected void dispatchSetSelected(boolean selected) { |
| 14854 | } |
| 14855 | |
| 14856 | /** |
| 14857 | * Indicates the selection state of this view. |
| 14858 | * |
| 14859 | * @return true if the view is selected, false otherwise |
| 14860 | */ |
| 14861 | @ViewDebug.ExportedProperty |
| 14862 | public boolean isSelected() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14863 | return (mPrivateFlags & PFLAG_SELECTED) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14864 | } |
| 14865 | |
| 14866 | /** |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14867 | * Changes the activated state of this view. A view can be activated or not. |
| 14868 | * Note that activation is not the same as selection. Selection is |
| 14869 | * a transient property, representing the view (hierarchy) the user is |
| 14870 | * currently interacting with. Activation is a longer-term state that the |
| 14871 | * user can move views in and out of. For example, in a list view with |
| 14872 | * single or multiple selection enabled, the views in the current selection |
| 14873 | * set are activated. (Um, yeah, we are deeply sorry about the terminology |
| 14874 | * here.) The activated state is propagated down to children of the view it |
| 14875 | * is set on. |
| 14876 | * |
| 14877 | * @param activated true if the view must be activated, false otherwise |
| 14878 | */ |
| 14879 | public void setActivated(boolean activated) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14880 | if (((mPrivateFlags & PFLAG_ACTIVATED) != 0) != activated) { |
| 14881 | mPrivateFlags = (mPrivateFlags & ~PFLAG_ACTIVATED) | (activated ? PFLAG_ACTIVATED : 0); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14882 | invalidate(true); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14883 | refreshDrawableState(); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 14884 | dispatchSetActivated(activated); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14885 | } |
| 14886 | } |
| 14887 | |
| 14888 | /** |
| 14889 | * Dispatch setActivated to all of this View's children. |
| 14890 | * |
| 14891 | * @see #setActivated(boolean) |
| 14892 | * |
| 14893 | * @param activated The new activated state |
| 14894 | */ |
| 14895 | protected void dispatchSetActivated(boolean activated) { |
| 14896 | } |
| 14897 | |
| 14898 | /** |
| 14899 | * Indicates the activation state of this view. |
| 14900 | * |
| 14901 | * @return true if the view is activated, false otherwise |
| 14902 | */ |
| 14903 | @ViewDebug.ExportedProperty |
| 14904 | public boolean isActivated() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14905 | return (mPrivateFlags & PFLAG_ACTIVATED) != 0; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14906 | } |
| 14907 | |
| 14908 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14909 | * Returns the ViewTreeObserver for this view's hierarchy. The view tree |
| 14910 | * observer can be used to get notifications when global events, like |
| 14911 | * layout, happen. |
| 14912 | * |
| 14913 | * The returned ViewTreeObserver observer is not guaranteed to remain |
| 14914 | * valid for the lifetime of this View. If the caller of this method keeps |
| 14915 | * a long-lived reference to ViewTreeObserver, it should always check for |
| 14916 | * the return value of {@link ViewTreeObserver#isAlive()}. |
| 14917 | * |
| 14918 | * @return The ViewTreeObserver for this view's hierarchy. |
| 14919 | */ |
| 14920 | public ViewTreeObserver getViewTreeObserver() { |
| 14921 | if (mAttachInfo != null) { |
| 14922 | return mAttachInfo.mTreeObserver; |
| 14923 | } |
| 14924 | if (mFloatingTreeObserver == null) { |
| 14925 | mFloatingTreeObserver = new ViewTreeObserver(); |
| 14926 | } |
| 14927 | return mFloatingTreeObserver; |
| 14928 | } |
| 14929 | |
| 14930 | /** |
| 14931 | * <p>Finds the topmost view in the current view hierarchy.</p> |
| 14932 | * |
| 14933 | * @return the topmost view containing this view |
| 14934 | */ |
| 14935 | public View getRootView() { |
| 14936 | if (mAttachInfo != null) { |
| 14937 | final View v = mAttachInfo.mRootView; |
| 14938 | if (v != null) { |
| 14939 | return v; |
| 14940 | } |
| 14941 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14942 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14943 | View parent = this; |
| 14944 | |
| 14945 | while (parent.mParent != null && parent.mParent instanceof View) { |
| 14946 | parent = (View) parent.mParent; |
| 14947 | } |
| 14948 | |
| 14949 | return parent; |
| 14950 | } |
| 14951 | |
| 14952 | /** |
| 14953 | * <p>Computes the coordinates of this view on the screen. The argument |
| 14954 | * must be an array of two integers. After the method returns, the array |
| 14955 | * contains the x and y location in that order.</p> |
| 14956 | * |
| 14957 | * @param location an array of two integers in which to hold the coordinates |
| 14958 | */ |
| 14959 | public void getLocationOnScreen(int[] location) { |
| 14960 | getLocationInWindow(location); |
| 14961 | |
| 14962 | final AttachInfo info = mAttachInfo; |
Romain Guy | 779398e | 2009-06-16 13:17:50 -0700 | [diff] [blame] | 14963 | if (info != null) { |
| 14964 | location[0] += info.mWindowLeft; |
| 14965 | location[1] += info.mWindowTop; |
| 14966 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14967 | } |
| 14968 | |
| 14969 | /** |
| 14970 | * <p>Computes the coordinates of this view in its window. The argument |
| 14971 | * must be an array of two integers. After the method returns, the array |
| 14972 | * contains the x and y location in that order.</p> |
| 14973 | * |
| 14974 | * @param location an array of two integers in which to hold the coordinates |
| 14975 | */ |
| 14976 | public void getLocationInWindow(int[] location) { |
| 14977 | if (location == null || location.length < 2) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14978 | 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] | 14979 | } |
| 14980 | |
Gilles Debunne | 6583ce5 | 2011-12-06 18:09:02 -0800 | [diff] [blame] | 14981 | if (mAttachInfo == null) { |
| 14982 | // When the view is not attached to a window, this method does not make sense |
| 14983 | location[0] = location[1] = 0; |
| 14984 | return; |
| 14985 | } |
| 14986 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14987 | float[] position = mAttachInfo.mTmpTransformLocation; |
| 14988 | position[0] = position[1] = 0.0f; |
| 14989 | |
| 14990 | if (!hasIdentityMatrix()) { |
| 14991 | getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 14992 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14993 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14994 | position[0] += mLeft; |
| 14995 | position[1] += mTop; |
| 14996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14997 | ViewParent viewParent = mParent; |
| 14998 | while (viewParent instanceof View) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14999 | final View view = (View) viewParent; |
| 15000 | |
| 15001 | position[0] -= view.mScrollX; |
| 15002 | position[1] -= view.mScrollY; |
| 15003 | |
| 15004 | if (!view.hasIdentityMatrix()) { |
| 15005 | view.getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 15006 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15007 | |
| 15008 | position[0] += view.mLeft; |
| 15009 | position[1] += view.mTop; |
| 15010 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15011 | viewParent = view.mParent; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 15012 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15013 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 15014 | if (viewParent instanceof ViewRootImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15015 | // *cough* |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15016 | final ViewRootImpl vr = (ViewRootImpl) viewParent; |
| 15017 | position[1] -= vr.mCurScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15018 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15019 | |
| 15020 | location[0] = (int) (position[0] + 0.5f); |
| 15021 | location[1] = (int) (position[1] + 0.5f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15022 | } |
| 15023 | |
| 15024 | /** |
| 15025 | * {@hide} |
| 15026 | * @param id the id of the view to be found |
| 15027 | * @return the view of the specified id, null if cannot be found |
| 15028 | */ |
| 15029 | protected View findViewTraversal(int id) { |
| 15030 | if (id == mID) { |
| 15031 | return this; |
| 15032 | } |
| 15033 | return null; |
| 15034 | } |
| 15035 | |
| 15036 | /** |
| 15037 | * {@hide} |
| 15038 | * @param tag the tag of the view to be found |
| 15039 | * @return the view of specified tag, null if cannot be found |
| 15040 | */ |
| 15041 | protected View findViewWithTagTraversal(Object tag) { |
| 15042 | if (tag != null && tag.equals(mTag)) { |
| 15043 | return this; |
| 15044 | } |
| 15045 | return null; |
| 15046 | } |
| 15047 | |
| 15048 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15049 | * {@hide} |
| 15050 | * @param predicate The predicate to evaluate. |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 15051 | * @param childToSkip If not null, ignores this child during the recursive traversal. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15052 | * @return The first view that matches the predicate or null. |
| 15053 | */ |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 15054 | protected View findViewByPredicateTraversal(Predicate<View> predicate, View childToSkip) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15055 | if (predicate.apply(this)) { |
| 15056 | return this; |
| 15057 | } |
| 15058 | return null; |
| 15059 | } |
| 15060 | |
| 15061 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15062 | * Look for a child view with the given id. If this view has the given |
| 15063 | * id, return this view. |
| 15064 | * |
| 15065 | * @param id The id to search for. |
| 15066 | * @return The view that has the given id in the hierarchy or null |
| 15067 | */ |
| 15068 | public final View findViewById(int id) { |
| 15069 | if (id < 0) { |
| 15070 | return null; |
| 15071 | } |
| 15072 | return findViewTraversal(id); |
| 15073 | } |
| 15074 | |
| 15075 | /** |
Svetoslav Ganov | 2cdedff | 2011-10-03 14:18:42 -0700 | [diff] [blame] | 15076 | * Finds a view by its unuque and stable accessibility id. |
| 15077 | * |
| 15078 | * @param accessibilityId The searched accessibility id. |
| 15079 | * @return The found view. |
| 15080 | */ |
| 15081 | final View findViewByAccessibilityId(int accessibilityId) { |
| 15082 | if (accessibilityId < 0) { |
| 15083 | return null; |
| 15084 | } |
| 15085 | return findViewByAccessibilityIdTraversal(accessibilityId); |
| 15086 | } |
| 15087 | |
| 15088 | /** |
| 15089 | * Performs the traversal to find a view by its unuque and stable accessibility id. |
| 15090 | * |
| 15091 | * <strong>Note:</strong>This method does not stop at the root namespace |
| 15092 | * boundary since the user can touch the screen at an arbitrary location |
| 15093 | * potentially crossing the root namespace bounday which will send an |
| 15094 | * accessibility event to accessibility services and they should be able |
| 15095 | * to obtain the event source. Also accessibility ids are guaranteed to be |
| 15096 | * unique in the window. |
| 15097 | * |
| 15098 | * @param accessibilityId The accessibility id. |
| 15099 | * @return The found view. |
| 15100 | */ |
| 15101 | View findViewByAccessibilityIdTraversal(int accessibilityId) { |
| 15102 | if (getAccessibilityViewId() == accessibilityId) { |
| 15103 | return this; |
| 15104 | } |
| 15105 | return null; |
| 15106 | } |
| 15107 | |
| 15108 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15109 | * Look for a child view with the given tag. If this view has the given |
| 15110 | * tag, return this view. |
| 15111 | * |
| 15112 | * @param tag The tag to search for, using "tag.equals(getTag())". |
| 15113 | * @return The View that has the given tag in the hierarchy or null |
| 15114 | */ |
| 15115 | public final View findViewWithTag(Object tag) { |
| 15116 | if (tag == null) { |
| 15117 | return null; |
| 15118 | } |
| 15119 | return findViewWithTagTraversal(tag); |
| 15120 | } |
| 15121 | |
| 15122 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15123 | * {@hide} |
| 15124 | * Look for a child view that matches the specified predicate. |
| 15125 | * If this view matches the predicate, return this view. |
| 15126 | * |
| 15127 | * @param predicate The predicate to evaluate. |
| 15128 | * @return The first view that matches the predicate or null. |
| 15129 | */ |
| 15130 | public final View findViewByPredicate(Predicate<View> predicate) { |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 15131 | return findViewByPredicateTraversal(predicate, null); |
| 15132 | } |
| 15133 | |
| 15134 | /** |
| 15135 | * {@hide} |
| 15136 | * Look for a child view that matches the specified predicate, |
| 15137 | * starting with the specified view and its descendents and then |
| 15138 | * recusively searching the ancestors and siblings of that view |
| 15139 | * until this view is reached. |
| 15140 | * |
| 15141 | * This method is useful in cases where the predicate does not match |
| 15142 | * a single unique view (perhaps multiple views use the same id) |
| 15143 | * and we are trying to find the view that is "closest" in scope to the |
| 15144 | * starting view. |
| 15145 | * |
| 15146 | * @param start The view to start from. |
| 15147 | * @param predicate The predicate to evaluate. |
| 15148 | * @return The first view that matches the predicate or null. |
| 15149 | */ |
| 15150 | public final View findViewByPredicateInsideOut(View start, Predicate<View> predicate) { |
| 15151 | View childToSkip = null; |
| 15152 | for (;;) { |
| 15153 | View view = start.findViewByPredicateTraversal(predicate, childToSkip); |
| 15154 | if (view != null || start == this) { |
| 15155 | return view; |
| 15156 | } |
| 15157 | |
| 15158 | ViewParent parent = start.getParent(); |
| 15159 | if (parent == null || !(parent instanceof View)) { |
| 15160 | return null; |
| 15161 | } |
| 15162 | |
| 15163 | childToSkip = start; |
| 15164 | start = (View) parent; |
| 15165 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15166 | } |
| 15167 | |
| 15168 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15169 | * Sets the identifier for this view. The identifier does not have to be |
| 15170 | * unique in this view's hierarchy. The identifier should be a positive |
| 15171 | * number. |
| 15172 | * |
| 15173 | * @see #NO_ID |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15174 | * @see #getId() |
| 15175 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15176 | * |
| 15177 | * @param id a number used to identify the view |
| 15178 | * |
| 15179 | * @attr ref android.R.styleable#View_id |
| 15180 | */ |
| 15181 | public void setId(int id) { |
| 15182 | mID = id; |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 15183 | if (mID == View.NO_ID && mLabelForId != View.NO_ID) { |
| 15184 | mID = generateViewId(); |
| 15185 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15186 | } |
| 15187 | |
| 15188 | /** |
| 15189 | * {@hide} |
| 15190 | * |
| 15191 | * @param isRoot true if the view belongs to the root namespace, false |
| 15192 | * otherwise |
| 15193 | */ |
| 15194 | public void setIsRootNamespace(boolean isRoot) { |
| 15195 | if (isRoot) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15196 | mPrivateFlags |= PFLAG_IS_ROOT_NAMESPACE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15197 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15198 | mPrivateFlags &= ~PFLAG_IS_ROOT_NAMESPACE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15199 | } |
| 15200 | } |
| 15201 | |
| 15202 | /** |
| 15203 | * {@hide} |
| 15204 | * |
| 15205 | * @return true if the view belongs to the root namespace, false otherwise |
| 15206 | */ |
| 15207 | public boolean isRootNamespace() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15208 | return (mPrivateFlags&PFLAG_IS_ROOT_NAMESPACE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15209 | } |
| 15210 | |
| 15211 | /** |
| 15212 | * Returns this view's identifier. |
| 15213 | * |
| 15214 | * @return a positive integer used to identify the view or {@link #NO_ID} |
| 15215 | * if the view has no ID |
| 15216 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15217 | * @see #setId(int) |
| 15218 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15219 | * @attr ref android.R.styleable#View_id |
| 15220 | */ |
| 15221 | @ViewDebug.CapturedViewProperty |
| 15222 | public int getId() { |
| 15223 | return mID; |
| 15224 | } |
| 15225 | |
| 15226 | /** |
| 15227 | * Returns this view's tag. |
| 15228 | * |
| 15229 | * @return the Object stored in this view as a tag |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15230 | * |
| 15231 | * @see #setTag(Object) |
| 15232 | * @see #getTag(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15233 | */ |
| 15234 | @ViewDebug.ExportedProperty |
| 15235 | public Object getTag() { |
| 15236 | return mTag; |
| 15237 | } |
| 15238 | |
| 15239 | /** |
| 15240 | * Sets the tag associated with this view. A tag can be used to mark |
| 15241 | * a view in its hierarchy and does not have to be unique within the |
| 15242 | * hierarchy. Tags can also be used to store data within a view without |
| 15243 | * resorting to another data structure. |
| 15244 | * |
| 15245 | * @param tag an Object to tag the view with |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15246 | * |
| 15247 | * @see #getTag() |
| 15248 | * @see #setTag(int, Object) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15249 | */ |
| 15250 | public void setTag(final Object tag) { |
| 15251 | mTag = tag; |
| 15252 | } |
| 15253 | |
| 15254 | /** |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15255 | * Returns the tag associated with this view and the specified key. |
| 15256 | * |
| 15257 | * @param key The key identifying the tag |
| 15258 | * |
| 15259 | * @return the Object stored in this view as a tag |
| 15260 | * |
| 15261 | * @see #setTag(int, Object) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15262 | * @see #getTag() |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15263 | */ |
| 15264 | public Object getTag(int key) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 15265 | if (mKeyedTags != null) return mKeyedTags.get(key); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15266 | return null; |
| 15267 | } |
| 15268 | |
| 15269 | /** |
| 15270 | * Sets a tag associated with this view and a key. A tag can be used |
| 15271 | * to mark a view in its hierarchy and does not have to be unique within |
| 15272 | * the hierarchy. Tags can also be used to store data within a view |
| 15273 | * without resorting to another data structure. |
| 15274 | * |
| 15275 | * 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] | 15276 | * application to ensure it is unique (see the <a |
| 15277 | * href={@docRoot}guide/topics/resources/more-resources.html#Id">ID resource type</a>). |
| 15278 | * Keys identified as belonging to |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15279 | * the Android framework or not associated with any package will cause |
| 15280 | * an {@link IllegalArgumentException} to be thrown. |
| 15281 | * |
| 15282 | * @param key The key identifying the tag |
| 15283 | * @param tag An Object to tag the view with |
| 15284 | * |
| 15285 | * @throws IllegalArgumentException If they specified key is not valid |
| 15286 | * |
| 15287 | * @see #setTag(Object) |
| 15288 | * @see #getTag(int) |
| 15289 | */ |
| 15290 | public void setTag(int key, final Object tag) { |
| 15291 | // If the package id is 0x00 or 0x01, it's either an undefined package |
| 15292 | // or a framework id |
| 15293 | if ((key >>> 24) < 2) { |
| 15294 | throw new IllegalArgumentException("The key must be an application-specific " |
| 15295 | + "resource id."); |
| 15296 | } |
| 15297 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 15298 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15299 | } |
| 15300 | |
| 15301 | /** |
| 15302 | * Variation of {@link #setTag(int, Object)} that enforces the key to be a |
| 15303 | * framework id. |
| 15304 | * |
| 15305 | * @hide |
| 15306 | */ |
| 15307 | public void setTagInternal(int key, Object tag) { |
| 15308 | if ((key >>> 24) != 0x1) { |
| 15309 | throw new IllegalArgumentException("The key must be a framework-specific " |
| 15310 | + "resource id."); |
| 15311 | } |
| 15312 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 15313 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15314 | } |
| 15315 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 15316 | private void setKeyedTag(int key, Object tag) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 15317 | if (mKeyedTags == null) { |
| 15318 | mKeyedTags = new SparseArray<Object>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15319 | } |
| 15320 | |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 15321 | mKeyedTags.put(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15322 | } |
| 15323 | |
| 15324 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15325 | * Prints information about this view in the log output, with the tag |
| 15326 | * {@link #VIEW_LOG_TAG}. |
| 15327 | * |
| 15328 | * @hide |
| 15329 | */ |
| 15330 | public void debug() { |
| 15331 | debug(0); |
| 15332 | } |
| 15333 | |
| 15334 | /** |
| 15335 | * Prints information about this view in the log output, with the tag |
| 15336 | * {@link #VIEW_LOG_TAG}. Each line in the output is preceded with an |
| 15337 | * indentation defined by the <code>depth</code>. |
| 15338 | * |
| 15339 | * @param depth the indentation level |
| 15340 | * |
| 15341 | * @hide |
| 15342 | */ |
| 15343 | protected void debug(int depth) { |
| 15344 | String output = debugIndent(depth - 1); |
| 15345 | |
| 15346 | output += "+ " + this; |
| 15347 | int id = getId(); |
| 15348 | if (id != -1) { |
| 15349 | output += " (id=" + id + ")"; |
| 15350 | } |
| 15351 | Object tag = getTag(); |
| 15352 | if (tag != null) { |
| 15353 | output += " (tag=" + tag + ")"; |
| 15354 | } |
| 15355 | Log.d(VIEW_LOG_TAG, output); |
| 15356 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15357 | if ((mPrivateFlags & PFLAG_FOCUSED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15358 | output = debugIndent(depth) + " FOCUSED"; |
| 15359 | Log.d(VIEW_LOG_TAG, output); |
| 15360 | } |
| 15361 | |
| 15362 | output = debugIndent(depth); |
| 15363 | output += "frame={" + mLeft + ", " + mTop + ", " + mRight |
| 15364 | + ", " + mBottom + "} scroll={" + mScrollX + ", " + mScrollY |
| 15365 | + "} "; |
| 15366 | Log.d(VIEW_LOG_TAG, output); |
| 15367 | |
| 15368 | if (mPaddingLeft != 0 || mPaddingTop != 0 || mPaddingRight != 0 |
| 15369 | || mPaddingBottom != 0) { |
| 15370 | output = debugIndent(depth); |
| 15371 | output += "padding={" + mPaddingLeft + ", " + mPaddingTop |
| 15372 | + ", " + mPaddingRight + ", " + mPaddingBottom + "}"; |
| 15373 | Log.d(VIEW_LOG_TAG, output); |
| 15374 | } |
| 15375 | |
| 15376 | output = debugIndent(depth); |
| 15377 | output += "mMeasureWidth=" + mMeasuredWidth + |
| 15378 | " mMeasureHeight=" + mMeasuredHeight; |
| 15379 | Log.d(VIEW_LOG_TAG, output); |
| 15380 | |
| 15381 | output = debugIndent(depth); |
| 15382 | if (mLayoutParams == null) { |
| 15383 | output += "BAD! no layout params"; |
| 15384 | } else { |
| 15385 | output = mLayoutParams.debug(output); |
| 15386 | } |
| 15387 | Log.d(VIEW_LOG_TAG, output); |
| 15388 | |
| 15389 | output = debugIndent(depth); |
| 15390 | output += "flags={"; |
| 15391 | output += View.printFlags(mViewFlags); |
| 15392 | output += "}"; |
| 15393 | Log.d(VIEW_LOG_TAG, output); |
| 15394 | |
| 15395 | output = debugIndent(depth); |
| 15396 | output += "privateFlags={"; |
| 15397 | output += View.printPrivateFlags(mPrivateFlags); |
| 15398 | output += "}"; |
| 15399 | Log.d(VIEW_LOG_TAG, output); |
| 15400 | } |
| 15401 | |
| 15402 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 15403 | * Creates a string of whitespaces used for indentation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15404 | * |
| 15405 | * @param depth the indentation level |
| 15406 | * @return a String containing (depth * 2 + 3) * 2 white spaces |
| 15407 | * |
| 15408 | * @hide |
| 15409 | */ |
| 15410 | protected static String debugIndent(int depth) { |
| 15411 | StringBuilder spaces = new StringBuilder((depth * 2 + 3) * 2); |
| 15412 | for (int i = 0; i < (depth * 2) + 3; i++) { |
| 15413 | spaces.append(' ').append(' '); |
| 15414 | } |
| 15415 | return spaces.toString(); |
| 15416 | } |
| 15417 | |
| 15418 | /** |
| 15419 | * <p>Return the offset of the widget's text baseline from the widget's top |
| 15420 | * boundary. If this widget does not support baseline alignment, this |
| 15421 | * method returns -1. </p> |
| 15422 | * |
| 15423 | * @return the offset of the baseline within the widget's bounds or -1 |
| 15424 | * if baseline alignment is not supported |
| 15425 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 15426 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15427 | public int getBaseline() { |
| 15428 | return -1; |
| 15429 | } |
| 15430 | |
| 15431 | /** |
| 15432 | * Call this when something has changed which has invalidated the |
| 15433 | * layout of this view. This will schedule a layout pass of the view |
| 15434 | * tree. |
| 15435 | */ |
| 15436 | public void requestLayout() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15437 | mPrivateFlags |= PFLAG_FORCE_LAYOUT; |
| 15438 | mPrivateFlags |= PFLAG_INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15439 | |
Fabrice Di Meglio | 4a526885 | 2012-03-30 15:56:48 -0700 | [diff] [blame] | 15440 | if (mParent != null && !mParent.isLayoutRequested()) { |
| 15441 | mParent.requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15442 | } |
| 15443 | } |
| 15444 | |
| 15445 | /** |
| 15446 | * Forces this view to be laid out during the next layout pass. |
| 15447 | * This method does not call requestLayout() or forceLayout() |
| 15448 | * on the parent. |
| 15449 | */ |
| 15450 | public void forceLayout() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15451 | mPrivateFlags |= PFLAG_FORCE_LAYOUT; |
| 15452 | mPrivateFlags |= PFLAG_INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15453 | } |
| 15454 | |
| 15455 | /** |
| 15456 | * <p> |
| 15457 | * This is called to find out how big a view should be. The parent |
| 15458 | * supplies constraint information in the width and height parameters. |
| 15459 | * </p> |
| 15460 | * |
| 15461 | * <p> |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 15462 | * 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] | 15463 | * {@link #onMeasure(int, int)}, called by this method. Therefore, only |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 15464 | * {@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] | 15465 | * </p> |
| 15466 | * |
| 15467 | * |
| 15468 | * @param widthMeasureSpec Horizontal space requirements as imposed by the |
| 15469 | * parent |
| 15470 | * @param heightMeasureSpec Vertical space requirements as imposed by the |
| 15471 | * parent |
| 15472 | * |
| 15473 | * @see #onMeasure(int, int) |
| 15474 | */ |
| 15475 | public final void measure(int widthMeasureSpec, int heightMeasureSpec) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15476 | if ((mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT || |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15477 | widthMeasureSpec != mOldWidthMeasureSpec || |
| 15478 | heightMeasureSpec != mOldHeightMeasureSpec) { |
| 15479 | |
| 15480 | // first clears the measured dimension flag |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15481 | mPrivateFlags &= ~PFLAG_MEASURED_DIMENSION_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15482 | |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 15483 | resolveRtlPropertiesIfNeeded(); |
Adam Powell | 0090f20 | 2012-08-07 17:15:30 -0700 | [diff] [blame] | 15484 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15485 | // measure ourselves, this should set the measured dimension flag back |
| 15486 | onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 15487 | |
| 15488 | // flag not set, setMeasuredDimension() was not invoked, we raise |
| 15489 | // an exception to warn the developer |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15490 | 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] | 15491 | throw new IllegalStateException("onMeasure() did not set the" |
| 15492 | + " measured dimension by calling" |
| 15493 | + " setMeasuredDimension()"); |
| 15494 | } |
| 15495 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15496 | mPrivateFlags |= PFLAG_LAYOUT_REQUIRED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15497 | } |
| 15498 | |
| 15499 | mOldWidthMeasureSpec = widthMeasureSpec; |
| 15500 | mOldHeightMeasureSpec = heightMeasureSpec; |
| 15501 | } |
| 15502 | |
| 15503 | /** |
| 15504 | * <p> |
| 15505 | * Measure the view and its content to determine the measured width and the |
| 15506 | * measured height. This method is invoked by {@link #measure(int, int)} and |
| 15507 | * should be overriden by subclasses to provide accurate and efficient |
| 15508 | * measurement of their contents. |
| 15509 | * </p> |
| 15510 | * |
| 15511 | * <p> |
| 15512 | * <strong>CONTRACT:</strong> When overriding this method, you |
| 15513 | * <em>must</em> call {@link #setMeasuredDimension(int, int)} to store the |
| 15514 | * measured width and height of this view. Failure to do so will trigger an |
| 15515 | * <code>IllegalStateException</code>, thrown by |
| 15516 | * {@link #measure(int, int)}. Calling the superclass' |
| 15517 | * {@link #onMeasure(int, int)} is a valid use. |
| 15518 | * </p> |
| 15519 | * |
| 15520 | * <p> |
| 15521 | * The base class implementation of measure defaults to the background size, |
| 15522 | * unless a larger size is allowed by the MeasureSpec. Subclasses should |
| 15523 | * override {@link #onMeasure(int, int)} to provide better measurements of |
| 15524 | * their content. |
| 15525 | * </p> |
| 15526 | * |
| 15527 | * <p> |
| 15528 | * If this method is overridden, it is the subclass's responsibility to make |
| 15529 | * sure the measured height and width are at least the view's minimum height |
| 15530 | * and width ({@link #getSuggestedMinimumHeight()} and |
| 15531 | * {@link #getSuggestedMinimumWidth()}). |
| 15532 | * </p> |
| 15533 | * |
| 15534 | * @param widthMeasureSpec horizontal space requirements as imposed by the parent. |
| 15535 | * The requirements are encoded with |
| 15536 | * {@link android.view.View.MeasureSpec}. |
| 15537 | * @param heightMeasureSpec vertical space requirements as imposed by the parent. |
| 15538 | * The requirements are encoded with |
| 15539 | * {@link android.view.View.MeasureSpec}. |
| 15540 | * |
| 15541 | * @see #getMeasuredWidth() |
| 15542 | * @see #getMeasuredHeight() |
| 15543 | * @see #setMeasuredDimension(int, int) |
| 15544 | * @see #getSuggestedMinimumHeight() |
| 15545 | * @see #getSuggestedMinimumWidth() |
| 15546 | * @see android.view.View.MeasureSpec#getMode(int) |
| 15547 | * @see android.view.View.MeasureSpec#getSize(int) |
| 15548 | */ |
| 15549 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 15550 | setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), |
| 15551 | getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); |
| 15552 | } |
| 15553 | |
| 15554 | /** |
| 15555 | * <p>This mehod must be called by {@link #onMeasure(int, int)} to store the |
| 15556 | * measured width and measured height. Failing to do so will trigger an |
| 15557 | * exception at measurement time.</p> |
| 15558 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15559 | * @param measuredWidth The measured width of this view. May be a complex |
| 15560 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 15561 | * {@link #MEASURED_STATE_TOO_SMALL}. |
| 15562 | * @param measuredHeight The measured height of this view. May be a complex |
| 15563 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 15564 | * {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15565 | */ |
| 15566 | protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) { |
| 15567 | mMeasuredWidth = measuredWidth; |
| 15568 | mMeasuredHeight = measuredHeight; |
| 15569 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15570 | mPrivateFlags |= PFLAG_MEASURED_DIMENSION_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15571 | } |
| 15572 | |
| 15573 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15574 | * Merge two states as returned by {@link #getMeasuredState()}. |
| 15575 | * @param curState The current state as returned from a view or the result |
| 15576 | * of combining multiple views. |
| 15577 | * @param newState The new view state to combine. |
| 15578 | * @return Returns a new integer reflecting the combination of the two |
| 15579 | * states. |
| 15580 | */ |
| 15581 | public static int combineMeasuredStates(int curState, int newState) { |
| 15582 | return curState | newState; |
| 15583 | } |
| 15584 | |
| 15585 | /** |
| 15586 | * Version of {@link #resolveSizeAndState(int, int, int)} |
| 15587 | * returning only the {@link #MEASURED_SIZE_MASK} bits of the result. |
| 15588 | */ |
| 15589 | public static int resolveSize(int size, int measureSpec) { |
| 15590 | return resolveSizeAndState(size, measureSpec, 0) & MEASURED_SIZE_MASK; |
| 15591 | } |
| 15592 | |
| 15593 | /** |
| 15594 | * Utility to reconcile a desired size and state, with constraints imposed |
| 15595 | * by a MeasureSpec. Will take the desired size, unless a different size |
| 15596 | * is imposed by the constraints. The returned value is a compound integer, |
| 15597 | * with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and |
| 15598 | * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting |
| 15599 | * 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] | 15600 | * |
| 15601 | * @param size How big the view wants to be |
| 15602 | * @param measureSpec Constraints imposed by the parent |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15603 | * @return Size information bit mask as defined by |
| 15604 | * {@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] | 15605 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15606 | 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] | 15607 | int result = size; |
| 15608 | int specMode = MeasureSpec.getMode(measureSpec); |
| 15609 | int specSize = MeasureSpec.getSize(measureSpec); |
| 15610 | switch (specMode) { |
| 15611 | case MeasureSpec.UNSPECIFIED: |
| 15612 | result = size; |
| 15613 | break; |
| 15614 | case MeasureSpec.AT_MOST: |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15615 | if (specSize < size) { |
| 15616 | result = specSize | MEASURED_STATE_TOO_SMALL; |
| 15617 | } else { |
| 15618 | result = size; |
| 15619 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15620 | break; |
| 15621 | case MeasureSpec.EXACTLY: |
| 15622 | result = specSize; |
| 15623 | break; |
| 15624 | } |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15625 | return result | (childMeasuredState&MEASURED_STATE_MASK); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15626 | } |
| 15627 | |
| 15628 | /** |
| 15629 | * Utility to return a default size. Uses the supplied size if the |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 15630 | * MeasureSpec imposed no constraints. Will get larger if allowed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15631 | * by the MeasureSpec. |
| 15632 | * |
| 15633 | * @param size Default size for this view |
| 15634 | * @param measureSpec Constraints imposed by the parent |
| 15635 | * @return The size this view should be. |
| 15636 | */ |
| 15637 | public static int getDefaultSize(int size, int measureSpec) { |
| 15638 | int result = size; |
| 15639 | int specMode = MeasureSpec.getMode(measureSpec); |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 15640 | int specSize = MeasureSpec.getSize(measureSpec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15641 | |
| 15642 | switch (specMode) { |
| 15643 | case MeasureSpec.UNSPECIFIED: |
| 15644 | result = size; |
| 15645 | break; |
| 15646 | case MeasureSpec.AT_MOST: |
| 15647 | case MeasureSpec.EXACTLY: |
| 15648 | result = specSize; |
| 15649 | break; |
| 15650 | } |
| 15651 | return result; |
| 15652 | } |
| 15653 | |
| 15654 | /** |
| 15655 | * Returns the suggested minimum height that the view should use. This |
| 15656 | * returns the maximum of the view's minimum height |
| 15657 | * and the background's minimum height |
| 15658 | * ({@link android.graphics.drawable.Drawable#getMinimumHeight()}). |
| 15659 | * <p> |
| 15660 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 15661 | * ensure the returned height is within the requirements of the parent. |
| 15662 | * |
| 15663 | * @return The suggested minimum height of the view. |
| 15664 | */ |
| 15665 | protected int getSuggestedMinimumHeight() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15666 | return (mBackground == null) ? mMinHeight : max(mMinHeight, mBackground.getMinimumHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15667 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15668 | } |
| 15669 | |
| 15670 | /** |
| 15671 | * Returns the suggested minimum width that the view should use. This |
| 15672 | * returns the maximum of the view's minimum width) |
| 15673 | * and the background's minimum width |
| 15674 | * ({@link android.graphics.drawable.Drawable#getMinimumWidth()}). |
| 15675 | * <p> |
| 15676 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 15677 | * ensure the returned width is within the requirements of the parent. |
| 15678 | * |
| 15679 | * @return The suggested minimum width of the view. |
| 15680 | */ |
| 15681 | protected int getSuggestedMinimumWidth() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15682 | return (mBackground == null) ? mMinWidth : max(mMinWidth, mBackground.getMinimumWidth()); |
| 15683 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15684 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15685 | /** |
| 15686 | * Returns the minimum height of the view. |
| 15687 | * |
| 15688 | * @return the minimum height the view will try to be. |
| 15689 | * |
| 15690 | * @see #setMinimumHeight(int) |
| 15691 | * |
| 15692 | * @attr ref android.R.styleable#View_minHeight |
| 15693 | */ |
| 15694 | public int getMinimumHeight() { |
| 15695 | return mMinHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15696 | } |
| 15697 | |
| 15698 | /** |
| 15699 | * Sets the minimum height of the view. It is not guaranteed the view will |
| 15700 | * be able to achieve this minimum height (for example, if its parent layout |
| 15701 | * constrains it with less available height). |
| 15702 | * |
| 15703 | * @param minHeight The minimum height the view will try to be. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15704 | * |
| 15705 | * @see #getMinimumHeight() |
| 15706 | * |
| 15707 | * @attr ref android.R.styleable#View_minHeight |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15708 | */ |
| 15709 | public void setMinimumHeight(int minHeight) { |
| 15710 | mMinHeight = minHeight; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15711 | requestLayout(); |
| 15712 | } |
| 15713 | |
| 15714 | /** |
| 15715 | * Returns the minimum width of the view. |
| 15716 | * |
| 15717 | * @return the minimum width the view will try to be. |
| 15718 | * |
| 15719 | * @see #setMinimumWidth(int) |
| 15720 | * |
| 15721 | * @attr ref android.R.styleable#View_minWidth |
| 15722 | */ |
| 15723 | public int getMinimumWidth() { |
| 15724 | return mMinWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15725 | } |
| 15726 | |
| 15727 | /** |
| 15728 | * Sets the minimum width of the view. It is not guaranteed the view will |
| 15729 | * be able to achieve this minimum width (for example, if its parent layout |
| 15730 | * constrains it with less available width). |
| 15731 | * |
| 15732 | * @param minWidth The minimum width the view will try to be. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15733 | * |
| 15734 | * @see #getMinimumWidth() |
| 15735 | * |
| 15736 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15737 | */ |
| 15738 | public void setMinimumWidth(int minWidth) { |
| 15739 | mMinWidth = minWidth; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15740 | requestLayout(); |
| 15741 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15742 | } |
| 15743 | |
| 15744 | /** |
| 15745 | * Get the animation currently associated with this view. |
| 15746 | * |
| 15747 | * @return The animation that is currently playing or |
| 15748 | * scheduled to play for this view. |
| 15749 | */ |
| 15750 | public Animation getAnimation() { |
| 15751 | return mCurrentAnimation; |
| 15752 | } |
| 15753 | |
| 15754 | /** |
| 15755 | * Start the specified animation now. |
| 15756 | * |
| 15757 | * @param animation the animation to start now |
| 15758 | */ |
| 15759 | public void startAnimation(Animation animation) { |
| 15760 | animation.setStartTime(Animation.START_ON_FIRST_FRAME); |
| 15761 | setAnimation(animation); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 15762 | invalidateParentCaches(); |
| 15763 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15764 | } |
| 15765 | |
| 15766 | /** |
| 15767 | * Cancels any animations for this view. |
| 15768 | */ |
| 15769 | public void clearAnimation() { |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 15770 | if (mCurrentAnimation != null) { |
Romain Guy | b4a107d | 2010-02-09 18:50:08 -0800 | [diff] [blame] | 15771 | mCurrentAnimation.detach(); |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 15772 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15773 | mCurrentAnimation = null; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 15774 | invalidateParentIfNeeded(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15775 | } |
| 15776 | |
| 15777 | /** |
| 15778 | * Sets the next animation to play for this view. |
| 15779 | * If you want the animation to play immediately, use |
Chet Haase | 4242893 | 2012-05-11 15:39:07 -0700 | [diff] [blame] | 15780 | * {@link #startAnimation(android.view.animation.Animation)} instead. |
| 15781 | * This method provides allows fine-grained |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15782 | * control over the start time and invalidation, but you |
| 15783 | * 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] | 15784 | * 2) the view's parent (which controls animations on its children) |
| 15785 | * will be invalidated when the animation is supposed to |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15786 | * start. |
| 15787 | * |
| 15788 | * @param animation The next animation, or null. |
| 15789 | */ |
| 15790 | public void setAnimation(Animation animation) { |
| 15791 | mCurrentAnimation = animation; |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 15792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15793 | if (animation != null) { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 15794 | // If the screen is off assume the animation start time is now instead of |
| 15795 | // the next frame we draw. Keeping the START_ON_FIRST_FRAME start time |
| 15796 | // would cause the animation to start when the screen turns back on |
| 15797 | if (mAttachInfo != null && !mAttachInfo.mScreenOn && |
| 15798 | animation.getStartTime() == Animation.START_ON_FIRST_FRAME) { |
| 15799 | animation.setStartTime(AnimationUtils.currentAnimationTimeMillis()); |
| 15800 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15801 | animation.reset(); |
| 15802 | } |
| 15803 | } |
| 15804 | |
| 15805 | /** |
| 15806 | * Invoked by a parent ViewGroup to notify the start of the animation |
| 15807 | * currently associated with this view. If you override this method, |
| 15808 | * always call super.onAnimationStart(); |
| 15809 | * |
| 15810 | * @see #setAnimation(android.view.animation.Animation) |
| 15811 | * @see #getAnimation() |
| 15812 | */ |
| 15813 | protected void onAnimationStart() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15814 | mPrivateFlags |= PFLAG_ANIMATION_STARTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15815 | } |
| 15816 | |
| 15817 | /** |
| 15818 | * Invoked by a parent ViewGroup to notify the end of the animation |
| 15819 | * currently associated with this view. If you override this method, |
| 15820 | * always call super.onAnimationEnd(); |
| 15821 | * |
| 15822 | * @see #setAnimation(android.view.animation.Animation) |
| 15823 | * @see #getAnimation() |
| 15824 | */ |
| 15825 | protected void onAnimationEnd() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15826 | mPrivateFlags &= ~PFLAG_ANIMATION_STARTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15827 | } |
| 15828 | |
| 15829 | /** |
| 15830 | * Invoked if there is a Transform that involves alpha. Subclass that can |
| 15831 | * draw themselves with the specified alpha should return true, and then |
| 15832 | * respect that alpha when their onDraw() is called. If this returns false |
| 15833 | * then the view may be redirected to draw into an offscreen buffer to |
| 15834 | * fulfill the request, which will look fine, but may be slower than if the |
| 15835 | * subclass handles it internally. The default implementation returns false. |
| 15836 | * |
| 15837 | * @param alpha The alpha (0..255) to apply to the view's drawing |
| 15838 | * @return true if the view can draw with the specified alpha. |
| 15839 | */ |
| 15840 | protected boolean onSetAlpha(int alpha) { |
| 15841 | return false; |
| 15842 | } |
| 15843 | |
| 15844 | /** |
| 15845 | * This is used by the RootView to perform an optimization when |
| 15846 | * the view hierarchy contains one or several SurfaceView. |
| 15847 | * SurfaceView is always considered transparent, but its children are not, |
| 15848 | * therefore all View objects remove themselves from the global transparent |
| 15849 | * region (passed as a parameter to this function). |
| 15850 | * |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 15851 | * @param region The transparent region for this ViewAncestor (window). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15852 | * |
| 15853 | * @return Returns true if the effective visibility of the view at this |
| 15854 | * point is opaque, regardless of the transparent region; returns false |
| 15855 | * if it is possible for underlying windows to be seen behind the view. |
| 15856 | * |
| 15857 | * {@hide} |
| 15858 | */ |
| 15859 | public boolean gatherTransparentRegion(Region region) { |
| 15860 | final AttachInfo attachInfo = mAttachInfo; |
| 15861 | if (region != null && attachInfo != null) { |
| 15862 | final int pflags = mPrivateFlags; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15863 | if ((pflags & PFLAG_SKIP_DRAW) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15864 | // The SKIP_DRAW flag IS NOT set, so this view draws. We need to |
| 15865 | // remove it from the transparent region. |
| 15866 | final int[] location = attachInfo.mTransparentLocation; |
| 15867 | getLocationInWindow(location); |
| 15868 | region.op(location[0], location[1], location[0] + mRight - mLeft, |
| 15869 | location[1] + mBottom - mTop, Region.Op.DIFFERENCE); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15870 | } 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] | 15871 | // The ONLY_DRAWS_BACKGROUND flag IS set and the background drawable |
| 15872 | // exists, so we remove the background drawable's non-transparent |
| 15873 | // parts from this transparent region. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15874 | applyDrawableToTransparentRegion(mBackground, region); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15875 | } |
| 15876 | } |
| 15877 | return true; |
| 15878 | } |
| 15879 | |
| 15880 | /** |
| 15881 | * Play a sound effect for this view. |
| 15882 | * |
| 15883 | * <p>The framework will play sound effects for some built in actions, such as |
| 15884 | * clicking, but you may wish to play these effects in your widget, |
| 15885 | * for instance, for internal navigation. |
| 15886 | * |
| 15887 | * <p>The sound effect will only be played if sound effects are enabled by the user, and |
| 15888 | * {@link #isSoundEffectsEnabled()} is true. |
| 15889 | * |
| 15890 | * @param soundConstant One of the constants defined in {@link SoundEffectConstants} |
| 15891 | */ |
| 15892 | public void playSoundEffect(int soundConstant) { |
| 15893 | if (mAttachInfo == null || mAttachInfo.mRootCallbacks == null || !isSoundEffectsEnabled()) { |
| 15894 | return; |
| 15895 | } |
| 15896 | mAttachInfo.mRootCallbacks.playSoundEffect(soundConstant); |
| 15897 | } |
| 15898 | |
| 15899 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15900 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15901 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15902 | * <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] | 15903 | * |
| 15904 | * <p>The framework will provide haptic feedback for some built in actions, |
| 15905 | * such as long presses, but you may wish to provide feedback for your |
| 15906 | * own widget. |
| 15907 | * |
| 15908 | * <p>The feedback will only be performed if |
| 15909 | * {@link #isHapticFeedbackEnabled()} is true. |
| 15910 | * |
| 15911 | * @param feedbackConstant One of the constants defined in |
| 15912 | * {@link HapticFeedbackConstants} |
| 15913 | */ |
| 15914 | public boolean performHapticFeedback(int feedbackConstant) { |
| 15915 | return performHapticFeedback(feedbackConstant, 0); |
| 15916 | } |
| 15917 | |
| 15918 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15919 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15920 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15921 | * <p>Like {@link #performHapticFeedback(int)}, with additional options. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15922 | * |
| 15923 | * @param feedbackConstant One of the constants defined in |
| 15924 | * {@link HapticFeedbackConstants} |
| 15925 | * @param flags Additional flags as per {@link HapticFeedbackConstants}. |
| 15926 | */ |
| 15927 | public boolean performHapticFeedback(int feedbackConstant, int flags) { |
| 15928 | if (mAttachInfo == null) { |
| 15929 | return false; |
| 15930 | } |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 15931 | //noinspection SimplifiableIfStatement |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 15932 | if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15933 | && !isHapticFeedbackEnabled()) { |
| 15934 | return false; |
| 15935 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 15936 | return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant, |
| 15937 | (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15938 | } |
| 15939 | |
| 15940 | /** |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 15941 | * Request that the visibility of the status bar or other screen/window |
| 15942 | * decorations be changed. |
| 15943 | * |
| 15944 | * <p>This method is used to put the over device UI into temporary modes |
| 15945 | * where the user's attention is focused more on the application content, |
| 15946 | * by dimming or hiding surrounding system affordances. This is typically |
| 15947 | * used in conjunction with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 15948 | * Window.FEATURE_ACTION_BAR_OVERLAY}, allowing the applications content |
| 15949 | * to be placed behind the action bar (and with these flags other system |
| 15950 | * affordances) so that smooth transitions between hiding and showing them |
| 15951 | * can be done. |
| 15952 | * |
| 15953 | * <p>Two representative examples of the use of system UI visibility is |
| 15954 | * implementing a content browsing application (like a magazine reader) |
| 15955 | * and a video playing application. |
| 15956 | * |
| 15957 | * <p>The first code shows a typical implementation of a View in a content |
| 15958 | * browsing application. In this implementation, the application goes |
| 15959 | * into a content-oriented mode by hiding the status bar and action bar, |
| 15960 | * and putting the navigation elements into lights out mode. The user can |
| 15961 | * then interact with content while in this mode. Such an application should |
| 15962 | * provide an easy way for the user to toggle out of the mode (such as to |
| 15963 | * check information in the status bar or access notifications). In the |
| 15964 | * implementation here, this is done simply by tapping on the content. |
| 15965 | * |
| 15966 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/view/ContentBrowserActivity.java |
| 15967 | * content} |
| 15968 | * |
| 15969 | * <p>This second code sample shows a typical implementation of a View |
| 15970 | * in a video playing application. In this situation, while the video is |
| 15971 | * playing the application would like to go into a complete full-screen mode, |
| 15972 | * to use as much of the display as possible for the video. When in this state |
| 15973 | * the user can not interact with the application; the system intercepts |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 15974 | * touching on the screen to pop the UI out of full screen mode. See |
| 15975 | * {@link #fitSystemWindows(Rect)} for a sample layout that goes with this code. |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 15976 | * |
| 15977 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/view/VideoPlayerActivity.java |
| 15978 | * content} |
| 15979 | * |
| 15980 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 15981 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN}, |
| 15982 | * {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, |
| 15983 | * and {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15984 | */ |
| 15985 | public void setSystemUiVisibility(int visibility) { |
Daniel Sandler | 7052406 | 2011-09-21 00:30:47 -0400 | [diff] [blame] | 15986 | if (visibility != mSystemUiVisibility) { |
| 15987 | mSystemUiVisibility = visibility; |
| 15988 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 15989 | mParent.recomputeViewAttributes(this); |
| 15990 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15991 | } |
| 15992 | } |
| 15993 | |
| 15994 | /** |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 15995 | * Returns the last {@link #setSystemUiVisibility(int) that this view has requested. |
| 15996 | * @return Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 15997 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN}, |
| 15998 | * {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, |
| 15999 | * and {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16000 | */ |
Joe Onorato | e595cad | 2011-01-24 09:22:12 -0800 | [diff] [blame] | 16001 | public int getSystemUiVisibility() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16002 | return mSystemUiVisibility; |
| 16003 | } |
| 16004 | |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 16005 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 16006 | * Returns the current system UI visibility that is currently set for |
| 16007 | * the entire window. This is the combination of the |
| 16008 | * {@link #setSystemUiVisibility(int)} values supplied by all of the |
| 16009 | * views in the window. |
| 16010 | */ |
| 16011 | public int getWindowSystemUiVisibility() { |
| 16012 | return mAttachInfo != null ? mAttachInfo.mSystemUiVisibility : 0; |
| 16013 | } |
| 16014 | |
| 16015 | /** |
| 16016 | * Override to find out when the window's requested system UI visibility |
| 16017 | * has changed, that is the value returned by {@link #getWindowSystemUiVisibility()}. |
| 16018 | * This is different from the callbacks recieved through |
| 16019 | * {@link #setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener)} |
| 16020 | * in that this is only telling you about the local request of the window, |
| 16021 | * not the actual values applied by the system. |
| 16022 | */ |
| 16023 | public void onWindowSystemUiVisibilityChanged(int visible) { |
| 16024 | } |
| 16025 | |
| 16026 | /** |
| 16027 | * Dispatch callbacks to {@link #onWindowSystemUiVisibilityChanged(int)} down |
| 16028 | * the view hierarchy. |
| 16029 | */ |
| 16030 | public void dispatchWindowSystemUiVisiblityChanged(int visible) { |
| 16031 | onWindowSystemUiVisibilityChanged(visible); |
| 16032 | } |
| 16033 | |
| 16034 | /** |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 16035 | * Set a listener to receive callbacks when the visibility of the system bar changes. |
| 16036 | * @param l The {@link OnSystemUiVisibilityChangeListener} to receive callbacks. |
| 16037 | */ |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16038 | public void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 16039 | getListenerInfo().mOnSystemUiVisibilityChangeListener = l; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16040 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 16041 | mParent.recomputeViewAttributes(this); |
| 16042 | } |
| 16043 | } |
| 16044 | |
| 16045 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16046 | * Dispatch callbacks to {@link #setOnSystemUiVisibilityChangeListener} down |
| 16047 | * the view hierarchy. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16048 | */ |
| 16049 | public void dispatchSystemUiVisibilityChanged(int visibility) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 16050 | ListenerInfo li = mListenerInfo; |
| 16051 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
| 16052 | li.mOnSystemUiVisibilityChangeListener.onSystemUiVisibilityChange( |
Joe Onorato | 6ab77bd | 2011-01-31 11:21:10 -0800 | [diff] [blame] | 16053 | visibility & PUBLIC_STATUS_BAR_VISIBILITY_MASK); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16054 | } |
| 16055 | } |
| 16056 | |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 16057 | boolean updateLocalSystemUiVisibility(int localValue, int localChanges) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16058 | int val = (mSystemUiVisibility&~localChanges) | (localValue&localChanges); |
| 16059 | if (val != mSystemUiVisibility) { |
| 16060 | setSystemUiVisibility(val); |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 16061 | return true; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16062 | } |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 16063 | return false; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16064 | } |
| 16065 | |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 16066 | /** @hide */ |
| 16067 | public void setDisabledSystemUiVisibility(int flags) { |
| 16068 | if (mAttachInfo != null) { |
| 16069 | if (mAttachInfo.mDisabledSystemUiVisibility != flags) { |
| 16070 | mAttachInfo.mDisabledSystemUiVisibility = flags; |
| 16071 | if (mParent != null) { |
| 16072 | mParent.recomputeViewAttributes(this); |
| 16073 | } |
| 16074 | } |
| 16075 | } |
| 16076 | } |
| 16077 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16078 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16079 | * Creates an image that the system displays during the drag and drop |
| 16080 | * operation. This is called a "drag shadow". The default implementation |
| 16081 | * for a DragShadowBuilder based on a View returns an image that has exactly the same |
| 16082 | * appearance as the given View. The default also positions the center of the drag shadow |
| 16083 | * directly under the touch point. If no View is provided (the constructor with no parameters |
| 16084 | * is used), and {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} and |
| 16085 | * {@link #onDrawShadow(Canvas) onDrawShadow()} are not overriden, then the |
| 16086 | * default is an invisible drag shadow. |
| 16087 | * <p> |
| 16088 | * You are not required to use the View you provide to the constructor as the basis of the |
| 16089 | * drag shadow. The {@link #onDrawShadow(Canvas) onDrawShadow()} method allows you to draw |
| 16090 | * anything you want as the drag shadow. |
| 16091 | * </p> |
| 16092 | * <p> |
| 16093 | * You pass a DragShadowBuilder object to the system when you start the drag. The system |
| 16094 | * calls {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} to get the |
| 16095 | * size and position of the drag shadow. It uses this data to construct a |
| 16096 | * {@link android.graphics.Canvas} object, then it calls {@link #onDrawShadow(Canvas) onDrawShadow()} |
| 16097 | * so that your application can draw the shadow image in the Canvas. |
| 16098 | * </p> |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 16099 | * |
| 16100 | * <div class="special reference"> |
| 16101 | * <h3>Developer Guides</h3> |
| 16102 | * <p>For a guide to implementing drag and drop features, read the |
| 16103 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 16104 | * </div> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16105 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16106 | public static class DragShadowBuilder { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16107 | private final WeakReference<View> mView; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16108 | |
| 16109 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16110 | * Constructs a shadow image builder based on a View. By default, the resulting drag |
| 16111 | * shadow will have the same appearance and dimensions as the View, with the touch point |
| 16112 | * over the center of the View. |
| 16113 | * @param view A View. Any View in scope can be used. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16114 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16115 | public DragShadowBuilder(View view) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16116 | mView = new WeakReference<View>(view); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16117 | } |
| 16118 | |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 16119 | /** |
| 16120 | * Construct a shadow builder object with no associated View. This |
| 16121 | * constructor variant is only useful when the {@link #onProvideShadowMetrics(Point, Point)} |
| 16122 | * and {@link #onDrawShadow(Canvas)} methods are also overridden in order |
| 16123 | * to supply the drag shadow's dimensions and appearance without |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16124 | * reference to any View object. If they are not overridden, then the result is an |
| 16125 | * invisible drag shadow. |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 16126 | */ |
| 16127 | public DragShadowBuilder() { |
| 16128 | mView = new WeakReference<View>(null); |
| 16129 | } |
| 16130 | |
| 16131 | /** |
| 16132 | * Returns the View object that had been passed to the |
| 16133 | * {@link #View.DragShadowBuilder(View)} |
| 16134 | * constructor. If that View parameter was {@code null} or if the |
| 16135 | * {@link #View.DragShadowBuilder()} |
| 16136 | * constructor was used to instantiate the builder object, this method will return |
| 16137 | * null. |
| 16138 | * |
| 16139 | * @return The View object associate with this builder object. |
| 16140 | */ |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 16141 | @SuppressWarnings({"JavadocReference"}) |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 16142 | final public View getView() { |
| 16143 | return mView.get(); |
| 16144 | } |
| 16145 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16146 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16147 | * Provides the metrics for the shadow image. These include the dimensions of |
| 16148 | * the shadow image, and the point within that shadow that should |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16149 | * be centered under the touch location while dragging. |
| 16150 | * <p> |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16151 | * The default implementation sets the dimensions of the shadow to be the |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16152 | * same as the dimensions of the View itself and centers the shadow under |
| 16153 | * the touch point. |
| 16154 | * </p> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16155 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16156 | * @param shadowSize A {@link android.graphics.Point} containing the width and height |
| 16157 | * of the shadow image. Your application must set {@link android.graphics.Point#x} to the |
| 16158 | * desired width and must set {@link android.graphics.Point#y} to the desired height of the |
| 16159 | * image. |
| 16160 | * |
| 16161 | * @param shadowTouchPoint A {@link android.graphics.Point} for the position within the |
| 16162 | * shadow image that should be underneath the touch point during the drag and drop |
| 16163 | * operation. Your application must set {@link android.graphics.Point#x} to the |
| 16164 | * 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] | 16165 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16166 | public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16167 | final View view = mView.get(); |
| 16168 | if (view != null) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16169 | shadowSize.set(view.getWidth(), view.getHeight()); |
| 16170 | shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2); |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16171 | } else { |
| 16172 | Log.e(View.VIEW_LOG_TAG, "Asked for drag thumb metrics but no view"); |
| 16173 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16174 | } |
| 16175 | |
| 16176 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16177 | * Draws the shadow image. The system creates the {@link android.graphics.Canvas} object |
| 16178 | * based on the dimensions it received from the |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16179 | * {@link #onProvideShadowMetrics(Point, Point)} callback. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16180 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16181 | * @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] | 16182 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16183 | public void onDrawShadow(Canvas canvas) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16184 | final View view = mView.get(); |
| 16185 | if (view != null) { |
| 16186 | view.draw(canvas); |
| 16187 | } else { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16188 | 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] | 16189 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16190 | } |
| 16191 | } |
| 16192 | |
| 16193 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16194 | * Starts a drag and drop operation. When your application calls this method, it passes a |
| 16195 | * {@link android.view.View.DragShadowBuilder} object to the system. The |
| 16196 | * system calls this object's {@link DragShadowBuilder#onProvideShadowMetrics(Point, Point)} |
| 16197 | * to get metrics for the drag shadow, and then calls the object's |
| 16198 | * {@link DragShadowBuilder#onDrawShadow(Canvas)} to draw the drag shadow itself. |
| 16199 | * <p> |
| 16200 | * Once the system has the drag shadow, it begins the drag and drop operation by sending |
| 16201 | * drag events to all the View objects in your application that are currently visible. It does |
| 16202 | * this either by calling the View object's drag listener (an implementation of |
| 16203 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent) onDrag()} or by calling the |
| 16204 | * View object's {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} method. |
| 16205 | * Both are passed a {@link android.view.DragEvent} object that has a |
| 16206 | * {@link android.view.DragEvent#getAction()} value of |
| 16207 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED}. |
| 16208 | * </p> |
| 16209 | * <p> |
| 16210 | * Your application can invoke startDrag() on any attached View object. The View object does not |
| 16211 | * need to be the one used in {@link android.view.View.DragShadowBuilder}, nor does it need to |
| 16212 | * be related to the View the user selected for dragging. |
| 16213 | * </p> |
| 16214 | * @param data A {@link android.content.ClipData} object pointing to the data to be |
| 16215 | * transferred by the drag and drop operation. |
| 16216 | * @param shadowBuilder A {@link android.view.View.DragShadowBuilder} object for building the |
| 16217 | * drag shadow. |
| 16218 | * @param myLocalState An {@link java.lang.Object} containing local data about the drag and |
| 16219 | * drop operation. This Object is put into every DragEvent object sent by the system during the |
| 16220 | * current drag. |
| 16221 | * <p> |
| 16222 | * myLocalState is a lightweight mechanism for the sending information from the dragged View |
| 16223 | * to the target Views. For example, it can contain flags that differentiate between a |
| 16224 | * a copy operation and a move operation. |
| 16225 | * </p> |
| 16226 | * @param flags Flags that control the drag and drop operation. No flags are currently defined, |
| 16227 | * so the parameter should be set to 0. |
| 16228 | * @return {@code true} if the method completes successfully, or |
| 16229 | * {@code false} if it fails anywhere. Returning {@code false} means the system was unable to |
| 16230 | * do a drag, and so no drag operation is in progress. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16231 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16232 | public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 16233 | Object myLocalState, int flags) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16234 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 16235 | Log.d(VIEW_LOG_TAG, "startDrag: data=" + data + " flags=" + flags); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16236 | } |
| 16237 | boolean okay = false; |
| 16238 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16239 | Point shadowSize = new Point(); |
| 16240 | Point shadowTouchPoint = new Point(); |
| 16241 | shadowBuilder.onProvideShadowMetrics(shadowSize, shadowTouchPoint); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16242 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16243 | if ((shadowSize.x < 0) || (shadowSize.y < 0) || |
| 16244 | (shadowTouchPoint.x < 0) || (shadowTouchPoint.y < 0)) { |
| 16245 | throw new IllegalStateException("Drag shadow dimensions must not be negative"); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16246 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16247 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 16248 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16249 | Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y |
| 16250 | + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 16251 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16252 | Surface surface = new Surface(); |
| 16253 | try { |
| 16254 | IBinder token = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 16255 | flags, shadowSize.x, shadowSize.y, surface); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16256 | 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] | 16257 | + " surface=" + surface); |
| 16258 | if (token != null) { |
| 16259 | Canvas canvas = surface.lockCanvas(null); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 16260 | try { |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 16261 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16262 | shadowBuilder.onDrawShadow(canvas); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 16263 | } finally { |
| 16264 | surface.unlockCanvasAndPost(canvas); |
| 16265 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16266 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 16267 | final ViewRootImpl root = getViewRootImpl(); |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 16268 | |
| 16269 | // Cache the local state object for delivery with DragEvents |
| 16270 | root.setLocalDragState(myLocalState); |
| 16271 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16272 | // repurpose 'shadowSize' for the last touch point |
| 16273 | root.getLastTouchPoint(shadowSize); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16274 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16275 | okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token, |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16276 | shadowSize.x, shadowSize.y, |
| 16277 | shadowTouchPoint.x, shadowTouchPoint.y, data); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16278 | if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay); |
Christopher Tate | 8f73b5d | 2011-09-12 15:22:12 -0700 | [diff] [blame] | 16279 | |
| 16280 | // Off and running! Release our local surface instance; the drag |
| 16281 | // shadow surface is now managed by the system process. |
| 16282 | surface.release(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16283 | } |
| 16284 | } catch (Exception e) { |
| 16285 | Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e); |
| 16286 | surface.destroy(); |
| 16287 | } |
| 16288 | |
| 16289 | return okay; |
| 16290 | } |
| 16291 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16292 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16293 | * Handles drag events sent by the system following a call to |
| 16294 | * {@link android.view.View#startDrag(ClipData,DragShadowBuilder,Object,int) startDrag()}. |
| 16295 | *<p> |
| 16296 | * When the system calls this method, it passes a |
| 16297 | * {@link android.view.DragEvent} object. A call to |
| 16298 | * {@link android.view.DragEvent#getAction()} returns one of the action type constants defined |
| 16299 | * in DragEvent. The method uses these to determine what is happening in the drag and drop |
| 16300 | * operation. |
| 16301 | * @param event The {@link android.view.DragEvent} sent by the system. |
| 16302 | * The {@link android.view.DragEvent#getAction()} method returns an action type constant defined |
| 16303 | * in DragEvent, indicating the type of drag event represented by this object. |
| 16304 | * @return {@code true} if the method was successful, otherwise {@code false}. |
| 16305 | * <p> |
| 16306 | * The method should return {@code true} in response to an action type of |
| 16307 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED} to receive drag events for the current |
| 16308 | * operation. |
| 16309 | * </p> |
| 16310 | * <p> |
| 16311 | * The method should also return {@code true} in response to an action type of |
| 16312 | * {@link android.view.DragEvent#ACTION_DROP} if it consumed the drop, or |
| 16313 | * {@code false} if it didn't. |
| 16314 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16315 | */ |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 16316 | public boolean onDragEvent(DragEvent event) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16317 | return false; |
| 16318 | } |
| 16319 | |
| 16320 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16321 | * Detects if this View is enabled and has a drag event listener. |
| 16322 | * If both are true, then it calls the drag event listener with the |
| 16323 | * {@link android.view.DragEvent} it received. If the drag event listener returns |
| 16324 | * {@code true}, then dispatchDragEvent() returns {@code true}. |
| 16325 | * <p> |
| 16326 | * For all other cases, the method calls the |
| 16327 | * {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} drag event handler |
| 16328 | * method and returns its result. |
| 16329 | * </p> |
| 16330 | * <p> |
| 16331 | * This ensures that a drag event is always consumed, even if the View does not have a drag |
| 16332 | * event listener. However, if the View has a listener and the listener returns true, then |
| 16333 | * onDragEvent() is not called. |
| 16334 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16335 | */ |
| 16336 | public boolean dispatchDragEvent(DragEvent event) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 16337 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 16338 | ListenerInfo li = mListenerInfo; |
| 16339 | if (li != null && li.mOnDragListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 16340 | && li.mOnDragListener.onDrag(this, event)) { |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 16341 | return true; |
| 16342 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16343 | return onDragEvent(event); |
| 16344 | } |
| 16345 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 16346 | boolean canAcceptDrag() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16347 | return (mPrivateFlags2 & PFLAG2_DRAG_CAN_ACCEPT) != 0; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 16348 | } |
| 16349 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16350 | /** |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 16351 | * This needs to be a better API (NOT ON VIEW) before it is exposed. If |
| 16352 | * it is ever exposed at all. |
Dianne Hackborn | 29e4a3c | 2009-09-30 22:35:40 -0700 | [diff] [blame] | 16353 | * @hide |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 16354 | */ |
| 16355 | public void onCloseSystemDialogs(String reason) { |
| 16356 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16357 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 16358 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16359 | * 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] | 16360 | * update a Region being computed for |
| 16361 | * {@link #gatherTransparentRegion(android.graphics.Region)} so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16362 | * that any non-transparent parts of the Drawable are removed from the |
| 16363 | * given transparent region. |
| 16364 | * |
| 16365 | * @param dr The Drawable whose transparency is to be applied to the region. |
| 16366 | * @param region A Region holding the current transparency information, |
| 16367 | * where any parts of the region that are set are considered to be |
| 16368 | * transparent. On return, this region will be modified to have the |
| 16369 | * transparency information reduced by the corresponding parts of the |
| 16370 | * Drawable that are not transparent. |
| 16371 | * {@hide} |
| 16372 | */ |
| 16373 | public void applyDrawableToTransparentRegion(Drawable dr, Region region) { |
| 16374 | if (DBG) { |
| 16375 | Log.i("View", "Getting transparent region for: " + this); |
| 16376 | } |
| 16377 | final Region r = dr.getTransparentRegion(); |
| 16378 | final Rect db = dr.getBounds(); |
| 16379 | final AttachInfo attachInfo = mAttachInfo; |
| 16380 | if (r != null && attachInfo != null) { |
| 16381 | final int w = getRight()-getLeft(); |
| 16382 | final int h = getBottom()-getTop(); |
| 16383 | if (db.left > 0) { |
| 16384 | //Log.i("VIEW", "Drawable left " + db.left + " > view 0"); |
| 16385 | r.op(0, 0, db.left, h, Region.Op.UNION); |
| 16386 | } |
| 16387 | if (db.right < w) { |
| 16388 | //Log.i("VIEW", "Drawable right " + db.right + " < view " + w); |
| 16389 | r.op(db.right, 0, w, h, Region.Op.UNION); |
| 16390 | } |
| 16391 | if (db.top > 0) { |
| 16392 | //Log.i("VIEW", "Drawable top " + db.top + " > view 0"); |
| 16393 | r.op(0, 0, w, db.top, Region.Op.UNION); |
| 16394 | } |
| 16395 | if (db.bottom < h) { |
| 16396 | //Log.i("VIEW", "Drawable bottom " + db.bottom + " < view " + h); |
| 16397 | r.op(0, db.bottom, w, h, Region.Op.UNION); |
| 16398 | } |
| 16399 | final int[] location = attachInfo.mTransparentLocation; |
| 16400 | getLocationInWindow(location); |
| 16401 | r.translate(location[0], location[1]); |
| 16402 | region.op(r, Region.Op.INTERSECT); |
| 16403 | } else { |
| 16404 | region.op(db, Region.Op.DIFFERENCE); |
| 16405 | } |
| 16406 | } |
| 16407 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 16408 | private void checkForLongClick(int delayOffset) { |
| 16409 | if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) { |
| 16410 | mHasPerformedLongPress = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16411 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 16412 | if (mPendingCheckForLongPress == null) { |
| 16413 | mPendingCheckForLongPress = new CheckForLongPress(); |
| 16414 | } |
| 16415 | mPendingCheckForLongPress.rememberWindowAttachCount(); |
| 16416 | postDelayed(mPendingCheckForLongPress, |
| 16417 | ViewConfiguration.getLongPressTimeout() - delayOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16418 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16419 | } |
| 16420 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16421 | /** |
| 16422 | * Inflate a view from an XML resource. This convenience method wraps the {@link |
| 16423 | * LayoutInflater} class, which provides a full range of options for view inflation. |
| 16424 | * |
| 16425 | * @param context The Context object for your activity or application. |
| 16426 | * @param resource The resource ID to inflate |
| 16427 | * @param root A view group that will be the parent. Used to properly inflate the |
| 16428 | * layout_* parameters. |
| 16429 | * @see LayoutInflater |
| 16430 | */ |
| 16431 | public static View inflate(Context context, int resource, ViewGroup root) { |
| 16432 | LayoutInflater factory = LayoutInflater.from(context); |
| 16433 | return factory.inflate(resource, root); |
| 16434 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 16435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16436 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 16437 | * Scroll the view with standard behavior for scrolling beyond the normal |
| 16438 | * content boundaries. Views that call this method should override |
| 16439 | * {@link #onOverScrolled(int, int, boolean, boolean)} to respond to the |
| 16440 | * results of an over-scroll operation. |
| 16441 | * |
| 16442 | * Views can use this method to handle any touch or fling-based scrolling. |
| 16443 | * |
| 16444 | * @param deltaX Change in X in pixels |
| 16445 | * @param deltaY Change in Y in pixels |
| 16446 | * @param scrollX Current X scroll value in pixels before applying deltaX |
| 16447 | * @param scrollY Current Y scroll value in pixels before applying deltaY |
| 16448 | * @param scrollRangeX Maximum content scroll range along the X axis |
| 16449 | * @param scrollRangeY Maximum content scroll range along the Y axis |
| 16450 | * @param maxOverScrollX Number of pixels to overscroll by in either direction |
| 16451 | * along the X axis. |
| 16452 | * @param maxOverScrollY Number of pixels to overscroll by in either direction |
| 16453 | * along the Y axis. |
| 16454 | * @param isTouchEvent true if this scroll operation is the result of a touch event. |
| 16455 | * @return true if scrolling was clamped to an over-scroll boundary along either |
| 16456 | * axis, false otherwise. |
| 16457 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 16458 | @SuppressWarnings({"UnusedParameters"}) |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 16459 | protected boolean overScrollBy(int deltaX, int deltaY, |
| 16460 | int scrollX, int scrollY, |
| 16461 | int scrollRangeX, int scrollRangeY, |
| 16462 | int maxOverScrollX, int maxOverScrollY, |
| 16463 | boolean isTouchEvent) { |
| 16464 | final int overScrollMode = mOverScrollMode; |
| 16465 | final boolean canScrollHorizontal = |
| 16466 | computeHorizontalScrollRange() > computeHorizontalScrollExtent(); |
| 16467 | final boolean canScrollVertical = |
| 16468 | computeVerticalScrollRange() > computeVerticalScrollExtent(); |
| 16469 | final boolean overScrollHorizontal = overScrollMode == OVER_SCROLL_ALWAYS || |
| 16470 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal); |
| 16471 | final boolean overScrollVertical = overScrollMode == OVER_SCROLL_ALWAYS || |
| 16472 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical); |
| 16473 | |
| 16474 | int newScrollX = scrollX + deltaX; |
| 16475 | if (!overScrollHorizontal) { |
| 16476 | maxOverScrollX = 0; |
| 16477 | } |
| 16478 | |
| 16479 | int newScrollY = scrollY + deltaY; |
| 16480 | if (!overScrollVertical) { |
| 16481 | maxOverScrollY = 0; |
| 16482 | } |
| 16483 | |
| 16484 | // Clamp values if at the limits and record |
| 16485 | final int left = -maxOverScrollX; |
| 16486 | final int right = maxOverScrollX + scrollRangeX; |
| 16487 | final int top = -maxOverScrollY; |
| 16488 | final int bottom = maxOverScrollY + scrollRangeY; |
| 16489 | |
| 16490 | boolean clampedX = false; |
| 16491 | if (newScrollX > right) { |
| 16492 | newScrollX = right; |
| 16493 | clampedX = true; |
| 16494 | } else if (newScrollX < left) { |
| 16495 | newScrollX = left; |
| 16496 | clampedX = true; |
| 16497 | } |
| 16498 | |
| 16499 | boolean clampedY = false; |
| 16500 | if (newScrollY > bottom) { |
| 16501 | newScrollY = bottom; |
| 16502 | clampedY = true; |
| 16503 | } else if (newScrollY < top) { |
| 16504 | newScrollY = top; |
| 16505 | clampedY = true; |
| 16506 | } |
| 16507 | |
| 16508 | onOverScrolled(newScrollX, newScrollY, clampedX, clampedY); |
| 16509 | |
| 16510 | return clampedX || clampedY; |
| 16511 | } |
| 16512 | |
| 16513 | /** |
| 16514 | * Called by {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)} to |
| 16515 | * respond to the results of an over-scroll operation. |
| 16516 | * |
| 16517 | * @param scrollX New X scroll value in pixels |
| 16518 | * @param scrollY New Y scroll value in pixels |
| 16519 | * @param clampedX True if scrollX was clamped to an over-scroll boundary |
| 16520 | * @param clampedY True if scrollY was clamped to an over-scroll boundary |
| 16521 | */ |
| 16522 | protected void onOverScrolled(int scrollX, int scrollY, |
| 16523 | boolean clampedX, boolean clampedY) { |
| 16524 | // Intentionally empty. |
| 16525 | } |
| 16526 | |
| 16527 | /** |
| 16528 | * Returns the over-scroll mode for this view. The result will be |
| 16529 | * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 16530 | * (allow over-scrolling only if the view content is larger than the container), |
| 16531 | * or {@link #OVER_SCROLL_NEVER}. |
| 16532 | * |
| 16533 | * @return This view's over-scroll mode. |
| 16534 | */ |
| 16535 | public int getOverScrollMode() { |
| 16536 | return mOverScrollMode; |
| 16537 | } |
| 16538 | |
| 16539 | /** |
| 16540 | * Set the over-scroll mode for this view. Valid over-scroll modes are |
| 16541 | * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 16542 | * (allow over-scrolling only if the view content is larger than the container), |
| 16543 | * or {@link #OVER_SCROLL_NEVER}. |
| 16544 | * |
| 16545 | * Setting the over-scroll mode of a view will have an effect only if the |
| 16546 | * view is capable of scrolling. |
| 16547 | * |
| 16548 | * @param overScrollMode The new over-scroll mode for this view. |
| 16549 | */ |
| 16550 | public void setOverScrollMode(int overScrollMode) { |
| 16551 | if (overScrollMode != OVER_SCROLL_ALWAYS && |
| 16552 | overScrollMode != OVER_SCROLL_IF_CONTENT_SCROLLS && |
| 16553 | overScrollMode != OVER_SCROLL_NEVER) { |
| 16554 | throw new IllegalArgumentException("Invalid overscroll mode " + overScrollMode); |
| 16555 | } |
| 16556 | mOverScrollMode = overScrollMode; |
| 16557 | } |
| 16558 | |
| 16559 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 16560 | * Gets a scale factor that determines the distance the view should scroll |
| 16561 | * vertically in response to {@link MotionEvent#ACTION_SCROLL}. |
| 16562 | * @return The vertical scroll scale factor. |
| 16563 | * @hide |
| 16564 | */ |
| 16565 | protected float getVerticalScrollFactor() { |
| 16566 | if (mVerticalScrollFactor == 0) { |
| 16567 | TypedValue outValue = new TypedValue(); |
| 16568 | if (!mContext.getTheme().resolveAttribute( |
| 16569 | com.android.internal.R.attr.listPreferredItemHeight, outValue, true)) { |
| 16570 | throw new IllegalStateException( |
| 16571 | "Expected theme to define listPreferredItemHeight."); |
| 16572 | } |
| 16573 | mVerticalScrollFactor = outValue.getDimension( |
| 16574 | mContext.getResources().getDisplayMetrics()); |
| 16575 | } |
| 16576 | return mVerticalScrollFactor; |
| 16577 | } |
| 16578 | |
| 16579 | /** |
| 16580 | * Gets a scale factor that determines the distance the view should scroll |
| 16581 | * horizontally in response to {@link MotionEvent#ACTION_SCROLL}. |
| 16582 | * @return The horizontal scroll scale factor. |
| 16583 | * @hide |
| 16584 | */ |
| 16585 | protected float getHorizontalScrollFactor() { |
| 16586 | // TODO: Should use something else. |
| 16587 | return getVerticalScrollFactor(); |
| 16588 | } |
| 16589 | |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16590 | /** |
| 16591 | * Return the value specifying the text direction or policy that was set with |
| 16592 | * {@link #setTextDirection(int)}. |
| 16593 | * |
| 16594 | * @return the defined text direction. It can be one of: |
| 16595 | * |
| 16596 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 16597 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 16598 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 16599 | * {@link #TEXT_DIRECTION_LTR}, |
| 16600 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16601 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16602 | * |
| 16603 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16604 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16605 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 16606 | @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), |
| 16607 | @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), |
| 16608 | @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), |
| 16609 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), |
| 16610 | @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), |
| 16611 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") |
| 16612 | }) |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16613 | public int getRawTextDirection() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16614 | return (mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_MASK) >> PFLAG2_TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16615 | } |
| 16616 | |
| 16617 | /** |
| 16618 | * Set the text direction. |
| 16619 | * |
| 16620 | * @param textDirection the direction to set. Should be one of: |
| 16621 | * |
| 16622 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 16623 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 16624 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 16625 | * {@link #TEXT_DIRECTION_LTR}, |
| 16626 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16627 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16628 | * |
| 16629 | * Resolution will be done if the value is set to TEXT_DIRECTION_INHERIT. The resolution |
| 16630 | * proceeds up the parent chain of the view to get the value. If there is no parent, then it will |
| 16631 | * return the default {@link #TEXT_DIRECTION_FIRST_STRONG}. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16632 | */ |
| 16633 | public void setTextDirection(int textDirection) { |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16634 | if (getRawTextDirection() != textDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 16635 | // Reset the current text direction and the resolved one |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16636 | mPrivateFlags2 &= ~PFLAG2_TEXT_DIRECTION_MASK; |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 16637 | resetResolvedTextDirection(); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16638 | // Set the new text direction |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16639 | mPrivateFlags2 |= ((textDirection << PFLAG2_TEXT_DIRECTION_MASK_SHIFT) & PFLAG2_TEXT_DIRECTION_MASK); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16640 | // Do resolution |
| 16641 | resolveTextDirection(); |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16642 | // Notify change |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 16643 | onRtlPropertiesChanged(getLayoutDirection()); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16644 | // Refresh |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16645 | requestLayout(); |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 16646 | invalidate(true); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16647 | } |
| 16648 | } |
| 16649 | |
| 16650 | /** |
| 16651 | * Return the resolved text direction. |
| 16652 | * |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16653 | * @return the resolved text direction. Returns one of: |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16654 | * |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 16655 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 16656 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16657 | * {@link #TEXT_DIRECTION_LTR}, |
| 16658 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16659 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16660 | */ |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16661 | public int getTextDirection() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16662 | 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] | 16663 | } |
| 16664 | |
| 16665 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16666 | * Resolve the text direction. |
| 16667 | * |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16668 | * @return true if resolution has been done, false otherwise. |
| 16669 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16670 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16671 | */ |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16672 | public boolean resolveTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16673 | // Reset any previous text direction resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16674 | mPrivateFlags2 &= ~(PFLAG2_TEXT_DIRECTION_RESOLVED | PFLAG2_TEXT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16675 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16676 | if (hasRtlSupport()) { |
| 16677 | // Set resolved text direction flag depending on text direction flag |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16678 | final int textDirection = getRawTextDirection(); |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16679 | switch(textDirection) { |
| 16680 | case TEXT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16681 | if (!canResolveTextDirection()) { |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16682 | // 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] | 16683 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16684 | // Resolution will need to happen again later |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16685 | return false; |
| 16686 | } |
| 16687 | |
| 16688 | View parent = ((View) mParent); |
| 16689 | // Parent has not yet resolved, so we still return the default |
| 16690 | if (!parent.isTextDirectionResolved()) { |
| 16691 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 16692 | // Resolution will need to happen again later |
| 16693 | return false; |
| 16694 | } |
| 16695 | |
| 16696 | // Set current resolved direction to the same value as the parent's one |
| 16697 | final int parentResolvedDirection = parent.getTextDirection(); |
| 16698 | switch (parentResolvedDirection) { |
| 16699 | case TEXT_DIRECTION_FIRST_STRONG: |
| 16700 | case TEXT_DIRECTION_ANY_RTL: |
| 16701 | case TEXT_DIRECTION_LTR: |
| 16702 | case TEXT_DIRECTION_RTL: |
| 16703 | case TEXT_DIRECTION_LOCALE: |
| 16704 | mPrivateFlags2 |= |
| 16705 | (parentResolvedDirection << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
| 16706 | break; |
| 16707 | default: |
| 16708 | // Default resolved direction is "first strong" heuristic |
| 16709 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16710 | } |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16711 | break; |
| 16712 | case TEXT_DIRECTION_FIRST_STRONG: |
| 16713 | case TEXT_DIRECTION_ANY_RTL: |
| 16714 | case TEXT_DIRECTION_LTR: |
| 16715 | case TEXT_DIRECTION_RTL: |
| 16716 | case TEXT_DIRECTION_LOCALE: |
| 16717 | // Resolved direction is the same as text direction |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16718 | mPrivateFlags2 |= (textDirection << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16719 | break; |
| 16720 | default: |
| 16721 | // Default resolved direction is "first strong" heuristic |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16722 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16723 | } |
| 16724 | } else { |
| 16725 | // Default resolved direction is "first strong" heuristic |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16726 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16727 | } |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16728 | |
| 16729 | // Set to resolved |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16730 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16731 | return true; |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16732 | } |
| 16733 | |
| 16734 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16735 | * Check if text direction resolution can be done. |
| 16736 | * |
| 16737 | * @return true if text direction resolution can be done otherwise return false. |
| 16738 | */ |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16739 | private boolean canResolveTextDirection() { |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16740 | switch (getRawTextDirection()) { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16741 | case TEXT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16742 | return (mParent != null) && (mParent instanceof View) && |
| 16743 | ((View) mParent).canResolveTextDirection(); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16744 | default: |
| 16745 | return true; |
| 16746 | } |
| 16747 | } |
| 16748 | |
| 16749 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16750 | * Reset resolved text direction. Text direction will be resolved during a call to |
| 16751 | * {@link #onMeasure(int, int)}. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16752 | * |
| 16753 | * @hide |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16754 | */ |
| 16755 | public void resetResolvedTextDirection() { |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16756 | // Reset any previous text direction resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16757 | mPrivateFlags2 &= ~(PFLAG2_TEXT_DIRECTION_RESOLVED | PFLAG2_TEXT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16758 | // Set to default value |
| 16759 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16760 | } |
| 16761 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16762 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16763 | * @return true if text direction is inherited. |
| 16764 | * |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16765 | * @hide |
| 16766 | */ |
| 16767 | public boolean isTextDirectionInherited() { |
| 16768 | return (getRawTextDirection() == TEXT_DIRECTION_INHERIT); |
| 16769 | } |
| 16770 | |
| 16771 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16772 | * @return true if text direction is resolved. |
| 16773 | */ |
| 16774 | private boolean isTextDirectionResolved() { |
| 16775 | return (mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_RESOLVED) == PFLAG2_TEXT_DIRECTION_RESOLVED; |
| 16776 | } |
| 16777 | |
| 16778 | /** |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16779 | * Return the value specifying the text alignment or policy that was set with |
| 16780 | * {@link #setTextAlignment(int)}. |
| 16781 | * |
| 16782 | * @return the defined text alignment. It can be one of: |
| 16783 | * |
| 16784 | * {@link #TEXT_ALIGNMENT_INHERIT}, |
| 16785 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 16786 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 16787 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 16788 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 16789 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 16790 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16791 | * |
| 16792 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16793 | */ |
| 16794 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 16795 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), |
| 16796 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_GRAVITY, to = "GRAVITY"), |
| 16797 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_START, to = "TEXT_START"), |
| 16798 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_END, to = "TEXT_END"), |
| 16799 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_CENTER, to = "CENTER"), |
| 16800 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), |
| 16801 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") |
| 16802 | }) |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16803 | public int getRawTextAlignment() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16804 | return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_MASK) >> PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16805 | } |
| 16806 | |
| 16807 | /** |
| 16808 | * Set the text alignment. |
| 16809 | * |
| 16810 | * @param textAlignment The text alignment to set. Should be one of |
| 16811 | * |
| 16812 | * {@link #TEXT_ALIGNMENT_INHERIT}, |
| 16813 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 16814 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 16815 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 16816 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 16817 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 16818 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
| 16819 | * |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16820 | * Resolution will be done if the value is set to TEXT_ALIGNMENT_INHERIT. The resolution |
| 16821 | * proceeds up the parent chain of the view to get the value. If there is no parent, then it |
| 16822 | * will return the default {@link #TEXT_ALIGNMENT_GRAVITY}. |
| 16823 | * |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16824 | * @attr ref android.R.styleable#View_textAlignment |
| 16825 | */ |
| 16826 | public void setTextAlignment(int textAlignment) { |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16827 | if (textAlignment != getRawTextAlignment()) { |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16828 | // Reset the current and resolved text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16829 | mPrivateFlags2 &= ~PFLAG2_TEXT_ALIGNMENT_MASK; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16830 | resetResolvedTextAlignment(); |
| 16831 | // Set the new text alignment |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16832 | mPrivateFlags2 |= |
| 16833 | ((textAlignment << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT) & PFLAG2_TEXT_ALIGNMENT_MASK); |
| 16834 | // Do resolution |
| 16835 | resolveTextAlignment(); |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16836 | // Notify change |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 16837 | onRtlPropertiesChanged(getLayoutDirection()); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16838 | // Refresh |
| 16839 | requestLayout(); |
| 16840 | invalidate(true); |
| 16841 | } |
| 16842 | } |
| 16843 | |
| 16844 | /** |
| 16845 | * Return the resolved text alignment. |
| 16846 | * |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16847 | * @return the resolved text alignment. Returns one of: |
| 16848 | * |
| 16849 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 16850 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 16851 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 16852 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 16853 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 16854 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
| 16855 | */ |
| 16856 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 16857 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), |
| 16858 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_GRAVITY, to = "GRAVITY"), |
| 16859 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_START, to = "TEXT_START"), |
| 16860 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_END, to = "TEXT_END"), |
| 16861 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_CENTER, to = "CENTER"), |
| 16862 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), |
| 16863 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") |
| 16864 | }) |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16865 | public int getTextAlignment() { |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16866 | return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK) >> |
| 16867 | PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16868 | } |
| 16869 | |
| 16870 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16871 | * Resolve the text alignment. |
| 16872 | * |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16873 | * @return true if resolution has been done, false otherwise. |
| 16874 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16875 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16876 | */ |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16877 | public boolean resolveTextAlignment() { |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16878 | // Reset any previous text alignment resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16879 | mPrivateFlags2 &= ~(PFLAG2_TEXT_ALIGNMENT_RESOLVED | PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16880 | |
| 16881 | if (hasRtlSupport()) { |
| 16882 | // Set resolved text alignment flag depending on text alignment flag |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16883 | final int textAlignment = getRawTextAlignment(); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16884 | switch (textAlignment) { |
| 16885 | case TEXT_ALIGNMENT_INHERIT: |
| 16886 | // Check if we can resolve the text alignment |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16887 | if (!canResolveTextAlignment()) { |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16888 | // 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] | 16889 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16890 | // Resolution will need to happen again later |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16891 | return false; |
| 16892 | } |
| 16893 | View parent = (View) mParent; |
| 16894 | |
| 16895 | // Parent has not yet resolved, so we still return the default |
| 16896 | if (!parent.isTextAlignmentResolved()) { |
| 16897 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 16898 | // Resolution will need to happen again later |
| 16899 | return false; |
| 16900 | } |
| 16901 | |
| 16902 | final int parentResolvedTextAlignment = parent.getTextAlignment(); |
| 16903 | switch (parentResolvedTextAlignment) { |
| 16904 | case TEXT_ALIGNMENT_GRAVITY: |
| 16905 | case TEXT_ALIGNMENT_TEXT_START: |
| 16906 | case TEXT_ALIGNMENT_TEXT_END: |
| 16907 | case TEXT_ALIGNMENT_CENTER: |
| 16908 | case TEXT_ALIGNMENT_VIEW_START: |
| 16909 | case TEXT_ALIGNMENT_VIEW_END: |
| 16910 | // Resolved text alignment is the same as the parent resolved |
| 16911 | // text alignment |
| 16912 | mPrivateFlags2 |= |
| 16913 | (parentResolvedTextAlignment << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT); |
| 16914 | break; |
| 16915 | default: |
| 16916 | // Use default resolved text alignment |
| 16917 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16918 | } |
| 16919 | break; |
| 16920 | case TEXT_ALIGNMENT_GRAVITY: |
| 16921 | case TEXT_ALIGNMENT_TEXT_START: |
| 16922 | case TEXT_ALIGNMENT_TEXT_END: |
| 16923 | case TEXT_ALIGNMENT_CENTER: |
| 16924 | case TEXT_ALIGNMENT_VIEW_START: |
| 16925 | case TEXT_ALIGNMENT_VIEW_END: |
| 16926 | // Resolved text alignment is the same as text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16927 | mPrivateFlags2 |= (textAlignment << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16928 | break; |
| 16929 | default: |
| 16930 | // Use default resolved text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16931 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16932 | } |
| 16933 | } else { |
| 16934 | // Use default resolved text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16935 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16936 | } |
| 16937 | |
| 16938 | // Set the resolved |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16939 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED; |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16940 | return true; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16941 | } |
| 16942 | |
| 16943 | /** |
| 16944 | * Check if text alignment resolution can be done. |
| 16945 | * |
| 16946 | * @return true if text alignment resolution can be done otherwise return false. |
| 16947 | */ |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16948 | private boolean canResolveTextAlignment() { |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16949 | switch (getRawTextAlignment()) { |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16950 | case TEXT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16951 | return (mParent != null) && (mParent instanceof View) && |
| 16952 | ((View) mParent).canResolveTextAlignment(); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16953 | default: |
| 16954 | return true; |
| 16955 | } |
| 16956 | } |
| 16957 | |
| 16958 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16959 | * Reset resolved text alignment. Text alignment will be resolved during a call to |
| 16960 | * {@link #onMeasure(int, int)}. |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16961 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16962 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16963 | */ |
| 16964 | public void resetResolvedTextAlignment() { |
| 16965 | // Reset any previous text alignment resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16966 | mPrivateFlags2 &= ~(PFLAG2_TEXT_ALIGNMENT_RESOLVED | PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16967 | // Set to default |
| 16968 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16969 | } |
| 16970 | |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 16971 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16972 | * @return true if text alignment is inherited. |
| 16973 | * |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16974 | * @hide |
| 16975 | */ |
| 16976 | public boolean isTextAlignmentInherited() { |
| 16977 | return (getRawTextAlignment() == TEXT_ALIGNMENT_INHERIT); |
| 16978 | } |
| 16979 | |
| 16980 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16981 | * @return true if text alignment is resolved. |
| 16982 | */ |
| 16983 | private boolean isTextAlignmentResolved() { |
| 16984 | return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_RESOLVED) == PFLAG2_TEXT_ALIGNMENT_RESOLVED; |
| 16985 | } |
| 16986 | |
| 16987 | /** |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 16988 | * Generate a value suitable for use in {@link #setId(int)}. |
| 16989 | * This value will not collide with ID values generated at build time by aapt for R.id. |
| 16990 | * |
| 16991 | * @return a generated ID value |
| 16992 | */ |
| 16993 | public static int generateViewId() { |
| 16994 | for (;;) { |
| 16995 | final int result = sNextGeneratedId.get(); |
| 16996 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that. |
| 16997 | int newValue = result + 1; |
| 16998 | if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. |
| 16999 | if (sNextGeneratedId.compareAndSet(result, newValue)) { |
| 17000 | return result; |
| 17001 | } |
| 17002 | } |
| 17003 | } |
| 17004 | |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17005 | // |
| 17006 | // Properties |
| 17007 | // |
| 17008 | /** |
| 17009 | * A Property wrapper around the <code>alpha</code> functionality handled by the |
| 17010 | * {@link View#setAlpha(float)} and {@link View#getAlpha()} methods. |
| 17011 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17012 | public static final Property<View, Float> ALPHA = new FloatProperty<View>("alpha") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17013 | @Override |
| 17014 | public void setValue(View object, float value) { |
| 17015 | object.setAlpha(value); |
| 17016 | } |
| 17017 | |
| 17018 | @Override |
| 17019 | public Float get(View object) { |
| 17020 | return object.getAlpha(); |
| 17021 | } |
| 17022 | }; |
| 17023 | |
| 17024 | /** |
| 17025 | * A Property wrapper around the <code>translationX</code> functionality handled by the |
| 17026 | * {@link View#setTranslationX(float)} and {@link View#getTranslationX()} methods. |
| 17027 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17028 | public static final Property<View, Float> TRANSLATION_X = new FloatProperty<View>("translationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17029 | @Override |
| 17030 | public void setValue(View object, float value) { |
| 17031 | object.setTranslationX(value); |
| 17032 | } |
| 17033 | |
| 17034 | @Override |
| 17035 | public Float get(View object) { |
| 17036 | return object.getTranslationX(); |
| 17037 | } |
| 17038 | }; |
| 17039 | |
| 17040 | /** |
| 17041 | * A Property wrapper around the <code>translationY</code> functionality handled by the |
| 17042 | * {@link View#setTranslationY(float)} and {@link View#getTranslationY()} methods. |
| 17043 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17044 | public static final Property<View, Float> TRANSLATION_Y = new FloatProperty<View>("translationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17045 | @Override |
| 17046 | public void setValue(View object, float value) { |
| 17047 | object.setTranslationY(value); |
| 17048 | } |
| 17049 | |
| 17050 | @Override |
| 17051 | public Float get(View object) { |
| 17052 | return object.getTranslationY(); |
| 17053 | } |
| 17054 | }; |
| 17055 | |
| 17056 | /** |
| 17057 | * A Property wrapper around the <code>x</code> functionality handled by the |
| 17058 | * {@link View#setX(float)} and {@link View#getX()} methods. |
| 17059 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17060 | public static final Property<View, Float> X = new FloatProperty<View>("x") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17061 | @Override |
| 17062 | public void setValue(View object, float value) { |
| 17063 | object.setX(value); |
| 17064 | } |
| 17065 | |
| 17066 | @Override |
| 17067 | public Float get(View object) { |
| 17068 | return object.getX(); |
| 17069 | } |
| 17070 | }; |
| 17071 | |
| 17072 | /** |
| 17073 | * A Property wrapper around the <code>y</code> functionality handled by the |
| 17074 | * {@link View#setY(float)} and {@link View#getY()} methods. |
| 17075 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17076 | public static final Property<View, Float> Y = new FloatProperty<View>("y") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17077 | @Override |
| 17078 | public void setValue(View object, float value) { |
| 17079 | object.setY(value); |
| 17080 | } |
| 17081 | |
| 17082 | @Override |
| 17083 | public Float get(View object) { |
| 17084 | return object.getY(); |
| 17085 | } |
| 17086 | }; |
| 17087 | |
| 17088 | /** |
| 17089 | * A Property wrapper around the <code>rotation</code> functionality handled by the |
| 17090 | * {@link View#setRotation(float)} and {@link View#getRotation()} methods. |
| 17091 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17092 | public static final Property<View, Float> ROTATION = new FloatProperty<View>("rotation") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17093 | @Override |
| 17094 | public void setValue(View object, float value) { |
| 17095 | object.setRotation(value); |
| 17096 | } |
| 17097 | |
| 17098 | @Override |
| 17099 | public Float get(View object) { |
| 17100 | return object.getRotation(); |
| 17101 | } |
| 17102 | }; |
| 17103 | |
| 17104 | /** |
| 17105 | * A Property wrapper around the <code>rotationX</code> functionality handled by the |
| 17106 | * {@link View#setRotationX(float)} and {@link View#getRotationX()} methods. |
| 17107 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17108 | public static final Property<View, Float> ROTATION_X = new FloatProperty<View>("rotationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17109 | @Override |
| 17110 | public void setValue(View object, float value) { |
| 17111 | object.setRotationX(value); |
| 17112 | } |
| 17113 | |
| 17114 | @Override |
| 17115 | public Float get(View object) { |
| 17116 | return object.getRotationX(); |
| 17117 | } |
| 17118 | }; |
| 17119 | |
| 17120 | /** |
| 17121 | * A Property wrapper around the <code>rotationY</code> functionality handled by the |
| 17122 | * {@link View#setRotationY(float)} and {@link View#getRotationY()} methods. |
| 17123 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17124 | public static final Property<View, Float> ROTATION_Y = new FloatProperty<View>("rotationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17125 | @Override |
| 17126 | public void setValue(View object, float value) { |
| 17127 | object.setRotationY(value); |
| 17128 | } |
| 17129 | |
| 17130 | @Override |
| 17131 | public Float get(View object) { |
| 17132 | return object.getRotationY(); |
| 17133 | } |
| 17134 | }; |
| 17135 | |
| 17136 | /** |
| 17137 | * A Property wrapper around the <code>scaleX</code> functionality handled by the |
| 17138 | * {@link View#setScaleX(float)} and {@link View#getScaleX()} methods. |
| 17139 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17140 | public static final Property<View, Float> SCALE_X = new FloatProperty<View>("scaleX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17141 | @Override |
| 17142 | public void setValue(View object, float value) { |
| 17143 | object.setScaleX(value); |
| 17144 | } |
| 17145 | |
| 17146 | @Override |
| 17147 | public Float get(View object) { |
| 17148 | return object.getScaleX(); |
| 17149 | } |
| 17150 | }; |
| 17151 | |
| 17152 | /** |
| 17153 | * A Property wrapper around the <code>scaleY</code> functionality handled by the |
| 17154 | * {@link View#setScaleY(float)} and {@link View#getScaleY()} methods. |
| 17155 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17156 | public static final Property<View, Float> SCALE_Y = new FloatProperty<View>("scaleY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17157 | @Override |
| 17158 | public void setValue(View object, float value) { |
| 17159 | object.setScaleY(value); |
| 17160 | } |
| 17161 | |
| 17162 | @Override |
| 17163 | public Float get(View object) { |
| 17164 | return object.getScaleY(); |
| 17165 | } |
| 17166 | }; |
| 17167 | |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 17168 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17169 | * A MeasureSpec encapsulates the layout requirements passed from parent to child. |
| 17170 | * Each MeasureSpec represents a requirement for either the width or the height. |
| 17171 | * A MeasureSpec is comprised of a size and a mode. There are three possible |
| 17172 | * modes: |
| 17173 | * <dl> |
| 17174 | * <dt>UNSPECIFIED</dt> |
| 17175 | * <dd> |
| 17176 | * The parent has not imposed any constraint on the child. It can be whatever size |
| 17177 | * it wants. |
| 17178 | * </dd> |
| 17179 | * |
| 17180 | * <dt>EXACTLY</dt> |
| 17181 | * <dd> |
| 17182 | * The parent has determined an exact size for the child. The child is going to be |
| 17183 | * given those bounds regardless of how big it wants to be. |
| 17184 | * </dd> |
| 17185 | * |
| 17186 | * <dt>AT_MOST</dt> |
| 17187 | * <dd> |
| 17188 | * The child can be as large as it wants up to the specified size. |
| 17189 | * </dd> |
| 17190 | * </dl> |
| 17191 | * |
| 17192 | * MeasureSpecs are implemented as ints to reduce object allocation. This class |
| 17193 | * is provided to pack and unpack the <size, mode> tuple into the int. |
| 17194 | */ |
| 17195 | public static class MeasureSpec { |
| 17196 | private static final int MODE_SHIFT = 30; |
| 17197 | private static final int MODE_MASK = 0x3 << MODE_SHIFT; |
| 17198 | |
| 17199 | /** |
| 17200 | * Measure specification mode: The parent has not imposed any constraint |
| 17201 | * on the child. It can be whatever size it wants. |
| 17202 | */ |
| 17203 | public static final int UNSPECIFIED = 0 << MODE_SHIFT; |
| 17204 | |
| 17205 | /** |
| 17206 | * Measure specification mode: The parent has determined an exact size |
| 17207 | * for the child. The child is going to be given those bounds regardless |
| 17208 | * of how big it wants to be. |
| 17209 | */ |
| 17210 | public static final int EXACTLY = 1 << MODE_SHIFT; |
| 17211 | |
| 17212 | /** |
| 17213 | * Measure specification mode: The child can be as large as it wants up |
| 17214 | * to the specified size. |
| 17215 | */ |
| 17216 | public static final int AT_MOST = 2 << MODE_SHIFT; |
| 17217 | |
| 17218 | /** |
| 17219 | * Creates a measure specification based on the supplied size and mode. |
| 17220 | * |
| 17221 | * The mode must always be one of the following: |
| 17222 | * <ul> |
| 17223 | * <li>{@link android.view.View.MeasureSpec#UNSPECIFIED}</li> |
| 17224 | * <li>{@link android.view.View.MeasureSpec#EXACTLY}</li> |
| 17225 | * <li>{@link android.view.View.MeasureSpec#AT_MOST}</li> |
| 17226 | * </ul> |
| 17227 | * |
| 17228 | * @param size the size of the measure specification |
| 17229 | * @param mode the mode of the measure specification |
| 17230 | * @return the measure specification based on size and mode |
| 17231 | */ |
| 17232 | public static int makeMeasureSpec(int size, int mode) { |
Adam Powell | 946d05b | 2012-10-01 15:06:20 -0700 | [diff] [blame] | 17233 | return size + mode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17234 | } |
| 17235 | |
| 17236 | /** |
| 17237 | * Extracts the mode from the supplied measure specification. |
| 17238 | * |
| 17239 | * @param measureSpec the measure specification to extract the mode from |
| 17240 | * @return {@link android.view.View.MeasureSpec#UNSPECIFIED}, |
| 17241 | * {@link android.view.View.MeasureSpec#AT_MOST} or |
| 17242 | * {@link android.view.View.MeasureSpec#EXACTLY} |
| 17243 | */ |
| 17244 | public static int getMode(int measureSpec) { |
| 17245 | return (measureSpec & MODE_MASK); |
| 17246 | } |
| 17247 | |
| 17248 | /** |
| 17249 | * Extracts the size from the supplied measure specification. |
| 17250 | * |
| 17251 | * @param measureSpec the measure specification to extract the size from |
| 17252 | * @return the size in pixels defined in the supplied measure specification |
| 17253 | */ |
| 17254 | public static int getSize(int measureSpec) { |
| 17255 | return (measureSpec & ~MODE_MASK); |
| 17256 | } |
| 17257 | |
| 17258 | /** |
| 17259 | * Returns a String representation of the specified measure |
| 17260 | * specification. |
| 17261 | * |
| 17262 | * @param measureSpec the measure specification to convert to a String |
| 17263 | * @return a String with the following format: "MeasureSpec: MODE SIZE" |
| 17264 | */ |
| 17265 | public static String toString(int measureSpec) { |
| 17266 | int mode = getMode(measureSpec); |
| 17267 | int size = getSize(measureSpec); |
| 17268 | |
| 17269 | StringBuilder sb = new StringBuilder("MeasureSpec: "); |
| 17270 | |
| 17271 | if (mode == UNSPECIFIED) |
| 17272 | sb.append("UNSPECIFIED "); |
| 17273 | else if (mode == EXACTLY) |
| 17274 | sb.append("EXACTLY "); |
| 17275 | else if (mode == AT_MOST) |
| 17276 | sb.append("AT_MOST "); |
| 17277 | else |
| 17278 | sb.append(mode).append(" "); |
| 17279 | |
| 17280 | sb.append(size); |
| 17281 | return sb.toString(); |
| 17282 | } |
| 17283 | } |
| 17284 | |
| 17285 | class CheckForLongPress implements Runnable { |
| 17286 | |
| 17287 | private int mOriginalWindowAttachCount; |
| 17288 | |
| 17289 | public void run() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 17290 | if (isPressed() && (mParent != null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17291 | && mOriginalWindowAttachCount == mWindowAttachCount) { |
| 17292 | if (performLongClick()) { |
| 17293 | mHasPerformedLongPress = true; |
| 17294 | } |
| 17295 | } |
| 17296 | } |
| 17297 | |
| 17298 | public void rememberWindowAttachCount() { |
| 17299 | mOriginalWindowAttachCount = mWindowAttachCount; |
| 17300 | } |
| 17301 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17302 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 17303 | private final class CheckForTap implements Runnable { |
| 17304 | public void run() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17305 | mPrivateFlags &= ~PFLAG_PREPRESSED; |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 17306 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 17307 | checkForLongClick(ViewConfiguration.getTapTimeout()); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 17308 | } |
| 17309 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17310 | |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 17311 | private final class PerformClick implements Runnable { |
| 17312 | public void run() { |
| 17313 | performClick(); |
| 17314 | } |
| 17315 | } |
| 17316 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 17317 | /** @hide */ |
| 17318 | public void hackTurnOffWindowResizeAnim(boolean off) { |
| 17319 | mAttachInfo.mTurnOffWindowResizeAnim = off; |
| 17320 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17322 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 17323 | * This method returns a ViewPropertyAnimator object, which can be used to animate |
| 17324 | * specific properties on this View. |
| 17325 | * |
| 17326 | * @return ViewPropertyAnimator The ViewPropertyAnimator associated with this View. |
| 17327 | */ |
| 17328 | public ViewPropertyAnimator animate() { |
| 17329 | if (mAnimator == null) { |
| 17330 | mAnimator = new ViewPropertyAnimator(this); |
| 17331 | } |
| 17332 | return mAnimator; |
| 17333 | } |
| 17334 | |
| 17335 | /** |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 17336 | * Interface definition for a callback to be invoked when a hardware key event is |
| 17337 | * dispatched to this view. The callback will be invoked before the key event is |
| 17338 | * given to the view. This is only useful for hardware keyboards; a software input |
| 17339 | * method has no obligation to trigger this listener. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17340 | */ |
| 17341 | public interface OnKeyListener { |
| 17342 | /** |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 17343 | * 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] | 17344 | * get a chance to respond before the target view. |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 17345 | * <p>Key presses in software keyboards will generally NOT trigger this method, |
| 17346 | * although some may elect to do so in some situations. Do not assume a |
| 17347 | * software input method has to be key-based; even if it is, it may use key presses |
| 17348 | * in a different way than you expect, so there is no way to reliably catch soft |
| 17349 | * input key presses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17350 | * |
| 17351 | * @param v The view the key has been dispatched to. |
| 17352 | * @param keyCode The code for the physical key that was pressed |
| 17353 | * @param event The KeyEvent object containing full information about |
| 17354 | * the event. |
| 17355 | * @return True if the listener has consumed the event, false otherwise. |
| 17356 | */ |
| 17357 | boolean onKey(View v, int keyCode, KeyEvent event); |
| 17358 | } |
| 17359 | |
| 17360 | /** |
| 17361 | * Interface definition for a callback to be invoked when a touch event is |
| 17362 | * dispatched to this view. The callback will be invoked before the touch |
| 17363 | * event is given to the view. |
| 17364 | */ |
| 17365 | public interface OnTouchListener { |
| 17366 | /** |
| 17367 | * Called when a touch event is dispatched to a view. This allows listeners to |
| 17368 | * get a chance to respond before the target view. |
| 17369 | * |
| 17370 | * @param v The view the touch event has been dispatched to. |
| 17371 | * @param event The MotionEvent object containing full information about |
| 17372 | * the event. |
| 17373 | * @return True if the listener has consumed the event, false otherwise. |
| 17374 | */ |
| 17375 | boolean onTouch(View v, MotionEvent event); |
| 17376 | } |
| 17377 | |
| 17378 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 17379 | * Interface definition for a callback to be invoked when a hover event is |
| 17380 | * dispatched to this view. The callback will be invoked before the hover |
| 17381 | * event is given to the view. |
| 17382 | */ |
| 17383 | public interface OnHoverListener { |
| 17384 | /** |
| 17385 | * Called when a hover event is dispatched to a view. This allows listeners to |
| 17386 | * get a chance to respond before the target view. |
| 17387 | * |
| 17388 | * @param v The view the hover event has been dispatched to. |
| 17389 | * @param event The MotionEvent object containing full information about |
| 17390 | * the event. |
| 17391 | * @return True if the listener has consumed the event, false otherwise. |
| 17392 | */ |
| 17393 | boolean onHover(View v, MotionEvent event); |
| 17394 | } |
| 17395 | |
| 17396 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 17397 | * Interface definition for a callback to be invoked when a generic motion event is |
| 17398 | * dispatched to this view. The callback will be invoked before the generic motion |
| 17399 | * event is given to the view. |
| 17400 | */ |
| 17401 | public interface OnGenericMotionListener { |
| 17402 | /** |
| 17403 | * Called when a generic motion event is dispatched to a view. This allows listeners to |
| 17404 | * get a chance to respond before the target view. |
| 17405 | * |
| 17406 | * @param v The view the generic motion event has been dispatched to. |
| 17407 | * @param event The MotionEvent object containing full information about |
| 17408 | * the event. |
| 17409 | * @return True if the listener has consumed the event, false otherwise. |
| 17410 | */ |
| 17411 | boolean onGenericMotion(View v, MotionEvent event); |
| 17412 | } |
| 17413 | |
| 17414 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17415 | * Interface definition for a callback to be invoked when a view has been clicked and held. |
| 17416 | */ |
| 17417 | public interface OnLongClickListener { |
| 17418 | /** |
| 17419 | * Called when a view has been clicked and held. |
| 17420 | * |
| 17421 | * @param v The view that was clicked and held. |
| 17422 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 17423 | * @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] | 17424 | */ |
| 17425 | boolean onLongClick(View v); |
| 17426 | } |
| 17427 | |
| 17428 | /** |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 17429 | * Interface definition for a callback to be invoked when a drag is being dispatched |
| 17430 | * to this view. The callback will be invoked before the hosting view's own |
| 17431 | * onDrag(event) method. If the listener wants to fall back to the hosting view's |
| 17432 | * onDrag(event) behavior, it should return 'false' from this callback. |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 17433 | * |
| 17434 | * <div class="special reference"> |
| 17435 | * <h3>Developer Guides</h3> |
| 17436 | * <p>For a guide to implementing drag and drop features, read the |
| 17437 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 17438 | * </div> |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 17439 | */ |
| 17440 | public interface OnDragListener { |
| 17441 | /** |
| 17442 | * Called when a drag event is dispatched to a view. This allows listeners |
| 17443 | * to get a chance to override base View behavior. |
| 17444 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17445 | * @param v The View that received the drag event. |
| 17446 | * @param event The {@link android.view.DragEvent} object for the drag event. |
| 17447 | * @return {@code true} if the drag event was handled successfully, or {@code false} |
| 17448 | * if the drag event was not handled. Note that {@code false} will trigger the View |
| 17449 | * to call its {@link #onDragEvent(DragEvent) onDragEvent()} handler. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 17450 | */ |
| 17451 | boolean onDrag(View v, DragEvent event); |
| 17452 | } |
| 17453 | |
| 17454 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17455 | * Interface definition for a callback to be invoked when the focus state of |
| 17456 | * a view changed. |
| 17457 | */ |
| 17458 | public interface OnFocusChangeListener { |
| 17459 | /** |
| 17460 | * Called when the focus state of a view has changed. |
| 17461 | * |
| 17462 | * @param v The view whose state has changed. |
| 17463 | * @param hasFocus The new focus state of v. |
| 17464 | */ |
| 17465 | void onFocusChange(View v, boolean hasFocus); |
| 17466 | } |
| 17467 | |
| 17468 | /** |
| 17469 | * Interface definition for a callback to be invoked when a view is clicked. |
| 17470 | */ |
| 17471 | public interface OnClickListener { |
| 17472 | /** |
| 17473 | * Called when a view has been clicked. |
| 17474 | * |
| 17475 | * @param v The view that was clicked. |
| 17476 | */ |
| 17477 | void onClick(View v); |
| 17478 | } |
| 17479 | |
| 17480 | /** |
| 17481 | * Interface definition for a callback to be invoked when the context menu |
| 17482 | * for this view is being built. |
| 17483 | */ |
| 17484 | public interface OnCreateContextMenuListener { |
| 17485 | /** |
| 17486 | * Called when the context menu for this view is being built. It is not |
| 17487 | * safe to hold onto the menu after this method returns. |
| 17488 | * |
| 17489 | * @param menu The context menu that is being built |
| 17490 | * @param v The view for which the context menu is being built |
| 17491 | * @param menuInfo Extra information about the item for which the |
| 17492 | * context menu should be shown. This information will vary |
| 17493 | * depending on the class of v. |
| 17494 | */ |
| 17495 | void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo); |
| 17496 | } |
| 17497 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17498 | /** |
| 17499 | * 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] | 17500 | * visibility. This reports <strong>global</strong> changes to the system UI |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 17501 | * state, not what the application is requesting. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17502 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 17503 | * @see View#setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17504 | */ |
| 17505 | public interface OnSystemUiVisibilityChangeListener { |
| 17506 | /** |
| 17507 | * Called when the status bar changes visibility because of a call to |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 17508 | * {@link View#setSystemUiVisibility(int)}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17509 | * |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 17510 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 17511 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, and {@link #SYSTEM_UI_FLAG_FULLSCREEN}. |
| 17512 | * This tells you the <strong>global</strong> state of these UI visibility |
| 17513 | * flags, not what your app is currently applying. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17514 | */ |
| 17515 | public void onSystemUiVisibilityChange(int visibility); |
| 17516 | } |
| 17517 | |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 17518 | /** |
| 17519 | * Interface definition for a callback to be invoked when this view is attached |
| 17520 | * or detached from its window. |
| 17521 | */ |
| 17522 | public interface OnAttachStateChangeListener { |
| 17523 | /** |
| 17524 | * Called when the view is attached to a window. |
| 17525 | * @param v The view that was attached |
| 17526 | */ |
| 17527 | public void onViewAttachedToWindow(View v); |
| 17528 | /** |
| 17529 | * Called when the view is detached from a window. |
| 17530 | * @param v The view that was detached |
| 17531 | */ |
| 17532 | public void onViewDetachedFromWindow(View v); |
| 17533 | } |
| 17534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17535 | private final class UnsetPressedState implements Runnable { |
| 17536 | public void run() { |
| 17537 | setPressed(false); |
| 17538 | } |
| 17539 | } |
| 17540 | |
| 17541 | /** |
| 17542 | * Base class for derived classes that want to save and restore their own |
| 17543 | * state in {@link android.view.View#onSaveInstanceState()}. |
| 17544 | */ |
| 17545 | public static class BaseSavedState extends AbsSavedState { |
| 17546 | /** |
| 17547 | * Constructor used when reading from a parcel. Reads the state of the superclass. |
| 17548 | * |
| 17549 | * @param source |
| 17550 | */ |
| 17551 | public BaseSavedState(Parcel source) { |
| 17552 | super(source); |
| 17553 | } |
| 17554 | |
| 17555 | /** |
| 17556 | * Constructor called by derived classes when creating their SavedState objects |
| 17557 | * |
| 17558 | * @param superState The state of the superclass of this view |
| 17559 | */ |
| 17560 | public BaseSavedState(Parcelable superState) { |
| 17561 | super(superState); |
| 17562 | } |
| 17563 | |
| 17564 | public static final Parcelable.Creator<BaseSavedState> CREATOR = |
| 17565 | new Parcelable.Creator<BaseSavedState>() { |
| 17566 | public BaseSavedState createFromParcel(Parcel in) { |
| 17567 | return new BaseSavedState(in); |
| 17568 | } |
| 17569 | |
| 17570 | public BaseSavedState[] newArray(int size) { |
| 17571 | return new BaseSavedState[size]; |
| 17572 | } |
| 17573 | }; |
| 17574 | } |
| 17575 | |
| 17576 | /** |
| 17577 | * A set of information given to a view when it is attached to its parent |
| 17578 | * window. |
| 17579 | */ |
| 17580 | static class AttachInfo { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17581 | interface Callbacks { |
| 17582 | void playSoundEffect(int effectId); |
| 17583 | boolean performHapticFeedback(int effectId, boolean always); |
| 17584 | } |
| 17585 | |
| 17586 | /** |
| 17587 | * InvalidateInfo is used to post invalidate(int, int, int, int) messages |
| 17588 | * to a Handler. This class contains the target (View) to invalidate and |
| 17589 | * the coordinates of the dirty rectangle. |
| 17590 | * |
| 17591 | * For performance purposes, this class also implements a pool of up to |
| 17592 | * POOL_LIMIT objects that get reused. This reduces memory allocations |
| 17593 | * whenever possible. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17594 | */ |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17595 | static class InvalidateInfo implements Poolable<InvalidateInfo> { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17596 | private static final int POOL_LIMIT = 10; |
Romain Guy | 2e9bbce | 2009-04-01 10:40:10 -0700 | [diff] [blame] | 17597 | private static final Pool<InvalidateInfo> sPool = Pools.synchronizedPool( |
| 17598 | Pools.finitePool(new PoolableManager<InvalidateInfo>() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17599 | public InvalidateInfo newInstance() { |
| 17600 | return new InvalidateInfo(); |
| 17601 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17602 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17603 | public void onAcquired(InvalidateInfo element) { |
| 17604 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17605 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17606 | public void onReleased(InvalidateInfo element) { |
Romain Guy | 40c18f5 | 2011-09-01 17:01:18 -0700 | [diff] [blame] | 17607 | element.target = null; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17608 | } |
| 17609 | }, POOL_LIMIT) |
| 17610 | ); |
| 17611 | |
| 17612 | private InvalidateInfo mNext; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 17613 | private boolean mIsPooled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17614 | |
| 17615 | View target; |
| 17616 | |
| 17617 | int left; |
| 17618 | int top; |
| 17619 | int right; |
| 17620 | int bottom; |
| 17621 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17622 | public void setNextPoolable(InvalidateInfo element) { |
| 17623 | mNext = element; |
| 17624 | } |
| 17625 | |
| 17626 | public InvalidateInfo getNextPoolable() { |
| 17627 | return mNext; |
| 17628 | } |
| 17629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17630 | static InvalidateInfo acquire() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17631 | return sPool.acquire(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17632 | } |
| 17633 | |
| 17634 | void release() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17635 | sPool.release(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17636 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 17637 | |
| 17638 | public boolean isPooled() { |
| 17639 | return mIsPooled; |
| 17640 | } |
| 17641 | |
| 17642 | public void setPooled(boolean isPooled) { |
| 17643 | mIsPooled = isPooled; |
| 17644 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17645 | } |
| 17646 | |
| 17647 | final IWindowSession mSession; |
| 17648 | |
| 17649 | final IWindow mWindow; |
| 17650 | |
| 17651 | final IBinder mWindowToken; |
| 17652 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 17653 | final Display mDisplay; |
| 17654 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17655 | final Callbacks mRootCallbacks; |
| 17656 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 17657 | HardwareCanvas mHardwareCanvas; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 17658 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17659 | /** |
| 17660 | * The top view of the hierarchy. |
| 17661 | */ |
| 17662 | View mRootView; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17663 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17664 | IBinder mPanelParentWindowToken; |
| 17665 | Surface mSurface; |
| 17666 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 17667 | boolean mHardwareAccelerated; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 17668 | boolean mHardwareAccelerationRequested; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 17669 | HardwareRenderer mHardwareRenderer; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17670 | |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 17671 | boolean mScreenOn; |
| 17672 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17673 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17674 | * Scale factor used by the compatibility mode |
| 17675 | */ |
| 17676 | float mApplicationScale; |
| 17677 | |
| 17678 | /** |
| 17679 | * Indicates whether the application is in compatibility mode |
| 17680 | */ |
| 17681 | boolean mScalingRequired; |
| 17682 | |
| 17683 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 17684 | * If set, ViewAncestor doesn't use its lame animation for when the window resizes. |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 17685 | */ |
| 17686 | boolean mTurnOffWindowResizeAnim; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17687 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 17688 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17689 | * Left position of this view's window |
| 17690 | */ |
| 17691 | int mWindowLeft; |
| 17692 | |
| 17693 | /** |
| 17694 | * Top position of this view's window |
| 17695 | */ |
| 17696 | int mWindowTop; |
| 17697 | |
| 17698 | /** |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 17699 | * Indicates whether views need to use 32-bit drawing caches |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 17700 | */ |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 17701 | boolean mUse32BitDrawingCache; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 17702 | |
| 17703 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17704 | * For windows that are full-screen but using insets to layout inside |
| 17705 | * of the screen decorations, these are the current insets for the |
| 17706 | * content of the window. |
| 17707 | */ |
| 17708 | final Rect mContentInsets = new Rect(); |
| 17709 | |
| 17710 | /** |
| 17711 | * For windows that are full-screen but using insets to layout inside |
| 17712 | * of the screen decorations, these are the current insets for the |
| 17713 | * actual visible parts of the window. |
| 17714 | */ |
| 17715 | final Rect mVisibleInsets = new Rect(); |
| 17716 | |
| 17717 | /** |
| 17718 | * The internal insets given by this window. This value is |
| 17719 | * supplied by the client (through |
| 17720 | * {@link ViewTreeObserver.OnComputeInternalInsetsListener}) and will |
| 17721 | * be given to the window manager when changed to be used in laying |
| 17722 | * out windows behind it. |
| 17723 | */ |
| 17724 | final ViewTreeObserver.InternalInsetsInfo mGivenInternalInsets |
| 17725 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 17726 | |
| 17727 | /** |
| 17728 | * All views in the window's hierarchy that serve as scroll containers, |
| 17729 | * used to determine if the window can be resized or must be panned |
| 17730 | * to adjust for a soft input area. |
| 17731 | */ |
| 17732 | final ArrayList<View> mScrollContainers = new ArrayList<View>(); |
| 17733 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 17734 | final KeyEvent.DispatcherState mKeyDispatchState |
| 17735 | = new KeyEvent.DispatcherState(); |
| 17736 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17737 | /** |
| 17738 | * Indicates whether the view's window currently has the focus. |
| 17739 | */ |
| 17740 | boolean mHasWindowFocus; |
| 17741 | |
| 17742 | /** |
| 17743 | * The current visibility of the window. |
| 17744 | */ |
| 17745 | int mWindowVisibility; |
| 17746 | |
| 17747 | /** |
| 17748 | * Indicates the time at which drawing started to occur. |
| 17749 | */ |
| 17750 | long mDrawingTime; |
| 17751 | |
| 17752 | /** |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 17753 | * Indicates whether or not ignoring the DIRTY_MASK flags. |
| 17754 | */ |
| 17755 | boolean mIgnoreDirtyState; |
| 17756 | |
| 17757 | /** |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 17758 | * This flag tracks when the mIgnoreDirtyState flag is set during draw(), |
| 17759 | * to avoid clearing that flag prematurely. |
| 17760 | */ |
| 17761 | boolean mSetIgnoreDirtyState = false; |
| 17762 | |
| 17763 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17764 | * Indicates whether the view's window is currently in touch mode. |
| 17765 | */ |
| 17766 | boolean mInTouchMode; |
| 17767 | |
| 17768 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 17769 | * Indicates that ViewAncestor should trigger a global layout change |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17770 | * the next time it performs a traversal |
| 17771 | */ |
| 17772 | boolean mRecomputeGlobalAttributes; |
| 17773 | |
| 17774 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 17775 | * Always report new attributes at next traversal. |
| 17776 | */ |
| 17777 | boolean mForceReportNewAttributes; |
| 17778 | |
| 17779 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17780 | * Set during a traveral if any views want to keep the screen on. |
| 17781 | */ |
| 17782 | boolean mKeepScreenOn; |
| 17783 | |
| 17784 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17785 | * Bitwise-or of all of the values that views have passed to setSystemUiVisibility(). |
| 17786 | */ |
| 17787 | int mSystemUiVisibility; |
| 17788 | |
| 17789 | /** |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 17790 | * Hack to force certain system UI visibility flags to be cleared. |
| 17791 | */ |
| 17792 | int mDisabledSystemUiVisibility; |
| 17793 | |
| 17794 | /** |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 17795 | * Last global system UI visibility reported by the window manager. |
| 17796 | */ |
| 17797 | int mGlobalSystemUiVisibility; |
| 17798 | |
| 17799 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17800 | * True if a view in this hierarchy has an OnSystemUiVisibilityChangeListener |
| 17801 | * attached. |
| 17802 | */ |
| 17803 | boolean mHasSystemUiListeners; |
| 17804 | |
| 17805 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17806 | * Set if the visibility of any views has changed. |
| 17807 | */ |
| 17808 | boolean mViewVisibilityChanged; |
| 17809 | |
| 17810 | /** |
| 17811 | * Set to true if a view has been scrolled. |
| 17812 | */ |
| 17813 | boolean mViewScrollChanged; |
| 17814 | |
| 17815 | /** |
| 17816 | * Global to the view hierarchy used as a temporary for dealing with |
| 17817 | * x/y points in the transparent region computations. |
| 17818 | */ |
| 17819 | final int[] mTransparentLocation = new int[2]; |
| 17820 | |
| 17821 | /** |
| 17822 | * Global to the view hierarchy used as a temporary for dealing with |
| 17823 | * x/y points in the ViewGroup.invalidateChild implementation. |
| 17824 | */ |
| 17825 | final int[] mInvalidateChildLocation = new int[2]; |
| 17826 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 17827 | |
| 17828 | /** |
| 17829 | * Global to the view hierarchy used as a temporary for dealing with |
| 17830 | * x/y location when view is transformed. |
| 17831 | */ |
| 17832 | final float[] mTmpTransformLocation = new float[2]; |
| 17833 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17834 | /** |
| 17835 | * The view tree observer used to dispatch global events like |
| 17836 | * layout, pre-draw, touch mode change, etc. |
| 17837 | */ |
| 17838 | final ViewTreeObserver mTreeObserver = new ViewTreeObserver(); |
| 17839 | |
| 17840 | /** |
| 17841 | * A Canvas used by the view hierarchy to perform bitmap caching. |
| 17842 | */ |
| 17843 | Canvas mCanvas; |
| 17844 | |
| 17845 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 17846 | * The view root impl. |
| 17847 | */ |
| 17848 | final ViewRootImpl mViewRootImpl; |
| 17849 | |
| 17850 | /** |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 17851 | * 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] | 17852 | * handler can be used to pump events in the UI events queue. |
| 17853 | */ |
| 17854 | final Handler mHandler; |
| 17855 | |
| 17856 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17857 | * Temporary for use in computing invalidate rectangles while |
| 17858 | * calling up the hierarchy. |
| 17859 | */ |
| 17860 | final Rect mTmpInvalRect = new Rect(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 17861 | |
| 17862 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 17863 | * Temporary for use in computing hit areas with transformed views |
| 17864 | */ |
| 17865 | final RectF mTmpTransformRect = new RectF(); |
| 17866 | |
| 17867 | /** |
Chet Haase | 599913d | 2012-07-23 16:22:05 -0700 | [diff] [blame] | 17868 | * Temporary for use in transforming invalidation rect |
| 17869 | */ |
| 17870 | final Matrix mTmpMatrix = new Matrix(); |
| 17871 | |
| 17872 | /** |
| 17873 | * Temporary for use in transforming invalidation rect |
| 17874 | */ |
| 17875 | final Transformation mTmpTransformation = new Transformation(); |
| 17876 | |
| 17877 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 17878 | * Temporary list for use in collecting focusable descendents of a view. |
| 17879 | */ |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 17880 | final ArrayList<View> mTempArrayList = new ArrayList<View>(24); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 17881 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17882 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 17883 | * The id of the window for accessibility purposes. |
| 17884 | */ |
| 17885 | int mAccessibilityWindowId = View.NO_ID; |
| 17886 | |
| 17887 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 17888 | * Whether to ingore not exposed for accessibility Views when |
| 17889 | * reporting the view tree to accessibility services. |
| 17890 | */ |
| 17891 | boolean mIncludeNotImportantViews; |
| 17892 | |
| 17893 | /** |
| 17894 | * The drawable for highlighting accessibility focus. |
| 17895 | */ |
| 17896 | Drawable mAccessibilityFocusDrawable; |
| 17897 | |
| 17898 | /** |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 17899 | * Show where the margins, bounds and layout bounds are for each view. |
| 17900 | */ |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 17901 | boolean mDebugLayout = SystemProperties.getBoolean(DEBUG_LAYOUT_PROPERTY, false); |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 17902 | |
| 17903 | /** |
Romain Guy | ab4c4f4f | 2012-05-06 13:11:24 -0700 | [diff] [blame] | 17904 | * Point used to compute visible regions. |
| 17905 | */ |
| 17906 | final Point mPoint = new Point(); |
| 17907 | |
| 17908 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17909 | * Creates a new set of attachment information with the specified |
| 17910 | * events handler and thread. |
| 17911 | * |
| 17912 | * @param handler the events handler the view must use |
| 17913 | */ |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 17914 | AttachInfo(IWindowSession session, IWindow window, Display display, |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 17915 | ViewRootImpl viewRootImpl, Handler handler, Callbacks effectPlayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17916 | mSession = session; |
| 17917 | mWindow = window; |
| 17918 | mWindowToken = window.asBinder(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 17919 | mDisplay = display; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 17920 | mViewRootImpl = viewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17921 | mHandler = handler; |
| 17922 | mRootCallbacks = effectPlayer; |
| 17923 | } |
| 17924 | } |
| 17925 | |
| 17926 | /** |
| 17927 | * <p>ScrollabilityCache holds various fields used by a View when scrolling |
| 17928 | * is supported. This avoids keeping too many unused fields in most |
| 17929 | * instances of View.</p> |
| 17930 | */ |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17931 | private static class ScrollabilityCache implements Runnable { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17932 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17933 | /** |
| 17934 | * Scrollbars are not visible |
| 17935 | */ |
| 17936 | public static final int OFF = 0; |
| 17937 | |
| 17938 | /** |
| 17939 | * Scrollbars are visible |
| 17940 | */ |
| 17941 | public static final int ON = 1; |
| 17942 | |
| 17943 | /** |
| 17944 | * Scrollbars are fading away |
| 17945 | */ |
| 17946 | public static final int FADING = 2; |
| 17947 | |
| 17948 | public boolean fadeScrollBars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17950 | public int fadingEdgeLength; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17951 | public int scrollBarDefaultDelayBeforeFade; |
| 17952 | public int scrollBarFadeDuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17953 | |
| 17954 | public int scrollBarSize; |
| 17955 | public ScrollBarDrawable scrollBar; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17956 | public float[] interpolatorValues; |
| 17957 | public View host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17958 | |
| 17959 | public final Paint paint; |
| 17960 | public final Matrix matrix; |
| 17961 | public Shader shader; |
| 17962 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17963 | public final Interpolator scrollBarInterpolator = new Interpolator(1, 2); |
| 17964 | |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 17965 | private static final float[] OPAQUE = { 255 }; |
| 17966 | private static final float[] TRANSPARENT = { 0.0f }; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17967 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17968 | /** |
| 17969 | * When fading should start. This time moves into the future every time |
| 17970 | * a new scroll happens. Measured based on SystemClock.uptimeMillis() |
| 17971 | */ |
| 17972 | public long fadeStartTime; |
| 17973 | |
| 17974 | |
| 17975 | /** |
| 17976 | * The current state of the scrollbars: ON, OFF, or FADING |
| 17977 | */ |
| 17978 | public int state = OFF; |
| 17979 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17980 | private int mLastColor; |
| 17981 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17982 | public ScrollabilityCache(ViewConfiguration configuration, View host) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17983 | fadingEdgeLength = configuration.getScaledFadingEdgeLength(); |
| 17984 | scrollBarSize = configuration.getScaledScrollBarSize(); |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 17985 | scrollBarDefaultDelayBeforeFade = ViewConfiguration.getScrollDefaultDelay(); |
| 17986 | scrollBarFadeDuration = ViewConfiguration.getScrollBarFadeDuration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17987 | |
| 17988 | paint = new Paint(); |
| 17989 | matrix = new Matrix(); |
| 17990 | // use use a height of 1, and then wack the matrix each time we |
| 17991 | // actually use it. |
| 17992 | 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] | 17993 | paint.setShader(shader); |
| 17994 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
Romain Guy | d679b57 | 2012-08-29 21:49:00 -0700 | [diff] [blame] | 17995 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17996 | this.host = host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17997 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17998 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17999 | public void setFadeColor(int color) { |
Romain Guy | d679b57 | 2012-08-29 21:49:00 -0700 | [diff] [blame] | 18000 | if (color != mLastColor) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18001 | mLastColor = color; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 18002 | |
Romain Guy | d679b57 | 2012-08-29 21:49:00 -0700 | [diff] [blame] | 18003 | if (color != 0) { |
| 18004 | shader = new LinearGradient(0, 0, 0, 1, color | 0xFF000000, |
| 18005 | color & 0x00FFFFFF, Shader.TileMode.CLAMP); |
| 18006 | paint.setShader(shader); |
| 18007 | // Restore the default transfer mode (src_over) |
| 18008 | paint.setXfermode(null); |
| 18009 | } else { |
| 18010 | shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP); |
| 18011 | paint.setShader(shader); |
| 18012 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
| 18013 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18014 | } |
| 18015 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 18016 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18017 | public void run() { |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 18018 | long now = AnimationUtils.currentAnimationTimeMillis(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18019 | if (now >= fadeStartTime) { |
| 18020 | |
| 18021 | // the animation fades the scrollbars out by changing |
| 18022 | // the opacity (alpha) from fully opaque to fully |
| 18023 | // transparent |
| 18024 | int nextFrame = (int) now; |
| 18025 | int framesCount = 0; |
| 18026 | |
| 18027 | Interpolator interpolator = scrollBarInterpolator; |
| 18028 | |
| 18029 | // Start opaque |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 18030 | interpolator.setKeyFrame(framesCount++, nextFrame, OPAQUE); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18031 | |
| 18032 | // End transparent |
| 18033 | nextFrame += scrollBarFadeDuration; |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 18034 | interpolator.setKeyFrame(framesCount, nextFrame, TRANSPARENT); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18035 | |
| 18036 | state = FADING; |
| 18037 | |
| 18038 | // Kick off the fade animation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 18039 | host.invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18040 | } |
| 18041 | } |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 18042 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18043 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 18044 | /** |
| 18045 | * Resuable callback for sending |
| 18046 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 18047 | */ |
| 18048 | private class SendViewScrolledAccessibilityEvent implements Runnable { |
| 18049 | public volatile boolean mIsPending; |
| 18050 | |
| 18051 | public void run() { |
| 18052 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED); |
| 18053 | mIsPending = false; |
| 18054 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18055 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 18056 | |
| 18057 | /** |
| 18058 | * <p> |
| 18059 | * This class represents a delegate that can be registered in a {@link View} |
| 18060 | * to enhance accessibility support via composition rather via inheritance. |
| 18061 | * It is specifically targeted to widget developers that extend basic View |
| 18062 | * classes i.e. classes in package android.view, that would like their |
| 18063 | * applications to be backwards compatible. |
| 18064 | * </p> |
Joe Fernandez | e1302ed | 2012-02-06 14:30:15 -0800 | [diff] [blame] | 18065 | * <div class="special reference"> |
| 18066 | * <h3>Developer Guides</h3> |
| 18067 | * <p>For more information about making applications accessible, read the |
| 18068 | * <a href="{@docRoot}guide/topics/ui/accessibility/index.html">Accessibility</a> |
| 18069 | * developer guide.</p> |
| 18070 | * </div> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 18071 | * <p> |
| 18072 | * A scenario in which a developer would like to use an accessibility delegate |
| 18073 | * is overriding a method introduced in a later API version then the minimal API |
| 18074 | * version supported by the application. For example, the method |
| 18075 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} is not available |
| 18076 | * in API version 4 when the accessibility APIs were first introduced. If a |
| 18077 | * developer would like his application to run on API version 4 devices (assuming |
| 18078 | * all other APIs used by the application are version 4 or lower) and take advantage |
| 18079 | * of this method, instead of overriding the method which would break the application's |
| 18080 | * backwards compatibility, he can override the corresponding method in this |
| 18081 | * delegate and register the delegate in the target View if the API version of |
| 18082 | * the system is high enough i.e. the API version is same or higher to the API |
| 18083 | * version that introduced |
| 18084 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)}. |
| 18085 | * </p> |
| 18086 | * <p> |
| 18087 | * Here is an example implementation: |
| 18088 | * </p> |
| 18089 | * <code><pre><p> |
| 18090 | * if (Build.VERSION.SDK_INT >= 14) { |
| 18091 | * // If the API version is equal of higher than the version in |
| 18092 | * // which onInitializeAccessibilityNodeInfo was introduced we |
| 18093 | * // register a delegate with a customized implementation. |
| 18094 | * View view = findViewById(R.id.view_id); |
| 18095 | * view.setAccessibilityDelegate(new AccessibilityDelegate() { |
| 18096 | * public void onInitializeAccessibilityNodeInfo(View host, |
| 18097 | * AccessibilityNodeInfo info) { |
| 18098 | * // Let the default implementation populate the info. |
| 18099 | * super.onInitializeAccessibilityNodeInfo(host, info); |
| 18100 | * // Set some other information. |
| 18101 | * info.setEnabled(host.isEnabled()); |
| 18102 | * } |
| 18103 | * }); |
| 18104 | * } |
| 18105 | * </code></pre></p> |
| 18106 | * <p> |
| 18107 | * This delegate contains methods that correspond to the accessibility methods |
| 18108 | * in View. If a delegate has been specified the implementation in View hands |
| 18109 | * off handling to the corresponding method in this delegate. The default |
| 18110 | * implementation the delegate methods behaves exactly as the corresponding |
| 18111 | * method in View for the case of no accessibility delegate been set. Hence, |
| 18112 | * to customize the behavior of a View method, clients can override only the |
| 18113 | * corresponding delegate method without altering the behavior of the rest |
| 18114 | * accessibility related methods of the host view. |
| 18115 | * </p> |
| 18116 | */ |
| 18117 | public static class AccessibilityDelegate { |
| 18118 | |
| 18119 | /** |
| 18120 | * Sends an accessibility event of the given type. If accessibility is not |
| 18121 | * enabled this method has no effect. |
| 18122 | * <p> |
| 18123 | * The default implementation behaves as {@link View#sendAccessibilityEvent(int) |
| 18124 | * View#sendAccessibilityEvent(int)} for the case of no accessibility delegate |
| 18125 | * been set. |
| 18126 | * </p> |
| 18127 | * |
| 18128 | * @param host The View hosting the delegate. |
| 18129 | * @param eventType The type of the event to send. |
| 18130 | * |
| 18131 | * @see View#sendAccessibilityEvent(int) View#sendAccessibilityEvent(int) |
| 18132 | */ |
| 18133 | public void sendAccessibilityEvent(View host, int eventType) { |
| 18134 | host.sendAccessibilityEventInternal(eventType); |
| 18135 | } |
| 18136 | |
| 18137 | /** |
alanv | 8eeefef | 2012-05-07 16:57:53 -0700 | [diff] [blame] | 18138 | * Performs the specified accessibility action on the view. For |
| 18139 | * possible accessibility actions look at {@link AccessibilityNodeInfo}. |
| 18140 | * <p> |
| 18141 | * The default implementation behaves as |
| 18142 | * {@link View#performAccessibilityAction(int, Bundle) |
| 18143 | * View#performAccessibilityAction(int, Bundle)} for the case of |
| 18144 | * no accessibility delegate been set. |
| 18145 | * </p> |
| 18146 | * |
| 18147 | * @param action The action to perform. |
| 18148 | * @return Whether the action was performed. |
| 18149 | * |
| 18150 | * @see View#performAccessibilityAction(int, Bundle) |
| 18151 | * View#performAccessibilityAction(int, Bundle) |
| 18152 | */ |
| 18153 | public boolean performAccessibilityAction(View host, int action, Bundle args) { |
| 18154 | return host.performAccessibilityActionInternal(action, args); |
| 18155 | } |
| 18156 | |
| 18157 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 18158 | * Sends an accessibility event. This method behaves exactly as |
| 18159 | * {@link #sendAccessibilityEvent(View, int)} but takes as an argument an |
| 18160 | * empty {@link AccessibilityEvent} and does not perform a check whether |
| 18161 | * accessibility is enabled. |
| 18162 | * <p> |
| 18163 | * The default implementation behaves as |
| 18164 | * {@link View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 18165 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent)} for |
| 18166 | * the case of no accessibility delegate been set. |
| 18167 | * </p> |
| 18168 | * |
| 18169 | * @param host The View hosting the delegate. |
| 18170 | * @param event The event to send. |
| 18171 | * |
| 18172 | * @see View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 18173 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 18174 | */ |
| 18175 | public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) { |
| 18176 | host.sendAccessibilityEventUncheckedInternal(event); |
| 18177 | } |
| 18178 | |
| 18179 | /** |
| 18180 | * Dispatches an {@link AccessibilityEvent} to the host {@link View} first and then |
| 18181 | * to its children for adding their text content to the event. |
| 18182 | * <p> |
| 18183 | * The default implementation behaves as |
| 18184 | * {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 18185 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 18186 | * the case of no accessibility delegate been set. |
| 18187 | * </p> |
| 18188 | * |
| 18189 | * @param host The View hosting the delegate. |
| 18190 | * @param event The event. |
| 18191 | * @return True if the event population was completed. |
| 18192 | * |
| 18193 | * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 18194 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 18195 | */ |
| 18196 | public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 18197 | return host.dispatchPopulateAccessibilityEventInternal(event); |
| 18198 | } |
| 18199 | |
| 18200 | /** |
| 18201 | * Gives a chance to the host View to populate the accessibility event with its |
| 18202 | * text content. |
| 18203 | * <p> |
| 18204 | * The default implementation behaves as |
| 18205 | * {@link View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 18206 | * View#onPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 18207 | * the case of no accessibility delegate been set. |
| 18208 | * </p> |
| 18209 | * |
| 18210 | * @param host The View hosting the delegate. |
| 18211 | * @param event The accessibility event which to populate. |
| 18212 | * |
| 18213 | * @see View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 18214 | * View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 18215 | */ |
| 18216 | public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 18217 | host.onPopulateAccessibilityEventInternal(event); |
| 18218 | } |
| 18219 | |
| 18220 | /** |
| 18221 | * Initializes an {@link AccessibilityEvent} with information about the |
| 18222 | * the host View which is the event source. |
| 18223 | * <p> |
| 18224 | * The default implementation behaves as |
| 18225 | * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 18226 | * View#onInitializeAccessibilityEvent(AccessibilityEvent)} for |
| 18227 | * the case of no accessibility delegate been set. |
| 18228 | * </p> |
| 18229 | * |
| 18230 | * @param host The View hosting the delegate. |
| 18231 | * @param event The event to initialize. |
| 18232 | * |
| 18233 | * @see View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 18234 | * View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 18235 | */ |
| 18236 | public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { |
| 18237 | host.onInitializeAccessibilityEventInternal(event); |
| 18238 | } |
| 18239 | |
| 18240 | /** |
| 18241 | * Initializes an {@link AccessibilityNodeInfo} with information about the host view. |
| 18242 | * <p> |
| 18243 | * The default implementation behaves as |
| 18244 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 18245 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} for |
| 18246 | * the case of no accessibility delegate been set. |
| 18247 | * </p> |
| 18248 | * |
| 18249 | * @param host The View hosting the delegate. |
| 18250 | * @param info The instance to initialize. |
| 18251 | * |
| 18252 | * @see View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 18253 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 18254 | */ |
| 18255 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 18256 | host.onInitializeAccessibilityNodeInfoInternal(info); |
| 18257 | } |
| 18258 | |
| 18259 | /** |
| 18260 | * Called when a child of the host View has requested sending an |
| 18261 | * {@link AccessibilityEvent} and gives an opportunity to the parent (the host) |
| 18262 | * to augment the event. |
| 18263 | * <p> |
| 18264 | * The default implementation behaves as |
| 18265 | * {@link ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 18266 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent)} for |
| 18267 | * the case of no accessibility delegate been set. |
| 18268 | * </p> |
| 18269 | * |
| 18270 | * @param host The View hosting the delegate. |
| 18271 | * @param child The child which requests sending the event. |
| 18272 | * @param event The event to be sent. |
| 18273 | * @return True if the event should be sent |
| 18274 | * |
| 18275 | * @see ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 18276 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 18277 | */ |
| 18278 | public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, |
| 18279 | AccessibilityEvent event) { |
| 18280 | return host.onRequestSendAccessibilityEventInternal(child, event); |
| 18281 | } |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 18282 | |
| 18283 | /** |
| 18284 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 18285 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 18286 | * that explore the window content. |
| 18287 | * <p> |
| 18288 | * The default implementation behaves as |
| 18289 | * {@link View#getAccessibilityNodeProvider() View#getAccessibilityNodeProvider()} for |
| 18290 | * the case of no accessibility delegate been set. |
| 18291 | * </p> |
| 18292 | * |
| 18293 | * @return The provider. |
| 18294 | * |
| 18295 | * @see AccessibilityNodeProvider |
| 18296 | */ |
| 18297 | public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) { |
| 18298 | return null; |
| 18299 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 18300 | } |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 18301 | |
| 18302 | private class MatchIdPredicate implements Predicate<View> { |
| 18303 | public int mId; |
| 18304 | |
| 18305 | @Override |
| 18306 | public boolean apply(View view) { |
| 18307 | return (view.mID == mId); |
| 18308 | } |
| 18309 | } |
| 18310 | |
| 18311 | private class MatchLabelForPredicate implements Predicate<View> { |
| 18312 | private int mLabeledId; |
| 18313 | |
| 18314 | @Override |
| 18315 | public boolean apply(View view) { |
| 18316 | return (view.mLabelForId == mLabeledId); |
| 18317 | } |
| 18318 | } |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 18319 | |
| 18320 | /** |
| 18321 | * Dump all private flags in readable format, useful for documentation and |
| 18322 | * sanity checking. |
| 18323 | */ |
| 18324 | private static void dumpFlags() { |
| 18325 | final HashMap<String, String> found = Maps.newHashMap(); |
| 18326 | try { |
| 18327 | for (Field field : View.class.getDeclaredFields()) { |
| 18328 | final int modifiers = field.getModifiers(); |
| 18329 | if (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)) { |
| 18330 | if (field.getType().equals(int.class)) { |
| 18331 | final int value = field.getInt(null); |
| 18332 | dumpFlag(found, field.getName(), value); |
| 18333 | } else if (field.getType().equals(int[].class)) { |
| 18334 | final int[] values = (int[]) field.get(null); |
| 18335 | for (int i = 0; i < values.length; i++) { |
| 18336 | dumpFlag(found, field.getName() + "[" + i + "]", values[i]); |
| 18337 | } |
| 18338 | } |
| 18339 | } |
| 18340 | } |
| 18341 | } catch (IllegalAccessException e) { |
| 18342 | throw new RuntimeException(e); |
| 18343 | } |
| 18344 | |
| 18345 | final ArrayList<String> keys = Lists.newArrayList(); |
| 18346 | keys.addAll(found.keySet()); |
| 18347 | Collections.sort(keys); |
| 18348 | for (String key : keys) { |
| 18349 | Log.d(VIEW_LOG_TAG, found.get(key)); |
| 18350 | } |
| 18351 | } |
| 18352 | |
| 18353 | private static void dumpFlag(HashMap<String, String> found, String name, int value) { |
| 18354 | // Sort flags by prefix, then by bits, always keeping unique keys |
| 18355 | final String bits = String.format("%32s", Integer.toBinaryString(value)).replace('0', ' '); |
| 18356 | final int prefix = name.indexOf('_'); |
| 18357 | final String key = (prefix > 0 ? name.substring(0, prefix) : name) + bits + name; |
| 18358 | final String output = bits + " " + name; |
| 18359 | found.put(key, output); |
| 18360 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18361 | } |