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 | |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 19 | import static android.view.WindowCallbacks.RESIZE_MODE_DOCKED_DIVIDER; |
| 20 | import static android.view.WindowCallbacks.RESIZE_MODE_FREEFORM; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 21 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY; |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 22 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 24 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; |
| 25 | import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 26 | |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 27 | import android.Manifest; |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 28 | import android.animation.LayoutTransition; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 29 | import android.app.ActivityManagerNative; |
| 30 | import android.content.ClipDescription; |
| 31 | import android.content.ComponentCallbacks; |
| 32 | import android.content.Context; |
| 33 | import android.content.pm.PackageManager; |
| 34 | import android.content.res.CompatibilityInfo; |
| 35 | import android.content.res.Configuration; |
| 36 | import android.content.res.Resources; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.graphics.Canvas; |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 38 | import android.graphics.Matrix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.graphics.PixelFormat; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 40 | import android.graphics.Point; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 41 | import android.graphics.PointF; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 42 | import android.graphics.PorterDuff; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import android.graphics.Rect; |
| 44 | import android.graphics.Region; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 45 | import android.graphics.drawable.Drawable; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 46 | import android.hardware.display.DisplayManager; |
| 47 | import android.hardware.display.DisplayManager.DisplayListener; |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 48 | import android.hardware.input.InputManager; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 49 | import android.media.AudioManager; |
| 50 | import android.os.Binder; |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 51 | import android.os.Build; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 52 | import android.os.Bundle; |
| 53 | import android.os.Debug; |
| 54 | import android.os.Handler; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 55 | import android.os.Looper; |
| 56 | import android.os.Message; |
| 57 | import android.os.ParcelFileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.os.Process; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 59 | import android.os.RemoteException; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 60 | import android.os.SystemClock; |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 61 | import android.os.SystemProperties; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 62 | import android.os.Trace; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.util.AndroidRuntimeException; |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 64 | import android.util.DisplayMetrics; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 65 | import android.util.Log; |
Chet Haase | 949dbf7 | 2010-08-11 18:41:06 -0700 | [diff] [blame] | 66 | import android.util.Slog; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 67 | import android.util.TimeUtils; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 68 | import android.util.TypedValue; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 69 | import android.view.Surface.OutOfResourcesException; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 70 | import android.view.View.AttachInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.view.View.MeasureSpec; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 72 | import android.view.accessibility.AccessibilityEvent; |
| 73 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 74 | import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 75 | import android.view.accessibility.AccessibilityManager.HighTextContrastChangeListener; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 76 | import android.view.accessibility.AccessibilityNodeInfo; |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 77 | import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 78 | import android.view.accessibility.AccessibilityNodeProvider; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 79 | import android.view.accessibility.IAccessibilityInteractionConnection; |
| 80 | import android.view.accessibility.IAccessibilityInteractionConnectionCallback; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 81 | import android.view.animation.AccelerateDecelerateInterpolator; |
| 82 | import android.view.animation.Interpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import android.view.inputmethod.InputConnection; |
| 84 | import android.view.inputmethod.InputMethodManager; |
| 85 | import android.widget.Scroller; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 86 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 87 | import com.android.internal.R; |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 88 | import com.android.internal.annotations.GuardedBy; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 89 | import com.android.internal.os.IResultReceiver; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 90 | import com.android.internal.os.SomeArgs; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 91 | import com.android.internal.policy.PhoneFallbackEventHandler; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 92 | import com.android.internal.view.BaseSurfaceHolder; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 93 | import com.android.internal.view.RootViewSurfaceTaker; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 95 | import java.io.FileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import java.io.IOException; |
| 97 | import java.io.OutputStream; |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 98 | import java.io.PrintWriter; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 99 | import java.lang.ref.WeakReference; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | import java.util.ArrayList; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 101 | import java.util.HashSet; |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 102 | import java.util.concurrent.CountDownLatch; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | /** |
| 105 | * The top of a view hierarchy, implementing the needed protocol between View |
| 106 | * and the WindowManager. This is for the most part an internal implementation |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 107 | * detail of {@link WindowManagerGlobal}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | * |
| 109 | * {@hide} |
| 110 | */ |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 111 | @SuppressWarnings({"EmptyCatchBlock", "PointlessBooleanExpression"}) |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 112 | public final class ViewRootImpl implements ViewParent, |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 113 | View.AttachInfo.Callbacks, ThreadedRenderer.HardwareDrawCallbacks { |
Dianne Hackborn | 70a3f67 | 2011-08-08 14:32:41 -0700 | [diff] [blame] | 114 | private static final String TAG = "ViewRootImpl"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | private static final boolean DBG = false; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 116 | private static final boolean LOCAL_LOGV = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | /** @noinspection PointlessBooleanExpression*/ |
| 118 | private static final boolean DEBUG_DRAW = false || LOCAL_LOGV; |
| 119 | private static final boolean DEBUG_LAYOUT = false || LOCAL_LOGV; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 120 | private static final boolean DEBUG_DIALOG = false || LOCAL_LOGV; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | private static final boolean DEBUG_INPUT_RESIZE = false || LOCAL_LOGV; |
| 122 | private static final boolean DEBUG_ORIENTATION = false || LOCAL_LOGV; |
| 123 | private static final boolean DEBUG_TRACKBALL = false || LOCAL_LOGV; |
| 124 | private static final boolean DEBUG_IMF = false || LOCAL_LOGV; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 125 | private static final boolean DEBUG_CONFIGURATION = false || LOCAL_LOGV; |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 126 | private static final boolean DEBUG_FPS = false; |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 127 | private static final boolean DEBUG_INPUT_STAGES = false || LOCAL_LOGV; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 129 | /** |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 130 | * Set to false if we do not want to use the multi threaded renderer. Note that by disabling |
| 131 | * this, WindowCallbacks will not fire. |
| 132 | */ |
| 133 | private static final boolean USE_MT_RENDERER = true; |
| 134 | |
| 135 | /** |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 136 | * Set this system property to true to force the view hierarchy to render |
| 137 | * at 60 Hz. This can be used to measure the potential framerate. |
| 138 | */ |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 139 | private static final String PROPERTY_PROFILE_RENDERING = "viewroot.profile_rendering"; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 140 | |
Griff Hazen | a093802 | 2015-03-13 10:01:41 -0700 | [diff] [blame] | 141 | // properties used by emulator to determine display shape |
Griff Hazen | a093802 | 2015-03-13 10:01:41 -0700 | [diff] [blame] | 142 | public static final String PROPERTY_EMULATOR_WIN_OUTSET_BOTTOM_PX = |
| 143 | "ro.emu.win_outset_bottom_px"; |
Michael Kolb | 437d313 | 2014-06-20 13:28:44 -0700 | [diff] [blame] | 144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | /** |
| 146 | * Maximum time we allow the user to roll the trackball enough to generate |
| 147 | * a key event, before resetting the counters. |
| 148 | */ |
| 149 | static final int MAX_TRACKBALL_DELAY = 250; |
| 150 | |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 151 | static final ThreadLocal<HandlerActionQueue> sRunQueues = new ThreadLocal<HandlerActionQueue>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 153 | static final ArrayList<Runnable> sFirstDrawHandlers = new ArrayList(); |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 154 | static boolean sFirstDrawComplete = false; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 155 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 156 | static final ArrayList<ComponentCallbacks> sConfigCallbacks = new ArrayList(); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 157 | |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 158 | /** |
| 159 | * This list must only be modified by the main thread, so a lock is only needed when changing |
| 160 | * the list or when accessing the list from a non-main thread. |
| 161 | */ |
| 162 | @GuardedBy("mWindowCallbacks") |
| 163 | final ArrayList<WindowCallbacks> mWindowCallbacks = new ArrayList<>(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 164 | final Context mContext; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 165 | final IWindowSession mWindowSession; |
| 166 | final Display mDisplay; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 167 | final DisplayManager mDisplayManager; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 168 | final String mBasePackageName; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | final int[] mTmpLocation = new int[2]; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 171 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 172 | final TypedValue mTmpValue = new TypedValue(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | final Thread mThread; |
| 175 | |
| 176 | final WindowLeaked mLocation; |
| 177 | |
| 178 | final WindowManager.LayoutParams mWindowAttributes = new WindowManager.LayoutParams(); |
| 179 | |
| 180 | final W mWindow; |
| 181 | |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 182 | final int mTargetSdkVersion; |
| 183 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 184 | int mSeq; |
| 185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | View mView; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 187 | |
| 188 | View mAccessibilityFocusedHost; |
| 189 | AccessibilityNodeInfo mAccessibilityFocusedVirtualView; |
| 190 | |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 191 | // The view which captures mouse input, or null when no one is capturing. |
| 192 | View mCapturingView; |
| 193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | int mViewVisibility; |
| 195 | boolean mAppVisible = true; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 196 | // For recents to freeform transition we need to keep drawing after the app receives information |
| 197 | // that it became invisible. This will ignore that information and depend on the decor view |
| 198 | // visibility to control drawing. The decor view visibility will get adjusted when the app get |
| 199 | // stopped and that's when the app will stop drawing further frames. |
| 200 | private boolean mForceDecorViewVisibility = false; |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 201 | int mOrigWindowType = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 203 | /** Whether the window had focus during the most recent traversal. */ |
| 204 | boolean mHadWindowFocus; |
| 205 | |
| 206 | /** |
| 207 | * Whether the window lost focus during a previous traversal and has not |
| 208 | * yet gained it back. Used to determine whether a WINDOW_STATE_CHANGE |
| 209 | * accessibility events should be sent during traversal. |
| 210 | */ |
| 211 | boolean mLostWindowFocus; |
| 212 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 213 | // Set to true if the owner of this window is in the stopped state, |
| 214 | // so the window should no longer be active. |
| 215 | boolean mStopped = false; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 216 | |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 217 | // Set to true if the owner of this window is in ambient mode, |
| 218 | // which means it won't receive input events. |
| 219 | boolean mIsAmbientMode = false; |
| 220 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 221 | // Set to true to stop input during an Activity Transition. |
| 222 | boolean mPausedForTransition = false; |
| 223 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 224 | boolean mLastInCompatMode = false; |
| 225 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 226 | SurfaceHolder.Callback2 mSurfaceHolderCallback; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 227 | BaseSurfaceHolder mSurfaceHolder; |
| 228 | boolean mIsCreating; |
| 229 | boolean mDrawingAllowed; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | final Region mTransparentRegion; |
| 232 | final Region mPreviousTransparentRegion; |
| 233 | |
| 234 | int mWidth; |
| 235 | int mHeight; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 236 | Rect mDirty; |
Romain Guy | bb93d55 | 2009-03-24 21:04:15 -0700 | [diff] [blame] | 237 | boolean mIsAnimating; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 238 | |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 239 | private boolean mDragResizing; |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 240 | private boolean mInvalidateRootRequested; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 241 | private int mResizeMode; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 242 | private int mCanvasOffsetX; |
| 243 | private int mCanvasOffsetY; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 244 | private boolean mActivityRelaunched; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 245 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 246 | CompatibilityInfo.Translator mTranslator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | |
| 248 | final View.AttachInfo mAttachInfo; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 249 | InputChannel mInputChannel; |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 250 | InputQueue.Callback mInputQueueCallback; |
| 251 | InputQueue mInputQueue; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 252 | FallbackEventHandler mFallbackEventHandler; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 253 | Choreographer mChoreographer; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | final Rect mTempRect; // used in the transaction to not thrash the heap. |
| 256 | final Rect mVisRect; // used to retrieve visible rect of focused view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | |
| 258 | boolean mTraversalScheduled; |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 259 | int mTraversalBarrier; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | boolean mWillDrawSoon; |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 261 | /** Set to true while in performTraversals for detecting when die(true) is called from internal |
| 262 | * callbacks such as onMeasure, onPreDraw, onDraw and deferring doDie() until later. */ |
| 263 | boolean mIsInTraversal; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 264 | boolean mApplyInsetsRequested; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | boolean mLayoutRequested; |
| 266 | boolean mFirst; |
| 267 | boolean mReportNextDraw; |
| 268 | boolean mFullRedrawNeeded; |
| 269 | boolean mNewSurfaceNeeded; |
| 270 | boolean mHasHadWindowFocus; |
| 271 | boolean mLastWasImTarget; |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 272 | boolean mForceNextWindowRelayout; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 273 | CountDownLatch mWindowDrawCountDown; |
Jorim Jaggi | 827e0fa | 2015-05-07 11:41:41 -0700 | [diff] [blame] | 274 | |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 275 | boolean mIsDrawing; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 276 | int mLastSystemUiVisibility; |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 277 | int mClientWindowLayoutFlags; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 278 | boolean mLastOverscanRequested; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 279 | |
| 280 | // Pool of queued input events. |
| 281 | private static final int MAX_QUEUED_INPUT_EVENT_POOL_SIZE = 10; |
| 282 | private QueuedInputEvent mQueuedInputEventPool; |
| 283 | private int mQueuedInputEventPoolSize; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 284 | |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 285 | /* Input event queue. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 286 | * Pending input events are input events waiting to be delivered to the input stages |
| 287 | * and handled by the application. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 288 | */ |
| 289 | QueuedInputEvent mPendingInputEventHead; |
| 290 | QueuedInputEvent mPendingInputEventTail; |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 291 | int mPendingInputEventCount; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 292 | boolean mProcessInputEventsScheduled; |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 293 | boolean mUnbufferedInputDispatch; |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 294 | String mPendingInputEventQueueLengthCounterName = "pq"; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 295 | |
| 296 | InputStage mFirstInputStage; |
| 297 | InputStage mFirstPostImeInputStage; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 298 | InputStage mSyntheticInputStage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | |
| 300 | boolean mWindowAttributesChanged = false; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 301 | int mWindowAttributesChangesFlag = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | |
| 303 | // These can be accessed by any thread, must be protected with a lock. |
Mathias Agopian | 5583dc6 | 2009-07-09 16:28:11 -0700 | [diff] [blame] | 304 | // Surface can never be reassigned or cleared (use Surface.clear()). |
John Reck | b13de07 | 2014-11-19 16:33:47 -0800 | [diff] [blame] | 305 | final Surface mSurface = new Surface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | |
| 307 | boolean mAdded; |
| 308 | boolean mAddedTouchMode; |
| 309 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 310 | final DisplayAdjustments mDisplayAdjustments; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 311 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | // These are accessed by multiple threads. |
| 313 | final Rect mWinFrame; // frame given by window manager. |
| 314 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 315 | final Rect mPendingOverscanInsets = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | final Rect mPendingVisibleInsets = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 317 | final Rect mPendingStableInsets = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | final Rect mPendingContentInsets = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 319 | final Rect mPendingOutsets = new Rect(); |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 320 | final Rect mPendingBackDropFrame = new Rect(); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 321 | boolean mPendingAlwaysConsumeNavBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | final ViewTreeObserver.InternalInsetsInfo mLastGivenInsets |
| 323 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 324 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 325 | final Rect mDispatchContentInsets = new Rect(); |
| 326 | final Rect mDispatchStableInsets = new Rect(); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 327 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 328 | private WindowInsets mLastWindowInsets; |
| 329 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 330 | final Configuration mLastConfiguration = new Configuration(); |
| 331 | final Configuration mPendingConfiguration = new Configuration(); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 332 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | boolean mScrollMayChange; |
| 334 | int mSoftInputMode; |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 335 | WeakReference<View> mLastScrolledFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | int mScrollY; |
| 337 | int mCurScrollY; |
| 338 | Scroller mScroller; |
John Reck | e56e9df | 2014-02-21 15:45:10 -0800 | [diff] [blame] | 339 | static final Interpolator mResizeInterpolator = new AccelerateDecelerateInterpolator(); |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 340 | private ArrayList<LayoutTransition> mPendingTransitions; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 341 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 342 | final ViewConfiguration mViewConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 344 | /* Drag/drop */ |
| 345 | ClipDescription mDragDescription; |
| 346 | View mCurrentDragView; |
Christopher Tate | 7fb8b56 | 2011-01-20 13:46:41 -0800 | [diff] [blame] | 347 | volatile Object mLocalDragState; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 348 | final PointF mDragPoint = new PointF(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 349 | final PointF mLastTouchPoint = new PointF(); |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 350 | int mLastTouchSource; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 351 | |
| 352 | private boolean mProfileRendering; |
Romain Guy | d075031 | 2012-11-29 11:34:43 -0800 | [diff] [blame] | 353 | private Choreographer.FrameCallback mRenderProfiler; |
| 354 | private boolean mRenderProfilingEnabled; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 355 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 356 | // Variables to track frames per second, enabled via DEBUG_FPS flag |
| 357 | private long mFpsStartTime = -1; |
| 358 | private long mFpsPrevTime = -1; |
| 359 | private int mFpsNumFrames; |
| 360 | |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 361 | private int mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 362 | private PointerIcon mCustomPointerIcon = null; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | /** |
| 365 | * see {@link #playSoundEffect(int)} |
| 366 | */ |
| 367 | AudioManager mAudioManager; |
| 368 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 369 | final AccessibilityManager mAccessibilityManager; |
| 370 | |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 371 | AccessibilityInteractionController mAccessibilityInteractionController; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 372 | |
| 373 | AccessibilityInteractionConnectionManager mAccessibilityInteractionConnectionManager; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 374 | HighContrastTextManager mHighContrastTextManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 375 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 376 | SendWindowContentChangedAccessibilityEvent mSendWindowContentChangedAccessibilityEvent; |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 377 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 378 | HashSet<View> mTempHashSet; |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 379 | |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 380 | private final int mDensity; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 381 | private final int mNoncompatDensity; |
Adam Powell | b08013c | 2010-09-16 16:28:11 -0700 | [diff] [blame] | 382 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 383 | private boolean mInLayout = false; |
| 384 | ArrayList<View> mLayoutRequesters = new ArrayList<View>(); |
| 385 | boolean mHandlingLayoutInLayoutRequest = false; |
| 386 | |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 387 | private int mViewLayoutDirectionInitial; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 388 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 389 | /** Set to true once doDie() has been called. */ |
| 390 | private boolean mRemoved; |
| 391 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 392 | /** |
| 393 | * Consistency verifier for debugging purposes. |
| 394 | */ |
| 395 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 396 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 397 | new InputEventConsistencyVerifier(this, 0) : null; |
| 398 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 399 | static final class SystemUiVisibilityInfo { |
| 400 | int seq; |
| 401 | int globalVisibility; |
| 402 | int localValue; |
| 403 | int localChanges; |
| 404 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 405 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 406 | private String mTag = TAG; |
| 407 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 408 | public ViewRootImpl(Context context, Display display) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 409 | mContext = context; |
| 410 | mWindowSession = WindowManagerGlobal.getWindowSession(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 411 | mDisplay = display; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 412 | mBasePackageName = context.getBasePackageName(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 413 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 414 | mDisplayAdjustments = display.getDisplayAdjustments(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 415 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | mThread = Thread.currentThread(); |
| 417 | mLocation = new WindowLeaked(null); |
| 418 | mLocation.fillInStackTrace(); |
| 419 | mWidth = -1; |
| 420 | mHeight = -1; |
| 421 | mDirty = new Rect(); |
| 422 | mTempRect = new Rect(); |
| 423 | mVisRect = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | mWinFrame = new Rect(); |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 425 | mWindow = new W(this); |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 426 | mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | mViewVisibility = View.GONE; |
| 428 | mTransparentRegion = new Region(); |
| 429 | mPreviousTransparentRegion = new Region(); |
| 430 | mFirst = true; // true for the first time the view is added |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | mAdded = false; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 432 | mAttachInfo = new View.AttachInfo(mWindowSession, mWindow, display, this, mHandler, this); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 433 | mAccessibilityManager = AccessibilityManager.getInstance(context); |
| 434 | mAccessibilityInteractionConnectionManager = |
| 435 | new AccessibilityInteractionConnectionManager(); |
Svetoslav Ganov | 00d0c14 | 2012-02-24 11:30:49 -0800 | [diff] [blame] | 436 | mAccessibilityManager.addAccessibilityStateChangeListener( |
| 437 | mAccessibilityInteractionConnectionManager); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 438 | mHighContrastTextManager = new HighContrastTextManager(); |
| 439 | mAccessibilityManager.addHighTextContrastStateChangeListener( |
| 440 | mHighContrastTextManager); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | mViewConfiguration = ViewConfiguration.get(context); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 442 | mDensity = context.getResources().getDisplayMetrics().densityDpi; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 443 | mNoncompatDensity = context.getResources().getDisplayMetrics().noncompatDensityDpi; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 444 | mFallbackEventHandler = new PhoneFallbackEventHandler(context); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 445 | mChoreographer = Choreographer.getInstance(); |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 446 | mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 447 | loadSystemProperties(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | } |
| 449 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 450 | public static void addFirstDrawHandler(Runnable callback) { |
| 451 | synchronized (sFirstDrawHandlers) { |
| 452 | if (!sFirstDrawComplete) { |
| 453 | sFirstDrawHandlers.add(callback); |
| 454 | } |
| 455 | } |
| 456 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 457 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 458 | public static void addConfigCallback(ComponentCallbacks callback) { |
| 459 | synchronized (sConfigCallbacks) { |
| 460 | sConfigCallbacks.add(callback); |
| 461 | } |
| 462 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 463 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 464 | public void addWindowCallbacks(WindowCallbacks callback) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 465 | if (USE_MT_RENDERER) { |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 466 | synchronized (mWindowCallbacks) { |
| 467 | mWindowCallbacks.add(callback); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 472 | public void removeWindowCallbacks(WindowCallbacks callback) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 473 | if (USE_MT_RENDERER) { |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 474 | synchronized (mWindowCallbacks) { |
| 475 | mWindowCallbacks.remove(callback); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 480 | public void reportDrawFinish() { |
| 481 | if (mWindowDrawCountDown != null) { |
| 482 | mWindowDrawCountDown.countDown(); |
| 483 | } |
| 484 | } |
| 485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | // FIXME for perf testing only |
| 487 | private boolean mProfile = false; |
| 488 | |
| 489 | /** |
| 490 | * Call this to profile the next traversal call. |
| 491 | * FIXME for perf testing only. Remove eventually |
| 492 | */ |
| 493 | public void profile() { |
| 494 | mProfile = true; |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * Indicates whether we are in touch mode. Calling this method triggers an IPC |
| 499 | * call and should be avoided whenever possible. |
| 500 | * |
| 501 | * @return True, if the device is in touch mode, false otherwise. |
| 502 | * |
| 503 | * @hide |
| 504 | */ |
| 505 | static boolean isInTouchMode() { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 506 | IWindowSession windowSession = WindowManagerGlobal.peekWindowSession(); |
| 507 | if (windowSession != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 509 | return windowSession.getInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | } catch (RemoteException e) { |
| 511 | } |
| 512 | } |
| 513 | return false; |
| 514 | } |
| 515 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | /** |
| 517 | * We have one child |
| 518 | */ |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 519 | public void setView(View view, WindowManager.LayoutParams attrs, View panelParentView) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | synchronized (this) { |
| 521 | if (mView == null) { |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 522 | mView = view; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 523 | |
| 524 | mAttachInfo.mDisplayState = mDisplay.getState(); |
| 525 | mDisplayManager.registerDisplayListener(mDisplayListener, mHandler); |
| 526 | |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 527 | mViewLayoutDirectionInitial = mView.getRawLayoutDirection(); |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 528 | mFallbackEventHandler.setView(view); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 529 | mWindowAttributes.copyFrom(attrs); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 530 | if (mWindowAttributes.packageName == null) { |
| 531 | mWindowAttributes.packageName = mBasePackageName; |
| 532 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 533 | attrs = mWindowAttributes; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 534 | setTag(); |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 535 | // Keep track of the actual window flags supplied by the client. |
| 536 | mClientWindowLayoutFlags = attrs.flags; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 537 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 538 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 539 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 540 | if (view instanceof RootViewSurfaceTaker) { |
| 541 | mSurfaceHolderCallback = |
| 542 | ((RootViewSurfaceTaker)view).willYouTakeTheSurface(); |
| 543 | if (mSurfaceHolderCallback != null) { |
| 544 | mSurfaceHolder = new TakenSurfaceHolder(); |
Dianne Hackborn | 289b9b6 | 2010-07-09 11:44:11 -0700 | [diff] [blame] | 545 | mSurfaceHolder.setFormat(PixelFormat.UNKNOWN); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 546 | } |
| 547 | } |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 548 | |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 549 | // Compute surface insets required to draw at specified Z value. |
| 550 | // TODO: Use real shadow insets for a constant max Z. |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 551 | if (!attrs.hasManualSurfaceInsets) { |
| 552 | final int surfaceInset = (int) Math.ceil(view.getZ() * 2); |
| 553 | attrs.surfaceInsets.set(surfaceInset, surfaceInset, surfaceInset, surfaceInset); |
| 554 | } |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 555 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 556 | CompatibilityInfo compatibilityInfo = mDisplayAdjustments.getCompatibilityInfo(); |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 557 | mTranslator = compatibilityInfo.getTranslator(); |
| 558 | |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 559 | // If the application owns the surface, don't enable hardware acceleration |
| 560 | if (mSurfaceHolder == null) { |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 561 | enableHardwareAcceleration(attrs); |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 562 | } |
| 563 | |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 564 | boolean restore = false; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 565 | if (mTranslator != null) { |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 566 | mSurface.setCompatibilityTranslator(mTranslator); |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 567 | restore = true; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 568 | attrs.backup(); |
| 569 | mTranslator.translateWindowLayout(attrs); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 570 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 571 | if (DEBUG_LAYOUT) Log.d(mTag, "WindowLayout in setView:" + attrs); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 572 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 573 | if (!compatibilityInfo.supportsScreen()) { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 574 | attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 575 | mLastInCompatMode = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 576 | } |
| 577 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | mSoftInputMode = attrs.softInputMode; |
| 579 | mWindowAttributesChanged = true; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 580 | mWindowAttributesChangesFlag = WindowManager.LayoutParams.EVERYTHING_CHANGED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | mAttachInfo.mRootView = view; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 582 | mAttachInfo.mScalingRequired = mTranslator != null; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 583 | mAttachInfo.mApplicationScale = |
| 584 | mTranslator == null ? 1.0f : mTranslator.applicationScale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | if (panelParentView != null) { |
| 586 | mAttachInfo.mPanelParentWindowToken |
| 587 | = panelParentView.getApplicationWindowToken(); |
| 588 | } |
| 589 | mAdded = true; |
| 590 | int res; /* = WindowManagerImpl.ADD_OKAY; */ |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 591 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 592 | // Schedule the first layout -before- adding to the window |
| 593 | // manager, to make sure we do the relayout before receiving |
| 594 | // any other events from the system. |
| 595 | requestLayout(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 596 | if ((mWindowAttributes.inputFeatures |
| 597 | & WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) { |
| 598 | mInputChannel = new InputChannel(); |
| 599 | } |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 600 | mForceDecorViewVisibility = (mWindowAttributes.privateFlags |
| 601 | & PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | try { |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 603 | mOrigWindowType = mWindowAttributes.type; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 604 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 605 | collectViewAttributes(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 606 | res = mWindowSession.addToDisplay(mWindow, mSeq, mWindowAttributes, |
| 607 | getHostVisibility(), mDisplay.getDisplayId(), |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 608 | mAttachInfo.mContentInsets, mAttachInfo.mStableInsets, |
| 609 | mAttachInfo.mOutsets, mInputChannel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 610 | } catch (RemoteException e) { |
| 611 | mAdded = false; |
| 612 | mView = null; |
| 613 | mAttachInfo.mRootView = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 614 | mInputChannel = null; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 615 | mFallbackEventHandler.setView(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | unscheduleTraversals(); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 617 | setAccessibilityFocus(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | throw new RuntimeException("Adding window failed", e); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 619 | } finally { |
| 620 | if (restore) { |
| 621 | attrs.restore(); |
| 622 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 623 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 624 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 625 | if (mTranslator != null) { |
| 626 | mTranslator.translateRectInScreenToAppWindow(mAttachInfo.mContentInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 627 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 628 | mPendingOverscanInsets.set(0, 0, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | mPendingContentInsets.set(mAttachInfo.mContentInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 630 | mPendingStableInsets.set(mAttachInfo.mStableInsets); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | mPendingVisibleInsets.set(0, 0, 0, 0); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 632 | mAttachInfo.mAlwaysConsumeNavBar = |
| 633 | (res & WindowManagerGlobal.ADD_FLAG_ALWAYS_CONSUME_NAV_BAR) != 0; |
| 634 | mPendingAlwaysConsumeNavBar = mAttachInfo.mAlwaysConsumeNavBar; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 635 | if (DEBUG_LAYOUT) Log.v(mTag, "Added window " + mWindow); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 636 | if (res < WindowManagerGlobal.ADD_OKAY) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | mAttachInfo.mRootView = null; |
| 638 | mAdded = false; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 639 | mFallbackEventHandler.setView(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | unscheduleTraversals(); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 641 | setAccessibilityFocus(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | switch (res) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 643 | case WindowManagerGlobal.ADD_BAD_APP_TOKEN: |
| 644 | case WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN: |
| 645 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 646 | "Unable to add window -- token " + attrs.token |
| 647 | + " is not valid; is your activity running?"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 648 | case WindowManagerGlobal.ADD_NOT_APP_TOKEN: |
| 649 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 650 | "Unable to add window -- token " + attrs.token |
| 651 | + " is not for an application"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 652 | case WindowManagerGlobal.ADD_APP_EXITING: |
| 653 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 654 | "Unable to add window -- app for token " + attrs.token |
| 655 | + " is exiting"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 656 | case WindowManagerGlobal.ADD_DUPLICATE_ADD: |
| 657 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 658 | "Unable to add window -- window " + mWindow |
| 659 | + " has already been added"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 660 | case WindowManagerGlobal.ADD_STARTING_NOT_NEEDED: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 661 | // Silently ignore -- we would have just removed it |
| 662 | // right away, anyway. |
| 663 | return; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 664 | case WindowManagerGlobal.ADD_MULTIPLE_SINGLETON: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 665 | throw new WindowManager.BadTokenException("Unable to add window " |
| 666 | + mWindow + " -- another window of type " |
| 667 | + mWindowAttributes.type + " already exists"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 668 | case WindowManagerGlobal.ADD_PERMISSION_DENIED: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 669 | throw new WindowManager.BadTokenException("Unable to add window " |
| 670 | + mWindow + " -- permission denied for window type " |
| 671 | + mWindowAttributes.type); |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 672 | case WindowManagerGlobal.ADD_INVALID_DISPLAY: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 673 | throw new WindowManager.InvalidDisplayException("Unable to add window " |
| 674 | + mWindow + " -- the specified display can not be found"); |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 675 | case WindowManagerGlobal.ADD_INVALID_TYPE: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 676 | throw new WindowManager.InvalidDisplayException("Unable to add window " |
| 677 | + mWindow + " -- the specified window type " |
| 678 | + mWindowAttributes.type + " is not valid"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | } |
| 680 | throw new RuntimeException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 681 | "Unable to add window -- unknown error code " + res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 683 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 684 | if (view instanceof RootViewSurfaceTaker) { |
| 685 | mInputQueueCallback = |
| 686 | ((RootViewSurfaceTaker)view).willYouTakeTheInputQueue(); |
| 687 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 688 | if (mInputChannel != null) { |
| 689 | if (mInputQueueCallback != null) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 690 | mInputQueue = new InputQueue(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 691 | mInputQueueCallback.onInputQueueCreated(mInputQueue); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 692 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 693 | mInputEventReceiver = new WindowInputEventReceiver(mInputChannel, |
| 694 | Looper.myLooper()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 695 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 | view.assignParent(this); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 698 | mAddedTouchMode = (res & WindowManagerGlobal.ADD_FLAG_IN_TOUCH_MODE) != 0; |
| 699 | mAppVisible = (res & WindowManagerGlobal.ADD_FLAG_APP_VISIBLE) != 0; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 700 | |
| 701 | if (mAccessibilityManager.isEnabled()) { |
| 702 | mAccessibilityInteractionConnectionManager.ensureConnection(); |
| 703 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 704 | |
| 705 | if (view.getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 706 | view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 707 | } |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 708 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 709 | // Set up the input pipeline. |
| 710 | CharSequence counterSuffix = attrs.getTitle(); |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 711 | mSyntheticInputStage = new SyntheticInputStage(); |
| 712 | InputStage viewPostImeStage = new ViewPostImeInputStage(mSyntheticInputStage); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 713 | InputStage nativePostImeStage = new NativePostImeInputStage(viewPostImeStage, |
| 714 | "aq:native-post-ime:" + counterSuffix); |
| 715 | InputStage earlyPostImeStage = new EarlyPostImeInputStage(nativePostImeStage); |
| 716 | InputStage imeStage = new ImeInputStage(earlyPostImeStage, |
| 717 | "aq:ime:" + counterSuffix); |
| 718 | InputStage viewPreImeStage = new ViewPreImeInputStage(imeStage); |
| 719 | InputStage nativePreImeStage = new NativePreImeInputStage(viewPreImeStage, |
| 720 | "aq:native-pre-ime:" + counterSuffix); |
| 721 | |
| 722 | mFirstInputStage = nativePreImeStage; |
| 723 | mFirstPostImeInputStage = earlyPostImeStage; |
| 724 | mPendingInputEventQueueLengthCounterName = "aq:pending:" + counterSuffix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | } |
| 726 | } |
| 727 | } |
| 728 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 729 | private void setTag() { |
| 730 | final String[] split = mWindowAttributes.getTitle().toString().split("\\."); |
| 731 | if (split.length > 0) { |
| 732 | mTag = TAG + "[" + split[split.length - 1] + "]"; |
| 733 | } |
| 734 | } |
| 735 | |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 736 | /** Whether the window is in local focus mode or not */ |
| 737 | private boolean isInLocalFocusMode() { |
| 738 | return (mWindowAttributes.flags & WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE) != 0; |
| 739 | } |
| 740 | |
Dianne Hackborn | 49b043f | 2015-05-07 14:21:38 -0700 | [diff] [blame] | 741 | public int getWindowFlags() { |
| 742 | return mWindowAttributes.flags; |
| 743 | } |
| 744 | |
Dianne Hackborn | ece0f4f | 2015-06-11 13:29:01 -0700 | [diff] [blame] | 745 | public int getDisplayId() { |
| 746 | return mDisplay.getDisplayId(); |
| 747 | } |
| 748 | |
Dianne Hackborn | a7bb6fb | 2015-02-03 18:13:40 -0800 | [diff] [blame] | 749 | public CharSequence getTitle() { |
| 750 | return mWindowAttributes.getTitle(); |
| 751 | } |
| 752 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 753 | void destroyHardwareResources() { |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 754 | if (mAttachInfo.mHardwareRenderer != null) { |
| 755 | mAttachInfo.mHardwareRenderer.destroyHardwareResources(mView); |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 756 | mAttachInfo.mHardwareRenderer.destroy(); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
Bo Liu | 845535a | 2014-03-21 12:06:23 -0700 | [diff] [blame] | 760 | public void detachFunctor(long functor) { |
John Reck | 44ac42a | 2014-05-16 14:46:07 -0700 | [diff] [blame] | 761 | if (mAttachInfo.mHardwareRenderer != null) { |
| 762 | // Fence so that any pending invokeFunctor() messages will be processed |
| 763 | // before we return from detachFunctor. |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 764 | mAttachInfo.mHardwareRenderer.stopDrawing(); |
John Reck | 44ac42a | 2014-05-16 14:46:07 -0700 | [diff] [blame] | 765 | } |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 766 | } |
| 767 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 768 | /** |
| 769 | * Schedules the functor for execution in either kModeProcess or |
| 770 | * kModeProcessNoContext, depending on whether or not there is an EGLContext. |
| 771 | * |
| 772 | * @param functor The native functor to invoke |
| 773 | * @param waitForCompletion If true, this will not return until the functor |
| 774 | * has invoked. If false, the functor may be invoked |
| 775 | * asynchronously. |
| 776 | */ |
Hui Shu | 9970aee | 2014-06-23 17:10:30 -0700 | [diff] [blame] | 777 | public void invokeFunctor(long functor, boolean waitForCompletion) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 778 | ThreadedRenderer.invokeFunctor(functor, waitForCompletion); |
Bo Liu | ae738a7 | 2014-04-27 16:22:04 -0700 | [diff] [blame] | 779 | } |
| 780 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 781 | public void registerAnimatingRenderNode(RenderNode animator) { |
| 782 | if (mAttachInfo.mHardwareRenderer != null) { |
| 783 | mAttachInfo.mHardwareRenderer.registerAnimatingRenderNode(animator); |
| 784 | } else { |
| 785 | if (mAttachInfo.mPendingAnimatingRenderNodes == null) { |
| 786 | mAttachInfo.mPendingAnimatingRenderNodes = new ArrayList<RenderNode>(); |
| 787 | } |
| 788 | mAttachInfo.mPendingAnimatingRenderNodes.add(animator); |
| 789 | } |
| 790 | } |
| 791 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 792 | private void enableHardwareAcceleration(WindowManager.LayoutParams attrs) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 793 | mAttachInfo.mHardwareAccelerated = false; |
| 794 | mAttachInfo.mHardwareAccelerationRequested = false; |
Romain Guy | 4f6aff3 | 2011-01-12 16:21:41 -0800 | [diff] [blame] | 795 | |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 796 | // Don't enable hardware acceleration when the application is in compatibility mode |
John Reck | dd58e79 | 2014-04-02 16:54:28 +0000 | [diff] [blame] | 797 | if (mTranslator != null) return; |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 798 | |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 799 | // Try to enable hardware acceleration if requested |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 800 | final boolean hardwareAccelerated = |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 801 | (attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 802 | |
John Reck | dd58e79 | 2014-04-02 16:54:28 +0000 | [diff] [blame] | 803 | if (hardwareAccelerated) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 804 | if (!ThreadedRenderer.isAvailable()) { |
Romain Guy | 1af23a3 | 2011-03-24 16:03:55 -0700 | [diff] [blame] | 805 | return; |
| 806 | } |
| 807 | |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 808 | // Persistent processes (including the system) should not do |
| 809 | // accelerated rendering on low-end devices. In that case, |
| 810 | // sRendererDisabled will be set. In addition, the system process |
| 811 | // itself should never do accelerated rendering. In that case, both |
| 812 | // sRendererDisabled and sSystemRendererDisabled are set. When |
| 813 | // sSystemRendererDisabled is set, PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED |
| 814 | // can be used by code on the system process to escape that and enable |
| 815 | // HW accelerated drawing. (This is basically for the lock screen.) |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 816 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 817 | final boolean fakeHwAccelerated = (attrs.privateFlags & |
| 818 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED) != 0; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 819 | final boolean forceHwAccelerated = (attrs.privateFlags & |
| 820 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED) != 0; |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 821 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 822 | if (fakeHwAccelerated) { |
| 823 | // This is exclusively for the preview windows the window manager |
| 824 | // shows for launching applications, so they will look more like |
| 825 | // the app being launched. |
| 826 | mAttachInfo.mHardwareAccelerationRequested = true; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 827 | } else if (!ThreadedRenderer.sRendererDisabled |
| 828 | || (ThreadedRenderer.sSystemRendererDisabled && forceHwAccelerated)) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 829 | if (mAttachInfo.mHardwareRenderer != null) { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 830 | mAttachInfo.mHardwareRenderer.destroy(); |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 831 | } |
| 832 | |
Alan Viverette | 2b12b58 | 2014-10-29 11:11:40 -0700 | [diff] [blame] | 833 | final Rect insets = attrs.surfaceInsets; |
Alan Viverette | 2cd23e6 | 2014-11-04 17:04:02 -0800 | [diff] [blame] | 834 | final boolean hasSurfaceInsets = insets.left != 0 || insets.right != 0 |
| 835 | || insets.top != 0 || insets.bottom != 0; |
Alan Viverette | 2b12b58 | 2014-10-29 11:11:40 -0700 | [diff] [blame] | 836 | final boolean translucent = attrs.format != PixelFormat.OPAQUE || hasSurfaceInsets; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 837 | mAttachInfo.mHardwareRenderer = ThreadedRenderer.create(mContext, translucent); |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 838 | if (mAttachInfo.mHardwareRenderer != null) { |
| 839 | mAttachInfo.mHardwareRenderer.setName(attrs.getTitle().toString()); |
| 840 | mAttachInfo.mHardwareAccelerated = |
| 841 | mAttachInfo.mHardwareAccelerationRequested = true; |
| 842 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 843 | } |
| 844 | } |
| 845 | } |
| 846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 847 | public View getView() { |
| 848 | return mView; |
| 849 | } |
| 850 | |
| 851 | final WindowLeaked getLocation() { |
| 852 | return mLocation; |
| 853 | } |
| 854 | |
| 855 | void setLayoutParams(WindowManager.LayoutParams attrs, boolean newView) { |
| 856 | synchronized (this) { |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 857 | final int oldInsetLeft = mWindowAttributes.surfaceInsets.left; |
| 858 | final int oldInsetTop = mWindowAttributes.surfaceInsets.top; |
| 859 | final int oldInsetRight = mWindowAttributes.surfaceInsets.right; |
| 860 | final int oldInsetBottom = mWindowAttributes.surfaceInsets.bottom; |
| 861 | final int oldSoftInputMode = mWindowAttributes.softInputMode; |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 862 | final boolean oldHasManualSurfaceInsets = mWindowAttributes.hasManualSurfaceInsets; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 863 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 864 | // Keep track of the actual window flags supplied by the client. |
| 865 | mClientWindowLayoutFlags = attrs.flags; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 866 | |
| 867 | // Preserve compatible window flag if exists. |
| 868 | final int compatibleWindowFlag = mWindowAttributes.privateFlags |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 869 | & WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 870 | |
| 871 | // Transfer over system UI visibility values as they carry current state. |
Craig Mautner | 3fe38c0 | 2012-05-03 17:28:09 -0700 | [diff] [blame] | 872 | attrs.systemUiVisibility = mWindowAttributes.systemUiVisibility; |
| 873 | attrs.subtreeSystemUiVisibility = mWindowAttributes.subtreeSystemUiVisibility; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 874 | |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 875 | mWindowAttributesChangesFlag = mWindowAttributes.copyFrom(attrs); |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 876 | if ((mWindowAttributesChangesFlag |
| 877 | & WindowManager.LayoutParams.TRANSLUCENT_FLAGS_CHANGED) != 0) { |
| 878 | // Recompute system ui visibility. |
| 879 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 880 | } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 881 | if (mWindowAttributes.packageName == null) { |
| 882 | mWindowAttributes.packageName = mBasePackageName; |
| 883 | } |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 884 | mWindowAttributes.privateFlags |= compatibleWindowFlag; |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 885 | |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 886 | // Restore old surface insets. |
| 887 | mWindowAttributes.surfaceInsets.set( |
| 888 | oldInsetLeft, oldInsetTop, oldInsetRight, oldInsetBottom); |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 889 | mWindowAttributes.hasManualSurfaceInsets = oldHasManualSurfaceInsets; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 890 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 891 | applyKeepScreenOnFlag(mWindowAttributes); |
| 892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | if (newView) { |
| 894 | mSoftInputMode = attrs.softInputMode; |
| 895 | requestLayout(); |
| 896 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 897 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 898 | // Don't lose the mode we last auto-computed. |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 899 | if ((attrs.softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 900 | == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED) { |
| 901 | mWindowAttributes.softInputMode = (mWindowAttributes.softInputMode |
| 902 | & ~WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 903 | | (oldSoftInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 904 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | mWindowAttributesChanged = true; |
| 907 | scheduleTraversals(); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | void handleAppVisibility(boolean visible) { |
| 912 | if (mAppVisible != visible) { |
| 913 | mAppVisible = visible; |
| 914 | scheduleTraversals(); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 915 | if (!mAppVisible) { |
| 916 | WindowManagerGlobal.trimForeground(); |
| 917 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | } |
| 919 | } |
| 920 | |
| 921 | void handleGetNewSurface() { |
| 922 | mNewSurfaceNeeded = true; |
| 923 | mFullRedrawNeeded = true; |
| 924 | scheduleTraversals(); |
| 925 | } |
| 926 | |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 927 | private final DisplayListener mDisplayListener = new DisplayListener() { |
| 928 | @Override |
| 929 | public void onDisplayChanged(int displayId) { |
| 930 | if (mView != null && mDisplay.getDisplayId() == displayId) { |
| 931 | final int oldDisplayState = mAttachInfo.mDisplayState; |
| 932 | final int newDisplayState = mDisplay.getState(); |
| 933 | if (oldDisplayState != newDisplayState) { |
| 934 | mAttachInfo.mDisplayState = newDisplayState; |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 935 | pokeDrawLockIfNeeded(); |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 936 | if (oldDisplayState != Display.STATE_UNKNOWN) { |
| 937 | final int oldScreenState = toViewScreenState(oldDisplayState); |
| 938 | final int newScreenState = toViewScreenState(newDisplayState); |
| 939 | if (oldScreenState != newScreenState) { |
| 940 | mView.dispatchScreenStateChanged(newScreenState); |
| 941 | } |
| 942 | if (oldDisplayState == Display.STATE_OFF) { |
| 943 | // Draw was suppressed so we need to for it to happen here. |
| 944 | mFullRedrawNeeded = true; |
| 945 | scheduleTraversals(); |
| 946 | } |
| 947 | } |
| 948 | } |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 949 | } |
| 950 | } |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 951 | |
| 952 | @Override |
| 953 | public void onDisplayRemoved(int displayId) { |
| 954 | } |
| 955 | |
| 956 | @Override |
| 957 | public void onDisplayAdded(int displayId) { |
| 958 | } |
| 959 | |
| 960 | private int toViewScreenState(int displayState) { |
| 961 | return displayState == Display.STATE_OFF ? |
| 962 | View.SCREEN_STATE_OFF : View.SCREEN_STATE_ON; |
| 963 | } |
| 964 | }; |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 965 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 966 | void pokeDrawLockIfNeeded() { |
| 967 | final int displayState = mAttachInfo.mDisplayState; |
| 968 | if (mView != null && mAdded && mTraversalScheduled |
| 969 | && (displayState == Display.STATE_DOZE |
| 970 | || displayState == Display.STATE_DOZE_SUSPEND)) { |
| 971 | try { |
| 972 | mWindowSession.pokeDrawLock(mWindow); |
| 973 | } catch (RemoteException ex) { |
| 974 | // System server died, oh well. |
| 975 | } |
| 976 | } |
| 977 | } |
| 978 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 979 | @Override |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 980 | public void requestFitSystemWindows() { |
| 981 | checkThread(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 982 | mApplyInsetsRequested = true; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 983 | scheduleTraversals(); |
| 984 | } |
| 985 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 986 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 987 | public void requestLayout() { |
Chet Haase | 3efa7b5 | 2012-12-03 08:33:17 -0800 | [diff] [blame] | 988 | if (!mHandlingLayoutInLayoutRequest) { |
| 989 | checkThread(); |
| 990 | mLayoutRequested = true; |
| 991 | scheduleTraversals(); |
| 992 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 993 | } |
| 994 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 995 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | public boolean isLayoutRequested() { |
| 997 | return mLayoutRequested; |
| 998 | } |
| 999 | |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1000 | void invalidate() { |
| 1001 | mDirty.set(0, 0, mWidth, mHeight); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 1002 | if (!mWillDrawSoon) { |
| 1003 | scheduleTraversals(); |
| 1004 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1005 | } |
| 1006 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 1007 | void invalidateWorld(View view) { |
| 1008 | view.invalidate(); |
| 1009 | if (view instanceof ViewGroup) { |
Romain Guy | f84208f | 2012-09-13 22:50:18 -0700 | [diff] [blame] | 1010 | ViewGroup parent = (ViewGroup) view; |
| 1011 | for (int i = 0; i < parent.getChildCount(); i++) { |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 1012 | invalidateWorld(parent.getChildAt(i)); |
| 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 1017 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | public void invalidateChild(View child, Rect dirty) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1019 | invalidateChildInParent(null, dirty); |
| 1020 | } |
| 1021 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1022 | @Override |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1023 | public ViewParent invalidateChildInParent(int[] location, Rect dirty) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1024 | checkThread(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1025 | if (DEBUG_DRAW) Log.v(mTag, "Invalidate child: " + dirty); |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1026 | |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1027 | if (dirty == null) { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1028 | invalidate(); |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1029 | return null; |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1030 | } else if (dirty.isEmpty() && !mIsAnimating) { |
Chet Haase | 05e91ed | 2012-07-03 14:17:57 -0700 | [diff] [blame] | 1031 | return null; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1032 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1033 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1034 | if (mCurScrollY != 0 || mTranslator != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | mTempRect.set(dirty); |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1036 | dirty = mTempRect; |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1037 | if (mCurScrollY != 0) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1038 | dirty.offset(0, -mCurScrollY); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1039 | } |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1040 | if (mTranslator != null) { |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1041 | mTranslator.translateRectInAppWindowToScreen(dirty); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1042 | } |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1043 | if (mAttachInfo.mScalingRequired) { |
| 1044 | dirty.inset(-1, -1); |
| 1045 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1047 | |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 1048 | invalidateRectOnScreen(dirty); |
| 1049 | |
| 1050 | return null; |
| 1051 | } |
| 1052 | |
| 1053 | private void invalidateRectOnScreen(Rect dirty) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1054 | final Rect localDirty = mDirty; |
| 1055 | if (!localDirty.isEmpty() && !localDirty.contains(dirty)) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 1056 | mAttachInfo.mSetIgnoreDirtyState = true; |
Romain Guy | 7d69594 | 2010-12-01 17:22:29 -0800 | [diff] [blame] | 1057 | mAttachInfo.mIgnoreDirtyState = true; |
| 1058 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1059 | |
| 1060 | // Add the new dirty rect to the current one |
| 1061 | localDirty.union(dirty.left, dirty.top, dirty.right, dirty.bottom); |
| 1062 | // Intersect with the bounds of the window to skip |
| 1063 | // updates that lie outside of the visible region |
Romain Guy | 7b2f8b8 | 2012-03-19 17:18:54 -0700 | [diff] [blame] | 1064 | final float appScale = mAttachInfo.mApplicationScale; |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1065 | final boolean intersected = localDirty.intersect(0, 0, |
| 1066 | (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f)); |
| 1067 | if (!intersected) { |
Chet Haase | b78ee0e | 2012-10-17 11:32:01 -0700 | [diff] [blame] | 1068 | localDirty.setEmpty(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | } |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1070 | if (!mWillDrawSoon && (intersected || mIsAnimating)) { |
| 1071 | scheduleTraversals(); |
| 1072 | } |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 1073 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1074 | |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 1075 | public void setIsAmbientMode(boolean ambient) { |
| 1076 | mIsAmbientMode = ambient; |
| 1077 | } |
| 1078 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1079 | void setWindowStopped(boolean stopped) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1080 | if (mStopped != stopped) { |
| 1081 | mStopped = stopped; |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1082 | if (!mStopped) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1083 | scheduleTraversals(); |
John Reck | d9b1607 | 2016-02-23 10:35:19 -0800 | [diff] [blame] | 1084 | } else { |
John Reck | f4db3d2 | 2016-02-26 12:58:17 -0800 | [diff] [blame] | 1085 | if (mAttachInfo.mHardwareRenderer != null) { |
Wale Ogunwale | e4f131a | 2016-03-07 07:33:56 -0800 | [diff] [blame] | 1086 | if (DEBUG_DRAW) Log.d(mTag, "WindowStopped on " + getTitle()); |
John Reck | f4db3d2 | 2016-02-26 12:58:17 -0800 | [diff] [blame] | 1087 | mAttachInfo.mHardwareRenderer.updateSurface(null); |
John Reck | fc73686 | 2016-02-26 15:01:52 -0800 | [diff] [blame] | 1088 | mAttachInfo.mHardwareRenderer.destroyHardwareResources(mView); |
John Reck | f4db3d2 | 2016-02-26 12:58:17 -0800 | [diff] [blame] | 1089 | } |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1090 | } |
| 1091 | } |
| 1092 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1094 | /** |
| 1095 | * Block the input events during an Activity Transition. The KEYCODE_BACK event is allowed |
| 1096 | * through to allow quick reversal of the Activity Transition. |
| 1097 | * |
| 1098 | * @param paused true to pause, false to resume. |
| 1099 | */ |
| 1100 | public void setPausedForTransition(boolean paused) { |
| 1101 | mPausedForTransition = paused; |
| 1102 | } |
| 1103 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1104 | @Override |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1105 | public ViewParent getParent() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | return null; |
| 1107 | } |
| 1108 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1109 | @Override |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1110 | public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point offset) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | if (child != mView) { |
| 1112 | throw new RuntimeException("child is not mine, honest!"); |
| 1113 | } |
| 1114 | // Note: don't apply scroll offset, because we want to know its |
| 1115 | // visibility in the virtual canvas being given to the view hierarchy. |
| 1116 | return r.intersect(0, 0, mWidth, mHeight); |
| 1117 | } |
| 1118 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1119 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | public void bringChildToFront(View child) { |
| 1121 | } |
| 1122 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | int getHostVisibility() { |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 1124 | return (mAppVisible || mForceDecorViewVisibility) ? mView.getVisibility() : View.GONE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1125 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1126 | |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 1127 | /** |
| 1128 | * Add LayoutTransition to the list of transitions to be started in the next traversal. |
| 1129 | * This list will be cleared after the transitions on the list are start()'ed. These |
| 1130 | * transitionsa re added by LayoutTransition itself when it sets up animations. The setup |
| 1131 | * happens during the layout phase of traversal, which we want to complete before any of the |
| 1132 | * animations are started (because those animations may side-effect properties that layout |
| 1133 | * depends upon, like the bounding rectangles of the affected views). So we add the transition |
| 1134 | * to the list and it is started just prior to starting the drawing phase of traversal. |
| 1135 | * |
| 1136 | * @param transition The LayoutTransition to be started on the next traversal. |
| 1137 | * |
| 1138 | * @hide |
| 1139 | */ |
| 1140 | public void requestTransitionStart(LayoutTransition transition) { |
| 1141 | if (mPendingTransitions == null || !mPendingTransitions.contains(transition)) { |
| 1142 | if (mPendingTransitions == null) { |
| 1143 | mPendingTransitions = new ArrayList<LayoutTransition>(); |
| 1144 | } |
| 1145 | mPendingTransitions.add(transition); |
| 1146 | } |
| 1147 | } |
| 1148 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1149 | /** |
| 1150 | * Notifies the HardwareRenderer that a new frame will be coming soon. |
| 1151 | * Currently only {@link ThreadedRenderer} cares about this, and uses |
| 1152 | * this knowledge to adjust the scheduling of off-thread animations |
| 1153 | */ |
| 1154 | void notifyRendererOfFramePending() { |
| 1155 | if (mAttachInfo.mHardwareRenderer != null) { |
| 1156 | mAttachInfo.mHardwareRenderer.notifyFramePending(); |
| 1157 | } |
| 1158 | } |
| 1159 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1160 | void scheduleTraversals() { |
| 1161 | if (!mTraversalScheduled) { |
| 1162 | mTraversalScheduled = true; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1163 | mTraversalBarrier = mHandler.getLooper().getQueue().postSyncBarrier(); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1164 | mChoreographer.postCallback( |
| 1165 | Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 1166 | if (!mUnbufferedInputDispatch) { |
| 1167 | scheduleConsumeBatchedInput(); |
| 1168 | } |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1169 | notifyRendererOfFramePending(); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 1170 | pokeDrawLockIfNeeded(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1171 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1172 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1173 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1174 | void unscheduleTraversals() { |
| 1175 | if (mTraversalScheduled) { |
| 1176 | mTraversalScheduled = false; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1177 | mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1178 | mChoreographer.removeCallbacks( |
| 1179 | Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | void doTraversal() { |
| 1184 | if (mTraversalScheduled) { |
| 1185 | mTraversalScheduled = false; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1186 | mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1187 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1188 | if (mProfile) { |
| 1189 | Debug.startMethodTracing("ViewAncestor"); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1190 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1191 | |
Chris Craik | e22c59b | 2015-05-21 18:33:37 -0700 | [diff] [blame] | 1192 | performTraversals(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1193 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1194 | if (mProfile) { |
| 1195 | Debug.stopMethodTracing(); |
| 1196 | mProfile = false; |
| 1197 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1198 | } |
| 1199 | } |
| 1200 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1201 | private void applyKeepScreenOnFlag(WindowManager.LayoutParams params) { |
| 1202 | // Update window's global keep screen on flag: if a view has requested |
| 1203 | // that the screen be kept on, then it is always set; otherwise, it is |
| 1204 | // set to whatever the client last requested for the global state. |
| 1205 | if (mAttachInfo.mKeepScreenOn) { |
| 1206 | params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
| 1207 | } else { |
| 1208 | params.flags = (params.flags&~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) |
| 1209 | | (mClientWindowLayoutFlags&WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
| 1210 | } |
| 1211 | } |
| 1212 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1213 | private boolean collectViewAttributes() { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1214 | if (mAttachInfo.mRecomputeGlobalAttributes) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1215 | //Log.i(mTag, "Computing view hierarchy attributes!"); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1216 | mAttachInfo.mRecomputeGlobalAttributes = false; |
| 1217 | boolean oldScreenOn = mAttachInfo.mKeepScreenOn; |
| 1218 | mAttachInfo.mKeepScreenOn = false; |
| 1219 | mAttachInfo.mSystemUiVisibility = 0; |
| 1220 | mAttachInfo.mHasSystemUiListeners = false; |
| 1221 | mView.dispatchCollectViewAttributes(mAttachInfo, 0); |
| 1222 | mAttachInfo.mSystemUiVisibility &= ~mAttachInfo.mDisabledSystemUiVisibility; |
Craig Mautner | 7eac0f5 | 2012-09-13 13:14:14 -0700 | [diff] [blame] | 1223 | WindowManager.LayoutParams params = mWindowAttributes; |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1224 | mAttachInfo.mSystemUiVisibility |= getImpliedSystemUiVisibility(params); |
| 1225 | if (mAttachInfo.mKeepScreenOn != oldScreenOn |
| 1226 | || mAttachInfo.mSystemUiVisibility != params.subtreeSystemUiVisibility |
| 1227 | || mAttachInfo.mHasSystemUiListeners != params.hasSystemUiListeners) { |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1228 | applyKeepScreenOnFlag(params); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1229 | params.subtreeSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
| 1230 | params.hasSystemUiListeners = mAttachInfo.mHasSystemUiListeners; |
| 1231 | mView.dispatchWindowSystemUiVisiblityChanged(mAttachInfo.mSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1232 | return true; |
| 1233 | } |
| 1234 | } |
| 1235 | return false; |
| 1236 | } |
| 1237 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 1238 | private int getImpliedSystemUiVisibility(WindowManager.LayoutParams params) { |
| 1239 | int vis = 0; |
| 1240 | // Translucent decor window flags imply stable system ui visibility. |
| 1241 | if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) != 0) { |
| 1242 | vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 1243 | } |
| 1244 | if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) != 0) { |
| 1245 | vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1246 | } |
| 1247 | return vis; |
| 1248 | } |
| 1249 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1250 | private boolean measureHierarchy(final View host, final WindowManager.LayoutParams lp, |
| 1251 | final Resources res, final int desiredWindowWidth, final int desiredWindowHeight) { |
| 1252 | int childWidthMeasureSpec; |
| 1253 | int childHeightMeasureSpec; |
| 1254 | boolean windowSizeMayChange = false; |
| 1255 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1256 | if (DEBUG_ORIENTATION || DEBUG_LAYOUT) Log.v(mTag, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1257 | "Measuring " + host + " in display " + desiredWindowWidth |
| 1258 | + "x" + desiredWindowHeight + "..."); |
| 1259 | |
| 1260 | boolean goodMeasure = false; |
| 1261 | if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) { |
| 1262 | // On large screens, we don't want to allow dialogs to just |
| 1263 | // stretch to fill the entire width of the screen to display |
| 1264 | // one line of text. First try doing the layout at a smaller |
| 1265 | // size to see if it will fit. |
| 1266 | final DisplayMetrics packageMetrics = res.getDisplayMetrics(); |
| 1267 | res.getValue(com.android.internal.R.dimen.config_prefDialogWidth, mTmpValue, true); |
| 1268 | int baseSize = 0; |
| 1269 | if (mTmpValue.type == TypedValue.TYPE_DIMENSION) { |
| 1270 | baseSize = (int)mTmpValue.getDimension(packageMetrics); |
| 1271 | } |
Filip Gruszczynski | 1937a4c | 2016-01-19 16:17:13 -0800 | [diff] [blame] | 1272 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": baseSize=" + baseSize |
| 1273 | + ", desiredWindowWidth=" + desiredWindowWidth); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1274 | if (baseSize != 0 && desiredWindowWidth > baseSize) { |
| 1275 | childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width); |
| 1276 | childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1277 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1278 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured (" |
Filip Gruszczynski | 1937a4c | 2016-01-19 16:17:13 -0800 | [diff] [blame] | 1279 | + host.getMeasuredWidth() + "," + host.getMeasuredHeight() |
| 1280 | + ") from width spec: " + MeasureSpec.toString(childWidthMeasureSpec) |
| 1281 | + " and height spec: " + MeasureSpec.toString(childHeightMeasureSpec)); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1282 | if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) { |
| 1283 | goodMeasure = true; |
| 1284 | } else { |
| 1285 | // Didn't fit in that size... try expanding a bit. |
| 1286 | baseSize = (baseSize+desiredWindowWidth)/2; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1287 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": next baseSize=" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1288 | + baseSize); |
| 1289 | childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1290 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1291 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured (" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1292 | + host.getMeasuredWidth() + "," + host.getMeasuredHeight() + ")"); |
| 1293 | if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1294 | if (DEBUG_DIALOG) Log.v(mTag, "Good!"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1295 | goodMeasure = true; |
| 1296 | } |
| 1297 | } |
| 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | if (!goodMeasure) { |
| 1302 | childWidthMeasureSpec = getRootMeasureSpec(desiredWindowWidth, lp.width); |
| 1303 | childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1304 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1305 | if (mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) { |
| 1306 | windowSizeMayChange = true; |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | if (DBG) { |
| 1311 | System.out.println("======================================"); |
| 1312 | System.out.println("performTraversals -- after measure"); |
| 1313 | host.debug(); |
| 1314 | } |
| 1315 | |
| 1316 | return windowSizeMayChange; |
| 1317 | } |
| 1318 | |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1319 | /** |
| 1320 | * Modifies the input matrix such that it maps view-local coordinates to |
| 1321 | * on-screen coordinates. |
| 1322 | * |
| 1323 | * @param m input matrix to modify |
| 1324 | */ |
| 1325 | void transformMatrixToGlobal(Matrix m) { |
Dake Gu | 7bf379c | 2014-07-15 16:29:38 -0700 | [diff] [blame] | 1326 | m.preTranslate(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | /** |
| 1330 | * Modifies the input matrix such that it maps on-screen coordinates to |
| 1331 | * view-local coordinates. |
| 1332 | * |
| 1333 | * @param m input matrix to modify |
| 1334 | */ |
| 1335 | void transformMatrixToLocal(Matrix m) { |
Dake Gu | 7bf379c | 2014-07-15 16:29:38 -0700 | [diff] [blame] | 1336 | m.postTranslate(-mAttachInfo.mWindowLeft, -mAttachInfo.mWindowTop); |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1337 | } |
| 1338 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1339 | /* package */ WindowInsets getWindowInsets(boolean forceConstruct) { |
| 1340 | if (mLastWindowInsets == null || forceConstruct) { |
| 1341 | mDispatchContentInsets.set(mAttachInfo.mContentInsets); |
| 1342 | mDispatchStableInsets.set(mAttachInfo.mStableInsets); |
| 1343 | Rect contentInsets = mDispatchContentInsets; |
| 1344 | Rect stableInsets = mDispatchStableInsets; |
| 1345 | // For dispatch we preserve old logic, but for direct requests from Views we allow to |
| 1346 | // immediately use pending insets. |
| 1347 | if (!forceConstruct |
| 1348 | && (!mPendingContentInsets.equals(contentInsets) || |
| 1349 | !mPendingStableInsets.equals(stableInsets))) { |
| 1350 | contentInsets = mPendingContentInsets; |
| 1351 | stableInsets = mPendingStableInsets; |
| 1352 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1353 | Rect outsets = mAttachInfo.mOutsets; |
| 1354 | if (outsets.left > 0 || outsets.top > 0 || outsets.right > 0 || outsets.bottom > 0) { |
| 1355 | contentInsets = new Rect(contentInsets.left + outsets.left, |
| 1356 | contentInsets.top + outsets.top, contentInsets.right + outsets.right, |
| 1357 | contentInsets.bottom + outsets.bottom); |
| 1358 | } |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1359 | mLastWindowInsets = new WindowInsets(contentInsets, |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1360 | null /* windowDecorInsets */, stableInsets, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1361 | mContext.getResources().getConfiguration().isScreenRound(), |
| 1362 | mAttachInfo.mAlwaysConsumeNavBar); |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1363 | } |
| 1364 | return mLastWindowInsets; |
| 1365 | } |
| 1366 | |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1367 | void dispatchApplyInsets(View host) { |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1368 | host.dispatchApplyWindowInsets(getWindowInsets(true /* forceConstruct */)); |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1371 | private static boolean shouldUseDisplaySize(final WindowManager.LayoutParams lp) { |
| 1372 | return lp.type == TYPE_STATUS_BAR_PANEL |
| 1373 | || lp.type == TYPE_INPUT_METHOD |
| 1374 | || lp.type == TYPE_VOLUME_OVERLAY; |
| 1375 | } |
| 1376 | |
| 1377 | private int dipToPx(int dip) { |
| 1378 | final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics(); |
| 1379 | return (int) (displayMetrics.density * dip + 0.5f); |
| 1380 | } |
| 1381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1382 | private void performTraversals() { |
| 1383 | // cache mView since it is used so much below... |
| 1384 | final View host = mView; |
| 1385 | |
| 1386 | if (DBG) { |
| 1387 | System.out.println("======================================"); |
| 1388 | System.out.println("performTraversals"); |
| 1389 | host.debug(); |
| 1390 | } |
| 1391 | |
| 1392 | if (host == null || !mAdded) |
| 1393 | return; |
| 1394 | |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 1395 | mIsInTraversal = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1396 | mWillDrawSoon = true; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1397 | boolean windowSizeMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | boolean newSurface = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1399 | boolean surfaceChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1400 | WindowManager.LayoutParams lp = mWindowAttributes; |
| 1401 | |
| 1402 | int desiredWindowWidth; |
| 1403 | int desiredWindowHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1405 | final int viewVisibility = getHostVisibility(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1406 | final boolean viewVisibilityChanged = !mFirst |
| 1407 | && (mViewVisibility != viewVisibility || mNewSurfaceNeeded); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1408 | |
| 1409 | WindowManager.LayoutParams params = null; |
| 1410 | if (mWindowAttributesChanged) { |
| 1411 | mWindowAttributesChanged = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1412 | surfaceChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1413 | params = lp; |
| 1414 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1415 | CompatibilityInfo compatibilityInfo = mDisplayAdjustments.getCompatibilityInfo(); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1416 | if (compatibilityInfo.supportsScreen() == mLastInCompatMode) { |
| 1417 | params = lp; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1418 | mFullRedrawNeeded = true; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1419 | mLayoutRequested = true; |
| 1420 | if (mLastInCompatMode) { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1421 | params.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1422 | mLastInCompatMode = false; |
| 1423 | } else { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1424 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1425 | mLastInCompatMode = true; |
| 1426 | } |
| 1427 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1428 | |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 1429 | mWindowAttributesChangesFlag = 0; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1430 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1431 | Rect frame = mWinFrame; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | if (mFirst) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1433 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1434 | mLayoutRequested = true; |
| 1435 | |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1436 | if (shouldUseDisplaySize(lp)) { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1437 | // NOTE -- system code, won't try to do compat mode. |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1438 | Point size = new Point(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1439 | mDisplay.getRealSize(size); |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1440 | desiredWindowWidth = size.x; |
| 1441 | desiredWindowHeight = size.y; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1442 | } else { |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1443 | Configuration config = mContext.getResources().getConfiguration(); |
| 1444 | desiredWindowWidth = dipToPx(config.screenWidthDp); |
| 1445 | desiredWindowHeight = dipToPx(config.screenHeightDp); |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1446 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1447 | |
Romain Guy | c5d5586 | 2011-01-21 19:01:46 -0800 | [diff] [blame] | 1448 | // We used to use the following condition to choose 32 bits drawing caches: |
| 1449 | // PixelFormat.hasAlpha(lp.format) || lp.format == PixelFormat.RGBX_8888 |
| 1450 | // However, windows are now always 32 bits by default, so choose 32 bits |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1451 | mAttachInfo.mUse32BitDrawingCache = true; |
| 1452 | mAttachInfo.mHasWindowFocus = false; |
| 1453 | mAttachInfo.mWindowVisibility = viewVisibility; |
| 1454 | mAttachInfo.mRecomputeGlobalAttributes = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1455 | mLastConfiguration.setTo(host.getResources().getConfiguration()); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1456 | mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 1457 | // Set the layout direction if it has not been set before (inherit is the default) |
| 1458 | if (mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) { |
| 1459 | host.setLayoutDirection(mLastConfiguration.getLayoutDirection()); |
| 1460 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1461 | host.dispatchAttachedToWindow(mAttachInfo, 0); |
| 1462 | mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(true); |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1463 | dispatchApplyInsets(host); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1464 | //Log.i(mTag, "Screen on initialized: " + attachInfo.mKeepScreenOn); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1465 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1466 | } else { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1467 | desiredWindowWidth = frame.width(); |
| 1468 | desiredWindowHeight = frame.height(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1469 | if (desiredWindowWidth != mWidth || desiredWindowHeight != mHeight) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1470 | if (DEBUG_ORIENTATION) Log.v(mTag, "View " + host + " resized to: " + frame); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1471 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1472 | mLayoutRequested = true; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1473 | windowSizeMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | if (viewVisibilityChanged) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1478 | mAttachInfo.mWindowVisibility = viewVisibility; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | host.dispatchWindowVisibilityChanged(viewVisibility); |
Adam Powell | 9c146bf | 2016-03-15 17:35:00 -0700 | [diff] [blame] | 1480 | host.dispatchVisibilityAggregated(viewVisibility == View.VISIBLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1481 | if (viewVisibility != View.VISIBLE || mNewSurfaceNeeded) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1482 | endDragResizing(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1483 | destroyHardwareResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1484 | } |
| 1485 | if (viewVisibility == View.GONE) { |
| 1486 | // After making a window gone, we will count it as being |
| 1487 | // shown for the first time the next time it gets focus. |
| 1488 | mHasHadWindowFocus = false; |
| 1489 | } |
| 1490 | } |
| 1491 | |
Alan Viverette | 7dbc3bf | 2015-01-28 16:14:36 -0800 | [diff] [blame] | 1492 | // Non-visible windows can't hold accessibility focus. |
| 1493 | if (mAttachInfo.mWindowVisibility != View.VISIBLE) { |
| 1494 | host.clearAccessibilityFocus(); |
| 1495 | } |
| 1496 | |
Chet Haase | b78c284 | 2012-04-19 13:39:50 -0700 | [diff] [blame] | 1497 | // Execute enqueued actions on every traversal in case a detached view enqueued an action |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1498 | getRunQueue().executeActions(mAttachInfo.mHandler); |
Chet Haase | b78c284 | 2012-04-19 13:39:50 -0700 | [diff] [blame] | 1499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | boolean insetsChanged = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1501 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1502 | boolean layoutRequested = mLayoutRequested && (!mStopped || mReportNextDraw); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1503 | if (layoutRequested) { |
Romain Guy | 15df670 | 2009-08-17 20:17:30 -0700 | [diff] [blame] | 1504 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1505 | final Resources res = mView.getContext().getResources(); |
| 1506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1507 | if (mFirst) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1508 | // make sure touch mode code executes by setting cached value |
| 1509 | // to opposite of the added touch mode. |
| 1510 | mAttachInfo.mInTouchMode = !mAddedTouchMode; |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 1511 | ensureTouchModeLocally(mAddedTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1513 | if (!mPendingOverscanInsets.equals(mAttachInfo.mOverscanInsets)) { |
| 1514 | insetsChanged = true; |
| 1515 | } |
Dianne Hackborn | fa6b35b | 2011-08-24 17:03:54 -0700 | [diff] [blame] | 1516 | if (!mPendingContentInsets.equals(mAttachInfo.mContentInsets)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | insetsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1518 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1519 | if (!mPendingStableInsets.equals(mAttachInfo.mStableInsets)) { |
| 1520 | insetsChanged = true; |
| 1521 | } |
Dianne Hackborn | fa6b35b | 2011-08-24 17:03:54 -0700 | [diff] [blame] | 1522 | if (!mPendingVisibleInsets.equals(mAttachInfo.mVisibleInsets)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1524 | if (DEBUG_LAYOUT) Log.v(mTag, "Visible insets changing to: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1525 | + mAttachInfo.mVisibleInsets); |
| 1526 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1527 | if (!mPendingOutsets.equals(mAttachInfo.mOutsets)) { |
| 1528 | insetsChanged = true; |
| 1529 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1530 | if (mPendingAlwaysConsumeNavBar != mAttachInfo.mAlwaysConsumeNavBar) { |
| 1531 | insetsChanged = true; |
| 1532 | } |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1533 | if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT |
| 1534 | || lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) { |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1535 | windowSizeMayChange = true; |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1536 | |
| 1537 | if (shouldUseDisplaySize(lp)) { |
| 1538 | // NOTE -- system code, won't try to do compat mode. |
| 1539 | Point size = new Point(); |
| 1540 | mDisplay.getRealSize(size); |
| 1541 | desiredWindowWidth = size.x; |
| 1542 | desiredWindowHeight = size.y; |
| 1543 | } else { |
| 1544 | Configuration config = res.getConfiguration(); |
| 1545 | desiredWindowWidth = dipToPx(config.screenWidthDp); |
| 1546 | desiredWindowHeight = dipToPx(config.screenHeightDp); |
| 1547 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1548 | } |
| 1549 | } |
| 1550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1551 | // Ask host how big it wants to be |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1552 | windowSizeMayChange |= measureHierarchy(host, lp, res, |
| 1553 | desiredWindowWidth, desiredWindowHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1554 | } |
| 1555 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1556 | if (collectViewAttributes()) { |
| 1557 | params = lp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1558 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1559 | if (mAttachInfo.mForceReportNewAttributes) { |
| 1560 | mAttachInfo.mForceReportNewAttributes = false; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1561 | params = lp; |
| 1562 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1563 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1564 | if (mFirst || mAttachInfo.mViewVisibilityChanged) { |
| 1565 | mAttachInfo.mViewVisibilityChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | int resizeMode = mSoftInputMode & |
| 1567 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 1568 | // If we are in auto resize mode, then we need to determine |
| 1569 | // what mode to use now. |
| 1570 | if (resizeMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1571 | final int N = mAttachInfo.mScrollContainers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1572 | for (int i=0; i<N; i++) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1573 | if (mAttachInfo.mScrollContainers.get(i).isShown()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | resizeMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 1575 | } |
| 1576 | } |
| 1577 | if (resizeMode == 0) { |
| 1578 | resizeMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN; |
| 1579 | } |
| 1580 | if ((lp.softInputMode & |
| 1581 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) != resizeMode) { |
| 1582 | lp.softInputMode = (lp.softInputMode & |
| 1583 | ~WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) | |
| 1584 | resizeMode; |
| 1585 | params = lp; |
| 1586 | } |
| 1587 | } |
| 1588 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1589 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1590 | if (params != null) { |
| 1591 | if ((host.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
| 1592 | if (!PixelFormat.formatHasAlpha(params.format)) { |
| 1593 | params.format = PixelFormat.TRANSLUCENT; |
| 1594 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1595 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1596 | mAttachInfo.mOverscanRequested = (params.flags |
| 1597 | & WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | } |
| 1599 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1600 | if (mApplyInsetsRequested) { |
| 1601 | mApplyInsetsRequested = false; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1602 | mLastOverscanRequested = mAttachInfo.mOverscanRequested; |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1603 | dispatchApplyInsets(host); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1604 | if (mLayoutRequested) { |
| 1605 | // Short-circuit catching a new layout request here, so |
| 1606 | // we don't need to go through two layout passes when things |
| 1607 | // change due to fitting system windows, which can happen a lot. |
| 1608 | windowSizeMayChange |= measureHierarchy(host, lp, |
| 1609 | mView.getContext().getResources(), |
| 1610 | desiredWindowWidth, desiredWindowHeight); |
| 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | if (layoutRequested) { |
| 1615 | // Clear this now, so that if anything requests a layout in the |
| 1616 | // rest of this function we will catch it and re-run a full |
| 1617 | // layout pass. |
| 1618 | mLayoutRequested = false; |
| 1619 | } |
| 1620 | |
| 1621 | boolean windowShouldResize = layoutRequested && windowSizeMayChange |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1622 | && ((mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) |
Romain Guy | 2e4f426 | 2010-04-06 11:07:52 -0700 | [diff] [blame] | 1623 | || (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT && |
| 1624 | frame.width() < desiredWindowWidth && frame.width() != mWidth) |
| 1625 | || (lp.height == ViewGroup.LayoutParams.WRAP_CONTENT && |
| 1626 | frame.height() < desiredWindowHeight && frame.height() != mHeight)); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1627 | windowShouldResize |= mDragResizing && mResizeMode == RESIZE_MODE_FREEFORM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1628 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1629 | // If the activity was just relaunched, it might have unfrozen the task bounds (while |
| 1630 | // relaunching), so we need to force a call into window manager to pick up the latest |
| 1631 | // bounds. |
| 1632 | windowShouldResize |= mActivityRelaunched; |
| 1633 | |
Jeff Brown | 2e05ec3 | 2013-09-30 15:57:43 -0700 | [diff] [blame] | 1634 | // Determine whether to compute insets. |
| 1635 | // If there are no inset listeners remaining then we may still need to compute |
| 1636 | // insets in case the old insets were non-empty and must be reset. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1637 | final boolean computesInternalInsets = |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1638 | mAttachInfo.mTreeObserver.hasComputeInternalInsetsListeners() |
| 1639 | || mAttachInfo.mHasNonEmptyGivenInternalInsets; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1641 | boolean insetsPending = false; |
| 1642 | int relayoutResult = 0; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1643 | |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 1644 | final boolean isViewVisible = viewVisibility == View.VISIBLE; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1645 | if (mFirst || windowShouldResize || insetsChanged || |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 1646 | viewVisibilityChanged || params != null || mForceNextWindowRelayout) { |
| 1647 | mForceNextWindowRelayout = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1648 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 1649 | if (isViewVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1650 | // If this window is giving internal insets to the window |
| 1651 | // manager, and it is being added or changing its visibility, |
| 1652 | // then we want to first give the window manager "fake" |
| 1653 | // insets to cause it to effectively ignore the content of |
| 1654 | // the window during layout. This avoids it briefly causing |
| 1655 | // other windows to resize/move based on the raw frame of the |
| 1656 | // window, waiting until we can finish laying out this window |
| 1657 | // and get back to the window manager with the ultimately |
| 1658 | // computed insets. |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1659 | insetsPending = computesInternalInsets && (mFirst || viewVisibilityChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1660 | } |
| 1661 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1662 | if (mSurfaceHolder != null) { |
| 1663 | mSurfaceHolder.mSurfaceLock.lock(); |
| 1664 | mDrawingAllowed = true; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1665 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1666 | |
Romain Guy | c361da8 | 2010-10-25 15:29:10 -0700 | [diff] [blame] | 1667 | boolean hwInitialized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1668 | boolean contentInsetsChanged = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1669 | boolean hadSurface = mSurface.isValid(); |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1670 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1671 | try { |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1672 | if (DEBUG_LAYOUT) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1673 | Log.i(mTag, "host=w:" + host.getMeasuredWidth() + ", h:" + |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1674 | host.getMeasuredHeight() + ", params=" + params); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1675 | } |
Romain Guy | 2a83f00 | 2011-01-18 18:28:21 -0800 | [diff] [blame] | 1676 | |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 1677 | if (mAttachInfo.mHardwareRenderer != null) { |
| 1678 | // relayoutWindow may decide to destroy mSurface. As that decision |
| 1679 | // happens in WindowManager service, we need to be defensive here |
| 1680 | // and stop using the surface in case it gets destroyed. |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 1681 | if (mAttachInfo.mHardwareRenderer.pauseSurface(mSurface)) { |
| 1682 | // Animations were running so we need to push a frame |
| 1683 | // to resume them |
| 1684 | mDirty.set(0, 0, mWidth, mHeight); |
| 1685 | } |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 1686 | mChoreographer.mFrameInfo.addFlags(FrameInfo.FLAG_WINDOW_LAYOUT_CHANGED); |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 1687 | } |
Romain Guy | 2a83f00 | 2011-01-18 18:28:21 -0800 | [diff] [blame] | 1688 | final int surfaceGenerationId = mSurface.getGenerationId(); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1689 | relayoutResult = relayoutWindow(params, viewVisibility, insetsPending); |
| 1690 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1691 | if (DEBUG_LAYOUT) Log.v(mTag, "relayout: frame=" + frame.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1692 | + " overscan=" + mPendingOverscanInsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1693 | + " content=" + mPendingContentInsets.toShortString() |
| 1694 | + " visible=" + mPendingVisibleInsets.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1695 | + " visible=" + mPendingStableInsets.toShortString() |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 1696 | + " outsets=" + mPendingOutsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1697 | + " surface=" + mSurface); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1698 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1699 | if (mPendingConfiguration.seq != 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1700 | if (DEBUG_CONFIGURATION) Log.v(mTag, "Visible with new config: " |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1701 | + mPendingConfiguration); |
riddle_hsu | 164725c | 2015-11-12 14:07:12 +0800 | [diff] [blame] | 1702 | updateConfiguration(new Configuration(mPendingConfiguration), !mFirst); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1703 | mPendingConfiguration.seq = 0; |
| 1704 | } |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 1705 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1706 | final boolean overscanInsetsChanged = !mPendingOverscanInsets.equals( |
| 1707 | mAttachInfo.mOverscanInsets); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1708 | contentInsetsChanged = !mPendingContentInsets.equals( |
| 1709 | mAttachInfo.mContentInsets); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1710 | final boolean visibleInsetsChanged = !mPendingVisibleInsets.equals( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1711 | mAttachInfo.mVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1712 | final boolean stableInsetsChanged = !mPendingStableInsets.equals( |
| 1713 | mAttachInfo.mStableInsets); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1714 | final boolean outsetsChanged = !mPendingOutsets.equals(mAttachInfo.mOutsets); |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1715 | final boolean surfaceSizeChanged = (relayoutResult |
| 1716 | & WindowManagerGlobal.RELAYOUT_RES_SURFACE_RESIZED) != 0; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1717 | final boolean alwaysConsumeNavBarChanged = |
| 1718 | mPendingAlwaysConsumeNavBar != mAttachInfo.mAlwaysConsumeNavBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1719 | if (contentInsetsChanged) { |
| 1720 | mAttachInfo.mContentInsets.set(mPendingContentInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1721 | if (DEBUG_LAYOUT) Log.v(mTag, "Content insets changing to: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1722 | + mAttachInfo.mContentInsets); |
| 1723 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1724 | if (overscanInsetsChanged) { |
| 1725 | mAttachInfo.mOverscanInsets.set(mPendingOverscanInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1726 | if (DEBUG_LAYOUT) Log.v(mTag, "Overscan insets changing to: " |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1727 | + mAttachInfo.mOverscanInsets); |
| 1728 | // Need to relayout with content insets. |
| 1729 | contentInsetsChanged = true; |
| 1730 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1731 | if (stableInsetsChanged) { |
| 1732 | mAttachInfo.mStableInsets.set(mPendingStableInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1733 | if (DEBUG_LAYOUT) Log.v(mTag, "Decor insets changing to: " |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1734 | + mAttachInfo.mStableInsets); |
| 1735 | // Need to relayout with content insets. |
| 1736 | contentInsetsChanged = true; |
| 1737 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1738 | if (alwaysConsumeNavBarChanged) { |
| 1739 | mAttachInfo.mAlwaysConsumeNavBar = mPendingAlwaysConsumeNavBar; |
| 1740 | contentInsetsChanged = true; |
| 1741 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1742 | if (contentInsetsChanged || mLastSystemUiVisibility != |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1743 | mAttachInfo.mSystemUiVisibility || mApplyInsetsRequested |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1744 | || mLastOverscanRequested != mAttachInfo.mOverscanRequested |
| 1745 | || outsetsChanged) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1746 | mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1747 | mLastOverscanRequested = mAttachInfo.mOverscanRequested; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1748 | mAttachInfo.mOutsets.set(mPendingOutsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1749 | mApplyInsetsRequested = false; |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1750 | dispatchApplyInsets(host); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1751 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1752 | if (visibleInsetsChanged) { |
| 1753 | mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1754 | if (DEBUG_LAYOUT) Log.v(mTag, "Visible insets changing to: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1755 | + mAttachInfo.mVisibleInsets); |
| 1756 | } |
| 1757 | |
| 1758 | if (!hadSurface) { |
| 1759 | if (mSurface.isValid()) { |
| 1760 | // If we are creating a new surface, then we need to |
| 1761 | // completely redraw it. Also, when we get to the |
| 1762 | // point of drawing it we will hold off and schedule |
| 1763 | // a new traversal instead. This is so we can tell the |
| 1764 | // window manager about all of the windows being displayed |
| 1765 | // before actually drawing them, so it can display then |
| 1766 | // all at once. |
| 1767 | newSurface = true; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1768 | mFullRedrawNeeded = true; |
Jack Palevich | 61a6e68 | 2009-10-09 17:37:50 -0700 | [diff] [blame] | 1769 | mPreviousTransparentRegion.setEmpty(); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1770 | |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 1771 | // Only initialize up-front if transparent regions are not |
| 1772 | // requested, otherwise defer to see if the entire window |
| 1773 | // will be transparent |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1774 | if (mAttachInfo.mHardwareRenderer != null) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1775 | try { |
Romain Guy | 786fc93 | 2012-07-24 16:24:56 -0700 | [diff] [blame] | 1776 | hwInitialized = mAttachInfo.mHardwareRenderer.initialize( |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 1777 | mSurface); |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 1778 | if (hwInitialized && (host.mPrivateFlags |
| 1779 | & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) == 0) { |
| 1780 | // Don't pre-allocate if transparent regions |
| 1781 | // are requested as they may not be needed |
| 1782 | mSurface.allocateBuffers(); |
| 1783 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1784 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 1785 | handleOutOfResourcesException(e); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1786 | return; |
| 1787 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1788 | } |
| 1789 | } |
| 1790 | } else if (!mSurface.isValid()) { |
| 1791 | // If the surface has been removed, then reset the scroll |
| 1792 | // positions. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 1793 | if (mLastScrolledFocus != null) { |
| 1794 | mLastScrolledFocus.clear(); |
| 1795 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1796 | mScrollY = mCurScrollY = 0; |
Adrian Roos | 0e7ae4e | 2014-10-01 15:33:22 +0200 | [diff] [blame] | 1797 | if (mView instanceof RootViewSurfaceTaker) { |
| 1798 | ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY); |
| 1799 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1800 | if (mScroller != null) { |
| 1801 | mScroller.abortAnimation(); |
| 1802 | } |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 1803 | // Our surface is gone |
| 1804 | if (mAttachInfo.mHardwareRenderer != null && |
| 1805 | mAttachInfo.mHardwareRenderer.isEnabled()) { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 1806 | mAttachInfo.mHardwareRenderer.destroy(); |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 1807 | } |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1808 | } else if ((surfaceGenerationId != mSurface.getGenerationId() |
| 1809 | || surfaceSizeChanged) |
| 1810 | && mSurfaceHolder == null |
| 1811 | && mAttachInfo.mHardwareRenderer != null) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1812 | mFullRedrawNeeded = true; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1813 | try { |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1814 | // Need to do updateSurface (which leads to CanvasContext::setSurface and |
| 1815 | // re-create the EGLSurface) if either the Surface changed (as indicated by |
| 1816 | // generation id), or WindowManager changed the surface size. The latter is |
| 1817 | // because on some chips, changing the consumer side's BufferQueue size may |
| 1818 | // not take effect immediately unless we create a new EGLSurface. |
| 1819 | // Note that frame size change doesn't always imply surface size change (eg. |
| 1820 | // drag resizing uses fullscreen surface), need to check surfaceSizeChanged |
| 1821 | // flag from WindowManager. |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 1822 | mAttachInfo.mHardwareRenderer.updateSurface(mSurface); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1823 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 1824 | handleOutOfResourcesException(e); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1825 | return; |
| 1826 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1827 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1828 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1829 | final boolean freeformResizing = (relayoutResult |
| 1830 | & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM) != 0; |
| 1831 | final boolean dockedResizing = (relayoutResult |
| 1832 | & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED) != 0; |
| 1833 | final boolean dragResizing = freeformResizing || dockedResizing; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1834 | if (mDragResizing != dragResizing) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1835 | if (dragResizing) { |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1836 | mResizeMode = freeformResizing |
| 1837 | ? RESIZE_MODE_FREEFORM |
| 1838 | : RESIZE_MODE_DOCKED_DIVIDER; |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 1839 | startDragResizing(mPendingBackDropFrame, |
| 1840 | mWinFrame.equals(mPendingBackDropFrame), mPendingVisibleInsets, |
| 1841 | mPendingStableInsets, mResizeMode); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1842 | } else { |
| 1843 | // We shouldn't come here, but if we come we should end the resize. |
| 1844 | endDragResizing(); |
| 1845 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1846 | } |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1847 | if (!USE_MT_RENDERER) { |
| 1848 | if (dragResizing) { |
| 1849 | mCanvasOffsetX = mWinFrame.left; |
| 1850 | mCanvasOffsetY = mWinFrame.top; |
| 1851 | } else { |
| 1852 | mCanvasOffsetX = mCanvasOffsetY = 0; |
| 1853 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1854 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1855 | } catch (RemoteException e) { |
| 1856 | } |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 1857 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1858 | if (DEBUG_ORIENTATION) Log.v( |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1859 | TAG, "Relayout returned: frame=" + frame + ", surface=" + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1860 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1861 | mAttachInfo.mWindowLeft = frame.left; |
| 1862 | mAttachInfo.mWindowTop = frame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1863 | |
| 1864 | // !!FIXME!! This next section handles the case where we did not get the |
| 1865 | // window size we asked for. We should avoid this by getting a maximum size from |
| 1866 | // the window session beforehand. |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 1867 | if (mWidth != frame.width() || mHeight != frame.height()) { |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 1868 | mWidth = frame.width(); |
| 1869 | mHeight = frame.height(); |
| 1870 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1871 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1872 | if (mSurfaceHolder != null) { |
| 1873 | // The app owns the surface; tell it about what is going on. |
| 1874 | if (mSurface.isValid()) { |
| 1875 | // XXX .copyFrom() doesn't work! |
| 1876 | //mSurfaceHolder.mSurface.copyFrom(mSurface); |
| 1877 | mSurfaceHolder.mSurface = mSurface; |
| 1878 | } |
Jeff Brown | 30bc34f | 2011-01-25 12:56:56 -0800 | [diff] [blame] | 1879 | mSurfaceHolder.setSurfaceFrameSize(mWidth, mHeight); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1880 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 1881 | if (mSurface.isValid()) { |
| 1882 | if (!hadSurface) { |
| 1883 | mSurfaceHolder.ungetCallbacks(); |
| 1884 | |
| 1885 | mIsCreating = true; |
| 1886 | mSurfaceHolderCallback.surfaceCreated(mSurfaceHolder); |
| 1887 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 1888 | if (callbacks != null) { |
| 1889 | for (SurfaceHolder.Callback c : callbacks) { |
| 1890 | c.surfaceCreated(mSurfaceHolder); |
| 1891 | } |
| 1892 | } |
| 1893 | surfaceChanged = true; |
| 1894 | } |
| 1895 | if (surfaceChanged) { |
| 1896 | mSurfaceHolderCallback.surfaceChanged(mSurfaceHolder, |
| 1897 | lp.format, mWidth, mHeight); |
| 1898 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 1899 | if (callbacks != null) { |
| 1900 | for (SurfaceHolder.Callback c : callbacks) { |
| 1901 | c.surfaceChanged(mSurfaceHolder, lp.format, |
| 1902 | mWidth, mHeight); |
| 1903 | } |
| 1904 | } |
| 1905 | } |
| 1906 | mIsCreating = false; |
| 1907 | } else if (hadSurface) { |
| 1908 | mSurfaceHolder.ungetCallbacks(); |
| 1909 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 1910 | mSurfaceHolderCallback.surfaceDestroyed(mSurfaceHolder); |
| 1911 | if (callbacks != null) { |
| 1912 | for (SurfaceHolder.Callback c : callbacks) { |
| 1913 | c.surfaceDestroyed(mSurfaceHolder); |
| 1914 | } |
| 1915 | } |
| 1916 | mSurfaceHolder.mSurfaceLock.lock(); |
Jozef BABJAK | 93c5b6a | 2011-02-22 09:33:19 +0100 | [diff] [blame] | 1917 | try { |
| 1918 | mSurfaceHolder.mSurface = new Surface(); |
| 1919 | } finally { |
| 1920 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 1921 | } |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1922 | } |
| 1923 | } |
Romain Guy | 53389bd | 2010-09-07 17:16:32 -0700 | [diff] [blame] | 1924 | |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 1925 | final ThreadedRenderer hardwareRenderer = mAttachInfo.mHardwareRenderer; |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 1926 | if (hardwareRenderer != null && hardwareRenderer.isEnabled()) { |
| 1927 | if (hwInitialized |
| 1928 | || mWidth != hardwareRenderer.getWidth() |
| 1929 | || mHeight != hardwareRenderer.getHeight()) { |
| 1930 | hardwareRenderer.setup(mWidth, mHeight, mAttachInfo, |
| 1931 | mWindowAttributes.surfaceInsets); |
Romain Guy | 0398575 | 2011-07-11 15:33:51 -0700 | [diff] [blame] | 1932 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1933 | } |
| 1934 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1935 | if (!mStopped || mReportNextDraw) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1936 | boolean focusChangedDueToTouchMode = ensureTouchModeLocally( |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1937 | (relayoutResult&WindowManagerGlobal.RELAYOUT_RES_IN_TOUCH_MODE) != 0); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1938 | if (focusChangedDueToTouchMode || mWidth != host.getMeasuredWidth() |
| 1939 | || mHeight != host.getMeasuredHeight() || contentInsetsChanged) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1940 | int childWidthMeasureSpec = getRootMeasureSpec(mWidth, lp.width); |
| 1941 | int childHeightMeasureSpec = getRootMeasureSpec(mHeight, lp.height); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1942 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1943 | if (DEBUG_LAYOUT) Log.v(mTag, "Ooops, something changed! mWidth=" |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1944 | + mWidth + " measuredWidth=" + host.getMeasuredWidth() |
| 1945 | + " mHeight=" + mHeight |
| 1946 | + " measuredHeight=" + host.getMeasuredHeight() |
| 1947 | + " coveredInsetsChanged=" + contentInsetsChanged); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1948 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1949 | // Ask host how big it wants to be |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1950 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1951 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1952 | // Implementation of weights from WindowManager.LayoutParams |
| 1953 | // We just grow the dimensions as needed and re-measure if |
| 1954 | // needs be |
| 1955 | int width = host.getMeasuredWidth(); |
| 1956 | int height = host.getMeasuredHeight(); |
| 1957 | boolean measureAgain = false; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1958 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1959 | if (lp.horizontalWeight > 0.0f) { |
| 1960 | width += (int) ((mWidth - width) * lp.horizontalWeight); |
| 1961 | childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(width, |
| 1962 | MeasureSpec.EXACTLY); |
| 1963 | measureAgain = true; |
| 1964 | } |
| 1965 | if (lp.verticalWeight > 0.0f) { |
| 1966 | height += (int) ((mHeight - height) * lp.verticalWeight); |
| 1967 | childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, |
| 1968 | MeasureSpec.EXACTLY); |
| 1969 | measureAgain = true; |
| 1970 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1971 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1972 | if (measureAgain) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1973 | if (DEBUG_LAYOUT) Log.v(mTag, |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1974 | "And hey let's measure once more: width=" + width |
| 1975 | + " height=" + height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1976 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1977 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1978 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1979 | layoutRequested = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1980 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1981 | } |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 1982 | } else { |
| 1983 | // Not the first pass and no window/insets/visibility change but the window |
| 1984 | // may have moved and we need check that and if so to update the left and right |
| 1985 | // in the attach info. We translate only the window frame since on window move |
| 1986 | // the window manager tells us only for the new frame but the insets are the |
| 1987 | // same and we do not want to translate them more than once. |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 1988 | maybeHandleWindowMove(frame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1989 | } |
| 1990 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1991 | final boolean didLayout = layoutRequested && (!mStopped || mReportNextDraw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1992 | boolean triggerGlobalLayoutListener = didLayout |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1993 | || mAttachInfo.mRecomputeGlobalAttributes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1994 | if (didLayout) { |
Jorim Jaggi | 26d02d2 | 2016-02-24 18:37:51 -0500 | [diff] [blame] | 1995 | performLayout(lp, mWidth, mHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1996 | |
Mathias Agopian | 54e3d384 | 2013-04-12 15:13:12 -0700 | [diff] [blame] | 1997 | // By this point all views have been sized and positioned |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1998 | // We can compute the transparent area |
| 1999 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2000 | if ((host.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2001 | // start out transparent |
| 2002 | // TODO: AVOID THAT CALL BY CACHING THE RESULT? |
| 2003 | host.getLocationInWindow(mTmpLocation); |
| 2004 | mTransparentRegion.set(mTmpLocation[0], mTmpLocation[1], |
| 2005 | mTmpLocation[0] + host.mRight - host.mLeft, |
| 2006 | mTmpLocation[1] + host.mBottom - host.mTop); |
| 2007 | |
| 2008 | host.gatherTransparentRegion(mTransparentRegion); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 2009 | if (mTranslator != null) { |
| 2010 | mTranslator.translateRegionInWindowToScreen(mTransparentRegion); |
| 2011 | } |
| 2012 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2013 | if (!mTransparentRegion.equals(mPreviousTransparentRegion)) { |
| 2014 | mPreviousTransparentRegion.set(mTransparentRegion); |
Mathias Agopian | 54e3d384 | 2013-04-12 15:13:12 -0700 | [diff] [blame] | 2015 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2016 | // reconfigure window manager |
| 2017 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2018 | mWindowSession.setTransparentRegion(mWindow, mTransparentRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2019 | } catch (RemoteException e) { |
| 2020 | } |
| 2021 | } |
| 2022 | } |
| 2023 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2024 | if (DBG) { |
| 2025 | System.out.println("======================================"); |
Chet Haase | 4610eef | 2015-12-03 07:38:11 -0800 | [diff] [blame] | 2026 | System.out.println("performTraversals -- after setFrame"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2027 | host.debug(); |
| 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | if (triggerGlobalLayoutListener) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2032 | mAttachInfo.mRecomputeGlobalAttributes = false; |
| 2033 | mAttachInfo.mTreeObserver.dispatchOnGlobalLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | if (computesInternalInsets) { |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2037 | // Clear the original insets. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2038 | final ViewTreeObserver.InternalInsetsInfo insets = mAttachInfo.mGivenInternalInsets; |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2039 | insets.reset(); |
| 2040 | |
| 2041 | // Compute new insets in place. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2042 | mAttachInfo.mTreeObserver.dispatchOnComputeInternalInsets(insets); |
| 2043 | mAttachInfo.mHasNonEmptyGivenInternalInsets = !insets.isEmpty(); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2044 | |
| 2045 | // Tell the window manager. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2046 | if (insetsPending || !mLastGivenInsets.equals(insets)) { |
| 2047 | mLastGivenInsets.set(insets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2048 | |
| 2049 | // Translate insets to screen coordinates if needed. |
| 2050 | final Rect contentInsets; |
| 2051 | final Rect visibleInsets; |
| 2052 | final Region touchableRegion; |
| 2053 | if (mTranslator != null) { |
| 2054 | contentInsets = mTranslator.getTranslatedContentInsets(insets.contentInsets); |
| 2055 | visibleInsets = mTranslator.getTranslatedVisibleInsets(insets.visibleInsets); |
| 2056 | touchableRegion = mTranslator.getTranslatedTouchableArea(insets.touchableRegion); |
| 2057 | } else { |
| 2058 | contentInsets = insets.contentInsets; |
| 2059 | visibleInsets = insets.visibleInsets; |
| 2060 | touchableRegion = insets.touchableRegion; |
| 2061 | } |
| 2062 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2063 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2064 | mWindowSession.setInsets(mWindow, insets.mTouchableInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2065 | contentInsets, visibleInsets, touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2066 | } catch (RemoteException e) { |
| 2067 | } |
| 2068 | } |
| 2069 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2071 | if (mFirst) { |
| 2072 | // handle first focus request |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2073 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: mView.hasFocus()=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | + mView.hasFocus()); |
| 2075 | if (mView != null) { |
| 2076 | if (!mView.hasFocus()) { |
| 2077 | mView.requestFocus(View.FOCUS_FORWARD); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2078 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: requested focused view=" |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2079 | + mView.findFocus()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2080 | } else { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2081 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: existing focused view=" |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2082 | + mView.findFocus()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2083 | } |
| 2084 | } |
| 2085 | } |
| 2086 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2087 | final boolean changedVisibility = (viewVisibilityChanged || mFirst) && isViewVisible; |
| 2088 | final boolean hasWindowFocus = mAttachInfo.mHasWindowFocus && isViewVisible; |
| 2089 | final boolean regainedFocus = hasWindowFocus && mLostWindowFocus; |
| 2090 | if (regainedFocus) { |
| 2091 | mLostWindowFocus = false; |
| 2092 | } else if (!hasWindowFocus && mHadWindowFocus) { |
| 2093 | mLostWindowFocus = true; |
| 2094 | } |
| 2095 | |
| 2096 | if (changedVisibility || regainedFocus) { |
| 2097 | host.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 2098 | } |
| 2099 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2100 | mFirst = false; |
| 2101 | mWillDrawSoon = false; |
| 2102 | mNewSurfaceNeeded = false; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 2103 | mActivityRelaunched = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2104 | mViewVisibility = viewVisibility; |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2105 | mHadWindowFocus = hasWindowFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2106 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2107 | if (hasWindowFocus && !isInLocalFocusMode()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2108 | final boolean imTarget = WindowManager.LayoutParams |
| 2109 | .mayUseInputMethod(mWindowAttributes.flags); |
| 2110 | if (imTarget != mLastWasImTarget) { |
| 2111 | mLastWasImTarget = imTarget; |
| 2112 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 2113 | if (imm != null && imTarget) { |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2114 | imm.onPreWindowFocus(mView, hasWindowFocus); |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 2115 | imm.onPostWindowFocus(mView, mView.findFocus(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2116 | mWindowAttributes.softInputMode, |
| 2117 | !mHasHadWindowFocus, mWindowAttributes.flags); |
| 2118 | } |
| 2119 | } |
| 2120 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2121 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2122 | // Remember if we must report the next draw. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2123 | if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2124 | mReportNextDraw = true; |
| 2125 | } |
| 2126 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2127 | boolean cancelDraw = mAttachInfo.mTreeObserver.dispatchOnPreDraw() || !isViewVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2128 | |
Jorim Jaggi | 75c21ca | 2016-03-28 19:26:09 -0400 | [diff] [blame] | 2129 | if (!cancelDraw && !newSurface) { |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2130 | if (mPendingTransitions != null && mPendingTransitions.size() > 0) { |
| 2131 | for (int i = 0; i < mPendingTransitions.size(); ++i) { |
| 2132 | mPendingTransitions.get(i).startChangingAnimations(); |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2133 | } |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2134 | mPendingTransitions.clear(); |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2135 | } |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2136 | |
| 2137 | performDraw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2138 | } else { |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2139 | if (isViewVisible) { |
Chris Wren | 78cb7cf | 2012-05-15 12:36:44 -0400 | [diff] [blame] | 2140 | // Try again |
| 2141 | scheduleTraversals(); |
| 2142 | } else if (mPendingTransitions != null && mPendingTransitions.size() > 0) { |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2143 | for (int i = 0; i < mPendingTransitions.size(); ++i) { |
| 2144 | mPendingTransitions.get(i).endChangingAnimations(); |
| 2145 | } |
| 2146 | mPendingTransitions.clear(); |
| 2147 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2148 | } |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 2149 | |
| 2150 | mIsInTraversal = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2151 | } |
| 2152 | |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2153 | private void maybeHandleWindowMove(Rect frame) { |
| 2154 | |
| 2155 | // TODO: Well, we are checking whether the frame has changed similarly |
| 2156 | // to how this is done for the insets. This is however incorrect since |
| 2157 | // the insets and the frame are translated. For example, the old frame |
| 2158 | // was (1, 1 - 1, 1) and was translated to say (2, 2 - 2, 2), now the new |
| 2159 | // reported frame is (2, 2 - 2, 2) which implies no change but this is not |
| 2160 | // true since we are comparing a not translated value to a translated one. |
| 2161 | // This scenario is rare but we may want to fix that. |
| 2162 | |
| 2163 | final boolean windowMoved = mAttachInfo.mWindowLeft != frame.left |
| 2164 | || mAttachInfo.mWindowTop != frame.top; |
| 2165 | if (windowMoved) { |
| 2166 | if (mTranslator != null) { |
| 2167 | mTranslator.translateRectInScreenToAppWinFrame(frame); |
| 2168 | } |
| 2169 | mAttachInfo.mWindowLeft = frame.left; |
| 2170 | mAttachInfo.mWindowTop = frame.top; |
| 2171 | |
| 2172 | // Update the light position for the new window offsets. |
| 2173 | if (mAttachInfo.mHardwareRenderer != null) { |
| 2174 | mAttachInfo.mHardwareRenderer.setLightCenter(mAttachInfo); |
| 2175 | } |
| 2176 | } |
| 2177 | } |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2178 | private void handleOutOfResourcesException(Surface.OutOfResourcesException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2179 | Log.e(mTag, "OutOfResourcesException initializing HW surface", e); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2180 | try { |
| 2181 | if (!mWindowSession.outOfMemory(mWindow) && |
| 2182 | Process.myUid() != Process.SYSTEM_UID) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2183 | Slog.w(mTag, "No processes killed for memory; killing self"); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2184 | Process.killProcess(Process.myPid()); |
| 2185 | } |
| 2186 | } catch (RemoteException ex) { |
| 2187 | } |
| 2188 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2189 | } |
| 2190 | |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2191 | private void performMeasure(int childWidthMeasureSpec, int childHeightMeasureSpec) { |
| 2192 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "measure"); |
| 2193 | try { |
| 2194 | mView.measure(childWidthMeasureSpec, childHeightMeasureSpec); |
| 2195 | } finally { |
| 2196 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2197 | } |
| 2198 | } |
| 2199 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2200 | /** |
| 2201 | * Called by {@link android.view.View#isInLayout()} to determine whether the view hierarchy |
| 2202 | * is currently undergoing a layout pass. |
| 2203 | * |
| 2204 | * @return whether the view hierarchy is currently undergoing a layout pass |
| 2205 | */ |
| 2206 | boolean isInLayout() { |
| 2207 | return mInLayout; |
| 2208 | } |
| 2209 | |
| 2210 | /** |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2211 | * Called by {@link android.view.View#requestLayout()} if the view hierarchy is currently |
| 2212 | * undergoing a layout pass. requestLayout() should not generally be called during layout, |
| 2213 | * unless the container hierarchy knows what it is doing (i.e., it is fine as long as |
| 2214 | * all children in that container hierarchy are measured and laid out at the end of the layout |
| 2215 | * pass for that container). If requestLayout() is called anyway, we handle it correctly |
| 2216 | * by registering all requesters during a frame as it proceeds. At the end of the frame, |
| 2217 | * we check all of those views to see if any still have pending layout requests, which |
| 2218 | * indicates that they were not correctly handled by their container hierarchy. If that is |
| 2219 | * the case, we clear all such flags in the tree, to remove the buggy flag state that leads |
| 2220 | * to blank containers, and force a second request/measure/layout pass in this frame. If |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2221 | * more requestLayout() calls are received during that second layout pass, we post those |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2222 | * requests to the next frame to avoid possible infinite loops. |
| 2223 | * |
| 2224 | * <p>The return value from this method indicates whether the request should proceed |
| 2225 | * (if it is a request during the first layout pass) or should be skipped and posted to the |
| 2226 | * next frame (if it is a request during the second layout pass).</p> |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2227 | * |
| 2228 | * @param view the view that requested the layout. |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2229 | * |
| 2230 | * @return true if request should proceed, false otherwise. |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2231 | */ |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2232 | boolean requestLayoutDuringLayout(final View view) { |
| 2233 | if (view.mParent == null || view.mAttachInfo == null) { |
| 2234 | // Would not normally trigger another layout, so just let it pass through as usual |
| 2235 | return true; |
| 2236 | } |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2237 | if (!mLayoutRequesters.contains(view)) { |
| 2238 | mLayoutRequesters.add(view); |
| 2239 | } |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2240 | if (!mHandlingLayoutInLayoutRequest) { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2241 | // Let the request proceed normally; it will be processed in a second layout pass |
| 2242 | // if necessary |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2243 | return true; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2244 | } else { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2245 | // Don't let the request proceed during the second layout pass. |
| 2246 | // It will post to the next frame instead. |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2247 | return false; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2248 | } |
| 2249 | } |
| 2250 | |
Chet Haase | 3efa7b5 | 2012-12-03 08:33:17 -0800 | [diff] [blame] | 2251 | private void performLayout(WindowManager.LayoutParams lp, int desiredWindowWidth, |
| 2252 | int desiredWindowHeight) { |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2253 | mLayoutRequested = false; |
| 2254 | mScrollMayChange = true; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2255 | mInLayout = true; |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2256 | |
| 2257 | final View host = mView; |
| 2258 | if (DEBUG_ORIENTATION || DEBUG_LAYOUT) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2259 | Log.v(mTag, "Laying out " + host + " to (" + |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2260 | host.getMeasuredWidth() + ", " + host.getMeasuredHeight() + ")"); |
| 2261 | } |
| 2262 | |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2263 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "layout"); |
| 2264 | try { |
| 2265 | host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2266 | |
Chet Haase | d5a8352 | 2012-11-21 16:24:44 -0800 | [diff] [blame] | 2267 | mInLayout = false; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2268 | int numViewsRequestingLayout = mLayoutRequesters.size(); |
| 2269 | if (numViewsRequestingLayout > 0) { |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2270 | // requestLayout() was called during layout. |
| 2271 | // If no layout-request flags are set on the requesting views, there is no problem. |
| 2272 | // If some requests are still pending, then we need to clear those flags and do |
| 2273 | // a full request/measure/layout pass to handle this situation. |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2274 | ArrayList<View> validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, |
| 2275 | false); |
| 2276 | if (validLayoutRequesters != null) { |
| 2277 | // Set this flag to indicate that any further requests are happening during |
| 2278 | // the second pass, which may result in posting those requests to the next |
| 2279 | // frame instead |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2280 | mHandlingLayoutInLayoutRequest = true; |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2281 | |
| 2282 | // Process fresh layout requests, then measure and layout |
| 2283 | int numValidRequests = validLayoutRequesters.size(); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2284 | for (int i = 0; i < numValidRequests; ++i) { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2285 | final View view = validLayoutRequesters.get(i); |
| 2286 | Log.w("View", "requestLayout() improperly called by " + view + |
| 2287 | " during layout: running second layout pass"); |
| 2288 | view.requestLayout(); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2289 | } |
| 2290 | measureHierarchy(host, lp, mView.getContext().getResources(), |
| 2291 | desiredWindowWidth, desiredWindowHeight); |
| 2292 | mInLayout = true; |
| 2293 | host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2294 | |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2295 | mHandlingLayoutInLayoutRequest = false; |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2296 | |
| 2297 | // Check the valid requests again, this time without checking/clearing the |
| 2298 | // layout flags, since requests happening during the second pass get noop'd |
| 2299 | validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, true); |
| 2300 | if (validLayoutRequesters != null) { |
| 2301 | final ArrayList<View> finalRequesters = validLayoutRequesters; |
| 2302 | // Post second-pass requests to the next frame |
| 2303 | getRunQueue().post(new Runnable() { |
| 2304 | @Override |
| 2305 | public void run() { |
| 2306 | int numValidRequests = finalRequesters.size(); |
| 2307 | for (int i = 0; i < numValidRequests; ++i) { |
| 2308 | final View view = finalRequesters.get(i); |
| 2309 | Log.w("View", "requestLayout() improperly called by " + view + |
| 2310 | " during second layout pass: posting in next frame"); |
| 2311 | view.requestLayout(); |
| 2312 | } |
| 2313 | } |
| 2314 | }); |
| 2315 | } |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2316 | } |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2317 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2318 | } |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2319 | } finally { |
| 2320 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2321 | } |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2322 | mInLayout = false; |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2325 | /** |
| 2326 | * This method is called during layout when there have been calls to requestLayout() during |
| 2327 | * layout. It walks through the list of views that requested layout to determine which ones |
| 2328 | * still need it, based on visibility in the hierarchy and whether they have already been |
| 2329 | * handled (as is usually the case with ListView children). |
| 2330 | * |
| 2331 | * @param layoutRequesters The list of views that requested layout during layout |
| 2332 | * @param secondLayoutRequests Whether the requests were issued during the second layout pass. |
| 2333 | * If so, the FORCE_LAYOUT flag was not set on requesters. |
| 2334 | * @return A list of the actual views that still need to be laid out. |
| 2335 | */ |
| 2336 | private ArrayList<View> getValidLayoutRequesters(ArrayList<View> layoutRequesters, |
| 2337 | boolean secondLayoutRequests) { |
| 2338 | |
| 2339 | int numViewsRequestingLayout = layoutRequesters.size(); |
| 2340 | ArrayList<View> validLayoutRequesters = null; |
| 2341 | for (int i = 0; i < numViewsRequestingLayout; ++i) { |
| 2342 | View view = layoutRequesters.get(i); |
| 2343 | if (view != null && view.mAttachInfo != null && view.mParent != null && |
| 2344 | (secondLayoutRequests || (view.mPrivateFlags & View.PFLAG_FORCE_LAYOUT) == |
| 2345 | View.PFLAG_FORCE_LAYOUT)) { |
| 2346 | boolean gone = false; |
| 2347 | View parent = view; |
| 2348 | // Only trigger new requests for views in a non-GONE hierarchy |
| 2349 | while (parent != null) { |
| 2350 | if ((parent.mViewFlags & View.VISIBILITY_MASK) == View.GONE) { |
| 2351 | gone = true; |
| 2352 | break; |
| 2353 | } |
| 2354 | if (parent.mParent instanceof View) { |
| 2355 | parent = (View) parent.mParent; |
| 2356 | } else { |
| 2357 | parent = null; |
| 2358 | } |
| 2359 | } |
| 2360 | if (!gone) { |
| 2361 | if (validLayoutRequesters == null) { |
| 2362 | validLayoutRequesters = new ArrayList<View>(); |
| 2363 | } |
| 2364 | validLayoutRequesters.add(view); |
| 2365 | } |
| 2366 | } |
| 2367 | } |
| 2368 | if (!secondLayoutRequests) { |
| 2369 | // If we're checking the layout flags, then we need to clean them up also |
| 2370 | for (int i = 0; i < numViewsRequestingLayout; ++i) { |
| 2371 | View view = layoutRequesters.get(i); |
| 2372 | while (view != null && |
| 2373 | (view.mPrivateFlags & View.PFLAG_FORCE_LAYOUT) != 0) { |
| 2374 | view.mPrivateFlags &= ~View.PFLAG_FORCE_LAYOUT; |
| 2375 | if (view.mParent instanceof View) { |
| 2376 | view = (View) view.mParent; |
| 2377 | } else { |
| 2378 | view = null; |
| 2379 | } |
| 2380 | } |
| 2381 | } |
| 2382 | } |
| 2383 | layoutRequesters.clear(); |
| 2384 | return validLayoutRequesters; |
| 2385 | } |
| 2386 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2387 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2388 | public void requestTransparentRegion(View child) { |
| 2389 | // the test below should not fail unless someone is messing with us |
| 2390 | checkThread(); |
| 2391 | if (mView == child) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2392 | mView.mPrivateFlags |= View.PFLAG_REQUEST_TRANSPARENT_REGIONS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2393 | // Need to make sure we re-evaluate the window attributes next |
| 2394 | // time around, to ensure the window has the correct format. |
| 2395 | mWindowAttributesChanged = true; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 2396 | mWindowAttributesChangesFlag = 0; |
Mathias Agopian | 1bd80ad | 2010-11-04 17:13:39 -0700 | [diff] [blame] | 2397 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | /** |
| 2402 | * Figures out the measure spec for the root view in a window based on it's |
| 2403 | * layout params. |
| 2404 | * |
| 2405 | * @param windowSize |
| 2406 | * The available width or height of the window |
| 2407 | * |
| 2408 | * @param rootDimension |
| 2409 | * The layout params for one dimension (width or height) of the |
| 2410 | * window. |
| 2411 | * |
| 2412 | * @return The measure spec to use to measure the root view. |
| 2413 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 2414 | private static int getRootMeasureSpec(int windowSize, int rootDimension) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2415 | int measureSpec; |
| 2416 | switch (rootDimension) { |
| 2417 | |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 2418 | case ViewGroup.LayoutParams.MATCH_PARENT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2419 | // Window can't resize. Force root view to be windowSize. |
| 2420 | measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.EXACTLY); |
| 2421 | break; |
| 2422 | case ViewGroup.LayoutParams.WRAP_CONTENT: |
| 2423 | // Window can resize. Set max size for root view. |
| 2424 | measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.AT_MOST); |
| 2425 | break; |
| 2426 | default: |
| 2427 | // Window wants to be an exact size. Force root view to be that size. |
| 2428 | measureSpec = MeasureSpec.makeMeasureSpec(rootDimension, MeasureSpec.EXACTLY); |
| 2429 | break; |
| 2430 | } |
| 2431 | return measureSpec; |
| 2432 | } |
| 2433 | |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2434 | int mHardwareXOffset; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2435 | int mHardwareYOffset; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2436 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2437 | @Override |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 2438 | public void onHardwarePreDraw(DisplayListCanvas canvas) { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2439 | canvas.translate(-mHardwareXOffset, -mHardwareYOffset); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2440 | } |
| 2441 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2442 | @Override |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 2443 | public void onHardwarePostDraw(DisplayListCanvas canvas) { |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2444 | drawAccessibilityFocusedDrawableIfNeeded(canvas); |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 2445 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 2446 | mWindowCallbacks.get(i).onPostDraw(canvas); |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 2447 | } |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2448 | } |
| 2449 | |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 2450 | /** |
| 2451 | * @hide |
| 2452 | */ |
| 2453 | void outputDisplayList(View view) { |
Chris Craik | 356b5fe | 2015-07-07 10:39:36 -0700 | [diff] [blame] | 2454 | view.mRenderNode.output(); |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 2455 | if (mAttachInfo.mHardwareRenderer != null) { |
| 2456 | ((ThreadedRenderer)mAttachInfo.mHardwareRenderer).serializeDisplayListTree(); |
| 2457 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2458 | } |
| 2459 | |
| 2460 | /** |
| 2461 | * @see #PROPERTY_PROFILE_RENDERING |
| 2462 | */ |
| 2463 | private void profileRendering(boolean enabled) { |
| 2464 | if (mProfileRendering) { |
| 2465 | mRenderProfilingEnabled = enabled; |
Chris Craik | ae4f3204 | 2013-02-07 12:57:10 -0800 | [diff] [blame] | 2466 | |
| 2467 | if (mRenderProfiler != null) { |
| 2468 | mChoreographer.removeFrameCallback(mRenderProfiler); |
| 2469 | } |
| 2470 | if (mRenderProfilingEnabled) { |
| 2471 | if (mRenderProfiler == null) { |
| 2472 | mRenderProfiler = new Choreographer.FrameCallback() { |
| 2473 | @Override |
| 2474 | public void doFrame(long frameTimeNanos) { |
| 2475 | mDirty.set(0, 0, mWidth, mHeight); |
| 2476 | scheduleTraversals(); |
| 2477 | if (mRenderProfilingEnabled) { |
| 2478 | mChoreographer.postFrameCallback(mRenderProfiler); |
| 2479 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2480 | } |
Chris Craik | ae4f3204 | 2013-02-07 12:57:10 -0800 | [diff] [blame] | 2481 | }; |
| 2482 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 2483 | mChoreographer.postFrameCallback(mRenderProfiler); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2484 | } else { |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2485 | mRenderProfiler = null; |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 2486 | } |
| 2487 | } |
| 2488 | } |
| 2489 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2490 | /** |
| 2491 | * Called from draw() when DEBUG_FPS is enabled |
| 2492 | */ |
| 2493 | private void trackFPS() { |
| 2494 | // Tracks frames per second drawn. First value in a series of draws may be bogus |
| 2495 | // because it down not account for the intervening idle time |
| 2496 | long nowTime = System.currentTimeMillis(); |
| 2497 | if (mFpsStartTime < 0) { |
| 2498 | mFpsStartTime = mFpsPrevTime = nowTime; |
| 2499 | mFpsNumFrames = 0; |
| 2500 | } else { |
| 2501 | ++mFpsNumFrames; |
| 2502 | String thisHash = Integer.toHexString(System.identityHashCode(this)); |
| 2503 | long frameTime = nowTime - mFpsPrevTime; |
| 2504 | long totalTime = nowTime - mFpsStartTime; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2505 | Log.v(mTag, "0x" + thisHash + "\tFrame time:\t" + frameTime); |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2506 | mFpsPrevTime = nowTime; |
| 2507 | if (totalTime > 1000) { |
| 2508 | float fps = (float) mFpsNumFrames * 1000 / totalTime; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2509 | Log.v(mTag, "0x" + thisHash + "\tFPS:\t" + fps); |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2510 | mFpsStartTime = nowTime; |
| 2511 | mFpsNumFrames = 0; |
| 2512 | } |
| 2513 | } |
| 2514 | } |
| 2515 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2516 | private void performDraw() { |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 2517 | if (mAttachInfo.mDisplayState == Display.STATE_OFF && !mReportNextDraw) { |
Craig Mautner | 006f0e4 | 2012-03-21 11:00:32 -0700 | [diff] [blame] | 2518 | return; |
| 2519 | } |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 2520 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2521 | final boolean fullRedrawNeeded = mFullRedrawNeeded; |
| 2522 | mFullRedrawNeeded = false; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2523 | |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 2524 | mIsDrawing = true; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2525 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "draw"); |
| 2526 | try { |
| 2527 | draw(fullRedrawNeeded); |
| 2528 | } finally { |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 2529 | mIsDrawing = false; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2530 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2531 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2532 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 2533 | // For whatever reason we didn't create a HardwareRenderer, end any |
| 2534 | // hardware animations that are now dangling |
| 2535 | if (mAttachInfo.mPendingAnimatingRenderNodes != null) { |
| 2536 | final int count = mAttachInfo.mPendingAnimatingRenderNodes.size(); |
| 2537 | for (int i = 0; i < count; i++) { |
| 2538 | mAttachInfo.mPendingAnimatingRenderNodes.get(i).endAllAnimators(); |
| 2539 | } |
| 2540 | mAttachInfo.mPendingAnimatingRenderNodes.clear(); |
| 2541 | } |
| 2542 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2543 | if (mReportNextDraw) { |
| 2544 | mReportNextDraw = false; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2545 | |
| 2546 | // if we're using multi-thread renderer, wait for the window frame draws |
| 2547 | if (mWindowDrawCountDown != null) { |
| 2548 | try { |
| 2549 | mWindowDrawCountDown.await(); |
| 2550 | } catch (InterruptedException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2551 | Log.e(mTag, "Window redraw count down interruped!"); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2552 | } |
| 2553 | mWindowDrawCountDown = null; |
| 2554 | } |
| 2555 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 2556 | if (mAttachInfo.mHardwareRenderer != null) { |
| 2557 | mAttachInfo.mHardwareRenderer.fence(); |
| 2558 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2559 | |
| 2560 | if (LOCAL_LOGV) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2561 | Log.v(mTag, "FINISHED DRAWING: " + mWindowAttributes.getTitle()); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2562 | } |
| 2563 | if (mSurfaceHolder != null && mSurface.isValid()) { |
| 2564 | mSurfaceHolderCallback.surfaceRedrawNeeded(mSurfaceHolder); |
| 2565 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 2566 | if (callbacks != null) { |
| 2567 | for (SurfaceHolder.Callback c : callbacks) { |
| 2568 | if (c instanceof SurfaceHolder.Callback2) { |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 2569 | ((SurfaceHolder.Callback2)c).surfaceRedrawNeeded(mSurfaceHolder); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2570 | } |
| 2571 | } |
| 2572 | } |
| 2573 | } |
| 2574 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2575 | mWindowSession.finishDrawing(mWindow); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2576 | } catch (RemoteException e) { |
| 2577 | } |
| 2578 | } |
| 2579 | } |
| 2580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2581 | private void draw(boolean fullRedrawNeeded) { |
| 2582 | Surface surface = mSurface; |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 2583 | if (!surface.isValid()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2584 | return; |
| 2585 | } |
| 2586 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2587 | if (DEBUG_FPS) { |
| 2588 | trackFPS(); |
| 2589 | } |
| 2590 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2591 | if (!sFirstDrawComplete) { |
| 2592 | synchronized (sFirstDrawHandlers) { |
| 2593 | sFirstDrawComplete = true; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 2594 | final int count = sFirstDrawHandlers.size(); |
| 2595 | for (int i = 0; i< count; i++) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 2596 | mHandler.post(sFirstDrawHandlers.get(i)); |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2597 | } |
| 2598 | } |
| 2599 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2600 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2601 | scrollToRectOrFocus(null, false); |
| 2602 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2603 | if (mAttachInfo.mViewScrollChanged) { |
| 2604 | mAttachInfo.mViewScrollChanged = false; |
| 2605 | mAttachInfo.mTreeObserver.dispatchOnScrollChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2606 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2607 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2608 | boolean animating = mScroller != null && mScroller.computeScrollOffset(); |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2609 | final int curScrollY; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2610 | if (animating) { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2611 | curScrollY = mScroller.getCurrY(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2612 | } else { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2613 | curScrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2614 | } |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2615 | if (mCurScrollY != curScrollY) { |
| 2616 | mCurScrollY = curScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | fullRedrawNeeded = true; |
Adrian Roos | 0e7ae4e | 2014-10-01 15:33:22 +0200 | [diff] [blame] | 2618 | if (mView instanceof RootViewSurfaceTaker) { |
| 2619 | ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY); |
| 2620 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2621 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2622 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2623 | final float appScale = mAttachInfo.mApplicationScale; |
| 2624 | final boolean scalingRequired = mAttachInfo.mScalingRequired; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2625 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2626 | int resizeAlpha = 0; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2627 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2628 | final Rect dirty = mDirty; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2629 | if (mSurfaceHolder != null) { |
| 2630 | // The app owns the surface, we won't draw. |
| 2631 | dirty.setEmpty(); |
Derek Sollenberger | 8d94835 | 2015-07-16 09:27:59 -0400 | [diff] [blame] | 2632 | if (animating && mScroller != null) { |
| 2633 | mScroller.abortAnimation(); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2634 | } |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2635 | return; |
| 2636 | } |
Romain Guy | 58ef7fb | 2010-09-13 12:52:37 -0700 | [diff] [blame] | 2637 | |
| 2638 | if (fullRedrawNeeded) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2639 | mAttachInfo.mIgnoreDirtyState = true; |
Romain Guy | c3166e1 | 2011-08-08 15:00:03 -0700 | [diff] [blame] | 2640 | dirty.set(0, 0, (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f)); |
Romain Guy | 58ef7fb | 2010-09-13 12:52:37 -0700 | [diff] [blame] | 2641 | } |
Chet Haase | ad4f703 | 2011-06-22 09:18:31 -0700 | [diff] [blame] | 2642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2643 | if (DEBUG_ORIENTATION || DEBUG_DRAW) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2644 | Log.v(mTag, "Draw " + mView + "/" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2645 | + mWindowAttributes.getTitle() |
| 2646 | + ": dirty={" + dirty.left + "," + dirty.top |
| 2647 | + "," + dirty.right + "," + dirty.bottom + "} surface=" |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 2648 | + surface + " surface.isValid()=" + surface.isValid() + ", appScale:" + |
| 2649 | appScale + ", width=" + mWidth + ", height=" + mHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2650 | } |
| 2651 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2652 | mAttachInfo.mTreeObserver.dispatchOnDraw(); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2653 | |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2654 | int xOffset = -mCanvasOffsetX; |
| 2655 | int yOffset = -mCanvasOffsetY + curScrollY; |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2656 | final WindowManager.LayoutParams params = mWindowAttributes; |
| 2657 | final Rect surfaceInsets = params != null ? params.surfaceInsets : null; |
| 2658 | if (surfaceInsets != null) { |
| 2659 | xOffset -= surfaceInsets.left; |
| 2660 | yOffset -= surfaceInsets.top; |
| 2661 | |
| 2662 | // Offset dirty rect for surface insets. |
| 2663 | dirty.offset(surfaceInsets.left, surfaceInsets.right); |
| 2664 | } |
| 2665 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2666 | boolean accessibilityFocusDirty = false; |
| 2667 | final Drawable drawable = mAttachInfo.mAccessibilityFocusDrawable; |
| 2668 | if (drawable != null) { |
| 2669 | final Rect bounds = mAttachInfo.mTmpInvalRect; |
| 2670 | final boolean hasFocus = getAccessibilityFocusedRect(bounds); |
| 2671 | if (!hasFocus) { |
| 2672 | bounds.setEmpty(); |
| 2673 | } |
| 2674 | if (!bounds.equals(drawable.getBounds())) { |
| 2675 | accessibilityFocusDirty = true; |
| 2676 | } |
| 2677 | } |
| 2678 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 2679 | mAttachInfo.mDrawingTime = |
| 2680 | mChoreographer.getFrameTimeNanos() / TimeUtils.NANOS_PER_MS; |
| 2681 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2682 | if (!dirty.isEmpty() || mIsAnimating || accessibilityFocusDirty) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2683 | if (mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled()) { |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2684 | // If accessibility focus moved, always invalidate the root. |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 2685 | boolean invalidateRoot = accessibilityFocusDirty || mInvalidateRootRequested; |
| 2686 | mInvalidateRootRequested = false; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2687 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2688 | // Draw with hardware renderer. |
| 2689 | mIsAnimating = false; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2690 | |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 2691 | if (mHardwareYOffset != yOffset || mHardwareXOffset != xOffset) { |
| 2692 | mHardwareYOffset = yOffset; |
| 2693 | mHardwareXOffset = xOffset; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2694 | invalidateRoot = true; |
Alan Viverette | f6cf1a0 | 2014-08-11 14:13:02 -0700 | [diff] [blame] | 2695 | } |
| 2696 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2697 | if (invalidateRoot) { |
| 2698 | mAttachInfo.mHardwareRenderer.invalidateRoot(); |
| 2699 | } |
| 2700 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2701 | dirty.setEmpty(); |
| 2702 | |
Skuhne | 980ee47 | 2015-10-06 11:31:31 -0700 | [diff] [blame] | 2703 | // Stage the content drawn size now. It will be transferred to the renderer |
| 2704 | // shortly before the draw commands get send to the renderer. |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2705 | final boolean updated = updateContentDrawBounds(); |
| 2706 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2707 | mAttachInfo.mHardwareRenderer.draw(mView, mAttachInfo, this); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2708 | |
| 2709 | if (updated) { |
| 2710 | requestDrawWindow(); |
| 2711 | } |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2712 | } else { |
| 2713 | // If we get here with a disabled & requested hardware renderer, something went |
| 2714 | // wrong (an invalidate posted right before we destroyed the hardware surface |
| 2715 | // for instance) so we should just bail out. Locking the surface with software |
| 2716 | // rendering at this point would lock it forever and prevent hardware renderer |
| 2717 | // from doing its job when it comes back. |
| 2718 | // Before we request a new frame we must however attempt to reinitiliaze the |
| 2719 | // hardware renderer if it's in requested state. This would happen after an |
| 2720 | // eglTerminate() for instance. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2721 | if (mAttachInfo.mHardwareRenderer != null && |
| 2722 | !mAttachInfo.mHardwareRenderer.isEnabled() && |
| 2723 | mAttachInfo.mHardwareRenderer.isRequested()) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2724 | |
| 2725 | try { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2726 | mAttachInfo.mHardwareRenderer.initializeIfNeeded( |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 2727 | mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2728 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2729 | handleOutOfResourcesException(e); |
| 2730 | return; |
| 2731 | } |
| 2732 | |
| 2733 | mFullRedrawNeeded = true; |
| 2734 | scheduleTraversals(); |
| 2735 | return; |
| 2736 | } |
| 2737 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2738 | if (!drawSoftware(surface, mAttachInfo, xOffset, yOffset, scalingRequired, dirty)) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2739 | return; |
| 2740 | } |
Jeff Brown | 95db2b2 | 2011-11-30 19:54:41 -0800 | [diff] [blame] | 2741 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2742 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2743 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2744 | if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2745 | mFullRedrawNeeded = true; |
| 2746 | scheduleTraversals(); |
| 2747 | } |
| 2748 | } |
| 2749 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2750 | /** |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2751 | * @return true if drawing was successful, false if an error occurred |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2752 | */ |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2753 | private boolean drawSoftware(Surface surface, AttachInfo attachInfo, int xoff, int yoff, |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2754 | boolean scalingRequired, Rect dirty) { |
| 2755 | |
| 2756 | // Draw with software renderer. |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2757 | final Canvas canvas; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2758 | try { |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2759 | final int left = dirty.left; |
| 2760 | final int top = dirty.top; |
| 2761 | final int right = dirty.right; |
| 2762 | final int bottom = dirty.bottom; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2763 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2764 | canvas = mSurface.lockCanvas(dirty); |
| 2765 | |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 2766 | // The dirty rectangle can be modified by Surface.lockCanvas() |
| 2767 | //noinspection ConstantConditions |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2768 | if (left != dirty.left || top != dirty.top || right != dirty.right |
| 2769 | || bottom != dirty.bottom) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2770 | attachInfo.mIgnoreDirtyState = true; |
| 2771 | } |
| 2772 | |
| 2773 | // TODO: Do this in native |
| 2774 | canvas.setDensity(mDensity); |
| 2775 | } catch (Surface.OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2776 | handleOutOfResourcesException(e); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2777 | return false; |
| 2778 | } catch (IllegalArgumentException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2779 | Log.e(mTag, "Could not lock surface", e); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2780 | // Don't assume this is due to out of memory, it could be |
| 2781 | // something else, and if it is something else then we could |
| 2782 | // kill stuff (or ourself) for no reason. |
| 2783 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2784 | return false; |
| 2785 | } |
| 2786 | |
| 2787 | try { |
| 2788 | if (DEBUG_ORIENTATION || DEBUG_DRAW) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2789 | Log.v(mTag, "Surface " + surface + " drawing to bitmap w=" |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2790 | + canvas.getWidth() + ", h=" + canvas.getHeight()); |
| 2791 | //canvas.drawARGB(255, 255, 0, 0); |
| 2792 | } |
| 2793 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2794 | // If this bitmap's format includes an alpha channel, we |
| 2795 | // need to clear it before drawing so that the child will |
| 2796 | // properly re-composite its drawing on a transparent |
| 2797 | // background. This automatically respects the clip/dirty region |
| 2798 | // or |
| 2799 | // If we are applying an offset, we need to clear the area |
| 2800 | // where the offset doesn't appear to avoid having garbage |
| 2801 | // left in the blank areas. |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2802 | if (!canvas.isOpaque() || yoff != 0 || xoff != 0) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2803 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 2804 | } |
| 2805 | |
| 2806 | dirty.setEmpty(); |
| 2807 | mIsAnimating = false; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2808 | mView.mPrivateFlags |= View.PFLAG_DRAWN; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2809 | |
| 2810 | if (DEBUG_DRAW) { |
| 2811 | Context cxt = mView.getContext(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2812 | Log.i(mTag, "Drawing: package:" + cxt.getPackageName() + |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2813 | ", metrics=" + cxt.getResources().getDisplayMetrics() + |
| 2814 | ", compatibilityInfo=" + cxt.getResources().getCompatibilityInfo()); |
| 2815 | } |
| 2816 | try { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2817 | canvas.translate(-xoff, -yoff); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2818 | if (mTranslator != null) { |
| 2819 | mTranslator.translateCanvas(canvas); |
| 2820 | } |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 2821 | canvas.setScreenDensity(scalingRequired ? mNoncompatDensity : 0); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2822 | attachInfo.mSetIgnoreDirtyState = false; |
| 2823 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2824 | mView.draw(canvas); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2825 | |
| 2826 | drawAccessibilityFocusedDrawableIfNeeded(canvas); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2827 | } finally { |
| 2828 | if (!attachInfo.mSetIgnoreDirtyState) { |
| 2829 | // Only clear the flag if it was not set during the mView.draw() call |
| 2830 | attachInfo.mIgnoreDirtyState = false; |
| 2831 | } |
| 2832 | } |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2833 | } finally { |
Romain Guy | dddcd22 | 2012-05-18 15:33:57 -0700 | [diff] [blame] | 2834 | try { |
| 2835 | surface.unlockCanvasAndPost(canvas); |
| 2836 | } catch (IllegalArgumentException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2837 | Log.e(mTag, "Could not unlock surface", e); |
Romain Guy | dddcd22 | 2012-05-18 15:33:57 -0700 | [diff] [blame] | 2838 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2839 | //noinspection ReturnInsideFinallyBlock |
| 2840 | return false; |
| 2841 | } |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2842 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2843 | if (LOCAL_LOGV) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2844 | Log.v(mTag, "Surface " + surface + " unlockCanvasAndPost"); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2845 | } |
| 2846 | } |
| 2847 | return true; |
| 2848 | } |
| 2849 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2850 | /** |
| 2851 | * We want to draw a highlight around the current accessibility focused. |
| 2852 | * Since adding a style for all possible view is not a viable option we |
| 2853 | * have this specialized drawing method. |
| 2854 | * |
| 2855 | * Note: We are doing this here to be able to draw the highlight for |
| 2856 | * virtual views in addition to real ones. |
| 2857 | * |
| 2858 | * @param canvas The canvas on which to draw. |
| 2859 | */ |
| 2860 | private void drawAccessibilityFocusedDrawableIfNeeded(Canvas canvas) { |
| 2861 | final Rect bounds = mAttachInfo.mTmpInvalRect; |
| 2862 | if (getAccessibilityFocusedRect(bounds)) { |
| 2863 | final Drawable drawable = getAccessibilityFocusedDrawable(); |
| 2864 | if (drawable != null) { |
| 2865 | drawable.setBounds(bounds); |
| 2866 | drawable.draw(canvas); |
| 2867 | } |
| 2868 | } else if (mAttachInfo.mAccessibilityFocusDrawable != null) { |
| 2869 | mAttachInfo.mAccessibilityFocusDrawable.setBounds(0, 0, 0, 0); |
| 2870 | } |
| 2871 | } |
| 2872 | |
| 2873 | private boolean getAccessibilityFocusedRect(Rect bounds) { |
| 2874 | final AccessibilityManager manager = AccessibilityManager.getInstance(mView.mContext); |
| 2875 | if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) { |
| 2876 | return false; |
| 2877 | } |
| 2878 | |
| 2879 | final View host = mAccessibilityFocusedHost; |
| 2880 | if (host == null || host.mAttachInfo == null) { |
| 2881 | return false; |
| 2882 | } |
| 2883 | |
| 2884 | final AccessibilityNodeProvider provider = host.getAccessibilityNodeProvider(); |
| 2885 | if (provider == null) { |
Svetoslav | ded133c | 2015-01-30 20:28:41 -0800 | [diff] [blame] | 2886 | host.getBoundsOnScreen(bounds, true); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2887 | } else if (mAccessibilityFocusedVirtualView != null) { |
| 2888 | mAccessibilityFocusedVirtualView.getBoundsInScreen(bounds); |
| 2889 | } else { |
| 2890 | return false; |
| 2891 | } |
| 2892 | |
Alan Viverette | 2232add | 2015-05-26 15:24:18 -0700 | [diff] [blame] | 2893 | // Transform the rect into window-relative coordinates. |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2894 | final AttachInfo attachInfo = mAttachInfo; |
Alan Viverette | 2232add | 2015-05-26 15:24:18 -0700 | [diff] [blame] | 2895 | bounds.offset(0, attachInfo.mViewRootImpl.mScrollY); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2896 | bounds.offset(-attachInfo.mWindowLeft, -attachInfo.mWindowTop); |
Doris Liu | 9607fbe | 2015-05-28 17:17:28 -0700 | [diff] [blame] | 2897 | if (!bounds.intersect(0, 0, attachInfo.mViewRootImpl.mWidth, |
| 2898 | attachInfo.mViewRootImpl.mHeight)) { |
| 2899 | // If no intersection, set bounds to empty. |
| 2900 | bounds.setEmpty(); |
| 2901 | } |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2902 | return !bounds.isEmpty(); |
| 2903 | } |
| 2904 | |
| 2905 | private Drawable getAccessibilityFocusedDrawable() { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2906 | // Lazily load the accessibility focus drawable. |
| 2907 | if (mAttachInfo.mAccessibilityFocusDrawable == null) { |
Alan Viverette | f6cf1a0 | 2014-08-11 14:13:02 -0700 | [diff] [blame] | 2908 | final TypedValue value = new TypedValue(); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2909 | final boolean resolved = mView.mContext.getTheme().resolveAttribute( |
| 2910 | R.attr.accessibilityFocusedDrawable, value, true); |
| 2911 | if (resolved) { |
| 2912 | mAttachInfo.mAccessibilityFocusDrawable = |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 2913 | mView.mContext.getDrawable(value.resourceId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2914 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2915 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2916 | return mAttachInfo.mAccessibilityFocusDrawable; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 2919 | /** |
| 2920 | * Requests that the root render node is invalidated next time we perform a draw, such that |
| 2921 | * {@link WindowCallbacks#onPostDraw} gets called. |
| 2922 | */ |
| 2923 | public void requestInvalidateRootRenderNode() { |
| 2924 | mInvalidateRootRequested = true; |
| 2925 | } |
| 2926 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2927 | boolean scrollToRectOrFocus(Rect rectangle, boolean immediate) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2928 | final Rect ci = mAttachInfo.mContentInsets; |
| 2929 | final Rect vi = mAttachInfo.mVisibleInsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2930 | int scrollY = 0; |
| 2931 | boolean handled = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2932 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2933 | if (vi.left > ci.left || vi.top > ci.top |
| 2934 | || vi.right > ci.right || vi.bottom > ci.bottom) { |
| 2935 | // We'll assume that we aren't going to change the scroll |
| 2936 | // offset, since we want to avoid that unless it is actually |
| 2937 | // going to make the focus visible... otherwise we scroll |
| 2938 | // all over the place. |
| 2939 | scrollY = mScrollY; |
| 2940 | // We can be called for two different situations: during a draw, |
| 2941 | // to update the scroll position if the focus has changed (in which |
| 2942 | // case 'rectangle' is null), or in response to a |
| 2943 | // requestChildRectangleOnScreen() call (in which case 'rectangle' |
| 2944 | // is non-null and we just want to scroll to whatever that |
| 2945 | // rectangle is). |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 2946 | final View focus = mView.findFocus(); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2947 | if (focus == null) { |
Romain Guy | e8b1652 | 2009-07-14 13:06:42 -0700 | [diff] [blame] | 2948 | return false; |
| 2949 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2950 | View lastScrolledFocus = (mLastScrolledFocus != null) ? mLastScrolledFocus.get() : null; |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 2951 | if (focus != lastScrolledFocus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2952 | // If the focus has changed, then ignore any requests to scroll |
| 2953 | // to a rectangle; first we want to make sure the entire focus |
| 2954 | // view is visible. |
| 2955 | rectangle = null; |
| 2956 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2957 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Eval scroll: focus=" + focus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2958 | + " rectangle=" + rectangle + " ci=" + ci |
| 2959 | + " vi=" + vi); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2960 | if (focus == lastScrolledFocus && !mScrollMayChange && rectangle == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2961 | // Optimization: if the focus hasn't changed since last |
| 2962 | // time, and no layout has happened, then just leave things |
| 2963 | // as they are. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2964 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Keeping scroll y=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | + mScrollY + " vi=" + vi.toShortString()); |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 2966 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2967 | // We need to determine if the currently focused view is |
| 2968 | // within the visible part of the window and, if not, apply |
| 2969 | // a pan so it can be seen. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2970 | mLastScrolledFocus = new WeakReference<View>(focus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | mScrollMayChange = false; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2972 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Need to scroll?"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2973 | // Try to find the rectangle from the focus view. |
| 2974 | if (focus.getGlobalVisibleRect(mVisRect, null)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2975 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Root w=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2976 | + mView.getWidth() + " h=" + mView.getHeight() |
| 2977 | + " ci=" + ci.toShortString() |
| 2978 | + " vi=" + vi.toShortString()); |
| 2979 | if (rectangle == null) { |
| 2980 | focus.getFocusedRect(mTempRect); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2981 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Focus " + focus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2982 | + ": focusRect=" + mTempRect.toShortString()); |
Dianne Hackborn | 1c6a894 | 2010-03-23 16:34:20 -0700 | [diff] [blame] | 2983 | if (mView instanceof ViewGroup) { |
| 2984 | ((ViewGroup) mView).offsetDescendantRectToMyCoords( |
| 2985 | focus, mTempRect); |
| 2986 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2987 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2988 | "Focus in window: focusRect=" |
| 2989 | + mTempRect.toShortString() |
| 2990 | + " visRect=" + mVisRect.toShortString()); |
| 2991 | } else { |
| 2992 | mTempRect.set(rectangle); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2993 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2994 | "Request scroll to rect: " |
| 2995 | + mTempRect.toShortString() |
| 2996 | + " visRect=" + mVisRect.toShortString()); |
| 2997 | } |
| 2998 | if (mTempRect.intersect(mVisRect)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2999 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3000 | "Focus window visible rect: " |
| 3001 | + mTempRect.toShortString()); |
| 3002 | if (mTempRect.height() > |
| 3003 | (mView.getHeight()-vi.top-vi.bottom)) { |
| 3004 | // If the focus simply is not going to fit, then |
| 3005 | // best is probably just to leave things as-is. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3006 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3007 | "Too tall; leaving scrollY=" + scrollY); |
| 3008 | } else if ((mTempRect.top-scrollY) < vi.top) { |
| 3009 | scrollY -= vi.top - (mTempRect.top-scrollY); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3010 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3011 | "Top covered; scrollY=" + scrollY); |
| 3012 | } else if ((mTempRect.bottom-scrollY) |
| 3013 | > (mView.getHeight()-vi.bottom)) { |
| 3014 | scrollY += (mTempRect.bottom-scrollY) |
| 3015 | - (mView.getHeight()-vi.bottom); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3016 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3017 | "Bottom covered; scrollY=" + scrollY); |
| 3018 | } |
| 3019 | handled = true; |
| 3020 | } |
| 3021 | } |
| 3022 | } |
| 3023 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3024 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3025 | if (scrollY != mScrollY) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3026 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Pan scroll changed: old=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3027 | + mScrollY + " , new=" + scrollY); |
Derek Sollenberger | 8d94835 | 2015-07-16 09:27:59 -0400 | [diff] [blame] | 3028 | if (!immediate) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3029 | if (mScroller == null) { |
| 3030 | mScroller = new Scroller(mView.getContext()); |
| 3031 | } |
| 3032 | mScroller.startScroll(0, mScrollY, 0, scrollY-mScrollY); |
| 3033 | } else if (mScroller != null) { |
| 3034 | mScroller.abortAnimation(); |
| 3035 | } |
| 3036 | mScrollY = scrollY; |
| 3037 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3038 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3039 | return handled; |
| 3040 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3041 | |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3042 | /** |
| 3043 | * @hide |
| 3044 | */ |
| 3045 | public View getAccessibilityFocusedHost() { |
| 3046 | return mAccessibilityFocusedHost; |
| 3047 | } |
| 3048 | |
| 3049 | /** |
| 3050 | * @hide |
| 3051 | */ |
| 3052 | public AccessibilityNodeInfo getAccessibilityFocusedVirtualView() { |
| 3053 | return mAccessibilityFocusedVirtualView; |
| 3054 | } |
| 3055 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3056 | void setAccessibilityFocus(View view, AccessibilityNodeInfo node) { |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3057 | // If we have a virtual view with accessibility focus we need |
| 3058 | // to clear the focus and invalidate the virtual view bounds. |
| 3059 | if (mAccessibilityFocusedVirtualView != null) { |
| 3060 | |
| 3061 | AccessibilityNodeInfo focusNode = mAccessibilityFocusedVirtualView; |
| 3062 | View focusHost = mAccessibilityFocusedHost; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3063 | |
| 3064 | // Wipe the state of the current accessibility focus since |
| 3065 | // the call into the provider to clear accessibility focus |
| 3066 | // will fire an accessibility event which will end up calling |
| 3067 | // this method and we want to have clean state when this |
| 3068 | // invocation happens. |
| 3069 | mAccessibilityFocusedHost = null; |
| 3070 | mAccessibilityFocusedVirtualView = null; |
| 3071 | |
Alan Viverette | 239a0c0 | 2013-05-07 17:17:35 -0700 | [diff] [blame] | 3072 | // Clear accessibility focus on the host after clearing state since |
| 3073 | // this method may be reentrant. |
| 3074 | focusHost.clearAccessibilityFocusNoCallbacks(); |
| 3075 | |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3076 | AccessibilityNodeProvider provider = focusHost.getAccessibilityNodeProvider(); |
| 3077 | if (provider != null) { |
| 3078 | // Invalidate the area of the cleared accessibility focus. |
| 3079 | focusNode.getBoundsInParent(mTempRect); |
| 3080 | focusHost.invalidate(mTempRect); |
| 3081 | // Clear accessibility focus in the virtual node. |
| 3082 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 3083 | focusNode.getSourceNodeId()); |
| 3084 | provider.performAction(virtualNodeId, |
| 3085 | AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null); |
| 3086 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3087 | focusNode.recycle(); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3088 | } |
| 3089 | if (mAccessibilityFocusedHost != null) { |
| 3090 | // Clear accessibility focus in the view. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3091 | mAccessibilityFocusedHost.clearAccessibilityFocusNoCallbacks(); |
| 3092 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3093 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3094 | // Set the new focus host and node. |
| 3095 | mAccessibilityFocusedHost = view; |
| 3096 | mAccessibilityFocusedVirtualView = node; |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 3097 | |
| 3098 | if (mAttachInfo.mHardwareRenderer != null) { |
| 3099 | mAttachInfo.mHardwareRenderer.invalidateRoot(); |
| 3100 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3101 | } |
| 3102 | |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3103 | void setPointerCapture(View view) { |
| 3104 | if (!mAttachInfo.mHasWindowFocus) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3105 | Log.w(mTag, "Can't set capture if it's not focused."); |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3106 | return; |
| 3107 | } |
| 3108 | if (mCapturingView == view) { |
| 3109 | return; |
| 3110 | } |
| 3111 | mCapturingView = view; |
| 3112 | InputManager.getInstance().setPointerIconDetached(true); |
| 3113 | } |
| 3114 | |
| 3115 | void releasePointerCapture(View view) { |
| 3116 | if (mCapturingView != view || mCapturingView == null) { |
| 3117 | return; |
| 3118 | } |
| 3119 | |
| 3120 | mCapturingView = null; |
| 3121 | InputManager.getInstance().setPointerIconDetached(false); |
| 3122 | } |
| 3123 | |
| 3124 | boolean hasPointerCapture(View view) { |
| 3125 | return view != null && mCapturingView == view; |
| 3126 | } |
| 3127 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3128 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3129 | public void requestChildFocus(View child, View focused) { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3130 | if (DEBUG_INPUT_RESIZE) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3131 | Log.v(mTag, "Request child focus: focus now " + focused); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3132 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3133 | checkThread(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3134 | scheduleTraversals(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3135 | } |
| 3136 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3137 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3138 | public void clearChildFocus(View child) { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3139 | if (DEBUG_INPUT_RESIZE) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3140 | Log.v(mTag, "Clearing child focus"); |
Amith Yamasani | 73eb97f | 2012-02-14 15:45:15 -0800 | [diff] [blame] | 3141 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3142 | checkThread(); |
| 3143 | scheduleTraversals(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3144 | } |
Amith Yamasani | 73eb97f | 2012-02-14 15:45:15 -0800 | [diff] [blame] | 3145 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3146 | @Override |
| 3147 | public ViewParent getParentForAccessibility() { |
| 3148 | return null; |
| 3149 | } |
| 3150 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3151 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3152 | public void focusableViewAvailable(View v) { |
| 3153 | checkThread(); |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3154 | if (mView != null) { |
| 3155 | if (!mView.hasFocus()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3156 | v.requestFocus(); |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3157 | } else { |
| 3158 | // the one case where will transfer focus away from the current one |
| 3159 | // is if the current view is a view group that prefers to give focus |
| 3160 | // to its children first AND the view is a descendant of it. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3161 | View focused = mView.findFocus(); |
| 3162 | if (focused instanceof ViewGroup) { |
| 3163 | ViewGroup group = (ViewGroup) focused; |
| 3164 | if (group.getDescendantFocusability() == ViewGroup.FOCUS_AFTER_DESCENDANTS |
| 3165 | && isViewDescendantOf(v, focused)) { |
| 3166 | v.requestFocus(); |
| 3167 | } |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3168 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3169 | } |
| 3170 | } |
| 3171 | } |
| 3172 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3173 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3174 | public void recomputeViewAttributes(View child) { |
| 3175 | checkThread(); |
| 3176 | if (mView == child) { |
| 3177 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 3178 | if (!mWillDrawSoon) { |
| 3179 | scheduleTraversals(); |
| 3180 | } |
| 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | void dispatchDetachedFromWindow() { |
Romain Guy | 90fc03b | 2011-01-16 13:07:15 -0800 | [diff] [blame] | 3185 | if (mView != null && mView.mAttachInfo != null) { |
Dianne Hackborn | 961cae9 | 2013-03-20 14:59:43 -0700 | [diff] [blame] | 3186 | mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3187 | mView.dispatchDetachedFromWindow(); |
| 3188 | } |
| 3189 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3190 | mAccessibilityInteractionConnectionManager.ensureNoConnection(); |
| 3191 | mAccessibilityManager.removeAccessibilityStateChangeListener( |
| 3192 | mAccessibilityInteractionConnectionManager); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 3193 | mAccessibilityManager.removeHighTextContrastStateChangeListener( |
| 3194 | mHighContrastTextManager); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 3195 | removeSendWindowContentChangedCallback(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3196 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3197 | destroyHardwareRenderer(); |
| 3198 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3199 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3200 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 3201 | mView.assignParent(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3202 | mView = null; |
| 3203 | mAttachInfo.mRootView = null; |
| 3204 | |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3205 | if (mCapturingView != null) { |
| 3206 | releasePointerCapture(mCapturingView); |
| 3207 | } |
| 3208 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 3209 | mSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3210 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3211 | if (mInputQueueCallback != null && mInputQueue != null) { |
| 3212 | mInputQueueCallback.onInputQueueDestroyed(mInputQueue); |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3213 | mInputQueue.dispose(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3214 | mInputQueueCallback = null; |
| 3215 | mInputQueue = null; |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3216 | } |
| 3217 | if (mInputEventReceiver != null) { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3218 | mInputEventReceiver.dispose(); |
| 3219 | mInputEventReceiver = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3220 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3221 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3222 | mWindowSession.remove(mWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3223 | } catch (RemoteException e) { |
| 3224 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3225 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3226 | // Dispose the input channel after removing the window so the Window Manager |
| 3227 | // doesn't interpret the input channel being closed as an abnormal termination. |
| 3228 | if (mInputChannel != null) { |
| 3229 | mInputChannel.dispose(); |
| 3230 | mInputChannel = null; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3231 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3232 | |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 3233 | mDisplayManager.unregisterDisplayListener(mDisplayListener); |
| 3234 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 3235 | unscheduleTraversals(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3237 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3238 | void updateConfiguration(Configuration config, boolean force) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3239 | if (DEBUG_CONFIGURATION) Log.v(mTag, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3240 | "Applying new config to window " |
| 3241 | + mWindowAttributes.getTitle() |
| 3242 | + ": " + config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3243 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 3244 | CompatibilityInfo ci = mDisplayAdjustments.getCompatibilityInfo(); |
| 3245 | if (!ci.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3246 | config = new Configuration(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3247 | ci.applyToConfiguration(mNoncompatDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3248 | } |
| 3249 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3250 | synchronized (sConfigCallbacks) { |
| 3251 | for (int i=sConfigCallbacks.size()-1; i>=0; i--) { |
| 3252 | sConfigCallbacks.get(i).onConfigurationChanged(config); |
| 3253 | } |
| 3254 | } |
| 3255 | if (mView != null) { |
| 3256 | // At this point the resources have been updated to |
| 3257 | // have the most recent config, whatever that is. Use |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3258 | // the one in them which may be newer. |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3259 | config = mView.getResources().getConfiguration(); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3260 | if (force || mLastConfiguration.diff(config) != 0) { |
Fabrice Di Meglio | cf12897 | 2012-10-16 20:51:12 -0700 | [diff] [blame] | 3261 | final int lastLayoutDirection = mLastConfiguration.getLayoutDirection(); |
| 3262 | final int currentLayoutDirection = config.getLayoutDirection(); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3263 | mLastConfiguration.setTo(config); |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 3264 | if (lastLayoutDirection != currentLayoutDirection && |
| 3265 | mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) { |
Fabrice Di Meglio | cf12897 | 2012-10-16 20:51:12 -0700 | [diff] [blame] | 3266 | mView.setLayoutDirection(currentLayoutDirection); |
| 3267 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3268 | mView.dispatchConfigurationChanged(config); |
| 3269 | } |
| 3270 | } |
| 3271 | } |
John Reck | 05e8584 | 2014-04-23 14:48:28 -0700 | [diff] [blame] | 3272 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3273 | /** |
| 3274 | * Return true if child is an ancestor of parent, (or equal to the parent). |
| 3275 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3276 | public static boolean isViewDescendantOf(View child, View parent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3277 | if (child == parent) { |
| 3278 | return true; |
| 3279 | } |
| 3280 | |
| 3281 | final ViewParent theParent = child.getParent(); |
| 3282 | return (theParent instanceof ViewGroup) && isViewDescendantOf((View) theParent, parent); |
| 3283 | } |
| 3284 | |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 3285 | private static void forceLayout(View view) { |
| 3286 | view.forceLayout(); |
| 3287 | if (view instanceof ViewGroup) { |
| 3288 | ViewGroup group = (ViewGroup) view; |
| 3289 | final int count = group.getChildCount(); |
| 3290 | for (int i = 0; i < count; i++) { |
| 3291 | forceLayout(group.getChildAt(i)); |
| 3292 | } |
| 3293 | } |
| 3294 | } |
| 3295 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3296 | private final static int MSG_INVALIDATE = 1; |
| 3297 | private final static int MSG_INVALIDATE_RECT = 2; |
| 3298 | private final static int MSG_DIE = 3; |
| 3299 | private final static int MSG_RESIZED = 4; |
| 3300 | private final static int MSG_RESIZED_REPORT = 5; |
| 3301 | private final static int MSG_WINDOW_FOCUS_CHANGED = 6; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3302 | private final static int MSG_DISPATCH_INPUT_EVENT = 7; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3303 | private final static int MSG_DISPATCH_APP_VISIBILITY = 8; |
| 3304 | private final static int MSG_DISPATCH_GET_NEW_SURFACE = 9; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3305 | private final static int MSG_DISPATCH_KEY_FROM_IME = 11; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3306 | private final static int MSG_CHECK_FOCUS = 13; |
| 3307 | private final static int MSG_CLOSE_SYSTEM_DIALOGS = 14; |
| 3308 | private final static int MSG_DISPATCH_DRAG_EVENT = 15; |
| 3309 | private final static int MSG_DISPATCH_DRAG_LOCATION_EVENT = 16; |
| 3310 | private final static int MSG_DISPATCH_SYSTEM_UI_VISIBILITY = 17; |
| 3311 | private final static int MSG_UPDATE_CONFIGURATION = 18; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3312 | private final static int MSG_PROCESS_INPUT_EVENTS = 19; |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 3313 | private final static int MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST = 21; |
Jorim Jaggi | 827e0fa | 2015-05-07 11:41:41 -0700 | [diff] [blame] | 3314 | private final static int MSG_INVALIDATE_WORLD = 22; |
| 3315 | private final static int MSG_WINDOW_MOVED = 23; |
| 3316 | private final static int MSG_SYNTHESIZE_INPUT_EVENT = 24; |
| 3317 | private final static int MSG_DISPATCH_WINDOW_SHOWN = 25; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 3318 | private final static int MSG_REQUEST_KEYBOARD_SHORTCUTS = 26; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 3319 | private final static int MSG_UPDATE_POINTER_ICON = 27; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3321 | final class ViewRootHandler extends Handler { |
| 3322 | @Override |
| 3323 | public String getMessageName(Message message) { |
| 3324 | switch (message.what) { |
| 3325 | case MSG_INVALIDATE: |
| 3326 | return "MSG_INVALIDATE"; |
| 3327 | case MSG_INVALIDATE_RECT: |
| 3328 | return "MSG_INVALIDATE_RECT"; |
| 3329 | case MSG_DIE: |
| 3330 | return "MSG_DIE"; |
| 3331 | case MSG_RESIZED: |
| 3332 | return "MSG_RESIZED"; |
| 3333 | case MSG_RESIZED_REPORT: |
| 3334 | return "MSG_RESIZED_REPORT"; |
| 3335 | case MSG_WINDOW_FOCUS_CHANGED: |
| 3336 | return "MSG_WINDOW_FOCUS_CHANGED"; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3337 | case MSG_DISPATCH_INPUT_EVENT: |
| 3338 | return "MSG_DISPATCH_INPUT_EVENT"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3339 | case MSG_DISPATCH_APP_VISIBILITY: |
| 3340 | return "MSG_DISPATCH_APP_VISIBILITY"; |
| 3341 | case MSG_DISPATCH_GET_NEW_SURFACE: |
| 3342 | return "MSG_DISPATCH_GET_NEW_SURFACE"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3343 | case MSG_DISPATCH_KEY_FROM_IME: |
| 3344 | return "MSG_DISPATCH_KEY_FROM_IME"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3345 | case MSG_CHECK_FOCUS: |
| 3346 | return "MSG_CHECK_FOCUS"; |
| 3347 | case MSG_CLOSE_SYSTEM_DIALOGS: |
| 3348 | return "MSG_CLOSE_SYSTEM_DIALOGS"; |
| 3349 | case MSG_DISPATCH_DRAG_EVENT: |
| 3350 | return "MSG_DISPATCH_DRAG_EVENT"; |
| 3351 | case MSG_DISPATCH_DRAG_LOCATION_EVENT: |
| 3352 | return "MSG_DISPATCH_DRAG_LOCATION_EVENT"; |
| 3353 | case MSG_DISPATCH_SYSTEM_UI_VISIBILITY: |
| 3354 | return "MSG_DISPATCH_SYSTEM_UI_VISIBILITY"; |
| 3355 | case MSG_UPDATE_CONFIGURATION: |
| 3356 | return "MSG_UPDATE_CONFIGURATION"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3357 | case MSG_PROCESS_INPUT_EVENTS: |
| 3358 | return "MSG_PROCESS_INPUT_EVENTS"; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 3359 | case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST: |
| 3360 | return "MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST"; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 3361 | case MSG_WINDOW_MOVED: |
| 3362 | return "MSG_WINDOW_MOVED"; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 3363 | case MSG_SYNTHESIZE_INPUT_EVENT: |
| 3364 | return "MSG_SYNTHESIZE_INPUT_EVENT"; |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 3365 | case MSG_DISPATCH_WINDOW_SHOWN: |
| 3366 | return "MSG_DISPATCH_WINDOW_SHOWN"; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 3367 | case MSG_UPDATE_POINTER_ICON: |
| 3368 | return "MSG_UPDATE_POINTER_ICON"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3369 | } |
| 3370 | return super.getMessageName(message); |
Romain Guy | f928469 | 2011-07-13 18:46:21 -0700 | [diff] [blame] | 3371 | } |
Romain Guy | f928469 | 2011-07-13 18:46:21 -0700 | [diff] [blame] | 3372 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3373 | @Override |
| 3374 | public void handleMessage(Message msg) { |
| 3375 | switch (msg.what) { |
| 3376 | case MSG_INVALIDATE: |
| 3377 | ((View) msg.obj).invalidate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3378 | break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3379 | case MSG_INVALIDATE_RECT: |
| 3380 | final View.AttachInfo.InvalidateInfo info = (View.AttachInfo.InvalidateInfo) msg.obj; |
| 3381 | info.target.invalidate(info.left, info.top, info.right, info.bottom); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 3382 | info.recycle(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3383 | break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3384 | case MSG_PROCESS_INPUT_EVENTS: |
| 3385 | mProcessInputEventsScheduled = false; |
| 3386 | doProcessInputEvents(); |
| 3387 | break; |
| 3388 | case MSG_DISPATCH_APP_VISIBILITY: |
| 3389 | handleAppVisibility(msg.arg1 != 0); |
| 3390 | break; |
| 3391 | case MSG_DISPATCH_GET_NEW_SURFACE: |
| 3392 | handleGetNewSurface(); |
| 3393 | break; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3394 | case MSG_RESIZED: { |
| 3395 | // Recycled in the fall through... |
| 3396 | SomeArgs args = (SomeArgs) msg.obj; |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 3397 | if (mWinFrame.equals(args.arg1) |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3398 | && mPendingOverscanInsets.equals(args.arg5) |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 3399 | && mPendingContentInsets.equals(args.arg2) |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3400 | && mPendingStableInsets.equals(args.arg6) |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 3401 | && mPendingVisibleInsets.equals(args.arg3) |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3402 | && mPendingOutsets.equals(args.arg7) |
Jorim Jaggi | 0fe356e | 2016-01-05 14:43:25 +0100 | [diff] [blame] | 3403 | && mPendingBackDropFrame.equals(args.arg8) |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 3404 | && args.arg4 == null |
| 3405 | && args.argi1 == 0) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3406 | break; |
Romain Guy | cdb8667 | 2010-03-18 18:54:50 -0700 | [diff] [blame] | 3407 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3408 | } // fall through... |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3409 | case MSG_RESIZED_REPORT: |
| 3410 | if (mAdded) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3411 | SomeArgs args = (SomeArgs) msg.obj; |
| 3412 | |
| 3413 | Configuration config = (Configuration) args.arg4; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3414 | if (config != null) { |
| 3415 | updateConfiguration(config, false); |
| 3416 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3417 | |
| 3418 | mWinFrame.set((Rect) args.arg1); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3419 | mPendingOverscanInsets.set((Rect) args.arg5); |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3420 | mPendingContentInsets.set((Rect) args.arg2); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3421 | mPendingStableInsets.set((Rect) args.arg6); |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3422 | mPendingVisibleInsets.set((Rect) args.arg3); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3423 | mPendingOutsets.set((Rect) args.arg7); |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 3424 | mPendingBackDropFrame.set((Rect) args.arg8); |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 3425 | mForceNextWindowRelayout = args.argi1 != 0; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 3426 | mPendingAlwaysConsumeNavBar = args.argi2 != 0; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3427 | |
| 3428 | args.recycle(); |
| 3429 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3430 | if (msg.what == MSG_RESIZED_REPORT) { |
| 3431 | mReportNextDraw = true; |
| 3432 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 3433 | |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 3434 | if (mView != null) { |
| 3435 | forceLayout(mView); |
| 3436 | } |
| 3437 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3438 | requestLayout(); |
| 3439 | } |
| 3440 | break; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 3441 | case MSG_WINDOW_MOVED: |
| 3442 | if (mAdded) { |
| 3443 | final int w = mWinFrame.width(); |
| 3444 | final int h = mWinFrame.height(); |
| 3445 | final int l = msg.arg1; |
| 3446 | final int t = msg.arg2; |
| 3447 | mWinFrame.left = l; |
| 3448 | mWinFrame.right = l + w; |
| 3449 | mWinFrame.top = t; |
| 3450 | mWinFrame.bottom = t + h; |
| 3451 | |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 3452 | mPendingBackDropFrame.set(mWinFrame); |
| 3453 | |
Jorim Jaggi | 844e171 | 2016-01-13 17:39:25 -0800 | [diff] [blame] | 3454 | // Suppress layouts during resizing - a correct layout will happen when resizing |
| 3455 | // is done, and this just increases system load. |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3456 | boolean isDockedDivider = mWindowAttributes.type == TYPE_DOCK_DIVIDER; |
| 3457 | boolean suppress = (mDragResizing && mResizeMode == RESIZE_MODE_DOCKED_DIVIDER) |
| 3458 | || isDockedDivider; |
Jorim Jaggi | 844e171 | 2016-01-13 17:39:25 -0800 | [diff] [blame] | 3459 | if (!suppress) { |
| 3460 | if (mView != null) { |
| 3461 | forceLayout(mView); |
| 3462 | } |
| 3463 | requestLayout(); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3464 | } else { |
| 3465 | maybeHandleWindowMove(mWinFrame); |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 3466 | } |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 3467 | } |
| 3468 | break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3469 | case MSG_WINDOW_FOCUS_CHANGED: { |
| 3470 | if (mAdded) { |
| 3471 | boolean hasWindowFocus = msg.arg1 != 0; |
| 3472 | mAttachInfo.mHasWindowFocus = hasWindowFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3473 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3474 | profileRendering(hasWindowFocus); |
| 3475 | |
| 3476 | if (hasWindowFocus) { |
| 3477 | boolean inTouchMode = msg.arg2 != 0; |
| 3478 | ensureTouchModeLocally(inTouchMode); |
| 3479 | |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 3480 | if (mAttachInfo.mHardwareRenderer != null && mSurface.isValid()){ |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3481 | mFullRedrawNeeded = true; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3482 | try { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3483 | final WindowManager.LayoutParams lp = mWindowAttributes; |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 3484 | final Rect surfaceInsets = lp != null ? lp.surfaceInsets : null; |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3485 | mAttachInfo.mHardwareRenderer.initializeIfNeeded( |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 3486 | mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3487 | } catch (OutOfResourcesException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3488 | Log.e(mTag, "OutOfResourcesException locking surface", e); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3489 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3490 | if (!mWindowSession.outOfMemory(mWindow)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3491 | Slog.w(mTag, "No processes killed for memory; killing self"); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3492 | Process.killProcess(Process.myPid()); |
| 3493 | } |
| 3494 | } catch (RemoteException ex) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3495 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3496 | // Retry in a bit. |
| 3497 | sendMessageDelayed(obtainMessage(msg.what, msg.arg1, msg.arg2), 500); |
| 3498 | return; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3499 | } |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3500 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3501 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3502 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3503 | mLastWasImTarget = WindowManager.LayoutParams |
| 3504 | .mayUseInputMethod(mWindowAttributes.flags); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3505 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3506 | InputMethodManager imm = InputMethodManager.peekInstance(); |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 3507 | if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) { |
| 3508 | imm.onPreWindowFocus(mView, hasWindowFocus); |
| 3509 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3510 | if (mView != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3511 | mAttachInfo.mKeyDispatchState.reset(); |
| 3512 | mView.dispatchWindowFocusChanged(hasWindowFocus); |
Dianne Hackborn | 961cae9 | 2013-03-20 14:59:43 -0700 | [diff] [blame] | 3513 | mAttachInfo.mTreeObserver.dispatchOnWindowFocusChange(hasWindowFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3514 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3515 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3516 | // Note: must be done after the focus change callbacks, |
| 3517 | // so all of the view state is set up correctly. |
| 3518 | if (hasWindowFocus) { |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3519 | if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) { |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 3520 | imm.onPostWindowFocus(mView, mView.findFocus(), |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3521 | mWindowAttributes.softInputMode, |
| 3522 | !mHasHadWindowFocus, mWindowAttributes.flags); |
| 3523 | } |
| 3524 | // Clear the forward bit. We can just do this directly, since |
| 3525 | // the window manager doesn't care about it. |
| 3526 | mWindowAttributes.softInputMode &= |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3527 | ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3528 | ((WindowManager.LayoutParams)mView.getLayoutParams()) |
| 3529 | .softInputMode &= |
| 3530 | ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION; |
| 3531 | mHasHadWindowFocus = true; |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3532 | } else if (mCapturingView != null) { |
| 3533 | releasePointerCapture(mCapturingView); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3534 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3535 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3536 | } break; |
| 3537 | case MSG_DIE: |
| 3538 | doDie(); |
| 3539 | break; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3540 | case MSG_DISPATCH_INPUT_EVENT: { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 3541 | SomeArgs args = (SomeArgs)msg.obj; |
| 3542 | InputEvent event = (InputEvent)args.arg1; |
| 3543 | InputEventReceiver receiver = (InputEventReceiver)args.arg2; |
| 3544 | enqueueInputEvent(event, receiver, 0, true); |
| 3545 | args.recycle(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3546 | } break; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 3547 | case MSG_SYNTHESIZE_INPUT_EVENT: { |
| 3548 | InputEvent event = (InputEvent)msg.obj; |
| 3549 | enqueueInputEvent(event, null, QueuedInputEvent.FLAG_UNHANDLED, true); |
| 3550 | } break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3551 | case MSG_DISPATCH_KEY_FROM_IME: { |
| 3552 | if (LOCAL_LOGV) Log.v( |
| 3553 | TAG, "Dispatching key " |
| 3554 | + msg.obj + " from IME to " + mView); |
| 3555 | KeyEvent event = (KeyEvent)msg.obj; |
| 3556 | if ((event.getFlags()&KeyEvent.FLAG_FROM_SYSTEM) != 0) { |
| 3557 | // The IME is trying to say this event is from the |
| 3558 | // system! Bad bad bad! |
| 3559 | //noinspection UnusedAssignment |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 3560 | event = KeyEvent.changeFlags(event, event.getFlags() & |
| 3561 | ~KeyEvent.FLAG_FROM_SYSTEM); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3562 | } |
| 3563 | enqueueInputEvent(event, null, QueuedInputEvent.FLAG_DELIVER_POST_IME, true); |
| 3564 | } break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3565 | case MSG_CHECK_FOCUS: { |
| 3566 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 3567 | if (imm != null) { |
| 3568 | imm.checkFocus(); |
| 3569 | } |
| 3570 | } break; |
| 3571 | case MSG_CLOSE_SYSTEM_DIALOGS: { |
| 3572 | if (mView != null) { |
| 3573 | mView.onCloseSystemDialogs((String)msg.obj); |
| 3574 | } |
| 3575 | } break; |
| 3576 | case MSG_DISPATCH_DRAG_EVENT: |
| 3577 | case MSG_DISPATCH_DRAG_LOCATION_EVENT: { |
| 3578 | DragEvent event = (DragEvent)msg.obj; |
| 3579 | event.mLocalState = mLocalDragState; // only present when this app called startDrag() |
| 3580 | handleDragEvent(event); |
| 3581 | } break; |
| 3582 | case MSG_DISPATCH_SYSTEM_UI_VISIBILITY: { |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 3583 | handleDispatchSystemUiVisibilityChanged((SystemUiVisibilityInfo) msg.obj); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3584 | } break; |
| 3585 | case MSG_UPDATE_CONFIGURATION: { |
| 3586 | Configuration config = (Configuration)msg.obj; |
| 3587 | if (config.isOtherSeqNewer(mLastConfiguration)) { |
| 3588 | config = mLastConfiguration; |
| 3589 | } |
| 3590 | updateConfiguration(config, false); |
| 3591 | } break; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 3592 | case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3593 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 3594 | } break; |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 3595 | case MSG_INVALIDATE_WORLD: { |
Romain Guy | f84208f | 2012-09-13 22:50:18 -0700 | [diff] [blame] | 3596 | if (mView != null) { |
| 3597 | invalidateWorld(mView); |
| 3598 | } |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 3599 | } break; |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 3600 | case MSG_DISPATCH_WINDOW_SHOWN: { |
| 3601 | handleDispatchWindowShown(); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 3602 | } break; |
| 3603 | case MSG_REQUEST_KEYBOARD_SHORTCUTS: { |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 3604 | final IResultReceiver receiver = (IResultReceiver) msg.obj; |
| 3605 | final int deviceId = msg.arg1; |
| 3606 | handleRequestKeyboardShortcuts(receiver, deviceId); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 3607 | } break; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 3608 | case MSG_UPDATE_POINTER_ICON: { |
| 3609 | MotionEvent event = (MotionEvent) msg.obj; |
| 3610 | resetPointerIcon(event); |
| 3611 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3612 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3613 | } |
| 3614 | } |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 3615 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3616 | final ViewRootHandler mHandler = new ViewRootHandler(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | /** |
| 3619 | * Something in the current window tells us we need to change the touch mode. For |
| 3620 | * example, we are not in touch mode, and the user touches the screen. |
| 3621 | * |
| 3622 | * If the touch mode has changed, tell the window manager, and handle it locally. |
| 3623 | * |
| 3624 | * @param inTouchMode Whether we want to be in touch mode. |
| 3625 | * @return True if the touch mode changed and focus changed was changed as a result |
| 3626 | */ |
| 3627 | boolean ensureTouchMode(boolean inTouchMode) { |
| 3628 | if (DBG) Log.d("touchmode", "ensureTouchMode(" + inTouchMode + "), current " |
| 3629 | + "touch mode is " + mAttachInfo.mInTouchMode); |
| 3630 | if (mAttachInfo.mInTouchMode == inTouchMode) return false; |
| 3631 | |
| 3632 | // tell the window manager |
| 3633 | try { |
Matt Wu | d6bc96d | 2016-01-14 12:59:24 -0800 | [diff] [blame] | 3634 | mWindowSession.setInTouchMode(inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3635 | } catch (RemoteException e) { |
| 3636 | throw new RuntimeException(e); |
| 3637 | } |
| 3638 | |
| 3639 | // handle the change |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3640 | return ensureTouchModeLocally(inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | /** |
| 3644 | * Ensure that the touch mode for this window is set, and if it is changing, |
| 3645 | * take the appropriate action. |
| 3646 | * @param inTouchMode Whether we want to be in touch mode. |
| 3647 | * @return True if the touch mode changed and focus changed was changed as a result |
| 3648 | */ |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3649 | private boolean ensureTouchModeLocally(boolean inTouchMode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3650 | if (DBG) Log.d("touchmode", "ensureTouchModeLocally(" + inTouchMode + "), current " |
| 3651 | + "touch mode is " + mAttachInfo.mInTouchMode); |
| 3652 | |
| 3653 | if (mAttachInfo.mInTouchMode == inTouchMode) return false; |
| 3654 | |
| 3655 | mAttachInfo.mInTouchMode = inTouchMode; |
| 3656 | mAttachInfo.mTreeObserver.dispatchOnTouchModeChanged(inTouchMode); |
| 3657 | |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3658 | return (inTouchMode) ? enterTouchMode() : leaveTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3659 | } |
| 3660 | |
| 3661 | private boolean enterTouchMode() { |
Alan Viverette | ed7821a | 2013-07-24 15:49:23 -0700 | [diff] [blame] | 3662 | if (mView != null && mView.hasFocus()) { |
| 3663 | // note: not relying on mFocusedView here because this could |
| 3664 | // be when the window is first being added, and mFocused isn't |
| 3665 | // set yet. |
| 3666 | final View focused = mView.findFocus(); |
| 3667 | if (focused != null && !focused.isFocusableInTouchMode()) { |
| 3668 | final ViewGroup ancestorToTakeFocus = findAncestorToTakeFocusInTouchMode(focused); |
| 3669 | if (ancestorToTakeFocus != null) { |
| 3670 | // there is an ancestor that wants focus after its |
| 3671 | // descendants that is focusable in touch mode.. give it |
| 3672 | // focus |
| 3673 | return ancestorToTakeFocus.requestFocus(); |
| 3674 | } else { |
Alan Viverette | 973f3b4 | 2013-08-13 16:57:28 -0700 | [diff] [blame] | 3675 | // There's nothing to focus. Clear and propagate through the |
| 3676 | // hierarchy, but don't attempt to place new focus. |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 3677 | focused.clearFocusInternal(null, true, false); |
Alan Viverette | ed7821a | 2013-07-24 15:49:23 -0700 | [diff] [blame] | 3678 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3679 | } |
| 3680 | } |
| 3681 | } |
| 3682 | return false; |
| 3683 | } |
| 3684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3685 | /** |
| 3686 | * Find an ancestor of focused that wants focus after its descendants and is |
| 3687 | * focusable in touch mode. |
| 3688 | * @param focused The currently focused view. |
| 3689 | * @return An appropriate view, or null if no such view exists. |
| 3690 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3691 | private static ViewGroup findAncestorToTakeFocusInTouchMode(View focused) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3692 | ViewParent parent = focused.getParent(); |
| 3693 | while (parent instanceof ViewGroup) { |
| 3694 | final ViewGroup vgParent = (ViewGroup) parent; |
| 3695 | if (vgParent.getDescendantFocusability() == ViewGroup.FOCUS_AFTER_DESCENDANTS |
| 3696 | && vgParent.isFocusableInTouchMode()) { |
| 3697 | return vgParent; |
| 3698 | } |
| 3699 | if (vgParent.isRootNamespace()) { |
| 3700 | return null; |
| 3701 | } else { |
| 3702 | parent = vgParent.getParent(); |
| 3703 | } |
| 3704 | } |
| 3705 | return null; |
| 3706 | } |
| 3707 | |
| 3708 | private boolean leaveTouchMode() { |
| 3709 | if (mView != null) { |
| 3710 | if (mView.hasFocus()) { |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3711 | View focusedView = mView.findFocus(); |
| 3712 | if (!(focusedView instanceof ViewGroup)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3713 | // some view has focus, let it keep it |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 3714 | return false; |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3715 | } else if (((ViewGroup) focusedView).getDescendantFocusability() != |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3716 | ViewGroup.FOCUS_AFTER_DESCENDANTS) { |
| 3717 | // some view group has focus, and doesn't prefer its children |
| 3718 | // over itself for focus, so let them keep it. |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 3719 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3720 | } |
| 3721 | } |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 3722 | |
| 3723 | // find the best view to give focus to in this brave new non-touch-mode |
| 3724 | // world |
| 3725 | final View focused = focusSearch(null, View.FOCUS_DOWN); |
| 3726 | if (focused != null) { |
| 3727 | return focused.requestFocus(View.FOCUS_DOWN); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3728 | } |
| 3729 | } |
| 3730 | return false; |
| 3731 | } |
| 3732 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3733 | /** |
| 3734 | * Base class for implementing a stage in the chain of responsibility |
| 3735 | * for processing input events. |
| 3736 | * <p> |
| 3737 | * Events are delivered to the stage by the {@link #deliver} method. The stage |
| 3738 | * then has the choice of finishing the event or forwarding it to the next stage. |
| 3739 | * </p> |
| 3740 | */ |
| 3741 | abstract class InputStage { |
| 3742 | private final InputStage mNext; |
| 3743 | |
| 3744 | protected static final int FORWARD = 0; |
| 3745 | protected static final int FINISH_HANDLED = 1; |
| 3746 | protected static final int FINISH_NOT_HANDLED = 2; |
| 3747 | |
| 3748 | /** |
| 3749 | * Creates an input stage. |
| 3750 | * @param next The next stage to which events should be forwarded. |
| 3751 | */ |
| 3752 | public InputStage(InputStage next) { |
| 3753 | mNext = next; |
| 3754 | } |
| 3755 | |
| 3756 | /** |
| 3757 | * Delivers an event to be processed. |
| 3758 | */ |
| 3759 | public final void deliver(QueuedInputEvent q) { |
| 3760 | if ((q.mFlags & QueuedInputEvent.FLAG_FINISHED) != 0) { |
| 3761 | forward(q); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 3762 | } else if (shouldDropInputEvent(q)) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3763 | finish(q, false); |
| 3764 | } else { |
| 3765 | apply(q, onProcess(q)); |
| 3766 | } |
| 3767 | } |
| 3768 | |
| 3769 | /** |
| 3770 | * Marks the the input event as finished then forwards it to the next stage. |
| 3771 | */ |
| 3772 | protected void finish(QueuedInputEvent q, boolean handled) { |
| 3773 | q.mFlags |= QueuedInputEvent.FLAG_FINISHED; |
| 3774 | if (handled) { |
| 3775 | q.mFlags |= QueuedInputEvent.FLAG_FINISHED_HANDLED; |
| 3776 | } |
| 3777 | forward(q); |
| 3778 | } |
| 3779 | |
| 3780 | /** |
| 3781 | * Forwards the event to the next stage. |
| 3782 | */ |
| 3783 | protected void forward(QueuedInputEvent q) { |
| 3784 | onDeliverToNext(q); |
| 3785 | } |
| 3786 | |
| 3787 | /** |
| 3788 | * Applies a result code from {@link #onProcess} to the specified event. |
| 3789 | */ |
| 3790 | protected void apply(QueuedInputEvent q, int result) { |
| 3791 | if (result == FORWARD) { |
| 3792 | forward(q); |
| 3793 | } else if (result == FINISH_HANDLED) { |
| 3794 | finish(q, true); |
| 3795 | } else if (result == FINISH_NOT_HANDLED) { |
| 3796 | finish(q, false); |
| 3797 | } else { |
| 3798 | throw new IllegalArgumentException("Invalid result: " + result); |
| 3799 | } |
| 3800 | } |
| 3801 | |
| 3802 | /** |
| 3803 | * Called when an event is ready to be processed. |
| 3804 | * @return A result code indicating how the event was handled. |
| 3805 | */ |
| 3806 | protected int onProcess(QueuedInputEvent q) { |
| 3807 | return FORWARD; |
| 3808 | } |
| 3809 | |
| 3810 | /** |
| 3811 | * Called when an event is being delivered to the next stage. |
| 3812 | */ |
| 3813 | protected void onDeliverToNext(QueuedInputEvent q) { |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 3814 | if (DEBUG_INPUT_STAGES) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3815 | Log.v(mTag, "Done with " + getClass().getSimpleName() + ". " + q); |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 3816 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3817 | if (mNext != null) { |
| 3818 | mNext.deliver(q); |
| 3819 | } else { |
| 3820 | finishInputEvent(q); |
| 3821 | } |
| 3822 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 3823 | |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 3824 | protected boolean shouldDropInputEvent(QueuedInputEvent q) { |
| 3825 | if (mView == null || !mAdded) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3826 | Slog.w(mTag, "Dropping event due to root view being removed: " + q.mEvent); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 3827 | return true; |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 3828 | } else if ((!mAttachInfo.mHasWindowFocus |
| 3829 | && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) || mStopped |
Joe LaPenna | 90776de | 2016-01-22 07:11:49 -0800 | [diff] [blame] | 3830 | || (mIsAmbientMode && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_BUTTON)) |
| 3831 | || (mPausedForTransition && !isBack(q.mEvent))) { |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 3832 | // This is a focus event and the window doesn't currently have input focus or |
| 3833 | // has stopped. This could be an event that came back from the previous stage |
| 3834 | // but the window has lost focus or stopped in the meantime. |
| 3835 | if (isTerminalInputEvent(q.mEvent)) { |
| 3836 | // Don't drop terminal input events, however mark them as canceled. |
| 3837 | q.mEvent.cancel(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3838 | Slog.w(mTag, "Cancelling event due to no window focus: " + q.mEvent); |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 3839 | return false; |
| 3840 | } |
| 3841 | |
| 3842 | // Drop non-terminal input events. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3843 | Slog.w(mTag, "Dropping event due to no window focus: " + q.mEvent); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 3844 | return true; |
| 3845 | } |
| 3846 | return false; |
| 3847 | } |
| 3848 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 3849 | void dump(String prefix, PrintWriter writer) { |
| 3850 | if (mNext != null) { |
| 3851 | mNext.dump(prefix, writer); |
| 3852 | } |
| 3853 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 3854 | |
| 3855 | private boolean isBack(InputEvent event) { |
| 3856 | if (event instanceof KeyEvent) { |
| 3857 | return ((KeyEvent) event).getKeyCode() == KeyEvent.KEYCODE_BACK; |
| 3858 | } else { |
| 3859 | return false; |
| 3860 | } |
| 3861 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3862 | } |
| 3863 | |
| 3864 | /** |
| 3865 | * Base class for implementing an input pipeline stage that supports |
| 3866 | * asynchronous and out-of-order processing of input events. |
| 3867 | * <p> |
| 3868 | * In addition to what a normal input stage can do, an asynchronous |
| 3869 | * input stage may also defer an input event that has been delivered to it |
| 3870 | * and finish or forward it later. |
| 3871 | * </p> |
| 3872 | */ |
| 3873 | abstract class AsyncInputStage extends InputStage { |
| 3874 | private final String mTraceCounter; |
| 3875 | |
| 3876 | private QueuedInputEvent mQueueHead; |
| 3877 | private QueuedInputEvent mQueueTail; |
| 3878 | private int mQueueLength; |
| 3879 | |
| 3880 | protected static final int DEFER = 3; |
| 3881 | |
| 3882 | /** |
| 3883 | * Creates an asynchronous input stage. |
| 3884 | * @param next The next stage to which events should be forwarded. |
| 3885 | * @param traceCounter The name of a counter to record the size of |
| 3886 | * the queue of pending events. |
| 3887 | */ |
| 3888 | public AsyncInputStage(InputStage next, String traceCounter) { |
| 3889 | super(next); |
| 3890 | mTraceCounter = traceCounter; |
| 3891 | } |
| 3892 | |
| 3893 | /** |
| 3894 | * Marks the event as deferred, which is to say that it will be handled |
| 3895 | * asynchronously. The caller is responsible for calling {@link #forward} |
| 3896 | * or {@link #finish} later when it is done handling the event. |
| 3897 | */ |
| 3898 | protected void defer(QueuedInputEvent q) { |
| 3899 | q.mFlags |= QueuedInputEvent.FLAG_DEFERRED; |
| 3900 | enqueue(q); |
| 3901 | } |
| 3902 | |
| 3903 | @Override |
| 3904 | protected void forward(QueuedInputEvent q) { |
| 3905 | // Clear the deferred flag. |
| 3906 | q.mFlags &= ~QueuedInputEvent.FLAG_DEFERRED; |
| 3907 | |
| 3908 | // Fast path if the queue is empty. |
| 3909 | QueuedInputEvent curr = mQueueHead; |
| 3910 | if (curr == null) { |
| 3911 | super.forward(q); |
| 3912 | return; |
| 3913 | } |
| 3914 | |
| 3915 | // Determine whether the event must be serialized behind any others |
| 3916 | // before it can be delivered to the next stage. This is done because |
| 3917 | // deferred events might be handled out of order by the stage. |
| 3918 | final int deviceId = q.mEvent.getDeviceId(); |
| 3919 | QueuedInputEvent prev = null; |
| 3920 | boolean blocked = false; |
| 3921 | while (curr != null && curr != q) { |
| 3922 | if (!blocked && deviceId == curr.mEvent.getDeviceId()) { |
| 3923 | blocked = true; |
| 3924 | } |
| 3925 | prev = curr; |
| 3926 | curr = curr.mNext; |
| 3927 | } |
| 3928 | |
| 3929 | // If the event is blocked, then leave it in the queue to be delivered later. |
| 3930 | // Note that the event might not yet be in the queue if it was not previously |
| 3931 | // deferred so we will enqueue it if needed. |
| 3932 | if (blocked) { |
| 3933 | if (curr == null) { |
| 3934 | enqueue(q); |
| 3935 | } |
| 3936 | return; |
| 3937 | } |
| 3938 | |
| 3939 | // The event is not blocked. Deliver it immediately. |
| 3940 | if (curr != null) { |
| 3941 | curr = curr.mNext; |
| 3942 | dequeue(q, prev); |
| 3943 | } |
| 3944 | super.forward(q); |
| 3945 | |
| 3946 | // Dequeuing this event may have unblocked successors. Deliver them. |
| 3947 | while (curr != null) { |
| 3948 | if (deviceId == curr.mEvent.getDeviceId()) { |
| 3949 | if ((curr.mFlags & QueuedInputEvent.FLAG_DEFERRED) != 0) { |
| 3950 | break; |
| 3951 | } |
| 3952 | QueuedInputEvent next = curr.mNext; |
| 3953 | dequeue(curr, prev); |
| 3954 | super.forward(curr); |
| 3955 | curr = next; |
| 3956 | } else { |
| 3957 | prev = curr; |
| 3958 | curr = curr.mNext; |
| 3959 | } |
| 3960 | } |
| 3961 | } |
| 3962 | |
| 3963 | @Override |
| 3964 | protected void apply(QueuedInputEvent q, int result) { |
| 3965 | if (result == DEFER) { |
| 3966 | defer(q); |
| 3967 | } else { |
| 3968 | super.apply(q, result); |
| 3969 | } |
| 3970 | } |
| 3971 | |
| 3972 | private void enqueue(QueuedInputEvent q) { |
| 3973 | if (mQueueTail == null) { |
| 3974 | mQueueHead = q; |
| 3975 | mQueueTail = q; |
| 3976 | } else { |
| 3977 | mQueueTail.mNext = q; |
| 3978 | mQueueTail = q; |
| 3979 | } |
| 3980 | |
| 3981 | mQueueLength += 1; |
| 3982 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mTraceCounter, mQueueLength); |
| 3983 | } |
| 3984 | |
| 3985 | private void dequeue(QueuedInputEvent q, QueuedInputEvent prev) { |
| 3986 | if (prev == null) { |
| 3987 | mQueueHead = q.mNext; |
| 3988 | } else { |
| 3989 | prev.mNext = q.mNext; |
| 3990 | } |
| 3991 | if (mQueueTail == q) { |
| 3992 | mQueueTail = prev; |
| 3993 | } |
| 3994 | q.mNext = null; |
| 3995 | |
| 3996 | mQueueLength -= 1; |
| 3997 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mTraceCounter, mQueueLength); |
| 3998 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 3999 | |
| 4000 | @Override |
| 4001 | void dump(String prefix, PrintWriter writer) { |
| 4002 | writer.print(prefix); |
| 4003 | writer.print(getClass().getName()); |
| 4004 | writer.print(": mQueueLength="); |
| 4005 | writer.println(mQueueLength); |
| 4006 | |
| 4007 | super.dump(prefix, writer); |
| 4008 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4009 | } |
| 4010 | |
| 4011 | /** |
| 4012 | * Delivers pre-ime input events to a native activity. |
| 4013 | * Does not support pointer events. |
| 4014 | */ |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4015 | final class NativePreImeInputStage extends AsyncInputStage |
| 4016 | implements InputQueue.FinishedInputEventCallback { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4017 | public NativePreImeInputStage(InputStage next, String traceCounter) { |
| 4018 | super(next, traceCounter); |
| 4019 | } |
| 4020 | |
| 4021 | @Override |
| 4022 | protected int onProcess(QueuedInputEvent q) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4023 | if (mInputQueue != null && q.mEvent instanceof KeyEvent) { |
| 4024 | mInputQueue.sendInputEvent(q.mEvent, q, true, this); |
| 4025 | return DEFER; |
| 4026 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4027 | return FORWARD; |
| 4028 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4029 | |
| 4030 | @Override |
| 4031 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4032 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4033 | if (handled) { |
| 4034 | finish(q, true); |
| 4035 | return; |
| 4036 | } |
| 4037 | forward(q); |
| 4038 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4039 | } |
| 4040 | |
| 4041 | /** |
| 4042 | * Delivers pre-ime input events to the view hierarchy. |
| 4043 | * Does not support pointer events. |
| 4044 | */ |
| 4045 | final class ViewPreImeInputStage extends InputStage { |
| 4046 | public ViewPreImeInputStage(InputStage next) { |
| 4047 | super(next); |
| 4048 | } |
| 4049 | |
| 4050 | @Override |
| 4051 | protected int onProcess(QueuedInputEvent q) { |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4052 | if (q.mEvent instanceof KeyEvent) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4053 | return processKeyEvent(q); |
| 4054 | } |
| 4055 | return FORWARD; |
| 4056 | } |
| 4057 | |
| 4058 | private int processKeyEvent(QueuedInputEvent q) { |
| 4059 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4060 | if (mView.dispatchKeyEventPreIme(event)) { |
| 4061 | return FINISH_HANDLED; |
| 4062 | } |
| 4063 | return FORWARD; |
| 4064 | } |
| 4065 | } |
| 4066 | |
| 4067 | /** |
| 4068 | * Delivers input events to the ime. |
| 4069 | * Does not support pointer events. |
| 4070 | */ |
| 4071 | final class ImeInputStage extends AsyncInputStage |
| 4072 | implements InputMethodManager.FinishedInputEventCallback { |
| 4073 | public ImeInputStage(InputStage next, String traceCounter) { |
| 4074 | super(next, traceCounter); |
| 4075 | } |
| 4076 | |
| 4077 | @Override |
| 4078 | protected int onProcess(QueuedInputEvent q) { |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 4079 | if (mLastWasImTarget && !isInLocalFocusMode()) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4080 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4081 | if (imm != null) { |
| 4082 | final InputEvent event = q.mEvent; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4083 | if (DEBUG_IMF) Log.v(mTag, "Sending input event to IME: " + event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4084 | int result = imm.dispatchInputEvent(event, q, this, mHandler); |
| 4085 | if (result == InputMethodManager.DISPATCH_HANDLED) { |
| 4086 | return FINISH_HANDLED; |
| 4087 | } else if (result == InputMethodManager.DISPATCH_NOT_HANDLED) { |
Adam Lesinski | c0f6eed | 2013-10-28 16:03:19 -0700 | [diff] [blame] | 4088 | // The IME could not handle it, so skip along to the next InputStage |
| 4089 | return FORWARD; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4090 | } else { |
| 4091 | return DEFER; // callback will be invoked later |
| 4092 | } |
| 4093 | } |
| 4094 | } |
| 4095 | return FORWARD; |
| 4096 | } |
| 4097 | |
| 4098 | @Override |
| 4099 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4100 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4101 | if (handled) { |
| 4102 | finish(q, true); |
| 4103 | return; |
| 4104 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4105 | forward(q); |
| 4106 | } |
| 4107 | } |
| 4108 | |
| 4109 | /** |
| 4110 | * Performs early processing of post-ime input events. |
| 4111 | */ |
| 4112 | final class EarlyPostImeInputStage extends InputStage { |
| 4113 | public EarlyPostImeInputStage(InputStage next) { |
| 4114 | super(next); |
| 4115 | } |
| 4116 | |
| 4117 | @Override |
| 4118 | protected int onProcess(QueuedInputEvent q) { |
| 4119 | if (q.mEvent instanceof KeyEvent) { |
| 4120 | return processKeyEvent(q); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4121 | } else { |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4122 | final int source = q.mEvent.getSource(); |
| 4123 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4124 | return processPointerEvent(q); |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4125 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4126 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4127 | return FORWARD; |
| 4128 | } |
| 4129 | |
| 4130 | private int processKeyEvent(QueuedInputEvent q) { |
| 4131 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4132 | |
| 4133 | // If the key's purpose is to exit touch mode then we consume it |
| 4134 | // and consider it handled. |
| 4135 | if (checkForLeavingTouchModeAndConsume(event)) { |
| 4136 | return FINISH_HANDLED; |
| 4137 | } |
| 4138 | |
| 4139 | // Make sure the fallback event policy sees all keys that will be |
| 4140 | // delivered to the view hierarchy. |
| 4141 | mFallbackEventHandler.preDispatchKeyEvent(event); |
| 4142 | return FORWARD; |
| 4143 | } |
| 4144 | |
| 4145 | private int processPointerEvent(QueuedInputEvent q) { |
| 4146 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4147 | |
| 4148 | // Translate the pointer event for compatibility, if needed. |
| 4149 | if (mTranslator != null) { |
| 4150 | mTranslator.translateEventInScreenToAppWindow(event); |
| 4151 | } |
| 4152 | |
| 4153 | // Enter touch mode on down or scroll. |
| 4154 | final int action = event.getAction(); |
| 4155 | if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_SCROLL) { |
| 4156 | ensureTouchMode(true); |
| 4157 | } |
| 4158 | |
| 4159 | // Offset the scroll position. |
| 4160 | if (mCurScrollY != 0) { |
| 4161 | event.offsetLocation(0, mCurScrollY); |
| 4162 | } |
| 4163 | |
| 4164 | // Remember the touch position for possible drag-initiation. |
| 4165 | if (event.isTouchEvent()) { |
| 4166 | mLastTouchPoint.x = event.getRawX(); |
| 4167 | mLastTouchPoint.y = event.getRawY(); |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 4168 | mLastTouchSource = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4169 | } |
| 4170 | return FORWARD; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4171 | } |
| 4172 | } |
| 4173 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4174 | /** |
| 4175 | * Delivers post-ime input events to a native activity. |
| 4176 | */ |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4177 | final class NativePostImeInputStage extends AsyncInputStage |
| 4178 | implements InputQueue.FinishedInputEventCallback { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4179 | public NativePostImeInputStage(InputStage next, String traceCounter) { |
| 4180 | super(next, traceCounter); |
| 4181 | } |
| 4182 | |
| 4183 | @Override |
| 4184 | protected int onProcess(QueuedInputEvent q) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4185 | if (mInputQueue != null) { |
| 4186 | mInputQueue.sendInputEvent(q.mEvent, q, false, this); |
| 4187 | return DEFER; |
| 4188 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4189 | return FORWARD; |
| 4190 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4191 | |
| 4192 | @Override |
| 4193 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4194 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4195 | if (handled) { |
| 4196 | finish(q, true); |
| 4197 | return; |
| 4198 | } |
| 4199 | forward(q); |
| 4200 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4201 | } |
| 4202 | |
| 4203 | /** |
| 4204 | * Delivers post-ime input events to the view hierarchy. |
| 4205 | */ |
| 4206 | final class ViewPostImeInputStage extends InputStage { |
| 4207 | public ViewPostImeInputStage(InputStage next) { |
| 4208 | super(next); |
| 4209 | } |
| 4210 | |
| 4211 | @Override |
| 4212 | protected int onProcess(QueuedInputEvent q) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4213 | if (q.mEvent instanceof KeyEvent) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4214 | return processKeyEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4215 | } else { |
| 4216 | final int source = q.mEvent.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4217 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 4218 | return processPointerEvent(q); |
| 4219 | } else if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
| 4220 | return processTrackballEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4221 | } else { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4222 | return processGenericMotionEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4223 | } |
| 4224 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4225 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4226 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 4227 | @Override |
| 4228 | protected void onDeliverToNext(QueuedInputEvent q) { |
| 4229 | if (mUnbufferedInputDispatch |
| 4230 | && q.mEvent instanceof MotionEvent |
| 4231 | && ((MotionEvent)q.mEvent).isTouchEvent() |
| 4232 | && isTerminalInputEvent(q.mEvent)) { |
| 4233 | mUnbufferedInputDispatch = false; |
| 4234 | scheduleConsumeBatchedInput(); |
| 4235 | } |
| 4236 | super.onDeliverToNext(q); |
| 4237 | } |
| 4238 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4239 | private int processKeyEvent(QueuedInputEvent q) { |
| 4240 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4241 | |
| 4242 | // Deliver the key to the view hierarchy. |
| 4243 | if (mView.dispatchKeyEvent(event)) { |
| 4244 | return FINISH_HANDLED; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4245 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4246 | |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4247 | if (shouldDropInputEvent(q)) { |
| 4248 | return FINISH_NOT_HANDLED; |
| 4249 | } |
| 4250 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4251 | // If the Control modifier is held, try to interpret the key as a shortcut. |
| 4252 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 4253 | && event.isCtrlPressed() |
| 4254 | && event.getRepeatCount() == 0 |
| 4255 | && !KeyEvent.isModifierKey(event.getKeyCode())) { |
| 4256 | if (mView.dispatchKeyShortcutEvent(event)) { |
| 4257 | return FINISH_HANDLED; |
| 4258 | } |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4259 | if (shouldDropInputEvent(q)) { |
| 4260 | return FINISH_NOT_HANDLED; |
| 4261 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | // Apply the fallback event policy. |
| 4265 | if (mFallbackEventHandler.dispatchKeyEvent(event)) { |
| 4266 | return FINISH_HANDLED; |
| 4267 | } |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4268 | if (shouldDropInputEvent(q)) { |
| 4269 | return FINISH_NOT_HANDLED; |
| 4270 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4271 | |
| 4272 | // Handle automatic focus changes. |
| 4273 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 4274 | int direction = 0; |
| 4275 | switch (event.getKeyCode()) { |
| 4276 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 4277 | if (event.hasNoModifiers()) { |
| 4278 | direction = View.FOCUS_LEFT; |
| 4279 | } |
| 4280 | break; |
| 4281 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 4282 | if (event.hasNoModifiers()) { |
| 4283 | direction = View.FOCUS_RIGHT; |
| 4284 | } |
| 4285 | break; |
| 4286 | case KeyEvent.KEYCODE_DPAD_UP: |
| 4287 | if (event.hasNoModifiers()) { |
| 4288 | direction = View.FOCUS_UP; |
| 4289 | } |
| 4290 | break; |
| 4291 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 4292 | if (event.hasNoModifiers()) { |
| 4293 | direction = View.FOCUS_DOWN; |
| 4294 | } |
| 4295 | break; |
| 4296 | case KeyEvent.KEYCODE_TAB: |
| 4297 | if (event.hasNoModifiers()) { |
| 4298 | direction = View.FOCUS_FORWARD; |
| 4299 | } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) { |
| 4300 | direction = View.FOCUS_BACKWARD; |
| 4301 | } |
| 4302 | break; |
| 4303 | } |
| 4304 | if (direction != 0) { |
| 4305 | View focused = mView.findFocus(); |
| 4306 | if (focused != null) { |
| 4307 | View v = focused.focusSearch(direction); |
| 4308 | if (v != null && v != focused) { |
| 4309 | // do the math the get the interesting rect |
| 4310 | // of previous focused into the coord system of |
| 4311 | // newly focused view |
| 4312 | focused.getFocusedRect(mTempRect); |
| 4313 | if (mView instanceof ViewGroup) { |
| 4314 | ((ViewGroup) mView).offsetDescendantRectToMyCoords( |
| 4315 | focused, mTempRect); |
| 4316 | ((ViewGroup) mView).offsetRectIntoDescendantCoords( |
| 4317 | v, mTempRect); |
| 4318 | } |
| 4319 | if (v.requestFocus(direction, mTempRect)) { |
| 4320 | playSoundEffect(SoundEffectConstants |
| 4321 | .getContantForFocusDirection(direction)); |
| 4322 | return FINISH_HANDLED; |
| 4323 | } |
| 4324 | } |
| 4325 | |
| 4326 | // Give the focused view a last chance to handle the dpad key. |
| 4327 | if (mView.dispatchUnhandledMove(focused, direction)) { |
| 4328 | return FINISH_HANDLED; |
| 4329 | } |
| 4330 | } else { |
| 4331 | // find the best view to give focus to in this non-touch-mode with no-focus |
| 4332 | View v = focusSearch(null, direction); |
| 4333 | if (v != null && v.requestFocus(direction)) { |
| 4334 | return FINISH_HANDLED; |
| 4335 | } |
| 4336 | } |
| 4337 | } |
| 4338 | } |
| 4339 | return FORWARD; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4340 | } |
| 4341 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4342 | private int processPointerEvent(QueuedInputEvent q) { |
| 4343 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4344 | |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 4345 | mAttachInfo.mUnbufferedDispatchRequested = false; |
| 4346 | final View eventTarget = |
| 4347 | (event.isFromSource(InputDevice.SOURCE_MOUSE) && mCapturingView != null) ? |
| 4348 | mCapturingView : mView; |
| 4349 | mAttachInfo.mHandlingPointerEvent = true; |
| 4350 | boolean handled = eventTarget.dispatchPointerEvent(event); |
| 4351 | maybeUpdatePointerIcon(event); |
| 4352 | mAttachInfo.mHandlingPointerEvent = false; |
| 4353 | if (mAttachInfo.mUnbufferedDispatchRequested && !mUnbufferedInputDispatch) { |
| 4354 | mUnbufferedInputDispatch = true; |
| 4355 | if (mConsumeBatchedInputScheduled) { |
| 4356 | scheduleConsumeBatchedInputImmediately(); |
| 4357 | } |
| 4358 | } |
| 4359 | return handled ? FINISH_HANDLED : FORWARD; |
| 4360 | } |
| 4361 | |
| 4362 | private void maybeUpdatePointerIcon(MotionEvent event) { |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 4363 | if (event.getPointerCount() == 1 |
| 4364 | && event.isFromSource(InputDevice.SOURCE_MOUSE)) { |
| 4365 | if (event.getActionMasked() == MotionEvent.ACTION_HOVER_ENTER |
| 4366 | || event.getActionMasked() == MotionEvent.ACTION_HOVER_EXIT) { |
| 4367 | // Other apps or the window manager may change the icon shape outside of |
| 4368 | // this app, therefore the icon shape has to be reset on enter/exit event. |
| 4369 | mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
| 4370 | } |
| 4371 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4372 | if (event.getActionMasked() != MotionEvent.ACTION_HOVER_EXIT) { |
| 4373 | if (!updatePointerIcon(event) && |
| 4374 | event.getActionMasked() == MotionEvent.ACTION_HOVER_MOVE) { |
| 4375 | mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 4376 | } |
| 4377 | } |
| 4378 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4379 | } |
| 4380 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4381 | private int processTrackballEvent(QueuedInputEvent q) { |
| 4382 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4383 | |
| 4384 | if (mView.dispatchTrackballEvent(event)) { |
| 4385 | return FINISH_HANDLED; |
| 4386 | } |
| 4387 | return FORWARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4388 | } |
| 4389 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4390 | private int processGenericMotionEvent(QueuedInputEvent q) { |
| 4391 | final MotionEvent event = (MotionEvent)q.mEvent; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4392 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4393 | // Deliver the event to the view. |
| 4394 | if (mView.dispatchGenericMotionEvent(event)) { |
| 4395 | return FINISH_HANDLED; |
| 4396 | } |
| 4397 | return FORWARD; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4398 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4399 | } |
| 4400 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4401 | private void resetPointerIcon(MotionEvent event) { |
| 4402 | mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
| 4403 | updatePointerIcon(event); |
| 4404 | } |
| 4405 | |
| 4406 | private boolean updatePointerIcon(MotionEvent event) { |
| 4407 | final float x = event.getX(); |
| 4408 | final float y = event.getY(); |
Andrii Kulian | 33c1bc5 | 2016-02-29 10:38:59 -0800 | [diff] [blame] | 4409 | if (mView == null) { |
| 4410 | // E.g. click outside a popup to dismiss it |
| 4411 | Slog.d(mTag, "updatePointerIcon called after view was removed"); |
| 4412 | return false; |
| 4413 | } |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4414 | if (x < 0 || x >= mView.getWidth() || y < 0 || y >= mView.getHeight()) { |
Andrii Kulian | 33c1bc5 | 2016-02-29 10:38:59 -0800 | [diff] [blame] | 4415 | // E.g. when moving window divider with mouse |
| 4416 | Slog.d(mTag, "updatePointerIcon called with position out of bounds"); |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4417 | return false; |
| 4418 | } |
| 4419 | final PointerIcon pointerIcon = mView.getPointerIcon(event, x, y); |
| 4420 | final int pointerShape = (pointerIcon != null) ? |
| 4421 | pointerIcon.getStyle() : PointerIcon.STYLE_DEFAULT; |
| 4422 | |
| 4423 | if (mPointerIconShape != pointerShape) { |
| 4424 | mPointerIconShape = pointerShape; |
| 4425 | if (mPointerIconShape != PointerIcon.STYLE_CUSTOM) { |
| 4426 | mCustomPointerIcon = null; |
| 4427 | InputManager.getInstance().setPointerIconShape(pointerShape); |
| 4428 | return true; |
| 4429 | } |
| 4430 | } |
| 4431 | if (mPointerIconShape == PointerIcon.STYLE_CUSTOM && |
| 4432 | !pointerIcon.equals(mCustomPointerIcon)) { |
| 4433 | mCustomPointerIcon = pointerIcon; |
| 4434 | InputManager.getInstance().setCustomPointerIcon(mCustomPointerIcon); |
| 4435 | } |
| 4436 | return true; |
| 4437 | } |
| 4438 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4439 | /** |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4440 | * Performs synthesis of new input events from unhandled input events. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4441 | */ |
| 4442 | final class SyntheticInputStage extends InputStage { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4443 | private final SyntheticTrackballHandler mTrackball = new SyntheticTrackballHandler(); |
| 4444 | private final SyntheticJoystickHandler mJoystick = new SyntheticJoystickHandler(); |
| 4445 | private final SyntheticTouchNavigationHandler mTouchNavigation = |
| 4446 | new SyntheticTouchNavigationHandler(); |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4447 | private final SyntheticKeyboardHandler mKeyboard = new SyntheticKeyboardHandler(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4448 | |
| 4449 | public SyntheticInputStage() { |
| 4450 | super(null); |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4451 | } |
| 4452 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4453 | @Override |
| 4454 | protected int onProcess(QueuedInputEvent q) { |
| 4455 | q.mFlags |= QueuedInputEvent.FLAG_RESYNTHESIZED; |
| 4456 | if (q.mEvent instanceof MotionEvent) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4457 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4458 | final int source = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4459 | if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4460 | mTrackball.process(event); |
| 4461 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4462 | } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4463 | mJoystick.process(event); |
| 4464 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4465 | } else if ((source & InputDevice.SOURCE_TOUCH_NAVIGATION) |
| 4466 | == InputDevice.SOURCE_TOUCH_NAVIGATION) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4467 | mTouchNavigation.process(event); |
| 4468 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4469 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4470 | } else if ((q.mFlags & QueuedInputEvent.FLAG_UNHANDLED) != 0) { |
| 4471 | mKeyboard.process((KeyEvent)q.mEvent); |
| 4472 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4473 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4474 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4475 | return FORWARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4476 | } |
| 4477 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4478 | @Override |
| 4479 | protected void onDeliverToNext(QueuedInputEvent q) { |
| 4480 | if ((q.mFlags & QueuedInputEvent.FLAG_RESYNTHESIZED) == 0) { |
| 4481 | // Cancel related synthetic events if any prior stage has handled the event. |
| 4482 | if (q.mEvent instanceof MotionEvent) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4483 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4484 | final int source = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4485 | if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4486 | mTrackball.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4487 | } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4488 | mJoystick.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4489 | } else if ((source & InputDevice.SOURCE_TOUCH_NAVIGATION) |
| 4490 | == InputDevice.SOURCE_TOUCH_NAVIGATION) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4491 | mTouchNavigation.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4492 | } |
| 4493 | } |
| 4494 | } |
| 4495 | super.onDeliverToNext(q); |
| 4496 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4497 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4498 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4499 | /** |
| 4500 | * Creates dpad events from unhandled trackball movements. |
| 4501 | */ |
| 4502 | final class SyntheticTrackballHandler { |
| 4503 | private final TrackballAxis mX = new TrackballAxis(); |
| 4504 | private final TrackballAxis mY = new TrackballAxis(); |
| 4505 | private long mLastTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4506 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4507 | public void process(MotionEvent event) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4508 | // Translate the trackball event into DPAD keys and try to deliver those. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4509 | long curTime = SystemClock.uptimeMillis(); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4510 | if ((mLastTime + MAX_TRACKBALL_DELAY) < curTime) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4511 | // It has been too long since the last movement, |
| 4512 | // so restart at the beginning. |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4513 | mX.reset(0); |
| 4514 | mY.reset(0); |
| 4515 | mLastTime = curTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4516 | } |
| 4517 | |
| 4518 | final int action = event.getAction(); |
| 4519 | final int metaState = event.getMetaState(); |
| 4520 | switch (action) { |
| 4521 | case MotionEvent.ACTION_DOWN: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4522 | mX.reset(2); |
| 4523 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4524 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4525 | KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER, 0, metaState, |
| 4526 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4527 | InputDevice.SOURCE_KEYBOARD)); |
| 4528 | break; |
| 4529 | case MotionEvent.ACTION_UP: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4530 | mX.reset(2); |
| 4531 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4532 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4533 | KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER, 0, metaState, |
| 4534 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4535 | InputDevice.SOURCE_KEYBOARD)); |
| 4536 | break; |
| 4537 | } |
| 4538 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4539 | if (DEBUG_TRACKBALL) Log.v(mTag, "TB X=" + mX.position + " step=" |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4540 | + mX.step + " dir=" + mX.dir + " acc=" + mX.acceleration |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4541 | + " move=" + event.getX() |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4542 | + " / Y=" + mY.position + " step=" |
| 4543 | + mY.step + " dir=" + mY.dir + " acc=" + mY.acceleration |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4544 | + " move=" + event.getY()); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4545 | final float xOff = mX.collect(event.getX(), event.getEventTime(), "X"); |
| 4546 | final float yOff = mY.collect(event.getY(), event.getEventTime(), "Y"); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4547 | |
| 4548 | // Generate DPAD events based on the trackball movement. |
| 4549 | // We pick the axis that has moved the most as the direction of |
| 4550 | // the DPAD. When we generate DPAD events for one axis, then the |
| 4551 | // other axis is reset -- we don't want to perform DPAD jumps due |
| 4552 | // to slight movements in the trackball when making major movements |
| 4553 | // along the other axis. |
| 4554 | int keycode = 0; |
| 4555 | int movement = 0; |
| 4556 | float accel = 1; |
| 4557 | if (xOff > yOff) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4558 | movement = mX.generate(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4559 | if (movement != 0) { |
| 4560 | keycode = movement > 0 ? KeyEvent.KEYCODE_DPAD_RIGHT |
| 4561 | : KeyEvent.KEYCODE_DPAD_LEFT; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4562 | accel = mX.acceleration; |
| 4563 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4564 | } |
| 4565 | } else if (yOff > 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4566 | movement = mY.generate(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4567 | if (movement != 0) { |
| 4568 | keycode = movement > 0 ? KeyEvent.KEYCODE_DPAD_DOWN |
| 4569 | : KeyEvent.KEYCODE_DPAD_UP; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4570 | accel = mY.acceleration; |
| 4571 | mX.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4572 | } |
| 4573 | } |
| 4574 | |
| 4575 | if (keycode != 0) { |
| 4576 | if (movement < 0) movement = -movement; |
| 4577 | int accelMovement = (int)(movement * accel); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4578 | if (DEBUG_TRACKBALL) Log.v(mTag, "Move: movement=" + movement |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4579 | + " accelMovement=" + accelMovement |
| 4580 | + " accel=" + accel); |
| 4581 | if (accelMovement > movement) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4582 | if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: " |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4583 | + keycode); |
| 4584 | movement--; |
| 4585 | int repeatCount = accelMovement - movement; |
| 4586 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4587 | KeyEvent.ACTION_MULTIPLE, keycode, repeatCount, metaState, |
| 4588 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4589 | InputDevice.SOURCE_KEYBOARD)); |
| 4590 | } |
| 4591 | while (movement > 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4592 | if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: " |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4593 | + keycode); |
| 4594 | movement--; |
| 4595 | curTime = SystemClock.uptimeMillis(); |
| 4596 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4597 | KeyEvent.ACTION_DOWN, keycode, 0, metaState, |
| 4598 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4599 | InputDevice.SOURCE_KEYBOARD)); |
| 4600 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4601 | KeyEvent.ACTION_UP, keycode, 0, metaState, |
| 4602 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4603 | InputDevice.SOURCE_KEYBOARD)); |
| 4604 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4605 | mLastTime = curTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4606 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4607 | } |
| 4608 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4609 | public void cancel(MotionEvent event) { |
| 4610 | mLastTime = Integer.MIN_VALUE; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4611 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4612 | // If we reach this, we consumed a trackball event. |
| 4613 | // Because we will not translate the trackball event into a key event, |
| 4614 | // touch mode will not exit, so we exit touch mode here. |
| 4615 | if (mView != null && mAdded) { |
| 4616 | ensureTouchMode(false); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4617 | } |
| 4618 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4619 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4620 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4621 | /** |
| 4622 | * Maintains state information for a single trackball axis, generating |
| 4623 | * discrete (DPAD) movements based on raw trackball motion. |
| 4624 | */ |
| 4625 | static final class TrackballAxis { |
| 4626 | /** |
| 4627 | * The maximum amount of acceleration we will apply. |
| 4628 | */ |
| 4629 | static final float MAX_ACCELERATION = 20; |
| 4630 | |
| 4631 | /** |
| 4632 | * The maximum amount of time (in milliseconds) between events in order |
| 4633 | * for us to consider the user to be doing fast trackball movements, |
| 4634 | * and thus apply an acceleration. |
| 4635 | */ |
| 4636 | static final long FAST_MOVE_TIME = 150; |
| 4637 | |
| 4638 | /** |
| 4639 | * Scaling factor to the time (in milliseconds) between events to how |
| 4640 | * much to multiple/divide the current acceleration. When movement |
| 4641 | * is < FAST_MOVE_TIME this multiplies the acceleration; when > |
| 4642 | * FAST_MOVE_TIME it divides it. |
| 4643 | */ |
| 4644 | static final float ACCEL_MOVE_SCALING_FACTOR = (1.0f/40); |
| 4645 | |
| 4646 | static final float FIRST_MOVEMENT_THRESHOLD = 0.5f; |
| 4647 | static final float SECOND_CUMULATIVE_MOVEMENT_THRESHOLD = 2.0f; |
| 4648 | static final float SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD = 1.0f; |
| 4649 | |
| 4650 | float position; |
| 4651 | float acceleration = 1; |
| 4652 | long lastMoveTime = 0; |
| 4653 | int step; |
| 4654 | int dir; |
| 4655 | int nonAccelMovement; |
| 4656 | |
| 4657 | void reset(int _step) { |
| 4658 | position = 0; |
| 4659 | acceleration = 1; |
| 4660 | lastMoveTime = 0; |
| 4661 | step = _step; |
| 4662 | dir = 0; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 4663 | } |
| 4664 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4665 | /** |
| 4666 | * Add trackball movement into the state. If the direction of movement |
| 4667 | * has been reversed, the state is reset before adding the |
| 4668 | * movement (so that you don't have to compensate for any previously |
| 4669 | * collected movement before see the result of the movement in the |
| 4670 | * new direction). |
| 4671 | * |
| 4672 | * @return Returns the absolute value of the amount of movement |
| 4673 | * collected so far. |
| 4674 | */ |
| 4675 | float collect(float off, long time, String axis) { |
| 4676 | long normTime; |
| 4677 | if (off > 0) { |
| 4678 | normTime = (long)(off * FAST_MOVE_TIME); |
| 4679 | if (dir < 0) { |
| 4680 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " reversed to positive!"); |
| 4681 | position = 0; |
| 4682 | step = 0; |
| 4683 | acceleration = 1; |
| 4684 | lastMoveTime = 0; |
| 4685 | } |
| 4686 | dir = 1; |
| 4687 | } else if (off < 0) { |
| 4688 | normTime = (long)((-off) * FAST_MOVE_TIME); |
| 4689 | if (dir > 0) { |
| 4690 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " reversed to negative!"); |
| 4691 | position = 0; |
| 4692 | step = 0; |
| 4693 | acceleration = 1; |
| 4694 | lastMoveTime = 0; |
| 4695 | } |
| 4696 | dir = -1; |
| 4697 | } else { |
| 4698 | normTime = 0; |
| 4699 | } |
| 4700 | |
| 4701 | // The number of milliseconds between each movement that is |
| 4702 | // considered "normal" and will not result in any acceleration |
| 4703 | // or deceleration, scaled by the offset we have here. |
| 4704 | if (normTime > 0) { |
| 4705 | long delta = time - lastMoveTime; |
| 4706 | lastMoveTime = time; |
| 4707 | float acc = acceleration; |
| 4708 | if (delta < normTime) { |
| 4709 | // The user is scrolling rapidly, so increase acceleration. |
| 4710 | float scale = (normTime-delta) * ACCEL_MOVE_SCALING_FACTOR; |
| 4711 | if (scale > 1) acc *= scale; |
| 4712 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " accelerate: off=" |
| 4713 | + off + " normTime=" + normTime + " delta=" + delta |
| 4714 | + " scale=" + scale + " acc=" + acc); |
| 4715 | acceleration = acc < MAX_ACCELERATION ? acc : MAX_ACCELERATION; |
| 4716 | } else { |
| 4717 | // The user is scrolling slowly, so decrease acceleration. |
| 4718 | float scale = (delta-normTime) * ACCEL_MOVE_SCALING_FACTOR; |
| 4719 | if (scale > 1) acc /= scale; |
| 4720 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " deccelerate: off=" |
| 4721 | + off + " normTime=" + normTime + " delta=" + delta |
| 4722 | + " scale=" + scale + " acc=" + acc); |
| 4723 | acceleration = acc > 1 ? acc : 1; |
| 4724 | } |
| 4725 | } |
| 4726 | position += off; |
| 4727 | return Math.abs(position); |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 4728 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4729 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4730 | /** |
| 4731 | * Generate the number of discrete movement events appropriate for |
| 4732 | * the currently collected trackball movement. |
| 4733 | * |
| 4734 | * @return Returns the number of discrete movements, either positive |
| 4735 | * or negative, or 0 if there is not enough trackball movement yet |
| 4736 | * for a discrete movement. |
| 4737 | */ |
| 4738 | int generate() { |
| 4739 | int movement = 0; |
| 4740 | nonAccelMovement = 0; |
| 4741 | do { |
| 4742 | final int dir = position >= 0 ? 1 : -1; |
| 4743 | switch (step) { |
| 4744 | // If we are going to execute the first step, then we want |
| 4745 | // to do this as soon as possible instead of waiting for |
| 4746 | // a full movement, in order to make things look responsive. |
| 4747 | case 0: |
| 4748 | if (Math.abs(position) < FIRST_MOVEMENT_THRESHOLD) { |
| 4749 | return movement; |
| 4750 | } |
| 4751 | movement += dir; |
| 4752 | nonAccelMovement += dir; |
| 4753 | step = 1; |
| 4754 | break; |
| 4755 | // If we have generated the first movement, then we need |
| 4756 | // to wait for the second complete trackball motion before |
| 4757 | // generating the second discrete movement. |
| 4758 | case 1: |
| 4759 | if (Math.abs(position) < SECOND_CUMULATIVE_MOVEMENT_THRESHOLD) { |
| 4760 | return movement; |
| 4761 | } |
| 4762 | movement += dir; |
| 4763 | nonAccelMovement += dir; |
| 4764 | position -= SECOND_CUMULATIVE_MOVEMENT_THRESHOLD * dir; |
| 4765 | step = 2; |
| 4766 | break; |
| 4767 | // After the first two, we generate discrete movements |
| 4768 | // consistently with the trackball, applying an acceleration |
| 4769 | // if the trackball is moving quickly. This is a simple |
| 4770 | // acceleration on top of what we already compute based |
| 4771 | // on how quickly the wheel is being turned, to apply |
| 4772 | // a longer increasing acceleration to continuous movement |
| 4773 | // in one direction. |
| 4774 | default: |
| 4775 | if (Math.abs(position) < SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD) { |
| 4776 | return movement; |
| 4777 | } |
| 4778 | movement += dir; |
| 4779 | position -= dir * SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD; |
| 4780 | float acc = acceleration; |
| 4781 | acc *= 1.1f; |
| 4782 | acceleration = acc < MAX_ACCELERATION ? acc : acceleration; |
| 4783 | break; |
| 4784 | } |
| 4785 | } while (true); |
| 4786 | } |
| 4787 | } |
| 4788 | |
| 4789 | /** |
| 4790 | * Creates dpad events from unhandled joystick movements. |
| 4791 | */ |
| 4792 | final class SyntheticJoystickHandler extends Handler { |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4793 | private final static String TAG = "SyntheticJoystickHandler"; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4794 | private final static int MSG_ENQUEUE_X_AXIS_KEY_REPEAT = 1; |
| 4795 | private final static int MSG_ENQUEUE_Y_AXIS_KEY_REPEAT = 2; |
| 4796 | |
| 4797 | private int mLastXDirection; |
| 4798 | private int mLastYDirection; |
| 4799 | private int mLastXKeyCode; |
| 4800 | private int mLastYKeyCode; |
| 4801 | |
| 4802 | public SyntheticJoystickHandler() { |
| 4803 | super(true); |
| 4804 | } |
| 4805 | |
| 4806 | @Override |
| 4807 | public void handleMessage(Message msg) { |
| 4808 | switch (msg.what) { |
| 4809 | case MSG_ENQUEUE_X_AXIS_KEY_REPEAT: |
| 4810 | case MSG_ENQUEUE_Y_AXIS_KEY_REPEAT: { |
| 4811 | KeyEvent oldEvent = (KeyEvent)msg.obj; |
| 4812 | KeyEvent e = KeyEvent.changeTimeRepeat(oldEvent, |
| 4813 | SystemClock.uptimeMillis(), |
| 4814 | oldEvent.getRepeatCount() + 1); |
| 4815 | if (mAttachInfo.mHasWindowFocus) { |
| 4816 | enqueueInputEvent(e); |
| 4817 | Message m = obtainMessage(msg.what, e); |
| 4818 | m.setAsynchronous(true); |
| 4819 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatDelay()); |
| 4820 | } |
| 4821 | } break; |
| 4822 | } |
| 4823 | } |
| 4824 | |
| 4825 | public void process(MotionEvent event) { |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4826 | switch(event.getActionMasked()) { |
| 4827 | case MotionEvent.ACTION_CANCEL: |
| 4828 | cancel(event); |
| 4829 | break; |
| 4830 | case MotionEvent.ACTION_MOVE: |
| 4831 | update(event, true); |
| 4832 | break; |
| 4833 | default: |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4834 | Log.w(mTag, "Unexpected action: " + event.getActionMasked()); |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4835 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4836 | } |
| 4837 | |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4838 | private void cancel(MotionEvent event) { |
| 4839 | removeMessages(MSG_ENQUEUE_X_AXIS_KEY_REPEAT); |
| 4840 | removeMessages(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4841 | update(event, false); |
| 4842 | } |
| 4843 | |
| 4844 | private void update(MotionEvent event, boolean synthesizeNewKeys) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4845 | final long time = event.getEventTime(); |
| 4846 | final int metaState = event.getMetaState(); |
| 4847 | final int deviceId = event.getDeviceId(); |
| 4848 | final int source = event.getSource(); |
| 4849 | |
| 4850 | int xDirection = joystickAxisValueToDirection( |
| 4851 | event.getAxisValue(MotionEvent.AXIS_HAT_X)); |
| 4852 | if (xDirection == 0) { |
| 4853 | xDirection = joystickAxisValueToDirection(event.getX()); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4854 | } |
| 4855 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4856 | int yDirection = joystickAxisValueToDirection( |
| 4857 | event.getAxisValue(MotionEvent.AXIS_HAT_Y)); |
| 4858 | if (yDirection == 0) { |
| 4859 | yDirection = joystickAxisValueToDirection(event.getY()); |
| 4860 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4861 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4862 | if (xDirection != mLastXDirection) { |
| 4863 | if (mLastXKeyCode != 0) { |
| 4864 | removeMessages(MSG_ENQUEUE_X_AXIS_KEY_REPEAT); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4865 | enqueueInputEvent(new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4866 | KeyEvent.ACTION_UP, mLastXKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4867 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source)); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4868 | mLastXKeyCode = 0; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4869 | } |
| 4870 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4871 | mLastXDirection = xDirection; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4872 | |
| 4873 | if (xDirection != 0 && synthesizeNewKeys) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4874 | mLastXKeyCode = xDirection > 0 |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4875 | ? KeyEvent.KEYCODE_DPAD_RIGHT : KeyEvent.KEYCODE_DPAD_LEFT; |
| 4876 | final KeyEvent e = new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4877 | KeyEvent.ACTION_DOWN, mLastXKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4878 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source); |
| 4879 | enqueueInputEvent(e); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4880 | Message m = obtainMessage(MSG_ENQUEUE_X_AXIS_KEY_REPEAT, e); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4881 | m.setAsynchronous(true); |
Michael Wright | b961852 | 2013-04-10 15:20:56 -0700 | [diff] [blame] | 4882 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatTimeout()); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4883 | } |
| 4884 | } |
| 4885 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4886 | if (yDirection != mLastYDirection) { |
| 4887 | if (mLastYKeyCode != 0) { |
| 4888 | removeMessages(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4889 | enqueueInputEvent(new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4890 | KeyEvent.ACTION_UP, mLastYKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4891 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source)); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4892 | mLastYKeyCode = 0; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4893 | } |
| 4894 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4895 | mLastYDirection = yDirection; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4896 | |
| 4897 | if (yDirection != 0 && synthesizeNewKeys) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4898 | mLastYKeyCode = yDirection > 0 |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4899 | ? KeyEvent.KEYCODE_DPAD_DOWN : KeyEvent.KEYCODE_DPAD_UP; |
| 4900 | final KeyEvent e = new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4901 | KeyEvent.ACTION_DOWN, mLastYKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4902 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source); |
| 4903 | enqueueInputEvent(e); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4904 | Message m = obtainMessage(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT, e); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4905 | m.setAsynchronous(true); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4906 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatTimeout()); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4907 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4908 | } |
| 4909 | } |
| 4910 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4911 | private int joystickAxisValueToDirection(float value) { |
| 4912 | if (value >= 0.5f) { |
| 4913 | return 1; |
| 4914 | } else if (value <= -0.5f) { |
| 4915 | return -1; |
| 4916 | } else { |
| 4917 | return 0; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4918 | } |
| 4919 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4920 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4921 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4922 | /** |
| 4923 | * Creates dpad events from unhandled touch navigation movements. |
| 4924 | */ |
| 4925 | final class SyntheticTouchNavigationHandler extends Handler { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4926 | private static final String LOCAL_TAG = "SyntheticTouchNavigationHandler"; |
| 4927 | private static final boolean LOCAL_DEBUG = false; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4928 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4929 | // Assumed nominal width and height in millimeters of a touch navigation pad, |
| 4930 | // if no resolution information is available from the input system. |
| 4931 | private static final float DEFAULT_WIDTH_MILLIMETERS = 48; |
| 4932 | private static final float DEFAULT_HEIGHT_MILLIMETERS = 48; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4933 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4934 | /* TODO: These constants should eventually be moved to ViewConfiguration. */ |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4935 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4936 | // The nominal distance traveled to move by one unit. |
| 4937 | private static final int TICK_DISTANCE_MILLIMETERS = 12; |
| 4938 | |
| 4939 | // Minimum and maximum fling velocity in ticks per second. |
| 4940 | // The minimum velocity should be set such that we perform enough ticks per |
| 4941 | // second that the fling appears to be fluid. For example, if we set the minimum |
| 4942 | // to 2 ticks per second, then there may be up to half a second delay between the next |
| 4943 | // to last and last ticks which is noticeably discrete and jerky. This value should |
| 4944 | // probably not be set to anything less than about 4. |
| 4945 | // If fling accuracy is a problem then consider tuning the tick distance instead. |
| 4946 | private static final float MIN_FLING_VELOCITY_TICKS_PER_SECOND = 6f; |
| 4947 | private static final float MAX_FLING_VELOCITY_TICKS_PER_SECOND = 20f; |
| 4948 | |
| 4949 | // Fling velocity decay factor applied after each new key is emitted. |
| 4950 | // This parameter controls the deceleration and overall duration of the fling. |
| 4951 | // The fling stops automatically when its velocity drops below the minimum |
| 4952 | // fling velocity defined above. |
| 4953 | private static final float FLING_TICK_DECAY = 0.8f; |
| 4954 | |
| 4955 | /* The input device that we are tracking. */ |
| 4956 | |
| 4957 | private int mCurrentDeviceId = -1; |
| 4958 | private int mCurrentSource; |
| 4959 | private boolean mCurrentDeviceSupported; |
| 4960 | |
| 4961 | /* Configuration for the current input device. */ |
| 4962 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4963 | // The scaled tick distance. A movement of this amount should generally translate |
| 4964 | // into a single dpad event in a given direction. |
| 4965 | private float mConfigTickDistance; |
| 4966 | |
| 4967 | // The minimum and maximum scaled fling velocity. |
| 4968 | private float mConfigMinFlingVelocity; |
| 4969 | private float mConfigMaxFlingVelocity; |
| 4970 | |
| 4971 | /* Tracking state. */ |
| 4972 | |
| 4973 | // The velocity tracker for detecting flings. |
| 4974 | private VelocityTracker mVelocityTracker; |
| 4975 | |
| 4976 | // The active pointer id, or -1 if none. |
| 4977 | private int mActivePointerId = -1; |
| 4978 | |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 4979 | // Location where tracking started. |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4980 | private float mStartX; |
| 4981 | private float mStartY; |
| 4982 | |
| 4983 | // Most recently observed position. |
| 4984 | private float mLastX; |
| 4985 | private float mLastY; |
| 4986 | |
| 4987 | // Accumulated movement delta since the last direction key was sent. |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4988 | private float mAccumulatedX; |
| 4989 | private float mAccumulatedY; |
| 4990 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4991 | // Set to true if any movement was delivered to the app. |
| 4992 | // Implies that tap slop was exceeded. |
| 4993 | private boolean mConsumedMovement; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4994 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4995 | // The most recently sent key down event. |
| 4996 | // The keycode remains set until the direction changes or a fling ends |
| 4997 | // so that repeated key events may be generated as required. |
| 4998 | private long mPendingKeyDownTime; |
| 4999 | private int mPendingKeyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 5000 | private int mPendingKeyRepeatCount; |
| 5001 | private int mPendingKeyMetaState; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5002 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5003 | // The current fling velocity while a fling is in progress. |
| 5004 | private boolean mFlinging; |
| 5005 | private float mFlingVelocity; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5006 | |
| 5007 | public SyntheticTouchNavigationHandler() { |
| 5008 | super(true); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5009 | } |
| 5010 | |
| 5011 | public void process(MotionEvent event) { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5012 | // Update the current device information. |
| 5013 | final long time = event.getEventTime(); |
| 5014 | final int deviceId = event.getDeviceId(); |
| 5015 | final int source = event.getSource(); |
| 5016 | if (mCurrentDeviceId != deviceId || mCurrentSource != source) { |
| 5017 | finishKeys(time); |
| 5018 | finishTracking(time); |
| 5019 | mCurrentDeviceId = deviceId; |
| 5020 | mCurrentSource = source; |
| 5021 | mCurrentDeviceSupported = false; |
| 5022 | InputDevice device = event.getDevice(); |
| 5023 | if (device != null) { |
| 5024 | // In order to support an input device, we must know certain |
| 5025 | // characteristics about it, such as its size and resolution. |
| 5026 | InputDevice.MotionRange xRange = device.getMotionRange(MotionEvent.AXIS_X); |
| 5027 | InputDevice.MotionRange yRange = device.getMotionRange(MotionEvent.AXIS_Y); |
| 5028 | if (xRange != null && yRange != null) { |
| 5029 | mCurrentDeviceSupported = true; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5030 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5031 | // Infer the resolution if it not actually known. |
| 5032 | float xRes = xRange.getResolution(); |
| 5033 | if (xRes <= 0) { |
| 5034 | xRes = xRange.getRange() / DEFAULT_WIDTH_MILLIMETERS; |
| 5035 | } |
| 5036 | float yRes = yRange.getResolution(); |
| 5037 | if (yRes <= 0) { |
| 5038 | yRes = yRange.getRange() / DEFAULT_HEIGHT_MILLIMETERS; |
| 5039 | } |
| 5040 | float nominalRes = (xRes + yRes) * 0.5f; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5041 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5042 | // Precompute all of the configuration thresholds we will need. |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5043 | mConfigTickDistance = TICK_DISTANCE_MILLIMETERS * nominalRes; |
| 5044 | mConfigMinFlingVelocity = |
| 5045 | MIN_FLING_VELOCITY_TICKS_PER_SECOND * mConfigTickDistance; |
| 5046 | mConfigMaxFlingVelocity = |
| 5047 | MAX_FLING_VELOCITY_TICKS_PER_SECOND * mConfigTickDistance; |
| 5048 | |
| 5049 | if (LOCAL_DEBUG) { |
| 5050 | Log.d(LOCAL_TAG, "Configured device " + mCurrentDeviceId |
| 5051 | + " (" + Integer.toHexString(mCurrentSource) + "): " |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5052 | + ", mConfigTickDistance=" + mConfigTickDistance |
| 5053 | + ", mConfigMinFlingVelocity=" + mConfigMinFlingVelocity |
| 5054 | + ", mConfigMaxFlingVelocity=" + mConfigMaxFlingVelocity); |
| 5055 | } |
| 5056 | } |
| 5057 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5058 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5059 | if (!mCurrentDeviceSupported) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5060 | return; |
| 5061 | } |
| 5062 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5063 | // Handle the event. |
| 5064 | final int action = event.getActionMasked(); |
| 5065 | switch (action) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5066 | case MotionEvent.ACTION_DOWN: { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5067 | boolean caughtFling = mFlinging; |
| 5068 | finishKeys(time); |
| 5069 | finishTracking(time); |
| 5070 | mActivePointerId = event.getPointerId(0); |
| 5071 | mVelocityTracker = VelocityTracker.obtain(); |
| 5072 | mVelocityTracker.addMovement(event); |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5073 | mStartX = event.getX(); |
| 5074 | mStartY = event.getY(); |
| 5075 | mLastX = mStartX; |
| 5076 | mLastY = mStartY; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5077 | mAccumulatedX = 0; |
| 5078 | mAccumulatedY = 0; |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5079 | |
| 5080 | // If we caught a fling, then pretend that the tap slop has already |
| 5081 | // been exceeded to suppress taps whose only purpose is to stop the fling. |
| 5082 | mConsumedMovement = caughtFling; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5083 | break; |
| 5084 | } |
| 5085 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5086 | case MotionEvent.ACTION_MOVE: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5087 | case MotionEvent.ACTION_UP: { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5088 | if (mActivePointerId < 0) { |
| 5089 | break; |
| 5090 | } |
| 5091 | final int index = event.findPointerIndex(mActivePointerId); |
| 5092 | if (index < 0) { |
| 5093 | finishKeys(time); |
| 5094 | finishTracking(time); |
| 5095 | break; |
| 5096 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5097 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5098 | mVelocityTracker.addMovement(event); |
| 5099 | final float x = event.getX(index); |
| 5100 | final float y = event.getY(index); |
| 5101 | mAccumulatedX += x - mLastX; |
| 5102 | mAccumulatedY += y - mLastY; |
| 5103 | mLastX = x; |
| 5104 | mLastY = y; |
| 5105 | |
| 5106 | // Consume any accumulated movement so far. |
| 5107 | final int metaState = event.getMetaState(); |
| 5108 | consumeAccumulatedMovement(time, metaState); |
| 5109 | |
| 5110 | // Detect taps and flings. |
| 5111 | if (action == MotionEvent.ACTION_UP) { |
Michael Wright | 88d7f79 | 2013-08-27 15:45:42 -0700 | [diff] [blame] | 5112 | if (mConsumedMovement && mPendingKeyCode != KeyEvent.KEYCODE_UNKNOWN) { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5113 | // It might be a fling. |
| 5114 | mVelocityTracker.computeCurrentVelocity(1000, mConfigMaxFlingVelocity); |
| 5115 | final float vx = mVelocityTracker.getXVelocity(mActivePointerId); |
| 5116 | final float vy = mVelocityTracker.getYVelocity(mActivePointerId); |
| 5117 | if (!startFling(time, vx, vy)) { |
| 5118 | finishKeys(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5119 | } |
| 5120 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5121 | finishTracking(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5122 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5123 | break; |
| 5124 | } |
| 5125 | |
| 5126 | case MotionEvent.ACTION_CANCEL: { |
| 5127 | finishKeys(time); |
| 5128 | finishTracking(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5129 | break; |
| 5130 | } |
| 5131 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5132 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5133 | |
| 5134 | public void cancel(MotionEvent event) { |
| 5135 | if (mCurrentDeviceId == event.getDeviceId() |
| 5136 | && mCurrentSource == event.getSource()) { |
| 5137 | final long time = event.getEventTime(); |
| 5138 | finishKeys(time); |
| 5139 | finishTracking(time); |
| 5140 | } |
| 5141 | } |
| 5142 | |
| 5143 | private void finishKeys(long time) { |
| 5144 | cancelFling(); |
| 5145 | sendKeyUp(time); |
| 5146 | } |
| 5147 | |
| 5148 | private void finishTracking(long time) { |
| 5149 | if (mActivePointerId >= 0) { |
| 5150 | mActivePointerId = -1; |
| 5151 | mVelocityTracker.recycle(); |
| 5152 | mVelocityTracker = null; |
| 5153 | } |
| 5154 | } |
| 5155 | |
| 5156 | private void consumeAccumulatedMovement(long time, int metaState) { |
| 5157 | final float absX = Math.abs(mAccumulatedX); |
| 5158 | final float absY = Math.abs(mAccumulatedY); |
| 5159 | if (absX >= absY) { |
| 5160 | if (absX >= mConfigTickDistance) { |
| 5161 | mAccumulatedX = consumeAccumulatedMovement(time, metaState, mAccumulatedX, |
| 5162 | KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_RIGHT); |
| 5163 | mAccumulatedY = 0; |
| 5164 | mConsumedMovement = true; |
| 5165 | } |
| 5166 | } else { |
| 5167 | if (absY >= mConfigTickDistance) { |
| 5168 | mAccumulatedY = consumeAccumulatedMovement(time, metaState, mAccumulatedY, |
| 5169 | KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN); |
| 5170 | mAccumulatedX = 0; |
| 5171 | mConsumedMovement = true; |
| 5172 | } |
| 5173 | } |
| 5174 | } |
| 5175 | |
| 5176 | private float consumeAccumulatedMovement(long time, int metaState, |
| 5177 | float accumulator, int negativeKeyCode, int positiveKeyCode) { |
| 5178 | while (accumulator <= -mConfigTickDistance) { |
| 5179 | sendKeyDownOrRepeat(time, negativeKeyCode, metaState); |
| 5180 | accumulator += mConfigTickDistance; |
| 5181 | } |
| 5182 | while (accumulator >= mConfigTickDistance) { |
| 5183 | sendKeyDownOrRepeat(time, positiveKeyCode, metaState); |
| 5184 | accumulator -= mConfigTickDistance; |
| 5185 | } |
| 5186 | return accumulator; |
| 5187 | } |
| 5188 | |
| 5189 | private void sendKeyDownOrRepeat(long time, int keyCode, int metaState) { |
| 5190 | if (mPendingKeyCode != keyCode) { |
| 5191 | sendKeyUp(time); |
| 5192 | mPendingKeyDownTime = time; |
| 5193 | mPendingKeyCode = keyCode; |
| 5194 | mPendingKeyRepeatCount = 0; |
| 5195 | } else { |
| 5196 | mPendingKeyRepeatCount += 1; |
| 5197 | } |
| 5198 | mPendingKeyMetaState = metaState; |
| 5199 | |
| 5200 | // Note: Normally we would pass FLAG_LONG_PRESS when the repeat count is 1 |
| 5201 | // but it doesn't quite make sense when simulating the events in this way. |
| 5202 | if (LOCAL_DEBUG) { |
| 5203 | Log.d(LOCAL_TAG, "Sending key down: keyCode=" + mPendingKeyCode |
| 5204 | + ", repeatCount=" + mPendingKeyRepeatCount |
| 5205 | + ", metaState=" + Integer.toHexString(mPendingKeyMetaState)); |
| 5206 | } |
| 5207 | enqueueInputEvent(new KeyEvent(mPendingKeyDownTime, time, |
| 5208 | KeyEvent.ACTION_DOWN, mPendingKeyCode, mPendingKeyRepeatCount, |
| 5209 | mPendingKeyMetaState, mCurrentDeviceId, |
| 5210 | KeyEvent.FLAG_FALLBACK, mCurrentSource)); |
| 5211 | } |
| 5212 | |
| 5213 | private void sendKeyUp(long time) { |
| 5214 | if (mPendingKeyCode != KeyEvent.KEYCODE_UNKNOWN) { |
| 5215 | if (LOCAL_DEBUG) { |
| 5216 | Log.d(LOCAL_TAG, "Sending key up: keyCode=" + mPendingKeyCode |
| 5217 | + ", metaState=" + Integer.toHexString(mPendingKeyMetaState)); |
| 5218 | } |
| 5219 | enqueueInputEvent(new KeyEvent(mPendingKeyDownTime, time, |
| 5220 | KeyEvent.ACTION_UP, mPendingKeyCode, 0, mPendingKeyMetaState, |
| 5221 | mCurrentDeviceId, 0, KeyEvent.FLAG_FALLBACK, |
| 5222 | mCurrentSource)); |
| 5223 | mPendingKeyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 5224 | } |
| 5225 | } |
| 5226 | |
| 5227 | private boolean startFling(long time, float vx, float vy) { |
| 5228 | if (LOCAL_DEBUG) { |
| 5229 | Log.d(LOCAL_TAG, "Considering fling: vx=" + vx + ", vy=" + vy |
| 5230 | + ", min=" + mConfigMinFlingVelocity); |
| 5231 | } |
| 5232 | |
| 5233 | // Flings must be oriented in the same direction as the preceding movements. |
| 5234 | switch (mPendingKeyCode) { |
| 5235 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 5236 | if (-vx >= mConfigMinFlingVelocity |
| 5237 | && Math.abs(vy) < mConfigMinFlingVelocity) { |
| 5238 | mFlingVelocity = -vx; |
| 5239 | break; |
| 5240 | } |
| 5241 | return false; |
| 5242 | |
| 5243 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 5244 | if (vx >= mConfigMinFlingVelocity |
| 5245 | && Math.abs(vy) < mConfigMinFlingVelocity) { |
| 5246 | mFlingVelocity = vx; |
| 5247 | break; |
| 5248 | } |
| 5249 | return false; |
| 5250 | |
| 5251 | case KeyEvent.KEYCODE_DPAD_UP: |
| 5252 | if (-vy >= mConfigMinFlingVelocity |
| 5253 | && Math.abs(vx) < mConfigMinFlingVelocity) { |
| 5254 | mFlingVelocity = -vy; |
| 5255 | break; |
| 5256 | } |
| 5257 | return false; |
| 5258 | |
| 5259 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 5260 | if (vy >= mConfigMinFlingVelocity |
| 5261 | && Math.abs(vx) < mConfigMinFlingVelocity) { |
| 5262 | mFlingVelocity = vy; |
| 5263 | break; |
| 5264 | } |
| 5265 | return false; |
| 5266 | } |
| 5267 | |
| 5268 | // Post the first fling event. |
| 5269 | mFlinging = postFling(time); |
| 5270 | return mFlinging; |
| 5271 | } |
| 5272 | |
| 5273 | private boolean postFling(long time) { |
| 5274 | // The idea here is to estimate the time when the pointer would have |
| 5275 | // traveled one tick distance unit given the current fling velocity. |
| 5276 | // This effect creates continuity of motion. |
| 5277 | if (mFlingVelocity >= mConfigMinFlingVelocity) { |
| 5278 | long delay = (long)(mConfigTickDistance / mFlingVelocity * 1000); |
| 5279 | postAtTime(mFlingRunnable, time + delay); |
| 5280 | if (LOCAL_DEBUG) { |
| 5281 | Log.d(LOCAL_TAG, "Posted fling: velocity=" |
| 5282 | + mFlingVelocity + ", delay=" + delay |
| 5283 | + ", keyCode=" + mPendingKeyCode); |
| 5284 | } |
| 5285 | return true; |
| 5286 | } |
| 5287 | return false; |
| 5288 | } |
| 5289 | |
| 5290 | private void cancelFling() { |
| 5291 | if (mFlinging) { |
| 5292 | removeCallbacks(mFlingRunnable); |
| 5293 | mFlinging = false; |
| 5294 | } |
| 5295 | } |
| 5296 | |
| 5297 | private final Runnable mFlingRunnable = new Runnable() { |
| 5298 | @Override |
| 5299 | public void run() { |
| 5300 | final long time = SystemClock.uptimeMillis(); |
| 5301 | sendKeyDownOrRepeat(time, mPendingKeyCode, mPendingKeyMetaState); |
| 5302 | mFlingVelocity *= FLING_TICK_DECAY; |
| 5303 | if (!postFling(time)) { |
| 5304 | mFlinging = false; |
| 5305 | finishKeys(time); |
| 5306 | } |
| 5307 | } |
| 5308 | }; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5309 | } |
| 5310 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5311 | final class SyntheticKeyboardHandler { |
| 5312 | public void process(KeyEvent event) { |
| 5313 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) != 0) { |
| 5314 | return; |
| 5315 | } |
| 5316 | |
| 5317 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 5318 | final int keyCode = event.getKeyCode(); |
| 5319 | final int metaState = event.getMetaState(); |
| 5320 | |
| 5321 | // Check for fallback actions specified by the key character map. |
| 5322 | KeyCharacterMap.FallbackAction fallbackAction = |
| 5323 | kcm.getFallbackAction(keyCode, metaState); |
| 5324 | if (fallbackAction != null) { |
| 5325 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 5326 | KeyEvent fallbackEvent = KeyEvent.obtain( |
| 5327 | event.getDownTime(), event.getEventTime(), |
| 5328 | event.getAction(), fallbackAction.keyCode, |
| 5329 | event.getRepeatCount(), fallbackAction.metaState, |
| 5330 | event.getDeviceId(), event.getScanCode(), |
| 5331 | flags, event.getSource(), null); |
| 5332 | fallbackAction.recycle(); |
| 5333 | enqueueInputEvent(fallbackEvent); |
| 5334 | } |
| 5335 | } |
| 5336 | } |
| 5337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5338 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5339 | * Returns true if the key is used for keyboard navigation. |
| 5340 | * @param keyEvent The key event. |
| 5341 | * @return True if the key is used for keyboard navigation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5342 | */ |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5343 | private static boolean isNavigationKey(KeyEvent keyEvent) { |
| 5344 | switch (keyEvent.getKeyCode()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5345 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 5346 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 5347 | case KeyEvent.KEYCODE_DPAD_UP: |
| 5348 | case KeyEvent.KEYCODE_DPAD_DOWN: |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5349 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 5350 | case KeyEvent.KEYCODE_PAGE_UP: |
| 5351 | case KeyEvent.KEYCODE_PAGE_DOWN: |
| 5352 | case KeyEvent.KEYCODE_MOVE_HOME: |
| 5353 | case KeyEvent.KEYCODE_MOVE_END: |
| 5354 | case KeyEvent.KEYCODE_TAB: |
| 5355 | case KeyEvent.KEYCODE_SPACE: |
| 5356 | case KeyEvent.KEYCODE_ENTER: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5357 | return true; |
| 5358 | } |
| 5359 | return false; |
| 5360 | } |
| 5361 | |
| 5362 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5363 | * Returns true if the key is used for typing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5364 | * @param keyEvent The key event. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5365 | * @return True if the key is used for typing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5366 | */ |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5367 | private static boolean isTypingKey(KeyEvent keyEvent) { |
| 5368 | return keyEvent.getUnicodeChar() > 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5369 | } |
| 5370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5371 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5372 | * See if the key event means we should leave touch mode (and leave touch mode if so). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5373 | * @param event The key event. |
| 5374 | * @return Whether this key event should be consumed (meaning the act of |
| 5375 | * leaving touch mode alone is considered the event). |
| 5376 | */ |
| 5377 | private boolean checkForLeavingTouchModeAndConsume(KeyEvent event) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5378 | // Only relevant in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5379 | if (!mAttachInfo.mInTouchMode) { |
| 5380 | return false; |
| 5381 | } |
| 5382 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5383 | // Only consider leaving touch mode on DOWN or MULTIPLE actions, never on UP. |
| 5384 | final int action = event.getAction(); |
| 5385 | if (action != KeyEvent.ACTION_DOWN && action != KeyEvent.ACTION_MULTIPLE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5386 | return false; |
| 5387 | } |
| 5388 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5389 | // Don't leave touch mode if the IME told us not to. |
| 5390 | if ((event.getFlags() & KeyEvent.FLAG_KEEP_TOUCH_MODE) != 0) { |
| 5391 | return false; |
| 5392 | } |
| 5393 | |
| 5394 | // If the key can be used for keyboard navigation then leave touch mode |
| 5395 | // and select a focused view if needed (in ensureTouchMode). |
| 5396 | // When a new focused view is selected, we consume the navigation key because |
| 5397 | // navigation doesn't make much sense unless a view already has focus so |
| 5398 | // the key's purpose is to set focus. |
| 5399 | if (isNavigationKey(event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5400 | return ensureTouchMode(false); |
| 5401 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5402 | |
| 5403 | // If the key can be used for typing then leave touch mode |
| 5404 | // and select a focused view if needed (in ensureTouchMode). |
| 5405 | // Always allow the view to process the typing key. |
| 5406 | if (isTypingKey(event)) { |
| 5407 | ensureTouchMode(false); |
| 5408 | return false; |
| 5409 | } |
| 5410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5411 | return false; |
| 5412 | } |
| 5413 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5414 | /* drag/drop */ |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5415 | void setLocalDragState(Object obj) { |
| 5416 | mLocalDragState = obj; |
| 5417 | } |
| 5418 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5419 | private void handleDragEvent(DragEvent event) { |
| 5420 | // From the root, only drag start/end/location are dispatched. entered/exited |
| 5421 | // are determined and dispatched by the viewgroup hierarchy, who then report |
| 5422 | // that back here for ultimate reporting back to the framework. |
| 5423 | if (mView != null && mAdded) { |
| 5424 | final int what = event.mAction; |
| 5425 | |
| 5426 | if (what == DragEvent.ACTION_DRAG_EXITED) { |
| 5427 | // A direct EXITED event means that the window manager knows we've just crossed |
| 5428 | // a window boundary, so the current drag target within this one must have |
| 5429 | // just been exited. Send it the usual notifications and then we're done |
| 5430 | // for now. |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 5431 | mView.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5432 | } else { |
| 5433 | // Cache the drag description when the operation starts, then fill it in |
| 5434 | // on subsequent calls as a convenience |
| 5435 | if (what == DragEvent.ACTION_DRAG_STARTED) { |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 5436 | mCurrentDragView = null; // Start the current-recipient tracking |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5437 | mDragDescription = event.mClipDescription; |
| 5438 | } else { |
| 5439 | event.mClipDescription = mDragDescription; |
| 5440 | } |
| 5441 | |
| 5442 | // For events with a [screen] location, translate into window coordinates |
| 5443 | if ((what == DragEvent.ACTION_DRAG_LOCATION) || (what == DragEvent.ACTION_DROP)) { |
| 5444 | mDragPoint.set(event.mX, event.mY); |
| 5445 | if (mTranslator != null) { |
| 5446 | mTranslator.translatePointInScreenToAppWindow(mDragPoint); |
| 5447 | } |
| 5448 | |
| 5449 | if (mCurScrollY != 0) { |
| 5450 | mDragPoint.offset(0, mCurScrollY); |
| 5451 | } |
| 5452 | |
| 5453 | event.mX = mDragPoint.x; |
| 5454 | event.mY = mDragPoint.y; |
| 5455 | } |
| 5456 | |
| 5457 | // Remember who the current drag target is pre-dispatch |
| 5458 | final View prevDragView = mCurrentDragView; |
| 5459 | |
| 5460 | // Now dispatch the drag/drop event |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5461 | boolean result = mView.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5462 | |
| 5463 | // If we changed apparent drag target, tell the OS about it |
| 5464 | if (prevDragView != mCurrentDragView) { |
| 5465 | try { |
| 5466 | if (prevDragView != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5467 | mWindowSession.dragRecipientExited(mWindow); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5468 | } |
| 5469 | if (mCurrentDragView != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5470 | mWindowSession.dragRecipientEntered(mWindow); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5471 | } |
| 5472 | } catch (RemoteException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5473 | Slog.e(mTag, "Unable to note drag target change"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5474 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5475 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5476 | |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5477 | // Report the drop result when we're done |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5478 | if (what == DragEvent.ACTION_DROP) { |
Christopher Tate | 1fc014f | 2011-01-19 12:56:26 -0800 | [diff] [blame] | 5479 | mDragDescription = null; |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5480 | try { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5481 | Log.i(mTag, "Reporting drop result: " + result); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5482 | mWindowSession.reportDropResult(mWindow, result); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5483 | } catch (RemoteException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5484 | Log.e(mTag, "Unable to report drop result"); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5485 | } |
| 5486 | } |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5487 | |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 5488 | // When the drag operation ends, reset drag-related state |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5489 | if (what == DragEvent.ACTION_DRAG_ENDED) { |
| 5490 | setLocalDragState(null); |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 5491 | mAttachInfo.mDragToken = null; |
Vladislav Kaznacheev | 4f63974 | 2015-11-18 13:21:35 -0800 | [diff] [blame] | 5492 | if (mAttachInfo.mDragSurface != null) { |
| 5493 | mAttachInfo.mDragSurface.release(); |
| 5494 | mAttachInfo.mDragSurface = null; |
| 5495 | } |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5496 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5497 | } |
| 5498 | } |
| 5499 | event.recycle(); |
| 5500 | } |
| 5501 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5502 | public void handleDispatchSystemUiVisibilityChanged(SystemUiVisibilityInfo args) { |
| 5503 | if (mSeq != args.seq) { |
| 5504 | // The sequence has changed, so we need to update our value and make |
| 5505 | // sure to do a traversal afterward so the window manager is given our |
| 5506 | // most recent data. |
| 5507 | mSeq = args.seq; |
| 5508 | mAttachInfo.mForceReportNewAttributes = true; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5509 | scheduleTraversals(); |
Joe Onorato | 14782f7 | 2011-01-25 19:53:17 -0800 | [diff] [blame] | 5510 | } |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5511 | if (mView == null) return; |
| 5512 | if (args.localChanges != 0) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5513 | mView.updateLocalSystemUiVisibility(args.localValue, args.localChanges); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5514 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 5515 | |
| 5516 | int visibility = args.globalVisibility&View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 5517 | if (visibility != mAttachInfo.mGlobalSystemUiVisibility) { |
| 5518 | mAttachInfo.mGlobalSystemUiVisibility = visibility; |
| 5519 | mView.dispatchSystemUiVisibilityChanged(visibility); |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5520 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5521 | } |
| 5522 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 5523 | public void handleDispatchWindowShown() { |
| 5524 | mAttachInfo.mTreeObserver.dispatchOnWindowShown(); |
| 5525 | } |
| 5526 | |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 5527 | public void handleRequestKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 5528 | Bundle data = new Bundle(); |
| 5529 | ArrayList<KeyboardShortcutGroup> list = new ArrayList<>(); |
| 5530 | if (mView != null) { |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 5531 | mView.requestKeyboardShortcuts(list, deviceId); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 5532 | } |
| 5533 | data.putParcelableArrayList(WindowManager.PARCEL_KEY_SHORTCUTS_ARRAY, list); |
| 5534 | try { |
| 5535 | receiver.send(0, data); |
| 5536 | } catch (RemoteException e) { |
| 5537 | } |
| 5538 | } |
| 5539 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5540 | public void getLastTouchPoint(Point outLocation) { |
| 5541 | outLocation.x = (int) mLastTouchPoint.x; |
| 5542 | outLocation.y = (int) mLastTouchPoint.y; |
| 5543 | } |
| 5544 | |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 5545 | public int getLastTouchSource() { |
| 5546 | return mLastTouchSource; |
| 5547 | } |
| 5548 | |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 5549 | public void setDragFocus(View newDragTarget) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5550 | if (mCurrentDragView != newDragTarget) { |
Chris Tate | 048691c | 2010-10-12 17:39:18 -0700 | [diff] [blame] | 5551 | mCurrentDragView = newDragTarget; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5552 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5553 | } |
| 5554 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5555 | private AudioManager getAudioManager() { |
| 5556 | if (mView == null) { |
| 5557 | throw new IllegalStateException("getAudioManager called when there is no mView"); |
| 5558 | } |
| 5559 | if (mAudioManager == null) { |
| 5560 | mAudioManager = (AudioManager) mView.getContext().getSystemService(Context.AUDIO_SERVICE); |
| 5561 | } |
| 5562 | return mAudioManager; |
| 5563 | } |
| 5564 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5565 | public AccessibilityInteractionController getAccessibilityInteractionController() { |
| 5566 | if (mView == null) { |
| 5567 | throw new IllegalStateException("getAccessibilityInteractionController" |
| 5568 | + " called when there is no mView"); |
| 5569 | } |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 5570 | if (mAccessibilityInteractionController == null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5571 | mAccessibilityInteractionController = new AccessibilityInteractionController(this); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5572 | } |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 5573 | return mAccessibilityInteractionController; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5574 | } |
| 5575 | |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 5576 | private int relayoutWindow(WindowManager.LayoutParams params, int viewVisibility, |
| 5577 | boolean insetsPending) throws RemoteException { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5578 | |
| 5579 | float appScale = mAttachInfo.mApplicationScale; |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5580 | boolean restore = false; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5581 | if (params != null && mTranslator != null) { |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 5582 | restore = true; |
| 5583 | params.backup(); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5584 | mTranslator.translateWindowLayout(params); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5585 | } |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5586 | if (params != null) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5587 | if (DBG) Log.d(mTag, "WindowLayout in layoutWindow:" + params); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5588 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 5589 | mPendingConfiguration.seq = 0; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5590 | //Log.d(mTag, ">>>>>> CALLING relayout"); |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 5591 | if (params != null && mOrigWindowType != params.type) { |
| 5592 | // For compatibility with old apps, don't crash here. |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 5593 | if (mTargetSdkVersion < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5594 | Slog.w(mTag, "Window type can not be changed after " |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 5595 | + "the window is added; ignoring change of " + mView); |
| 5596 | params.type = mOrigWindowType; |
| 5597 | } |
| 5598 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5599 | int relayoutResult = mWindowSession.relayout( |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5600 | mWindow, mSeq, params, |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 5601 | (int) (mView.getMeasuredWidth() * appScale + 0.5f), |
| 5602 | (int) (mView.getMeasuredHeight() * appScale + 0.5f), |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5603 | viewVisibility, insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5604 | mWinFrame, mPendingOverscanInsets, mPendingContentInsets, mPendingVisibleInsets, |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 5605 | mPendingStableInsets, mPendingOutsets, mPendingBackDropFrame, mPendingConfiguration, |
| 5606 | mSurface); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 5607 | |
| 5608 | mPendingAlwaysConsumeNavBar = |
| 5609 | (relayoutResult & WindowManagerGlobal.RELAYOUT_RES_CONSUME_ALWAYS_NAV_BAR) != 0; |
| 5610 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5611 | //Log.d(mTag, "<<<<<< BACK FROM relayout"); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5612 | if (restore) { |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 5613 | params.restore(); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5614 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5615 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5616 | if (mTranslator != null) { |
| 5617 | mTranslator.translateRectInScreenToAppWinFrame(mWinFrame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5618 | mTranslator.translateRectInScreenToAppWindow(mPendingOverscanInsets); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5619 | mTranslator.translateRectInScreenToAppWindow(mPendingContentInsets); |
| 5620 | mTranslator.translateRectInScreenToAppWindow(mPendingVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 5621 | mTranslator.translateRectInScreenToAppWindow(mPendingStableInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5622 | } |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 5623 | return relayoutResult; |
| 5624 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5625 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5626 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5627 | * {@inheritDoc} |
| 5628 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5629 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5630 | public void playSoundEffect(int effectId) { |
| 5631 | checkThread(); |
| 5632 | |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 5633 | try { |
| 5634 | final AudioManager audioManager = getAudioManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5635 | |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 5636 | switch (effectId) { |
| 5637 | case SoundEffectConstants.CLICK: |
| 5638 | audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK); |
| 5639 | return; |
| 5640 | case SoundEffectConstants.NAVIGATION_DOWN: |
| 5641 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_DOWN); |
| 5642 | return; |
| 5643 | case SoundEffectConstants.NAVIGATION_LEFT: |
| 5644 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_LEFT); |
| 5645 | return; |
| 5646 | case SoundEffectConstants.NAVIGATION_RIGHT: |
| 5647 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_RIGHT); |
| 5648 | return; |
| 5649 | case SoundEffectConstants.NAVIGATION_UP: |
| 5650 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_UP); |
| 5651 | return; |
| 5652 | default: |
| 5653 | throw new IllegalArgumentException("unknown effect id " + effectId + |
| 5654 | " not defined in " + SoundEffectConstants.class.getCanonicalName()); |
| 5655 | } |
| 5656 | } catch (IllegalStateException e) { |
| 5657 | // Exception thrown by getAudioManager() when mView is null |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5658 | Log.e(mTag, "FATAL EXCEPTION when attempting to play sound effect: " + e); |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 5659 | e.printStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5660 | } |
| 5661 | } |
| 5662 | |
| 5663 | /** |
| 5664 | * {@inheritDoc} |
| 5665 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5666 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5667 | public boolean performHapticFeedback(int effectId, boolean always) { |
| 5668 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5669 | return mWindowSession.performHapticFeedback(mWindow, effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5670 | } catch (RemoteException e) { |
| 5671 | return false; |
| 5672 | } |
| 5673 | } |
| 5674 | |
| 5675 | /** |
| 5676 | * {@inheritDoc} |
| 5677 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5678 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5679 | public View focusSearch(View focused, int direction) { |
| 5680 | checkThread(); |
| 5681 | if (!(mView instanceof ViewGroup)) { |
| 5682 | return null; |
| 5683 | } |
| 5684 | return FocusFinder.getInstance().findNextFocus((ViewGroup) mView, focused, direction); |
| 5685 | } |
| 5686 | |
| 5687 | public void debug() { |
| 5688 | mView.debug(); |
| 5689 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5690 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5691 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 5692 | String innerPrefix = prefix + " "; |
| 5693 | writer.print(prefix); writer.println("ViewRoot:"); |
| 5694 | writer.print(innerPrefix); writer.print("mAdded="); writer.print(mAdded); |
| 5695 | writer.print(" mRemoved="); writer.println(mRemoved); |
| 5696 | writer.print(innerPrefix); writer.print("mConsumeBatchedInputScheduled="); |
| 5697 | writer.println(mConsumeBatchedInputScheduled); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 5698 | writer.print(innerPrefix); writer.print("mConsumeBatchedInputImmediatelyScheduled="); |
| 5699 | writer.println(mConsumeBatchedInputImmediatelyScheduled); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5700 | writer.print(innerPrefix); writer.print("mPendingInputEventCount="); |
| 5701 | writer.println(mPendingInputEventCount); |
| 5702 | writer.print(innerPrefix); writer.print("mProcessInputEventsScheduled="); |
| 5703 | writer.println(mProcessInputEventsScheduled); |
| 5704 | writer.print(innerPrefix); writer.print("mTraversalScheduled="); |
| 5705 | writer.print(mTraversalScheduled); |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 5706 | writer.print(innerPrefix); writer.print("mIsAmbientMode="); |
| 5707 | writer.print(mIsAmbientMode); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5708 | if (mTraversalScheduled) { |
| 5709 | writer.print(" (barrier="); writer.print(mTraversalBarrier); writer.println(")"); |
| 5710 | } else { |
| 5711 | writer.println(); |
| 5712 | } |
| 5713 | mFirstInputStage.dump(innerPrefix, writer); |
| 5714 | |
| 5715 | mChoreographer.dump(prefix, writer); |
| 5716 | |
| 5717 | writer.print(prefix); writer.println("View Hierarchy:"); |
| 5718 | dumpViewHierarchy(innerPrefix, writer, mView); |
| 5719 | } |
| 5720 | |
| 5721 | private void dumpViewHierarchy(String prefix, PrintWriter writer, View view) { |
| 5722 | writer.print(prefix); |
| 5723 | if (view == null) { |
| 5724 | writer.println("null"); |
| 5725 | return; |
| 5726 | } |
| 5727 | writer.println(view.toString()); |
| 5728 | if (!(view instanceof ViewGroup)) { |
| 5729 | return; |
| 5730 | } |
| 5731 | ViewGroup grp = (ViewGroup)view; |
| 5732 | final int N = grp.getChildCount(); |
| 5733 | if (N <= 0) { |
| 5734 | return; |
| 5735 | } |
| 5736 | prefix = prefix + " "; |
| 5737 | for (int i=0; i<N; i++) { |
| 5738 | dumpViewHierarchy(prefix, writer, grp.getChildAt(i)); |
| 5739 | } |
| 5740 | } |
| 5741 | |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 5742 | public void dumpGfxInfo(int[] info) { |
Romain Guy | 54ab347 | 2012-06-14 12:52:53 -0700 | [diff] [blame] | 5743 | info[0] = info[1] = 0; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5744 | if (mView != null) { |
| 5745 | getGfxInfo(mView, info); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5746 | } |
| 5747 | } |
| 5748 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5749 | private static void getGfxInfo(View view, int[] info) { |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 5750 | RenderNode renderNode = view.mRenderNode; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5751 | info[0]++; |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 5752 | if (renderNode != null) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 5753 | info[1] += renderNode.getDebugSize(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5754 | } |
| 5755 | |
| 5756 | if (view instanceof ViewGroup) { |
| 5757 | ViewGroup group = (ViewGroup) view; |
| 5758 | |
| 5759 | int count = group.getChildCount(); |
| 5760 | for (int i = 0; i < count; i++) { |
| 5761 | getGfxInfo(group.getChildAt(i), info); |
| 5762 | } |
| 5763 | } |
| 5764 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5765 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5766 | /** |
| 5767 | * @param immediate True, do now if not in traversal. False, put on queue and do later. |
| 5768 | * @return True, request has been queued. False, request has been completed. |
| 5769 | */ |
| 5770 | boolean die(boolean immediate) { |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 5771 | // Make sure we do execute immediately if we are in the middle of a traversal or the damage |
| 5772 | // done by dispatchDetachedFromWindow will cause havoc on return. |
| 5773 | if (immediate && !mIsInTraversal) { |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 5774 | doDie(); |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5775 | return false; |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 5776 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5777 | |
| 5778 | if (!mIsDrawing) { |
| 5779 | destroyHardwareRenderer(); |
| 5780 | } else { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5781 | Log.e(mTag, "Attempting to destroy the window while drawing!\n" + |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5782 | " window=" + this + ", title=" + mWindowAttributes.getTitle()); |
| 5783 | } |
| 5784 | mHandler.sendEmptyMessage(MSG_DIE); |
| 5785 | return true; |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 5786 | } |
| 5787 | |
| 5788 | void doDie() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5789 | checkThread(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5790 | if (LOCAL_LOGV) Log.v(mTag, "DIE in " + this + " of " + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | synchronized (this) { |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5792 | if (mRemoved) { |
| 5793 | return; |
| 5794 | } |
| 5795 | mRemoved = true; |
Romain Guy | 16260e7 | 2011-09-01 14:26:11 -0700 | [diff] [blame] | 5796 | if (mAdded) { |
Romain Guy | 16260e7 | 2011-09-01 14:26:11 -0700 | [diff] [blame] | 5797 | dispatchDetachedFromWindow(); |
| 5798 | } |
| 5799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5800 | if (mAdded && !mFirst) { |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 5801 | destroyHardwareRenderer(); |
| 5802 | |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5803 | if (mView != null) { |
| 5804 | int viewVisibility = mView.getVisibility(); |
| 5805 | boolean viewVisibilityChanged = mViewVisibility != viewVisibility; |
| 5806 | if (mWindowAttributesChanged || viewVisibilityChanged) { |
| 5807 | // If layout params have been changed, first give them |
| 5808 | // to the window manager to make sure it has the correct |
| 5809 | // animation info. |
| 5810 | try { |
| 5811 | if ((relayoutWindow(mWindowAttributes, viewVisibility, false) |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5812 | & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { |
| 5813 | mWindowSession.finishDrawing(mWindow); |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5814 | } |
| 5815 | } catch (RemoteException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5816 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5817 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5818 | |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5819 | mSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5820 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5821 | } |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5822 | |
| 5823 | mAdded = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5824 | } |
Craig Mautner | 05eb730 | 2013-06-03 17:24:21 -0700 | [diff] [blame] | 5825 | WindowManagerGlobal.getInstance().doRemoveView(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5826 | } |
| 5827 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5828 | public void requestUpdateConfiguration(Configuration config) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 5829 | Message msg = mHandler.obtainMessage(MSG_UPDATE_CONFIGURATION, config); |
| 5830 | mHandler.sendMessage(msg); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5831 | } |
| 5832 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 5833 | public void loadSystemProperties() { |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 5834 | mHandler.post(new Runnable() { |
| 5835 | @Override |
| 5836 | public void run() { |
| 5837 | // Profiling |
| 5838 | mProfileRendering = SystemProperties.getBoolean(PROPERTY_PROFILE_RENDERING, false); |
| 5839 | profileRendering(mAttachInfo.mHasWindowFocus); |
| 5840 | |
| 5841 | // Hardware rendering |
| 5842 | if (mAttachInfo.mHardwareRenderer != null) { |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 5843 | if (mAttachInfo.mHardwareRenderer.loadSystemProperties()) { |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 5844 | invalidate(); |
| 5845 | } |
| 5846 | } |
| 5847 | |
| 5848 | // Layout debugging |
| 5849 | boolean layout = SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false); |
| 5850 | if (layout != mAttachInfo.mDebugLayout) { |
| 5851 | mAttachInfo.mDebugLayout = layout; |
| 5852 | if (!mHandler.hasMessages(MSG_INVALIDATE_WORLD)) { |
| 5853 | mHandler.sendEmptyMessageDelayed(MSG_INVALIDATE_WORLD, 200); |
| 5854 | } |
| 5855 | } |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 5856 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 5857 | }); |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 5858 | } |
| 5859 | |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 5860 | private void destroyHardwareRenderer() { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5861 | ThreadedRenderer hardwareRenderer = mAttachInfo.mHardwareRenderer; |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5862 | |
| 5863 | if (hardwareRenderer != null) { |
| 5864 | if (mView != null) { |
| 5865 | hardwareRenderer.destroyHardwareResources(mView); |
| 5866 | } |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 5867 | hardwareRenderer.destroy(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5868 | hardwareRenderer.setRequested(false); |
| 5869 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 5870 | mAttachInfo.mHardwareRenderer = null; |
| 5871 | mAttachInfo.mHardwareAccelerated = false; |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 5872 | } |
| 5873 | } |
| 5874 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5875 | public void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5876 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 5877 | Configuration newConfig, Rect backDropFrame, boolean forceLayout, |
| 5878 | boolean alwaysConsumeNavBar) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5879 | if (DEBUG_LAYOUT) Log.v(mTag, "Resizing " + this + ": frame=" + frame.toShortString() |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5880 | + " contentInsets=" + contentInsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5881 | + " visibleInsets=" + visibleInsets.toShortString() |
Chong Zhang | d153c4f | 2015-11-06 20:26:40 -0800 | [diff] [blame] | 5882 | + " reportDraw=" + reportDraw |
| 5883 | + " backDropFrame=" + backDropFrame); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 5884 | |
| 5885 | // Tell all listeners that we are resizing the window so that the chrome can get |
| 5886 | // updated as fast as possible on a separate thread, |
| 5887 | if (mDragResizing) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 5888 | boolean fullscreen = frame.equals(backDropFrame); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 5889 | synchronized (mWindowCallbacks) { |
| 5890 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 5891 | mWindowCallbacks.get(i).onWindowSizeIsChanging(backDropFrame, fullscreen, |
| 5892 | visibleInsets, stableInsets); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 5893 | } |
| 5894 | } |
| 5895 | } |
| 5896 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5897 | Message msg = mHandler.obtainMessage(reportDraw ? MSG_RESIZED_REPORT : MSG_RESIZED); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5898 | if (mTranslator != null) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5899 | mTranslator.translateRectInScreenToAppWindow(frame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5900 | mTranslator.translateRectInScreenToAppWindow(overscanInsets); |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 5901 | mTranslator.translateRectInScreenToAppWindow(contentInsets); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5902 | mTranslator.translateRectInScreenToAppWindow(visibleInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5903 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5904 | SomeArgs args = SomeArgs.obtain(); |
| 5905 | final boolean sameProcessCall = (Binder.getCallingPid() == android.os.Process.myPid()); |
| 5906 | args.arg1 = sameProcessCall ? new Rect(frame) : frame; |
| 5907 | args.arg2 = sameProcessCall ? new Rect(contentInsets) : contentInsets; |
| 5908 | args.arg3 = sameProcessCall ? new Rect(visibleInsets) : visibleInsets; |
| 5909 | args.arg4 = sameProcessCall && newConfig != null ? new Configuration(newConfig) : newConfig; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5910 | args.arg5 = sameProcessCall ? new Rect(overscanInsets) : overscanInsets; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 5911 | args.arg6 = sameProcessCall ? new Rect(stableInsets) : stableInsets; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5912 | args.arg7 = sameProcessCall ? new Rect(outsets) : outsets; |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 5913 | args.arg8 = sameProcessCall ? new Rect(backDropFrame) : backDropFrame; |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 5914 | args.argi1 = forceLayout ? 1 : 0; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 5915 | args.argi2 = alwaysConsumeNavBar ? 1 : 0; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5916 | msg.obj = args; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 5917 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5918 | } |
Chet Haase | 1f4786b | 2011-11-02 10:51:52 -0700 | [diff] [blame] | 5919 | |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 5920 | public void dispatchMoved(int newX, int newY) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5921 | if (DEBUG_LAYOUT) Log.v(mTag, "Window moved " + this + ": newX=" + newX + " newY=" + newY); |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 5922 | if (mTranslator != null) { |
| 5923 | PointF point = new PointF(newX, newY); |
| 5924 | mTranslator.translatePointInScreenToAppWindow(point); |
| 5925 | newX = (int) (point.x + 0.5); |
| 5926 | newY = (int) (point.y + 0.5); |
| 5927 | } |
| 5928 | Message msg = mHandler.obtainMessage(MSG_WINDOW_MOVED, newX, newY); |
| 5929 | mHandler.sendMessage(msg); |
| 5930 | } |
| 5931 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5932 | /** |
| 5933 | * Represents a pending input event that is waiting in a queue. |
| 5934 | * |
| 5935 | * Input events are processed in serial order by the timestamp specified by |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 5936 | * {@link InputEvent#getEventTimeNano()}. In general, the input dispatcher delivers |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5937 | * one input event to the application at a time and waits for the application |
| 5938 | * to finish handling it before delivering the next one. |
| 5939 | * |
| 5940 | * However, because the application or IME can synthesize and inject multiple |
| 5941 | * key events at a time without going through the input dispatcher, we end up |
| 5942 | * needing a queue on the application's side. |
| 5943 | */ |
| 5944 | private static final class QueuedInputEvent { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5945 | public static final int FLAG_DELIVER_POST_IME = 1 << 0; |
| 5946 | public static final int FLAG_DEFERRED = 1 << 1; |
| 5947 | public static final int FLAG_FINISHED = 1 << 2; |
| 5948 | public static final int FLAG_FINISHED_HANDLED = 1 << 3; |
| 5949 | public static final int FLAG_RESYNTHESIZED = 1 << 4; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5950 | public static final int FLAG_UNHANDLED = 1 << 5; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5951 | |
| 5952 | public QueuedInputEvent mNext; |
| 5953 | |
| 5954 | public InputEvent mEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 5955 | public InputEventReceiver mReceiver; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5956 | public int mFlags; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5957 | |
| 5958 | public boolean shouldSkipIme() { |
| 5959 | if ((mFlags & FLAG_DELIVER_POST_IME) != 0) { |
| 5960 | return true; |
| 5961 | } |
| 5962 | return mEvent instanceof MotionEvent |
| 5963 | && mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER); |
| 5964 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5965 | |
| 5966 | public boolean shouldSendToSynthesizer() { |
| 5967 | if ((mFlags & FLAG_UNHANDLED) != 0) { |
| 5968 | return true; |
| 5969 | } |
| 5970 | |
| 5971 | return false; |
| 5972 | } |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 5973 | |
| 5974 | @Override |
| 5975 | public String toString() { |
| 5976 | StringBuilder sb = new StringBuilder("QueuedInputEvent{flags="); |
| 5977 | boolean hasPrevious = false; |
| 5978 | hasPrevious = flagToString("DELIVER_POST_IME", FLAG_DELIVER_POST_IME, hasPrevious, sb); |
| 5979 | hasPrevious = flagToString("DEFERRED", FLAG_DEFERRED, hasPrevious, sb); |
| 5980 | hasPrevious = flagToString("FINISHED", FLAG_FINISHED, hasPrevious, sb); |
| 5981 | hasPrevious = flagToString("FINISHED_HANDLED", FLAG_FINISHED_HANDLED, hasPrevious, sb); |
| 5982 | hasPrevious = flagToString("RESYNTHESIZED", FLAG_RESYNTHESIZED, hasPrevious, sb); |
| 5983 | hasPrevious = flagToString("UNHANDLED", FLAG_UNHANDLED, hasPrevious, sb); |
| 5984 | if (!hasPrevious) { |
| 5985 | sb.append("0"); |
| 5986 | } |
| 5987 | sb.append(", hasNextQueuedEvent=" + (mEvent != null ? "true" : "false")); |
| 5988 | sb.append(", hasInputEventReceiver=" + (mReceiver != null ? "true" : "false")); |
| 5989 | sb.append(", mEvent=" + mEvent + "}"); |
| 5990 | return sb.toString(); |
| 5991 | } |
| 5992 | |
| 5993 | private boolean flagToString(String name, int flag, |
| 5994 | boolean hasPrevious, StringBuilder sb) { |
| 5995 | if ((mFlags & flag) != 0) { |
| 5996 | if (hasPrevious) { |
| 5997 | sb.append("|"); |
| 5998 | } |
| 5999 | sb.append(name); |
| 6000 | return true; |
| 6001 | } |
| 6002 | return hasPrevious; |
| 6003 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6004 | } |
| 6005 | |
| 6006 | private QueuedInputEvent obtainQueuedInputEvent(InputEvent event, |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6007 | InputEventReceiver receiver, int flags) { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6008 | QueuedInputEvent q = mQueuedInputEventPool; |
| 6009 | if (q != null) { |
| 6010 | mQueuedInputEventPoolSize -= 1; |
| 6011 | mQueuedInputEventPool = q.mNext; |
| 6012 | q.mNext = null; |
| 6013 | } else { |
| 6014 | q = new QueuedInputEvent(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6015 | } |
| 6016 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6017 | q.mEvent = event; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6018 | q.mReceiver = receiver; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6019 | q.mFlags = flags; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6020 | return q; |
| 6021 | } |
| 6022 | |
| 6023 | private void recycleQueuedInputEvent(QueuedInputEvent q) { |
| 6024 | q.mEvent = null; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6025 | q.mReceiver = null; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6026 | |
| 6027 | if (mQueuedInputEventPoolSize < MAX_QUEUED_INPUT_EVENT_POOL_SIZE) { |
| 6028 | mQueuedInputEventPoolSize += 1; |
| 6029 | q.mNext = mQueuedInputEventPool; |
| 6030 | mQueuedInputEventPool = q; |
| 6031 | } |
| 6032 | } |
| 6033 | |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6034 | void enqueueInputEvent(InputEvent event) { |
| 6035 | enqueueInputEvent(event, null, 0, false); |
| 6036 | } |
| 6037 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6038 | void enqueueInputEvent(InputEvent event, |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6039 | InputEventReceiver receiver, int flags, boolean processImmediately) { |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6040 | adjustInputEventForCompatibility(event); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6041 | QueuedInputEvent q = obtainQueuedInputEvent(event, receiver, flags); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6042 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6043 | // Always enqueue the input event in order, regardless of its time stamp. |
| 6044 | // We do this because the application or the IME may inject key events |
| 6045 | // in response to touch events and we want to ensure that the injected keys |
| 6046 | // are processed in the order they were received and we cannot trust that |
| 6047 | // the time stamp of injected events are monotonic. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6048 | QueuedInputEvent last = mPendingInputEventTail; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6049 | if (last == null) { |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6050 | mPendingInputEventHead = q; |
| 6051 | mPendingInputEventTail = q; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6052 | } else { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6053 | last.mNext = q; |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6054 | mPendingInputEventTail = q; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6055 | } |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 6056 | mPendingInputEventCount += 1; |
| 6057 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mPendingInputEventQueueLengthCounterName, |
| 6058 | mPendingInputEventCount); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6059 | |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6060 | if (processImmediately) { |
| 6061 | doProcessInputEvents(); |
| 6062 | } else { |
| 6063 | scheduleProcessInputEvents(); |
| 6064 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6065 | } |
| 6066 | |
| 6067 | private void scheduleProcessInputEvents() { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 6068 | if (!mProcessInputEventsScheduled) { |
| 6069 | mProcessInputEventsScheduled = true; |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6070 | Message msg = mHandler.obtainMessage(MSG_PROCESS_INPUT_EVENTS); |
| 6071 | msg.setAsynchronous(true); |
| 6072 | mHandler.sendMessage(msg); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6073 | } |
| 6074 | } |
| 6075 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6076 | void doProcessInputEvents() { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6077 | // Deliver all pending input events in the queue. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6078 | while (mPendingInputEventHead != null) { |
| 6079 | QueuedInputEvent q = mPendingInputEventHead; |
| 6080 | mPendingInputEventHead = q.mNext; |
| 6081 | if (mPendingInputEventHead == null) { |
| 6082 | mPendingInputEventTail = null; |
| 6083 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6084 | q.mNext = null; |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6085 | |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 6086 | mPendingInputEventCount -= 1; |
| 6087 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mPendingInputEventQueueLengthCounterName, |
| 6088 | mPendingInputEventCount); |
| 6089 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 6090 | long eventTime = q.mEvent.getEventTimeNano(); |
| 6091 | long oldestEventTime = eventTime; |
| 6092 | if (q.mEvent instanceof MotionEvent) { |
| 6093 | MotionEvent me = (MotionEvent)q.mEvent; |
| 6094 | if (me.getHistorySize() > 0) { |
| 6095 | oldestEventTime = me.getHistoricalEventTimeNano(0); |
| 6096 | } |
| 6097 | } |
| 6098 | mChoreographer.mFrameInfo.updateInputEventTime(eventTime, oldestEventTime); |
| 6099 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6100 | deliverInputEvent(q); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | // We are done processing all input events that we can process right now |
| 6104 | // so we can clear the pending flag immediately. |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 6105 | if (mProcessInputEventsScheduled) { |
| 6106 | mProcessInputEventsScheduled = false; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6107 | mHandler.removeMessages(MSG_PROCESS_INPUT_EVENTS); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6108 | } |
| 6109 | } |
| 6110 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6111 | private void deliverInputEvent(QueuedInputEvent q) { |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6112 | Trace.asyncTraceBegin(Trace.TRACE_TAG_VIEW, "deliverInputEvent", |
| 6113 | q.mEvent.getSequenceNumber()); |
| 6114 | if (mInputEventConsistencyVerifier != null) { |
| 6115 | mInputEventConsistencyVerifier.onInputEvent(q.mEvent, 0); |
| 6116 | } |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6117 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6118 | InputStage stage; |
| 6119 | if (q.shouldSendToSynthesizer()) { |
| 6120 | stage = mSyntheticInputStage; |
| 6121 | } else { |
| 6122 | stage = q.shouldSkipIme() ? mFirstPostImeInputStage : mFirstInputStage; |
| 6123 | } |
| 6124 | |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6125 | if (stage != null) { |
| 6126 | stage.deliver(q); |
| 6127 | } else { |
| 6128 | finishInputEvent(q); |
Michael Wright | bf02096 | 2013-03-28 17:27:50 -0700 | [diff] [blame] | 6129 | } |
Michael Wright | bf02096 | 2013-03-28 17:27:50 -0700 | [diff] [blame] | 6130 | } |
| 6131 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6132 | private void finishInputEvent(QueuedInputEvent q) { |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6133 | Trace.asyncTraceEnd(Trace.TRACE_TAG_VIEW, "deliverInputEvent", |
| 6134 | q.mEvent.getSequenceNumber()); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6135 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6136 | if (q.mReceiver != null) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6137 | boolean handled = (q.mFlags & QueuedInputEvent.FLAG_FINISHED_HANDLED) != 0; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6138 | q.mReceiver.finishInputEvent(q.mEvent, handled); |
Jeff Brown | 92cc2d8 | 2011-12-02 01:19:47 -0800 | [diff] [blame] | 6139 | } else { |
| 6140 | q.mEvent.recycleIfNeededAfterDispatch(); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6141 | } |
| 6142 | |
| 6143 | recycleQueuedInputEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6144 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6145 | |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6146 | private void adjustInputEventForCompatibility(InputEvent e) { |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6147 | if (mTargetSdkVersion < Build.VERSION_CODES.M && e instanceof MotionEvent) { |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6148 | MotionEvent motion = (MotionEvent) e; |
| 6149 | final int mask = |
| 6150 | MotionEvent.BUTTON_STYLUS_PRIMARY | MotionEvent.BUTTON_STYLUS_SECONDARY; |
| 6151 | final int buttonState = motion.getButtonState(); |
| 6152 | final int compatButtonState = (buttonState & mask) >> 4; |
| 6153 | if (compatButtonState != 0) { |
| 6154 | motion.setButtonState(buttonState | compatButtonState); |
| 6155 | } |
| 6156 | } |
| 6157 | } |
| 6158 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6159 | static boolean isTerminalInputEvent(InputEvent event) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6160 | if (event instanceof KeyEvent) { |
| 6161 | final KeyEvent keyEvent = (KeyEvent)event; |
| 6162 | return keyEvent.getAction() == KeyEvent.ACTION_UP; |
| 6163 | } else { |
| 6164 | final MotionEvent motionEvent = (MotionEvent)event; |
| 6165 | final int action = motionEvent.getAction(); |
| 6166 | return action == MotionEvent.ACTION_UP |
| 6167 | || action == MotionEvent.ACTION_CANCEL |
| 6168 | || action == MotionEvent.ACTION_HOVER_EXIT; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6169 | } |
| 6170 | } |
| 6171 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6172 | void scheduleConsumeBatchedInput() { |
| 6173 | if (!mConsumeBatchedInputScheduled) { |
| 6174 | mConsumeBatchedInputScheduled = true; |
| 6175 | mChoreographer.postCallback(Choreographer.CALLBACK_INPUT, |
| 6176 | mConsumedBatchedInputRunnable, null); |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 6177 | } |
| 6178 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6179 | |
| 6180 | void unscheduleConsumeBatchedInput() { |
| 6181 | if (mConsumeBatchedInputScheduled) { |
| 6182 | mConsumeBatchedInputScheduled = false; |
| 6183 | mChoreographer.removeCallbacks(Choreographer.CALLBACK_INPUT, |
| 6184 | mConsumedBatchedInputRunnable, null); |
| 6185 | } |
| 6186 | } |
| 6187 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6188 | void scheduleConsumeBatchedInputImmediately() { |
| 6189 | if (!mConsumeBatchedInputImmediatelyScheduled) { |
| 6190 | unscheduleConsumeBatchedInput(); |
| 6191 | mConsumeBatchedInputImmediatelyScheduled = true; |
| 6192 | mHandler.post(mConsumeBatchedInputImmediatelyRunnable); |
| 6193 | } |
| 6194 | } |
| 6195 | |
Jeff Brown | 771526c | 2012-04-27 15:13:25 -0700 | [diff] [blame] | 6196 | void doConsumeBatchedInput(long frameTimeNanos) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6197 | if (mConsumeBatchedInputScheduled) { |
| 6198 | mConsumeBatchedInputScheduled = false; |
Jeff Brown | 330314c | 2012-04-27 02:20:22 -0700 | [diff] [blame] | 6199 | if (mInputEventReceiver != null) { |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6200 | if (mInputEventReceiver.consumeBatchedInputEvents(frameTimeNanos) |
| 6201 | && frameTimeNanos != -1) { |
Michael Wright | 62ce65d | 2013-10-25 14:50:36 -0700 | [diff] [blame] | 6202 | // If we consumed a batch here, we want to go ahead and schedule the |
| 6203 | // consumption of batched input events on the next frame. Otherwise, we would |
| 6204 | // wait until we have more input events pending and might get starved by other |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6205 | // things occurring in the process. If the frame time is -1, however, then |
| 6206 | // we're in a non-batching mode, so there's no need to schedule this. |
Michael Wright | 62ce65d | 2013-10-25 14:50:36 -0700 | [diff] [blame] | 6207 | scheduleConsumeBatchedInput(); |
| 6208 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6209 | } |
Jeff Brown | 330314c | 2012-04-27 02:20:22 -0700 | [diff] [blame] | 6210 | doProcessInputEvents(); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6211 | } |
| 6212 | } |
| 6213 | |
| 6214 | final class TraversalRunnable implements Runnable { |
| 6215 | @Override |
| 6216 | public void run() { |
| 6217 | doTraversal(); |
| 6218 | } |
| 6219 | } |
| 6220 | final TraversalRunnable mTraversalRunnable = new TraversalRunnable(); |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 6221 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6222 | final class WindowInputEventReceiver extends InputEventReceiver { |
| 6223 | public WindowInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 6224 | super(inputChannel, looper); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6225 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6226 | |
| 6227 | @Override |
| 6228 | public void onInputEvent(InputEvent event) { |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6229 | enqueueInputEvent(event, this, 0, true); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6230 | } |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 6231 | |
| 6232 | @Override |
| 6233 | public void onBatchedInputEventPending() { |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6234 | if (mUnbufferedInputDispatch) { |
| 6235 | super.onBatchedInputEventPending(); |
| 6236 | } else { |
| 6237 | scheduleConsumeBatchedInput(); |
| 6238 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6239 | } |
| 6240 | |
| 6241 | @Override |
| 6242 | public void dispose() { |
| 6243 | unscheduleConsumeBatchedInput(); |
| 6244 | super.dispose(); |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 6245 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6246 | } |
| 6247 | WindowInputEventReceiver mInputEventReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6248 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6249 | final class ConsumeBatchedInputRunnable implements Runnable { |
| 6250 | @Override |
| 6251 | public void run() { |
Jeff Brown | 771526c | 2012-04-27 15:13:25 -0700 | [diff] [blame] | 6252 | doConsumeBatchedInput(mChoreographer.getFrameTimeNanos()); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6253 | } |
| 6254 | } |
| 6255 | final ConsumeBatchedInputRunnable mConsumedBatchedInputRunnable = |
| 6256 | new ConsumeBatchedInputRunnable(); |
| 6257 | boolean mConsumeBatchedInputScheduled; |
| 6258 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6259 | final class ConsumeBatchedInputImmediatelyRunnable implements Runnable { |
| 6260 | @Override |
| 6261 | public void run() { |
| 6262 | doConsumeBatchedInput(-1); |
| 6263 | } |
| 6264 | } |
| 6265 | final ConsumeBatchedInputImmediatelyRunnable mConsumeBatchedInputImmediatelyRunnable = |
| 6266 | new ConsumeBatchedInputImmediatelyRunnable(); |
| 6267 | boolean mConsumeBatchedInputImmediatelyScheduled; |
| 6268 | |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6269 | final class InvalidateOnAnimationRunnable implements Runnable { |
| 6270 | private boolean mPosted; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6271 | private final ArrayList<View> mViews = new ArrayList<View>(); |
| 6272 | private final ArrayList<AttachInfo.InvalidateInfo> mViewRects = |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6273 | new ArrayList<AttachInfo.InvalidateInfo>(); |
| 6274 | private View[] mTempViews; |
| 6275 | private AttachInfo.InvalidateInfo[] mTempViewRects; |
| 6276 | |
| 6277 | public void addView(View view) { |
| 6278 | synchronized (this) { |
| 6279 | mViews.add(view); |
| 6280 | postIfNeededLocked(); |
| 6281 | } |
| 6282 | } |
| 6283 | |
| 6284 | public void addViewRect(AttachInfo.InvalidateInfo info) { |
| 6285 | synchronized (this) { |
| 6286 | mViewRects.add(info); |
| 6287 | postIfNeededLocked(); |
| 6288 | } |
| 6289 | } |
| 6290 | |
| 6291 | public void removeView(View view) { |
| 6292 | synchronized (this) { |
| 6293 | mViews.remove(view); |
| 6294 | |
| 6295 | for (int i = mViewRects.size(); i-- > 0; ) { |
| 6296 | AttachInfo.InvalidateInfo info = mViewRects.get(i); |
| 6297 | if (info.target == view) { |
| 6298 | mViewRects.remove(i); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 6299 | info.recycle(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6300 | } |
| 6301 | } |
| 6302 | |
| 6303 | if (mPosted && mViews.isEmpty() && mViewRects.isEmpty()) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6304 | mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, this, null); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6305 | mPosted = false; |
| 6306 | } |
| 6307 | } |
| 6308 | } |
| 6309 | |
| 6310 | @Override |
| 6311 | public void run() { |
| 6312 | final int viewCount; |
| 6313 | final int viewRectCount; |
| 6314 | synchronized (this) { |
| 6315 | mPosted = false; |
| 6316 | |
| 6317 | viewCount = mViews.size(); |
| 6318 | if (viewCount != 0) { |
| 6319 | mTempViews = mViews.toArray(mTempViews != null |
| 6320 | ? mTempViews : new View[viewCount]); |
| 6321 | mViews.clear(); |
| 6322 | } |
| 6323 | |
| 6324 | viewRectCount = mViewRects.size(); |
| 6325 | if (viewRectCount != 0) { |
| 6326 | mTempViewRects = mViewRects.toArray(mTempViewRects != null |
| 6327 | ? mTempViewRects : new AttachInfo.InvalidateInfo[viewRectCount]); |
| 6328 | mViewRects.clear(); |
| 6329 | } |
| 6330 | } |
| 6331 | |
| 6332 | for (int i = 0; i < viewCount; i++) { |
| 6333 | mTempViews[i].invalidate(); |
Adam Powell | 3e3c4ee | 2012-05-16 17:34:21 -0700 | [diff] [blame] | 6334 | mTempViews[i] = null; |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6335 | } |
| 6336 | |
| 6337 | for (int i = 0; i < viewRectCount; i++) { |
| 6338 | final View.AttachInfo.InvalidateInfo info = mTempViewRects[i]; |
| 6339 | info.target.invalidate(info.left, info.top, info.right, info.bottom); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 6340 | info.recycle(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6341 | } |
| 6342 | } |
| 6343 | |
| 6344 | private void postIfNeededLocked() { |
| 6345 | if (!mPosted) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6346 | mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, this, null); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6347 | mPosted = true; |
| 6348 | } |
| 6349 | } |
| 6350 | } |
| 6351 | final InvalidateOnAnimationRunnable mInvalidateOnAnimationRunnable = |
| 6352 | new InvalidateOnAnimationRunnable(); |
| 6353 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6354 | public void dispatchInvalidateDelayed(View view, long delayMilliseconds) { |
| 6355 | Message msg = mHandler.obtainMessage(MSG_INVALIDATE, view); |
| 6356 | mHandler.sendMessageDelayed(msg, delayMilliseconds); |
| 6357 | } |
| 6358 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6359 | public void dispatchInvalidateRectDelayed(AttachInfo.InvalidateInfo info, |
| 6360 | long delayMilliseconds) { |
| 6361 | final Message msg = mHandler.obtainMessage(MSG_INVALIDATE_RECT, info); |
| 6362 | mHandler.sendMessageDelayed(msg, delayMilliseconds); |
| 6363 | } |
| 6364 | |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6365 | public void dispatchInvalidateOnAnimation(View view) { |
| 6366 | mInvalidateOnAnimationRunnable.addView(view); |
| 6367 | } |
| 6368 | |
| 6369 | public void dispatchInvalidateRectOnAnimation(AttachInfo.InvalidateInfo info) { |
| 6370 | mInvalidateOnAnimationRunnable.addViewRect(info); |
| 6371 | } |
| 6372 | |
| 6373 | public void cancelInvalidate(View view) { |
| 6374 | mHandler.removeMessages(MSG_INVALIDATE, view); |
| 6375 | // fixme: might leak the AttachInfo.InvalidateInfo objects instead of returning |
| 6376 | // them to the pool |
| 6377 | mHandler.removeMessages(MSG_INVALIDATE_RECT, view); |
| 6378 | mInvalidateOnAnimationRunnable.removeView(view); |
| 6379 | } |
| 6380 | |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 6381 | public void dispatchInputEvent(InputEvent event) { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 6382 | dispatchInputEvent(event, null); |
| 6383 | } |
| 6384 | |
| 6385 | public void dispatchInputEvent(InputEvent event, InputEventReceiver receiver) { |
| 6386 | SomeArgs args = SomeArgs.obtain(); |
| 6387 | args.arg1 = event; |
| 6388 | args.arg2 = receiver; |
| 6389 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_INPUT_EVENT, args); |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 6390 | msg.setAsynchronous(true); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6391 | mHandler.sendMessage(msg); |
| 6392 | } |
| 6393 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6394 | public void synthesizeInputEvent(InputEvent event) { |
| 6395 | Message msg = mHandler.obtainMessage(MSG_SYNTHESIZE_INPUT_EVENT, event); |
| 6396 | msg.setAsynchronous(true); |
| 6397 | mHandler.sendMessage(msg); |
| 6398 | } |
| 6399 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6400 | public void dispatchKeyFromIme(KeyEvent event) { |
| 6401 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_KEY_FROM_IME, event); |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 6402 | msg.setAsynchronous(true); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6403 | mHandler.sendMessage(msg); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6404 | } |
| 6405 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6406 | /** |
| 6407 | * Reinject unhandled {@link InputEvent}s in order to synthesize fallbacks events. |
| 6408 | * |
| 6409 | * Note that it is the responsibility of the caller of this API to recycle the InputEvent it |
| 6410 | * passes in. |
| 6411 | */ |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6412 | public void dispatchUnhandledInputEvent(InputEvent event) { |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6413 | if (event instanceof MotionEvent) { |
| 6414 | event = MotionEvent.obtain((MotionEvent) event); |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6415 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6416 | synthesizeInputEvent(event); |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6417 | } |
| 6418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6419 | public void dispatchAppVisibility(boolean visible) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6420 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_APP_VISIBILITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6421 | msg.arg1 = visible ? 1 : 0; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6422 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6423 | } |
| 6424 | |
| 6425 | public void dispatchGetNewSurface() { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6426 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_GET_NEW_SURFACE); |
| 6427 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6428 | } |
| 6429 | |
| 6430 | public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { |
| 6431 | Message msg = Message.obtain(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6432 | msg.what = MSG_WINDOW_FOCUS_CHANGED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6433 | msg.arg1 = hasFocus ? 1 : 0; |
| 6434 | msg.arg2 = inTouchMode ? 1 : 0; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6435 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6436 | } |
| 6437 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 6438 | public void dispatchWindowShown() { |
| 6439 | mHandler.sendEmptyMessage(MSG_DISPATCH_WINDOW_SHOWN); |
| 6440 | } |
| 6441 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6442 | public void dispatchCloseSystemDialogs(String reason) { |
| 6443 | Message msg = Message.obtain(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6444 | msg.what = MSG_CLOSE_SYSTEM_DIALOGS; |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6445 | msg.obj = reason; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6446 | mHandler.sendMessage(msg); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6447 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6448 | |
| 6449 | public void dispatchDragEvent(DragEvent event) { |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6450 | final int what; |
| 6451 | if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6452 | what = MSG_DISPATCH_DRAG_LOCATION_EVENT; |
| 6453 | mHandler.removeMessages(what); |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6454 | } else { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6455 | what = MSG_DISPATCH_DRAG_EVENT; |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6456 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6457 | Message msg = mHandler.obtainMessage(what, event); |
| 6458 | mHandler.sendMessage(msg); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6459 | } |
| 6460 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 6461 | public void updatePointerIcon(float x, float y) { |
| 6462 | final int what = MSG_UPDATE_POINTER_ICON; |
| 6463 | mHandler.removeMessages(what); |
| 6464 | final long now = SystemClock.uptimeMillis(); |
| 6465 | final MotionEvent event = MotionEvent.obtain( |
| 6466 | 0, now, MotionEvent.ACTION_HOVER_MOVE, x, y, 0); |
| 6467 | Message msg = mHandler.obtainMessage(what, event); |
| 6468 | mHandler.sendMessage(msg); |
| 6469 | } |
| 6470 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6471 | public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, |
| 6472 | int localValue, int localChanges) { |
| 6473 | SystemUiVisibilityInfo args = new SystemUiVisibilityInfo(); |
| 6474 | args.seq = seq; |
| 6475 | args.globalVisibility = globalVisibility; |
| 6476 | args.localValue = localValue; |
| 6477 | args.localChanges = localChanges; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6478 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DISPATCH_SYSTEM_UI_VISIBILITY, args)); |
| 6479 | } |
| 6480 | |
| 6481 | public void dispatchCheckFocus() { |
| 6482 | if (!mHandler.hasMessages(MSG_CHECK_FOCUS)) { |
| 6483 | // This will result in a call to checkFocus() below. |
| 6484 | mHandler.sendEmptyMessage(MSG_CHECK_FOCUS); |
| 6485 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6486 | } |
| 6487 | |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 6488 | public void dispatchRequestKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
| 6489 | mHandler.obtainMessage( |
| 6490 | MSG_REQUEST_KEYBOARD_SHORTCUTS, deviceId, 0, receiver).sendToTarget(); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 6491 | } |
| 6492 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6493 | /** |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6494 | * Post a callback to send a |
| 6495 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6496 | * This event is send at most once every |
| 6497 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6498 | */ |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 6499 | private void postSendWindowContentChangedCallback(View source, int changeType) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6500 | if (mSendWindowContentChangedAccessibilityEvent == null) { |
| 6501 | mSendWindowContentChangedAccessibilityEvent = |
| 6502 | new SendWindowContentChangedAccessibilityEvent(); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6503 | } |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 6504 | mSendWindowContentChangedAccessibilityEvent.runOrPost(source, changeType); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6505 | } |
| 6506 | |
| 6507 | /** |
| 6508 | * Remove a posted callback to send a |
| 6509 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. |
| 6510 | */ |
| 6511 | private void removeSendWindowContentChangedCallback() { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6512 | if (mSendWindowContentChangedAccessibilityEvent != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6513 | mHandler.removeCallbacks(mSendWindowContentChangedAccessibilityEvent); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6514 | } |
| 6515 | } |
| 6516 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6517 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6518 | public boolean showContextMenuForChild(View originalView) { |
| 6519 | return false; |
| 6520 | } |
| 6521 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6522 | @Override |
Oren Blasberg | ed39126 | 2015-09-01 12:12:51 -0700 | [diff] [blame] | 6523 | public boolean showContextMenuForChild(View originalView, float x, float y) { |
| 6524 | return false; |
| 6525 | } |
| 6526 | |
| 6527 | @Override |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 6528 | public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) { |
| 6529 | return null; |
| 6530 | } |
| 6531 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6532 | @Override |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 6533 | public ActionMode startActionModeForChild( |
| 6534 | View originalView, ActionMode.Callback callback, int type) { |
| 6535 | return null; |
| 6536 | } |
| 6537 | |
| 6538 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6539 | public void createContextMenu(ContextMenu menu) { |
| 6540 | } |
| 6541 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6542 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6543 | public void childDrawableStateChanged(View child) { |
| 6544 | } |
| 6545 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6546 | @Override |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6547 | public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 6548 | if (mView == null || mStopped || mPausedForTransition) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6549 | return false; |
| 6550 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6551 | // Intercept accessibility focus events fired by virtual nodes to keep |
| 6552 | // track of accessibility focus position in such nodes. |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6553 | final int eventType = event.getEventType(); |
| 6554 | switch (eventType) { |
| 6555 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6556 | final long sourceNodeId = event.getSourceNodeId(); |
| 6557 | final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 6558 | sourceNodeId); |
| 6559 | View source = mView.findViewByAccessibilityId(accessibilityViewId); |
| 6560 | if (source != null) { |
| 6561 | AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider(); |
| 6562 | if (provider != null) { |
Svetoslav | b3ba1d4 | 2014-09-26 15:20:40 -0700 | [diff] [blame] | 6563 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 6564 | sourceNodeId); |
| 6565 | final AccessibilityNodeInfo node; |
| 6566 | if (virtualNodeId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
| 6567 | node = provider.createAccessibilityNodeInfo( |
| 6568 | AccessibilityNodeProvider.HOST_VIEW_ID); |
| 6569 | } else { |
| 6570 | node = provider.createAccessibilityNodeInfo(virtualNodeId); |
| 6571 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6572 | setAccessibilityFocus(source, node); |
| 6573 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6574 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6575 | } break; |
| 6576 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6577 | final long sourceNodeId = event.getSourceNodeId(); |
| 6578 | final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 6579 | sourceNodeId); |
| 6580 | View source = mView.findViewByAccessibilityId(accessibilityViewId); |
| 6581 | if (source != null) { |
| 6582 | AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider(); |
| 6583 | if (provider != null) { |
| 6584 | setAccessibilityFocus(null, null); |
| 6585 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6586 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6587 | } break; |
Svetoslav | f0c758b | 2014-09-03 17:47:37 -0700 | [diff] [blame] | 6588 | |
| 6589 | |
| 6590 | case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: { |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6591 | handleWindowContentChangedEvent(event); |
Svetoslav | f0c758b | 2014-09-03 17:47:37 -0700 | [diff] [blame] | 6592 | } break; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6593 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6594 | mAccessibilityManager.sendAccessibilityEvent(event); |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6595 | return true; |
| 6596 | } |
| 6597 | |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6598 | /** |
| 6599 | * Updates the focused virtual view, when necessary, in response to a |
| 6600 | * content changed event. |
| 6601 | * <p> |
| 6602 | * This is necessary to get updated bounds after a position change. |
| 6603 | * |
| 6604 | * @param event an accessibility event of type |
| 6605 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} |
| 6606 | */ |
| 6607 | private void handleWindowContentChangedEvent(AccessibilityEvent event) { |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6608 | final View focusedHost = mAccessibilityFocusedHost; |
| 6609 | if (focusedHost == null || mAccessibilityFocusedVirtualView == null) { |
| 6610 | // No virtual view focused, nothing to do here. |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6611 | return; |
| 6612 | } |
| 6613 | |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6614 | final AccessibilityNodeProvider provider = focusedHost.getAccessibilityNodeProvider(); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6615 | if (provider == null) { |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6616 | // Error state: virtual view with no provider. Clear focus. |
| 6617 | mAccessibilityFocusedHost = null; |
| 6618 | mAccessibilityFocusedVirtualView = null; |
| 6619 | focusedHost.clearAccessibilityFocusNoCallbacks(); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6620 | return; |
| 6621 | } |
| 6622 | |
| 6623 | // We only care about change types that may affect the bounds of the |
| 6624 | // focused virtual view. |
| 6625 | final int changes = event.getContentChangeTypes(); |
| 6626 | if ((changes & AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE) == 0 |
| 6627 | && changes != AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED) { |
| 6628 | return; |
| 6629 | } |
| 6630 | |
| 6631 | final long eventSourceNodeId = event.getSourceNodeId(); |
| 6632 | final int changedViewId = AccessibilityNodeInfo.getAccessibilityViewId(eventSourceNodeId); |
| 6633 | |
| 6634 | // Search up the tree for subtree containment. |
| 6635 | boolean hostInSubtree = false; |
| 6636 | View root = mAccessibilityFocusedHost; |
| 6637 | while (root != null && !hostInSubtree) { |
| 6638 | if (changedViewId == root.getAccessibilityViewId()) { |
| 6639 | hostInSubtree = true; |
| 6640 | } else { |
| 6641 | final ViewParent parent = root.getParent(); |
| 6642 | if (parent instanceof View) { |
| 6643 | root = (View) parent; |
| 6644 | } else { |
| 6645 | root = null; |
| 6646 | } |
| 6647 | } |
| 6648 | } |
| 6649 | |
| 6650 | // We care only about changes in subtrees containing the host view. |
| 6651 | if (!hostInSubtree) { |
| 6652 | return; |
| 6653 | } |
| 6654 | |
| 6655 | final long focusedSourceNodeId = mAccessibilityFocusedVirtualView.getSourceNodeId(); |
| 6656 | int focusedChildId = AccessibilityNodeInfo.getVirtualDescendantId(focusedSourceNodeId); |
| 6657 | if (focusedChildId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
| 6658 | // TODO: Should we clear the focused virtual view? |
| 6659 | focusedChildId = AccessibilityNodeProvider.HOST_VIEW_ID; |
| 6660 | } |
| 6661 | |
| 6662 | // Refresh the node for the focused virtual view. |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 6663 | final Rect oldBounds = mTempRect; |
| 6664 | mAccessibilityFocusedVirtualView.getBoundsInScreen(oldBounds); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6665 | mAccessibilityFocusedVirtualView = provider.createAccessibilityNodeInfo(focusedChildId); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6666 | if (mAccessibilityFocusedVirtualView == null) { |
| 6667 | // Error state: The node no longer exists. Clear focus. |
| 6668 | mAccessibilityFocusedHost = null; |
| 6669 | focusedHost.clearAccessibilityFocusNoCallbacks(); |
| 6670 | |
| 6671 | // This will probably fail, but try to keep the provider's internal |
| 6672 | // state consistent by clearing focus. |
| 6673 | provider.performAction(focusedChildId, |
| 6674 | AccessibilityAction.ACTION_CLEAR_ACCESSIBILITY_FOCUS.getId(), null); |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 6675 | invalidateRectOnScreen(oldBounds); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6676 | } else { |
| 6677 | // The node was refreshed, invalidate bounds if necessary. |
| 6678 | final Rect newBounds = mAccessibilityFocusedVirtualView.getBoundsInScreen(); |
| 6679 | if (!oldBounds.equals(newBounds)) { |
| 6680 | oldBounds.union(newBounds); |
| 6681 | invalidateRectOnScreen(oldBounds); |
| 6682 | } |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 6683 | } |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6684 | } |
| 6685 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6686 | @Override |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 6687 | public void notifySubtreeAccessibilityStateChanged(View child, View source, int changeType) { |
| 6688 | postSendWindowContentChangedCallback(source, changeType); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6689 | } |
| 6690 | |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 6691 | @Override |
| 6692 | public boolean canResolveLayoutDirection() { |
| 6693 | return true; |
| 6694 | } |
| 6695 | |
| 6696 | @Override |
| 6697 | public boolean isLayoutDirectionResolved() { |
| 6698 | return true; |
| 6699 | } |
| 6700 | |
| 6701 | @Override |
| 6702 | public int getLayoutDirection() { |
| 6703 | return View.LAYOUT_DIRECTION_RESOLVED_DEFAULT; |
| 6704 | } |
| 6705 | |
| 6706 | @Override |
| 6707 | public boolean canResolveTextDirection() { |
| 6708 | return true; |
| 6709 | } |
| 6710 | |
| 6711 | @Override |
| 6712 | public boolean isTextDirectionResolved() { |
| 6713 | return true; |
| 6714 | } |
| 6715 | |
| 6716 | @Override |
| 6717 | public int getTextDirection() { |
| 6718 | return View.TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 6719 | } |
| 6720 | |
| 6721 | @Override |
| 6722 | public boolean canResolveTextAlignment() { |
| 6723 | return true; |
| 6724 | } |
| 6725 | |
| 6726 | @Override |
| 6727 | public boolean isTextAlignmentResolved() { |
| 6728 | return true; |
| 6729 | } |
| 6730 | |
| 6731 | @Override |
| 6732 | public int getTextAlignment() { |
| 6733 | return View.TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 6734 | } |
| 6735 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6736 | private View getCommonPredecessor(View first, View second) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 6737 | if (mTempHashSet == null) { |
| 6738 | mTempHashSet = new HashSet<View>(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6739 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 6740 | HashSet<View> seen = mTempHashSet; |
| 6741 | seen.clear(); |
| 6742 | View firstCurrent = first; |
| 6743 | while (firstCurrent != null) { |
| 6744 | seen.add(firstCurrent); |
| 6745 | ViewParent firstCurrentParent = firstCurrent.mParent; |
| 6746 | if (firstCurrentParent instanceof View) { |
| 6747 | firstCurrent = (View) firstCurrentParent; |
| 6748 | } else { |
| 6749 | firstCurrent = null; |
| 6750 | } |
| 6751 | } |
| 6752 | View secondCurrent = second; |
| 6753 | while (secondCurrent != null) { |
| 6754 | if (seen.contains(secondCurrent)) { |
| 6755 | seen.clear(); |
| 6756 | return secondCurrent; |
| 6757 | } |
| 6758 | ViewParent secondCurrentParent = secondCurrent.mParent; |
| 6759 | if (secondCurrentParent instanceof View) { |
| 6760 | secondCurrent = (View) secondCurrentParent; |
| 6761 | } else { |
| 6762 | secondCurrent = null; |
| 6763 | } |
| 6764 | } |
| 6765 | seen.clear(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6766 | return null; |
| 6767 | } |
| 6768 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6769 | void checkThread() { |
| 6770 | if (mThread != Thread.currentThread()) { |
| 6771 | throw new CalledFromWrongThreadException( |
| 6772 | "Only the original thread that created a view hierarchy can touch its views."); |
| 6773 | } |
| 6774 | } |
| 6775 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6776 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6777 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 6778 | // ViewAncestor never intercepts touch event, so this can be a no-op |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6779 | } |
| 6780 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6781 | @Override |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6782 | public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { |
Yigit Boyar | d62d5e9 | 2016-01-19 18:56:20 -0800 | [diff] [blame] | 6783 | if (rectangle == null) { |
| 6784 | return scrollToRectOrFocus(null, immediate); |
| 6785 | } |
| 6786 | rectangle.offset(child.getLeft() - child.getScrollX(), |
| 6787 | child.getTop() - child.getScrollY()); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6788 | final boolean scrolled = scrollToRectOrFocus(rectangle, immediate); |
Yigit Boyar | d62d5e9 | 2016-01-19 18:56:20 -0800 | [diff] [blame] | 6789 | mTempRect.set(rectangle); |
| 6790 | mTempRect.offset(0, -mCurScrollY); |
| 6791 | mTempRect.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
| 6792 | try { |
| 6793 | mWindowSession.onRectangleOnScreenRequested(mWindow, mTempRect); |
| 6794 | } catch (RemoteException re) { |
| 6795 | /* ignore */ |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6796 | } |
| 6797 | return scrolled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6798 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6799 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6800 | @Override |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 6801 | public void childHasTransientStateChanged(View child, boolean hasTransientState) { |
| 6802 | // Do nothing. |
| 6803 | } |
| 6804 | |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 6805 | @Override |
| 6806 | public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) { |
| 6807 | return false; |
| 6808 | } |
| 6809 | |
| 6810 | @Override |
| 6811 | public void onStopNestedScroll(View target) { |
| 6812 | } |
| 6813 | |
| 6814 | @Override |
| 6815 | public void onNestedScrollAccepted(View child, View target, int nestedScrollAxes) { |
| 6816 | } |
| 6817 | |
| 6818 | @Override |
| 6819 | public void onNestedScroll(View target, int dxConsumed, int dyConsumed, |
| 6820 | int dxUnconsumed, int dyUnconsumed) { |
| 6821 | } |
| 6822 | |
| 6823 | @Override |
| 6824 | public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { |
| 6825 | } |
| 6826 | |
| 6827 | @Override |
Adam Powell | b36e4f9 | 2014-05-01 10:23:33 -0700 | [diff] [blame] | 6828 | public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) { |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 6829 | return false; |
| 6830 | } |
| 6831 | |
Adam Powell | b72be59 | 2014-07-16 21:41:31 -0700 | [diff] [blame] | 6832 | @Override |
| 6833 | public boolean onNestedPreFling(View target, float velocityX, float velocityY) { |
| 6834 | return false; |
| 6835 | } |
| 6836 | |
Adam Powell | b6ab098 | 2015-01-07 17:00:12 -0800 | [diff] [blame] | 6837 | @Override |
| 6838 | public boolean onNestedPrePerformAccessibilityAction(View target, int action, Bundle args) { |
| 6839 | return false; |
| 6840 | } |
| 6841 | |
Jorim Jaggi | b774e55 | 2015-08-24 14:52:45 -0700 | [diff] [blame] | 6842 | /** |
| 6843 | * Force the window to report its next draw. |
| 6844 | * <p> |
| 6845 | * This method is only supposed to be used to speed up the interaction from SystemUI and window |
| 6846 | * manager when waiting for the first frame to be drawn when turning on the screen. DO NOT USE |
| 6847 | * unless you fully understand this interaction. |
| 6848 | * @hide |
| 6849 | */ |
| 6850 | public void setReportNextDraw() { |
| 6851 | mReportNextDraw = true; |
| 6852 | invalidate(); |
| 6853 | } |
| 6854 | |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 6855 | void changeCanvasOpacity(boolean opaque) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6856 | Log.d(mTag, "changeCanvasOpacity: opaque=" + opaque); |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 6857 | if (mAttachInfo.mHardwareRenderer != null) { |
| 6858 | mAttachInfo.mHardwareRenderer.setOpaque(opaque); |
| 6859 | } |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 6860 | } |
| 6861 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6862 | class TakenSurfaceHolder extends BaseSurfaceHolder { |
| 6863 | @Override |
| 6864 | public boolean onAllowLockCanvas() { |
| 6865 | return mDrawingAllowed; |
| 6866 | } |
| 6867 | |
| 6868 | @Override |
| 6869 | public void onRelayoutContainer() { |
| 6870 | // Not currently interesting -- from changing between fixed and layout size. |
| 6871 | } |
| 6872 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6873 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6874 | public void setFormat(int format) { |
| 6875 | ((RootViewSurfaceTaker)mView).setSurfaceFormat(format); |
| 6876 | } |
| 6877 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6878 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6879 | public void setType(int type) { |
| 6880 | ((RootViewSurfaceTaker)mView).setSurfaceType(type); |
| 6881 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6882 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6883 | @Override |
| 6884 | public void onUpdateSurface() { |
| 6885 | // We take care of format and type changes on our own. |
| 6886 | throw new IllegalStateException("Shouldn't be here"); |
| 6887 | } |
| 6888 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6889 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6890 | public boolean isCreating() { |
| 6891 | return mIsCreating; |
| 6892 | } |
| 6893 | |
| 6894 | @Override |
| 6895 | public void setFixedSize(int width, int height) { |
| 6896 | throw new UnsupportedOperationException( |
| 6897 | "Currently only support sizing from layout"); |
| 6898 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6899 | |
| 6900 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6901 | public void setKeepScreenOn(boolean screenOn) { |
| 6902 | ((RootViewSurfaceTaker)mView).setSurfaceKeepScreenOn(screenOn); |
| 6903 | } |
| 6904 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6906 | static class W extends IWindow.Stub { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6907 | private final WeakReference<ViewRootImpl> mViewAncestor; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6908 | private final IWindowSession mWindowSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6909 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6910 | W(ViewRootImpl viewAncestor) { |
| 6911 | mViewAncestor = new WeakReference<ViewRootImpl>(viewAncestor); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6912 | mWindowSession = viewAncestor.mWindowSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6913 | } |
| 6914 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6915 | @Override |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6916 | public void resized(Rect frame, Rect overscanInsets, Rect contentInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 6917 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6918 | Configuration newConfig, Rect backDropFrame, boolean forceLayout, |
| 6919 | boolean alwaysConsumeNavBar) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6920 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6921 | if (viewAncestor != null) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6922 | viewAncestor.dispatchResized(frame, overscanInsets, contentInsets, |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 6923 | visibleInsets, stableInsets, outsets, reportDraw, newConfig, backDropFrame, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6924 | forceLayout, alwaysConsumeNavBar); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6925 | } |
| 6926 | } |
| 6927 | |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 6928 | @Override |
| 6929 | public void moved(int newX, int newY) { |
| 6930 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 6931 | if (viewAncestor != null) { |
| 6932 | viewAncestor.dispatchMoved(newX, newY); |
| 6933 | } |
| 6934 | } |
| 6935 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6936 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6937 | public void dispatchAppVisibility(boolean visible) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6938 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6939 | if (viewAncestor != null) { |
| 6940 | viewAncestor.dispatchAppVisibility(visible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6941 | } |
| 6942 | } |
| 6943 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6944 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6945 | public void dispatchGetNewSurface() { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6946 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6947 | if (viewAncestor != null) { |
| 6948 | viewAncestor.dispatchGetNewSurface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6949 | } |
| 6950 | } |
| 6951 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6952 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6953 | public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6954 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6955 | if (viewAncestor != null) { |
| 6956 | viewAncestor.windowFocusChanged(hasFocus, inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6957 | } |
| 6958 | } |
| 6959 | |
| 6960 | private static int checkCallingPermission(String permission) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6961 | try { |
| 6962 | return ActivityManagerNative.getDefault().checkPermission( |
| 6963 | permission, Binder.getCallingPid(), Binder.getCallingUid()); |
| 6964 | } catch (RemoteException e) { |
| 6965 | return PackageManager.PERMISSION_DENIED; |
| 6966 | } |
| 6967 | } |
| 6968 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6969 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6970 | public void executeCommand(String command, String parameters, ParcelFileDescriptor out) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6971 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6972 | if (viewAncestor != null) { |
| 6973 | final View view = viewAncestor.mView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6974 | if (view != null) { |
| 6975 | if (checkCallingPermission(Manifest.permission.DUMP) != |
| 6976 | PackageManager.PERMISSION_GRANTED) { |
| 6977 | throw new SecurityException("Insufficient permissions to invoke" |
| 6978 | + " executeCommand() from pid=" + Binder.getCallingPid() |
| 6979 | + ", uid=" + Binder.getCallingUid()); |
| 6980 | } |
| 6981 | |
| 6982 | OutputStream clientStream = null; |
| 6983 | try { |
| 6984 | clientStream = new ParcelFileDescriptor.AutoCloseOutputStream(out); |
| 6985 | ViewDebug.dispatchCommand(view, command, parameters, clientStream); |
| 6986 | } catch (IOException e) { |
| 6987 | e.printStackTrace(); |
| 6988 | } finally { |
| 6989 | if (clientStream != null) { |
| 6990 | try { |
| 6991 | clientStream.close(); |
| 6992 | } catch (IOException e) { |
| 6993 | e.printStackTrace(); |
| 6994 | } |
| 6995 | } |
| 6996 | } |
| 6997 | } |
| 6998 | } |
| 6999 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7000 | |
| 7001 | @Override |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 7002 | public void closeSystemDialogs(String reason) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7003 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7004 | if (viewAncestor != null) { |
| 7005 | viewAncestor.dispatchCloseSystemDialogs(reason); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 7006 | } |
| 7007 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7008 | |
| 7009 | @Override |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7010 | public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep, |
| 7011 | boolean sync) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7012 | if (sync) { |
| 7013 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7014 | mWindowSession.wallpaperOffsetsComplete(asBinder()); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7015 | } catch (RemoteException e) { |
| 7016 | } |
| 7017 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7018 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7019 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7020 | @Override |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 7021 | public void dispatchWallpaperCommand(String action, int x, int y, |
| 7022 | int z, Bundle extras, boolean sync) { |
| 7023 | if (sync) { |
| 7024 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7025 | mWindowSession.wallpaperCommandComplete(asBinder(), null); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 7026 | } catch (RemoteException e) { |
| 7027 | } |
| 7028 | } |
| 7029 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7030 | |
| 7031 | /* Drag/drop */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7032 | @Override |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7033 | public void dispatchDragEvent(DragEvent event) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7034 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7035 | if (viewAncestor != null) { |
| 7036 | viewAncestor.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7037 | } |
| 7038 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7039 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7040 | @Override |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 7041 | public void updatePointerIcon(float x, float y) { |
| 7042 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7043 | if (viewAncestor != null) { |
| 7044 | viewAncestor.updatePointerIcon(x, y); |
| 7045 | } |
| 7046 | } |
| 7047 | |
| 7048 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 7049 | public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, |
| 7050 | int localValue, int localChanges) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7051 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7052 | if (viewAncestor != null) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 7053 | viewAncestor.dispatchSystemUiVisibilityChanged(seq, globalVisibility, |
| 7054 | localValue, localChanges); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7055 | } |
| 7056 | } |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 7057 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7058 | @Override |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 7059 | public void dispatchWindowShown() { |
| 7060 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7061 | if (viewAncestor != null) { |
| 7062 | viewAncestor.dispatchWindowShown(); |
| 7063 | } |
| 7064 | } |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 7065 | |
| 7066 | @Override |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 7067 | public void requestAppKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
| 7068 | ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7069 | if (viewAncestor != null) { |
| 7070 | viewAncestor.dispatchRequestKeyboardShortcuts(receiver, deviceId); |
| 7071 | } |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 7072 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7073 | } |
| 7074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7075 | public static final class CalledFromWrongThreadException extends AndroidRuntimeException { |
| 7076 | public CalledFromWrongThreadException(String msg) { |
| 7077 | super(msg); |
| 7078 | } |
| 7079 | } |
| 7080 | |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 7081 | static HandlerActionQueue getRunQueue() { |
| 7082 | HandlerActionQueue rq = sRunQueues.get(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7083 | if (rq != null) { |
| 7084 | return rq; |
| 7085 | } |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 7086 | rq = new HandlerActionQueue(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7087 | sRunQueues.set(rq); |
| 7088 | return rq; |
| 7089 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7091 | /** |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7092 | * Start a drag resizing which will inform all listeners that a window resize is taking place. |
| 7093 | */ |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 7094 | private void startDragResizing(Rect initialBounds, boolean fullscreen, Rect systemInsets, |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 7095 | Rect stableInsets, int resizeMode) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7096 | if (!mDragResizing) { |
| 7097 | mDragResizing = true; |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 7098 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7099 | mWindowCallbacks.get(i).onWindowDragResizeStart(initialBounds, fullscreen, |
| 7100 | systemInsets, stableInsets, resizeMode); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7101 | } |
| 7102 | mFullRedrawNeeded = true; |
| 7103 | } |
| 7104 | } |
| 7105 | |
| 7106 | /** |
| 7107 | * End a drag resize which will inform all listeners that a window resize has ended. |
| 7108 | */ |
| 7109 | private void endDragResizing() { |
| 7110 | if (mDragResizing) { |
| 7111 | mDragResizing = false; |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 7112 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7113 | mWindowCallbacks.get(i).onWindowDragResizeEnd(); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7114 | } |
| 7115 | mFullRedrawNeeded = true; |
| 7116 | } |
| 7117 | } |
| 7118 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 7119 | private boolean updateContentDrawBounds() { |
| 7120 | boolean updated = false; |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 7121 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7122 | updated |= mWindowCallbacks.get(i).onContentDrawn( |
| 7123 | mWindowAttributes.surfaceInsets.left, |
| 7124 | mWindowAttributes.surfaceInsets.top, |
| 7125 | mWidth, mHeight); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 7126 | } |
| 7127 | return updated | (mDragResizing && mReportNextDraw); |
| 7128 | } |
| 7129 | |
| 7130 | private void requestDrawWindow() { |
| 7131 | if (mReportNextDraw) { |
| 7132 | mWindowDrawCountDown = new CountDownLatch(mWindowCallbacks.size()); |
| 7133 | } |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 7134 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7135 | mWindowCallbacks.get(i).onRequestDraw(mReportNextDraw); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 7136 | } |
| 7137 | } |
| 7138 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7139 | /** |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 7140 | * Tells this instance that its corresponding activity has just relaunched. In this case, we |
| 7141 | * need to force a relayout of the window to make sure we get the correct bounds from window |
| 7142 | * manager. |
| 7143 | */ |
| 7144 | public void reportActivityRelaunched() { |
| 7145 | mActivityRelaunched = true; |
| 7146 | } |
| 7147 | |
| 7148 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7149 | * Class for managing the accessibility interaction connection |
| 7150 | * based on the global accessibility state. |
| 7151 | */ |
| 7152 | final class AccessibilityInteractionConnectionManager |
| 7153 | implements AccessibilityStateChangeListener { |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7154 | @Override |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7155 | public void onAccessibilityStateChanged(boolean enabled) { |
| 7156 | if (enabled) { |
| 7157 | ensureConnection(); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7158 | if (mAttachInfo.mHasWindowFocus) { |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 7159 | mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 7160 | View focusedView = mView.findFocus(); |
| 7161 | if (focusedView != null && focusedView != mView) { |
| 7162 | focusedView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 7163 | } |
| 7164 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7165 | } else { |
| 7166 | ensureNoConnection(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 7167 | mHandler.obtainMessage(MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST).sendToTarget(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7168 | } |
| 7169 | } |
| 7170 | |
| 7171 | public void ensureConnection() { |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7172 | final boolean registered = |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 7173 | mAttachInfo.mAccessibilityWindowId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7174 | if (!registered) { |
| 7175 | mAttachInfo.mAccessibilityWindowId = |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 7176 | mAccessibilityManager.addAccessibilityInteractionConnection(mWindow, |
| 7177 | new AccessibilityInteractionConnection(ViewRootImpl.this)); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7178 | } |
| 7179 | } |
| 7180 | |
| 7181 | public void ensureNoConnection() { |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 7182 | final boolean registered = |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 7183 | mAttachInfo.mAccessibilityWindowId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7184 | if (registered) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 7185 | mAttachInfo.mAccessibilityWindowId = AccessibilityNodeInfo.UNDEFINED_ITEM_ID; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7186 | mAccessibilityManager.removeAccessibilityInteractionConnection(mWindow); |
| 7187 | } |
| 7188 | } |
| 7189 | } |
| 7190 | |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7191 | final class HighContrastTextManager implements HighTextContrastChangeListener { |
| 7192 | HighContrastTextManager() { |
| 7193 | mAttachInfo.mHighContrastText = mAccessibilityManager.isHighTextContrastEnabled(); |
| 7194 | } |
| 7195 | @Override |
| 7196 | public void onHighTextContrastStateChanged(boolean enabled) { |
| 7197 | mAttachInfo.mHighContrastText = enabled; |
| 7198 | |
| 7199 | // Destroy Displaylists so they can be recreated with high contrast recordings |
| 7200 | destroyHardwareResources(); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 7201 | |
| 7202 | // Schedule redraw, which will rerecord + redraw all text |
| 7203 | invalidate(); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7204 | } |
| 7205 | } |
| 7206 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7207 | /** |
| 7208 | * This class is an interface this ViewAncestor provides to the |
| 7209 | * AccessibilityManagerService to the latter can interact with |
| 7210 | * the view hierarchy in this ViewAncestor. |
| 7211 | */ |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7212 | static final class AccessibilityInteractionConnection |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7213 | extends IAccessibilityInteractionConnection.Stub { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7214 | private final WeakReference<ViewRootImpl> mViewRootImpl; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7215 | |
Svetoslav Ganov | f79f476 | 2011-10-28 15:40:32 -0700 | [diff] [blame] | 7216 | AccessibilityInteractionConnection(ViewRootImpl viewRootImpl) { |
| 7217 | mViewRootImpl = new WeakReference<ViewRootImpl>(viewRootImpl); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7218 | } |
| 7219 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7220 | @Override |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7221 | public void findAccessibilityNodeInfoByAccessibilityId(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7222 | Region interactiveRegion, int interactionId, |
| 7223 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7224 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7225 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7226 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7227 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7228 | .findAccessibilityNodeInfoByAccessibilityIdClientThread(accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7229 | interactiveRegion, interactionId, callback, flags, interrogatingPid, |
| 7230 | interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7231 | } else { |
| 7232 | // We cannot make the call and notify the caller so it does not wait. |
| 7233 | try { |
| 7234 | callback.setFindAccessibilityNodeInfosResult(null, interactionId); |
| 7235 | } catch (RemoteException re) { |
| 7236 | /* best effort - ignore */ |
| 7237 | } |
Svetoslav Ganov | 601ad80 | 2011-06-09 14:47:38 -0700 | [diff] [blame] | 7238 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7239 | } |
| 7240 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7241 | @Override |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7242 | public void performAccessibilityAction(long accessibilityNodeId, int action, |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 7243 | Bundle arguments, int interactionId, |
| 7244 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 7245 | int interrogatingPid, long interrogatingTid) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7246 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7247 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7248 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 7249 | .performAccessibilityActionClientThread(accessibilityNodeId, action, arguments, |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 7250 | interactionId, callback, flags, interrogatingPid, interrogatingTid); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7251 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7252 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7253 | try { |
| 7254 | callback.setPerformAccessibilityActionResult(false, interactionId); |
| 7255 | } catch (RemoteException re) { |
| 7256 | /* best effort - ignore */ |
| 7257 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7258 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7259 | } |
| 7260 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7261 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7262 | public void findAccessibilityNodeInfosByViewId(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7263 | String viewId, Region interactiveRegion, int interactionId, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7264 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7265 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7266 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7267 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7268 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7269 | .findAccessibilityNodeInfosByViewIdClientThread(accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7270 | viewId, interactiveRegion, interactionId, callback, flags, |
| 7271 | interrogatingPid, interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7272 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7273 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7274 | try { |
| 7275 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
| 7276 | } catch (RemoteException re) { |
| 7277 | /* best effort - ignore */ |
| 7278 | } |
| 7279 | } |
| 7280 | } |
| 7281 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7282 | @Override |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7283 | public void findAccessibilityNodeInfosByText(long accessibilityNodeId, String text, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7284 | Region interactiveRegion, int interactionId, |
| 7285 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7286 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7287 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7288 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7289 | viewRootImpl.getAccessibilityInteractionController() |
| 7290 | .findAccessibilityNodeInfosByTextClientThread(accessibilityNodeId, text, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7291 | interactiveRegion, interactionId, callback, flags, interrogatingPid, |
| 7292 | interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7293 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7294 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7295 | try { |
| 7296 | callback.setFindAccessibilityNodeInfosResult(null, interactionId); |
| 7297 | } catch (RemoteException re) { |
| 7298 | /* best effort - ignore */ |
| 7299 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7300 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7301 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7302 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7303 | @Override |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7304 | public void findFocus(long accessibilityNodeId, int focusType, Region interactiveRegion, |
| 7305 | int interactionId, IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7306 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7307 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7308 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7309 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7310 | .findFocusClientThread(accessibilityNodeId, focusType, interactiveRegion, |
| 7311 | interactionId, callback, flags, interrogatingPid, interrogatingTid, |
| 7312 | spec); |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 7313 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7314 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7315 | try { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7316 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7317 | } catch (RemoteException re) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7318 | /* best effort - ignore */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7319 | } |
| 7320 | } |
| 7321 | } |
| 7322 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7323 | @Override |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7324 | public void focusSearch(long accessibilityNodeId, int direction, Region interactiveRegion, |
| 7325 | int interactionId, IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7326 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7327 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7328 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7329 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7330 | .focusSearchClientThread(accessibilityNodeId, direction, interactiveRegion, |
| 7331 | interactionId, callback, flags, interrogatingPid, interrogatingTid, |
| 7332 | spec); |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 7333 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7334 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7335 | try { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7336 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7337 | } catch (RemoteException re) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7338 | /* best effort - ignore */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7339 | } |
| 7340 | } |
| 7341 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7342 | } |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7343 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7344 | private class SendWindowContentChangedAccessibilityEvent implements Runnable { |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7345 | private int mChangeTypes = 0; |
| 7346 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7347 | public View mSource; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7348 | public long mLastEventTimeMillis; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7349 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7350 | @Override |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7351 | public void run() { |
Svetoslav | 8d820ecf | 2013-07-15 17:12:41 -0700 | [diff] [blame] | 7352 | // The accessibility may be turned off while we were waiting so check again. |
| 7353 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 7354 | mLastEventTimeMillis = SystemClock.uptimeMillis(); |
| 7355 | AccessibilityEvent event = AccessibilityEvent.obtain(); |
| 7356 | event.setEventType(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7357 | event.setContentChangeTypes(mChangeTypes); |
Svetoslav | 8d820ecf | 2013-07-15 17:12:41 -0700 | [diff] [blame] | 7358 | mSource.sendAccessibilityEventUnchecked(event); |
| 7359 | } else { |
| 7360 | mLastEventTimeMillis = 0; |
| 7361 | } |
| 7362 | // In any case reset to initial state. |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7363 | mSource.resetSubtreeAccessibilityStateChanged(); |
| 7364 | mSource = null; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7365 | mChangeTypes = 0; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7366 | } |
| 7367 | |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7368 | public void runOrPost(View source, int changeType) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7369 | if (mSource != null) { |
Svetoslav | 9dafebb | 2013-06-18 16:29:25 -0700 | [diff] [blame] | 7370 | // If there is no common predecessor, then mSource points to |
| 7371 | // a removed view, hence in this case always prefer the source. |
| 7372 | View predecessor = getCommonPredecessor(mSource, source); |
| 7373 | mSource = (predecessor != null) ? predecessor : source; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7374 | mChangeTypes |= changeType; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7375 | return; |
| 7376 | } |
| 7377 | mSource = source; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7378 | mChangeTypes = changeType; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7379 | final long timeSinceLastMillis = SystemClock.uptimeMillis() - mLastEventTimeMillis; |
| 7380 | final long minEventIntevalMillis = |
| 7381 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval(); |
| 7382 | if (timeSinceLastMillis >= minEventIntevalMillis) { |
Svetoslav | 9dafebb | 2013-06-18 16:29:25 -0700 | [diff] [blame] | 7383 | mSource.removeCallbacks(this); |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7384 | run(); |
| 7385 | } else { |
| 7386 | mSource.postDelayed(this, minEventIntevalMillis - timeSinceLastMillis); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7387 | } |
| 7388 | } |
| 7389 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7390 | } |