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; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 88 | import com.android.internal.os.IResultReceiver; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 89 | import com.android.internal.os.SomeArgs; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 90 | import com.android.internal.policy.PhoneFallbackEventHandler; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 91 | import com.android.internal.view.BaseSurfaceHolder; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 92 | import com.android.internal.view.RootViewSurfaceTaker; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 94 | import java.io.FileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | import java.io.IOException; |
| 96 | import java.io.OutputStream; |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 97 | import java.io.PrintWriter; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 98 | import java.lang.ref.WeakReference; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | import java.util.ArrayList; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 100 | import java.util.HashSet; |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame^] | 101 | import java.util.concurrent.CountDownLatch; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | /** |
| 104 | * The top of a view hierarchy, implementing the needed protocol between View |
| 105 | * and the WindowManager. This is for the most part an internal implementation |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 106 | * detail of {@link WindowManagerGlobal}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | * |
| 108 | * {@hide} |
| 109 | */ |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 110 | @SuppressWarnings({"EmptyCatchBlock", "PointlessBooleanExpression"}) |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 111 | public final class ViewRootImpl implements ViewParent, |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 112 | View.AttachInfo.Callbacks, ThreadedRenderer.HardwareDrawCallbacks { |
Dianne Hackborn | 70a3f67 | 2011-08-08 14:32:41 -0700 | [diff] [blame] | 113 | private static final String TAG = "ViewRootImpl"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | private static final boolean DBG = false; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 115 | private static final boolean LOCAL_LOGV = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | /** @noinspection PointlessBooleanExpression*/ |
| 117 | private static final boolean DEBUG_DRAW = false || LOCAL_LOGV; |
| 118 | private static final boolean DEBUG_LAYOUT = false || LOCAL_LOGV; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 119 | private static final boolean DEBUG_DIALOG = false || LOCAL_LOGV; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | private static final boolean DEBUG_INPUT_RESIZE = false || LOCAL_LOGV; |
| 121 | private static final boolean DEBUG_ORIENTATION = false || LOCAL_LOGV; |
| 122 | private static final boolean DEBUG_TRACKBALL = false || LOCAL_LOGV; |
| 123 | private static final boolean DEBUG_IMF = false || LOCAL_LOGV; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 124 | private static final boolean DEBUG_CONFIGURATION = false || LOCAL_LOGV; |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 125 | private static final boolean DEBUG_FPS = false; |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 126 | 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] | 127 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 128 | /** |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 129 | * Set to false if we do not want to use the multi threaded renderer. Note that by disabling |
| 130 | * this, WindowCallbacks will not fire. |
| 131 | */ |
| 132 | private static final boolean USE_MT_RENDERER = true; |
| 133 | |
| 134 | /** |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 135 | * Set this system property to true to force the view hierarchy to render |
| 136 | * at 60 Hz. This can be used to measure the potential framerate. |
| 137 | */ |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 138 | private static final String PROPERTY_PROFILE_RENDERING = "viewroot.profile_rendering"; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 139 | |
Griff Hazen | a093802 | 2015-03-13 10:01:41 -0700 | [diff] [blame] | 140 | // properties used by emulator to determine display shape |
Griff Hazen | a093802 | 2015-03-13 10:01:41 -0700 | [diff] [blame] | 141 | public static final String PROPERTY_EMULATOR_WIN_OUTSET_BOTTOM_PX = |
| 142 | "ro.emu.win_outset_bottom_px"; |
Michael Kolb | 437d313 | 2014-06-20 13:28:44 -0700 | [diff] [blame] | 143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | /** |
| 145 | * Maximum time we allow the user to roll the trackball enough to generate |
| 146 | * a key event, before resetting the counters. |
| 147 | */ |
| 148 | static final int MAX_TRACKBALL_DELAY = 250; |
| 149 | |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 150 | static final ThreadLocal<HandlerActionQueue> sRunQueues = new ThreadLocal<HandlerActionQueue>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 152 | static final ArrayList<Runnable> sFirstDrawHandlers = new ArrayList(); |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 153 | static boolean sFirstDrawComplete = false; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 154 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 155 | static final ArrayList<ComponentCallbacks> sConfigCallbacks = new ArrayList(); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 156 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 157 | final ArrayList<WindowCallbacks> mWindowCallbacks = new ArrayList(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 158 | final Context mContext; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 159 | final IWindowSession mWindowSession; |
| 160 | final Display mDisplay; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 161 | final DisplayManager mDisplayManager; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 162 | final String mBasePackageName; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | final int[] mTmpLocation = new int[2]; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 165 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 166 | final TypedValue mTmpValue = new TypedValue(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | final Thread mThread; |
| 169 | |
| 170 | final WindowLeaked mLocation; |
| 171 | |
| 172 | final WindowManager.LayoutParams mWindowAttributes = new WindowManager.LayoutParams(); |
| 173 | |
| 174 | final W mWindow; |
| 175 | |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 176 | final int mTargetSdkVersion; |
| 177 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 178 | int mSeq; |
| 179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | View mView; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 181 | |
| 182 | View mAccessibilityFocusedHost; |
| 183 | AccessibilityNodeInfo mAccessibilityFocusedVirtualView; |
| 184 | |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 185 | // The view which captures mouse input, or null when no one is capturing. |
| 186 | View mCapturingView; |
| 187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | int mViewVisibility; |
| 189 | boolean mAppVisible = true; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 190 | // For recents to freeform transition we need to keep drawing after the app receives information |
| 191 | // that it became invisible. This will ignore that information and depend on the decor view |
| 192 | // visibility to control drawing. The decor view visibility will get adjusted when the app get |
| 193 | // stopped and that's when the app will stop drawing further frames. |
| 194 | private boolean mForceDecorViewVisibility = false; |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 195 | int mOrigWindowType = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 197 | /** Whether the window had focus during the most recent traversal. */ |
| 198 | boolean mHadWindowFocus; |
| 199 | |
| 200 | /** |
| 201 | * Whether the window lost focus during a previous traversal and has not |
| 202 | * yet gained it back. Used to determine whether a WINDOW_STATE_CHANGE |
| 203 | * accessibility events should be sent during traversal. |
| 204 | */ |
| 205 | boolean mLostWindowFocus; |
| 206 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 207 | // Set to true if the owner of this window is in the stopped state, |
| 208 | // so the window should no longer be active. |
| 209 | boolean mStopped = false; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 210 | |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 211 | // Set to true if the owner of this window is in ambient mode, |
| 212 | // which means it won't receive input events. |
| 213 | boolean mIsAmbientMode = false; |
| 214 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 215 | // Set to true to stop input during an Activity Transition. |
| 216 | boolean mPausedForTransition = false; |
| 217 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 218 | boolean mLastInCompatMode = false; |
| 219 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 220 | SurfaceHolder.Callback2 mSurfaceHolderCallback; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 221 | BaseSurfaceHolder mSurfaceHolder; |
| 222 | boolean mIsCreating; |
| 223 | boolean mDrawingAllowed; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | final Region mTransparentRegion; |
| 226 | final Region mPreviousTransparentRegion; |
| 227 | |
| 228 | int mWidth; |
| 229 | int mHeight; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 230 | Rect mDirty; |
Romain Guy | bb93d55 | 2009-03-24 21:04:15 -0700 | [diff] [blame] | 231 | boolean mIsAnimating; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 232 | |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 233 | private boolean mDragResizing; |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame^] | 234 | private boolean mInvalidateRootRequested; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 235 | private int mResizeMode; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 236 | private int mCanvasOffsetX; |
| 237 | private int mCanvasOffsetY; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 238 | private boolean mActivityRelaunched; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 239 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 240 | CompatibilityInfo.Translator mTranslator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | |
| 242 | final View.AttachInfo mAttachInfo; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 243 | InputChannel mInputChannel; |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 244 | InputQueue.Callback mInputQueueCallback; |
| 245 | InputQueue mInputQueue; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 246 | FallbackEventHandler mFallbackEventHandler; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 247 | Choreographer mChoreographer; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | final Rect mTempRect; // used in the transaction to not thrash the heap. |
| 250 | 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] | 251 | |
| 252 | boolean mTraversalScheduled; |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 253 | int mTraversalBarrier; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | boolean mWillDrawSoon; |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 255 | /** Set to true while in performTraversals for detecting when die(true) is called from internal |
| 256 | * callbacks such as onMeasure, onPreDraw, onDraw and deferring doDie() until later. */ |
| 257 | boolean mIsInTraversal; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 258 | boolean mApplyInsetsRequested; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | boolean mLayoutRequested; |
| 260 | boolean mFirst; |
| 261 | boolean mReportNextDraw; |
| 262 | boolean mFullRedrawNeeded; |
| 263 | boolean mNewSurfaceNeeded; |
| 264 | boolean mHasHadWindowFocus; |
| 265 | boolean mLastWasImTarget; |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 266 | boolean mForceNextWindowRelayout; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 267 | CountDownLatch mWindowDrawCountDown; |
Jorim Jaggi | 827e0fa | 2015-05-07 11:41:41 -0700 | [diff] [blame] | 268 | |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 269 | boolean mIsDrawing; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 270 | int mLastSystemUiVisibility; |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 271 | int mClientWindowLayoutFlags; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 272 | boolean mLastOverscanRequested; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 273 | |
| 274 | // Pool of queued input events. |
| 275 | private static final int MAX_QUEUED_INPUT_EVENT_POOL_SIZE = 10; |
| 276 | private QueuedInputEvent mQueuedInputEventPool; |
| 277 | private int mQueuedInputEventPoolSize; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 278 | |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 279 | /* Input event queue. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 280 | * Pending input events are input events waiting to be delivered to the input stages |
| 281 | * and handled by the application. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 282 | */ |
| 283 | QueuedInputEvent mPendingInputEventHead; |
| 284 | QueuedInputEvent mPendingInputEventTail; |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 285 | int mPendingInputEventCount; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 286 | boolean mProcessInputEventsScheduled; |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 287 | boolean mUnbufferedInputDispatch; |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 288 | String mPendingInputEventQueueLengthCounterName = "pq"; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 289 | |
| 290 | InputStage mFirstInputStage; |
| 291 | InputStage mFirstPostImeInputStage; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 292 | InputStage mSyntheticInputStage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | |
| 294 | boolean mWindowAttributesChanged = false; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 295 | int mWindowAttributesChangesFlag = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | |
| 297 | // 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] | 298 | // Surface can never be reassigned or cleared (use Surface.clear()). |
John Reck | b13de07 | 2014-11-19 16:33:47 -0800 | [diff] [blame] | 299 | final Surface mSurface = new Surface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | |
| 301 | boolean mAdded; |
| 302 | boolean mAddedTouchMode; |
| 303 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 304 | final DisplayAdjustments mDisplayAdjustments; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | // These are accessed by multiple threads. |
| 307 | final Rect mWinFrame; // frame given by window manager. |
| 308 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 309 | final Rect mPendingOverscanInsets = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | final Rect mPendingVisibleInsets = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 311 | final Rect mPendingStableInsets = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | final Rect mPendingContentInsets = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 313 | final Rect mPendingOutsets = new Rect(); |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 314 | final Rect mPendingBackDropFrame = new Rect(); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 315 | boolean mPendingAlwaysConsumeNavBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | final ViewTreeObserver.InternalInsetsInfo mLastGivenInsets |
| 317 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 318 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 319 | final Rect mDispatchContentInsets = new Rect(); |
| 320 | final Rect mDispatchStableInsets = new Rect(); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 321 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 322 | private WindowInsets mLastWindowInsets; |
| 323 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 324 | final Configuration mLastConfiguration = new Configuration(); |
| 325 | final Configuration mPendingConfiguration = new Configuration(); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | boolean mScrollMayChange; |
| 328 | int mSoftInputMode; |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 329 | WeakReference<View> mLastScrolledFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | int mScrollY; |
| 331 | int mCurScrollY; |
| 332 | Scroller mScroller; |
John Reck | e56e9df | 2014-02-21 15:45:10 -0800 | [diff] [blame] | 333 | static final Interpolator mResizeInterpolator = new AccelerateDecelerateInterpolator(); |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 334 | private ArrayList<LayoutTransition> mPendingTransitions; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 335 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 336 | final ViewConfiguration mViewConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 338 | /* Drag/drop */ |
| 339 | ClipDescription mDragDescription; |
| 340 | View mCurrentDragView; |
Christopher Tate | 7fb8b56 | 2011-01-20 13:46:41 -0800 | [diff] [blame] | 341 | volatile Object mLocalDragState; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 342 | final PointF mDragPoint = new PointF(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 343 | final PointF mLastTouchPoint = new PointF(); |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 344 | int mLastTouchSource; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 345 | |
| 346 | private boolean mProfileRendering; |
Romain Guy | d075031 | 2012-11-29 11:34:43 -0800 | [diff] [blame] | 347 | private Choreographer.FrameCallback mRenderProfiler; |
| 348 | private boolean mRenderProfilingEnabled; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 349 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 350 | // Variables to track frames per second, enabled via DEBUG_FPS flag |
| 351 | private long mFpsStartTime = -1; |
| 352 | private long mFpsPrevTime = -1; |
| 353 | private int mFpsNumFrames; |
| 354 | |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 355 | private int mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 356 | private PointerIcon mCustomPointerIcon = null; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 357 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | /** |
| 359 | * see {@link #playSoundEffect(int)} |
| 360 | */ |
| 361 | AudioManager mAudioManager; |
| 362 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 363 | final AccessibilityManager mAccessibilityManager; |
| 364 | |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 365 | AccessibilityInteractionController mAccessibilityInteractionController; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 366 | |
| 367 | AccessibilityInteractionConnectionManager mAccessibilityInteractionConnectionManager; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 368 | HighContrastTextManager mHighContrastTextManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 369 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 370 | SendWindowContentChangedAccessibilityEvent mSendWindowContentChangedAccessibilityEvent; |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 371 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 372 | HashSet<View> mTempHashSet; |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 373 | |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 374 | private final int mDensity; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 375 | private final int mNoncompatDensity; |
Adam Powell | b08013c | 2010-09-16 16:28:11 -0700 | [diff] [blame] | 376 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 377 | private boolean mInLayout = false; |
| 378 | ArrayList<View> mLayoutRequesters = new ArrayList<View>(); |
| 379 | boolean mHandlingLayoutInLayoutRequest = false; |
| 380 | |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 381 | private int mViewLayoutDirectionInitial; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 382 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 383 | /** Set to true once doDie() has been called. */ |
| 384 | private boolean mRemoved; |
| 385 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 386 | /** |
| 387 | * Consistency verifier for debugging purposes. |
| 388 | */ |
| 389 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 390 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 391 | new InputEventConsistencyVerifier(this, 0) : null; |
| 392 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 393 | static final class SystemUiVisibilityInfo { |
| 394 | int seq; |
| 395 | int globalVisibility; |
| 396 | int localValue; |
| 397 | int localChanges; |
| 398 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 399 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 400 | private String mTag = TAG; |
| 401 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 402 | public ViewRootImpl(Context context, Display display) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 403 | mContext = context; |
| 404 | mWindowSession = WindowManagerGlobal.getWindowSession(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 405 | mDisplay = display; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 406 | mBasePackageName = context.getBasePackageName(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 407 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 408 | mDisplayAdjustments = display.getDisplayAdjustments(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | mThread = Thread.currentThread(); |
| 411 | mLocation = new WindowLeaked(null); |
| 412 | mLocation.fillInStackTrace(); |
| 413 | mWidth = -1; |
| 414 | mHeight = -1; |
| 415 | mDirty = new Rect(); |
| 416 | mTempRect = new Rect(); |
| 417 | mVisRect = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | mWinFrame = new Rect(); |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 419 | mWindow = new W(this); |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 420 | mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | mViewVisibility = View.GONE; |
| 422 | mTransparentRegion = new Region(); |
| 423 | mPreviousTransparentRegion = new Region(); |
| 424 | 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] | 425 | mAdded = false; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 426 | mAttachInfo = new View.AttachInfo(mWindowSession, mWindow, display, this, mHandler, this); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 427 | mAccessibilityManager = AccessibilityManager.getInstance(context); |
| 428 | mAccessibilityInteractionConnectionManager = |
| 429 | new AccessibilityInteractionConnectionManager(); |
Svetoslav Ganov | 00d0c14 | 2012-02-24 11:30:49 -0800 | [diff] [blame] | 430 | mAccessibilityManager.addAccessibilityStateChangeListener( |
| 431 | mAccessibilityInteractionConnectionManager); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 432 | mHighContrastTextManager = new HighContrastTextManager(); |
| 433 | mAccessibilityManager.addHighTextContrastStateChangeListener( |
| 434 | mHighContrastTextManager); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | mViewConfiguration = ViewConfiguration.get(context); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 436 | mDensity = context.getResources().getDisplayMetrics().densityDpi; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 437 | mNoncompatDensity = context.getResources().getDisplayMetrics().noncompatDensityDpi; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 438 | mFallbackEventHandler = new PhoneFallbackEventHandler(context); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 439 | mChoreographer = Choreographer.getInstance(); |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 440 | mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 441 | loadSystemProperties(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 442 | } |
| 443 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 444 | public static void addFirstDrawHandler(Runnable callback) { |
| 445 | synchronized (sFirstDrawHandlers) { |
| 446 | if (!sFirstDrawComplete) { |
| 447 | sFirstDrawHandlers.add(callback); |
| 448 | } |
| 449 | } |
| 450 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 451 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 452 | public static void addConfigCallback(ComponentCallbacks callback) { |
| 453 | synchronized (sConfigCallbacks) { |
| 454 | sConfigCallbacks.add(callback); |
| 455 | } |
| 456 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 457 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 458 | public void addWindowCallbacks(WindowCallbacks callback) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 459 | if (USE_MT_RENDERER) { |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 460 | synchronized (mWindowCallbacks) { |
| 461 | mWindowCallbacks.add(callback); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | } |
| 465 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 466 | public void removeWindowCallbacks(WindowCallbacks callback) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 467 | if (USE_MT_RENDERER) { |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 468 | synchronized (mWindowCallbacks) { |
| 469 | mWindowCallbacks.remove(callback); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 474 | public void reportDrawFinish() { |
| 475 | if (mWindowDrawCountDown != null) { |
| 476 | mWindowDrawCountDown.countDown(); |
| 477 | } |
| 478 | } |
| 479 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | // FIXME for perf testing only |
| 481 | private boolean mProfile = false; |
| 482 | |
| 483 | /** |
| 484 | * Call this to profile the next traversal call. |
| 485 | * FIXME for perf testing only. Remove eventually |
| 486 | */ |
| 487 | public void profile() { |
| 488 | mProfile = true; |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * Indicates whether we are in touch mode. Calling this method triggers an IPC |
| 493 | * call and should be avoided whenever possible. |
| 494 | * |
| 495 | * @return True, if the device is in touch mode, false otherwise. |
| 496 | * |
| 497 | * @hide |
| 498 | */ |
| 499 | static boolean isInTouchMode() { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 500 | IWindowSession windowSession = WindowManagerGlobal.peekWindowSession(); |
| 501 | if (windowSession != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 503 | return windowSession.getInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | } catch (RemoteException e) { |
| 505 | } |
| 506 | } |
| 507 | return false; |
| 508 | } |
| 509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | /** |
| 511 | * We have one child |
| 512 | */ |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 513 | 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] | 514 | synchronized (this) { |
| 515 | if (mView == null) { |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 516 | mView = view; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 517 | |
| 518 | mAttachInfo.mDisplayState = mDisplay.getState(); |
| 519 | mDisplayManager.registerDisplayListener(mDisplayListener, mHandler); |
| 520 | |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 521 | mViewLayoutDirectionInitial = mView.getRawLayoutDirection(); |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 522 | mFallbackEventHandler.setView(view); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 523 | mWindowAttributes.copyFrom(attrs); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 524 | if (mWindowAttributes.packageName == null) { |
| 525 | mWindowAttributes.packageName = mBasePackageName; |
| 526 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 527 | attrs = mWindowAttributes; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 528 | setTag(); |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 529 | // Keep track of the actual window flags supplied by the client. |
| 530 | mClientWindowLayoutFlags = attrs.flags; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 531 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 532 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 533 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 534 | if (view instanceof RootViewSurfaceTaker) { |
| 535 | mSurfaceHolderCallback = |
| 536 | ((RootViewSurfaceTaker)view).willYouTakeTheSurface(); |
| 537 | if (mSurfaceHolderCallback != null) { |
| 538 | mSurfaceHolder = new TakenSurfaceHolder(); |
Dianne Hackborn | 289b9b6 | 2010-07-09 11:44:11 -0700 | [diff] [blame] | 539 | mSurfaceHolder.setFormat(PixelFormat.UNKNOWN); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 540 | } |
| 541 | } |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 542 | |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 543 | // Compute surface insets required to draw at specified Z value. |
| 544 | // TODO: Use real shadow insets for a constant max Z. |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 545 | if (!attrs.hasManualSurfaceInsets) { |
| 546 | final int surfaceInset = (int) Math.ceil(view.getZ() * 2); |
| 547 | attrs.surfaceInsets.set(surfaceInset, surfaceInset, surfaceInset, surfaceInset); |
| 548 | } |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 549 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 550 | CompatibilityInfo compatibilityInfo = mDisplayAdjustments.getCompatibilityInfo(); |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 551 | mTranslator = compatibilityInfo.getTranslator(); |
| 552 | |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 553 | // If the application owns the surface, don't enable hardware acceleration |
| 554 | if (mSurfaceHolder == null) { |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 555 | enableHardwareAcceleration(attrs); |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 556 | } |
| 557 | |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 558 | boolean restore = false; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 559 | if (mTranslator != null) { |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 560 | mSurface.setCompatibilityTranslator(mTranslator); |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 561 | restore = true; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 562 | attrs.backup(); |
| 563 | mTranslator.translateWindowLayout(attrs); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 564 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 565 | if (DEBUG_LAYOUT) Log.d(mTag, "WindowLayout in setView:" + attrs); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 566 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 567 | if (!compatibilityInfo.supportsScreen()) { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 568 | attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 569 | mLastInCompatMode = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 570 | } |
| 571 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | mSoftInputMode = attrs.softInputMode; |
| 573 | mWindowAttributesChanged = true; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 574 | mWindowAttributesChangesFlag = WindowManager.LayoutParams.EVERYTHING_CHANGED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | mAttachInfo.mRootView = view; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 576 | mAttachInfo.mScalingRequired = mTranslator != null; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 577 | mAttachInfo.mApplicationScale = |
| 578 | mTranslator == null ? 1.0f : mTranslator.applicationScale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | if (panelParentView != null) { |
| 580 | mAttachInfo.mPanelParentWindowToken |
| 581 | = panelParentView.getApplicationWindowToken(); |
| 582 | } |
| 583 | mAdded = true; |
| 584 | int res; /* = WindowManagerImpl.ADD_OKAY; */ |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 585 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | // Schedule the first layout -before- adding to the window |
| 587 | // manager, to make sure we do the relayout before receiving |
| 588 | // any other events from the system. |
| 589 | requestLayout(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 590 | if ((mWindowAttributes.inputFeatures |
| 591 | & WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) { |
| 592 | mInputChannel = new InputChannel(); |
| 593 | } |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 594 | mForceDecorViewVisibility = (mWindowAttributes.privateFlags |
| 595 | & PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | try { |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 597 | mOrigWindowType = mWindowAttributes.type; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 598 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 599 | collectViewAttributes(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 600 | res = mWindowSession.addToDisplay(mWindow, mSeq, mWindowAttributes, |
| 601 | getHostVisibility(), mDisplay.getDisplayId(), |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 602 | mAttachInfo.mContentInsets, mAttachInfo.mStableInsets, |
| 603 | mAttachInfo.mOutsets, mInputChannel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | } catch (RemoteException e) { |
| 605 | mAdded = false; |
| 606 | mView = null; |
| 607 | mAttachInfo.mRootView = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 608 | mInputChannel = null; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 609 | mFallbackEventHandler.setView(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 610 | unscheduleTraversals(); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 611 | setAccessibilityFocus(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | throw new RuntimeException("Adding window failed", e); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 613 | } finally { |
| 614 | if (restore) { |
| 615 | attrs.restore(); |
| 616 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 617 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 618 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 619 | if (mTranslator != null) { |
| 620 | mTranslator.translateRectInScreenToAppWindow(mAttachInfo.mContentInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 621 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 622 | mPendingOverscanInsets.set(0, 0, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 623 | mPendingContentInsets.set(mAttachInfo.mContentInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 624 | mPendingStableInsets.set(mAttachInfo.mStableInsets); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | mPendingVisibleInsets.set(0, 0, 0, 0); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 626 | mAttachInfo.mAlwaysConsumeNavBar = |
| 627 | (res & WindowManagerGlobal.ADD_FLAG_ALWAYS_CONSUME_NAV_BAR) != 0; |
| 628 | mPendingAlwaysConsumeNavBar = mAttachInfo.mAlwaysConsumeNavBar; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 629 | if (DEBUG_LAYOUT) Log.v(mTag, "Added window " + mWindow); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 630 | if (res < WindowManagerGlobal.ADD_OKAY) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | mAttachInfo.mRootView = null; |
| 632 | mAdded = false; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 633 | mFallbackEventHandler.setView(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | unscheduleTraversals(); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 635 | setAccessibilityFocus(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | switch (res) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 637 | case WindowManagerGlobal.ADD_BAD_APP_TOKEN: |
| 638 | case WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN: |
| 639 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 640 | "Unable to add window -- token " + attrs.token |
| 641 | + " is not valid; is your activity running?"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 642 | case WindowManagerGlobal.ADD_NOT_APP_TOKEN: |
| 643 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 644 | "Unable to add window -- token " + attrs.token |
| 645 | + " is not for an application"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 646 | case WindowManagerGlobal.ADD_APP_EXITING: |
| 647 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 648 | "Unable to add window -- app for token " + attrs.token |
| 649 | + " is exiting"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 650 | case WindowManagerGlobal.ADD_DUPLICATE_ADD: |
| 651 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 652 | "Unable to add window -- window " + mWindow |
| 653 | + " has already been added"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 654 | case WindowManagerGlobal.ADD_STARTING_NOT_NEEDED: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 655 | // Silently ignore -- we would have just removed it |
| 656 | // right away, anyway. |
| 657 | return; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 658 | case WindowManagerGlobal.ADD_MULTIPLE_SINGLETON: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 659 | throw new WindowManager.BadTokenException("Unable to add window " |
| 660 | + mWindow + " -- another window of type " |
| 661 | + mWindowAttributes.type + " already exists"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 662 | case WindowManagerGlobal.ADD_PERMISSION_DENIED: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 663 | throw new WindowManager.BadTokenException("Unable to add window " |
| 664 | + mWindow + " -- permission denied for window type " |
| 665 | + mWindowAttributes.type); |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 666 | case WindowManagerGlobal.ADD_INVALID_DISPLAY: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 667 | throw new WindowManager.InvalidDisplayException("Unable to add window " |
| 668 | + mWindow + " -- the specified display can not be found"); |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 669 | case WindowManagerGlobal.ADD_INVALID_TYPE: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 670 | throw new WindowManager.InvalidDisplayException("Unable to add window " |
| 671 | + mWindow + " -- the specified window type " |
| 672 | + mWindowAttributes.type + " is not valid"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 673 | } |
| 674 | throw new RuntimeException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 675 | "Unable to add window -- unknown error code " + res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 677 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 678 | if (view instanceof RootViewSurfaceTaker) { |
| 679 | mInputQueueCallback = |
| 680 | ((RootViewSurfaceTaker)view).willYouTakeTheInputQueue(); |
| 681 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 682 | if (mInputChannel != null) { |
| 683 | if (mInputQueueCallback != null) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 684 | mInputQueue = new InputQueue(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 685 | mInputQueueCallback.onInputQueueCreated(mInputQueue); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 686 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 687 | mInputEventReceiver = new WindowInputEventReceiver(mInputChannel, |
| 688 | Looper.myLooper()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 689 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 690 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 691 | view.assignParent(this); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 692 | mAddedTouchMode = (res & WindowManagerGlobal.ADD_FLAG_IN_TOUCH_MODE) != 0; |
| 693 | mAppVisible = (res & WindowManagerGlobal.ADD_FLAG_APP_VISIBLE) != 0; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 694 | |
| 695 | if (mAccessibilityManager.isEnabled()) { |
| 696 | mAccessibilityInteractionConnectionManager.ensureConnection(); |
| 697 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 698 | |
| 699 | if (view.getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 700 | view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 701 | } |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 702 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 703 | // Set up the input pipeline. |
| 704 | CharSequence counterSuffix = attrs.getTitle(); |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 705 | mSyntheticInputStage = new SyntheticInputStage(); |
| 706 | InputStage viewPostImeStage = new ViewPostImeInputStage(mSyntheticInputStage); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 707 | InputStage nativePostImeStage = new NativePostImeInputStage(viewPostImeStage, |
| 708 | "aq:native-post-ime:" + counterSuffix); |
| 709 | InputStage earlyPostImeStage = new EarlyPostImeInputStage(nativePostImeStage); |
| 710 | InputStage imeStage = new ImeInputStage(earlyPostImeStage, |
| 711 | "aq:ime:" + counterSuffix); |
| 712 | InputStage viewPreImeStage = new ViewPreImeInputStage(imeStage); |
| 713 | InputStage nativePreImeStage = new NativePreImeInputStage(viewPreImeStage, |
| 714 | "aq:native-pre-ime:" + counterSuffix); |
| 715 | |
| 716 | mFirstInputStage = nativePreImeStage; |
| 717 | mFirstPostImeInputStage = earlyPostImeStage; |
| 718 | mPendingInputEventQueueLengthCounterName = "aq:pending:" + counterSuffix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | } |
| 722 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 723 | private void setTag() { |
| 724 | final String[] split = mWindowAttributes.getTitle().toString().split("\\."); |
| 725 | if (split.length > 0) { |
| 726 | mTag = TAG + "[" + split[split.length - 1] + "]"; |
| 727 | } |
| 728 | } |
| 729 | |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 730 | /** Whether the window is in local focus mode or not */ |
| 731 | private boolean isInLocalFocusMode() { |
| 732 | return (mWindowAttributes.flags & WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE) != 0; |
| 733 | } |
| 734 | |
Dianne Hackborn | 49b043f | 2015-05-07 14:21:38 -0700 | [diff] [blame] | 735 | public int getWindowFlags() { |
| 736 | return mWindowAttributes.flags; |
| 737 | } |
| 738 | |
Dianne Hackborn | ece0f4f | 2015-06-11 13:29:01 -0700 | [diff] [blame] | 739 | public int getDisplayId() { |
| 740 | return mDisplay.getDisplayId(); |
| 741 | } |
| 742 | |
Dianne Hackborn | a7bb6fb | 2015-02-03 18:13:40 -0800 | [diff] [blame] | 743 | public CharSequence getTitle() { |
| 744 | return mWindowAttributes.getTitle(); |
| 745 | } |
| 746 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 747 | void destroyHardwareResources() { |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 748 | if (mAttachInfo.mHardwareRenderer != null) { |
| 749 | mAttachInfo.mHardwareRenderer.destroyHardwareResources(mView); |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 750 | mAttachInfo.mHardwareRenderer.destroy(); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | |
Bo Liu | 845535a | 2014-03-21 12:06:23 -0700 | [diff] [blame] | 754 | public void detachFunctor(long functor) { |
John Reck | 44ac42a | 2014-05-16 14:46:07 -0700 | [diff] [blame] | 755 | if (mAttachInfo.mHardwareRenderer != null) { |
| 756 | // Fence so that any pending invokeFunctor() messages will be processed |
| 757 | // before we return from detachFunctor. |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 758 | mAttachInfo.mHardwareRenderer.stopDrawing(); |
John Reck | 44ac42a | 2014-05-16 14:46:07 -0700 | [diff] [blame] | 759 | } |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 760 | } |
| 761 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 762 | /** |
| 763 | * Schedules the functor for execution in either kModeProcess or |
| 764 | * kModeProcessNoContext, depending on whether or not there is an EGLContext. |
| 765 | * |
| 766 | * @param functor The native functor to invoke |
| 767 | * @param waitForCompletion If true, this will not return until the functor |
| 768 | * has invoked. If false, the functor may be invoked |
| 769 | * asynchronously. |
| 770 | */ |
Hui Shu | 9970aee | 2014-06-23 17:10:30 -0700 | [diff] [blame] | 771 | public void invokeFunctor(long functor, boolean waitForCompletion) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 772 | ThreadedRenderer.invokeFunctor(functor, waitForCompletion); |
Bo Liu | ae738a7 | 2014-04-27 16:22:04 -0700 | [diff] [blame] | 773 | } |
| 774 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 775 | public void registerAnimatingRenderNode(RenderNode animator) { |
| 776 | if (mAttachInfo.mHardwareRenderer != null) { |
| 777 | mAttachInfo.mHardwareRenderer.registerAnimatingRenderNode(animator); |
| 778 | } else { |
| 779 | if (mAttachInfo.mPendingAnimatingRenderNodes == null) { |
| 780 | mAttachInfo.mPendingAnimatingRenderNodes = new ArrayList<RenderNode>(); |
| 781 | } |
| 782 | mAttachInfo.mPendingAnimatingRenderNodes.add(animator); |
| 783 | } |
| 784 | } |
| 785 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 786 | private void enableHardwareAcceleration(WindowManager.LayoutParams attrs) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 787 | mAttachInfo.mHardwareAccelerated = false; |
| 788 | mAttachInfo.mHardwareAccelerationRequested = false; |
Romain Guy | 4f6aff3 | 2011-01-12 16:21:41 -0800 | [diff] [blame] | 789 | |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 790 | // Don't enable hardware acceleration when the application is in compatibility mode |
John Reck | dd58e79 | 2014-04-02 16:54:28 +0000 | [diff] [blame] | 791 | if (mTranslator != null) return; |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 792 | |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 793 | // Try to enable hardware acceleration if requested |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 794 | final boolean hardwareAccelerated = |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 795 | (attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 796 | |
John Reck | dd58e79 | 2014-04-02 16:54:28 +0000 | [diff] [blame] | 797 | if (hardwareAccelerated) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 798 | if (!ThreadedRenderer.isAvailable()) { |
Romain Guy | 1af23a3 | 2011-03-24 16:03:55 -0700 | [diff] [blame] | 799 | return; |
| 800 | } |
| 801 | |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 802 | // Persistent processes (including the system) should not do |
| 803 | // accelerated rendering on low-end devices. In that case, |
| 804 | // sRendererDisabled will be set. In addition, the system process |
| 805 | // itself should never do accelerated rendering. In that case, both |
| 806 | // sRendererDisabled and sSystemRendererDisabled are set. When |
| 807 | // sSystemRendererDisabled is set, PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED |
| 808 | // can be used by code on the system process to escape that and enable |
| 809 | // HW accelerated drawing. (This is basically for the lock screen.) |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 810 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 811 | final boolean fakeHwAccelerated = (attrs.privateFlags & |
| 812 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED) != 0; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 813 | final boolean forceHwAccelerated = (attrs.privateFlags & |
| 814 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED) != 0; |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 815 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 816 | if (fakeHwAccelerated) { |
| 817 | // This is exclusively for the preview windows the window manager |
| 818 | // shows for launching applications, so they will look more like |
| 819 | // the app being launched. |
| 820 | mAttachInfo.mHardwareAccelerationRequested = true; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 821 | } else if (!ThreadedRenderer.sRendererDisabled |
| 822 | || (ThreadedRenderer.sSystemRendererDisabled && forceHwAccelerated)) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 823 | if (mAttachInfo.mHardwareRenderer != null) { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 824 | mAttachInfo.mHardwareRenderer.destroy(); |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 825 | } |
| 826 | |
Alan Viverette | 2b12b58 | 2014-10-29 11:11:40 -0700 | [diff] [blame] | 827 | final Rect insets = attrs.surfaceInsets; |
Alan Viverette | 2cd23e6 | 2014-11-04 17:04:02 -0800 | [diff] [blame] | 828 | final boolean hasSurfaceInsets = insets.left != 0 || insets.right != 0 |
| 829 | || insets.top != 0 || insets.bottom != 0; |
Alan Viverette | 2b12b58 | 2014-10-29 11:11:40 -0700 | [diff] [blame] | 830 | final boolean translucent = attrs.format != PixelFormat.OPAQUE || hasSurfaceInsets; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 831 | mAttachInfo.mHardwareRenderer = ThreadedRenderer.create(mContext, translucent); |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 832 | if (mAttachInfo.mHardwareRenderer != null) { |
| 833 | mAttachInfo.mHardwareRenderer.setName(attrs.getTitle().toString()); |
| 834 | mAttachInfo.mHardwareAccelerated = |
| 835 | mAttachInfo.mHardwareAccelerationRequested = true; |
| 836 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | } |
| 840 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | public View getView() { |
| 842 | return mView; |
| 843 | } |
| 844 | |
| 845 | final WindowLeaked getLocation() { |
| 846 | return mLocation; |
| 847 | } |
| 848 | |
| 849 | void setLayoutParams(WindowManager.LayoutParams attrs, boolean newView) { |
| 850 | synchronized (this) { |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 851 | final int oldInsetLeft = mWindowAttributes.surfaceInsets.left; |
| 852 | final int oldInsetTop = mWindowAttributes.surfaceInsets.top; |
| 853 | final int oldInsetRight = mWindowAttributes.surfaceInsets.right; |
| 854 | final int oldInsetBottom = mWindowAttributes.surfaceInsets.bottom; |
| 855 | final int oldSoftInputMode = mWindowAttributes.softInputMode; |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 856 | final boolean oldHasManualSurfaceInsets = mWindowAttributes.hasManualSurfaceInsets; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 857 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 858 | // Keep track of the actual window flags supplied by the client. |
| 859 | mClientWindowLayoutFlags = attrs.flags; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 860 | |
| 861 | // Preserve compatible window flag if exists. |
| 862 | final int compatibleWindowFlag = mWindowAttributes.privateFlags |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 863 | & WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 864 | |
| 865 | // Transfer over system UI visibility values as they carry current state. |
Craig Mautner | 3fe38c0 | 2012-05-03 17:28:09 -0700 | [diff] [blame] | 866 | attrs.systemUiVisibility = mWindowAttributes.systemUiVisibility; |
| 867 | attrs.subtreeSystemUiVisibility = mWindowAttributes.subtreeSystemUiVisibility; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 868 | |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 869 | mWindowAttributesChangesFlag = mWindowAttributes.copyFrom(attrs); |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 870 | if ((mWindowAttributesChangesFlag |
| 871 | & WindowManager.LayoutParams.TRANSLUCENT_FLAGS_CHANGED) != 0) { |
| 872 | // Recompute system ui visibility. |
| 873 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 874 | } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 875 | if (mWindowAttributes.packageName == null) { |
| 876 | mWindowAttributes.packageName = mBasePackageName; |
| 877 | } |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 878 | mWindowAttributes.privateFlags |= compatibleWindowFlag; |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 879 | |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 880 | // Restore old surface insets. |
| 881 | mWindowAttributes.surfaceInsets.set( |
| 882 | oldInsetLeft, oldInsetTop, oldInsetRight, oldInsetBottom); |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 883 | mWindowAttributes.hasManualSurfaceInsets = oldHasManualSurfaceInsets; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 884 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 885 | applyKeepScreenOnFlag(mWindowAttributes); |
| 886 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 887 | if (newView) { |
| 888 | mSoftInputMode = attrs.softInputMode; |
| 889 | requestLayout(); |
| 890 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 891 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 892 | // Don't lose the mode we last auto-computed. |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 893 | if ((attrs.softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 894 | == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED) { |
| 895 | mWindowAttributes.softInputMode = (mWindowAttributes.softInputMode |
| 896 | & ~WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 897 | | (oldSoftInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 898 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 900 | mWindowAttributesChanged = true; |
| 901 | scheduleTraversals(); |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | void handleAppVisibility(boolean visible) { |
| 906 | if (mAppVisible != visible) { |
| 907 | mAppVisible = visible; |
| 908 | scheduleTraversals(); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 909 | if (!mAppVisible) { |
| 910 | WindowManagerGlobal.trimForeground(); |
| 911 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | } |
| 913 | } |
| 914 | |
| 915 | void handleGetNewSurface() { |
| 916 | mNewSurfaceNeeded = true; |
| 917 | mFullRedrawNeeded = true; |
| 918 | scheduleTraversals(); |
| 919 | } |
| 920 | |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 921 | private final DisplayListener mDisplayListener = new DisplayListener() { |
| 922 | @Override |
| 923 | public void onDisplayChanged(int displayId) { |
| 924 | if (mView != null && mDisplay.getDisplayId() == displayId) { |
| 925 | final int oldDisplayState = mAttachInfo.mDisplayState; |
| 926 | final int newDisplayState = mDisplay.getState(); |
| 927 | if (oldDisplayState != newDisplayState) { |
| 928 | mAttachInfo.mDisplayState = newDisplayState; |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 929 | pokeDrawLockIfNeeded(); |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 930 | if (oldDisplayState != Display.STATE_UNKNOWN) { |
| 931 | final int oldScreenState = toViewScreenState(oldDisplayState); |
| 932 | final int newScreenState = toViewScreenState(newDisplayState); |
| 933 | if (oldScreenState != newScreenState) { |
| 934 | mView.dispatchScreenStateChanged(newScreenState); |
| 935 | } |
| 936 | if (oldDisplayState == Display.STATE_OFF) { |
| 937 | // Draw was suppressed so we need to for it to happen here. |
| 938 | mFullRedrawNeeded = true; |
| 939 | scheduleTraversals(); |
| 940 | } |
| 941 | } |
| 942 | } |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 943 | } |
| 944 | } |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 945 | |
| 946 | @Override |
| 947 | public void onDisplayRemoved(int displayId) { |
| 948 | } |
| 949 | |
| 950 | @Override |
| 951 | public void onDisplayAdded(int displayId) { |
| 952 | } |
| 953 | |
| 954 | private int toViewScreenState(int displayState) { |
| 955 | return displayState == Display.STATE_OFF ? |
| 956 | View.SCREEN_STATE_OFF : View.SCREEN_STATE_ON; |
| 957 | } |
| 958 | }; |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 959 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 960 | void pokeDrawLockIfNeeded() { |
| 961 | final int displayState = mAttachInfo.mDisplayState; |
| 962 | if (mView != null && mAdded && mTraversalScheduled |
| 963 | && (displayState == Display.STATE_DOZE |
| 964 | || displayState == Display.STATE_DOZE_SUSPEND)) { |
| 965 | try { |
| 966 | mWindowSession.pokeDrawLock(mWindow); |
| 967 | } catch (RemoteException ex) { |
| 968 | // System server died, oh well. |
| 969 | } |
| 970 | } |
| 971 | } |
| 972 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 973 | @Override |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 974 | public void requestFitSystemWindows() { |
| 975 | checkThread(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 976 | mApplyInsetsRequested = true; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 977 | scheduleTraversals(); |
| 978 | } |
| 979 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 980 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | public void requestLayout() { |
Chet Haase | 3efa7b5 | 2012-12-03 08:33:17 -0800 | [diff] [blame] | 982 | if (!mHandlingLayoutInLayoutRequest) { |
| 983 | checkThread(); |
| 984 | mLayoutRequested = true; |
| 985 | scheduleTraversals(); |
| 986 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 987 | } |
| 988 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 989 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 990 | public boolean isLayoutRequested() { |
| 991 | return mLayoutRequested; |
| 992 | } |
| 993 | |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 994 | void invalidate() { |
| 995 | mDirty.set(0, 0, mWidth, mHeight); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 996 | if (!mWillDrawSoon) { |
| 997 | scheduleTraversals(); |
| 998 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 999 | } |
| 1000 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 1001 | void invalidateWorld(View view) { |
| 1002 | view.invalidate(); |
| 1003 | if (view instanceof ViewGroup) { |
Romain Guy | f84208f | 2012-09-13 22:50:18 -0700 | [diff] [blame] | 1004 | ViewGroup parent = (ViewGroup) view; |
| 1005 | for (int i = 0; i < parent.getChildCount(); i++) { |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 1006 | invalidateWorld(parent.getChildAt(i)); |
| 1007 | } |
| 1008 | } |
| 1009 | } |
| 1010 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 1011 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | public void invalidateChild(View child, Rect dirty) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1013 | invalidateChildInParent(null, dirty); |
| 1014 | } |
| 1015 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1016 | @Override |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1017 | public ViewParent invalidateChildInParent(int[] location, Rect dirty) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | checkThread(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1019 | if (DEBUG_DRAW) Log.v(mTag, "Invalidate child: " + dirty); |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1020 | |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1021 | if (dirty == null) { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1022 | invalidate(); |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1023 | return null; |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1024 | } else if (dirty.isEmpty() && !mIsAnimating) { |
Chet Haase | 05e91ed | 2012-07-03 14:17:57 -0700 | [diff] [blame] | 1025 | return null; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1026 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1027 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1028 | if (mCurScrollY != 0 || mTranslator != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1029 | mTempRect.set(dirty); |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1030 | dirty = mTempRect; |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1031 | if (mCurScrollY != 0) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1032 | dirty.offset(0, -mCurScrollY); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1033 | } |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1034 | if (mTranslator != null) { |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1035 | mTranslator.translateRectInAppWindowToScreen(dirty); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1036 | } |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1037 | if (mAttachInfo.mScalingRequired) { |
| 1038 | dirty.inset(-1, -1); |
| 1039 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1041 | |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 1042 | invalidateRectOnScreen(dirty); |
| 1043 | |
| 1044 | return null; |
| 1045 | } |
| 1046 | |
| 1047 | private void invalidateRectOnScreen(Rect dirty) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1048 | final Rect localDirty = mDirty; |
| 1049 | if (!localDirty.isEmpty() && !localDirty.contains(dirty)) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 1050 | mAttachInfo.mSetIgnoreDirtyState = true; |
Romain Guy | 7d69594 | 2010-12-01 17:22:29 -0800 | [diff] [blame] | 1051 | mAttachInfo.mIgnoreDirtyState = true; |
| 1052 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1053 | |
| 1054 | // Add the new dirty rect to the current one |
| 1055 | localDirty.union(dirty.left, dirty.top, dirty.right, dirty.bottom); |
| 1056 | // Intersect with the bounds of the window to skip |
| 1057 | // updates that lie outside of the visible region |
Romain Guy | 7b2f8b8 | 2012-03-19 17:18:54 -0700 | [diff] [blame] | 1058 | final float appScale = mAttachInfo.mApplicationScale; |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1059 | final boolean intersected = localDirty.intersect(0, 0, |
| 1060 | (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f)); |
| 1061 | if (!intersected) { |
Chet Haase | b78ee0e | 2012-10-17 11:32:01 -0700 | [diff] [blame] | 1062 | localDirty.setEmpty(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | } |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1064 | if (!mWillDrawSoon && (intersected || mIsAnimating)) { |
| 1065 | scheduleTraversals(); |
| 1066 | } |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 1067 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1068 | |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 1069 | public void setIsAmbientMode(boolean ambient) { |
| 1070 | mIsAmbientMode = ambient; |
| 1071 | } |
| 1072 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1073 | void setWindowStopped(boolean stopped) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1074 | if (mStopped != stopped) { |
| 1075 | mStopped = stopped; |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1076 | if (!mStopped) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1077 | scheduleTraversals(); |
John Reck | d9b1607 | 2016-02-23 10:35:19 -0800 | [diff] [blame] | 1078 | } else { |
John Reck | f4db3d2 | 2016-02-26 12:58:17 -0800 | [diff] [blame] | 1079 | if (mAttachInfo.mHardwareRenderer != null) { |
Wale Ogunwale | e4f131a | 2016-03-07 07:33:56 -0800 | [diff] [blame] | 1080 | if (DEBUG_DRAW) Log.d(mTag, "WindowStopped on " + getTitle()); |
John Reck | f4db3d2 | 2016-02-26 12:58:17 -0800 | [diff] [blame] | 1081 | mAttachInfo.mHardwareRenderer.updateSurface(null); |
John Reck | fc73686 | 2016-02-26 15:01:52 -0800 | [diff] [blame] | 1082 | mAttachInfo.mHardwareRenderer.destroyHardwareResources(mView); |
John Reck | f4db3d2 | 2016-02-26 12:58:17 -0800 | [diff] [blame] | 1083 | } |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1088 | /** |
| 1089 | * Block the input events during an Activity Transition. The KEYCODE_BACK event is allowed |
| 1090 | * through to allow quick reversal of the Activity Transition. |
| 1091 | * |
| 1092 | * @param paused true to pause, false to resume. |
| 1093 | */ |
| 1094 | public void setPausedForTransition(boolean paused) { |
| 1095 | mPausedForTransition = paused; |
| 1096 | } |
| 1097 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1098 | @Override |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1099 | public ViewParent getParent() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1100 | return null; |
| 1101 | } |
| 1102 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1103 | @Override |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1104 | 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] | 1105 | if (child != mView) { |
| 1106 | throw new RuntimeException("child is not mine, honest!"); |
| 1107 | } |
| 1108 | // Note: don't apply scroll offset, because we want to know its |
| 1109 | // visibility in the virtual canvas being given to the view hierarchy. |
| 1110 | return r.intersect(0, 0, mWidth, mHeight); |
| 1111 | } |
| 1112 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1113 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | public void bringChildToFront(View child) { |
| 1115 | } |
| 1116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1117 | int getHostVisibility() { |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 1118 | return (mAppVisible || mForceDecorViewVisibility) ? mView.getVisibility() : View.GONE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1120 | |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 1121 | /** |
| 1122 | * Add LayoutTransition to the list of transitions to be started in the next traversal. |
| 1123 | * This list will be cleared after the transitions on the list are start()'ed. These |
| 1124 | * transitionsa re added by LayoutTransition itself when it sets up animations. The setup |
| 1125 | * happens during the layout phase of traversal, which we want to complete before any of the |
| 1126 | * animations are started (because those animations may side-effect properties that layout |
| 1127 | * depends upon, like the bounding rectangles of the affected views). So we add the transition |
| 1128 | * to the list and it is started just prior to starting the drawing phase of traversal. |
| 1129 | * |
| 1130 | * @param transition The LayoutTransition to be started on the next traversal. |
| 1131 | * |
| 1132 | * @hide |
| 1133 | */ |
| 1134 | public void requestTransitionStart(LayoutTransition transition) { |
| 1135 | if (mPendingTransitions == null || !mPendingTransitions.contains(transition)) { |
| 1136 | if (mPendingTransitions == null) { |
| 1137 | mPendingTransitions = new ArrayList<LayoutTransition>(); |
| 1138 | } |
| 1139 | mPendingTransitions.add(transition); |
| 1140 | } |
| 1141 | } |
| 1142 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1143 | /** |
| 1144 | * Notifies the HardwareRenderer that a new frame will be coming soon. |
| 1145 | * Currently only {@link ThreadedRenderer} cares about this, and uses |
| 1146 | * this knowledge to adjust the scheduling of off-thread animations |
| 1147 | */ |
| 1148 | void notifyRendererOfFramePending() { |
| 1149 | if (mAttachInfo.mHardwareRenderer != null) { |
| 1150 | mAttachInfo.mHardwareRenderer.notifyFramePending(); |
| 1151 | } |
| 1152 | } |
| 1153 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1154 | void scheduleTraversals() { |
| 1155 | if (!mTraversalScheduled) { |
| 1156 | mTraversalScheduled = true; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1157 | mTraversalBarrier = mHandler.getLooper().getQueue().postSyncBarrier(); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1158 | mChoreographer.postCallback( |
| 1159 | Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 1160 | if (!mUnbufferedInputDispatch) { |
| 1161 | scheduleConsumeBatchedInput(); |
| 1162 | } |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1163 | notifyRendererOfFramePending(); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 1164 | pokeDrawLockIfNeeded(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1165 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1166 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1167 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1168 | void unscheduleTraversals() { |
| 1169 | if (mTraversalScheduled) { |
| 1170 | mTraversalScheduled = false; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1171 | mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1172 | mChoreographer.removeCallbacks( |
| 1173 | Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | void doTraversal() { |
| 1178 | if (mTraversalScheduled) { |
| 1179 | mTraversalScheduled = false; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1180 | mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1181 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1182 | if (mProfile) { |
| 1183 | Debug.startMethodTracing("ViewAncestor"); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1184 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1185 | |
Chris Craik | e22c59b | 2015-05-21 18:33:37 -0700 | [diff] [blame] | 1186 | performTraversals(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1187 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1188 | if (mProfile) { |
| 1189 | Debug.stopMethodTracing(); |
| 1190 | mProfile = false; |
| 1191 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1195 | private void applyKeepScreenOnFlag(WindowManager.LayoutParams params) { |
| 1196 | // Update window's global keep screen on flag: if a view has requested |
| 1197 | // that the screen be kept on, then it is always set; otherwise, it is |
| 1198 | // set to whatever the client last requested for the global state. |
| 1199 | if (mAttachInfo.mKeepScreenOn) { |
| 1200 | params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
| 1201 | } else { |
| 1202 | params.flags = (params.flags&~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) |
| 1203 | | (mClientWindowLayoutFlags&WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
| 1204 | } |
| 1205 | } |
| 1206 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1207 | private boolean collectViewAttributes() { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1208 | if (mAttachInfo.mRecomputeGlobalAttributes) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1209 | //Log.i(mTag, "Computing view hierarchy attributes!"); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1210 | mAttachInfo.mRecomputeGlobalAttributes = false; |
| 1211 | boolean oldScreenOn = mAttachInfo.mKeepScreenOn; |
| 1212 | mAttachInfo.mKeepScreenOn = false; |
| 1213 | mAttachInfo.mSystemUiVisibility = 0; |
| 1214 | mAttachInfo.mHasSystemUiListeners = false; |
| 1215 | mView.dispatchCollectViewAttributes(mAttachInfo, 0); |
| 1216 | mAttachInfo.mSystemUiVisibility &= ~mAttachInfo.mDisabledSystemUiVisibility; |
Craig Mautner | 7eac0f5 | 2012-09-13 13:14:14 -0700 | [diff] [blame] | 1217 | WindowManager.LayoutParams params = mWindowAttributes; |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1218 | mAttachInfo.mSystemUiVisibility |= getImpliedSystemUiVisibility(params); |
| 1219 | if (mAttachInfo.mKeepScreenOn != oldScreenOn |
| 1220 | || mAttachInfo.mSystemUiVisibility != params.subtreeSystemUiVisibility |
| 1221 | || mAttachInfo.mHasSystemUiListeners != params.hasSystemUiListeners) { |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1222 | applyKeepScreenOnFlag(params); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1223 | params.subtreeSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
| 1224 | params.hasSystemUiListeners = mAttachInfo.mHasSystemUiListeners; |
| 1225 | mView.dispatchWindowSystemUiVisiblityChanged(mAttachInfo.mSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1226 | return true; |
| 1227 | } |
| 1228 | } |
| 1229 | return false; |
| 1230 | } |
| 1231 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 1232 | private int getImpliedSystemUiVisibility(WindowManager.LayoutParams params) { |
| 1233 | int vis = 0; |
| 1234 | // Translucent decor window flags imply stable system ui visibility. |
| 1235 | if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) != 0) { |
| 1236 | vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 1237 | } |
| 1238 | if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) != 0) { |
| 1239 | vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1240 | } |
| 1241 | return vis; |
| 1242 | } |
| 1243 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1244 | private boolean measureHierarchy(final View host, final WindowManager.LayoutParams lp, |
| 1245 | final Resources res, final int desiredWindowWidth, final int desiredWindowHeight) { |
| 1246 | int childWidthMeasureSpec; |
| 1247 | int childHeightMeasureSpec; |
| 1248 | boolean windowSizeMayChange = false; |
| 1249 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1250 | if (DEBUG_ORIENTATION || DEBUG_LAYOUT) Log.v(mTag, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1251 | "Measuring " + host + " in display " + desiredWindowWidth |
| 1252 | + "x" + desiredWindowHeight + "..."); |
| 1253 | |
| 1254 | boolean goodMeasure = false; |
| 1255 | if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) { |
| 1256 | // On large screens, we don't want to allow dialogs to just |
| 1257 | // stretch to fill the entire width of the screen to display |
| 1258 | // one line of text. First try doing the layout at a smaller |
| 1259 | // size to see if it will fit. |
| 1260 | final DisplayMetrics packageMetrics = res.getDisplayMetrics(); |
| 1261 | res.getValue(com.android.internal.R.dimen.config_prefDialogWidth, mTmpValue, true); |
| 1262 | int baseSize = 0; |
| 1263 | if (mTmpValue.type == TypedValue.TYPE_DIMENSION) { |
| 1264 | baseSize = (int)mTmpValue.getDimension(packageMetrics); |
| 1265 | } |
Filip Gruszczynski | 1937a4c | 2016-01-19 16:17:13 -0800 | [diff] [blame] | 1266 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": baseSize=" + baseSize |
| 1267 | + ", desiredWindowWidth=" + desiredWindowWidth); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1268 | if (baseSize != 0 && desiredWindowWidth > baseSize) { |
| 1269 | childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width); |
| 1270 | childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1271 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1272 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured (" |
Filip Gruszczynski | 1937a4c | 2016-01-19 16:17:13 -0800 | [diff] [blame] | 1273 | + host.getMeasuredWidth() + "," + host.getMeasuredHeight() |
| 1274 | + ") from width spec: " + MeasureSpec.toString(childWidthMeasureSpec) |
| 1275 | + " and height spec: " + MeasureSpec.toString(childHeightMeasureSpec)); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1276 | if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) { |
| 1277 | goodMeasure = true; |
| 1278 | } else { |
| 1279 | // Didn't fit in that size... try expanding a bit. |
| 1280 | baseSize = (baseSize+desiredWindowWidth)/2; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1281 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": next baseSize=" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1282 | + baseSize); |
| 1283 | childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1284 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1285 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured (" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1286 | + host.getMeasuredWidth() + "," + host.getMeasuredHeight() + ")"); |
| 1287 | if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1288 | if (DEBUG_DIALOG) Log.v(mTag, "Good!"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1289 | goodMeasure = true; |
| 1290 | } |
| 1291 | } |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | if (!goodMeasure) { |
| 1296 | childWidthMeasureSpec = getRootMeasureSpec(desiredWindowWidth, lp.width); |
| 1297 | childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1298 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1299 | if (mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) { |
| 1300 | windowSizeMayChange = true; |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | if (DBG) { |
| 1305 | System.out.println("======================================"); |
| 1306 | System.out.println("performTraversals -- after measure"); |
| 1307 | host.debug(); |
| 1308 | } |
| 1309 | |
| 1310 | return windowSizeMayChange; |
| 1311 | } |
| 1312 | |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1313 | /** |
| 1314 | * Modifies the input matrix such that it maps view-local coordinates to |
| 1315 | * on-screen coordinates. |
| 1316 | * |
| 1317 | * @param m input matrix to modify |
| 1318 | */ |
| 1319 | void transformMatrixToGlobal(Matrix m) { |
Dake Gu | 7bf379c | 2014-07-15 16:29:38 -0700 | [diff] [blame] | 1320 | m.preTranslate(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | /** |
| 1324 | * Modifies the input matrix such that it maps on-screen coordinates to |
| 1325 | * view-local coordinates. |
| 1326 | * |
| 1327 | * @param m input matrix to modify |
| 1328 | */ |
| 1329 | void transformMatrixToLocal(Matrix m) { |
Dake Gu | 7bf379c | 2014-07-15 16:29:38 -0700 | [diff] [blame] | 1330 | m.postTranslate(-mAttachInfo.mWindowLeft, -mAttachInfo.mWindowTop); |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1331 | } |
| 1332 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1333 | /* package */ WindowInsets getWindowInsets(boolean forceConstruct) { |
| 1334 | if (mLastWindowInsets == null || forceConstruct) { |
| 1335 | mDispatchContentInsets.set(mAttachInfo.mContentInsets); |
| 1336 | mDispatchStableInsets.set(mAttachInfo.mStableInsets); |
| 1337 | Rect contentInsets = mDispatchContentInsets; |
| 1338 | Rect stableInsets = mDispatchStableInsets; |
| 1339 | // For dispatch we preserve old logic, but for direct requests from Views we allow to |
| 1340 | // immediately use pending insets. |
| 1341 | if (!forceConstruct |
| 1342 | && (!mPendingContentInsets.equals(contentInsets) || |
| 1343 | !mPendingStableInsets.equals(stableInsets))) { |
| 1344 | contentInsets = mPendingContentInsets; |
| 1345 | stableInsets = mPendingStableInsets; |
| 1346 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1347 | Rect outsets = mAttachInfo.mOutsets; |
| 1348 | if (outsets.left > 0 || outsets.top > 0 || outsets.right > 0 || outsets.bottom > 0) { |
| 1349 | contentInsets = new Rect(contentInsets.left + outsets.left, |
| 1350 | contentInsets.top + outsets.top, contentInsets.right + outsets.right, |
| 1351 | contentInsets.bottom + outsets.bottom); |
| 1352 | } |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1353 | mLastWindowInsets = new WindowInsets(contentInsets, |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1354 | null /* windowDecorInsets */, stableInsets, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1355 | mContext.getResources().getConfiguration().isScreenRound(), |
| 1356 | mAttachInfo.mAlwaysConsumeNavBar); |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1357 | } |
| 1358 | return mLastWindowInsets; |
| 1359 | } |
| 1360 | |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1361 | void dispatchApplyInsets(View host) { |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1362 | host.dispatchApplyWindowInsets(getWindowInsets(true /* forceConstruct */)); |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1365 | private static boolean shouldUseDisplaySize(final WindowManager.LayoutParams lp) { |
| 1366 | return lp.type == TYPE_STATUS_BAR_PANEL |
| 1367 | || lp.type == TYPE_INPUT_METHOD |
| 1368 | || lp.type == TYPE_VOLUME_OVERLAY; |
| 1369 | } |
| 1370 | |
| 1371 | private int dipToPx(int dip) { |
| 1372 | final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics(); |
| 1373 | return (int) (displayMetrics.density * dip + 0.5f); |
| 1374 | } |
| 1375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1376 | private void performTraversals() { |
| 1377 | // cache mView since it is used so much below... |
| 1378 | final View host = mView; |
| 1379 | |
| 1380 | if (DBG) { |
| 1381 | System.out.println("======================================"); |
| 1382 | System.out.println("performTraversals"); |
| 1383 | host.debug(); |
| 1384 | } |
| 1385 | |
| 1386 | if (host == null || !mAdded) |
| 1387 | return; |
| 1388 | |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 1389 | mIsInTraversal = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1390 | mWillDrawSoon = true; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1391 | boolean windowSizeMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1392 | boolean newSurface = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1393 | boolean surfaceChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1394 | WindowManager.LayoutParams lp = mWindowAttributes; |
| 1395 | |
| 1396 | int desiredWindowWidth; |
| 1397 | int desiredWindowHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1399 | final int viewVisibility = getHostVisibility(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1400 | final boolean viewVisibilityChanged = !mFirst |
| 1401 | && (mViewVisibility != viewVisibility || mNewSurfaceNeeded); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1402 | |
| 1403 | WindowManager.LayoutParams params = null; |
| 1404 | if (mWindowAttributesChanged) { |
| 1405 | mWindowAttributesChanged = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1406 | surfaceChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1407 | params = lp; |
| 1408 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1409 | CompatibilityInfo compatibilityInfo = mDisplayAdjustments.getCompatibilityInfo(); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1410 | if (compatibilityInfo.supportsScreen() == mLastInCompatMode) { |
| 1411 | params = lp; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1412 | mFullRedrawNeeded = true; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1413 | mLayoutRequested = true; |
| 1414 | if (mLastInCompatMode) { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1415 | params.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1416 | mLastInCompatMode = false; |
| 1417 | } else { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1418 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1419 | mLastInCompatMode = true; |
| 1420 | } |
| 1421 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1422 | |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 1423 | mWindowAttributesChangesFlag = 0; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1424 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1425 | Rect frame = mWinFrame; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1426 | if (mFirst) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1427 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1428 | mLayoutRequested = true; |
| 1429 | |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1430 | if (shouldUseDisplaySize(lp)) { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1431 | // NOTE -- system code, won't try to do compat mode. |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1432 | Point size = new Point(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1433 | mDisplay.getRealSize(size); |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1434 | desiredWindowWidth = size.x; |
| 1435 | desiredWindowHeight = size.y; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1436 | } else { |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1437 | Configuration config = mContext.getResources().getConfiguration(); |
| 1438 | desiredWindowWidth = dipToPx(config.screenWidthDp); |
| 1439 | desiredWindowHeight = dipToPx(config.screenHeightDp); |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1440 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1441 | |
Romain Guy | c5d5586 | 2011-01-21 19:01:46 -0800 | [diff] [blame] | 1442 | // We used to use the following condition to choose 32 bits drawing caches: |
| 1443 | // PixelFormat.hasAlpha(lp.format) || lp.format == PixelFormat.RGBX_8888 |
| 1444 | // 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] | 1445 | mAttachInfo.mUse32BitDrawingCache = true; |
| 1446 | mAttachInfo.mHasWindowFocus = false; |
| 1447 | mAttachInfo.mWindowVisibility = viewVisibility; |
| 1448 | mAttachInfo.mRecomputeGlobalAttributes = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1449 | mLastConfiguration.setTo(host.getResources().getConfiguration()); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1450 | mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 1451 | // Set the layout direction if it has not been set before (inherit is the default) |
| 1452 | if (mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) { |
| 1453 | host.setLayoutDirection(mLastConfiguration.getLayoutDirection()); |
| 1454 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1455 | host.dispatchAttachedToWindow(mAttachInfo, 0); |
| 1456 | mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(true); |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1457 | dispatchApplyInsets(host); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1458 | //Log.i(mTag, "Screen on initialized: " + attachInfo.mKeepScreenOn); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1460 | } else { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1461 | desiredWindowWidth = frame.width(); |
| 1462 | desiredWindowHeight = frame.height(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | if (desiredWindowWidth != mWidth || desiredWindowHeight != mHeight) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1464 | if (DEBUG_ORIENTATION) Log.v(mTag, "View " + host + " resized to: " + frame); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1465 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1466 | mLayoutRequested = true; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1467 | windowSizeMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | if (viewVisibilityChanged) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1472 | mAttachInfo.mWindowVisibility = viewVisibility; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1473 | host.dispatchWindowVisibilityChanged(viewVisibility); |
Adam Powell | 9c146bf | 2016-03-15 17:35:00 -0700 | [diff] [blame] | 1474 | host.dispatchVisibilityAggregated(viewVisibility == View.VISIBLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1475 | if (viewVisibility != View.VISIBLE || mNewSurfaceNeeded) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1476 | endDragResizing(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1477 | destroyHardwareResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1478 | } |
| 1479 | if (viewVisibility == View.GONE) { |
| 1480 | // After making a window gone, we will count it as being |
| 1481 | // shown for the first time the next time it gets focus. |
| 1482 | mHasHadWindowFocus = false; |
| 1483 | } |
| 1484 | } |
| 1485 | |
Alan Viverette | 7dbc3bf | 2015-01-28 16:14:36 -0800 | [diff] [blame] | 1486 | // Non-visible windows can't hold accessibility focus. |
| 1487 | if (mAttachInfo.mWindowVisibility != View.VISIBLE) { |
| 1488 | host.clearAccessibilityFocus(); |
| 1489 | } |
| 1490 | |
Chet Haase | b78c284 | 2012-04-19 13:39:50 -0700 | [diff] [blame] | 1491 | // 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] | 1492 | getRunQueue().executeActions(mAttachInfo.mHandler); |
Chet Haase | b78c284 | 2012-04-19 13:39:50 -0700 | [diff] [blame] | 1493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | boolean insetsChanged = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1495 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1496 | boolean layoutRequested = mLayoutRequested && (!mStopped || mReportNextDraw); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1497 | if (layoutRequested) { |
Romain Guy | 15df670 | 2009-08-17 20:17:30 -0700 | [diff] [blame] | 1498 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1499 | final Resources res = mView.getContext().getResources(); |
| 1500 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1501 | if (mFirst) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1502 | // make sure touch mode code executes by setting cached value |
| 1503 | // to opposite of the added touch mode. |
| 1504 | mAttachInfo.mInTouchMode = !mAddedTouchMode; |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 1505 | ensureTouchModeLocally(mAddedTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1507 | if (!mPendingOverscanInsets.equals(mAttachInfo.mOverscanInsets)) { |
| 1508 | insetsChanged = true; |
| 1509 | } |
Dianne Hackborn | fa6b35b | 2011-08-24 17:03:54 -0700 | [diff] [blame] | 1510 | if (!mPendingContentInsets.equals(mAttachInfo.mContentInsets)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | insetsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1513 | if (!mPendingStableInsets.equals(mAttachInfo.mStableInsets)) { |
| 1514 | insetsChanged = true; |
| 1515 | } |
Dianne Hackborn | fa6b35b | 2011-08-24 17:03:54 -0700 | [diff] [blame] | 1516 | if (!mPendingVisibleInsets.equals(mAttachInfo.mVisibleInsets)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1518 | 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] | 1519 | + mAttachInfo.mVisibleInsets); |
| 1520 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1521 | if (!mPendingOutsets.equals(mAttachInfo.mOutsets)) { |
| 1522 | insetsChanged = true; |
| 1523 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1524 | if (mPendingAlwaysConsumeNavBar != mAttachInfo.mAlwaysConsumeNavBar) { |
| 1525 | insetsChanged = true; |
| 1526 | } |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1527 | if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT |
| 1528 | || lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) { |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1529 | windowSizeMayChange = true; |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1530 | |
| 1531 | if (shouldUseDisplaySize(lp)) { |
| 1532 | // NOTE -- system code, won't try to do compat mode. |
| 1533 | Point size = new Point(); |
| 1534 | mDisplay.getRealSize(size); |
| 1535 | desiredWindowWidth = size.x; |
| 1536 | desiredWindowHeight = size.y; |
| 1537 | } else { |
| 1538 | Configuration config = res.getConfiguration(); |
| 1539 | desiredWindowWidth = dipToPx(config.screenWidthDp); |
| 1540 | desiredWindowHeight = dipToPx(config.screenHeightDp); |
| 1541 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1542 | } |
| 1543 | } |
| 1544 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | // Ask host how big it wants to be |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1546 | windowSizeMayChange |= measureHierarchy(host, lp, res, |
| 1547 | desiredWindowWidth, desiredWindowHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1548 | } |
| 1549 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1550 | if (collectViewAttributes()) { |
| 1551 | params = lp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1552 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1553 | if (mAttachInfo.mForceReportNewAttributes) { |
| 1554 | mAttachInfo.mForceReportNewAttributes = false; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1555 | params = lp; |
| 1556 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1557 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1558 | if (mFirst || mAttachInfo.mViewVisibilityChanged) { |
| 1559 | mAttachInfo.mViewVisibilityChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1560 | int resizeMode = mSoftInputMode & |
| 1561 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 1562 | // If we are in auto resize mode, then we need to determine |
| 1563 | // what mode to use now. |
| 1564 | if (resizeMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1565 | final int N = mAttachInfo.mScrollContainers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | for (int i=0; i<N; i++) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1567 | if (mAttachInfo.mScrollContainers.get(i).isShown()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1568 | resizeMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 1569 | } |
| 1570 | } |
| 1571 | if (resizeMode == 0) { |
| 1572 | resizeMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN; |
| 1573 | } |
| 1574 | if ((lp.softInputMode & |
| 1575 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) != resizeMode) { |
| 1576 | lp.softInputMode = (lp.softInputMode & |
| 1577 | ~WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) | |
| 1578 | resizeMode; |
| 1579 | params = lp; |
| 1580 | } |
| 1581 | } |
| 1582 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1583 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1584 | if (params != null) { |
| 1585 | if ((host.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
| 1586 | if (!PixelFormat.formatHasAlpha(params.format)) { |
| 1587 | params.format = PixelFormat.TRANSLUCENT; |
| 1588 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1590 | mAttachInfo.mOverscanRequested = (params.flags |
| 1591 | & WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1592 | } |
| 1593 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1594 | if (mApplyInsetsRequested) { |
| 1595 | mApplyInsetsRequested = false; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1596 | mLastOverscanRequested = mAttachInfo.mOverscanRequested; |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1597 | dispatchApplyInsets(host); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1598 | if (mLayoutRequested) { |
| 1599 | // Short-circuit catching a new layout request here, so |
| 1600 | // we don't need to go through two layout passes when things |
| 1601 | // change due to fitting system windows, which can happen a lot. |
| 1602 | windowSizeMayChange |= measureHierarchy(host, lp, |
| 1603 | mView.getContext().getResources(), |
| 1604 | desiredWindowWidth, desiredWindowHeight); |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | if (layoutRequested) { |
| 1609 | // Clear this now, so that if anything requests a layout in the |
| 1610 | // rest of this function we will catch it and re-run a full |
| 1611 | // layout pass. |
| 1612 | mLayoutRequested = false; |
| 1613 | } |
| 1614 | |
| 1615 | boolean windowShouldResize = layoutRequested && windowSizeMayChange |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1616 | && ((mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) |
Romain Guy | 2e4f426 | 2010-04-06 11:07:52 -0700 | [diff] [blame] | 1617 | || (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT && |
| 1618 | frame.width() < desiredWindowWidth && frame.width() != mWidth) |
| 1619 | || (lp.height == ViewGroup.LayoutParams.WRAP_CONTENT && |
| 1620 | frame.height() < desiredWindowHeight && frame.height() != mHeight)); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1621 | windowShouldResize |= mDragResizing && mResizeMode == RESIZE_MODE_FREEFORM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1622 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1623 | // If the activity was just relaunched, it might have unfrozen the task bounds (while |
| 1624 | // relaunching), so we need to force a call into window manager to pick up the latest |
| 1625 | // bounds. |
| 1626 | windowShouldResize |= mActivityRelaunched; |
| 1627 | |
Jeff Brown | 2e05ec3 | 2013-09-30 15:57:43 -0700 | [diff] [blame] | 1628 | // Determine whether to compute insets. |
| 1629 | // If there are no inset listeners remaining then we may still need to compute |
| 1630 | // 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] | 1631 | final boolean computesInternalInsets = |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1632 | mAttachInfo.mTreeObserver.hasComputeInternalInsetsListeners() |
| 1633 | || mAttachInfo.mHasNonEmptyGivenInternalInsets; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1635 | boolean insetsPending = false; |
| 1636 | int relayoutResult = 0; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1637 | |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 1638 | final boolean isViewVisible = viewVisibility == View.VISIBLE; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1639 | if (mFirst || windowShouldResize || insetsChanged || |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 1640 | viewVisibilityChanged || params != null || mForceNextWindowRelayout) { |
| 1641 | mForceNextWindowRelayout = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1642 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 1643 | if (isViewVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1644 | // If this window is giving internal insets to the window |
| 1645 | // manager, and it is being added or changing its visibility, |
| 1646 | // then we want to first give the window manager "fake" |
| 1647 | // insets to cause it to effectively ignore the content of |
| 1648 | // the window during layout. This avoids it briefly causing |
| 1649 | // other windows to resize/move based on the raw frame of the |
| 1650 | // window, waiting until we can finish laying out this window |
| 1651 | // and get back to the window manager with the ultimately |
| 1652 | // computed insets. |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1653 | insetsPending = computesInternalInsets && (mFirst || viewVisibilityChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1654 | } |
| 1655 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1656 | if (mSurfaceHolder != null) { |
| 1657 | mSurfaceHolder.mSurfaceLock.lock(); |
| 1658 | mDrawingAllowed = true; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1659 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1660 | |
Romain Guy | c361da8 | 2010-10-25 15:29:10 -0700 | [diff] [blame] | 1661 | boolean hwInitialized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1662 | boolean contentInsetsChanged = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1663 | boolean hadSurface = mSurface.isValid(); |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1665 | try { |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1666 | if (DEBUG_LAYOUT) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1667 | Log.i(mTag, "host=w:" + host.getMeasuredWidth() + ", h:" + |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1668 | host.getMeasuredHeight() + ", params=" + params); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1669 | } |
Romain Guy | 2a83f00 | 2011-01-18 18:28:21 -0800 | [diff] [blame] | 1670 | |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 1671 | if (mAttachInfo.mHardwareRenderer != null) { |
| 1672 | // relayoutWindow may decide to destroy mSurface. As that decision |
| 1673 | // happens in WindowManager service, we need to be defensive here |
| 1674 | // and stop using the surface in case it gets destroyed. |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 1675 | if (mAttachInfo.mHardwareRenderer.pauseSurface(mSurface)) { |
| 1676 | // Animations were running so we need to push a frame |
| 1677 | // to resume them |
| 1678 | mDirty.set(0, 0, mWidth, mHeight); |
| 1679 | } |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 1680 | mChoreographer.mFrameInfo.addFlags(FrameInfo.FLAG_WINDOW_LAYOUT_CHANGED); |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 1681 | } |
Romain Guy | 2a83f00 | 2011-01-18 18:28:21 -0800 | [diff] [blame] | 1682 | final int surfaceGenerationId = mSurface.getGenerationId(); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1683 | relayoutResult = relayoutWindow(params, viewVisibility, insetsPending); |
| 1684 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1685 | if (DEBUG_LAYOUT) Log.v(mTag, "relayout: frame=" + frame.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1686 | + " overscan=" + mPendingOverscanInsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1687 | + " content=" + mPendingContentInsets.toShortString() |
| 1688 | + " visible=" + mPendingVisibleInsets.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1689 | + " visible=" + mPendingStableInsets.toShortString() |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 1690 | + " outsets=" + mPendingOutsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1691 | + " surface=" + mSurface); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1692 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1693 | if (mPendingConfiguration.seq != 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1694 | if (DEBUG_CONFIGURATION) Log.v(mTag, "Visible with new config: " |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1695 | + mPendingConfiguration); |
riddle_hsu | 164725c | 2015-11-12 14:07:12 +0800 | [diff] [blame] | 1696 | updateConfiguration(new Configuration(mPendingConfiguration), !mFirst); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1697 | mPendingConfiguration.seq = 0; |
| 1698 | } |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 1699 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1700 | final boolean overscanInsetsChanged = !mPendingOverscanInsets.equals( |
| 1701 | mAttachInfo.mOverscanInsets); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1702 | contentInsetsChanged = !mPendingContentInsets.equals( |
| 1703 | mAttachInfo.mContentInsets); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1704 | final boolean visibleInsetsChanged = !mPendingVisibleInsets.equals( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1705 | mAttachInfo.mVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1706 | final boolean stableInsetsChanged = !mPendingStableInsets.equals( |
| 1707 | mAttachInfo.mStableInsets); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1708 | final boolean outsetsChanged = !mPendingOutsets.equals(mAttachInfo.mOutsets); |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1709 | final boolean surfaceSizeChanged = (relayoutResult |
| 1710 | & WindowManagerGlobal.RELAYOUT_RES_SURFACE_RESIZED) != 0; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1711 | final boolean alwaysConsumeNavBarChanged = |
| 1712 | mPendingAlwaysConsumeNavBar != mAttachInfo.mAlwaysConsumeNavBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1713 | if (contentInsetsChanged) { |
| 1714 | mAttachInfo.mContentInsets.set(mPendingContentInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1715 | 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] | 1716 | + mAttachInfo.mContentInsets); |
| 1717 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1718 | if (overscanInsetsChanged) { |
| 1719 | mAttachInfo.mOverscanInsets.set(mPendingOverscanInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1720 | if (DEBUG_LAYOUT) Log.v(mTag, "Overscan insets changing to: " |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1721 | + mAttachInfo.mOverscanInsets); |
| 1722 | // Need to relayout with content insets. |
| 1723 | contentInsetsChanged = true; |
| 1724 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1725 | if (stableInsetsChanged) { |
| 1726 | mAttachInfo.mStableInsets.set(mPendingStableInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1727 | if (DEBUG_LAYOUT) Log.v(mTag, "Decor insets changing to: " |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1728 | + mAttachInfo.mStableInsets); |
| 1729 | // Need to relayout with content insets. |
| 1730 | contentInsetsChanged = true; |
| 1731 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1732 | if (alwaysConsumeNavBarChanged) { |
| 1733 | mAttachInfo.mAlwaysConsumeNavBar = mPendingAlwaysConsumeNavBar; |
| 1734 | contentInsetsChanged = true; |
| 1735 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1736 | if (contentInsetsChanged || mLastSystemUiVisibility != |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1737 | mAttachInfo.mSystemUiVisibility || mApplyInsetsRequested |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1738 | || mLastOverscanRequested != mAttachInfo.mOverscanRequested |
| 1739 | || outsetsChanged) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1740 | mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1741 | mLastOverscanRequested = mAttachInfo.mOverscanRequested; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1742 | mAttachInfo.mOutsets.set(mPendingOutsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1743 | mApplyInsetsRequested = false; |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1744 | dispatchApplyInsets(host); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1745 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1746 | if (visibleInsetsChanged) { |
| 1747 | mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1748 | 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] | 1749 | + mAttachInfo.mVisibleInsets); |
| 1750 | } |
| 1751 | |
| 1752 | if (!hadSurface) { |
| 1753 | if (mSurface.isValid()) { |
| 1754 | // If we are creating a new surface, then we need to |
| 1755 | // completely redraw it. Also, when we get to the |
| 1756 | // point of drawing it we will hold off and schedule |
| 1757 | // a new traversal instead. This is so we can tell the |
| 1758 | // window manager about all of the windows being displayed |
| 1759 | // before actually drawing them, so it can display then |
| 1760 | // all at once. |
| 1761 | newSurface = true; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1762 | mFullRedrawNeeded = true; |
Jack Palevich | 61a6e68 | 2009-10-09 17:37:50 -0700 | [diff] [blame] | 1763 | mPreviousTransparentRegion.setEmpty(); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1764 | |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 1765 | // Only initialize up-front if transparent regions are not |
| 1766 | // requested, otherwise defer to see if the entire window |
| 1767 | // will be transparent |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1768 | if (mAttachInfo.mHardwareRenderer != null) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1769 | try { |
Romain Guy | 786fc93 | 2012-07-24 16:24:56 -0700 | [diff] [blame] | 1770 | hwInitialized = mAttachInfo.mHardwareRenderer.initialize( |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 1771 | mSurface); |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 1772 | if (hwInitialized && (host.mPrivateFlags |
| 1773 | & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) == 0) { |
| 1774 | // Don't pre-allocate if transparent regions |
| 1775 | // are requested as they may not be needed |
| 1776 | mSurface.allocateBuffers(); |
| 1777 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1778 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 1779 | handleOutOfResourcesException(e); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1780 | return; |
| 1781 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1782 | } |
| 1783 | } |
| 1784 | } else if (!mSurface.isValid()) { |
| 1785 | // If the surface has been removed, then reset the scroll |
| 1786 | // positions. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 1787 | if (mLastScrolledFocus != null) { |
| 1788 | mLastScrolledFocus.clear(); |
| 1789 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1790 | mScrollY = mCurScrollY = 0; |
Adrian Roos | 0e7ae4e | 2014-10-01 15:33:22 +0200 | [diff] [blame] | 1791 | if (mView instanceof RootViewSurfaceTaker) { |
| 1792 | ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY); |
| 1793 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1794 | if (mScroller != null) { |
| 1795 | mScroller.abortAnimation(); |
| 1796 | } |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 1797 | // Our surface is gone |
| 1798 | if (mAttachInfo.mHardwareRenderer != null && |
| 1799 | mAttachInfo.mHardwareRenderer.isEnabled()) { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 1800 | mAttachInfo.mHardwareRenderer.destroy(); |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 1801 | } |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1802 | } else if ((surfaceGenerationId != mSurface.getGenerationId() |
| 1803 | || surfaceSizeChanged) |
| 1804 | && mSurfaceHolder == null |
| 1805 | && mAttachInfo.mHardwareRenderer != null) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1806 | mFullRedrawNeeded = true; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1807 | try { |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1808 | // Need to do updateSurface (which leads to CanvasContext::setSurface and |
| 1809 | // re-create the EGLSurface) if either the Surface changed (as indicated by |
| 1810 | // generation id), or WindowManager changed the surface size. The latter is |
| 1811 | // because on some chips, changing the consumer side's BufferQueue size may |
| 1812 | // not take effect immediately unless we create a new EGLSurface. |
| 1813 | // Note that frame size change doesn't always imply surface size change (eg. |
| 1814 | // drag resizing uses fullscreen surface), need to check surfaceSizeChanged |
| 1815 | // flag from WindowManager. |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 1816 | mAttachInfo.mHardwareRenderer.updateSurface(mSurface); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1817 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 1818 | handleOutOfResourcesException(e); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1819 | return; |
| 1820 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1821 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1822 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1823 | final boolean freeformResizing = (relayoutResult |
| 1824 | & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM) != 0; |
| 1825 | final boolean dockedResizing = (relayoutResult |
| 1826 | & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED) != 0; |
| 1827 | final boolean dragResizing = freeformResizing || dockedResizing; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1828 | if (mDragResizing != dragResizing) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1829 | if (dragResizing) { |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1830 | mResizeMode = freeformResizing |
| 1831 | ? RESIZE_MODE_FREEFORM |
| 1832 | : RESIZE_MODE_DOCKED_DIVIDER; |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame^] | 1833 | startDragResizing(mPendingBackDropFrame, |
| 1834 | mWinFrame.equals(mPendingBackDropFrame), mPendingVisibleInsets, |
| 1835 | mPendingStableInsets, mResizeMode); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1836 | } else { |
| 1837 | // We shouldn't come here, but if we come we should end the resize. |
| 1838 | endDragResizing(); |
| 1839 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1840 | } |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1841 | if (!USE_MT_RENDERER) { |
| 1842 | if (dragResizing) { |
| 1843 | mCanvasOffsetX = mWinFrame.left; |
| 1844 | mCanvasOffsetY = mWinFrame.top; |
| 1845 | } else { |
| 1846 | mCanvasOffsetX = mCanvasOffsetY = 0; |
| 1847 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1848 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1849 | } catch (RemoteException e) { |
| 1850 | } |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 1851 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1852 | if (DEBUG_ORIENTATION) Log.v( |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1853 | TAG, "Relayout returned: frame=" + frame + ", surface=" + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1854 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1855 | mAttachInfo.mWindowLeft = frame.left; |
| 1856 | mAttachInfo.mWindowTop = frame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1857 | |
| 1858 | // !!FIXME!! This next section handles the case where we did not get the |
| 1859 | // window size we asked for. We should avoid this by getting a maximum size from |
| 1860 | // the window session beforehand. |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 1861 | if (mWidth != frame.width() || mHeight != frame.height()) { |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 1862 | mWidth = frame.width(); |
| 1863 | mHeight = frame.height(); |
| 1864 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1865 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1866 | if (mSurfaceHolder != null) { |
| 1867 | // The app owns the surface; tell it about what is going on. |
| 1868 | if (mSurface.isValid()) { |
| 1869 | // XXX .copyFrom() doesn't work! |
| 1870 | //mSurfaceHolder.mSurface.copyFrom(mSurface); |
| 1871 | mSurfaceHolder.mSurface = mSurface; |
| 1872 | } |
Jeff Brown | 30bc34f | 2011-01-25 12:56:56 -0800 | [diff] [blame] | 1873 | mSurfaceHolder.setSurfaceFrameSize(mWidth, mHeight); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1874 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 1875 | if (mSurface.isValid()) { |
| 1876 | if (!hadSurface) { |
| 1877 | mSurfaceHolder.ungetCallbacks(); |
| 1878 | |
| 1879 | mIsCreating = true; |
| 1880 | mSurfaceHolderCallback.surfaceCreated(mSurfaceHolder); |
| 1881 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 1882 | if (callbacks != null) { |
| 1883 | for (SurfaceHolder.Callback c : callbacks) { |
| 1884 | c.surfaceCreated(mSurfaceHolder); |
| 1885 | } |
| 1886 | } |
| 1887 | surfaceChanged = true; |
| 1888 | } |
| 1889 | if (surfaceChanged) { |
| 1890 | mSurfaceHolderCallback.surfaceChanged(mSurfaceHolder, |
| 1891 | lp.format, mWidth, mHeight); |
| 1892 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 1893 | if (callbacks != null) { |
| 1894 | for (SurfaceHolder.Callback c : callbacks) { |
| 1895 | c.surfaceChanged(mSurfaceHolder, lp.format, |
| 1896 | mWidth, mHeight); |
| 1897 | } |
| 1898 | } |
| 1899 | } |
| 1900 | mIsCreating = false; |
| 1901 | } else if (hadSurface) { |
| 1902 | mSurfaceHolder.ungetCallbacks(); |
| 1903 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 1904 | mSurfaceHolderCallback.surfaceDestroyed(mSurfaceHolder); |
| 1905 | if (callbacks != null) { |
| 1906 | for (SurfaceHolder.Callback c : callbacks) { |
| 1907 | c.surfaceDestroyed(mSurfaceHolder); |
| 1908 | } |
| 1909 | } |
| 1910 | mSurfaceHolder.mSurfaceLock.lock(); |
Jozef BABJAK | 93c5b6a | 2011-02-22 09:33:19 +0100 | [diff] [blame] | 1911 | try { |
| 1912 | mSurfaceHolder.mSurface = new Surface(); |
| 1913 | } finally { |
| 1914 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 1915 | } |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1916 | } |
| 1917 | } |
Romain Guy | 53389bd | 2010-09-07 17:16:32 -0700 | [diff] [blame] | 1918 | |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 1919 | final ThreadedRenderer hardwareRenderer = mAttachInfo.mHardwareRenderer; |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 1920 | if (hardwareRenderer != null && hardwareRenderer.isEnabled()) { |
| 1921 | if (hwInitialized |
| 1922 | || mWidth != hardwareRenderer.getWidth() |
| 1923 | || mHeight != hardwareRenderer.getHeight()) { |
| 1924 | hardwareRenderer.setup(mWidth, mHeight, mAttachInfo, |
| 1925 | mWindowAttributes.surfaceInsets); |
Romain Guy | 0398575 | 2011-07-11 15:33:51 -0700 | [diff] [blame] | 1926 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1927 | } |
| 1928 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1929 | if (!mStopped || mReportNextDraw) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1930 | boolean focusChangedDueToTouchMode = ensureTouchModeLocally( |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1931 | (relayoutResult&WindowManagerGlobal.RELAYOUT_RES_IN_TOUCH_MODE) != 0); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1932 | if (focusChangedDueToTouchMode || mWidth != host.getMeasuredWidth() |
| 1933 | || mHeight != host.getMeasuredHeight() || contentInsetsChanged) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1934 | int childWidthMeasureSpec = getRootMeasureSpec(mWidth, lp.width); |
| 1935 | int childHeightMeasureSpec = getRootMeasureSpec(mHeight, lp.height); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1936 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1937 | if (DEBUG_LAYOUT) Log.v(mTag, "Ooops, something changed! mWidth=" |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1938 | + mWidth + " measuredWidth=" + host.getMeasuredWidth() |
| 1939 | + " mHeight=" + mHeight |
| 1940 | + " measuredHeight=" + host.getMeasuredHeight() |
| 1941 | + " coveredInsetsChanged=" + contentInsetsChanged); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1942 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1943 | // Ask host how big it wants to be |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1944 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1945 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1946 | // Implementation of weights from WindowManager.LayoutParams |
| 1947 | // We just grow the dimensions as needed and re-measure if |
| 1948 | // needs be |
| 1949 | int width = host.getMeasuredWidth(); |
| 1950 | int height = host.getMeasuredHeight(); |
| 1951 | boolean measureAgain = false; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1952 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1953 | if (lp.horizontalWeight > 0.0f) { |
| 1954 | width += (int) ((mWidth - width) * lp.horizontalWeight); |
| 1955 | childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(width, |
| 1956 | MeasureSpec.EXACTLY); |
| 1957 | measureAgain = true; |
| 1958 | } |
| 1959 | if (lp.verticalWeight > 0.0f) { |
| 1960 | height += (int) ((mHeight - height) * lp.verticalWeight); |
| 1961 | childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, |
| 1962 | MeasureSpec.EXACTLY); |
| 1963 | measureAgain = true; |
| 1964 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1965 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1966 | if (measureAgain) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1967 | if (DEBUG_LAYOUT) Log.v(mTag, |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1968 | "And hey let's measure once more: width=" + width |
| 1969 | + " height=" + height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1970 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1971 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1972 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1973 | layoutRequested = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1974 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1975 | } |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 1976 | } else { |
| 1977 | // Not the first pass and no window/insets/visibility change but the window |
| 1978 | // may have moved and we need check that and if so to update the left and right |
| 1979 | // in the attach info. We translate only the window frame since on window move |
| 1980 | // the window manager tells us only for the new frame but the insets are the |
| 1981 | // same and we do not want to translate them more than once. |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 1982 | maybeHandleWindowMove(frame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1983 | } |
| 1984 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1985 | final boolean didLayout = layoutRequested && (!mStopped || mReportNextDraw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1986 | boolean triggerGlobalLayoutListener = didLayout |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1987 | || mAttachInfo.mRecomputeGlobalAttributes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1988 | if (didLayout) { |
Jorim Jaggi | 26d02d2 | 2016-02-24 18:37:51 -0500 | [diff] [blame] | 1989 | performLayout(lp, mWidth, mHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1990 | |
Mathias Agopian | 54e3d384 | 2013-04-12 15:13:12 -0700 | [diff] [blame] | 1991 | // 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] | 1992 | // We can compute the transparent area |
| 1993 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1994 | if ((host.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1995 | // start out transparent |
| 1996 | // TODO: AVOID THAT CALL BY CACHING THE RESULT? |
| 1997 | host.getLocationInWindow(mTmpLocation); |
| 1998 | mTransparentRegion.set(mTmpLocation[0], mTmpLocation[1], |
| 1999 | mTmpLocation[0] + host.mRight - host.mLeft, |
| 2000 | mTmpLocation[1] + host.mBottom - host.mTop); |
| 2001 | |
| 2002 | host.gatherTransparentRegion(mTransparentRegion); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 2003 | if (mTranslator != null) { |
| 2004 | mTranslator.translateRegionInWindowToScreen(mTransparentRegion); |
| 2005 | } |
| 2006 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2007 | if (!mTransparentRegion.equals(mPreviousTransparentRegion)) { |
| 2008 | mPreviousTransparentRegion.set(mTransparentRegion); |
Mathias Agopian | 54e3d384 | 2013-04-12 15:13:12 -0700 | [diff] [blame] | 2009 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2010 | // reconfigure window manager |
| 2011 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2012 | mWindowSession.setTransparentRegion(mWindow, mTransparentRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2013 | } catch (RemoteException e) { |
| 2014 | } |
| 2015 | } |
| 2016 | } |
| 2017 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2018 | if (DBG) { |
| 2019 | System.out.println("======================================"); |
Chet Haase | 4610eef | 2015-12-03 07:38:11 -0800 | [diff] [blame] | 2020 | System.out.println("performTraversals -- after setFrame"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2021 | host.debug(); |
| 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | if (triggerGlobalLayoutListener) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2026 | mAttachInfo.mRecomputeGlobalAttributes = false; |
| 2027 | mAttachInfo.mTreeObserver.dispatchOnGlobalLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2028 | } |
| 2029 | |
| 2030 | if (computesInternalInsets) { |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2031 | // Clear the original insets. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2032 | final ViewTreeObserver.InternalInsetsInfo insets = mAttachInfo.mGivenInternalInsets; |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2033 | insets.reset(); |
| 2034 | |
| 2035 | // Compute new insets in place. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2036 | mAttachInfo.mTreeObserver.dispatchOnComputeInternalInsets(insets); |
| 2037 | mAttachInfo.mHasNonEmptyGivenInternalInsets = !insets.isEmpty(); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2038 | |
| 2039 | // Tell the window manager. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2040 | if (insetsPending || !mLastGivenInsets.equals(insets)) { |
| 2041 | mLastGivenInsets.set(insets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2042 | |
| 2043 | // Translate insets to screen coordinates if needed. |
| 2044 | final Rect contentInsets; |
| 2045 | final Rect visibleInsets; |
| 2046 | final Region touchableRegion; |
| 2047 | if (mTranslator != null) { |
| 2048 | contentInsets = mTranslator.getTranslatedContentInsets(insets.contentInsets); |
| 2049 | visibleInsets = mTranslator.getTranslatedVisibleInsets(insets.visibleInsets); |
| 2050 | touchableRegion = mTranslator.getTranslatedTouchableArea(insets.touchableRegion); |
| 2051 | } else { |
| 2052 | contentInsets = insets.contentInsets; |
| 2053 | visibleInsets = insets.visibleInsets; |
| 2054 | touchableRegion = insets.touchableRegion; |
| 2055 | } |
| 2056 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2057 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2058 | mWindowSession.setInsets(mWindow, insets.mTouchableInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2059 | contentInsets, visibleInsets, touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2060 | } catch (RemoteException e) { |
| 2061 | } |
| 2062 | } |
| 2063 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2064 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2065 | if (mFirst) { |
| 2066 | // handle first focus request |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2067 | 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] | 2068 | + mView.hasFocus()); |
| 2069 | if (mView != null) { |
| 2070 | if (!mView.hasFocus()) { |
| 2071 | mView.requestFocus(View.FOCUS_FORWARD); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2072 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: requested focused view=" |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2073 | + mView.findFocus()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | } else { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2075 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: existing focused view=" |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2076 | + mView.findFocus()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2077 | } |
| 2078 | } |
| 2079 | } |
| 2080 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2081 | final boolean changedVisibility = (viewVisibilityChanged || mFirst) && isViewVisible; |
| 2082 | final boolean hasWindowFocus = mAttachInfo.mHasWindowFocus && isViewVisible; |
| 2083 | final boolean regainedFocus = hasWindowFocus && mLostWindowFocus; |
| 2084 | if (regainedFocus) { |
| 2085 | mLostWindowFocus = false; |
| 2086 | } else if (!hasWindowFocus && mHadWindowFocus) { |
| 2087 | mLostWindowFocus = true; |
| 2088 | } |
| 2089 | |
| 2090 | if (changedVisibility || regainedFocus) { |
| 2091 | host.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 2092 | } |
| 2093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2094 | mFirst = false; |
| 2095 | mWillDrawSoon = false; |
| 2096 | mNewSurfaceNeeded = false; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 2097 | mActivityRelaunched = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2098 | mViewVisibility = viewVisibility; |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2099 | mHadWindowFocus = hasWindowFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2100 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2101 | if (hasWindowFocus && !isInLocalFocusMode()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2102 | final boolean imTarget = WindowManager.LayoutParams |
| 2103 | .mayUseInputMethod(mWindowAttributes.flags); |
| 2104 | if (imTarget != mLastWasImTarget) { |
| 2105 | mLastWasImTarget = imTarget; |
| 2106 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 2107 | if (imm != null && imTarget) { |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2108 | imm.onPreWindowFocus(mView, hasWindowFocus); |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 2109 | imm.onPostWindowFocus(mView, mView.findFocus(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2110 | mWindowAttributes.softInputMode, |
| 2111 | !mHasHadWindowFocus, mWindowAttributes.flags); |
| 2112 | } |
| 2113 | } |
| 2114 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2115 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2116 | // Remember if we must report the next draw. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2117 | if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2118 | mReportNextDraw = true; |
| 2119 | } |
| 2120 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2121 | boolean cancelDraw = mAttachInfo.mTreeObserver.dispatchOnPreDraw() || !isViewVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2122 | |
Jorim Jaggi | 3127c2a4 | 2016-01-26 18:48:44 -0800 | [diff] [blame] | 2123 | if (!cancelDraw) { |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2124 | if (mPendingTransitions != null && mPendingTransitions.size() > 0) { |
| 2125 | for (int i = 0; i < mPendingTransitions.size(); ++i) { |
| 2126 | mPendingTransitions.get(i).startChangingAnimations(); |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2127 | } |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2128 | mPendingTransitions.clear(); |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2129 | } |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2130 | |
| 2131 | performDraw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2132 | } else { |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2133 | if (isViewVisible) { |
Chris Wren | 78cb7cf | 2012-05-15 12:36:44 -0400 | [diff] [blame] | 2134 | // Try again |
| 2135 | scheduleTraversals(); |
| 2136 | } else if (mPendingTransitions != null && mPendingTransitions.size() > 0) { |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2137 | for (int i = 0; i < mPendingTransitions.size(); ++i) { |
| 2138 | mPendingTransitions.get(i).endChangingAnimations(); |
| 2139 | } |
| 2140 | mPendingTransitions.clear(); |
| 2141 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2142 | } |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 2143 | |
| 2144 | mIsInTraversal = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2145 | } |
| 2146 | |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2147 | private void maybeHandleWindowMove(Rect frame) { |
| 2148 | |
| 2149 | // TODO: Well, we are checking whether the frame has changed similarly |
| 2150 | // to how this is done for the insets. This is however incorrect since |
| 2151 | // the insets and the frame are translated. For example, the old frame |
| 2152 | // was (1, 1 - 1, 1) and was translated to say (2, 2 - 2, 2), now the new |
| 2153 | // reported frame is (2, 2 - 2, 2) which implies no change but this is not |
| 2154 | // true since we are comparing a not translated value to a translated one. |
| 2155 | // This scenario is rare but we may want to fix that. |
| 2156 | |
| 2157 | final boolean windowMoved = mAttachInfo.mWindowLeft != frame.left |
| 2158 | || mAttachInfo.mWindowTop != frame.top; |
| 2159 | if (windowMoved) { |
| 2160 | if (mTranslator != null) { |
| 2161 | mTranslator.translateRectInScreenToAppWinFrame(frame); |
| 2162 | } |
| 2163 | mAttachInfo.mWindowLeft = frame.left; |
| 2164 | mAttachInfo.mWindowTop = frame.top; |
| 2165 | |
| 2166 | // Update the light position for the new window offsets. |
| 2167 | if (mAttachInfo.mHardwareRenderer != null) { |
| 2168 | mAttachInfo.mHardwareRenderer.setLightCenter(mAttachInfo); |
| 2169 | } |
| 2170 | } |
| 2171 | } |
Jorim Jaggi | 3127c2a4 | 2016-01-26 18:48:44 -0800 | [diff] [blame] | 2172 | |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2173 | private void handleOutOfResourcesException(Surface.OutOfResourcesException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2174 | Log.e(mTag, "OutOfResourcesException initializing HW surface", e); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2175 | try { |
| 2176 | if (!mWindowSession.outOfMemory(mWindow) && |
| 2177 | Process.myUid() != Process.SYSTEM_UID) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2178 | Slog.w(mTag, "No processes killed for memory; killing self"); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2179 | Process.killProcess(Process.myPid()); |
| 2180 | } |
| 2181 | } catch (RemoteException ex) { |
| 2182 | } |
| 2183 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2184 | } |
| 2185 | |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2186 | private void performMeasure(int childWidthMeasureSpec, int childHeightMeasureSpec) { |
| 2187 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "measure"); |
| 2188 | try { |
| 2189 | mView.measure(childWidthMeasureSpec, childHeightMeasureSpec); |
| 2190 | } finally { |
| 2191 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2192 | } |
| 2193 | } |
| 2194 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2195 | /** |
| 2196 | * Called by {@link android.view.View#isInLayout()} to determine whether the view hierarchy |
| 2197 | * is currently undergoing a layout pass. |
| 2198 | * |
| 2199 | * @return whether the view hierarchy is currently undergoing a layout pass |
| 2200 | */ |
| 2201 | boolean isInLayout() { |
| 2202 | return mInLayout; |
| 2203 | } |
| 2204 | |
| 2205 | /** |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2206 | * Called by {@link android.view.View#requestLayout()} if the view hierarchy is currently |
| 2207 | * undergoing a layout pass. requestLayout() should not generally be called during layout, |
| 2208 | * unless the container hierarchy knows what it is doing (i.e., it is fine as long as |
| 2209 | * all children in that container hierarchy are measured and laid out at the end of the layout |
| 2210 | * pass for that container). If requestLayout() is called anyway, we handle it correctly |
| 2211 | * by registering all requesters during a frame as it proceeds. At the end of the frame, |
| 2212 | * we check all of those views to see if any still have pending layout requests, which |
| 2213 | * indicates that they were not correctly handled by their container hierarchy. If that is |
| 2214 | * the case, we clear all such flags in the tree, to remove the buggy flag state that leads |
| 2215 | * 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] | 2216 | * 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] | 2217 | * requests to the next frame to avoid possible infinite loops. |
| 2218 | * |
| 2219 | * <p>The return value from this method indicates whether the request should proceed |
| 2220 | * (if it is a request during the first layout pass) or should be skipped and posted to the |
| 2221 | * 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] | 2222 | * |
| 2223 | * @param view the view that requested the layout. |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2224 | * |
| 2225 | * @return true if request should proceed, false otherwise. |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2226 | */ |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2227 | boolean requestLayoutDuringLayout(final View view) { |
| 2228 | if (view.mParent == null || view.mAttachInfo == null) { |
| 2229 | // Would not normally trigger another layout, so just let it pass through as usual |
| 2230 | return true; |
| 2231 | } |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2232 | if (!mLayoutRequesters.contains(view)) { |
| 2233 | mLayoutRequesters.add(view); |
| 2234 | } |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2235 | if (!mHandlingLayoutInLayoutRequest) { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2236 | // Let the request proceed normally; it will be processed in a second layout pass |
| 2237 | // if necessary |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2238 | return true; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2239 | } else { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2240 | // Don't let the request proceed during the second layout pass. |
| 2241 | // It will post to the next frame instead. |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2242 | return false; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2243 | } |
| 2244 | } |
| 2245 | |
Chet Haase | 3efa7b5 | 2012-12-03 08:33:17 -0800 | [diff] [blame] | 2246 | private void performLayout(WindowManager.LayoutParams lp, int desiredWindowWidth, |
| 2247 | int desiredWindowHeight) { |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2248 | mLayoutRequested = false; |
| 2249 | mScrollMayChange = true; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2250 | mInLayout = true; |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2251 | |
| 2252 | final View host = mView; |
| 2253 | if (DEBUG_ORIENTATION || DEBUG_LAYOUT) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2254 | Log.v(mTag, "Laying out " + host + " to (" + |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2255 | host.getMeasuredWidth() + ", " + host.getMeasuredHeight() + ")"); |
| 2256 | } |
| 2257 | |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2258 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "layout"); |
| 2259 | try { |
| 2260 | host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2261 | |
Chet Haase | d5a8352 | 2012-11-21 16:24:44 -0800 | [diff] [blame] | 2262 | mInLayout = false; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2263 | int numViewsRequestingLayout = mLayoutRequesters.size(); |
| 2264 | if (numViewsRequestingLayout > 0) { |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2265 | // requestLayout() was called during layout. |
| 2266 | // If no layout-request flags are set on the requesting views, there is no problem. |
| 2267 | // If some requests are still pending, then we need to clear those flags and do |
| 2268 | // a full request/measure/layout pass to handle this situation. |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2269 | ArrayList<View> validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, |
| 2270 | false); |
| 2271 | if (validLayoutRequesters != null) { |
| 2272 | // Set this flag to indicate that any further requests are happening during |
| 2273 | // the second pass, which may result in posting those requests to the next |
| 2274 | // frame instead |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2275 | mHandlingLayoutInLayoutRequest = true; |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2276 | |
| 2277 | // Process fresh layout requests, then measure and layout |
| 2278 | int numValidRequests = validLayoutRequesters.size(); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2279 | for (int i = 0; i < numValidRequests; ++i) { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2280 | final View view = validLayoutRequesters.get(i); |
| 2281 | Log.w("View", "requestLayout() improperly called by " + view + |
| 2282 | " during layout: running second layout pass"); |
| 2283 | view.requestLayout(); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2284 | } |
| 2285 | measureHierarchy(host, lp, mView.getContext().getResources(), |
| 2286 | desiredWindowWidth, desiredWindowHeight); |
| 2287 | mInLayout = true; |
| 2288 | host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2289 | |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2290 | mHandlingLayoutInLayoutRequest = false; |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2291 | |
| 2292 | // Check the valid requests again, this time without checking/clearing the |
| 2293 | // layout flags, since requests happening during the second pass get noop'd |
| 2294 | validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, true); |
| 2295 | if (validLayoutRequesters != null) { |
| 2296 | final ArrayList<View> finalRequesters = validLayoutRequesters; |
| 2297 | // Post second-pass requests to the next frame |
| 2298 | getRunQueue().post(new Runnable() { |
| 2299 | @Override |
| 2300 | public void run() { |
| 2301 | int numValidRequests = finalRequesters.size(); |
| 2302 | for (int i = 0; i < numValidRequests; ++i) { |
| 2303 | final View view = finalRequesters.get(i); |
| 2304 | Log.w("View", "requestLayout() improperly called by " + view + |
| 2305 | " during second layout pass: posting in next frame"); |
| 2306 | view.requestLayout(); |
| 2307 | } |
| 2308 | } |
| 2309 | }); |
| 2310 | } |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2311 | } |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2312 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2313 | } |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2314 | } finally { |
| 2315 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2316 | } |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2317 | mInLayout = false; |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2318 | } |
| 2319 | |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2320 | /** |
| 2321 | * This method is called during layout when there have been calls to requestLayout() during |
| 2322 | * layout. It walks through the list of views that requested layout to determine which ones |
| 2323 | * still need it, based on visibility in the hierarchy and whether they have already been |
| 2324 | * handled (as is usually the case with ListView children). |
| 2325 | * |
| 2326 | * @param layoutRequesters The list of views that requested layout during layout |
| 2327 | * @param secondLayoutRequests Whether the requests were issued during the second layout pass. |
| 2328 | * If so, the FORCE_LAYOUT flag was not set on requesters. |
| 2329 | * @return A list of the actual views that still need to be laid out. |
| 2330 | */ |
| 2331 | private ArrayList<View> getValidLayoutRequesters(ArrayList<View> layoutRequesters, |
| 2332 | boolean secondLayoutRequests) { |
| 2333 | |
| 2334 | int numViewsRequestingLayout = layoutRequesters.size(); |
| 2335 | ArrayList<View> validLayoutRequesters = null; |
| 2336 | for (int i = 0; i < numViewsRequestingLayout; ++i) { |
| 2337 | View view = layoutRequesters.get(i); |
| 2338 | if (view != null && view.mAttachInfo != null && view.mParent != null && |
| 2339 | (secondLayoutRequests || (view.mPrivateFlags & View.PFLAG_FORCE_LAYOUT) == |
| 2340 | View.PFLAG_FORCE_LAYOUT)) { |
| 2341 | boolean gone = false; |
| 2342 | View parent = view; |
| 2343 | // Only trigger new requests for views in a non-GONE hierarchy |
| 2344 | while (parent != null) { |
| 2345 | if ((parent.mViewFlags & View.VISIBILITY_MASK) == View.GONE) { |
| 2346 | gone = true; |
| 2347 | break; |
| 2348 | } |
| 2349 | if (parent.mParent instanceof View) { |
| 2350 | parent = (View) parent.mParent; |
| 2351 | } else { |
| 2352 | parent = null; |
| 2353 | } |
| 2354 | } |
| 2355 | if (!gone) { |
| 2356 | if (validLayoutRequesters == null) { |
| 2357 | validLayoutRequesters = new ArrayList<View>(); |
| 2358 | } |
| 2359 | validLayoutRequesters.add(view); |
| 2360 | } |
| 2361 | } |
| 2362 | } |
| 2363 | if (!secondLayoutRequests) { |
| 2364 | // If we're checking the layout flags, then we need to clean them up also |
| 2365 | for (int i = 0; i < numViewsRequestingLayout; ++i) { |
| 2366 | View view = layoutRequesters.get(i); |
| 2367 | while (view != null && |
| 2368 | (view.mPrivateFlags & View.PFLAG_FORCE_LAYOUT) != 0) { |
| 2369 | view.mPrivateFlags &= ~View.PFLAG_FORCE_LAYOUT; |
| 2370 | if (view.mParent instanceof View) { |
| 2371 | view = (View) view.mParent; |
| 2372 | } else { |
| 2373 | view = null; |
| 2374 | } |
| 2375 | } |
| 2376 | } |
| 2377 | } |
| 2378 | layoutRequesters.clear(); |
| 2379 | return validLayoutRequesters; |
| 2380 | } |
| 2381 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2382 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2383 | public void requestTransparentRegion(View child) { |
| 2384 | // the test below should not fail unless someone is messing with us |
| 2385 | checkThread(); |
| 2386 | if (mView == child) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2387 | mView.mPrivateFlags |= View.PFLAG_REQUEST_TRANSPARENT_REGIONS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2388 | // Need to make sure we re-evaluate the window attributes next |
| 2389 | // time around, to ensure the window has the correct format. |
| 2390 | mWindowAttributesChanged = true; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 2391 | mWindowAttributesChangesFlag = 0; |
Mathias Agopian | 1bd80ad | 2010-11-04 17:13:39 -0700 | [diff] [blame] | 2392 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2393 | } |
| 2394 | } |
| 2395 | |
| 2396 | /** |
| 2397 | * Figures out the measure spec for the root view in a window based on it's |
| 2398 | * layout params. |
| 2399 | * |
| 2400 | * @param windowSize |
| 2401 | * The available width or height of the window |
| 2402 | * |
| 2403 | * @param rootDimension |
| 2404 | * The layout params for one dimension (width or height) of the |
| 2405 | * window. |
| 2406 | * |
| 2407 | * @return The measure spec to use to measure the root view. |
| 2408 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 2409 | private static int getRootMeasureSpec(int windowSize, int rootDimension) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2410 | int measureSpec; |
| 2411 | switch (rootDimension) { |
| 2412 | |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 2413 | case ViewGroup.LayoutParams.MATCH_PARENT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2414 | // Window can't resize. Force root view to be windowSize. |
| 2415 | measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.EXACTLY); |
| 2416 | break; |
| 2417 | case ViewGroup.LayoutParams.WRAP_CONTENT: |
| 2418 | // Window can resize. Set max size for root view. |
| 2419 | measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.AT_MOST); |
| 2420 | break; |
| 2421 | default: |
| 2422 | // Window wants to be an exact size. Force root view to be that size. |
| 2423 | measureSpec = MeasureSpec.makeMeasureSpec(rootDimension, MeasureSpec.EXACTLY); |
| 2424 | break; |
| 2425 | } |
| 2426 | return measureSpec; |
| 2427 | } |
| 2428 | |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2429 | int mHardwareXOffset; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2430 | int mHardwareYOffset; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2431 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2432 | @Override |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 2433 | public void onHardwarePreDraw(DisplayListCanvas canvas) { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2434 | canvas.translate(-mHardwareXOffset, -mHardwareYOffset); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2435 | } |
| 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 onHardwarePostDraw(DisplayListCanvas canvas) { |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2439 | drawAccessibilityFocusedDrawableIfNeeded(canvas); |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame^] | 2440 | synchronized (mWindowCallbacks) { |
| 2441 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 2442 | mWindowCallbacks.get(i).onPostDraw(canvas); |
| 2443 | } |
| 2444 | } |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2445 | } |
| 2446 | |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 2447 | /** |
| 2448 | * @hide |
| 2449 | */ |
| 2450 | void outputDisplayList(View view) { |
Chris Craik | 356b5fe | 2015-07-07 10:39:36 -0700 | [diff] [blame] | 2451 | view.mRenderNode.output(); |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 2452 | if (mAttachInfo.mHardwareRenderer != null) { |
| 2453 | ((ThreadedRenderer)mAttachInfo.mHardwareRenderer).serializeDisplayListTree(); |
| 2454 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | /** |
| 2458 | * @see #PROPERTY_PROFILE_RENDERING |
| 2459 | */ |
| 2460 | private void profileRendering(boolean enabled) { |
| 2461 | if (mProfileRendering) { |
| 2462 | mRenderProfilingEnabled = enabled; |
Chris Craik | ae4f3204 | 2013-02-07 12:57:10 -0800 | [diff] [blame] | 2463 | |
| 2464 | if (mRenderProfiler != null) { |
| 2465 | mChoreographer.removeFrameCallback(mRenderProfiler); |
| 2466 | } |
| 2467 | if (mRenderProfilingEnabled) { |
| 2468 | if (mRenderProfiler == null) { |
| 2469 | mRenderProfiler = new Choreographer.FrameCallback() { |
| 2470 | @Override |
| 2471 | public void doFrame(long frameTimeNanos) { |
| 2472 | mDirty.set(0, 0, mWidth, mHeight); |
| 2473 | scheduleTraversals(); |
| 2474 | if (mRenderProfilingEnabled) { |
| 2475 | mChoreographer.postFrameCallback(mRenderProfiler); |
| 2476 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2477 | } |
Chris Craik | ae4f3204 | 2013-02-07 12:57:10 -0800 | [diff] [blame] | 2478 | }; |
| 2479 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 2480 | mChoreographer.postFrameCallback(mRenderProfiler); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2481 | } else { |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2482 | mRenderProfiler = null; |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 2483 | } |
| 2484 | } |
| 2485 | } |
| 2486 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2487 | /** |
| 2488 | * Called from draw() when DEBUG_FPS is enabled |
| 2489 | */ |
| 2490 | private void trackFPS() { |
| 2491 | // Tracks frames per second drawn. First value in a series of draws may be bogus |
| 2492 | // because it down not account for the intervening idle time |
| 2493 | long nowTime = System.currentTimeMillis(); |
| 2494 | if (mFpsStartTime < 0) { |
| 2495 | mFpsStartTime = mFpsPrevTime = nowTime; |
| 2496 | mFpsNumFrames = 0; |
| 2497 | } else { |
| 2498 | ++mFpsNumFrames; |
| 2499 | String thisHash = Integer.toHexString(System.identityHashCode(this)); |
| 2500 | long frameTime = nowTime - mFpsPrevTime; |
| 2501 | long totalTime = nowTime - mFpsStartTime; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2502 | Log.v(mTag, "0x" + thisHash + "\tFrame time:\t" + frameTime); |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2503 | mFpsPrevTime = nowTime; |
| 2504 | if (totalTime > 1000) { |
| 2505 | float fps = (float) mFpsNumFrames * 1000 / totalTime; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2506 | Log.v(mTag, "0x" + thisHash + "\tFPS:\t" + fps); |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2507 | mFpsStartTime = nowTime; |
| 2508 | mFpsNumFrames = 0; |
| 2509 | } |
| 2510 | } |
| 2511 | } |
| 2512 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2513 | private void performDraw() { |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 2514 | if (mAttachInfo.mDisplayState == Display.STATE_OFF && !mReportNextDraw) { |
Craig Mautner | 006f0e4 | 2012-03-21 11:00:32 -0700 | [diff] [blame] | 2515 | return; |
| 2516 | } |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 2517 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2518 | final boolean fullRedrawNeeded = mFullRedrawNeeded; |
| 2519 | mFullRedrawNeeded = false; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2520 | |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 2521 | mIsDrawing = true; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2522 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "draw"); |
| 2523 | try { |
| 2524 | draw(fullRedrawNeeded); |
| 2525 | } finally { |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 2526 | mIsDrawing = false; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2527 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2528 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2529 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 2530 | // For whatever reason we didn't create a HardwareRenderer, end any |
| 2531 | // hardware animations that are now dangling |
| 2532 | if (mAttachInfo.mPendingAnimatingRenderNodes != null) { |
| 2533 | final int count = mAttachInfo.mPendingAnimatingRenderNodes.size(); |
| 2534 | for (int i = 0; i < count; i++) { |
| 2535 | mAttachInfo.mPendingAnimatingRenderNodes.get(i).endAllAnimators(); |
| 2536 | } |
| 2537 | mAttachInfo.mPendingAnimatingRenderNodes.clear(); |
| 2538 | } |
| 2539 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2540 | if (mReportNextDraw) { |
| 2541 | mReportNextDraw = false; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2542 | |
| 2543 | // if we're using multi-thread renderer, wait for the window frame draws |
| 2544 | if (mWindowDrawCountDown != null) { |
| 2545 | try { |
| 2546 | mWindowDrawCountDown.await(); |
| 2547 | } catch (InterruptedException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2548 | Log.e(mTag, "Window redraw count down interruped!"); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2549 | } |
| 2550 | mWindowDrawCountDown = null; |
| 2551 | } |
| 2552 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 2553 | if (mAttachInfo.mHardwareRenderer != null) { |
| 2554 | mAttachInfo.mHardwareRenderer.fence(); |
| 2555 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2556 | |
| 2557 | if (LOCAL_LOGV) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2558 | Log.v(mTag, "FINISHED DRAWING: " + mWindowAttributes.getTitle()); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2559 | } |
| 2560 | if (mSurfaceHolder != null && mSurface.isValid()) { |
| 2561 | mSurfaceHolderCallback.surfaceRedrawNeeded(mSurfaceHolder); |
| 2562 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 2563 | if (callbacks != null) { |
| 2564 | for (SurfaceHolder.Callback c : callbacks) { |
| 2565 | if (c instanceof SurfaceHolder.Callback2) { |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 2566 | ((SurfaceHolder.Callback2)c).surfaceRedrawNeeded(mSurfaceHolder); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2567 | } |
| 2568 | } |
| 2569 | } |
| 2570 | } |
| 2571 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2572 | mWindowSession.finishDrawing(mWindow); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2573 | } catch (RemoteException e) { |
| 2574 | } |
| 2575 | } |
| 2576 | } |
| 2577 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2578 | private void draw(boolean fullRedrawNeeded) { |
| 2579 | Surface surface = mSurface; |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 2580 | if (!surface.isValid()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2581 | return; |
| 2582 | } |
| 2583 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2584 | if (DEBUG_FPS) { |
| 2585 | trackFPS(); |
| 2586 | } |
| 2587 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2588 | if (!sFirstDrawComplete) { |
| 2589 | synchronized (sFirstDrawHandlers) { |
| 2590 | sFirstDrawComplete = true; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 2591 | final int count = sFirstDrawHandlers.size(); |
| 2592 | for (int i = 0; i< count; i++) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 2593 | mHandler.post(sFirstDrawHandlers.get(i)); |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2594 | } |
| 2595 | } |
| 2596 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2598 | scrollToRectOrFocus(null, false); |
| 2599 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2600 | if (mAttachInfo.mViewScrollChanged) { |
| 2601 | mAttachInfo.mViewScrollChanged = false; |
| 2602 | mAttachInfo.mTreeObserver.dispatchOnScrollChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2603 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2604 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2605 | boolean animating = mScroller != null && mScroller.computeScrollOffset(); |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2606 | final int curScrollY; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2607 | if (animating) { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2608 | curScrollY = mScroller.getCurrY(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2609 | } else { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2610 | curScrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2611 | } |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2612 | if (mCurScrollY != curScrollY) { |
| 2613 | mCurScrollY = curScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2614 | fullRedrawNeeded = true; |
Adrian Roos | 0e7ae4e | 2014-10-01 15:33:22 +0200 | [diff] [blame] | 2615 | if (mView instanceof RootViewSurfaceTaker) { |
| 2616 | ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY); |
| 2617 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2618 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2619 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2620 | final float appScale = mAttachInfo.mApplicationScale; |
| 2621 | final boolean scalingRequired = mAttachInfo.mScalingRequired; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2622 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2623 | int resizeAlpha = 0; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2624 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2625 | final Rect dirty = mDirty; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2626 | if (mSurfaceHolder != null) { |
| 2627 | // The app owns the surface, we won't draw. |
| 2628 | dirty.setEmpty(); |
Derek Sollenberger | 8d94835 | 2015-07-16 09:27:59 -0400 | [diff] [blame] | 2629 | if (animating && mScroller != null) { |
| 2630 | mScroller.abortAnimation(); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2631 | } |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2632 | return; |
| 2633 | } |
Romain Guy | 58ef7fb | 2010-09-13 12:52:37 -0700 | [diff] [blame] | 2634 | |
| 2635 | if (fullRedrawNeeded) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2636 | mAttachInfo.mIgnoreDirtyState = true; |
Romain Guy | c3166e1 | 2011-08-08 15:00:03 -0700 | [diff] [blame] | 2637 | 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] | 2638 | } |
Chet Haase | ad4f703 | 2011-06-22 09:18:31 -0700 | [diff] [blame] | 2639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2640 | if (DEBUG_ORIENTATION || DEBUG_DRAW) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2641 | Log.v(mTag, "Draw " + mView + "/" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2642 | + mWindowAttributes.getTitle() |
| 2643 | + ": dirty={" + dirty.left + "," + dirty.top |
| 2644 | + "," + dirty.right + "," + dirty.bottom + "} surface=" |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 2645 | + surface + " surface.isValid()=" + surface.isValid() + ", appScale:" + |
| 2646 | appScale + ", width=" + mWidth + ", height=" + mHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2647 | } |
| 2648 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2649 | mAttachInfo.mTreeObserver.dispatchOnDraw(); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2650 | |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2651 | int xOffset = -mCanvasOffsetX; |
| 2652 | int yOffset = -mCanvasOffsetY + curScrollY; |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2653 | final WindowManager.LayoutParams params = mWindowAttributes; |
| 2654 | final Rect surfaceInsets = params != null ? params.surfaceInsets : null; |
| 2655 | if (surfaceInsets != null) { |
| 2656 | xOffset -= surfaceInsets.left; |
| 2657 | yOffset -= surfaceInsets.top; |
| 2658 | |
| 2659 | // Offset dirty rect for surface insets. |
| 2660 | dirty.offset(surfaceInsets.left, surfaceInsets.right); |
| 2661 | } |
| 2662 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2663 | boolean accessibilityFocusDirty = false; |
| 2664 | final Drawable drawable = mAttachInfo.mAccessibilityFocusDrawable; |
| 2665 | if (drawable != null) { |
| 2666 | final Rect bounds = mAttachInfo.mTmpInvalRect; |
| 2667 | final boolean hasFocus = getAccessibilityFocusedRect(bounds); |
| 2668 | if (!hasFocus) { |
| 2669 | bounds.setEmpty(); |
| 2670 | } |
| 2671 | if (!bounds.equals(drawable.getBounds())) { |
| 2672 | accessibilityFocusDirty = true; |
| 2673 | } |
| 2674 | } |
| 2675 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 2676 | mAttachInfo.mDrawingTime = |
| 2677 | mChoreographer.getFrameTimeNanos() / TimeUtils.NANOS_PER_MS; |
| 2678 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2679 | if (!dirty.isEmpty() || mIsAnimating || accessibilityFocusDirty) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2680 | if (mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled()) { |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2681 | // If accessibility focus moved, always invalidate the root. |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame^] | 2682 | boolean invalidateRoot = accessibilityFocusDirty || mInvalidateRootRequested; |
| 2683 | mInvalidateRootRequested = false; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2684 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2685 | // Draw with hardware renderer. |
| 2686 | mIsAnimating = false; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2687 | |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 2688 | if (mHardwareYOffset != yOffset || mHardwareXOffset != xOffset) { |
| 2689 | mHardwareYOffset = yOffset; |
| 2690 | mHardwareXOffset = xOffset; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2691 | invalidateRoot = true; |
Alan Viverette | f6cf1a0 | 2014-08-11 14:13:02 -0700 | [diff] [blame] | 2692 | } |
| 2693 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2694 | if (invalidateRoot) { |
| 2695 | mAttachInfo.mHardwareRenderer.invalidateRoot(); |
| 2696 | } |
| 2697 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2698 | dirty.setEmpty(); |
| 2699 | |
Skuhne | 980ee47 | 2015-10-06 11:31:31 -0700 | [diff] [blame] | 2700 | // Stage the content drawn size now. It will be transferred to the renderer |
| 2701 | // shortly before the draw commands get send to the renderer. |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2702 | final boolean updated = updateContentDrawBounds(); |
| 2703 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2704 | mAttachInfo.mHardwareRenderer.draw(mView, mAttachInfo, this); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2705 | |
| 2706 | if (updated) { |
| 2707 | requestDrawWindow(); |
| 2708 | } |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2709 | } else { |
| 2710 | // If we get here with a disabled & requested hardware renderer, something went |
| 2711 | // wrong (an invalidate posted right before we destroyed the hardware surface |
| 2712 | // for instance) so we should just bail out. Locking the surface with software |
| 2713 | // rendering at this point would lock it forever and prevent hardware renderer |
| 2714 | // from doing its job when it comes back. |
| 2715 | // Before we request a new frame we must however attempt to reinitiliaze the |
| 2716 | // hardware renderer if it's in requested state. This would happen after an |
| 2717 | // eglTerminate() for instance. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2718 | if (mAttachInfo.mHardwareRenderer != null && |
| 2719 | !mAttachInfo.mHardwareRenderer.isEnabled() && |
| 2720 | mAttachInfo.mHardwareRenderer.isRequested()) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2721 | |
| 2722 | try { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2723 | mAttachInfo.mHardwareRenderer.initializeIfNeeded( |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 2724 | mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2725 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2726 | handleOutOfResourcesException(e); |
| 2727 | return; |
| 2728 | } |
| 2729 | |
| 2730 | mFullRedrawNeeded = true; |
| 2731 | scheduleTraversals(); |
| 2732 | return; |
| 2733 | } |
| 2734 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2735 | if (!drawSoftware(surface, mAttachInfo, xOffset, yOffset, scalingRequired, dirty)) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2736 | return; |
| 2737 | } |
Jeff Brown | 95db2b2 | 2011-11-30 19:54:41 -0800 | [diff] [blame] | 2738 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2739 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2740 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2741 | if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2742 | mFullRedrawNeeded = true; |
| 2743 | scheduleTraversals(); |
| 2744 | } |
| 2745 | } |
| 2746 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2747 | /** |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2748 | * @return true if drawing was successful, false if an error occurred |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2749 | */ |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2750 | private boolean drawSoftware(Surface surface, AttachInfo attachInfo, int xoff, int yoff, |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2751 | boolean scalingRequired, Rect dirty) { |
| 2752 | |
| 2753 | // Draw with software renderer. |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2754 | final Canvas canvas; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2755 | try { |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2756 | final int left = dirty.left; |
| 2757 | final int top = dirty.top; |
| 2758 | final int right = dirty.right; |
| 2759 | final int bottom = dirty.bottom; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2760 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2761 | canvas = mSurface.lockCanvas(dirty); |
| 2762 | |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 2763 | // The dirty rectangle can be modified by Surface.lockCanvas() |
| 2764 | //noinspection ConstantConditions |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2765 | if (left != dirty.left || top != dirty.top || right != dirty.right |
| 2766 | || bottom != dirty.bottom) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2767 | attachInfo.mIgnoreDirtyState = true; |
| 2768 | } |
| 2769 | |
| 2770 | // TODO: Do this in native |
| 2771 | canvas.setDensity(mDensity); |
| 2772 | } catch (Surface.OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2773 | handleOutOfResourcesException(e); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2774 | return false; |
| 2775 | } catch (IllegalArgumentException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2776 | Log.e(mTag, "Could not lock surface", e); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2777 | // Don't assume this is due to out of memory, it could be |
| 2778 | // something else, and if it is something else then we could |
| 2779 | // kill stuff (or ourself) for no reason. |
| 2780 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2781 | return false; |
| 2782 | } |
| 2783 | |
| 2784 | try { |
| 2785 | if (DEBUG_ORIENTATION || DEBUG_DRAW) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2786 | Log.v(mTag, "Surface " + surface + " drawing to bitmap w=" |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2787 | + canvas.getWidth() + ", h=" + canvas.getHeight()); |
| 2788 | //canvas.drawARGB(255, 255, 0, 0); |
| 2789 | } |
| 2790 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2791 | // If this bitmap's format includes an alpha channel, we |
| 2792 | // need to clear it before drawing so that the child will |
| 2793 | // properly re-composite its drawing on a transparent |
| 2794 | // background. This automatically respects the clip/dirty region |
| 2795 | // or |
| 2796 | // If we are applying an offset, we need to clear the area |
| 2797 | // where the offset doesn't appear to avoid having garbage |
| 2798 | // left in the blank areas. |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2799 | if (!canvas.isOpaque() || yoff != 0 || xoff != 0) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2800 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 2801 | } |
| 2802 | |
| 2803 | dirty.setEmpty(); |
| 2804 | mIsAnimating = false; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2805 | mView.mPrivateFlags |= View.PFLAG_DRAWN; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2806 | |
| 2807 | if (DEBUG_DRAW) { |
| 2808 | Context cxt = mView.getContext(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2809 | Log.i(mTag, "Drawing: package:" + cxt.getPackageName() + |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2810 | ", metrics=" + cxt.getResources().getDisplayMetrics() + |
| 2811 | ", compatibilityInfo=" + cxt.getResources().getCompatibilityInfo()); |
| 2812 | } |
| 2813 | try { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2814 | canvas.translate(-xoff, -yoff); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2815 | if (mTranslator != null) { |
| 2816 | mTranslator.translateCanvas(canvas); |
| 2817 | } |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 2818 | canvas.setScreenDensity(scalingRequired ? mNoncompatDensity : 0); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2819 | attachInfo.mSetIgnoreDirtyState = false; |
| 2820 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2821 | mView.draw(canvas); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2822 | |
| 2823 | drawAccessibilityFocusedDrawableIfNeeded(canvas); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2824 | } finally { |
| 2825 | if (!attachInfo.mSetIgnoreDirtyState) { |
| 2826 | // Only clear the flag if it was not set during the mView.draw() call |
| 2827 | attachInfo.mIgnoreDirtyState = false; |
| 2828 | } |
| 2829 | } |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2830 | } finally { |
Romain Guy | dddcd22 | 2012-05-18 15:33:57 -0700 | [diff] [blame] | 2831 | try { |
| 2832 | surface.unlockCanvasAndPost(canvas); |
| 2833 | } catch (IllegalArgumentException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2834 | Log.e(mTag, "Could not unlock surface", e); |
Romain Guy | dddcd22 | 2012-05-18 15:33:57 -0700 | [diff] [blame] | 2835 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2836 | //noinspection ReturnInsideFinallyBlock |
| 2837 | return false; |
| 2838 | } |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2839 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2840 | if (LOCAL_LOGV) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2841 | Log.v(mTag, "Surface " + surface + " unlockCanvasAndPost"); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2842 | } |
| 2843 | } |
| 2844 | return true; |
| 2845 | } |
| 2846 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2847 | /** |
| 2848 | * We want to draw a highlight around the current accessibility focused. |
| 2849 | * Since adding a style for all possible view is not a viable option we |
| 2850 | * have this specialized drawing method. |
| 2851 | * |
| 2852 | * Note: We are doing this here to be able to draw the highlight for |
| 2853 | * virtual views in addition to real ones. |
| 2854 | * |
| 2855 | * @param canvas The canvas on which to draw. |
| 2856 | */ |
| 2857 | private void drawAccessibilityFocusedDrawableIfNeeded(Canvas canvas) { |
| 2858 | final Rect bounds = mAttachInfo.mTmpInvalRect; |
| 2859 | if (getAccessibilityFocusedRect(bounds)) { |
| 2860 | final Drawable drawable = getAccessibilityFocusedDrawable(); |
| 2861 | if (drawable != null) { |
| 2862 | drawable.setBounds(bounds); |
| 2863 | drawable.draw(canvas); |
| 2864 | } |
| 2865 | } else if (mAttachInfo.mAccessibilityFocusDrawable != null) { |
| 2866 | mAttachInfo.mAccessibilityFocusDrawable.setBounds(0, 0, 0, 0); |
| 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | private boolean getAccessibilityFocusedRect(Rect bounds) { |
| 2871 | final AccessibilityManager manager = AccessibilityManager.getInstance(mView.mContext); |
| 2872 | if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) { |
| 2873 | return false; |
| 2874 | } |
| 2875 | |
| 2876 | final View host = mAccessibilityFocusedHost; |
| 2877 | if (host == null || host.mAttachInfo == null) { |
| 2878 | return false; |
| 2879 | } |
| 2880 | |
| 2881 | final AccessibilityNodeProvider provider = host.getAccessibilityNodeProvider(); |
| 2882 | if (provider == null) { |
Svetoslav | ded133c | 2015-01-30 20:28:41 -0800 | [diff] [blame] | 2883 | host.getBoundsOnScreen(bounds, true); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2884 | } else if (mAccessibilityFocusedVirtualView != null) { |
| 2885 | mAccessibilityFocusedVirtualView.getBoundsInScreen(bounds); |
| 2886 | } else { |
| 2887 | return false; |
| 2888 | } |
| 2889 | |
Alan Viverette | 2232add | 2015-05-26 15:24:18 -0700 | [diff] [blame] | 2890 | // Transform the rect into window-relative coordinates. |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2891 | final AttachInfo attachInfo = mAttachInfo; |
Alan Viverette | 2232add | 2015-05-26 15:24:18 -0700 | [diff] [blame] | 2892 | bounds.offset(0, attachInfo.mViewRootImpl.mScrollY); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2893 | bounds.offset(-attachInfo.mWindowLeft, -attachInfo.mWindowTop); |
Doris Liu | 9607fbe | 2015-05-28 17:17:28 -0700 | [diff] [blame] | 2894 | if (!bounds.intersect(0, 0, attachInfo.mViewRootImpl.mWidth, |
| 2895 | attachInfo.mViewRootImpl.mHeight)) { |
| 2896 | // If no intersection, set bounds to empty. |
| 2897 | bounds.setEmpty(); |
| 2898 | } |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2899 | return !bounds.isEmpty(); |
| 2900 | } |
| 2901 | |
| 2902 | private Drawable getAccessibilityFocusedDrawable() { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2903 | // Lazily load the accessibility focus drawable. |
| 2904 | if (mAttachInfo.mAccessibilityFocusDrawable == null) { |
Alan Viverette | f6cf1a0 | 2014-08-11 14:13:02 -0700 | [diff] [blame] | 2905 | final TypedValue value = new TypedValue(); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2906 | final boolean resolved = mView.mContext.getTheme().resolveAttribute( |
| 2907 | R.attr.accessibilityFocusedDrawable, value, true); |
| 2908 | if (resolved) { |
| 2909 | mAttachInfo.mAccessibilityFocusDrawable = |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 2910 | mView.mContext.getDrawable(value.resourceId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2911 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2912 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2913 | return mAttachInfo.mAccessibilityFocusDrawable; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2914 | } |
| 2915 | |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame^] | 2916 | /** |
| 2917 | * Requests that the root render node is invalidated next time we perform a draw, such that |
| 2918 | * {@link WindowCallbacks#onPostDraw} gets called. |
| 2919 | */ |
| 2920 | public void requestInvalidateRootRenderNode() { |
| 2921 | mInvalidateRootRequested = true; |
| 2922 | } |
| 2923 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2924 | boolean scrollToRectOrFocus(Rect rectangle, boolean immediate) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2925 | final Rect ci = mAttachInfo.mContentInsets; |
| 2926 | final Rect vi = mAttachInfo.mVisibleInsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2927 | int scrollY = 0; |
| 2928 | boolean handled = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2930 | if (vi.left > ci.left || vi.top > ci.top |
| 2931 | || vi.right > ci.right || vi.bottom > ci.bottom) { |
| 2932 | // We'll assume that we aren't going to change the scroll |
| 2933 | // offset, since we want to avoid that unless it is actually |
| 2934 | // going to make the focus visible... otherwise we scroll |
| 2935 | // all over the place. |
| 2936 | scrollY = mScrollY; |
| 2937 | // We can be called for two different situations: during a draw, |
| 2938 | // to update the scroll position if the focus has changed (in which |
| 2939 | // case 'rectangle' is null), or in response to a |
| 2940 | // requestChildRectangleOnScreen() call (in which case 'rectangle' |
| 2941 | // is non-null and we just want to scroll to whatever that |
| 2942 | // rectangle is). |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 2943 | final View focus = mView.findFocus(); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2944 | if (focus == null) { |
Romain Guy | e8b1652 | 2009-07-14 13:06:42 -0700 | [diff] [blame] | 2945 | return false; |
| 2946 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2947 | View lastScrolledFocus = (mLastScrolledFocus != null) ? mLastScrolledFocus.get() : null; |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 2948 | if (focus != lastScrolledFocus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2949 | // If the focus has changed, then ignore any requests to scroll |
| 2950 | // to a rectangle; first we want to make sure the entire focus |
| 2951 | // view is visible. |
| 2952 | rectangle = null; |
| 2953 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2954 | 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] | 2955 | + " rectangle=" + rectangle + " ci=" + ci |
| 2956 | + " vi=" + vi); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2957 | if (focus == lastScrolledFocus && !mScrollMayChange && rectangle == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2958 | // Optimization: if the focus hasn't changed since last |
| 2959 | // time, and no layout has happened, then just leave things |
| 2960 | // as they are. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2961 | 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] | 2962 | + mScrollY + " vi=" + vi.toShortString()); |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 2963 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2964 | // We need to determine if the currently focused view is |
| 2965 | // within the visible part of the window and, if not, apply |
| 2966 | // a pan so it can be seen. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2967 | mLastScrolledFocus = new WeakReference<View>(focus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2968 | mScrollMayChange = false; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2969 | 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] | 2970 | // Try to find the rectangle from the focus view. |
| 2971 | if (focus.getGlobalVisibleRect(mVisRect, null)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2972 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Root w=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2973 | + mView.getWidth() + " h=" + mView.getHeight() |
| 2974 | + " ci=" + ci.toShortString() |
| 2975 | + " vi=" + vi.toShortString()); |
| 2976 | if (rectangle == null) { |
| 2977 | focus.getFocusedRect(mTempRect); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2978 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Focus " + focus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2979 | + ": focusRect=" + mTempRect.toShortString()); |
Dianne Hackborn | 1c6a894 | 2010-03-23 16:34:20 -0700 | [diff] [blame] | 2980 | if (mView instanceof ViewGroup) { |
| 2981 | ((ViewGroup) mView).offsetDescendantRectToMyCoords( |
| 2982 | focus, mTempRect); |
| 2983 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2984 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2985 | "Focus in window: focusRect=" |
| 2986 | + mTempRect.toShortString() |
| 2987 | + " visRect=" + mVisRect.toShortString()); |
| 2988 | } else { |
| 2989 | mTempRect.set(rectangle); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2990 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2991 | "Request scroll to rect: " |
| 2992 | + mTempRect.toShortString() |
| 2993 | + " visRect=" + mVisRect.toShortString()); |
| 2994 | } |
| 2995 | if (mTempRect.intersect(mVisRect)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2996 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2997 | "Focus window visible rect: " |
| 2998 | + mTempRect.toShortString()); |
| 2999 | if (mTempRect.height() > |
| 3000 | (mView.getHeight()-vi.top-vi.bottom)) { |
| 3001 | // If the focus simply is not going to fit, then |
| 3002 | // best is probably just to leave things as-is. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3003 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3004 | "Too tall; leaving scrollY=" + scrollY); |
| 3005 | } else if ((mTempRect.top-scrollY) < vi.top) { |
| 3006 | scrollY -= vi.top - (mTempRect.top-scrollY); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3007 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3008 | "Top covered; scrollY=" + scrollY); |
| 3009 | } else if ((mTempRect.bottom-scrollY) |
| 3010 | > (mView.getHeight()-vi.bottom)) { |
| 3011 | scrollY += (mTempRect.bottom-scrollY) |
| 3012 | - (mView.getHeight()-vi.bottom); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3013 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3014 | "Bottom covered; scrollY=" + scrollY); |
| 3015 | } |
| 3016 | handled = true; |
| 3017 | } |
| 3018 | } |
| 3019 | } |
| 3020 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3022 | if (scrollY != mScrollY) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3023 | 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] | 3024 | + mScrollY + " , new=" + scrollY); |
Derek Sollenberger | 8d94835 | 2015-07-16 09:27:59 -0400 | [diff] [blame] | 3025 | if (!immediate) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3026 | if (mScroller == null) { |
| 3027 | mScroller = new Scroller(mView.getContext()); |
| 3028 | } |
| 3029 | mScroller.startScroll(0, mScrollY, 0, scrollY-mScrollY); |
| 3030 | } else if (mScroller != null) { |
| 3031 | mScroller.abortAnimation(); |
| 3032 | } |
| 3033 | mScrollY = scrollY; |
| 3034 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3035 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | return handled; |
| 3037 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3038 | |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3039 | /** |
| 3040 | * @hide |
| 3041 | */ |
| 3042 | public View getAccessibilityFocusedHost() { |
| 3043 | return mAccessibilityFocusedHost; |
| 3044 | } |
| 3045 | |
| 3046 | /** |
| 3047 | * @hide |
| 3048 | */ |
| 3049 | public AccessibilityNodeInfo getAccessibilityFocusedVirtualView() { |
| 3050 | return mAccessibilityFocusedVirtualView; |
| 3051 | } |
| 3052 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3053 | void setAccessibilityFocus(View view, AccessibilityNodeInfo node) { |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3054 | // If we have a virtual view with accessibility focus we need |
| 3055 | // to clear the focus and invalidate the virtual view bounds. |
| 3056 | if (mAccessibilityFocusedVirtualView != null) { |
| 3057 | |
| 3058 | AccessibilityNodeInfo focusNode = mAccessibilityFocusedVirtualView; |
| 3059 | View focusHost = mAccessibilityFocusedHost; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3060 | |
| 3061 | // Wipe the state of the current accessibility focus since |
| 3062 | // the call into the provider to clear accessibility focus |
| 3063 | // will fire an accessibility event which will end up calling |
| 3064 | // this method and we want to have clean state when this |
| 3065 | // invocation happens. |
| 3066 | mAccessibilityFocusedHost = null; |
| 3067 | mAccessibilityFocusedVirtualView = null; |
| 3068 | |
Alan Viverette | 239a0c0 | 2013-05-07 17:17:35 -0700 | [diff] [blame] | 3069 | // Clear accessibility focus on the host after clearing state since |
| 3070 | // this method may be reentrant. |
| 3071 | focusHost.clearAccessibilityFocusNoCallbacks(); |
| 3072 | |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3073 | AccessibilityNodeProvider provider = focusHost.getAccessibilityNodeProvider(); |
| 3074 | if (provider != null) { |
| 3075 | // Invalidate the area of the cleared accessibility focus. |
| 3076 | focusNode.getBoundsInParent(mTempRect); |
| 3077 | focusHost.invalidate(mTempRect); |
| 3078 | // Clear accessibility focus in the virtual node. |
| 3079 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 3080 | focusNode.getSourceNodeId()); |
| 3081 | provider.performAction(virtualNodeId, |
| 3082 | AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null); |
| 3083 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3084 | focusNode.recycle(); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3085 | } |
| 3086 | if (mAccessibilityFocusedHost != null) { |
| 3087 | // Clear accessibility focus in the view. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3088 | mAccessibilityFocusedHost.clearAccessibilityFocusNoCallbacks(); |
| 3089 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3090 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3091 | // Set the new focus host and node. |
| 3092 | mAccessibilityFocusedHost = view; |
| 3093 | mAccessibilityFocusedVirtualView = node; |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 3094 | |
| 3095 | if (mAttachInfo.mHardwareRenderer != null) { |
| 3096 | mAttachInfo.mHardwareRenderer.invalidateRoot(); |
| 3097 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3098 | } |
| 3099 | |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3100 | void setPointerCapture(View view) { |
| 3101 | if (!mAttachInfo.mHasWindowFocus) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3102 | Log.w(mTag, "Can't set capture if it's not focused."); |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3103 | return; |
| 3104 | } |
| 3105 | if (mCapturingView == view) { |
| 3106 | return; |
| 3107 | } |
| 3108 | mCapturingView = view; |
| 3109 | InputManager.getInstance().setPointerIconDetached(true); |
| 3110 | } |
| 3111 | |
| 3112 | void releasePointerCapture(View view) { |
| 3113 | if (mCapturingView != view || mCapturingView == null) { |
| 3114 | return; |
| 3115 | } |
| 3116 | |
| 3117 | mCapturingView = null; |
| 3118 | InputManager.getInstance().setPointerIconDetached(false); |
| 3119 | } |
| 3120 | |
| 3121 | boolean hasPointerCapture(View view) { |
| 3122 | return view != null && mCapturingView == view; |
| 3123 | } |
| 3124 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3125 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3126 | public void requestChildFocus(View child, View focused) { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3127 | if (DEBUG_INPUT_RESIZE) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3128 | Log.v(mTag, "Request child focus: focus now " + focused); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3129 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3130 | checkThread(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3131 | scheduleTraversals(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3132 | } |
| 3133 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3134 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3135 | public void clearChildFocus(View child) { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3136 | if (DEBUG_INPUT_RESIZE) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3137 | Log.v(mTag, "Clearing child focus"); |
Amith Yamasani | 73eb97f | 2012-02-14 15:45:15 -0800 | [diff] [blame] | 3138 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3139 | checkThread(); |
| 3140 | scheduleTraversals(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3141 | } |
Amith Yamasani | 73eb97f | 2012-02-14 15:45:15 -0800 | [diff] [blame] | 3142 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3143 | @Override |
| 3144 | public ViewParent getParentForAccessibility() { |
| 3145 | return null; |
| 3146 | } |
| 3147 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3148 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3149 | public void focusableViewAvailable(View v) { |
| 3150 | checkThread(); |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3151 | if (mView != null) { |
| 3152 | if (!mView.hasFocus()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3153 | v.requestFocus(); |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3154 | } else { |
| 3155 | // the one case where will transfer focus away from the current one |
| 3156 | // is if the current view is a view group that prefers to give focus |
| 3157 | // to its children first AND the view is a descendant of it. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3158 | View focused = mView.findFocus(); |
| 3159 | if (focused instanceof ViewGroup) { |
| 3160 | ViewGroup group = (ViewGroup) focused; |
| 3161 | if (group.getDescendantFocusability() == ViewGroup.FOCUS_AFTER_DESCENDANTS |
| 3162 | && isViewDescendantOf(v, focused)) { |
| 3163 | v.requestFocus(); |
| 3164 | } |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3165 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3166 | } |
| 3167 | } |
| 3168 | } |
| 3169 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3170 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3171 | public void recomputeViewAttributes(View child) { |
| 3172 | checkThread(); |
| 3173 | if (mView == child) { |
| 3174 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 3175 | if (!mWillDrawSoon) { |
| 3176 | scheduleTraversals(); |
| 3177 | } |
| 3178 | } |
| 3179 | } |
| 3180 | |
| 3181 | void dispatchDetachedFromWindow() { |
Romain Guy | 90fc03b | 2011-01-16 13:07:15 -0800 | [diff] [blame] | 3182 | if (mView != null && mView.mAttachInfo != null) { |
Dianne Hackborn | 961cae9 | 2013-03-20 14:59:43 -0700 | [diff] [blame] | 3183 | mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3184 | mView.dispatchDetachedFromWindow(); |
| 3185 | } |
| 3186 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3187 | mAccessibilityInteractionConnectionManager.ensureNoConnection(); |
| 3188 | mAccessibilityManager.removeAccessibilityStateChangeListener( |
| 3189 | mAccessibilityInteractionConnectionManager); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 3190 | mAccessibilityManager.removeHighTextContrastStateChangeListener( |
| 3191 | mHighContrastTextManager); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 3192 | removeSendWindowContentChangedCallback(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3193 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3194 | destroyHardwareRenderer(); |
| 3195 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3196 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3197 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 3198 | mView.assignParent(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3199 | mView = null; |
| 3200 | mAttachInfo.mRootView = null; |
| 3201 | |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3202 | if (mCapturingView != null) { |
| 3203 | releasePointerCapture(mCapturingView); |
| 3204 | } |
| 3205 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 3206 | mSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3207 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3208 | if (mInputQueueCallback != null && mInputQueue != null) { |
| 3209 | mInputQueueCallback.onInputQueueDestroyed(mInputQueue); |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3210 | mInputQueue.dispose(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3211 | mInputQueueCallback = null; |
| 3212 | mInputQueue = null; |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3213 | } |
| 3214 | if (mInputEventReceiver != null) { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3215 | mInputEventReceiver.dispose(); |
| 3216 | mInputEventReceiver = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3217 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3218 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3219 | mWindowSession.remove(mWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3220 | } catch (RemoteException e) { |
| 3221 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3222 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3223 | // Dispose the input channel after removing the window so the Window Manager |
| 3224 | // doesn't interpret the input channel being closed as an abnormal termination. |
| 3225 | if (mInputChannel != null) { |
| 3226 | mInputChannel.dispose(); |
| 3227 | mInputChannel = null; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3228 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3229 | |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 3230 | mDisplayManager.unregisterDisplayListener(mDisplayListener); |
| 3231 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 3232 | unscheduleTraversals(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3233 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3234 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3235 | void updateConfiguration(Configuration config, boolean force) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3236 | if (DEBUG_CONFIGURATION) Log.v(mTag, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3237 | "Applying new config to window " |
| 3238 | + mWindowAttributes.getTitle() |
| 3239 | + ": " + config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3240 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 3241 | CompatibilityInfo ci = mDisplayAdjustments.getCompatibilityInfo(); |
| 3242 | if (!ci.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3243 | config = new Configuration(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3244 | ci.applyToConfiguration(mNoncompatDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3245 | } |
| 3246 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3247 | synchronized (sConfigCallbacks) { |
| 3248 | for (int i=sConfigCallbacks.size()-1; i>=0; i--) { |
| 3249 | sConfigCallbacks.get(i).onConfigurationChanged(config); |
| 3250 | } |
| 3251 | } |
| 3252 | if (mView != null) { |
| 3253 | // At this point the resources have been updated to |
| 3254 | // have the most recent config, whatever that is. Use |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3255 | // the one in them which may be newer. |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3256 | config = mView.getResources().getConfiguration(); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3257 | if (force || mLastConfiguration.diff(config) != 0) { |
Fabrice Di Meglio | cf12897 | 2012-10-16 20:51:12 -0700 | [diff] [blame] | 3258 | final int lastLayoutDirection = mLastConfiguration.getLayoutDirection(); |
| 3259 | final int currentLayoutDirection = config.getLayoutDirection(); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3260 | mLastConfiguration.setTo(config); |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 3261 | if (lastLayoutDirection != currentLayoutDirection && |
| 3262 | mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) { |
Fabrice Di Meglio | cf12897 | 2012-10-16 20:51:12 -0700 | [diff] [blame] | 3263 | mView.setLayoutDirection(currentLayoutDirection); |
| 3264 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3265 | mView.dispatchConfigurationChanged(config); |
| 3266 | } |
| 3267 | } |
| 3268 | } |
John Reck | 05e8584 | 2014-04-23 14:48:28 -0700 | [diff] [blame] | 3269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3270 | /** |
| 3271 | * Return true if child is an ancestor of parent, (or equal to the parent). |
| 3272 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3273 | public static boolean isViewDescendantOf(View child, View parent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3274 | if (child == parent) { |
| 3275 | return true; |
| 3276 | } |
| 3277 | |
| 3278 | final ViewParent theParent = child.getParent(); |
| 3279 | return (theParent instanceof ViewGroup) && isViewDescendantOf((View) theParent, parent); |
| 3280 | } |
| 3281 | |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 3282 | private static void forceLayout(View view) { |
| 3283 | view.forceLayout(); |
| 3284 | if (view instanceof ViewGroup) { |
| 3285 | ViewGroup group = (ViewGroup) view; |
| 3286 | final int count = group.getChildCount(); |
| 3287 | for (int i = 0; i < count; i++) { |
| 3288 | forceLayout(group.getChildAt(i)); |
| 3289 | } |
| 3290 | } |
| 3291 | } |
| 3292 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3293 | private final static int MSG_INVALIDATE = 1; |
| 3294 | private final static int MSG_INVALIDATE_RECT = 2; |
| 3295 | private final static int MSG_DIE = 3; |
| 3296 | private final static int MSG_RESIZED = 4; |
| 3297 | private final static int MSG_RESIZED_REPORT = 5; |
| 3298 | private final static int MSG_WINDOW_FOCUS_CHANGED = 6; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3299 | private final static int MSG_DISPATCH_INPUT_EVENT = 7; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3300 | private final static int MSG_DISPATCH_APP_VISIBILITY = 8; |
| 3301 | private final static int MSG_DISPATCH_GET_NEW_SURFACE = 9; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3302 | private final static int MSG_DISPATCH_KEY_FROM_IME = 11; |
Yohei Yukawa | 1fa5f59 | 2016-03-24 10:24:23 -0700 | [diff] [blame] | 3303 | private final static int MSG_FINISH_INPUT_CONNECTION = 12; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3304 | private final static int MSG_CHECK_FOCUS = 13; |
| 3305 | private final static int MSG_CLOSE_SYSTEM_DIALOGS = 14; |
| 3306 | private final static int MSG_DISPATCH_DRAG_EVENT = 15; |
| 3307 | private final static int MSG_DISPATCH_DRAG_LOCATION_EVENT = 16; |
| 3308 | private final static int MSG_DISPATCH_SYSTEM_UI_VISIBILITY = 17; |
| 3309 | private final static int MSG_UPDATE_CONFIGURATION = 18; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3310 | private final static int MSG_PROCESS_INPUT_EVENTS = 19; |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 3311 | private final static int MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST = 21; |
Jorim Jaggi | 827e0fa | 2015-05-07 11:41:41 -0700 | [diff] [blame] | 3312 | private final static int MSG_INVALIDATE_WORLD = 22; |
| 3313 | private final static int MSG_WINDOW_MOVED = 23; |
| 3314 | private final static int MSG_SYNTHESIZE_INPUT_EVENT = 24; |
| 3315 | private final static int MSG_DISPATCH_WINDOW_SHOWN = 25; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 3316 | private final static int MSG_REQUEST_KEYBOARD_SHORTCUTS = 26; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 3317 | private final static int MSG_UPDATE_POINTER_ICON = 27; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3318 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3319 | final class ViewRootHandler extends Handler { |
| 3320 | @Override |
| 3321 | public String getMessageName(Message message) { |
| 3322 | switch (message.what) { |
| 3323 | case MSG_INVALIDATE: |
| 3324 | return "MSG_INVALIDATE"; |
| 3325 | case MSG_INVALIDATE_RECT: |
| 3326 | return "MSG_INVALIDATE_RECT"; |
| 3327 | case MSG_DIE: |
| 3328 | return "MSG_DIE"; |
| 3329 | case MSG_RESIZED: |
| 3330 | return "MSG_RESIZED"; |
| 3331 | case MSG_RESIZED_REPORT: |
| 3332 | return "MSG_RESIZED_REPORT"; |
| 3333 | case MSG_WINDOW_FOCUS_CHANGED: |
| 3334 | return "MSG_WINDOW_FOCUS_CHANGED"; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3335 | case MSG_DISPATCH_INPUT_EVENT: |
| 3336 | return "MSG_DISPATCH_INPUT_EVENT"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3337 | case MSG_DISPATCH_APP_VISIBILITY: |
| 3338 | return "MSG_DISPATCH_APP_VISIBILITY"; |
| 3339 | case MSG_DISPATCH_GET_NEW_SURFACE: |
| 3340 | return "MSG_DISPATCH_GET_NEW_SURFACE"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3341 | case MSG_DISPATCH_KEY_FROM_IME: |
| 3342 | return "MSG_DISPATCH_KEY_FROM_IME"; |
Yohei Yukawa | 1fa5f59 | 2016-03-24 10:24:23 -0700 | [diff] [blame] | 3343 | case MSG_FINISH_INPUT_CONNECTION: |
| 3344 | return "MSG_FINISH_INPUT_CONNECTION"; |
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; |
Yohei Yukawa | 1fa5f59 | 2016-03-24 10:24:23 -0700 | [diff] [blame] | 3565 | case MSG_FINISH_INPUT_CONNECTION: { |
| 3566 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 3567 | if (imm != null) { |
| 3568 | imm.reportFinishInputConnection((InputConnection)msg.obj); |
| 3569 | } |
| 3570 | } break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3571 | case MSG_CHECK_FOCUS: { |
| 3572 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 3573 | if (imm != null) { |
| 3574 | imm.checkFocus(); |
| 3575 | } |
| 3576 | } break; |
| 3577 | case MSG_CLOSE_SYSTEM_DIALOGS: { |
| 3578 | if (mView != null) { |
| 3579 | mView.onCloseSystemDialogs((String)msg.obj); |
| 3580 | } |
| 3581 | } break; |
| 3582 | case MSG_DISPATCH_DRAG_EVENT: |
| 3583 | case MSG_DISPATCH_DRAG_LOCATION_EVENT: { |
| 3584 | DragEvent event = (DragEvent)msg.obj; |
| 3585 | event.mLocalState = mLocalDragState; // only present when this app called startDrag() |
| 3586 | handleDragEvent(event); |
| 3587 | } break; |
| 3588 | case MSG_DISPATCH_SYSTEM_UI_VISIBILITY: { |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 3589 | handleDispatchSystemUiVisibilityChanged((SystemUiVisibilityInfo) msg.obj); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3590 | } break; |
| 3591 | case MSG_UPDATE_CONFIGURATION: { |
| 3592 | Configuration config = (Configuration)msg.obj; |
| 3593 | if (config.isOtherSeqNewer(mLastConfiguration)) { |
| 3594 | config = mLastConfiguration; |
| 3595 | } |
| 3596 | updateConfiguration(config, false); |
| 3597 | } break; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 3598 | case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3599 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 3600 | } break; |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 3601 | case MSG_INVALIDATE_WORLD: { |
Romain Guy | f84208f | 2012-09-13 22:50:18 -0700 | [diff] [blame] | 3602 | if (mView != null) { |
| 3603 | invalidateWorld(mView); |
| 3604 | } |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 3605 | } break; |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 3606 | case MSG_DISPATCH_WINDOW_SHOWN: { |
| 3607 | handleDispatchWindowShown(); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 3608 | } break; |
| 3609 | case MSG_REQUEST_KEYBOARD_SHORTCUTS: { |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 3610 | final IResultReceiver receiver = (IResultReceiver) msg.obj; |
| 3611 | final int deviceId = msg.arg1; |
| 3612 | handleRequestKeyboardShortcuts(receiver, deviceId); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 3613 | } break; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 3614 | case MSG_UPDATE_POINTER_ICON: { |
| 3615 | MotionEvent event = (MotionEvent) msg.obj; |
| 3616 | resetPointerIcon(event); |
| 3617 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3619 | } |
| 3620 | } |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 3621 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3622 | final ViewRootHandler mHandler = new ViewRootHandler(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3623 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3624 | /** |
| 3625 | * Something in the current window tells us we need to change the touch mode. For |
| 3626 | * example, we are not in touch mode, and the user touches the screen. |
| 3627 | * |
| 3628 | * If the touch mode has changed, tell the window manager, and handle it locally. |
| 3629 | * |
| 3630 | * @param inTouchMode Whether we want to be in touch mode. |
| 3631 | * @return True if the touch mode changed and focus changed was changed as a result |
| 3632 | */ |
| 3633 | boolean ensureTouchMode(boolean inTouchMode) { |
| 3634 | if (DBG) Log.d("touchmode", "ensureTouchMode(" + inTouchMode + "), current " |
| 3635 | + "touch mode is " + mAttachInfo.mInTouchMode); |
| 3636 | if (mAttachInfo.mInTouchMode == inTouchMode) return false; |
| 3637 | |
| 3638 | // tell the window manager |
| 3639 | try { |
Matt Wu | d6bc96d | 2016-01-14 12:59:24 -0800 | [diff] [blame] | 3640 | mWindowSession.setInTouchMode(inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | } catch (RemoteException e) { |
| 3642 | throw new RuntimeException(e); |
| 3643 | } |
| 3644 | |
| 3645 | // handle the change |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3646 | return ensureTouchModeLocally(inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | /** |
| 3650 | * Ensure that the touch mode for this window is set, and if it is changing, |
| 3651 | * take the appropriate action. |
| 3652 | * @param inTouchMode Whether we want to be in touch mode. |
| 3653 | * @return True if the touch mode changed and focus changed was changed as a result |
| 3654 | */ |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3655 | private boolean ensureTouchModeLocally(boolean inTouchMode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3656 | if (DBG) Log.d("touchmode", "ensureTouchModeLocally(" + inTouchMode + "), current " |
| 3657 | + "touch mode is " + mAttachInfo.mInTouchMode); |
| 3658 | |
| 3659 | if (mAttachInfo.mInTouchMode == inTouchMode) return false; |
| 3660 | |
| 3661 | mAttachInfo.mInTouchMode = inTouchMode; |
| 3662 | mAttachInfo.mTreeObserver.dispatchOnTouchModeChanged(inTouchMode); |
| 3663 | |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3664 | return (inTouchMode) ? enterTouchMode() : leaveTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | private boolean enterTouchMode() { |
Alan Viverette | ed7821a | 2013-07-24 15:49:23 -0700 | [diff] [blame] | 3668 | if (mView != null && mView.hasFocus()) { |
| 3669 | // note: not relying on mFocusedView here because this could |
| 3670 | // be when the window is first being added, and mFocused isn't |
| 3671 | // set yet. |
| 3672 | final View focused = mView.findFocus(); |
| 3673 | if (focused != null && !focused.isFocusableInTouchMode()) { |
| 3674 | final ViewGroup ancestorToTakeFocus = findAncestorToTakeFocusInTouchMode(focused); |
| 3675 | if (ancestorToTakeFocus != null) { |
| 3676 | // there is an ancestor that wants focus after its |
| 3677 | // descendants that is focusable in touch mode.. give it |
| 3678 | // focus |
| 3679 | return ancestorToTakeFocus.requestFocus(); |
| 3680 | } else { |
Alan Viverette | 973f3b4 | 2013-08-13 16:57:28 -0700 | [diff] [blame] | 3681 | // There's nothing to focus. Clear and propagate through the |
| 3682 | // hierarchy, but don't attempt to place new focus. |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 3683 | focused.clearFocusInternal(null, true, false); |
Alan Viverette | ed7821a | 2013-07-24 15:49:23 -0700 | [diff] [blame] | 3684 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3685 | } |
| 3686 | } |
| 3687 | } |
| 3688 | return false; |
| 3689 | } |
| 3690 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3691 | /** |
| 3692 | * Find an ancestor of focused that wants focus after its descendants and is |
| 3693 | * focusable in touch mode. |
| 3694 | * @param focused The currently focused view. |
| 3695 | * @return An appropriate view, or null if no such view exists. |
| 3696 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3697 | private static ViewGroup findAncestorToTakeFocusInTouchMode(View focused) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3698 | ViewParent parent = focused.getParent(); |
| 3699 | while (parent instanceof ViewGroup) { |
| 3700 | final ViewGroup vgParent = (ViewGroup) parent; |
| 3701 | if (vgParent.getDescendantFocusability() == ViewGroup.FOCUS_AFTER_DESCENDANTS |
| 3702 | && vgParent.isFocusableInTouchMode()) { |
| 3703 | return vgParent; |
| 3704 | } |
| 3705 | if (vgParent.isRootNamespace()) { |
| 3706 | return null; |
| 3707 | } else { |
| 3708 | parent = vgParent.getParent(); |
| 3709 | } |
| 3710 | } |
| 3711 | return null; |
| 3712 | } |
| 3713 | |
| 3714 | private boolean leaveTouchMode() { |
| 3715 | if (mView != null) { |
| 3716 | if (mView.hasFocus()) { |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3717 | View focusedView = mView.findFocus(); |
| 3718 | if (!(focusedView instanceof ViewGroup)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3719 | // some view has focus, let it keep it |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 3720 | return false; |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3721 | } else if (((ViewGroup) focusedView).getDescendantFocusability() != |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3722 | ViewGroup.FOCUS_AFTER_DESCENDANTS) { |
| 3723 | // some view group has focus, and doesn't prefer its children |
| 3724 | // over itself for focus, so let them keep it. |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 3725 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3726 | } |
| 3727 | } |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 3728 | |
| 3729 | // find the best view to give focus to in this brave new non-touch-mode |
| 3730 | // world |
| 3731 | final View focused = focusSearch(null, View.FOCUS_DOWN); |
| 3732 | if (focused != null) { |
| 3733 | return focused.requestFocus(View.FOCUS_DOWN); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3734 | } |
| 3735 | } |
| 3736 | return false; |
| 3737 | } |
| 3738 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3739 | /** |
| 3740 | * Base class for implementing a stage in the chain of responsibility |
| 3741 | * for processing input events. |
| 3742 | * <p> |
| 3743 | * Events are delivered to the stage by the {@link #deliver} method. The stage |
| 3744 | * then has the choice of finishing the event or forwarding it to the next stage. |
| 3745 | * </p> |
| 3746 | */ |
| 3747 | abstract class InputStage { |
| 3748 | private final InputStage mNext; |
| 3749 | |
| 3750 | protected static final int FORWARD = 0; |
| 3751 | protected static final int FINISH_HANDLED = 1; |
| 3752 | protected static final int FINISH_NOT_HANDLED = 2; |
| 3753 | |
| 3754 | /** |
| 3755 | * Creates an input stage. |
| 3756 | * @param next The next stage to which events should be forwarded. |
| 3757 | */ |
| 3758 | public InputStage(InputStage next) { |
| 3759 | mNext = next; |
| 3760 | } |
| 3761 | |
| 3762 | /** |
| 3763 | * Delivers an event to be processed. |
| 3764 | */ |
| 3765 | public final void deliver(QueuedInputEvent q) { |
| 3766 | if ((q.mFlags & QueuedInputEvent.FLAG_FINISHED) != 0) { |
| 3767 | forward(q); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 3768 | } else if (shouldDropInputEvent(q)) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3769 | finish(q, false); |
| 3770 | } else { |
| 3771 | apply(q, onProcess(q)); |
| 3772 | } |
| 3773 | } |
| 3774 | |
| 3775 | /** |
| 3776 | * Marks the the input event as finished then forwards it to the next stage. |
| 3777 | */ |
| 3778 | protected void finish(QueuedInputEvent q, boolean handled) { |
| 3779 | q.mFlags |= QueuedInputEvent.FLAG_FINISHED; |
| 3780 | if (handled) { |
| 3781 | q.mFlags |= QueuedInputEvent.FLAG_FINISHED_HANDLED; |
| 3782 | } |
| 3783 | forward(q); |
| 3784 | } |
| 3785 | |
| 3786 | /** |
| 3787 | * Forwards the event to the next stage. |
| 3788 | */ |
| 3789 | protected void forward(QueuedInputEvent q) { |
| 3790 | onDeliverToNext(q); |
| 3791 | } |
| 3792 | |
| 3793 | /** |
| 3794 | * Applies a result code from {@link #onProcess} to the specified event. |
| 3795 | */ |
| 3796 | protected void apply(QueuedInputEvent q, int result) { |
| 3797 | if (result == FORWARD) { |
| 3798 | forward(q); |
| 3799 | } else if (result == FINISH_HANDLED) { |
| 3800 | finish(q, true); |
| 3801 | } else if (result == FINISH_NOT_HANDLED) { |
| 3802 | finish(q, false); |
| 3803 | } else { |
| 3804 | throw new IllegalArgumentException("Invalid result: " + result); |
| 3805 | } |
| 3806 | } |
| 3807 | |
| 3808 | /** |
| 3809 | * Called when an event is ready to be processed. |
| 3810 | * @return A result code indicating how the event was handled. |
| 3811 | */ |
| 3812 | protected int onProcess(QueuedInputEvent q) { |
| 3813 | return FORWARD; |
| 3814 | } |
| 3815 | |
| 3816 | /** |
| 3817 | * Called when an event is being delivered to the next stage. |
| 3818 | */ |
| 3819 | protected void onDeliverToNext(QueuedInputEvent q) { |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 3820 | if (DEBUG_INPUT_STAGES) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3821 | Log.v(mTag, "Done with " + getClass().getSimpleName() + ". " + q); |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 3822 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3823 | if (mNext != null) { |
| 3824 | mNext.deliver(q); |
| 3825 | } else { |
| 3826 | finishInputEvent(q); |
| 3827 | } |
| 3828 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 3829 | |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 3830 | protected boolean shouldDropInputEvent(QueuedInputEvent q) { |
| 3831 | if (mView == null || !mAdded) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3832 | 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] | 3833 | return true; |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 3834 | } else if ((!mAttachInfo.mHasWindowFocus |
| 3835 | && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) || mStopped |
Joe LaPenna | 90776de | 2016-01-22 07:11:49 -0800 | [diff] [blame] | 3836 | || (mIsAmbientMode && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_BUTTON)) |
| 3837 | || (mPausedForTransition && !isBack(q.mEvent))) { |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 3838 | // This is a focus event and the window doesn't currently have input focus or |
| 3839 | // has stopped. This could be an event that came back from the previous stage |
| 3840 | // but the window has lost focus or stopped in the meantime. |
| 3841 | if (isTerminalInputEvent(q.mEvent)) { |
| 3842 | // Don't drop terminal input events, however mark them as canceled. |
| 3843 | q.mEvent.cancel(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3844 | Slog.w(mTag, "Cancelling event due to no window focus: " + q.mEvent); |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 3845 | return false; |
| 3846 | } |
| 3847 | |
| 3848 | // Drop non-terminal input events. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3849 | Slog.w(mTag, "Dropping event due to no window focus: " + q.mEvent); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 3850 | return true; |
| 3851 | } |
| 3852 | return false; |
| 3853 | } |
| 3854 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 3855 | void dump(String prefix, PrintWriter writer) { |
| 3856 | if (mNext != null) { |
| 3857 | mNext.dump(prefix, writer); |
| 3858 | } |
| 3859 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 3860 | |
| 3861 | private boolean isBack(InputEvent event) { |
| 3862 | if (event instanceof KeyEvent) { |
| 3863 | return ((KeyEvent) event).getKeyCode() == KeyEvent.KEYCODE_BACK; |
| 3864 | } else { |
| 3865 | return false; |
| 3866 | } |
| 3867 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3868 | } |
| 3869 | |
| 3870 | /** |
| 3871 | * Base class for implementing an input pipeline stage that supports |
| 3872 | * asynchronous and out-of-order processing of input events. |
| 3873 | * <p> |
| 3874 | * In addition to what a normal input stage can do, an asynchronous |
| 3875 | * input stage may also defer an input event that has been delivered to it |
| 3876 | * and finish or forward it later. |
| 3877 | * </p> |
| 3878 | */ |
| 3879 | abstract class AsyncInputStage extends InputStage { |
| 3880 | private final String mTraceCounter; |
| 3881 | |
| 3882 | private QueuedInputEvent mQueueHead; |
| 3883 | private QueuedInputEvent mQueueTail; |
| 3884 | private int mQueueLength; |
| 3885 | |
| 3886 | protected static final int DEFER = 3; |
| 3887 | |
| 3888 | /** |
| 3889 | * Creates an asynchronous input stage. |
| 3890 | * @param next The next stage to which events should be forwarded. |
| 3891 | * @param traceCounter The name of a counter to record the size of |
| 3892 | * the queue of pending events. |
| 3893 | */ |
| 3894 | public AsyncInputStage(InputStage next, String traceCounter) { |
| 3895 | super(next); |
| 3896 | mTraceCounter = traceCounter; |
| 3897 | } |
| 3898 | |
| 3899 | /** |
| 3900 | * Marks the event as deferred, which is to say that it will be handled |
| 3901 | * asynchronously. The caller is responsible for calling {@link #forward} |
| 3902 | * or {@link #finish} later when it is done handling the event. |
| 3903 | */ |
| 3904 | protected void defer(QueuedInputEvent q) { |
| 3905 | q.mFlags |= QueuedInputEvent.FLAG_DEFERRED; |
| 3906 | enqueue(q); |
| 3907 | } |
| 3908 | |
| 3909 | @Override |
| 3910 | protected void forward(QueuedInputEvent q) { |
| 3911 | // Clear the deferred flag. |
| 3912 | q.mFlags &= ~QueuedInputEvent.FLAG_DEFERRED; |
| 3913 | |
| 3914 | // Fast path if the queue is empty. |
| 3915 | QueuedInputEvent curr = mQueueHead; |
| 3916 | if (curr == null) { |
| 3917 | super.forward(q); |
| 3918 | return; |
| 3919 | } |
| 3920 | |
| 3921 | // Determine whether the event must be serialized behind any others |
| 3922 | // before it can be delivered to the next stage. This is done because |
| 3923 | // deferred events might be handled out of order by the stage. |
| 3924 | final int deviceId = q.mEvent.getDeviceId(); |
| 3925 | QueuedInputEvent prev = null; |
| 3926 | boolean blocked = false; |
| 3927 | while (curr != null && curr != q) { |
| 3928 | if (!blocked && deviceId == curr.mEvent.getDeviceId()) { |
| 3929 | blocked = true; |
| 3930 | } |
| 3931 | prev = curr; |
| 3932 | curr = curr.mNext; |
| 3933 | } |
| 3934 | |
| 3935 | // If the event is blocked, then leave it in the queue to be delivered later. |
| 3936 | // Note that the event might not yet be in the queue if it was not previously |
| 3937 | // deferred so we will enqueue it if needed. |
| 3938 | if (blocked) { |
| 3939 | if (curr == null) { |
| 3940 | enqueue(q); |
| 3941 | } |
| 3942 | return; |
| 3943 | } |
| 3944 | |
| 3945 | // The event is not blocked. Deliver it immediately. |
| 3946 | if (curr != null) { |
| 3947 | curr = curr.mNext; |
| 3948 | dequeue(q, prev); |
| 3949 | } |
| 3950 | super.forward(q); |
| 3951 | |
| 3952 | // Dequeuing this event may have unblocked successors. Deliver them. |
| 3953 | while (curr != null) { |
| 3954 | if (deviceId == curr.mEvent.getDeviceId()) { |
| 3955 | if ((curr.mFlags & QueuedInputEvent.FLAG_DEFERRED) != 0) { |
| 3956 | break; |
| 3957 | } |
| 3958 | QueuedInputEvent next = curr.mNext; |
| 3959 | dequeue(curr, prev); |
| 3960 | super.forward(curr); |
| 3961 | curr = next; |
| 3962 | } else { |
| 3963 | prev = curr; |
| 3964 | curr = curr.mNext; |
| 3965 | } |
| 3966 | } |
| 3967 | } |
| 3968 | |
| 3969 | @Override |
| 3970 | protected void apply(QueuedInputEvent q, int result) { |
| 3971 | if (result == DEFER) { |
| 3972 | defer(q); |
| 3973 | } else { |
| 3974 | super.apply(q, result); |
| 3975 | } |
| 3976 | } |
| 3977 | |
| 3978 | private void enqueue(QueuedInputEvent q) { |
| 3979 | if (mQueueTail == null) { |
| 3980 | mQueueHead = q; |
| 3981 | mQueueTail = q; |
| 3982 | } else { |
| 3983 | mQueueTail.mNext = q; |
| 3984 | mQueueTail = q; |
| 3985 | } |
| 3986 | |
| 3987 | mQueueLength += 1; |
| 3988 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mTraceCounter, mQueueLength); |
| 3989 | } |
| 3990 | |
| 3991 | private void dequeue(QueuedInputEvent q, QueuedInputEvent prev) { |
| 3992 | if (prev == null) { |
| 3993 | mQueueHead = q.mNext; |
| 3994 | } else { |
| 3995 | prev.mNext = q.mNext; |
| 3996 | } |
| 3997 | if (mQueueTail == q) { |
| 3998 | mQueueTail = prev; |
| 3999 | } |
| 4000 | q.mNext = null; |
| 4001 | |
| 4002 | mQueueLength -= 1; |
| 4003 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mTraceCounter, mQueueLength); |
| 4004 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 4005 | |
| 4006 | @Override |
| 4007 | void dump(String prefix, PrintWriter writer) { |
| 4008 | writer.print(prefix); |
| 4009 | writer.print(getClass().getName()); |
| 4010 | writer.print(": mQueueLength="); |
| 4011 | writer.println(mQueueLength); |
| 4012 | |
| 4013 | super.dump(prefix, writer); |
| 4014 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4015 | } |
| 4016 | |
| 4017 | /** |
| 4018 | * Delivers pre-ime input events to a native activity. |
| 4019 | * Does not support pointer events. |
| 4020 | */ |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4021 | final class NativePreImeInputStage extends AsyncInputStage |
| 4022 | implements InputQueue.FinishedInputEventCallback { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4023 | public NativePreImeInputStage(InputStage next, String traceCounter) { |
| 4024 | super(next, traceCounter); |
| 4025 | } |
| 4026 | |
| 4027 | @Override |
| 4028 | protected int onProcess(QueuedInputEvent q) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4029 | if (mInputQueue != null && q.mEvent instanceof KeyEvent) { |
| 4030 | mInputQueue.sendInputEvent(q.mEvent, q, true, this); |
| 4031 | return DEFER; |
| 4032 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4033 | return FORWARD; |
| 4034 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4035 | |
| 4036 | @Override |
| 4037 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4038 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4039 | if (handled) { |
| 4040 | finish(q, true); |
| 4041 | return; |
| 4042 | } |
| 4043 | forward(q); |
| 4044 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | /** |
| 4048 | * Delivers pre-ime input events to the view hierarchy. |
| 4049 | * Does not support pointer events. |
| 4050 | */ |
| 4051 | final class ViewPreImeInputStage extends InputStage { |
| 4052 | public ViewPreImeInputStage(InputStage next) { |
| 4053 | super(next); |
| 4054 | } |
| 4055 | |
| 4056 | @Override |
| 4057 | protected int onProcess(QueuedInputEvent q) { |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4058 | if (q.mEvent instanceof KeyEvent) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4059 | return processKeyEvent(q); |
| 4060 | } |
| 4061 | return FORWARD; |
| 4062 | } |
| 4063 | |
| 4064 | private int processKeyEvent(QueuedInputEvent q) { |
| 4065 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4066 | if (mView.dispatchKeyEventPreIme(event)) { |
| 4067 | return FINISH_HANDLED; |
| 4068 | } |
| 4069 | return FORWARD; |
| 4070 | } |
| 4071 | } |
| 4072 | |
| 4073 | /** |
| 4074 | * Delivers input events to the ime. |
| 4075 | * Does not support pointer events. |
| 4076 | */ |
| 4077 | final class ImeInputStage extends AsyncInputStage |
| 4078 | implements InputMethodManager.FinishedInputEventCallback { |
| 4079 | public ImeInputStage(InputStage next, String traceCounter) { |
| 4080 | super(next, traceCounter); |
| 4081 | } |
| 4082 | |
| 4083 | @Override |
| 4084 | protected int onProcess(QueuedInputEvent q) { |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 4085 | if (mLastWasImTarget && !isInLocalFocusMode()) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4086 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4087 | if (imm != null) { |
| 4088 | final InputEvent event = q.mEvent; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4089 | if (DEBUG_IMF) Log.v(mTag, "Sending input event to IME: " + event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4090 | int result = imm.dispatchInputEvent(event, q, this, mHandler); |
| 4091 | if (result == InputMethodManager.DISPATCH_HANDLED) { |
| 4092 | return FINISH_HANDLED; |
| 4093 | } else if (result == InputMethodManager.DISPATCH_NOT_HANDLED) { |
Adam Lesinski | c0f6eed | 2013-10-28 16:03:19 -0700 | [diff] [blame] | 4094 | // The IME could not handle it, so skip along to the next InputStage |
| 4095 | return FORWARD; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4096 | } else { |
| 4097 | return DEFER; // callback will be invoked later |
| 4098 | } |
| 4099 | } |
| 4100 | } |
| 4101 | return FORWARD; |
| 4102 | } |
| 4103 | |
| 4104 | @Override |
| 4105 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4106 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4107 | if (handled) { |
| 4108 | finish(q, true); |
| 4109 | return; |
| 4110 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4111 | forward(q); |
| 4112 | } |
| 4113 | } |
| 4114 | |
| 4115 | /** |
| 4116 | * Performs early processing of post-ime input events. |
| 4117 | */ |
| 4118 | final class EarlyPostImeInputStage extends InputStage { |
| 4119 | public EarlyPostImeInputStage(InputStage next) { |
| 4120 | super(next); |
| 4121 | } |
| 4122 | |
| 4123 | @Override |
| 4124 | protected int onProcess(QueuedInputEvent q) { |
| 4125 | if (q.mEvent instanceof KeyEvent) { |
| 4126 | return processKeyEvent(q); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4127 | } else { |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4128 | final int source = q.mEvent.getSource(); |
| 4129 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4130 | return processPointerEvent(q); |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4131 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4132 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4133 | return FORWARD; |
| 4134 | } |
| 4135 | |
| 4136 | private int processKeyEvent(QueuedInputEvent q) { |
| 4137 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4138 | |
| 4139 | // If the key's purpose is to exit touch mode then we consume it |
| 4140 | // and consider it handled. |
| 4141 | if (checkForLeavingTouchModeAndConsume(event)) { |
| 4142 | return FINISH_HANDLED; |
| 4143 | } |
| 4144 | |
| 4145 | // Make sure the fallback event policy sees all keys that will be |
| 4146 | // delivered to the view hierarchy. |
| 4147 | mFallbackEventHandler.preDispatchKeyEvent(event); |
| 4148 | return FORWARD; |
| 4149 | } |
| 4150 | |
| 4151 | private int processPointerEvent(QueuedInputEvent q) { |
| 4152 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4153 | |
| 4154 | // Translate the pointer event for compatibility, if needed. |
| 4155 | if (mTranslator != null) { |
| 4156 | mTranslator.translateEventInScreenToAppWindow(event); |
| 4157 | } |
| 4158 | |
| 4159 | // Enter touch mode on down or scroll. |
| 4160 | final int action = event.getAction(); |
| 4161 | if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_SCROLL) { |
| 4162 | ensureTouchMode(true); |
| 4163 | } |
| 4164 | |
| 4165 | // Offset the scroll position. |
| 4166 | if (mCurScrollY != 0) { |
| 4167 | event.offsetLocation(0, mCurScrollY); |
| 4168 | } |
| 4169 | |
| 4170 | // Remember the touch position for possible drag-initiation. |
| 4171 | if (event.isTouchEvent()) { |
| 4172 | mLastTouchPoint.x = event.getRawX(); |
| 4173 | mLastTouchPoint.y = event.getRawY(); |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 4174 | mLastTouchSource = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4175 | } |
| 4176 | return FORWARD; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4177 | } |
| 4178 | } |
| 4179 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4180 | /** |
| 4181 | * Delivers post-ime input events to a native activity. |
| 4182 | */ |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4183 | final class NativePostImeInputStage extends AsyncInputStage |
| 4184 | implements InputQueue.FinishedInputEventCallback { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4185 | public NativePostImeInputStage(InputStage next, String traceCounter) { |
| 4186 | super(next, traceCounter); |
| 4187 | } |
| 4188 | |
| 4189 | @Override |
| 4190 | protected int onProcess(QueuedInputEvent q) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4191 | if (mInputQueue != null) { |
| 4192 | mInputQueue.sendInputEvent(q.mEvent, q, false, this); |
| 4193 | return DEFER; |
| 4194 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4195 | return FORWARD; |
| 4196 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4197 | |
| 4198 | @Override |
| 4199 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4200 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4201 | if (handled) { |
| 4202 | finish(q, true); |
| 4203 | return; |
| 4204 | } |
| 4205 | forward(q); |
| 4206 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4207 | } |
| 4208 | |
| 4209 | /** |
| 4210 | * Delivers post-ime input events to the view hierarchy. |
| 4211 | */ |
| 4212 | final class ViewPostImeInputStage extends InputStage { |
| 4213 | public ViewPostImeInputStage(InputStage next) { |
| 4214 | super(next); |
| 4215 | } |
| 4216 | |
| 4217 | @Override |
| 4218 | protected int onProcess(QueuedInputEvent q) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4219 | if (q.mEvent instanceof KeyEvent) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4220 | return processKeyEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4221 | } else { |
| 4222 | final int source = q.mEvent.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4223 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 4224 | return processPointerEvent(q); |
| 4225 | } else if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
| 4226 | return processTrackballEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4227 | } else { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4228 | return processGenericMotionEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4229 | } |
| 4230 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4231 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4232 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 4233 | @Override |
| 4234 | protected void onDeliverToNext(QueuedInputEvent q) { |
| 4235 | if (mUnbufferedInputDispatch |
| 4236 | && q.mEvent instanceof MotionEvent |
| 4237 | && ((MotionEvent)q.mEvent).isTouchEvent() |
| 4238 | && isTerminalInputEvent(q.mEvent)) { |
| 4239 | mUnbufferedInputDispatch = false; |
| 4240 | scheduleConsumeBatchedInput(); |
| 4241 | } |
| 4242 | super.onDeliverToNext(q); |
| 4243 | } |
| 4244 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4245 | private int processKeyEvent(QueuedInputEvent q) { |
| 4246 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4247 | |
| 4248 | // Deliver the key to the view hierarchy. |
| 4249 | if (mView.dispatchKeyEvent(event)) { |
| 4250 | return FINISH_HANDLED; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4251 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4252 | |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4253 | if (shouldDropInputEvent(q)) { |
| 4254 | return FINISH_NOT_HANDLED; |
| 4255 | } |
| 4256 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4257 | // If the Control modifier is held, try to interpret the key as a shortcut. |
| 4258 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 4259 | && event.isCtrlPressed() |
| 4260 | && event.getRepeatCount() == 0 |
| 4261 | && !KeyEvent.isModifierKey(event.getKeyCode())) { |
| 4262 | if (mView.dispatchKeyShortcutEvent(event)) { |
| 4263 | return FINISH_HANDLED; |
| 4264 | } |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4265 | if (shouldDropInputEvent(q)) { |
| 4266 | return FINISH_NOT_HANDLED; |
| 4267 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4268 | } |
| 4269 | |
| 4270 | // Apply the fallback event policy. |
| 4271 | if (mFallbackEventHandler.dispatchKeyEvent(event)) { |
| 4272 | return FINISH_HANDLED; |
| 4273 | } |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4274 | if (shouldDropInputEvent(q)) { |
| 4275 | return FINISH_NOT_HANDLED; |
| 4276 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4277 | |
| 4278 | // Handle automatic focus changes. |
| 4279 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 4280 | int direction = 0; |
| 4281 | switch (event.getKeyCode()) { |
| 4282 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 4283 | if (event.hasNoModifiers()) { |
| 4284 | direction = View.FOCUS_LEFT; |
| 4285 | } |
| 4286 | break; |
| 4287 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 4288 | if (event.hasNoModifiers()) { |
| 4289 | direction = View.FOCUS_RIGHT; |
| 4290 | } |
| 4291 | break; |
| 4292 | case KeyEvent.KEYCODE_DPAD_UP: |
| 4293 | if (event.hasNoModifiers()) { |
| 4294 | direction = View.FOCUS_UP; |
| 4295 | } |
| 4296 | break; |
| 4297 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 4298 | if (event.hasNoModifiers()) { |
| 4299 | direction = View.FOCUS_DOWN; |
| 4300 | } |
| 4301 | break; |
| 4302 | case KeyEvent.KEYCODE_TAB: |
| 4303 | if (event.hasNoModifiers()) { |
| 4304 | direction = View.FOCUS_FORWARD; |
| 4305 | } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) { |
| 4306 | direction = View.FOCUS_BACKWARD; |
| 4307 | } |
| 4308 | break; |
| 4309 | } |
| 4310 | if (direction != 0) { |
| 4311 | View focused = mView.findFocus(); |
| 4312 | if (focused != null) { |
| 4313 | View v = focused.focusSearch(direction); |
| 4314 | if (v != null && v != focused) { |
| 4315 | // do the math the get the interesting rect |
| 4316 | // of previous focused into the coord system of |
| 4317 | // newly focused view |
| 4318 | focused.getFocusedRect(mTempRect); |
| 4319 | if (mView instanceof ViewGroup) { |
| 4320 | ((ViewGroup) mView).offsetDescendantRectToMyCoords( |
| 4321 | focused, mTempRect); |
| 4322 | ((ViewGroup) mView).offsetRectIntoDescendantCoords( |
| 4323 | v, mTempRect); |
| 4324 | } |
| 4325 | if (v.requestFocus(direction, mTempRect)) { |
| 4326 | playSoundEffect(SoundEffectConstants |
| 4327 | .getContantForFocusDirection(direction)); |
| 4328 | return FINISH_HANDLED; |
| 4329 | } |
| 4330 | } |
| 4331 | |
| 4332 | // Give the focused view a last chance to handle the dpad key. |
| 4333 | if (mView.dispatchUnhandledMove(focused, direction)) { |
| 4334 | return FINISH_HANDLED; |
| 4335 | } |
| 4336 | } else { |
| 4337 | // find the best view to give focus to in this non-touch-mode with no-focus |
| 4338 | View v = focusSearch(null, direction); |
| 4339 | if (v != null && v.requestFocus(direction)) { |
| 4340 | return FINISH_HANDLED; |
| 4341 | } |
| 4342 | } |
| 4343 | } |
| 4344 | } |
| 4345 | return FORWARD; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4346 | } |
| 4347 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4348 | private int processPointerEvent(QueuedInputEvent q) { |
| 4349 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4350 | |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 4351 | mAttachInfo.mUnbufferedDispatchRequested = false; |
| 4352 | final View eventTarget = |
| 4353 | (event.isFromSource(InputDevice.SOURCE_MOUSE) && mCapturingView != null) ? |
| 4354 | mCapturingView : mView; |
| 4355 | mAttachInfo.mHandlingPointerEvent = true; |
| 4356 | boolean handled = eventTarget.dispatchPointerEvent(event); |
| 4357 | maybeUpdatePointerIcon(event); |
| 4358 | mAttachInfo.mHandlingPointerEvent = false; |
| 4359 | if (mAttachInfo.mUnbufferedDispatchRequested && !mUnbufferedInputDispatch) { |
| 4360 | mUnbufferedInputDispatch = true; |
| 4361 | if (mConsumeBatchedInputScheduled) { |
| 4362 | scheduleConsumeBatchedInputImmediately(); |
| 4363 | } |
| 4364 | } |
| 4365 | return handled ? FINISH_HANDLED : FORWARD; |
| 4366 | } |
| 4367 | |
| 4368 | private void maybeUpdatePointerIcon(MotionEvent event) { |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 4369 | if (event.getPointerCount() == 1 |
| 4370 | && event.isFromSource(InputDevice.SOURCE_MOUSE)) { |
| 4371 | if (event.getActionMasked() == MotionEvent.ACTION_HOVER_ENTER |
| 4372 | || event.getActionMasked() == MotionEvent.ACTION_HOVER_EXIT) { |
| 4373 | // Other apps or the window manager may change the icon shape outside of |
| 4374 | // this app, therefore the icon shape has to be reset on enter/exit event. |
| 4375 | mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
| 4376 | } |
| 4377 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4378 | if (event.getActionMasked() != MotionEvent.ACTION_HOVER_EXIT) { |
| 4379 | if (!updatePointerIcon(event) && |
| 4380 | event.getActionMasked() == MotionEvent.ACTION_HOVER_MOVE) { |
| 4381 | mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 4382 | } |
| 4383 | } |
| 4384 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4385 | } |
| 4386 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4387 | private int processTrackballEvent(QueuedInputEvent q) { |
| 4388 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4389 | |
| 4390 | if (mView.dispatchTrackballEvent(event)) { |
| 4391 | return FINISH_HANDLED; |
| 4392 | } |
| 4393 | return FORWARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4394 | } |
| 4395 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4396 | private int processGenericMotionEvent(QueuedInputEvent q) { |
| 4397 | final MotionEvent event = (MotionEvent)q.mEvent; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4398 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4399 | // Deliver the event to the view. |
| 4400 | if (mView.dispatchGenericMotionEvent(event)) { |
| 4401 | return FINISH_HANDLED; |
| 4402 | } |
| 4403 | return FORWARD; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4404 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4405 | } |
| 4406 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4407 | private void resetPointerIcon(MotionEvent event) { |
| 4408 | mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
| 4409 | updatePointerIcon(event); |
| 4410 | } |
| 4411 | |
| 4412 | private boolean updatePointerIcon(MotionEvent event) { |
| 4413 | final float x = event.getX(); |
| 4414 | final float y = event.getY(); |
Andrii Kulian | 33c1bc5 | 2016-02-29 10:38:59 -0800 | [diff] [blame] | 4415 | if (mView == null) { |
| 4416 | // E.g. click outside a popup to dismiss it |
| 4417 | Slog.d(mTag, "updatePointerIcon called after view was removed"); |
| 4418 | return false; |
| 4419 | } |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4420 | if (x < 0 || x >= mView.getWidth() || y < 0 || y >= mView.getHeight()) { |
Andrii Kulian | 33c1bc5 | 2016-02-29 10:38:59 -0800 | [diff] [blame] | 4421 | // E.g. when moving window divider with mouse |
| 4422 | Slog.d(mTag, "updatePointerIcon called with position out of bounds"); |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4423 | return false; |
| 4424 | } |
| 4425 | final PointerIcon pointerIcon = mView.getPointerIcon(event, x, y); |
| 4426 | final int pointerShape = (pointerIcon != null) ? |
| 4427 | pointerIcon.getStyle() : PointerIcon.STYLE_DEFAULT; |
| 4428 | |
| 4429 | if (mPointerIconShape != pointerShape) { |
| 4430 | mPointerIconShape = pointerShape; |
| 4431 | if (mPointerIconShape != PointerIcon.STYLE_CUSTOM) { |
| 4432 | mCustomPointerIcon = null; |
| 4433 | InputManager.getInstance().setPointerIconShape(pointerShape); |
| 4434 | return true; |
| 4435 | } |
| 4436 | } |
| 4437 | if (mPointerIconShape == PointerIcon.STYLE_CUSTOM && |
| 4438 | !pointerIcon.equals(mCustomPointerIcon)) { |
| 4439 | mCustomPointerIcon = pointerIcon; |
| 4440 | InputManager.getInstance().setCustomPointerIcon(mCustomPointerIcon); |
| 4441 | } |
| 4442 | return true; |
| 4443 | } |
| 4444 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4445 | /** |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4446 | * Performs synthesis of new input events from unhandled input events. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4447 | */ |
| 4448 | final class SyntheticInputStage extends InputStage { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4449 | private final SyntheticTrackballHandler mTrackball = new SyntheticTrackballHandler(); |
| 4450 | private final SyntheticJoystickHandler mJoystick = new SyntheticJoystickHandler(); |
| 4451 | private final SyntheticTouchNavigationHandler mTouchNavigation = |
| 4452 | new SyntheticTouchNavigationHandler(); |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4453 | private final SyntheticKeyboardHandler mKeyboard = new SyntheticKeyboardHandler(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4454 | |
| 4455 | public SyntheticInputStage() { |
| 4456 | super(null); |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4457 | } |
| 4458 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4459 | @Override |
| 4460 | protected int onProcess(QueuedInputEvent q) { |
| 4461 | q.mFlags |= QueuedInputEvent.FLAG_RESYNTHESIZED; |
| 4462 | if (q.mEvent instanceof MotionEvent) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4463 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4464 | final int source = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4465 | if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4466 | mTrackball.process(event); |
| 4467 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4468 | } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4469 | mJoystick.process(event); |
| 4470 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4471 | } else if ((source & InputDevice.SOURCE_TOUCH_NAVIGATION) |
| 4472 | == InputDevice.SOURCE_TOUCH_NAVIGATION) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4473 | mTouchNavigation.process(event); |
| 4474 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4475 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4476 | } else if ((q.mFlags & QueuedInputEvent.FLAG_UNHANDLED) != 0) { |
| 4477 | mKeyboard.process((KeyEvent)q.mEvent); |
| 4478 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4479 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4480 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4481 | return FORWARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4482 | } |
| 4483 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4484 | @Override |
| 4485 | protected void onDeliverToNext(QueuedInputEvent q) { |
| 4486 | if ((q.mFlags & QueuedInputEvent.FLAG_RESYNTHESIZED) == 0) { |
| 4487 | // Cancel related synthetic events if any prior stage has handled the event. |
| 4488 | if (q.mEvent instanceof MotionEvent) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4489 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4490 | final int source = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4491 | if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4492 | mTrackball.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4493 | } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4494 | mJoystick.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4495 | } else if ((source & InputDevice.SOURCE_TOUCH_NAVIGATION) |
| 4496 | == InputDevice.SOURCE_TOUCH_NAVIGATION) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4497 | mTouchNavigation.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4498 | } |
| 4499 | } |
| 4500 | } |
| 4501 | super.onDeliverToNext(q); |
| 4502 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4503 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4504 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4505 | /** |
| 4506 | * Creates dpad events from unhandled trackball movements. |
| 4507 | */ |
| 4508 | final class SyntheticTrackballHandler { |
| 4509 | private final TrackballAxis mX = new TrackballAxis(); |
| 4510 | private final TrackballAxis mY = new TrackballAxis(); |
| 4511 | private long mLastTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4512 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4513 | public void process(MotionEvent event) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4514 | // Translate the trackball event into DPAD keys and try to deliver those. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4515 | long curTime = SystemClock.uptimeMillis(); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4516 | if ((mLastTime + MAX_TRACKBALL_DELAY) < curTime) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4517 | // It has been too long since the last movement, |
| 4518 | // so restart at the beginning. |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4519 | mX.reset(0); |
| 4520 | mY.reset(0); |
| 4521 | mLastTime = curTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4522 | } |
| 4523 | |
| 4524 | final int action = event.getAction(); |
| 4525 | final int metaState = event.getMetaState(); |
| 4526 | switch (action) { |
| 4527 | case MotionEvent.ACTION_DOWN: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4528 | mX.reset(2); |
| 4529 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4530 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4531 | KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER, 0, metaState, |
| 4532 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4533 | InputDevice.SOURCE_KEYBOARD)); |
| 4534 | break; |
| 4535 | case MotionEvent.ACTION_UP: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4536 | mX.reset(2); |
| 4537 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4538 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4539 | KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER, 0, metaState, |
| 4540 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4541 | InputDevice.SOURCE_KEYBOARD)); |
| 4542 | break; |
| 4543 | } |
| 4544 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4545 | if (DEBUG_TRACKBALL) Log.v(mTag, "TB X=" + mX.position + " step=" |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4546 | + mX.step + " dir=" + mX.dir + " acc=" + mX.acceleration |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4547 | + " move=" + event.getX() |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4548 | + " / Y=" + mY.position + " step=" |
| 4549 | + mY.step + " dir=" + mY.dir + " acc=" + mY.acceleration |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4550 | + " move=" + event.getY()); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4551 | final float xOff = mX.collect(event.getX(), event.getEventTime(), "X"); |
| 4552 | final float yOff = mY.collect(event.getY(), event.getEventTime(), "Y"); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4553 | |
| 4554 | // Generate DPAD events based on the trackball movement. |
| 4555 | // We pick the axis that has moved the most as the direction of |
| 4556 | // the DPAD. When we generate DPAD events for one axis, then the |
| 4557 | // other axis is reset -- we don't want to perform DPAD jumps due |
| 4558 | // to slight movements in the trackball when making major movements |
| 4559 | // along the other axis. |
| 4560 | int keycode = 0; |
| 4561 | int movement = 0; |
| 4562 | float accel = 1; |
| 4563 | if (xOff > yOff) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4564 | movement = mX.generate(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4565 | if (movement != 0) { |
| 4566 | keycode = movement > 0 ? KeyEvent.KEYCODE_DPAD_RIGHT |
| 4567 | : KeyEvent.KEYCODE_DPAD_LEFT; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4568 | accel = mX.acceleration; |
| 4569 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4570 | } |
| 4571 | } else if (yOff > 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4572 | movement = mY.generate(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4573 | if (movement != 0) { |
| 4574 | keycode = movement > 0 ? KeyEvent.KEYCODE_DPAD_DOWN |
| 4575 | : KeyEvent.KEYCODE_DPAD_UP; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4576 | accel = mY.acceleration; |
| 4577 | mX.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4578 | } |
| 4579 | } |
| 4580 | |
| 4581 | if (keycode != 0) { |
| 4582 | if (movement < 0) movement = -movement; |
| 4583 | int accelMovement = (int)(movement * accel); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4584 | if (DEBUG_TRACKBALL) Log.v(mTag, "Move: movement=" + movement |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4585 | + " accelMovement=" + accelMovement |
| 4586 | + " accel=" + accel); |
| 4587 | if (accelMovement > movement) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4588 | if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: " |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4589 | + keycode); |
| 4590 | movement--; |
| 4591 | int repeatCount = accelMovement - movement; |
| 4592 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4593 | KeyEvent.ACTION_MULTIPLE, keycode, repeatCount, metaState, |
| 4594 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4595 | InputDevice.SOURCE_KEYBOARD)); |
| 4596 | } |
| 4597 | while (movement > 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4598 | if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: " |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4599 | + keycode); |
| 4600 | movement--; |
| 4601 | curTime = SystemClock.uptimeMillis(); |
| 4602 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4603 | KeyEvent.ACTION_DOWN, keycode, 0, metaState, |
| 4604 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4605 | InputDevice.SOURCE_KEYBOARD)); |
| 4606 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4607 | KeyEvent.ACTION_UP, keycode, 0, metaState, |
| 4608 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4609 | InputDevice.SOURCE_KEYBOARD)); |
| 4610 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4611 | mLastTime = curTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4612 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4613 | } |
| 4614 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4615 | public void cancel(MotionEvent event) { |
| 4616 | mLastTime = Integer.MIN_VALUE; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4617 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4618 | // If we reach this, we consumed a trackball event. |
| 4619 | // Because we will not translate the trackball event into a key event, |
| 4620 | // touch mode will not exit, so we exit touch mode here. |
| 4621 | if (mView != null && mAdded) { |
| 4622 | ensureTouchMode(false); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4623 | } |
| 4624 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4625 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4626 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4627 | /** |
| 4628 | * Maintains state information for a single trackball axis, generating |
| 4629 | * discrete (DPAD) movements based on raw trackball motion. |
| 4630 | */ |
| 4631 | static final class TrackballAxis { |
| 4632 | /** |
| 4633 | * The maximum amount of acceleration we will apply. |
| 4634 | */ |
| 4635 | static final float MAX_ACCELERATION = 20; |
| 4636 | |
| 4637 | /** |
| 4638 | * The maximum amount of time (in milliseconds) between events in order |
| 4639 | * for us to consider the user to be doing fast trackball movements, |
| 4640 | * and thus apply an acceleration. |
| 4641 | */ |
| 4642 | static final long FAST_MOVE_TIME = 150; |
| 4643 | |
| 4644 | /** |
| 4645 | * Scaling factor to the time (in milliseconds) between events to how |
| 4646 | * much to multiple/divide the current acceleration. When movement |
| 4647 | * is < FAST_MOVE_TIME this multiplies the acceleration; when > |
| 4648 | * FAST_MOVE_TIME it divides it. |
| 4649 | */ |
| 4650 | static final float ACCEL_MOVE_SCALING_FACTOR = (1.0f/40); |
| 4651 | |
| 4652 | static final float FIRST_MOVEMENT_THRESHOLD = 0.5f; |
| 4653 | static final float SECOND_CUMULATIVE_MOVEMENT_THRESHOLD = 2.0f; |
| 4654 | static final float SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD = 1.0f; |
| 4655 | |
| 4656 | float position; |
| 4657 | float acceleration = 1; |
| 4658 | long lastMoveTime = 0; |
| 4659 | int step; |
| 4660 | int dir; |
| 4661 | int nonAccelMovement; |
| 4662 | |
| 4663 | void reset(int _step) { |
| 4664 | position = 0; |
| 4665 | acceleration = 1; |
| 4666 | lastMoveTime = 0; |
| 4667 | step = _step; |
| 4668 | dir = 0; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 4669 | } |
| 4670 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4671 | /** |
| 4672 | * Add trackball movement into the state. If the direction of movement |
| 4673 | * has been reversed, the state is reset before adding the |
| 4674 | * movement (so that you don't have to compensate for any previously |
| 4675 | * collected movement before see the result of the movement in the |
| 4676 | * new direction). |
| 4677 | * |
| 4678 | * @return Returns the absolute value of the amount of movement |
| 4679 | * collected so far. |
| 4680 | */ |
| 4681 | float collect(float off, long time, String axis) { |
| 4682 | long normTime; |
| 4683 | if (off > 0) { |
| 4684 | normTime = (long)(off * FAST_MOVE_TIME); |
| 4685 | if (dir < 0) { |
| 4686 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " reversed to positive!"); |
| 4687 | position = 0; |
| 4688 | step = 0; |
| 4689 | acceleration = 1; |
| 4690 | lastMoveTime = 0; |
| 4691 | } |
| 4692 | dir = 1; |
| 4693 | } else if (off < 0) { |
| 4694 | normTime = (long)((-off) * FAST_MOVE_TIME); |
| 4695 | if (dir > 0) { |
| 4696 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " reversed to negative!"); |
| 4697 | position = 0; |
| 4698 | step = 0; |
| 4699 | acceleration = 1; |
| 4700 | lastMoveTime = 0; |
| 4701 | } |
| 4702 | dir = -1; |
| 4703 | } else { |
| 4704 | normTime = 0; |
| 4705 | } |
| 4706 | |
| 4707 | // The number of milliseconds between each movement that is |
| 4708 | // considered "normal" and will not result in any acceleration |
| 4709 | // or deceleration, scaled by the offset we have here. |
| 4710 | if (normTime > 0) { |
| 4711 | long delta = time - lastMoveTime; |
| 4712 | lastMoveTime = time; |
| 4713 | float acc = acceleration; |
| 4714 | if (delta < normTime) { |
| 4715 | // The user is scrolling rapidly, so increase acceleration. |
| 4716 | float scale = (normTime-delta) * ACCEL_MOVE_SCALING_FACTOR; |
| 4717 | if (scale > 1) acc *= scale; |
| 4718 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " accelerate: off=" |
| 4719 | + off + " normTime=" + normTime + " delta=" + delta |
| 4720 | + " scale=" + scale + " acc=" + acc); |
| 4721 | acceleration = acc < MAX_ACCELERATION ? acc : MAX_ACCELERATION; |
| 4722 | } else { |
| 4723 | // The user is scrolling slowly, so decrease acceleration. |
| 4724 | float scale = (delta-normTime) * ACCEL_MOVE_SCALING_FACTOR; |
| 4725 | if (scale > 1) acc /= scale; |
| 4726 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " deccelerate: off=" |
| 4727 | + off + " normTime=" + normTime + " delta=" + delta |
| 4728 | + " scale=" + scale + " acc=" + acc); |
| 4729 | acceleration = acc > 1 ? acc : 1; |
| 4730 | } |
| 4731 | } |
| 4732 | position += off; |
| 4733 | return Math.abs(position); |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 4734 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4735 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4736 | /** |
| 4737 | * Generate the number of discrete movement events appropriate for |
| 4738 | * the currently collected trackball movement. |
| 4739 | * |
| 4740 | * @return Returns the number of discrete movements, either positive |
| 4741 | * or negative, or 0 if there is not enough trackball movement yet |
| 4742 | * for a discrete movement. |
| 4743 | */ |
| 4744 | int generate() { |
| 4745 | int movement = 0; |
| 4746 | nonAccelMovement = 0; |
| 4747 | do { |
| 4748 | final int dir = position >= 0 ? 1 : -1; |
| 4749 | switch (step) { |
| 4750 | // If we are going to execute the first step, then we want |
| 4751 | // to do this as soon as possible instead of waiting for |
| 4752 | // a full movement, in order to make things look responsive. |
| 4753 | case 0: |
| 4754 | if (Math.abs(position) < FIRST_MOVEMENT_THRESHOLD) { |
| 4755 | return movement; |
| 4756 | } |
| 4757 | movement += dir; |
| 4758 | nonAccelMovement += dir; |
| 4759 | step = 1; |
| 4760 | break; |
| 4761 | // If we have generated the first movement, then we need |
| 4762 | // to wait for the second complete trackball motion before |
| 4763 | // generating the second discrete movement. |
| 4764 | case 1: |
| 4765 | if (Math.abs(position) < SECOND_CUMULATIVE_MOVEMENT_THRESHOLD) { |
| 4766 | return movement; |
| 4767 | } |
| 4768 | movement += dir; |
| 4769 | nonAccelMovement += dir; |
| 4770 | position -= SECOND_CUMULATIVE_MOVEMENT_THRESHOLD * dir; |
| 4771 | step = 2; |
| 4772 | break; |
| 4773 | // After the first two, we generate discrete movements |
| 4774 | // consistently with the trackball, applying an acceleration |
| 4775 | // if the trackball is moving quickly. This is a simple |
| 4776 | // acceleration on top of what we already compute based |
| 4777 | // on how quickly the wheel is being turned, to apply |
| 4778 | // a longer increasing acceleration to continuous movement |
| 4779 | // in one direction. |
| 4780 | default: |
| 4781 | if (Math.abs(position) < SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD) { |
| 4782 | return movement; |
| 4783 | } |
| 4784 | movement += dir; |
| 4785 | position -= dir * SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD; |
| 4786 | float acc = acceleration; |
| 4787 | acc *= 1.1f; |
| 4788 | acceleration = acc < MAX_ACCELERATION ? acc : acceleration; |
| 4789 | break; |
| 4790 | } |
| 4791 | } while (true); |
| 4792 | } |
| 4793 | } |
| 4794 | |
| 4795 | /** |
| 4796 | * Creates dpad events from unhandled joystick movements. |
| 4797 | */ |
| 4798 | final class SyntheticJoystickHandler extends Handler { |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4799 | private final static String TAG = "SyntheticJoystickHandler"; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4800 | private final static int MSG_ENQUEUE_X_AXIS_KEY_REPEAT = 1; |
| 4801 | private final static int MSG_ENQUEUE_Y_AXIS_KEY_REPEAT = 2; |
| 4802 | |
| 4803 | private int mLastXDirection; |
| 4804 | private int mLastYDirection; |
| 4805 | private int mLastXKeyCode; |
| 4806 | private int mLastYKeyCode; |
| 4807 | |
| 4808 | public SyntheticJoystickHandler() { |
| 4809 | super(true); |
| 4810 | } |
| 4811 | |
| 4812 | @Override |
| 4813 | public void handleMessage(Message msg) { |
| 4814 | switch (msg.what) { |
| 4815 | case MSG_ENQUEUE_X_AXIS_KEY_REPEAT: |
| 4816 | case MSG_ENQUEUE_Y_AXIS_KEY_REPEAT: { |
| 4817 | KeyEvent oldEvent = (KeyEvent)msg.obj; |
| 4818 | KeyEvent e = KeyEvent.changeTimeRepeat(oldEvent, |
| 4819 | SystemClock.uptimeMillis(), |
| 4820 | oldEvent.getRepeatCount() + 1); |
| 4821 | if (mAttachInfo.mHasWindowFocus) { |
| 4822 | enqueueInputEvent(e); |
| 4823 | Message m = obtainMessage(msg.what, e); |
| 4824 | m.setAsynchronous(true); |
| 4825 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatDelay()); |
| 4826 | } |
| 4827 | } break; |
| 4828 | } |
| 4829 | } |
| 4830 | |
| 4831 | public void process(MotionEvent event) { |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4832 | switch(event.getActionMasked()) { |
| 4833 | case MotionEvent.ACTION_CANCEL: |
| 4834 | cancel(event); |
| 4835 | break; |
| 4836 | case MotionEvent.ACTION_MOVE: |
| 4837 | update(event, true); |
| 4838 | break; |
| 4839 | default: |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4840 | Log.w(mTag, "Unexpected action: " + event.getActionMasked()); |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4841 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4842 | } |
| 4843 | |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4844 | private void cancel(MotionEvent event) { |
| 4845 | removeMessages(MSG_ENQUEUE_X_AXIS_KEY_REPEAT); |
| 4846 | removeMessages(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4847 | update(event, false); |
| 4848 | } |
| 4849 | |
| 4850 | private void update(MotionEvent event, boolean synthesizeNewKeys) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4851 | final long time = event.getEventTime(); |
| 4852 | final int metaState = event.getMetaState(); |
| 4853 | final int deviceId = event.getDeviceId(); |
| 4854 | final int source = event.getSource(); |
| 4855 | |
| 4856 | int xDirection = joystickAxisValueToDirection( |
| 4857 | event.getAxisValue(MotionEvent.AXIS_HAT_X)); |
| 4858 | if (xDirection == 0) { |
| 4859 | xDirection = joystickAxisValueToDirection(event.getX()); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4860 | } |
| 4861 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4862 | int yDirection = joystickAxisValueToDirection( |
| 4863 | event.getAxisValue(MotionEvent.AXIS_HAT_Y)); |
| 4864 | if (yDirection == 0) { |
| 4865 | yDirection = joystickAxisValueToDirection(event.getY()); |
| 4866 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4867 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4868 | if (xDirection != mLastXDirection) { |
| 4869 | if (mLastXKeyCode != 0) { |
| 4870 | removeMessages(MSG_ENQUEUE_X_AXIS_KEY_REPEAT); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4871 | enqueueInputEvent(new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4872 | KeyEvent.ACTION_UP, mLastXKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4873 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source)); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4874 | mLastXKeyCode = 0; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4875 | } |
| 4876 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4877 | mLastXDirection = xDirection; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4878 | |
| 4879 | if (xDirection != 0 && synthesizeNewKeys) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4880 | mLastXKeyCode = xDirection > 0 |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4881 | ? KeyEvent.KEYCODE_DPAD_RIGHT : KeyEvent.KEYCODE_DPAD_LEFT; |
| 4882 | final KeyEvent e = new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4883 | KeyEvent.ACTION_DOWN, mLastXKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4884 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source); |
| 4885 | enqueueInputEvent(e); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4886 | Message m = obtainMessage(MSG_ENQUEUE_X_AXIS_KEY_REPEAT, e); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4887 | m.setAsynchronous(true); |
Michael Wright | b961852 | 2013-04-10 15:20:56 -0700 | [diff] [blame] | 4888 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatTimeout()); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4889 | } |
| 4890 | } |
| 4891 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4892 | if (yDirection != mLastYDirection) { |
| 4893 | if (mLastYKeyCode != 0) { |
| 4894 | removeMessages(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4895 | enqueueInputEvent(new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4896 | KeyEvent.ACTION_UP, mLastYKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4897 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source)); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4898 | mLastYKeyCode = 0; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4899 | } |
| 4900 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4901 | mLastYDirection = yDirection; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4902 | |
| 4903 | if (yDirection != 0 && synthesizeNewKeys) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4904 | mLastYKeyCode = yDirection > 0 |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4905 | ? KeyEvent.KEYCODE_DPAD_DOWN : KeyEvent.KEYCODE_DPAD_UP; |
| 4906 | final KeyEvent e = new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4907 | KeyEvent.ACTION_DOWN, mLastYKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4908 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source); |
| 4909 | enqueueInputEvent(e); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4910 | Message m = obtainMessage(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT, e); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4911 | m.setAsynchronous(true); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4912 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatTimeout()); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4913 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4914 | } |
| 4915 | } |
| 4916 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4917 | private int joystickAxisValueToDirection(float value) { |
| 4918 | if (value >= 0.5f) { |
| 4919 | return 1; |
| 4920 | } else if (value <= -0.5f) { |
| 4921 | return -1; |
| 4922 | } else { |
| 4923 | return 0; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4924 | } |
| 4925 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4926 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4927 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4928 | /** |
| 4929 | * Creates dpad events from unhandled touch navigation movements. |
| 4930 | */ |
| 4931 | final class SyntheticTouchNavigationHandler extends Handler { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4932 | private static final String LOCAL_TAG = "SyntheticTouchNavigationHandler"; |
| 4933 | private static final boolean LOCAL_DEBUG = false; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4934 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4935 | // Assumed nominal width and height in millimeters of a touch navigation pad, |
| 4936 | // if no resolution information is available from the input system. |
| 4937 | private static final float DEFAULT_WIDTH_MILLIMETERS = 48; |
| 4938 | private static final float DEFAULT_HEIGHT_MILLIMETERS = 48; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4939 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4940 | /* TODO: These constants should eventually be moved to ViewConfiguration. */ |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4941 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4942 | // The nominal distance traveled to move by one unit. |
| 4943 | private static final int TICK_DISTANCE_MILLIMETERS = 12; |
| 4944 | |
| 4945 | // Minimum and maximum fling velocity in ticks per second. |
| 4946 | // The minimum velocity should be set such that we perform enough ticks per |
| 4947 | // second that the fling appears to be fluid. For example, if we set the minimum |
| 4948 | // to 2 ticks per second, then there may be up to half a second delay between the next |
| 4949 | // to last and last ticks which is noticeably discrete and jerky. This value should |
| 4950 | // probably not be set to anything less than about 4. |
| 4951 | // If fling accuracy is a problem then consider tuning the tick distance instead. |
| 4952 | private static final float MIN_FLING_VELOCITY_TICKS_PER_SECOND = 6f; |
| 4953 | private static final float MAX_FLING_VELOCITY_TICKS_PER_SECOND = 20f; |
| 4954 | |
| 4955 | // Fling velocity decay factor applied after each new key is emitted. |
| 4956 | // This parameter controls the deceleration and overall duration of the fling. |
| 4957 | // The fling stops automatically when its velocity drops below the minimum |
| 4958 | // fling velocity defined above. |
| 4959 | private static final float FLING_TICK_DECAY = 0.8f; |
| 4960 | |
| 4961 | /* The input device that we are tracking. */ |
| 4962 | |
| 4963 | private int mCurrentDeviceId = -1; |
| 4964 | private int mCurrentSource; |
| 4965 | private boolean mCurrentDeviceSupported; |
| 4966 | |
| 4967 | /* Configuration for the current input device. */ |
| 4968 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4969 | // The scaled tick distance. A movement of this amount should generally translate |
| 4970 | // into a single dpad event in a given direction. |
| 4971 | private float mConfigTickDistance; |
| 4972 | |
| 4973 | // The minimum and maximum scaled fling velocity. |
| 4974 | private float mConfigMinFlingVelocity; |
| 4975 | private float mConfigMaxFlingVelocity; |
| 4976 | |
| 4977 | /* Tracking state. */ |
| 4978 | |
| 4979 | // The velocity tracker for detecting flings. |
| 4980 | private VelocityTracker mVelocityTracker; |
| 4981 | |
| 4982 | // The active pointer id, or -1 if none. |
| 4983 | private int mActivePointerId = -1; |
| 4984 | |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 4985 | // Location where tracking started. |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4986 | private float mStartX; |
| 4987 | private float mStartY; |
| 4988 | |
| 4989 | // Most recently observed position. |
| 4990 | private float mLastX; |
| 4991 | private float mLastY; |
| 4992 | |
| 4993 | // Accumulated movement delta since the last direction key was sent. |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4994 | private float mAccumulatedX; |
| 4995 | private float mAccumulatedY; |
| 4996 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4997 | // Set to true if any movement was delivered to the app. |
| 4998 | // Implies that tap slop was exceeded. |
| 4999 | private boolean mConsumedMovement; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5000 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5001 | // The most recently sent key down event. |
| 5002 | // The keycode remains set until the direction changes or a fling ends |
| 5003 | // so that repeated key events may be generated as required. |
| 5004 | private long mPendingKeyDownTime; |
| 5005 | private int mPendingKeyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 5006 | private int mPendingKeyRepeatCount; |
| 5007 | private int mPendingKeyMetaState; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5008 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5009 | // The current fling velocity while a fling is in progress. |
| 5010 | private boolean mFlinging; |
| 5011 | private float mFlingVelocity; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5012 | |
| 5013 | public SyntheticTouchNavigationHandler() { |
| 5014 | super(true); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | public void process(MotionEvent event) { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5018 | // Update the current device information. |
| 5019 | final long time = event.getEventTime(); |
| 5020 | final int deviceId = event.getDeviceId(); |
| 5021 | final int source = event.getSource(); |
| 5022 | if (mCurrentDeviceId != deviceId || mCurrentSource != source) { |
| 5023 | finishKeys(time); |
| 5024 | finishTracking(time); |
| 5025 | mCurrentDeviceId = deviceId; |
| 5026 | mCurrentSource = source; |
| 5027 | mCurrentDeviceSupported = false; |
| 5028 | InputDevice device = event.getDevice(); |
| 5029 | if (device != null) { |
| 5030 | // In order to support an input device, we must know certain |
| 5031 | // characteristics about it, such as its size and resolution. |
| 5032 | InputDevice.MotionRange xRange = device.getMotionRange(MotionEvent.AXIS_X); |
| 5033 | InputDevice.MotionRange yRange = device.getMotionRange(MotionEvent.AXIS_Y); |
| 5034 | if (xRange != null && yRange != null) { |
| 5035 | mCurrentDeviceSupported = true; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5036 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5037 | // Infer the resolution if it not actually known. |
| 5038 | float xRes = xRange.getResolution(); |
| 5039 | if (xRes <= 0) { |
| 5040 | xRes = xRange.getRange() / DEFAULT_WIDTH_MILLIMETERS; |
| 5041 | } |
| 5042 | float yRes = yRange.getResolution(); |
| 5043 | if (yRes <= 0) { |
| 5044 | yRes = yRange.getRange() / DEFAULT_HEIGHT_MILLIMETERS; |
| 5045 | } |
| 5046 | float nominalRes = (xRes + yRes) * 0.5f; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5047 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5048 | // Precompute all of the configuration thresholds we will need. |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5049 | mConfigTickDistance = TICK_DISTANCE_MILLIMETERS * nominalRes; |
| 5050 | mConfigMinFlingVelocity = |
| 5051 | MIN_FLING_VELOCITY_TICKS_PER_SECOND * mConfigTickDistance; |
| 5052 | mConfigMaxFlingVelocity = |
| 5053 | MAX_FLING_VELOCITY_TICKS_PER_SECOND * mConfigTickDistance; |
| 5054 | |
| 5055 | if (LOCAL_DEBUG) { |
| 5056 | Log.d(LOCAL_TAG, "Configured device " + mCurrentDeviceId |
| 5057 | + " (" + Integer.toHexString(mCurrentSource) + "): " |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5058 | + ", mConfigTickDistance=" + mConfigTickDistance |
| 5059 | + ", mConfigMinFlingVelocity=" + mConfigMinFlingVelocity |
| 5060 | + ", mConfigMaxFlingVelocity=" + mConfigMaxFlingVelocity); |
| 5061 | } |
| 5062 | } |
| 5063 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5064 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5065 | if (!mCurrentDeviceSupported) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5066 | return; |
| 5067 | } |
| 5068 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5069 | // Handle the event. |
| 5070 | final int action = event.getActionMasked(); |
| 5071 | switch (action) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5072 | case MotionEvent.ACTION_DOWN: { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5073 | boolean caughtFling = mFlinging; |
| 5074 | finishKeys(time); |
| 5075 | finishTracking(time); |
| 5076 | mActivePointerId = event.getPointerId(0); |
| 5077 | mVelocityTracker = VelocityTracker.obtain(); |
| 5078 | mVelocityTracker.addMovement(event); |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5079 | mStartX = event.getX(); |
| 5080 | mStartY = event.getY(); |
| 5081 | mLastX = mStartX; |
| 5082 | mLastY = mStartY; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5083 | mAccumulatedX = 0; |
| 5084 | mAccumulatedY = 0; |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5085 | |
| 5086 | // If we caught a fling, then pretend that the tap slop has already |
| 5087 | // been exceeded to suppress taps whose only purpose is to stop the fling. |
| 5088 | mConsumedMovement = caughtFling; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5089 | break; |
| 5090 | } |
| 5091 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5092 | case MotionEvent.ACTION_MOVE: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5093 | case MotionEvent.ACTION_UP: { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5094 | if (mActivePointerId < 0) { |
| 5095 | break; |
| 5096 | } |
| 5097 | final int index = event.findPointerIndex(mActivePointerId); |
| 5098 | if (index < 0) { |
| 5099 | finishKeys(time); |
| 5100 | finishTracking(time); |
| 5101 | break; |
| 5102 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5103 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5104 | mVelocityTracker.addMovement(event); |
| 5105 | final float x = event.getX(index); |
| 5106 | final float y = event.getY(index); |
| 5107 | mAccumulatedX += x - mLastX; |
| 5108 | mAccumulatedY += y - mLastY; |
| 5109 | mLastX = x; |
| 5110 | mLastY = y; |
| 5111 | |
| 5112 | // Consume any accumulated movement so far. |
| 5113 | final int metaState = event.getMetaState(); |
| 5114 | consumeAccumulatedMovement(time, metaState); |
| 5115 | |
| 5116 | // Detect taps and flings. |
| 5117 | if (action == MotionEvent.ACTION_UP) { |
Michael Wright | 88d7f79 | 2013-08-27 15:45:42 -0700 | [diff] [blame] | 5118 | if (mConsumedMovement && mPendingKeyCode != KeyEvent.KEYCODE_UNKNOWN) { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5119 | // It might be a fling. |
| 5120 | mVelocityTracker.computeCurrentVelocity(1000, mConfigMaxFlingVelocity); |
| 5121 | final float vx = mVelocityTracker.getXVelocity(mActivePointerId); |
| 5122 | final float vy = mVelocityTracker.getYVelocity(mActivePointerId); |
| 5123 | if (!startFling(time, vx, vy)) { |
| 5124 | finishKeys(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5125 | } |
| 5126 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5127 | finishTracking(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5128 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5129 | break; |
| 5130 | } |
| 5131 | |
| 5132 | case MotionEvent.ACTION_CANCEL: { |
| 5133 | finishKeys(time); |
| 5134 | finishTracking(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5135 | break; |
| 5136 | } |
| 5137 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5138 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5139 | |
| 5140 | public void cancel(MotionEvent event) { |
| 5141 | if (mCurrentDeviceId == event.getDeviceId() |
| 5142 | && mCurrentSource == event.getSource()) { |
| 5143 | final long time = event.getEventTime(); |
| 5144 | finishKeys(time); |
| 5145 | finishTracking(time); |
| 5146 | } |
| 5147 | } |
| 5148 | |
| 5149 | private void finishKeys(long time) { |
| 5150 | cancelFling(); |
| 5151 | sendKeyUp(time); |
| 5152 | } |
| 5153 | |
| 5154 | private void finishTracking(long time) { |
| 5155 | if (mActivePointerId >= 0) { |
| 5156 | mActivePointerId = -1; |
| 5157 | mVelocityTracker.recycle(); |
| 5158 | mVelocityTracker = null; |
| 5159 | } |
| 5160 | } |
| 5161 | |
| 5162 | private void consumeAccumulatedMovement(long time, int metaState) { |
| 5163 | final float absX = Math.abs(mAccumulatedX); |
| 5164 | final float absY = Math.abs(mAccumulatedY); |
| 5165 | if (absX >= absY) { |
| 5166 | if (absX >= mConfigTickDistance) { |
| 5167 | mAccumulatedX = consumeAccumulatedMovement(time, metaState, mAccumulatedX, |
| 5168 | KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_RIGHT); |
| 5169 | mAccumulatedY = 0; |
| 5170 | mConsumedMovement = true; |
| 5171 | } |
| 5172 | } else { |
| 5173 | if (absY >= mConfigTickDistance) { |
| 5174 | mAccumulatedY = consumeAccumulatedMovement(time, metaState, mAccumulatedY, |
| 5175 | KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN); |
| 5176 | mAccumulatedX = 0; |
| 5177 | mConsumedMovement = true; |
| 5178 | } |
| 5179 | } |
| 5180 | } |
| 5181 | |
| 5182 | private float consumeAccumulatedMovement(long time, int metaState, |
| 5183 | float accumulator, int negativeKeyCode, int positiveKeyCode) { |
| 5184 | while (accumulator <= -mConfigTickDistance) { |
| 5185 | sendKeyDownOrRepeat(time, negativeKeyCode, metaState); |
| 5186 | accumulator += mConfigTickDistance; |
| 5187 | } |
| 5188 | while (accumulator >= mConfigTickDistance) { |
| 5189 | sendKeyDownOrRepeat(time, positiveKeyCode, metaState); |
| 5190 | accumulator -= mConfigTickDistance; |
| 5191 | } |
| 5192 | return accumulator; |
| 5193 | } |
| 5194 | |
| 5195 | private void sendKeyDownOrRepeat(long time, int keyCode, int metaState) { |
| 5196 | if (mPendingKeyCode != keyCode) { |
| 5197 | sendKeyUp(time); |
| 5198 | mPendingKeyDownTime = time; |
| 5199 | mPendingKeyCode = keyCode; |
| 5200 | mPendingKeyRepeatCount = 0; |
| 5201 | } else { |
| 5202 | mPendingKeyRepeatCount += 1; |
| 5203 | } |
| 5204 | mPendingKeyMetaState = metaState; |
| 5205 | |
| 5206 | // Note: Normally we would pass FLAG_LONG_PRESS when the repeat count is 1 |
| 5207 | // but it doesn't quite make sense when simulating the events in this way. |
| 5208 | if (LOCAL_DEBUG) { |
| 5209 | Log.d(LOCAL_TAG, "Sending key down: keyCode=" + mPendingKeyCode |
| 5210 | + ", repeatCount=" + mPendingKeyRepeatCount |
| 5211 | + ", metaState=" + Integer.toHexString(mPendingKeyMetaState)); |
| 5212 | } |
| 5213 | enqueueInputEvent(new KeyEvent(mPendingKeyDownTime, time, |
| 5214 | KeyEvent.ACTION_DOWN, mPendingKeyCode, mPendingKeyRepeatCount, |
| 5215 | mPendingKeyMetaState, mCurrentDeviceId, |
| 5216 | KeyEvent.FLAG_FALLBACK, mCurrentSource)); |
| 5217 | } |
| 5218 | |
| 5219 | private void sendKeyUp(long time) { |
| 5220 | if (mPendingKeyCode != KeyEvent.KEYCODE_UNKNOWN) { |
| 5221 | if (LOCAL_DEBUG) { |
| 5222 | Log.d(LOCAL_TAG, "Sending key up: keyCode=" + mPendingKeyCode |
| 5223 | + ", metaState=" + Integer.toHexString(mPendingKeyMetaState)); |
| 5224 | } |
| 5225 | enqueueInputEvent(new KeyEvent(mPendingKeyDownTime, time, |
| 5226 | KeyEvent.ACTION_UP, mPendingKeyCode, 0, mPendingKeyMetaState, |
| 5227 | mCurrentDeviceId, 0, KeyEvent.FLAG_FALLBACK, |
| 5228 | mCurrentSource)); |
| 5229 | mPendingKeyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 5230 | } |
| 5231 | } |
| 5232 | |
| 5233 | private boolean startFling(long time, float vx, float vy) { |
| 5234 | if (LOCAL_DEBUG) { |
| 5235 | Log.d(LOCAL_TAG, "Considering fling: vx=" + vx + ", vy=" + vy |
| 5236 | + ", min=" + mConfigMinFlingVelocity); |
| 5237 | } |
| 5238 | |
| 5239 | // Flings must be oriented in the same direction as the preceding movements. |
| 5240 | switch (mPendingKeyCode) { |
| 5241 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 5242 | if (-vx >= mConfigMinFlingVelocity |
| 5243 | && Math.abs(vy) < mConfigMinFlingVelocity) { |
| 5244 | mFlingVelocity = -vx; |
| 5245 | break; |
| 5246 | } |
| 5247 | return false; |
| 5248 | |
| 5249 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 5250 | if (vx >= mConfigMinFlingVelocity |
| 5251 | && Math.abs(vy) < mConfigMinFlingVelocity) { |
| 5252 | mFlingVelocity = vx; |
| 5253 | break; |
| 5254 | } |
| 5255 | return false; |
| 5256 | |
| 5257 | case KeyEvent.KEYCODE_DPAD_UP: |
| 5258 | if (-vy >= mConfigMinFlingVelocity |
| 5259 | && Math.abs(vx) < mConfigMinFlingVelocity) { |
| 5260 | mFlingVelocity = -vy; |
| 5261 | break; |
| 5262 | } |
| 5263 | return false; |
| 5264 | |
| 5265 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 5266 | if (vy >= mConfigMinFlingVelocity |
| 5267 | && Math.abs(vx) < mConfigMinFlingVelocity) { |
| 5268 | mFlingVelocity = vy; |
| 5269 | break; |
| 5270 | } |
| 5271 | return false; |
| 5272 | } |
| 5273 | |
| 5274 | // Post the first fling event. |
| 5275 | mFlinging = postFling(time); |
| 5276 | return mFlinging; |
| 5277 | } |
| 5278 | |
| 5279 | private boolean postFling(long time) { |
| 5280 | // The idea here is to estimate the time when the pointer would have |
| 5281 | // traveled one tick distance unit given the current fling velocity. |
| 5282 | // This effect creates continuity of motion. |
| 5283 | if (mFlingVelocity >= mConfigMinFlingVelocity) { |
| 5284 | long delay = (long)(mConfigTickDistance / mFlingVelocity * 1000); |
| 5285 | postAtTime(mFlingRunnable, time + delay); |
| 5286 | if (LOCAL_DEBUG) { |
| 5287 | Log.d(LOCAL_TAG, "Posted fling: velocity=" |
| 5288 | + mFlingVelocity + ", delay=" + delay |
| 5289 | + ", keyCode=" + mPendingKeyCode); |
| 5290 | } |
| 5291 | return true; |
| 5292 | } |
| 5293 | return false; |
| 5294 | } |
| 5295 | |
| 5296 | private void cancelFling() { |
| 5297 | if (mFlinging) { |
| 5298 | removeCallbacks(mFlingRunnable); |
| 5299 | mFlinging = false; |
| 5300 | } |
| 5301 | } |
| 5302 | |
| 5303 | private final Runnable mFlingRunnable = new Runnable() { |
| 5304 | @Override |
| 5305 | public void run() { |
| 5306 | final long time = SystemClock.uptimeMillis(); |
| 5307 | sendKeyDownOrRepeat(time, mPendingKeyCode, mPendingKeyMetaState); |
| 5308 | mFlingVelocity *= FLING_TICK_DECAY; |
| 5309 | if (!postFling(time)) { |
| 5310 | mFlinging = false; |
| 5311 | finishKeys(time); |
| 5312 | } |
| 5313 | } |
| 5314 | }; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5315 | } |
| 5316 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5317 | final class SyntheticKeyboardHandler { |
| 5318 | public void process(KeyEvent event) { |
| 5319 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) != 0) { |
| 5320 | return; |
| 5321 | } |
| 5322 | |
| 5323 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 5324 | final int keyCode = event.getKeyCode(); |
| 5325 | final int metaState = event.getMetaState(); |
| 5326 | |
| 5327 | // Check for fallback actions specified by the key character map. |
| 5328 | KeyCharacterMap.FallbackAction fallbackAction = |
| 5329 | kcm.getFallbackAction(keyCode, metaState); |
| 5330 | if (fallbackAction != null) { |
| 5331 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 5332 | KeyEvent fallbackEvent = KeyEvent.obtain( |
| 5333 | event.getDownTime(), event.getEventTime(), |
| 5334 | event.getAction(), fallbackAction.keyCode, |
| 5335 | event.getRepeatCount(), fallbackAction.metaState, |
| 5336 | event.getDeviceId(), event.getScanCode(), |
| 5337 | flags, event.getSource(), null); |
| 5338 | fallbackAction.recycle(); |
| 5339 | enqueueInputEvent(fallbackEvent); |
| 5340 | } |
| 5341 | } |
| 5342 | } |
| 5343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5344 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5345 | * Returns true if the key is used for keyboard navigation. |
| 5346 | * @param keyEvent The key event. |
| 5347 | * @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] | 5348 | */ |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5349 | private static boolean isNavigationKey(KeyEvent keyEvent) { |
| 5350 | switch (keyEvent.getKeyCode()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5351 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 5352 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 5353 | case KeyEvent.KEYCODE_DPAD_UP: |
| 5354 | case KeyEvent.KEYCODE_DPAD_DOWN: |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5355 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 5356 | case KeyEvent.KEYCODE_PAGE_UP: |
| 5357 | case KeyEvent.KEYCODE_PAGE_DOWN: |
| 5358 | case KeyEvent.KEYCODE_MOVE_HOME: |
| 5359 | case KeyEvent.KEYCODE_MOVE_END: |
| 5360 | case KeyEvent.KEYCODE_TAB: |
| 5361 | case KeyEvent.KEYCODE_SPACE: |
| 5362 | case KeyEvent.KEYCODE_ENTER: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5363 | return true; |
| 5364 | } |
| 5365 | return false; |
| 5366 | } |
| 5367 | |
| 5368 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5369 | * Returns true if the key is used for typing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5370 | * @param keyEvent The key event. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5371 | * @return True if the key is used for typing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5372 | */ |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5373 | private static boolean isTypingKey(KeyEvent keyEvent) { |
| 5374 | return keyEvent.getUnicodeChar() > 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5375 | } |
| 5376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5377 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5378 | * 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] | 5379 | * @param event The key event. |
| 5380 | * @return Whether this key event should be consumed (meaning the act of |
| 5381 | * leaving touch mode alone is considered the event). |
| 5382 | */ |
| 5383 | private boolean checkForLeavingTouchModeAndConsume(KeyEvent event) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5384 | // Only relevant in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5385 | if (!mAttachInfo.mInTouchMode) { |
| 5386 | return false; |
| 5387 | } |
| 5388 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5389 | // Only consider leaving touch mode on DOWN or MULTIPLE actions, never on UP. |
| 5390 | final int action = event.getAction(); |
| 5391 | if (action != KeyEvent.ACTION_DOWN && action != KeyEvent.ACTION_MULTIPLE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5392 | return false; |
| 5393 | } |
| 5394 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5395 | // Don't leave touch mode if the IME told us not to. |
| 5396 | if ((event.getFlags() & KeyEvent.FLAG_KEEP_TOUCH_MODE) != 0) { |
| 5397 | return false; |
| 5398 | } |
| 5399 | |
| 5400 | // If the key can be used for keyboard navigation then leave touch mode |
| 5401 | // and select a focused view if needed (in ensureTouchMode). |
| 5402 | // When a new focused view is selected, we consume the navigation key because |
| 5403 | // navigation doesn't make much sense unless a view already has focus so |
| 5404 | // the key's purpose is to set focus. |
| 5405 | if (isNavigationKey(event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5406 | return ensureTouchMode(false); |
| 5407 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5408 | |
| 5409 | // If the key can be used for typing then leave touch mode |
| 5410 | // and select a focused view if needed (in ensureTouchMode). |
| 5411 | // Always allow the view to process the typing key. |
| 5412 | if (isTypingKey(event)) { |
| 5413 | ensureTouchMode(false); |
| 5414 | return false; |
| 5415 | } |
| 5416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5417 | return false; |
| 5418 | } |
| 5419 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5420 | /* drag/drop */ |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5421 | void setLocalDragState(Object obj) { |
| 5422 | mLocalDragState = obj; |
| 5423 | } |
| 5424 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5425 | private void handleDragEvent(DragEvent event) { |
| 5426 | // From the root, only drag start/end/location are dispatched. entered/exited |
| 5427 | // are determined and dispatched by the viewgroup hierarchy, who then report |
| 5428 | // that back here for ultimate reporting back to the framework. |
| 5429 | if (mView != null && mAdded) { |
| 5430 | final int what = event.mAction; |
| 5431 | |
| 5432 | if (what == DragEvent.ACTION_DRAG_EXITED) { |
| 5433 | // A direct EXITED event means that the window manager knows we've just crossed |
| 5434 | // a window boundary, so the current drag target within this one must have |
| 5435 | // just been exited. Send it the usual notifications and then we're done |
| 5436 | // for now. |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 5437 | mView.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5438 | } else { |
| 5439 | // Cache the drag description when the operation starts, then fill it in |
| 5440 | // on subsequent calls as a convenience |
| 5441 | if (what == DragEvent.ACTION_DRAG_STARTED) { |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 5442 | mCurrentDragView = null; // Start the current-recipient tracking |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5443 | mDragDescription = event.mClipDescription; |
| 5444 | } else { |
| 5445 | event.mClipDescription = mDragDescription; |
| 5446 | } |
| 5447 | |
| 5448 | // For events with a [screen] location, translate into window coordinates |
| 5449 | if ((what == DragEvent.ACTION_DRAG_LOCATION) || (what == DragEvent.ACTION_DROP)) { |
| 5450 | mDragPoint.set(event.mX, event.mY); |
| 5451 | if (mTranslator != null) { |
| 5452 | mTranslator.translatePointInScreenToAppWindow(mDragPoint); |
| 5453 | } |
| 5454 | |
| 5455 | if (mCurScrollY != 0) { |
| 5456 | mDragPoint.offset(0, mCurScrollY); |
| 5457 | } |
| 5458 | |
| 5459 | event.mX = mDragPoint.x; |
| 5460 | event.mY = mDragPoint.y; |
| 5461 | } |
| 5462 | |
| 5463 | // Remember who the current drag target is pre-dispatch |
| 5464 | final View prevDragView = mCurrentDragView; |
| 5465 | |
| 5466 | // Now dispatch the drag/drop event |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5467 | boolean result = mView.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5468 | |
| 5469 | // If we changed apparent drag target, tell the OS about it |
| 5470 | if (prevDragView != mCurrentDragView) { |
| 5471 | try { |
| 5472 | if (prevDragView != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5473 | mWindowSession.dragRecipientExited(mWindow); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5474 | } |
| 5475 | if (mCurrentDragView != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5476 | mWindowSession.dragRecipientEntered(mWindow); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5477 | } |
| 5478 | } catch (RemoteException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5479 | Slog.e(mTag, "Unable to note drag target change"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5480 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5481 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5482 | |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5483 | // Report the drop result when we're done |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5484 | if (what == DragEvent.ACTION_DROP) { |
Christopher Tate | 1fc014f | 2011-01-19 12:56:26 -0800 | [diff] [blame] | 5485 | mDragDescription = null; |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5486 | try { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5487 | Log.i(mTag, "Reporting drop result: " + result); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5488 | mWindowSession.reportDropResult(mWindow, result); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5489 | } catch (RemoteException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5490 | Log.e(mTag, "Unable to report drop result"); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5491 | } |
| 5492 | } |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5493 | |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 5494 | // When the drag operation ends, reset drag-related state |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5495 | if (what == DragEvent.ACTION_DRAG_ENDED) { |
| 5496 | setLocalDragState(null); |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 5497 | mAttachInfo.mDragToken = null; |
Vladislav Kaznacheev | 4f63974 | 2015-11-18 13:21:35 -0800 | [diff] [blame] | 5498 | if (mAttachInfo.mDragSurface != null) { |
| 5499 | mAttachInfo.mDragSurface.release(); |
| 5500 | mAttachInfo.mDragSurface = null; |
| 5501 | } |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5502 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5503 | } |
| 5504 | } |
| 5505 | event.recycle(); |
| 5506 | } |
| 5507 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5508 | public void handleDispatchSystemUiVisibilityChanged(SystemUiVisibilityInfo args) { |
| 5509 | if (mSeq != args.seq) { |
| 5510 | // The sequence has changed, so we need to update our value and make |
| 5511 | // sure to do a traversal afterward so the window manager is given our |
| 5512 | // most recent data. |
| 5513 | mSeq = args.seq; |
| 5514 | mAttachInfo.mForceReportNewAttributes = true; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5515 | scheduleTraversals(); |
Joe Onorato | 14782f7 | 2011-01-25 19:53:17 -0800 | [diff] [blame] | 5516 | } |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5517 | if (mView == null) return; |
| 5518 | if (args.localChanges != 0) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5519 | mView.updateLocalSystemUiVisibility(args.localValue, args.localChanges); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5520 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 5521 | |
| 5522 | int visibility = args.globalVisibility&View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 5523 | if (visibility != mAttachInfo.mGlobalSystemUiVisibility) { |
| 5524 | mAttachInfo.mGlobalSystemUiVisibility = visibility; |
| 5525 | mView.dispatchSystemUiVisibilityChanged(visibility); |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5526 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5527 | } |
| 5528 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 5529 | public void handleDispatchWindowShown() { |
| 5530 | mAttachInfo.mTreeObserver.dispatchOnWindowShown(); |
| 5531 | } |
| 5532 | |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 5533 | public void handleRequestKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 5534 | Bundle data = new Bundle(); |
| 5535 | ArrayList<KeyboardShortcutGroup> list = new ArrayList<>(); |
| 5536 | if (mView != null) { |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 5537 | mView.requestKeyboardShortcuts(list, deviceId); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 5538 | } |
| 5539 | data.putParcelableArrayList(WindowManager.PARCEL_KEY_SHORTCUTS_ARRAY, list); |
| 5540 | try { |
| 5541 | receiver.send(0, data); |
| 5542 | } catch (RemoteException e) { |
| 5543 | } |
| 5544 | } |
| 5545 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5546 | public void getLastTouchPoint(Point outLocation) { |
| 5547 | outLocation.x = (int) mLastTouchPoint.x; |
| 5548 | outLocation.y = (int) mLastTouchPoint.y; |
| 5549 | } |
| 5550 | |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 5551 | public int getLastTouchSource() { |
| 5552 | return mLastTouchSource; |
| 5553 | } |
| 5554 | |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 5555 | public void setDragFocus(View newDragTarget) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5556 | if (mCurrentDragView != newDragTarget) { |
Chris Tate | 048691c | 2010-10-12 17:39:18 -0700 | [diff] [blame] | 5557 | mCurrentDragView = newDragTarget; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5558 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5559 | } |
| 5560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5561 | private AudioManager getAudioManager() { |
| 5562 | if (mView == null) { |
| 5563 | throw new IllegalStateException("getAudioManager called when there is no mView"); |
| 5564 | } |
| 5565 | if (mAudioManager == null) { |
| 5566 | mAudioManager = (AudioManager) mView.getContext().getSystemService(Context.AUDIO_SERVICE); |
| 5567 | } |
| 5568 | return mAudioManager; |
| 5569 | } |
| 5570 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5571 | public AccessibilityInteractionController getAccessibilityInteractionController() { |
| 5572 | if (mView == null) { |
| 5573 | throw new IllegalStateException("getAccessibilityInteractionController" |
| 5574 | + " called when there is no mView"); |
| 5575 | } |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 5576 | if (mAccessibilityInteractionController == null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5577 | mAccessibilityInteractionController = new AccessibilityInteractionController(this); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5578 | } |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 5579 | return mAccessibilityInteractionController; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5580 | } |
| 5581 | |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 5582 | private int relayoutWindow(WindowManager.LayoutParams params, int viewVisibility, |
| 5583 | boolean insetsPending) throws RemoteException { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5584 | |
| 5585 | float appScale = mAttachInfo.mApplicationScale; |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5586 | boolean restore = false; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5587 | if (params != null && mTranslator != null) { |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 5588 | restore = true; |
| 5589 | params.backup(); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5590 | mTranslator.translateWindowLayout(params); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5591 | } |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5592 | if (params != null) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5593 | if (DBG) Log.d(mTag, "WindowLayout in layoutWindow:" + params); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5594 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 5595 | mPendingConfiguration.seq = 0; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5596 | //Log.d(mTag, ">>>>>> CALLING relayout"); |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 5597 | if (params != null && mOrigWindowType != params.type) { |
| 5598 | // For compatibility with old apps, don't crash here. |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 5599 | if (mTargetSdkVersion < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5600 | Slog.w(mTag, "Window type can not be changed after " |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 5601 | + "the window is added; ignoring change of " + mView); |
| 5602 | params.type = mOrigWindowType; |
| 5603 | } |
| 5604 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5605 | int relayoutResult = mWindowSession.relayout( |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5606 | mWindow, mSeq, params, |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 5607 | (int) (mView.getMeasuredWidth() * appScale + 0.5f), |
| 5608 | (int) (mView.getMeasuredHeight() * appScale + 0.5f), |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5609 | viewVisibility, insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5610 | mWinFrame, mPendingOverscanInsets, mPendingContentInsets, mPendingVisibleInsets, |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 5611 | mPendingStableInsets, mPendingOutsets, mPendingBackDropFrame, mPendingConfiguration, |
| 5612 | mSurface); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 5613 | |
| 5614 | mPendingAlwaysConsumeNavBar = |
| 5615 | (relayoutResult & WindowManagerGlobal.RELAYOUT_RES_CONSUME_ALWAYS_NAV_BAR) != 0; |
| 5616 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5617 | //Log.d(mTag, "<<<<<< BACK FROM relayout"); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5618 | if (restore) { |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 5619 | params.restore(); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5620 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5621 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5622 | if (mTranslator != null) { |
| 5623 | mTranslator.translateRectInScreenToAppWinFrame(mWinFrame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5624 | mTranslator.translateRectInScreenToAppWindow(mPendingOverscanInsets); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5625 | mTranslator.translateRectInScreenToAppWindow(mPendingContentInsets); |
| 5626 | mTranslator.translateRectInScreenToAppWindow(mPendingVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 5627 | mTranslator.translateRectInScreenToAppWindow(mPendingStableInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5628 | } |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 5629 | return relayoutResult; |
| 5630 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5631 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5632 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5633 | * {@inheritDoc} |
| 5634 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5635 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5636 | public void playSoundEffect(int effectId) { |
| 5637 | checkThread(); |
| 5638 | |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 5639 | try { |
| 5640 | final AudioManager audioManager = getAudioManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5641 | |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 5642 | switch (effectId) { |
| 5643 | case SoundEffectConstants.CLICK: |
| 5644 | audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK); |
| 5645 | return; |
| 5646 | case SoundEffectConstants.NAVIGATION_DOWN: |
| 5647 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_DOWN); |
| 5648 | return; |
| 5649 | case SoundEffectConstants.NAVIGATION_LEFT: |
| 5650 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_LEFT); |
| 5651 | return; |
| 5652 | case SoundEffectConstants.NAVIGATION_RIGHT: |
| 5653 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_RIGHT); |
| 5654 | return; |
| 5655 | case SoundEffectConstants.NAVIGATION_UP: |
| 5656 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_UP); |
| 5657 | return; |
| 5658 | default: |
| 5659 | throw new IllegalArgumentException("unknown effect id " + effectId + |
| 5660 | " not defined in " + SoundEffectConstants.class.getCanonicalName()); |
| 5661 | } |
| 5662 | } catch (IllegalStateException e) { |
| 5663 | // Exception thrown by getAudioManager() when mView is null |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5664 | 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] | 5665 | e.printStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5666 | } |
| 5667 | } |
| 5668 | |
| 5669 | /** |
| 5670 | * {@inheritDoc} |
| 5671 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5672 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5673 | public boolean performHapticFeedback(int effectId, boolean always) { |
| 5674 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5675 | return mWindowSession.performHapticFeedback(mWindow, effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5676 | } catch (RemoteException e) { |
| 5677 | return false; |
| 5678 | } |
| 5679 | } |
| 5680 | |
| 5681 | /** |
| 5682 | * {@inheritDoc} |
| 5683 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5684 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5685 | public View focusSearch(View focused, int direction) { |
| 5686 | checkThread(); |
| 5687 | if (!(mView instanceof ViewGroup)) { |
| 5688 | return null; |
| 5689 | } |
| 5690 | return FocusFinder.getInstance().findNextFocus((ViewGroup) mView, focused, direction); |
| 5691 | } |
| 5692 | |
| 5693 | public void debug() { |
| 5694 | mView.debug(); |
| 5695 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5696 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5697 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 5698 | String innerPrefix = prefix + " "; |
| 5699 | writer.print(prefix); writer.println("ViewRoot:"); |
| 5700 | writer.print(innerPrefix); writer.print("mAdded="); writer.print(mAdded); |
| 5701 | writer.print(" mRemoved="); writer.println(mRemoved); |
| 5702 | writer.print(innerPrefix); writer.print("mConsumeBatchedInputScheduled="); |
| 5703 | writer.println(mConsumeBatchedInputScheduled); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 5704 | writer.print(innerPrefix); writer.print("mConsumeBatchedInputImmediatelyScheduled="); |
| 5705 | writer.println(mConsumeBatchedInputImmediatelyScheduled); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5706 | writer.print(innerPrefix); writer.print("mPendingInputEventCount="); |
| 5707 | writer.println(mPendingInputEventCount); |
| 5708 | writer.print(innerPrefix); writer.print("mProcessInputEventsScheduled="); |
| 5709 | writer.println(mProcessInputEventsScheduled); |
| 5710 | writer.print(innerPrefix); writer.print("mTraversalScheduled="); |
| 5711 | writer.print(mTraversalScheduled); |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 5712 | writer.print(innerPrefix); writer.print("mIsAmbientMode="); |
| 5713 | writer.print(mIsAmbientMode); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5714 | if (mTraversalScheduled) { |
| 5715 | writer.print(" (barrier="); writer.print(mTraversalBarrier); writer.println(")"); |
| 5716 | } else { |
| 5717 | writer.println(); |
| 5718 | } |
| 5719 | mFirstInputStage.dump(innerPrefix, writer); |
| 5720 | |
| 5721 | mChoreographer.dump(prefix, writer); |
| 5722 | |
| 5723 | writer.print(prefix); writer.println("View Hierarchy:"); |
| 5724 | dumpViewHierarchy(innerPrefix, writer, mView); |
| 5725 | } |
| 5726 | |
| 5727 | private void dumpViewHierarchy(String prefix, PrintWriter writer, View view) { |
| 5728 | writer.print(prefix); |
| 5729 | if (view == null) { |
| 5730 | writer.println("null"); |
| 5731 | return; |
| 5732 | } |
| 5733 | writer.println(view.toString()); |
| 5734 | if (!(view instanceof ViewGroup)) { |
| 5735 | return; |
| 5736 | } |
| 5737 | ViewGroup grp = (ViewGroup)view; |
| 5738 | final int N = grp.getChildCount(); |
| 5739 | if (N <= 0) { |
| 5740 | return; |
| 5741 | } |
| 5742 | prefix = prefix + " "; |
| 5743 | for (int i=0; i<N; i++) { |
| 5744 | dumpViewHierarchy(prefix, writer, grp.getChildAt(i)); |
| 5745 | } |
| 5746 | } |
| 5747 | |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 5748 | public void dumpGfxInfo(int[] info) { |
Romain Guy | 54ab347 | 2012-06-14 12:52:53 -0700 | [diff] [blame] | 5749 | info[0] = info[1] = 0; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5750 | if (mView != null) { |
| 5751 | getGfxInfo(mView, info); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5752 | } |
| 5753 | } |
| 5754 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5755 | private static void getGfxInfo(View view, int[] info) { |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 5756 | RenderNode renderNode = view.mRenderNode; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5757 | info[0]++; |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 5758 | if (renderNode != null) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 5759 | info[1] += renderNode.getDebugSize(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5760 | } |
| 5761 | |
| 5762 | if (view instanceof ViewGroup) { |
| 5763 | ViewGroup group = (ViewGroup) view; |
| 5764 | |
| 5765 | int count = group.getChildCount(); |
| 5766 | for (int i = 0; i < count; i++) { |
| 5767 | getGfxInfo(group.getChildAt(i), info); |
| 5768 | } |
| 5769 | } |
| 5770 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5771 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5772 | /** |
| 5773 | * @param immediate True, do now if not in traversal. False, put on queue and do later. |
| 5774 | * @return True, request has been queued. False, request has been completed. |
| 5775 | */ |
| 5776 | boolean die(boolean immediate) { |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 5777 | // Make sure we do execute immediately if we are in the middle of a traversal or the damage |
| 5778 | // done by dispatchDetachedFromWindow will cause havoc on return. |
| 5779 | if (immediate && !mIsInTraversal) { |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 5780 | doDie(); |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5781 | return false; |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 5782 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5783 | |
| 5784 | if (!mIsDrawing) { |
| 5785 | destroyHardwareRenderer(); |
| 5786 | } else { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5787 | Log.e(mTag, "Attempting to destroy the window while drawing!\n" + |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5788 | " window=" + this + ", title=" + mWindowAttributes.getTitle()); |
| 5789 | } |
| 5790 | mHandler.sendEmptyMessage(MSG_DIE); |
| 5791 | return true; |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 5792 | } |
| 5793 | |
| 5794 | void doDie() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5795 | checkThread(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5796 | 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] | 5797 | synchronized (this) { |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5798 | if (mRemoved) { |
| 5799 | return; |
| 5800 | } |
| 5801 | mRemoved = true; |
Romain Guy | 16260e7 | 2011-09-01 14:26:11 -0700 | [diff] [blame] | 5802 | if (mAdded) { |
Romain Guy | 16260e7 | 2011-09-01 14:26:11 -0700 | [diff] [blame] | 5803 | dispatchDetachedFromWindow(); |
| 5804 | } |
| 5805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5806 | if (mAdded && !mFirst) { |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 5807 | destroyHardwareRenderer(); |
| 5808 | |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5809 | if (mView != null) { |
| 5810 | int viewVisibility = mView.getVisibility(); |
| 5811 | boolean viewVisibilityChanged = mViewVisibility != viewVisibility; |
| 5812 | if (mWindowAttributesChanged || viewVisibilityChanged) { |
| 5813 | // If layout params have been changed, first give them |
| 5814 | // to the window manager to make sure it has the correct |
| 5815 | // animation info. |
| 5816 | try { |
| 5817 | if ((relayoutWindow(mWindowAttributes, viewVisibility, false) |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5818 | & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { |
| 5819 | mWindowSession.finishDrawing(mWindow); |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5820 | } |
| 5821 | } catch (RemoteException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5822 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5823 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5824 | |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5825 | mSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5826 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5827 | } |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5828 | |
| 5829 | mAdded = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5830 | } |
Craig Mautner | 05eb730 | 2013-06-03 17:24:21 -0700 | [diff] [blame] | 5831 | WindowManagerGlobal.getInstance().doRemoveView(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5832 | } |
| 5833 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5834 | public void requestUpdateConfiguration(Configuration config) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 5835 | Message msg = mHandler.obtainMessage(MSG_UPDATE_CONFIGURATION, config); |
| 5836 | mHandler.sendMessage(msg); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5837 | } |
| 5838 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 5839 | public void loadSystemProperties() { |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 5840 | mHandler.post(new Runnable() { |
| 5841 | @Override |
| 5842 | public void run() { |
| 5843 | // Profiling |
| 5844 | mProfileRendering = SystemProperties.getBoolean(PROPERTY_PROFILE_RENDERING, false); |
| 5845 | profileRendering(mAttachInfo.mHasWindowFocus); |
| 5846 | |
| 5847 | // Hardware rendering |
| 5848 | if (mAttachInfo.mHardwareRenderer != null) { |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 5849 | if (mAttachInfo.mHardwareRenderer.loadSystemProperties()) { |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 5850 | invalidate(); |
| 5851 | } |
| 5852 | } |
| 5853 | |
| 5854 | // Layout debugging |
| 5855 | boolean layout = SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false); |
| 5856 | if (layout != mAttachInfo.mDebugLayout) { |
| 5857 | mAttachInfo.mDebugLayout = layout; |
| 5858 | if (!mHandler.hasMessages(MSG_INVALIDATE_WORLD)) { |
| 5859 | mHandler.sendEmptyMessageDelayed(MSG_INVALIDATE_WORLD, 200); |
| 5860 | } |
| 5861 | } |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 5862 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 5863 | }); |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 5864 | } |
| 5865 | |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 5866 | private void destroyHardwareRenderer() { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5867 | ThreadedRenderer hardwareRenderer = mAttachInfo.mHardwareRenderer; |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5868 | |
| 5869 | if (hardwareRenderer != null) { |
| 5870 | if (mView != null) { |
| 5871 | hardwareRenderer.destroyHardwareResources(mView); |
| 5872 | } |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 5873 | hardwareRenderer.destroy(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5874 | hardwareRenderer.setRequested(false); |
| 5875 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 5876 | mAttachInfo.mHardwareRenderer = null; |
| 5877 | mAttachInfo.mHardwareAccelerated = false; |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 5878 | } |
| 5879 | } |
| 5880 | |
Yohei Yukawa | 1fa5f59 | 2016-03-24 10:24:23 -0700 | [diff] [blame] | 5881 | public void dispatchFinishInputConnection(InputConnection connection) { |
| 5882 | Message msg = mHandler.obtainMessage(MSG_FINISH_INPUT_CONNECTION, connection); |
| 5883 | mHandler.sendMessage(msg); |
| 5884 | } |
| 5885 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5886 | public void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5887 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 5888 | Configuration newConfig, Rect backDropFrame, boolean forceLayout, |
| 5889 | boolean alwaysConsumeNavBar) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5890 | if (DEBUG_LAYOUT) Log.v(mTag, "Resizing " + this + ": frame=" + frame.toShortString() |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5891 | + " contentInsets=" + contentInsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5892 | + " visibleInsets=" + visibleInsets.toShortString() |
Chong Zhang | d153c4f | 2015-11-06 20:26:40 -0800 | [diff] [blame] | 5893 | + " reportDraw=" + reportDraw |
| 5894 | + " backDropFrame=" + backDropFrame); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 5895 | |
| 5896 | // Tell all listeners that we are resizing the window so that the chrome can get |
| 5897 | // updated as fast as possible on a separate thread, |
| 5898 | if (mDragResizing) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 5899 | boolean fullscreen = frame.equals(backDropFrame); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 5900 | synchronized (mWindowCallbacks) { |
| 5901 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 5902 | mWindowCallbacks.get(i).onWindowSizeIsChanging(backDropFrame, fullscreen, |
| 5903 | visibleInsets, stableInsets); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 5904 | } |
| 5905 | } |
| 5906 | } |
| 5907 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5908 | Message msg = mHandler.obtainMessage(reportDraw ? MSG_RESIZED_REPORT : MSG_RESIZED); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5909 | if (mTranslator != null) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5910 | mTranslator.translateRectInScreenToAppWindow(frame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5911 | mTranslator.translateRectInScreenToAppWindow(overscanInsets); |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 5912 | mTranslator.translateRectInScreenToAppWindow(contentInsets); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5913 | mTranslator.translateRectInScreenToAppWindow(visibleInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5914 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5915 | SomeArgs args = SomeArgs.obtain(); |
| 5916 | final boolean sameProcessCall = (Binder.getCallingPid() == android.os.Process.myPid()); |
| 5917 | args.arg1 = sameProcessCall ? new Rect(frame) : frame; |
| 5918 | args.arg2 = sameProcessCall ? new Rect(contentInsets) : contentInsets; |
| 5919 | args.arg3 = sameProcessCall ? new Rect(visibleInsets) : visibleInsets; |
| 5920 | args.arg4 = sameProcessCall && newConfig != null ? new Configuration(newConfig) : newConfig; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5921 | args.arg5 = sameProcessCall ? new Rect(overscanInsets) : overscanInsets; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 5922 | args.arg6 = sameProcessCall ? new Rect(stableInsets) : stableInsets; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5923 | args.arg7 = sameProcessCall ? new Rect(outsets) : outsets; |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 5924 | args.arg8 = sameProcessCall ? new Rect(backDropFrame) : backDropFrame; |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 5925 | args.argi1 = forceLayout ? 1 : 0; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 5926 | args.argi2 = alwaysConsumeNavBar ? 1 : 0; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5927 | msg.obj = args; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 5928 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5929 | } |
Chet Haase | 1f4786b | 2011-11-02 10:51:52 -0700 | [diff] [blame] | 5930 | |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 5931 | public void dispatchMoved(int newX, int newY) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5932 | 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] | 5933 | if (mTranslator != null) { |
| 5934 | PointF point = new PointF(newX, newY); |
| 5935 | mTranslator.translatePointInScreenToAppWindow(point); |
| 5936 | newX = (int) (point.x + 0.5); |
| 5937 | newY = (int) (point.y + 0.5); |
| 5938 | } |
| 5939 | Message msg = mHandler.obtainMessage(MSG_WINDOW_MOVED, newX, newY); |
| 5940 | mHandler.sendMessage(msg); |
| 5941 | } |
| 5942 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5943 | /** |
| 5944 | * Represents a pending input event that is waiting in a queue. |
| 5945 | * |
| 5946 | * Input events are processed in serial order by the timestamp specified by |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 5947 | * {@link InputEvent#getEventTimeNano()}. In general, the input dispatcher delivers |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5948 | * one input event to the application at a time and waits for the application |
| 5949 | * to finish handling it before delivering the next one. |
| 5950 | * |
| 5951 | * However, because the application or IME can synthesize and inject multiple |
| 5952 | * key events at a time without going through the input dispatcher, we end up |
| 5953 | * needing a queue on the application's side. |
| 5954 | */ |
| 5955 | private static final class QueuedInputEvent { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5956 | public static final int FLAG_DELIVER_POST_IME = 1 << 0; |
| 5957 | public static final int FLAG_DEFERRED = 1 << 1; |
| 5958 | public static final int FLAG_FINISHED = 1 << 2; |
| 5959 | public static final int FLAG_FINISHED_HANDLED = 1 << 3; |
| 5960 | public static final int FLAG_RESYNTHESIZED = 1 << 4; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5961 | public static final int FLAG_UNHANDLED = 1 << 5; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5962 | |
| 5963 | public QueuedInputEvent mNext; |
| 5964 | |
| 5965 | public InputEvent mEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 5966 | public InputEventReceiver mReceiver; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5967 | public int mFlags; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5968 | |
| 5969 | public boolean shouldSkipIme() { |
| 5970 | if ((mFlags & FLAG_DELIVER_POST_IME) != 0) { |
| 5971 | return true; |
| 5972 | } |
| 5973 | return mEvent instanceof MotionEvent |
| 5974 | && mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER); |
| 5975 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5976 | |
| 5977 | public boolean shouldSendToSynthesizer() { |
| 5978 | if ((mFlags & FLAG_UNHANDLED) != 0) { |
| 5979 | return true; |
| 5980 | } |
| 5981 | |
| 5982 | return false; |
| 5983 | } |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 5984 | |
| 5985 | @Override |
| 5986 | public String toString() { |
| 5987 | StringBuilder sb = new StringBuilder("QueuedInputEvent{flags="); |
| 5988 | boolean hasPrevious = false; |
| 5989 | hasPrevious = flagToString("DELIVER_POST_IME", FLAG_DELIVER_POST_IME, hasPrevious, sb); |
| 5990 | hasPrevious = flagToString("DEFERRED", FLAG_DEFERRED, hasPrevious, sb); |
| 5991 | hasPrevious = flagToString("FINISHED", FLAG_FINISHED, hasPrevious, sb); |
| 5992 | hasPrevious = flagToString("FINISHED_HANDLED", FLAG_FINISHED_HANDLED, hasPrevious, sb); |
| 5993 | hasPrevious = flagToString("RESYNTHESIZED", FLAG_RESYNTHESIZED, hasPrevious, sb); |
| 5994 | hasPrevious = flagToString("UNHANDLED", FLAG_UNHANDLED, hasPrevious, sb); |
| 5995 | if (!hasPrevious) { |
| 5996 | sb.append("0"); |
| 5997 | } |
| 5998 | sb.append(", hasNextQueuedEvent=" + (mEvent != null ? "true" : "false")); |
| 5999 | sb.append(", hasInputEventReceiver=" + (mReceiver != null ? "true" : "false")); |
| 6000 | sb.append(", mEvent=" + mEvent + "}"); |
| 6001 | return sb.toString(); |
| 6002 | } |
| 6003 | |
| 6004 | private boolean flagToString(String name, int flag, |
| 6005 | boolean hasPrevious, StringBuilder sb) { |
| 6006 | if ((mFlags & flag) != 0) { |
| 6007 | if (hasPrevious) { |
| 6008 | sb.append("|"); |
| 6009 | } |
| 6010 | sb.append(name); |
| 6011 | return true; |
| 6012 | } |
| 6013 | return hasPrevious; |
| 6014 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | private QueuedInputEvent obtainQueuedInputEvent(InputEvent event, |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6018 | InputEventReceiver receiver, int flags) { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6019 | QueuedInputEvent q = mQueuedInputEventPool; |
| 6020 | if (q != null) { |
| 6021 | mQueuedInputEventPoolSize -= 1; |
| 6022 | mQueuedInputEventPool = q.mNext; |
| 6023 | q.mNext = null; |
| 6024 | } else { |
| 6025 | q = new QueuedInputEvent(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6026 | } |
| 6027 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6028 | q.mEvent = event; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6029 | q.mReceiver = receiver; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6030 | q.mFlags = flags; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6031 | return q; |
| 6032 | } |
| 6033 | |
| 6034 | private void recycleQueuedInputEvent(QueuedInputEvent q) { |
| 6035 | q.mEvent = null; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6036 | q.mReceiver = null; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6037 | |
| 6038 | if (mQueuedInputEventPoolSize < MAX_QUEUED_INPUT_EVENT_POOL_SIZE) { |
| 6039 | mQueuedInputEventPoolSize += 1; |
| 6040 | q.mNext = mQueuedInputEventPool; |
| 6041 | mQueuedInputEventPool = q; |
| 6042 | } |
| 6043 | } |
| 6044 | |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6045 | void enqueueInputEvent(InputEvent event) { |
| 6046 | enqueueInputEvent(event, null, 0, false); |
| 6047 | } |
| 6048 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6049 | void enqueueInputEvent(InputEvent event, |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6050 | InputEventReceiver receiver, int flags, boolean processImmediately) { |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6051 | adjustInputEventForCompatibility(event); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6052 | QueuedInputEvent q = obtainQueuedInputEvent(event, receiver, flags); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6053 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6054 | // Always enqueue the input event in order, regardless of its time stamp. |
| 6055 | // We do this because the application or the IME may inject key events |
| 6056 | // in response to touch events and we want to ensure that the injected keys |
| 6057 | // are processed in the order they were received and we cannot trust that |
| 6058 | // the time stamp of injected events are monotonic. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6059 | QueuedInputEvent last = mPendingInputEventTail; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6060 | if (last == null) { |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6061 | mPendingInputEventHead = q; |
| 6062 | mPendingInputEventTail = q; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6063 | } else { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6064 | last.mNext = q; |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6065 | mPendingInputEventTail = q; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6066 | } |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 6067 | mPendingInputEventCount += 1; |
| 6068 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mPendingInputEventQueueLengthCounterName, |
| 6069 | mPendingInputEventCount); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6070 | |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6071 | if (processImmediately) { |
| 6072 | doProcessInputEvents(); |
| 6073 | } else { |
| 6074 | scheduleProcessInputEvents(); |
| 6075 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6076 | } |
| 6077 | |
| 6078 | private void scheduleProcessInputEvents() { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 6079 | if (!mProcessInputEventsScheduled) { |
| 6080 | mProcessInputEventsScheduled = true; |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6081 | Message msg = mHandler.obtainMessage(MSG_PROCESS_INPUT_EVENTS); |
| 6082 | msg.setAsynchronous(true); |
| 6083 | mHandler.sendMessage(msg); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6084 | } |
| 6085 | } |
| 6086 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6087 | void doProcessInputEvents() { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6088 | // Deliver all pending input events in the queue. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6089 | while (mPendingInputEventHead != null) { |
| 6090 | QueuedInputEvent q = mPendingInputEventHead; |
| 6091 | mPendingInputEventHead = q.mNext; |
| 6092 | if (mPendingInputEventHead == null) { |
| 6093 | mPendingInputEventTail = null; |
| 6094 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6095 | q.mNext = null; |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6096 | |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 6097 | mPendingInputEventCount -= 1; |
| 6098 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mPendingInputEventQueueLengthCounterName, |
| 6099 | mPendingInputEventCount); |
| 6100 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 6101 | long eventTime = q.mEvent.getEventTimeNano(); |
| 6102 | long oldestEventTime = eventTime; |
| 6103 | if (q.mEvent instanceof MotionEvent) { |
| 6104 | MotionEvent me = (MotionEvent)q.mEvent; |
| 6105 | if (me.getHistorySize() > 0) { |
| 6106 | oldestEventTime = me.getHistoricalEventTimeNano(0); |
| 6107 | } |
| 6108 | } |
| 6109 | mChoreographer.mFrameInfo.updateInputEventTime(eventTime, oldestEventTime); |
| 6110 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6111 | deliverInputEvent(q); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6112 | } |
| 6113 | |
| 6114 | // We are done processing all input events that we can process right now |
| 6115 | // so we can clear the pending flag immediately. |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 6116 | if (mProcessInputEventsScheduled) { |
| 6117 | mProcessInputEventsScheduled = false; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6118 | mHandler.removeMessages(MSG_PROCESS_INPUT_EVENTS); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6119 | } |
| 6120 | } |
| 6121 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6122 | private void deliverInputEvent(QueuedInputEvent q) { |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6123 | Trace.asyncTraceBegin(Trace.TRACE_TAG_VIEW, "deliverInputEvent", |
| 6124 | q.mEvent.getSequenceNumber()); |
| 6125 | if (mInputEventConsistencyVerifier != null) { |
| 6126 | mInputEventConsistencyVerifier.onInputEvent(q.mEvent, 0); |
| 6127 | } |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6128 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6129 | InputStage stage; |
| 6130 | if (q.shouldSendToSynthesizer()) { |
| 6131 | stage = mSyntheticInputStage; |
| 6132 | } else { |
| 6133 | stage = q.shouldSkipIme() ? mFirstPostImeInputStage : mFirstInputStage; |
| 6134 | } |
| 6135 | |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6136 | if (stage != null) { |
| 6137 | stage.deliver(q); |
| 6138 | } else { |
| 6139 | finishInputEvent(q); |
Michael Wright | bf02096 | 2013-03-28 17:27:50 -0700 | [diff] [blame] | 6140 | } |
Michael Wright | bf02096 | 2013-03-28 17:27:50 -0700 | [diff] [blame] | 6141 | } |
| 6142 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6143 | private void finishInputEvent(QueuedInputEvent q) { |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6144 | Trace.asyncTraceEnd(Trace.TRACE_TAG_VIEW, "deliverInputEvent", |
| 6145 | q.mEvent.getSequenceNumber()); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6146 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6147 | if (q.mReceiver != null) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6148 | boolean handled = (q.mFlags & QueuedInputEvent.FLAG_FINISHED_HANDLED) != 0; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6149 | q.mReceiver.finishInputEvent(q.mEvent, handled); |
Jeff Brown | 92cc2d8 | 2011-12-02 01:19:47 -0800 | [diff] [blame] | 6150 | } else { |
| 6151 | q.mEvent.recycleIfNeededAfterDispatch(); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | recycleQueuedInputEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6155 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6156 | |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6157 | private void adjustInputEventForCompatibility(InputEvent e) { |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6158 | if (mTargetSdkVersion < Build.VERSION_CODES.M && e instanceof MotionEvent) { |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6159 | MotionEvent motion = (MotionEvent) e; |
| 6160 | final int mask = |
| 6161 | MotionEvent.BUTTON_STYLUS_PRIMARY | MotionEvent.BUTTON_STYLUS_SECONDARY; |
| 6162 | final int buttonState = motion.getButtonState(); |
| 6163 | final int compatButtonState = (buttonState & mask) >> 4; |
| 6164 | if (compatButtonState != 0) { |
| 6165 | motion.setButtonState(buttonState | compatButtonState); |
| 6166 | } |
| 6167 | } |
| 6168 | } |
| 6169 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6170 | static boolean isTerminalInputEvent(InputEvent event) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6171 | if (event instanceof KeyEvent) { |
| 6172 | final KeyEvent keyEvent = (KeyEvent)event; |
| 6173 | return keyEvent.getAction() == KeyEvent.ACTION_UP; |
| 6174 | } else { |
| 6175 | final MotionEvent motionEvent = (MotionEvent)event; |
| 6176 | final int action = motionEvent.getAction(); |
| 6177 | return action == MotionEvent.ACTION_UP |
| 6178 | || action == MotionEvent.ACTION_CANCEL |
| 6179 | || action == MotionEvent.ACTION_HOVER_EXIT; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6180 | } |
| 6181 | } |
| 6182 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6183 | void scheduleConsumeBatchedInput() { |
| 6184 | if (!mConsumeBatchedInputScheduled) { |
| 6185 | mConsumeBatchedInputScheduled = true; |
| 6186 | mChoreographer.postCallback(Choreographer.CALLBACK_INPUT, |
| 6187 | mConsumedBatchedInputRunnable, null); |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 6188 | } |
| 6189 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6190 | |
| 6191 | void unscheduleConsumeBatchedInput() { |
| 6192 | if (mConsumeBatchedInputScheduled) { |
| 6193 | mConsumeBatchedInputScheduled = false; |
| 6194 | mChoreographer.removeCallbacks(Choreographer.CALLBACK_INPUT, |
| 6195 | mConsumedBatchedInputRunnable, null); |
| 6196 | } |
| 6197 | } |
| 6198 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6199 | void scheduleConsumeBatchedInputImmediately() { |
| 6200 | if (!mConsumeBatchedInputImmediatelyScheduled) { |
| 6201 | unscheduleConsumeBatchedInput(); |
| 6202 | mConsumeBatchedInputImmediatelyScheduled = true; |
| 6203 | mHandler.post(mConsumeBatchedInputImmediatelyRunnable); |
| 6204 | } |
| 6205 | } |
| 6206 | |
Jeff Brown | 771526c | 2012-04-27 15:13:25 -0700 | [diff] [blame] | 6207 | void doConsumeBatchedInput(long frameTimeNanos) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6208 | if (mConsumeBatchedInputScheduled) { |
| 6209 | mConsumeBatchedInputScheduled = false; |
Jeff Brown | 330314c | 2012-04-27 02:20:22 -0700 | [diff] [blame] | 6210 | if (mInputEventReceiver != null) { |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6211 | if (mInputEventReceiver.consumeBatchedInputEvents(frameTimeNanos) |
| 6212 | && frameTimeNanos != -1) { |
Michael Wright | 62ce65d | 2013-10-25 14:50:36 -0700 | [diff] [blame] | 6213 | // If we consumed a batch here, we want to go ahead and schedule the |
| 6214 | // consumption of batched input events on the next frame. Otherwise, we would |
| 6215 | // 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] | 6216 | // things occurring in the process. If the frame time is -1, however, then |
| 6217 | // 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] | 6218 | scheduleConsumeBatchedInput(); |
| 6219 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6220 | } |
Jeff Brown | 330314c | 2012-04-27 02:20:22 -0700 | [diff] [blame] | 6221 | doProcessInputEvents(); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6222 | } |
| 6223 | } |
| 6224 | |
| 6225 | final class TraversalRunnable implements Runnable { |
| 6226 | @Override |
| 6227 | public void run() { |
| 6228 | doTraversal(); |
| 6229 | } |
| 6230 | } |
| 6231 | final TraversalRunnable mTraversalRunnable = new TraversalRunnable(); |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 6232 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6233 | final class WindowInputEventReceiver extends InputEventReceiver { |
| 6234 | public WindowInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 6235 | super(inputChannel, looper); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6236 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6237 | |
| 6238 | @Override |
| 6239 | public void onInputEvent(InputEvent event) { |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6240 | enqueueInputEvent(event, this, 0, true); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6241 | } |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 6242 | |
| 6243 | @Override |
| 6244 | public void onBatchedInputEventPending() { |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6245 | if (mUnbufferedInputDispatch) { |
| 6246 | super.onBatchedInputEventPending(); |
| 6247 | } else { |
| 6248 | scheduleConsumeBatchedInput(); |
| 6249 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6250 | } |
| 6251 | |
| 6252 | @Override |
| 6253 | public void dispose() { |
| 6254 | unscheduleConsumeBatchedInput(); |
| 6255 | super.dispose(); |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 6256 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6257 | } |
| 6258 | WindowInputEventReceiver mInputEventReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6259 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6260 | final class ConsumeBatchedInputRunnable implements Runnable { |
| 6261 | @Override |
| 6262 | public void run() { |
Jeff Brown | 771526c | 2012-04-27 15:13:25 -0700 | [diff] [blame] | 6263 | doConsumeBatchedInput(mChoreographer.getFrameTimeNanos()); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6264 | } |
| 6265 | } |
| 6266 | final ConsumeBatchedInputRunnable mConsumedBatchedInputRunnable = |
| 6267 | new ConsumeBatchedInputRunnable(); |
| 6268 | boolean mConsumeBatchedInputScheduled; |
| 6269 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6270 | final class ConsumeBatchedInputImmediatelyRunnable implements Runnable { |
| 6271 | @Override |
| 6272 | public void run() { |
| 6273 | doConsumeBatchedInput(-1); |
| 6274 | } |
| 6275 | } |
| 6276 | final ConsumeBatchedInputImmediatelyRunnable mConsumeBatchedInputImmediatelyRunnable = |
| 6277 | new ConsumeBatchedInputImmediatelyRunnable(); |
| 6278 | boolean mConsumeBatchedInputImmediatelyScheduled; |
| 6279 | |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6280 | final class InvalidateOnAnimationRunnable implements Runnable { |
| 6281 | private boolean mPosted; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6282 | private final ArrayList<View> mViews = new ArrayList<View>(); |
| 6283 | private final ArrayList<AttachInfo.InvalidateInfo> mViewRects = |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6284 | new ArrayList<AttachInfo.InvalidateInfo>(); |
| 6285 | private View[] mTempViews; |
| 6286 | private AttachInfo.InvalidateInfo[] mTempViewRects; |
| 6287 | |
| 6288 | public void addView(View view) { |
| 6289 | synchronized (this) { |
| 6290 | mViews.add(view); |
| 6291 | postIfNeededLocked(); |
| 6292 | } |
| 6293 | } |
| 6294 | |
| 6295 | public void addViewRect(AttachInfo.InvalidateInfo info) { |
| 6296 | synchronized (this) { |
| 6297 | mViewRects.add(info); |
| 6298 | postIfNeededLocked(); |
| 6299 | } |
| 6300 | } |
| 6301 | |
| 6302 | public void removeView(View view) { |
| 6303 | synchronized (this) { |
| 6304 | mViews.remove(view); |
| 6305 | |
| 6306 | for (int i = mViewRects.size(); i-- > 0; ) { |
| 6307 | AttachInfo.InvalidateInfo info = mViewRects.get(i); |
| 6308 | if (info.target == view) { |
| 6309 | mViewRects.remove(i); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 6310 | info.recycle(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6311 | } |
| 6312 | } |
| 6313 | |
| 6314 | if (mPosted && mViews.isEmpty() && mViewRects.isEmpty()) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6315 | mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, this, null); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6316 | mPosted = false; |
| 6317 | } |
| 6318 | } |
| 6319 | } |
| 6320 | |
| 6321 | @Override |
| 6322 | public void run() { |
| 6323 | final int viewCount; |
| 6324 | final int viewRectCount; |
| 6325 | synchronized (this) { |
| 6326 | mPosted = false; |
| 6327 | |
| 6328 | viewCount = mViews.size(); |
| 6329 | if (viewCount != 0) { |
| 6330 | mTempViews = mViews.toArray(mTempViews != null |
| 6331 | ? mTempViews : new View[viewCount]); |
| 6332 | mViews.clear(); |
| 6333 | } |
| 6334 | |
| 6335 | viewRectCount = mViewRects.size(); |
| 6336 | if (viewRectCount != 0) { |
| 6337 | mTempViewRects = mViewRects.toArray(mTempViewRects != null |
| 6338 | ? mTempViewRects : new AttachInfo.InvalidateInfo[viewRectCount]); |
| 6339 | mViewRects.clear(); |
| 6340 | } |
| 6341 | } |
| 6342 | |
| 6343 | for (int i = 0; i < viewCount; i++) { |
| 6344 | mTempViews[i].invalidate(); |
Adam Powell | 3e3c4ee | 2012-05-16 17:34:21 -0700 | [diff] [blame] | 6345 | mTempViews[i] = null; |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6346 | } |
| 6347 | |
| 6348 | for (int i = 0; i < viewRectCount; i++) { |
| 6349 | final View.AttachInfo.InvalidateInfo info = mTempViewRects[i]; |
| 6350 | info.target.invalidate(info.left, info.top, info.right, info.bottom); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 6351 | info.recycle(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6352 | } |
| 6353 | } |
| 6354 | |
| 6355 | private void postIfNeededLocked() { |
| 6356 | if (!mPosted) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6357 | mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, this, null); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6358 | mPosted = true; |
| 6359 | } |
| 6360 | } |
| 6361 | } |
| 6362 | final InvalidateOnAnimationRunnable mInvalidateOnAnimationRunnable = |
| 6363 | new InvalidateOnAnimationRunnable(); |
| 6364 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6365 | public void dispatchInvalidateDelayed(View view, long delayMilliseconds) { |
| 6366 | Message msg = mHandler.obtainMessage(MSG_INVALIDATE, view); |
| 6367 | mHandler.sendMessageDelayed(msg, delayMilliseconds); |
| 6368 | } |
| 6369 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6370 | public void dispatchInvalidateRectDelayed(AttachInfo.InvalidateInfo info, |
| 6371 | long delayMilliseconds) { |
| 6372 | final Message msg = mHandler.obtainMessage(MSG_INVALIDATE_RECT, info); |
| 6373 | mHandler.sendMessageDelayed(msg, delayMilliseconds); |
| 6374 | } |
| 6375 | |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6376 | public void dispatchInvalidateOnAnimation(View view) { |
| 6377 | mInvalidateOnAnimationRunnable.addView(view); |
| 6378 | } |
| 6379 | |
| 6380 | public void dispatchInvalidateRectOnAnimation(AttachInfo.InvalidateInfo info) { |
| 6381 | mInvalidateOnAnimationRunnable.addViewRect(info); |
| 6382 | } |
| 6383 | |
| 6384 | public void cancelInvalidate(View view) { |
| 6385 | mHandler.removeMessages(MSG_INVALIDATE, view); |
| 6386 | // fixme: might leak the AttachInfo.InvalidateInfo objects instead of returning |
| 6387 | // them to the pool |
| 6388 | mHandler.removeMessages(MSG_INVALIDATE_RECT, view); |
| 6389 | mInvalidateOnAnimationRunnable.removeView(view); |
| 6390 | } |
| 6391 | |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 6392 | public void dispatchInputEvent(InputEvent event) { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 6393 | dispatchInputEvent(event, null); |
| 6394 | } |
| 6395 | |
| 6396 | public void dispatchInputEvent(InputEvent event, InputEventReceiver receiver) { |
| 6397 | SomeArgs args = SomeArgs.obtain(); |
| 6398 | args.arg1 = event; |
| 6399 | args.arg2 = receiver; |
| 6400 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_INPUT_EVENT, args); |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 6401 | msg.setAsynchronous(true); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6402 | mHandler.sendMessage(msg); |
| 6403 | } |
| 6404 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6405 | public void synthesizeInputEvent(InputEvent event) { |
| 6406 | Message msg = mHandler.obtainMessage(MSG_SYNTHESIZE_INPUT_EVENT, event); |
| 6407 | msg.setAsynchronous(true); |
| 6408 | mHandler.sendMessage(msg); |
| 6409 | } |
| 6410 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6411 | public void dispatchKeyFromIme(KeyEvent event) { |
| 6412 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_KEY_FROM_IME, event); |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 6413 | msg.setAsynchronous(true); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6414 | mHandler.sendMessage(msg); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6415 | } |
| 6416 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6417 | /** |
| 6418 | * Reinject unhandled {@link InputEvent}s in order to synthesize fallbacks events. |
| 6419 | * |
| 6420 | * Note that it is the responsibility of the caller of this API to recycle the InputEvent it |
| 6421 | * passes in. |
| 6422 | */ |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6423 | public void dispatchUnhandledInputEvent(InputEvent event) { |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6424 | if (event instanceof MotionEvent) { |
| 6425 | event = MotionEvent.obtain((MotionEvent) event); |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6426 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6427 | synthesizeInputEvent(event); |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6428 | } |
| 6429 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6430 | public void dispatchAppVisibility(boolean visible) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6431 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_APP_VISIBILITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6432 | msg.arg1 = visible ? 1 : 0; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6433 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6434 | } |
| 6435 | |
| 6436 | public void dispatchGetNewSurface() { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6437 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_GET_NEW_SURFACE); |
| 6438 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6439 | } |
| 6440 | |
| 6441 | public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { |
| 6442 | Message msg = Message.obtain(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6443 | msg.what = MSG_WINDOW_FOCUS_CHANGED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6444 | msg.arg1 = hasFocus ? 1 : 0; |
| 6445 | msg.arg2 = inTouchMode ? 1 : 0; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6446 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6447 | } |
| 6448 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 6449 | public void dispatchWindowShown() { |
| 6450 | mHandler.sendEmptyMessage(MSG_DISPATCH_WINDOW_SHOWN); |
| 6451 | } |
| 6452 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6453 | public void dispatchCloseSystemDialogs(String reason) { |
| 6454 | Message msg = Message.obtain(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6455 | msg.what = MSG_CLOSE_SYSTEM_DIALOGS; |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6456 | msg.obj = reason; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6457 | mHandler.sendMessage(msg); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6458 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6459 | |
| 6460 | public void dispatchDragEvent(DragEvent event) { |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6461 | final int what; |
| 6462 | if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6463 | what = MSG_DISPATCH_DRAG_LOCATION_EVENT; |
| 6464 | mHandler.removeMessages(what); |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6465 | } else { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6466 | what = MSG_DISPATCH_DRAG_EVENT; |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6467 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6468 | Message msg = mHandler.obtainMessage(what, event); |
| 6469 | mHandler.sendMessage(msg); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6470 | } |
| 6471 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 6472 | public void updatePointerIcon(float x, float y) { |
| 6473 | final int what = MSG_UPDATE_POINTER_ICON; |
| 6474 | mHandler.removeMessages(what); |
| 6475 | final long now = SystemClock.uptimeMillis(); |
| 6476 | final MotionEvent event = MotionEvent.obtain( |
| 6477 | 0, now, MotionEvent.ACTION_HOVER_MOVE, x, y, 0); |
| 6478 | Message msg = mHandler.obtainMessage(what, event); |
| 6479 | mHandler.sendMessage(msg); |
| 6480 | } |
| 6481 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6482 | public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, |
| 6483 | int localValue, int localChanges) { |
| 6484 | SystemUiVisibilityInfo args = new SystemUiVisibilityInfo(); |
| 6485 | args.seq = seq; |
| 6486 | args.globalVisibility = globalVisibility; |
| 6487 | args.localValue = localValue; |
| 6488 | args.localChanges = localChanges; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6489 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DISPATCH_SYSTEM_UI_VISIBILITY, args)); |
| 6490 | } |
| 6491 | |
| 6492 | public void dispatchCheckFocus() { |
| 6493 | if (!mHandler.hasMessages(MSG_CHECK_FOCUS)) { |
| 6494 | // This will result in a call to checkFocus() below. |
| 6495 | mHandler.sendEmptyMessage(MSG_CHECK_FOCUS); |
| 6496 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6497 | } |
| 6498 | |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 6499 | public void dispatchRequestKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
| 6500 | mHandler.obtainMessage( |
| 6501 | MSG_REQUEST_KEYBOARD_SHORTCUTS, deviceId, 0, receiver).sendToTarget(); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 6502 | } |
| 6503 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6504 | /** |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6505 | * Post a callback to send a |
| 6506 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6507 | * This event is send at most once every |
| 6508 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6509 | */ |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 6510 | private void postSendWindowContentChangedCallback(View source, int changeType) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6511 | if (mSendWindowContentChangedAccessibilityEvent == null) { |
| 6512 | mSendWindowContentChangedAccessibilityEvent = |
| 6513 | new SendWindowContentChangedAccessibilityEvent(); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6514 | } |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 6515 | mSendWindowContentChangedAccessibilityEvent.runOrPost(source, changeType); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6516 | } |
| 6517 | |
| 6518 | /** |
| 6519 | * Remove a posted callback to send a |
| 6520 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. |
| 6521 | */ |
| 6522 | private void removeSendWindowContentChangedCallback() { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6523 | if (mSendWindowContentChangedAccessibilityEvent != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6524 | mHandler.removeCallbacks(mSendWindowContentChangedAccessibilityEvent); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6525 | } |
| 6526 | } |
| 6527 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6528 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6529 | public boolean showContextMenuForChild(View originalView) { |
| 6530 | return false; |
| 6531 | } |
| 6532 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6533 | @Override |
Oren Blasberg | ed39126 | 2015-09-01 12:12:51 -0700 | [diff] [blame] | 6534 | public boolean showContextMenuForChild(View originalView, float x, float y) { |
| 6535 | return false; |
| 6536 | } |
| 6537 | |
| 6538 | @Override |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 6539 | public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) { |
| 6540 | return null; |
| 6541 | } |
| 6542 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6543 | @Override |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 6544 | public ActionMode startActionModeForChild( |
| 6545 | View originalView, ActionMode.Callback callback, int type) { |
| 6546 | return null; |
| 6547 | } |
| 6548 | |
| 6549 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6550 | public void createContextMenu(ContextMenu menu) { |
| 6551 | } |
| 6552 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6553 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6554 | public void childDrawableStateChanged(View child) { |
| 6555 | } |
| 6556 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6557 | @Override |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6558 | public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 6559 | if (mView == null || mStopped || mPausedForTransition) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6560 | return false; |
| 6561 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6562 | // Intercept accessibility focus events fired by virtual nodes to keep |
| 6563 | // track of accessibility focus position in such nodes. |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6564 | final int eventType = event.getEventType(); |
| 6565 | switch (eventType) { |
| 6566 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6567 | final long sourceNodeId = event.getSourceNodeId(); |
| 6568 | final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 6569 | sourceNodeId); |
| 6570 | View source = mView.findViewByAccessibilityId(accessibilityViewId); |
| 6571 | if (source != null) { |
| 6572 | AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider(); |
| 6573 | if (provider != null) { |
Svetoslav | b3ba1d4 | 2014-09-26 15:20:40 -0700 | [diff] [blame] | 6574 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 6575 | sourceNodeId); |
| 6576 | final AccessibilityNodeInfo node; |
| 6577 | if (virtualNodeId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
| 6578 | node = provider.createAccessibilityNodeInfo( |
| 6579 | AccessibilityNodeProvider.HOST_VIEW_ID); |
| 6580 | } else { |
| 6581 | node = provider.createAccessibilityNodeInfo(virtualNodeId); |
| 6582 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6583 | setAccessibilityFocus(source, node); |
| 6584 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6585 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6586 | } break; |
| 6587 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6588 | final long sourceNodeId = event.getSourceNodeId(); |
| 6589 | final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 6590 | sourceNodeId); |
| 6591 | View source = mView.findViewByAccessibilityId(accessibilityViewId); |
| 6592 | if (source != null) { |
| 6593 | AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider(); |
| 6594 | if (provider != null) { |
| 6595 | setAccessibilityFocus(null, null); |
| 6596 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6597 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6598 | } break; |
Svetoslav | f0c758b | 2014-09-03 17:47:37 -0700 | [diff] [blame] | 6599 | |
| 6600 | |
| 6601 | case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: { |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6602 | handleWindowContentChangedEvent(event); |
Svetoslav | f0c758b | 2014-09-03 17:47:37 -0700 | [diff] [blame] | 6603 | } break; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6604 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6605 | mAccessibilityManager.sendAccessibilityEvent(event); |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6606 | return true; |
| 6607 | } |
| 6608 | |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6609 | /** |
| 6610 | * Updates the focused virtual view, when necessary, in response to a |
| 6611 | * content changed event. |
| 6612 | * <p> |
| 6613 | * This is necessary to get updated bounds after a position change. |
| 6614 | * |
| 6615 | * @param event an accessibility event of type |
| 6616 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} |
| 6617 | */ |
| 6618 | private void handleWindowContentChangedEvent(AccessibilityEvent event) { |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6619 | final View focusedHost = mAccessibilityFocusedHost; |
| 6620 | if (focusedHost == null || mAccessibilityFocusedVirtualView == null) { |
| 6621 | // No virtual view focused, nothing to do here. |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6622 | return; |
| 6623 | } |
| 6624 | |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6625 | final AccessibilityNodeProvider provider = focusedHost.getAccessibilityNodeProvider(); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6626 | if (provider == null) { |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6627 | // Error state: virtual view with no provider. Clear focus. |
| 6628 | mAccessibilityFocusedHost = null; |
| 6629 | mAccessibilityFocusedVirtualView = null; |
| 6630 | focusedHost.clearAccessibilityFocusNoCallbacks(); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6631 | return; |
| 6632 | } |
| 6633 | |
| 6634 | // We only care about change types that may affect the bounds of the |
| 6635 | // focused virtual view. |
| 6636 | final int changes = event.getContentChangeTypes(); |
| 6637 | if ((changes & AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE) == 0 |
| 6638 | && changes != AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED) { |
| 6639 | return; |
| 6640 | } |
| 6641 | |
| 6642 | final long eventSourceNodeId = event.getSourceNodeId(); |
| 6643 | final int changedViewId = AccessibilityNodeInfo.getAccessibilityViewId(eventSourceNodeId); |
| 6644 | |
| 6645 | // Search up the tree for subtree containment. |
| 6646 | boolean hostInSubtree = false; |
| 6647 | View root = mAccessibilityFocusedHost; |
| 6648 | while (root != null && !hostInSubtree) { |
| 6649 | if (changedViewId == root.getAccessibilityViewId()) { |
| 6650 | hostInSubtree = true; |
| 6651 | } else { |
| 6652 | final ViewParent parent = root.getParent(); |
| 6653 | if (parent instanceof View) { |
| 6654 | root = (View) parent; |
| 6655 | } else { |
| 6656 | root = null; |
| 6657 | } |
| 6658 | } |
| 6659 | } |
| 6660 | |
| 6661 | // We care only about changes in subtrees containing the host view. |
| 6662 | if (!hostInSubtree) { |
| 6663 | return; |
| 6664 | } |
| 6665 | |
| 6666 | final long focusedSourceNodeId = mAccessibilityFocusedVirtualView.getSourceNodeId(); |
| 6667 | int focusedChildId = AccessibilityNodeInfo.getVirtualDescendantId(focusedSourceNodeId); |
| 6668 | if (focusedChildId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
| 6669 | // TODO: Should we clear the focused virtual view? |
| 6670 | focusedChildId = AccessibilityNodeProvider.HOST_VIEW_ID; |
| 6671 | } |
| 6672 | |
| 6673 | // Refresh the node for the focused virtual view. |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 6674 | final Rect oldBounds = mTempRect; |
| 6675 | mAccessibilityFocusedVirtualView.getBoundsInScreen(oldBounds); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6676 | mAccessibilityFocusedVirtualView = provider.createAccessibilityNodeInfo(focusedChildId); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6677 | if (mAccessibilityFocusedVirtualView == null) { |
| 6678 | // Error state: The node no longer exists. Clear focus. |
| 6679 | mAccessibilityFocusedHost = null; |
| 6680 | focusedHost.clearAccessibilityFocusNoCallbacks(); |
| 6681 | |
| 6682 | // This will probably fail, but try to keep the provider's internal |
| 6683 | // state consistent by clearing focus. |
| 6684 | provider.performAction(focusedChildId, |
| 6685 | AccessibilityAction.ACTION_CLEAR_ACCESSIBILITY_FOCUS.getId(), null); |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 6686 | invalidateRectOnScreen(oldBounds); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6687 | } else { |
| 6688 | // The node was refreshed, invalidate bounds if necessary. |
| 6689 | final Rect newBounds = mAccessibilityFocusedVirtualView.getBoundsInScreen(); |
| 6690 | if (!oldBounds.equals(newBounds)) { |
| 6691 | oldBounds.union(newBounds); |
| 6692 | invalidateRectOnScreen(oldBounds); |
| 6693 | } |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 6694 | } |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6695 | } |
| 6696 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6697 | @Override |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 6698 | public void notifySubtreeAccessibilityStateChanged(View child, View source, int changeType) { |
| 6699 | postSendWindowContentChangedCallback(source, changeType); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6700 | } |
| 6701 | |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 6702 | @Override |
| 6703 | public boolean canResolveLayoutDirection() { |
| 6704 | return true; |
| 6705 | } |
| 6706 | |
| 6707 | @Override |
| 6708 | public boolean isLayoutDirectionResolved() { |
| 6709 | return true; |
| 6710 | } |
| 6711 | |
| 6712 | @Override |
| 6713 | public int getLayoutDirection() { |
| 6714 | return View.LAYOUT_DIRECTION_RESOLVED_DEFAULT; |
| 6715 | } |
| 6716 | |
| 6717 | @Override |
| 6718 | public boolean canResolveTextDirection() { |
| 6719 | return true; |
| 6720 | } |
| 6721 | |
| 6722 | @Override |
| 6723 | public boolean isTextDirectionResolved() { |
| 6724 | return true; |
| 6725 | } |
| 6726 | |
| 6727 | @Override |
| 6728 | public int getTextDirection() { |
| 6729 | return View.TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 6730 | } |
| 6731 | |
| 6732 | @Override |
| 6733 | public boolean canResolveTextAlignment() { |
| 6734 | return true; |
| 6735 | } |
| 6736 | |
| 6737 | @Override |
| 6738 | public boolean isTextAlignmentResolved() { |
| 6739 | return true; |
| 6740 | } |
| 6741 | |
| 6742 | @Override |
| 6743 | public int getTextAlignment() { |
| 6744 | return View.TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 6745 | } |
| 6746 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6747 | private View getCommonPredecessor(View first, View second) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 6748 | if (mTempHashSet == null) { |
| 6749 | mTempHashSet = new HashSet<View>(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6750 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 6751 | HashSet<View> seen = mTempHashSet; |
| 6752 | seen.clear(); |
| 6753 | View firstCurrent = first; |
| 6754 | while (firstCurrent != null) { |
| 6755 | seen.add(firstCurrent); |
| 6756 | ViewParent firstCurrentParent = firstCurrent.mParent; |
| 6757 | if (firstCurrentParent instanceof View) { |
| 6758 | firstCurrent = (View) firstCurrentParent; |
| 6759 | } else { |
| 6760 | firstCurrent = null; |
| 6761 | } |
| 6762 | } |
| 6763 | View secondCurrent = second; |
| 6764 | while (secondCurrent != null) { |
| 6765 | if (seen.contains(secondCurrent)) { |
| 6766 | seen.clear(); |
| 6767 | return secondCurrent; |
| 6768 | } |
| 6769 | ViewParent secondCurrentParent = secondCurrent.mParent; |
| 6770 | if (secondCurrentParent instanceof View) { |
| 6771 | secondCurrent = (View) secondCurrentParent; |
| 6772 | } else { |
| 6773 | secondCurrent = null; |
| 6774 | } |
| 6775 | } |
| 6776 | seen.clear(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6777 | return null; |
| 6778 | } |
| 6779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6780 | void checkThread() { |
| 6781 | if (mThread != Thread.currentThread()) { |
| 6782 | throw new CalledFromWrongThreadException( |
| 6783 | "Only the original thread that created a view hierarchy can touch its views."); |
| 6784 | } |
| 6785 | } |
| 6786 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6787 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6788 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 6789 | // 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] | 6790 | } |
| 6791 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6792 | @Override |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6793 | public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { |
Yigit Boyar | d62d5e9 | 2016-01-19 18:56:20 -0800 | [diff] [blame] | 6794 | if (rectangle == null) { |
| 6795 | return scrollToRectOrFocus(null, immediate); |
| 6796 | } |
| 6797 | rectangle.offset(child.getLeft() - child.getScrollX(), |
| 6798 | child.getTop() - child.getScrollY()); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6799 | final boolean scrolled = scrollToRectOrFocus(rectangle, immediate); |
Yigit Boyar | d62d5e9 | 2016-01-19 18:56:20 -0800 | [diff] [blame] | 6800 | mTempRect.set(rectangle); |
| 6801 | mTempRect.offset(0, -mCurScrollY); |
| 6802 | mTempRect.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
| 6803 | try { |
| 6804 | mWindowSession.onRectangleOnScreenRequested(mWindow, mTempRect); |
| 6805 | } catch (RemoteException re) { |
| 6806 | /* ignore */ |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6807 | } |
| 6808 | return scrolled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6809 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6810 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6811 | @Override |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 6812 | public void childHasTransientStateChanged(View child, boolean hasTransientState) { |
| 6813 | // Do nothing. |
| 6814 | } |
| 6815 | |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 6816 | @Override |
| 6817 | public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) { |
| 6818 | return false; |
| 6819 | } |
| 6820 | |
| 6821 | @Override |
| 6822 | public void onStopNestedScroll(View target) { |
| 6823 | } |
| 6824 | |
| 6825 | @Override |
| 6826 | public void onNestedScrollAccepted(View child, View target, int nestedScrollAxes) { |
| 6827 | } |
| 6828 | |
| 6829 | @Override |
| 6830 | public void onNestedScroll(View target, int dxConsumed, int dyConsumed, |
| 6831 | int dxUnconsumed, int dyUnconsumed) { |
| 6832 | } |
| 6833 | |
| 6834 | @Override |
| 6835 | public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { |
| 6836 | } |
| 6837 | |
| 6838 | @Override |
Adam Powell | b36e4f9 | 2014-05-01 10:23:33 -0700 | [diff] [blame] | 6839 | public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) { |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 6840 | return false; |
| 6841 | } |
| 6842 | |
Adam Powell | b72be59 | 2014-07-16 21:41:31 -0700 | [diff] [blame] | 6843 | @Override |
| 6844 | public boolean onNestedPreFling(View target, float velocityX, float velocityY) { |
| 6845 | return false; |
| 6846 | } |
| 6847 | |
Adam Powell | b6ab098 | 2015-01-07 17:00:12 -0800 | [diff] [blame] | 6848 | @Override |
| 6849 | public boolean onNestedPrePerformAccessibilityAction(View target, int action, Bundle args) { |
| 6850 | return false; |
| 6851 | } |
| 6852 | |
Jorim Jaggi | b774e55 | 2015-08-24 14:52:45 -0700 | [diff] [blame] | 6853 | /** |
| 6854 | * Force the window to report its next draw. |
| 6855 | * <p> |
| 6856 | * This method is only supposed to be used to speed up the interaction from SystemUI and window |
| 6857 | * manager when waiting for the first frame to be drawn when turning on the screen. DO NOT USE |
| 6858 | * unless you fully understand this interaction. |
| 6859 | * @hide |
| 6860 | */ |
| 6861 | public void setReportNextDraw() { |
| 6862 | mReportNextDraw = true; |
| 6863 | invalidate(); |
| 6864 | } |
| 6865 | |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 6866 | void changeCanvasOpacity(boolean opaque) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6867 | Log.d(mTag, "changeCanvasOpacity: opaque=" + opaque); |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 6868 | if (mAttachInfo.mHardwareRenderer != null) { |
| 6869 | mAttachInfo.mHardwareRenderer.setOpaque(opaque); |
| 6870 | } |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 6871 | } |
| 6872 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6873 | class TakenSurfaceHolder extends BaseSurfaceHolder { |
| 6874 | @Override |
| 6875 | public boolean onAllowLockCanvas() { |
| 6876 | return mDrawingAllowed; |
| 6877 | } |
| 6878 | |
| 6879 | @Override |
| 6880 | public void onRelayoutContainer() { |
| 6881 | // Not currently interesting -- from changing between fixed and layout size. |
| 6882 | } |
| 6883 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6884 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6885 | public void setFormat(int format) { |
| 6886 | ((RootViewSurfaceTaker)mView).setSurfaceFormat(format); |
| 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 void setType(int type) { |
| 6891 | ((RootViewSurfaceTaker)mView).setSurfaceType(type); |
| 6892 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6893 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6894 | @Override |
| 6895 | public void onUpdateSurface() { |
| 6896 | // We take care of format and type changes on our own. |
| 6897 | throw new IllegalStateException("Shouldn't be here"); |
| 6898 | } |
| 6899 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6900 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6901 | public boolean isCreating() { |
| 6902 | return mIsCreating; |
| 6903 | } |
| 6904 | |
| 6905 | @Override |
| 6906 | public void setFixedSize(int width, int height) { |
| 6907 | throw new UnsupportedOperationException( |
| 6908 | "Currently only support sizing from layout"); |
| 6909 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6910 | |
| 6911 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6912 | public void setKeepScreenOn(boolean screenOn) { |
| 6913 | ((RootViewSurfaceTaker)mView).setSurfaceKeepScreenOn(screenOn); |
| 6914 | } |
| 6915 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6916 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6917 | static class W extends IWindow.Stub { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6918 | private final WeakReference<ViewRootImpl> mViewAncestor; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6919 | private final IWindowSession mWindowSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6920 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6921 | W(ViewRootImpl viewAncestor) { |
| 6922 | mViewAncestor = new WeakReference<ViewRootImpl>(viewAncestor); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6923 | mWindowSession = viewAncestor.mWindowSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6924 | } |
| 6925 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6926 | @Override |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6927 | public void resized(Rect frame, Rect overscanInsets, Rect contentInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 6928 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6929 | Configuration newConfig, Rect backDropFrame, boolean forceLayout, |
| 6930 | boolean alwaysConsumeNavBar) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6931 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6932 | if (viewAncestor != null) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6933 | viewAncestor.dispatchResized(frame, overscanInsets, contentInsets, |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 6934 | visibleInsets, stableInsets, outsets, reportDraw, newConfig, backDropFrame, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6935 | forceLayout, alwaysConsumeNavBar); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6936 | } |
| 6937 | } |
| 6938 | |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 6939 | @Override |
| 6940 | public void moved(int newX, int newY) { |
| 6941 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 6942 | if (viewAncestor != null) { |
| 6943 | viewAncestor.dispatchMoved(newX, newY); |
| 6944 | } |
| 6945 | } |
| 6946 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6947 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6948 | public void dispatchAppVisibility(boolean visible) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6949 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6950 | if (viewAncestor != null) { |
| 6951 | viewAncestor.dispatchAppVisibility(visible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6952 | } |
| 6953 | } |
| 6954 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6955 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6956 | public void dispatchGetNewSurface() { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6957 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6958 | if (viewAncestor != null) { |
| 6959 | viewAncestor.dispatchGetNewSurface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6960 | } |
| 6961 | } |
| 6962 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6963 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6964 | public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6965 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6966 | if (viewAncestor != null) { |
| 6967 | viewAncestor.windowFocusChanged(hasFocus, inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6968 | } |
| 6969 | } |
| 6970 | |
| 6971 | private static int checkCallingPermission(String permission) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6972 | try { |
| 6973 | return ActivityManagerNative.getDefault().checkPermission( |
| 6974 | permission, Binder.getCallingPid(), Binder.getCallingUid()); |
| 6975 | } catch (RemoteException e) { |
| 6976 | return PackageManager.PERMISSION_DENIED; |
| 6977 | } |
| 6978 | } |
| 6979 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6980 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6981 | public void executeCommand(String command, String parameters, ParcelFileDescriptor out) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6982 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6983 | if (viewAncestor != null) { |
| 6984 | final View view = viewAncestor.mView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6985 | if (view != null) { |
| 6986 | if (checkCallingPermission(Manifest.permission.DUMP) != |
| 6987 | PackageManager.PERMISSION_GRANTED) { |
| 6988 | throw new SecurityException("Insufficient permissions to invoke" |
| 6989 | + " executeCommand() from pid=" + Binder.getCallingPid() |
| 6990 | + ", uid=" + Binder.getCallingUid()); |
| 6991 | } |
| 6992 | |
| 6993 | OutputStream clientStream = null; |
| 6994 | try { |
| 6995 | clientStream = new ParcelFileDescriptor.AutoCloseOutputStream(out); |
| 6996 | ViewDebug.dispatchCommand(view, command, parameters, clientStream); |
| 6997 | } catch (IOException e) { |
| 6998 | e.printStackTrace(); |
| 6999 | } finally { |
| 7000 | if (clientStream != null) { |
| 7001 | try { |
| 7002 | clientStream.close(); |
| 7003 | } catch (IOException e) { |
| 7004 | e.printStackTrace(); |
| 7005 | } |
| 7006 | } |
| 7007 | } |
| 7008 | } |
| 7009 | } |
| 7010 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7011 | |
| 7012 | @Override |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 7013 | public void closeSystemDialogs(String reason) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7014 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7015 | if (viewAncestor != null) { |
| 7016 | viewAncestor.dispatchCloseSystemDialogs(reason); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 7017 | } |
| 7018 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7019 | |
| 7020 | @Override |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7021 | public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep, |
| 7022 | boolean sync) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7023 | if (sync) { |
| 7024 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7025 | mWindowSession.wallpaperOffsetsComplete(asBinder()); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7026 | } catch (RemoteException e) { |
| 7027 | } |
| 7028 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7029 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7030 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7031 | @Override |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 7032 | public void dispatchWallpaperCommand(String action, int x, int y, |
| 7033 | int z, Bundle extras, boolean sync) { |
| 7034 | if (sync) { |
| 7035 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7036 | mWindowSession.wallpaperCommandComplete(asBinder(), null); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 7037 | } catch (RemoteException e) { |
| 7038 | } |
| 7039 | } |
| 7040 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7041 | |
| 7042 | /* Drag/drop */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7043 | @Override |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7044 | public void dispatchDragEvent(DragEvent event) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7045 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7046 | if (viewAncestor != null) { |
| 7047 | viewAncestor.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7048 | } |
| 7049 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7050 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7051 | @Override |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 7052 | public void updatePointerIcon(float x, float y) { |
| 7053 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7054 | if (viewAncestor != null) { |
| 7055 | viewAncestor.updatePointerIcon(x, y); |
| 7056 | } |
| 7057 | } |
| 7058 | |
| 7059 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 7060 | public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, |
| 7061 | int localValue, int localChanges) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7062 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7063 | if (viewAncestor != null) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 7064 | viewAncestor.dispatchSystemUiVisibilityChanged(seq, globalVisibility, |
| 7065 | localValue, localChanges); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7066 | } |
| 7067 | } |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 7068 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7069 | @Override |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 7070 | public void dispatchWindowShown() { |
| 7071 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7072 | if (viewAncestor != null) { |
| 7073 | viewAncestor.dispatchWindowShown(); |
| 7074 | } |
| 7075 | } |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 7076 | |
| 7077 | @Override |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 7078 | public void requestAppKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
| 7079 | ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7080 | if (viewAncestor != null) { |
| 7081 | viewAncestor.dispatchRequestKeyboardShortcuts(receiver, deviceId); |
| 7082 | } |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 7083 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7084 | } |
| 7085 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7086 | public static final class CalledFromWrongThreadException extends AndroidRuntimeException { |
| 7087 | public CalledFromWrongThreadException(String msg) { |
| 7088 | super(msg); |
| 7089 | } |
| 7090 | } |
| 7091 | |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 7092 | static HandlerActionQueue getRunQueue() { |
| 7093 | HandlerActionQueue rq = sRunQueues.get(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7094 | if (rq != null) { |
| 7095 | return rq; |
| 7096 | } |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 7097 | rq = new HandlerActionQueue(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7098 | sRunQueues.set(rq); |
| 7099 | return rq; |
| 7100 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7101 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7102 | /** |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7103 | * Start a drag resizing which will inform all listeners that a window resize is taking place. |
| 7104 | */ |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 7105 | private void startDragResizing(Rect initialBounds, boolean fullscreen, Rect systemInsets, |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame^] | 7106 | Rect stableInsets, int resizeMode) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7107 | if (!mDragResizing) { |
| 7108 | mDragResizing = true; |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 7109 | synchronized (mWindowCallbacks) { |
| 7110 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 7111 | mWindowCallbacks.get(i).onWindowDragResizeStart(initialBounds, fullscreen, |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame^] | 7112 | systemInsets, stableInsets, resizeMode); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7113 | } |
| 7114 | } |
| 7115 | mFullRedrawNeeded = true; |
| 7116 | } |
| 7117 | } |
| 7118 | |
| 7119 | /** |
| 7120 | * End a drag resize which will inform all listeners that a window resize has ended. |
| 7121 | */ |
| 7122 | private void endDragResizing() { |
| 7123 | if (mDragResizing) { |
| 7124 | mDragResizing = false; |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 7125 | synchronized (mWindowCallbacks) { |
| 7126 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7127 | mWindowCallbacks.get(i).onWindowDragResizeEnd(); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7128 | } |
| 7129 | } |
| 7130 | mFullRedrawNeeded = true; |
| 7131 | } |
| 7132 | } |
| 7133 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 7134 | private boolean updateContentDrawBounds() { |
| 7135 | boolean updated = false; |
| 7136 | synchronized (mWindowCallbacks) { |
| 7137 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7138 | updated |= mWindowCallbacks.get(i).onContentDrawn( |
| 7139 | mWindowAttributes.surfaceInsets.left, |
| 7140 | mWindowAttributes.surfaceInsets.top, |
| 7141 | mWidth, mHeight); |
| 7142 | } |
| 7143 | } |
| 7144 | return updated | (mDragResizing && mReportNextDraw); |
| 7145 | } |
| 7146 | |
| 7147 | private void requestDrawWindow() { |
| 7148 | if (mReportNextDraw) { |
| 7149 | mWindowDrawCountDown = new CountDownLatch(mWindowCallbacks.size()); |
| 7150 | } |
| 7151 | synchronized (mWindowCallbacks) { |
| 7152 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7153 | mWindowCallbacks.get(i).onRequestDraw(mReportNextDraw); |
| 7154 | } |
| 7155 | } |
| 7156 | } |
| 7157 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7158 | /** |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 7159 | * Tells this instance that its corresponding activity has just relaunched. In this case, we |
| 7160 | * need to force a relayout of the window to make sure we get the correct bounds from window |
| 7161 | * manager. |
| 7162 | */ |
| 7163 | public void reportActivityRelaunched() { |
| 7164 | mActivityRelaunched = true; |
| 7165 | } |
| 7166 | |
| 7167 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7168 | * Class for managing the accessibility interaction connection |
| 7169 | * based on the global accessibility state. |
| 7170 | */ |
| 7171 | final class AccessibilityInteractionConnectionManager |
| 7172 | implements AccessibilityStateChangeListener { |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7173 | @Override |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7174 | public void onAccessibilityStateChanged(boolean enabled) { |
| 7175 | if (enabled) { |
| 7176 | ensureConnection(); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7177 | if (mAttachInfo.mHasWindowFocus) { |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 7178 | mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 7179 | View focusedView = mView.findFocus(); |
| 7180 | if (focusedView != null && focusedView != mView) { |
| 7181 | focusedView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 7182 | } |
| 7183 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7184 | } else { |
| 7185 | ensureNoConnection(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 7186 | mHandler.obtainMessage(MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST).sendToTarget(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7187 | } |
| 7188 | } |
| 7189 | |
| 7190 | public void ensureConnection() { |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7191 | final boolean registered = |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 7192 | mAttachInfo.mAccessibilityWindowId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7193 | if (!registered) { |
| 7194 | mAttachInfo.mAccessibilityWindowId = |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 7195 | mAccessibilityManager.addAccessibilityInteractionConnection(mWindow, |
| 7196 | new AccessibilityInteractionConnection(ViewRootImpl.this)); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7197 | } |
| 7198 | } |
| 7199 | |
| 7200 | public void ensureNoConnection() { |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 7201 | final boolean registered = |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 7202 | mAttachInfo.mAccessibilityWindowId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7203 | if (registered) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 7204 | mAttachInfo.mAccessibilityWindowId = AccessibilityNodeInfo.UNDEFINED_ITEM_ID; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7205 | mAccessibilityManager.removeAccessibilityInteractionConnection(mWindow); |
| 7206 | } |
| 7207 | } |
| 7208 | } |
| 7209 | |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7210 | final class HighContrastTextManager implements HighTextContrastChangeListener { |
| 7211 | HighContrastTextManager() { |
| 7212 | mAttachInfo.mHighContrastText = mAccessibilityManager.isHighTextContrastEnabled(); |
| 7213 | } |
| 7214 | @Override |
| 7215 | public void onHighTextContrastStateChanged(boolean enabled) { |
| 7216 | mAttachInfo.mHighContrastText = enabled; |
| 7217 | |
| 7218 | // Destroy Displaylists so they can be recreated with high contrast recordings |
| 7219 | destroyHardwareResources(); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 7220 | |
| 7221 | // Schedule redraw, which will rerecord + redraw all text |
| 7222 | invalidate(); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7223 | } |
| 7224 | } |
| 7225 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7226 | /** |
| 7227 | * This class is an interface this ViewAncestor provides to the |
| 7228 | * AccessibilityManagerService to the latter can interact with |
| 7229 | * the view hierarchy in this ViewAncestor. |
| 7230 | */ |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7231 | static final class AccessibilityInteractionConnection |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7232 | extends IAccessibilityInteractionConnection.Stub { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7233 | private final WeakReference<ViewRootImpl> mViewRootImpl; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7234 | |
Svetoslav Ganov | f79f476 | 2011-10-28 15:40:32 -0700 | [diff] [blame] | 7235 | AccessibilityInteractionConnection(ViewRootImpl viewRootImpl) { |
| 7236 | mViewRootImpl = new WeakReference<ViewRootImpl>(viewRootImpl); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7237 | } |
| 7238 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7239 | @Override |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7240 | public void findAccessibilityNodeInfoByAccessibilityId(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7241 | Region interactiveRegion, int interactionId, |
| 7242 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7243 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7244 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7245 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7246 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7247 | .findAccessibilityNodeInfoByAccessibilityIdClientThread(accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7248 | interactiveRegion, interactionId, callback, flags, interrogatingPid, |
| 7249 | interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7250 | } else { |
| 7251 | // We cannot make the call and notify the caller so it does not wait. |
| 7252 | try { |
| 7253 | callback.setFindAccessibilityNodeInfosResult(null, interactionId); |
| 7254 | } catch (RemoteException re) { |
| 7255 | /* best effort - ignore */ |
| 7256 | } |
Svetoslav Ganov | 601ad80 | 2011-06-09 14:47:38 -0700 | [diff] [blame] | 7257 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7258 | } |
| 7259 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7260 | @Override |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7261 | public void performAccessibilityAction(long accessibilityNodeId, int action, |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 7262 | Bundle arguments, int interactionId, |
| 7263 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 7264 | int interrogatingPid, long interrogatingTid) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7265 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7266 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7267 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 7268 | .performAccessibilityActionClientThread(accessibilityNodeId, action, arguments, |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 7269 | interactionId, callback, flags, interrogatingPid, interrogatingTid); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7270 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7271 | // 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] | 7272 | try { |
| 7273 | callback.setPerformAccessibilityActionResult(false, interactionId); |
| 7274 | } catch (RemoteException re) { |
| 7275 | /* best effort - ignore */ |
| 7276 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7277 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7278 | } |
| 7279 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7280 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7281 | public void findAccessibilityNodeInfosByViewId(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7282 | String viewId, Region interactiveRegion, int interactionId, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7283 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7284 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7285 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7286 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7287 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7288 | .findAccessibilityNodeInfosByViewIdClientThread(accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7289 | viewId, interactiveRegion, interactionId, callback, flags, |
| 7290 | interrogatingPid, interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7291 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7292 | // 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] | 7293 | try { |
| 7294 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
| 7295 | } catch (RemoteException re) { |
| 7296 | /* best effort - ignore */ |
| 7297 | } |
| 7298 | } |
| 7299 | } |
| 7300 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7301 | @Override |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7302 | public void findAccessibilityNodeInfosByText(long accessibilityNodeId, String text, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7303 | Region interactiveRegion, int interactionId, |
| 7304 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7305 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7306 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7307 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7308 | viewRootImpl.getAccessibilityInteractionController() |
| 7309 | .findAccessibilityNodeInfosByTextClientThread(accessibilityNodeId, text, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7310 | interactiveRegion, interactionId, callback, flags, interrogatingPid, |
| 7311 | interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7312 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7313 | // 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] | 7314 | try { |
| 7315 | callback.setFindAccessibilityNodeInfosResult(null, interactionId); |
| 7316 | } catch (RemoteException re) { |
| 7317 | /* best effort - ignore */ |
| 7318 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7319 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7320 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7321 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7322 | @Override |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7323 | public void findFocus(long accessibilityNodeId, int focusType, Region interactiveRegion, |
| 7324 | int interactionId, IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7325 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7326 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7327 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7328 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7329 | .findFocusClientThread(accessibilityNodeId, focusType, interactiveRegion, |
| 7330 | interactionId, callback, flags, interrogatingPid, interrogatingTid, |
| 7331 | spec); |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 7332 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7333 | // 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] | 7334 | try { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7335 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7336 | } catch (RemoteException re) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7337 | /* best effort - ignore */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7338 | } |
| 7339 | } |
| 7340 | } |
| 7341 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7342 | @Override |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7343 | public void focusSearch(long accessibilityNodeId, int direction, Region interactiveRegion, |
| 7344 | int interactionId, IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7345 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7346 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7347 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7348 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7349 | .focusSearchClientThread(accessibilityNodeId, direction, interactiveRegion, |
| 7350 | interactionId, callback, flags, interrogatingPid, interrogatingTid, |
| 7351 | spec); |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 7352 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7353 | // 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] | 7354 | try { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7355 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7356 | } catch (RemoteException re) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7357 | /* best effort - ignore */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7358 | } |
| 7359 | } |
| 7360 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7361 | } |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7362 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7363 | private class SendWindowContentChangedAccessibilityEvent implements Runnable { |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7364 | private int mChangeTypes = 0; |
| 7365 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7366 | public View mSource; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7367 | public long mLastEventTimeMillis; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7368 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7369 | @Override |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7370 | public void run() { |
Svetoslav | 8d820ecf | 2013-07-15 17:12:41 -0700 | [diff] [blame] | 7371 | // The accessibility may be turned off while we were waiting so check again. |
| 7372 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 7373 | mLastEventTimeMillis = SystemClock.uptimeMillis(); |
| 7374 | AccessibilityEvent event = AccessibilityEvent.obtain(); |
| 7375 | event.setEventType(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7376 | event.setContentChangeTypes(mChangeTypes); |
Svetoslav | 8d820ecf | 2013-07-15 17:12:41 -0700 | [diff] [blame] | 7377 | mSource.sendAccessibilityEventUnchecked(event); |
| 7378 | } else { |
| 7379 | mLastEventTimeMillis = 0; |
| 7380 | } |
| 7381 | // In any case reset to initial state. |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7382 | mSource.resetSubtreeAccessibilityStateChanged(); |
| 7383 | mSource = null; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7384 | mChangeTypes = 0; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7385 | } |
| 7386 | |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7387 | public void runOrPost(View source, int changeType) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7388 | if (mSource != null) { |
Svetoslav | 9dafebb | 2013-06-18 16:29:25 -0700 | [diff] [blame] | 7389 | // If there is no common predecessor, then mSource points to |
| 7390 | // a removed view, hence in this case always prefer the source. |
| 7391 | View predecessor = getCommonPredecessor(mSource, source); |
| 7392 | mSource = (predecessor != null) ? predecessor : source; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7393 | mChangeTypes |= changeType; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7394 | return; |
| 7395 | } |
| 7396 | mSource = source; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7397 | mChangeTypes = changeType; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7398 | final long timeSinceLastMillis = SystemClock.uptimeMillis() - mLastEventTimeMillis; |
| 7399 | final long minEventIntevalMillis = |
| 7400 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval(); |
| 7401 | if (timeSinceLastMillis >= minEventIntevalMillis) { |
Svetoslav | 9dafebb | 2013-06-18 16:29:25 -0700 | [diff] [blame] | 7402 | mSource.removeCallbacks(this); |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7403 | run(); |
| 7404 | } else { |
| 7405 | mSource.postDelayed(this, minEventIntevalMillis - timeSinceLastMillis); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7406 | } |
| 7407 | } |
| 7408 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7409 | } |