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 | |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY; |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 20 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 21 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 22 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; |
| 23 | import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 24 | |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 25 | import android.Manifest; |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 26 | import android.animation.LayoutTransition; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 27 | import android.app.ActivityManagerNative; |
| 28 | import android.content.ClipDescription; |
| 29 | import android.content.ComponentCallbacks; |
| 30 | import android.content.Context; |
| 31 | import android.content.pm.PackageManager; |
| 32 | import android.content.res.CompatibilityInfo; |
| 33 | import android.content.res.Configuration; |
| 34 | import android.content.res.Resources; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.graphics.Canvas; |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 36 | import android.graphics.Matrix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.graphics.PixelFormat; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 38 | import android.graphics.Point; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 39 | import android.graphics.PointF; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 40 | import android.graphics.PorterDuff; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.graphics.Rect; |
| 42 | import android.graphics.Region; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 43 | import android.graphics.drawable.Drawable; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 44 | import android.hardware.display.DisplayManager; |
| 45 | import android.hardware.display.DisplayManager.DisplayListener; |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 46 | import android.hardware.input.InputManager; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 47 | import android.media.AudioManager; |
| 48 | import android.os.Binder; |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 49 | import android.os.Build; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 50 | import android.os.Bundle; |
| 51 | import android.os.Debug; |
| 52 | import android.os.Handler; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 53 | import android.os.Looper; |
| 54 | import android.os.Message; |
| 55 | import android.os.ParcelFileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.os.Process; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 57 | import android.os.RemoteException; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 58 | import android.os.SystemClock; |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 59 | import android.os.SystemProperties; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 60 | import android.os.Trace; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.util.AndroidRuntimeException; |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 62 | import android.util.DisplayMetrics; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 63 | import android.util.Log; |
Chet Haase | 949dbf7 | 2010-08-11 18:41:06 -0700 | [diff] [blame] | 64 | import android.util.Slog; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 65 | import android.util.TimeUtils; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 66 | import android.util.TypedValue; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 67 | import android.view.Surface.OutOfResourcesException; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 68 | import android.view.View.AttachInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.view.View.MeasureSpec; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 70 | import android.view.accessibility.AccessibilityEvent; |
| 71 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 72 | import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 73 | import android.view.accessibility.AccessibilityManager.HighTextContrastChangeListener; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 74 | import android.view.accessibility.AccessibilityNodeInfo; |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 75 | import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 76 | import android.view.accessibility.AccessibilityNodeProvider; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 77 | import android.view.accessibility.IAccessibilityInteractionConnection; |
| 78 | import android.view.accessibility.IAccessibilityInteractionConnectionCallback; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 79 | import android.view.animation.AccelerateDecelerateInterpolator; |
| 80 | import android.view.animation.Interpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | import android.view.inputmethod.InputConnection; |
| 82 | import android.view.inputmethod.InputMethodManager; |
| 83 | import android.widget.Scroller; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 84 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 85 | import com.android.internal.R; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 86 | import com.android.internal.os.IResultReceiver; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 87 | import com.android.internal.os.SomeArgs; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 88 | import com.android.internal.policy.PhoneFallbackEventHandler; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 89 | import com.android.internal.view.BaseSurfaceHolder; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 90 | import com.android.internal.view.RootViewSurfaceTaker; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 92 | import java.io.FileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | import java.io.IOException; |
| 94 | import java.io.OutputStream; |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 95 | import java.io.PrintWriter; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 96 | import java.lang.ref.WeakReference; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import java.util.ArrayList; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 98 | import java.util.concurrent.CountDownLatch; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 99 | import java.util.HashSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | /** |
| 102 | * The top of a view hierarchy, implementing the needed protocol between View |
| 103 | * and the WindowManager. This is for the most part an internal implementation |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 104 | * detail of {@link WindowManagerGlobal}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | * |
| 106 | * {@hide} |
| 107 | */ |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 108 | @SuppressWarnings({"EmptyCatchBlock", "PointlessBooleanExpression"}) |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 109 | public final class ViewRootImpl implements ViewParent, |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 110 | View.AttachInfo.Callbacks, ThreadedRenderer.HardwareDrawCallbacks { |
Dianne Hackborn | 70a3f67 | 2011-08-08 14:32:41 -0700 | [diff] [blame] | 111 | private static final String TAG = "ViewRootImpl"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | private static final boolean DBG = false; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 113 | private static final boolean LOCAL_LOGV = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | /** @noinspection PointlessBooleanExpression*/ |
| 115 | private static final boolean DEBUG_DRAW = false || LOCAL_LOGV; |
| 116 | private static final boolean DEBUG_LAYOUT = false || LOCAL_LOGV; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 117 | private static final boolean DEBUG_DIALOG = false || LOCAL_LOGV; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | private static final boolean DEBUG_INPUT_RESIZE = false || LOCAL_LOGV; |
| 119 | private static final boolean DEBUG_ORIENTATION = false || LOCAL_LOGV; |
| 120 | private static final boolean DEBUG_TRACKBALL = false || LOCAL_LOGV; |
| 121 | private static final boolean DEBUG_IMF = false || LOCAL_LOGV; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 122 | private static final boolean DEBUG_CONFIGURATION = false || LOCAL_LOGV; |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 123 | private static final boolean DEBUG_FPS = false; |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 124 | 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] | 125 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 126 | /** |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 127 | * Set to false if we do not want to use the multi threaded renderer. Note that by disabling |
| 128 | * this, WindowCallbacks will not fire. |
| 129 | */ |
| 130 | private static final boolean USE_MT_RENDERER = true; |
| 131 | |
| 132 | /** |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 133 | * Set this system property to true to force the view hierarchy to render |
| 134 | * at 60 Hz. This can be used to measure the potential framerate. |
| 135 | */ |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 136 | private static final String PROPERTY_PROFILE_RENDERING = "viewroot.profile_rendering"; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 137 | |
Griff Hazen | a093802 | 2015-03-13 10:01:41 -0700 | [diff] [blame] | 138 | // properties used by emulator to determine display shape |
Griff Hazen | a093802 | 2015-03-13 10:01:41 -0700 | [diff] [blame] | 139 | public static final String PROPERTY_EMULATOR_WIN_OUTSET_BOTTOM_PX = |
| 140 | "ro.emu.win_outset_bottom_px"; |
Michael Kolb | 437d313 | 2014-06-20 13:28:44 -0700 | [diff] [blame] | 141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | /** |
| 143 | * Maximum time we allow the user to roll the trackball enough to generate |
| 144 | * a key event, before resetting the counters. |
| 145 | */ |
| 146 | static final int MAX_TRACKBALL_DELAY = 250; |
| 147 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 148 | private static final int RESIZE_MODE_FREEFORM = 0; |
| 149 | private static final int RESIZE_MODE_DOCKED_DIVIDER = 1; |
| 150 | |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 151 | static final ThreadLocal<HandlerActionQueue> sRunQueues = new ThreadLocal<HandlerActionQueue>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 153 | static final ArrayList<Runnable> sFirstDrawHandlers = new ArrayList(); |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 154 | static boolean sFirstDrawComplete = false; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 155 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 156 | static final ArrayList<ComponentCallbacks> sConfigCallbacks = new ArrayList(); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 157 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 158 | final ArrayList<WindowCallbacks> mWindowCallbacks = new ArrayList(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 159 | final Context mContext; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 160 | final IWindowSession mWindowSession; |
| 161 | final Display mDisplay; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 162 | final DisplayManager mDisplayManager; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 163 | final String mBasePackageName; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | final int[] mTmpLocation = new int[2]; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 166 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 167 | final TypedValue mTmpValue = new TypedValue(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | final Thread mThread; |
| 170 | |
| 171 | final WindowLeaked mLocation; |
| 172 | |
| 173 | final WindowManager.LayoutParams mWindowAttributes = new WindowManager.LayoutParams(); |
| 174 | |
| 175 | final W mWindow; |
| 176 | |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 177 | final int mTargetSdkVersion; |
| 178 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 179 | int mSeq; |
| 180 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | View mView; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 182 | |
| 183 | View mAccessibilityFocusedHost; |
| 184 | AccessibilityNodeInfo mAccessibilityFocusedVirtualView; |
| 185 | |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 186 | // The view which captures mouse input, or null when no one is capturing. |
| 187 | View mCapturingView; |
| 188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | int mViewVisibility; |
| 190 | boolean mAppVisible = true; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 191 | // For recents to freeform transition we need to keep drawing after the app receives information |
| 192 | // that it became invisible. This will ignore that information and depend on the decor view |
| 193 | // visibility to control drawing. The decor view visibility will get adjusted when the app get |
| 194 | // stopped and that's when the app will stop drawing further frames. |
| 195 | private boolean mForceDecorViewVisibility = false; |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 196 | int mOrigWindowType = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 198 | /** Whether the window had focus during the most recent traversal. */ |
| 199 | boolean mHadWindowFocus; |
| 200 | |
| 201 | /** |
| 202 | * Whether the window lost focus during a previous traversal and has not |
| 203 | * yet gained it back. Used to determine whether a WINDOW_STATE_CHANGE |
| 204 | * accessibility events should be sent during traversal. |
| 205 | */ |
| 206 | boolean mLostWindowFocus; |
| 207 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 208 | // Set to true if the owner of this window is in the stopped state, |
| 209 | // so the window should no longer be active. |
| 210 | boolean mStopped = false; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 211 | |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 212 | // Set to true if the owner of this window is in ambient mode, |
| 213 | // which means it won't receive input events. |
| 214 | boolean mIsAmbientMode = false; |
| 215 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 216 | // Set to true to stop input during an Activity Transition. |
| 217 | boolean mPausedForTransition = false; |
| 218 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 219 | boolean mLastInCompatMode = false; |
| 220 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 221 | SurfaceHolder.Callback2 mSurfaceHolderCallback; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 222 | BaseSurfaceHolder mSurfaceHolder; |
| 223 | boolean mIsCreating; |
| 224 | boolean mDrawingAllowed; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | final Region mTransparentRegion; |
| 227 | final Region mPreviousTransparentRegion; |
| 228 | |
| 229 | int mWidth; |
| 230 | int mHeight; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 231 | Rect mDirty; |
Romain Guy | bb93d55 | 2009-03-24 21:04:15 -0700 | [diff] [blame] | 232 | boolean mIsAnimating; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 233 | |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 234 | private boolean mDragResizing; |
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; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 266 | CountDownLatch mWindowDrawCountDown; |
Jorim Jaggi | 827e0fa | 2015-05-07 11:41:41 -0700 | [diff] [blame] | 267 | |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 268 | boolean mIsDrawing; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 269 | int mLastSystemUiVisibility; |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 270 | int mClientWindowLayoutFlags; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 271 | boolean mLastOverscanRequested; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 272 | |
| 273 | // Pool of queued input events. |
| 274 | private static final int MAX_QUEUED_INPUT_EVENT_POOL_SIZE = 10; |
| 275 | private QueuedInputEvent mQueuedInputEventPool; |
| 276 | private int mQueuedInputEventPoolSize; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 277 | |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 278 | /* Input event queue. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 279 | * Pending input events are input events waiting to be delivered to the input stages |
| 280 | * and handled by the application. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 281 | */ |
| 282 | QueuedInputEvent mPendingInputEventHead; |
| 283 | QueuedInputEvent mPendingInputEventTail; |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 284 | int mPendingInputEventCount; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 285 | boolean mProcessInputEventsScheduled; |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 286 | boolean mUnbufferedInputDispatch; |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 287 | String mPendingInputEventQueueLengthCounterName = "pq"; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 288 | |
| 289 | InputStage mFirstInputStage; |
| 290 | InputStage mFirstPostImeInputStage; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 291 | InputStage mSyntheticInputStage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | |
| 293 | boolean mWindowAttributesChanged = false; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 294 | int mWindowAttributesChangesFlag = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | |
| 296 | // 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] | 297 | // Surface can never be reassigned or cleared (use Surface.clear()). |
John Reck | b13de07 | 2014-11-19 16:33:47 -0800 | [diff] [blame] | 298 | final Surface mSurface = new Surface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | |
| 300 | boolean mAdded; |
| 301 | boolean mAddedTouchMode; |
| 302 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 303 | final DisplayAdjustments mDisplayAdjustments; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | // These are accessed by multiple threads. |
| 306 | final Rect mWinFrame; // frame given by window manager. |
| 307 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 308 | final Rect mPendingOverscanInsets = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | final Rect mPendingVisibleInsets = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 310 | final Rect mPendingStableInsets = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | final Rect mPendingContentInsets = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 312 | final Rect mPendingOutsets = new Rect(); |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 313 | final Rect mPendingBackDropFrame = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | final ViewTreeObserver.InternalInsetsInfo mLastGivenInsets |
| 315 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 316 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 317 | final Rect mDispatchContentInsets = new Rect(); |
| 318 | final Rect mDispatchStableInsets = new Rect(); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 319 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 320 | private WindowInsets mLastWindowInsets; |
| 321 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 322 | final Configuration mLastConfiguration = new Configuration(); |
| 323 | final Configuration mPendingConfiguration = new Configuration(); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | boolean mScrollMayChange; |
| 326 | int mSoftInputMode; |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 327 | WeakReference<View> mLastScrolledFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | int mScrollY; |
| 329 | int mCurScrollY; |
| 330 | Scroller mScroller; |
John Reck | e56e9df | 2014-02-21 15:45:10 -0800 | [diff] [blame] | 331 | static final Interpolator mResizeInterpolator = new AccelerateDecelerateInterpolator(); |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 332 | private ArrayList<LayoutTransition> mPendingTransitions; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 333 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 334 | final ViewConfiguration mViewConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 336 | /* Drag/drop */ |
| 337 | ClipDescription mDragDescription; |
| 338 | View mCurrentDragView; |
Christopher Tate | 7fb8b56 | 2011-01-20 13:46:41 -0800 | [diff] [blame] | 339 | volatile Object mLocalDragState; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 340 | final PointF mDragPoint = new PointF(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 341 | final PointF mLastTouchPoint = new PointF(); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 342 | |
| 343 | private boolean mProfileRendering; |
Romain Guy | d075031 | 2012-11-29 11:34:43 -0800 | [diff] [blame] | 344 | private Choreographer.FrameCallback mRenderProfiler; |
| 345 | private boolean mRenderProfilingEnabled; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 346 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 347 | // Variables to track frames per second, enabled via DEBUG_FPS flag |
| 348 | private long mFpsStartTime = -1; |
| 349 | private long mFpsPrevTime = -1; |
| 350 | private int mFpsNumFrames; |
| 351 | |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 352 | private int mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 353 | private PointerIcon mCustomPointerIcon = null; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | /** |
| 356 | * see {@link #playSoundEffect(int)} |
| 357 | */ |
| 358 | AudioManager mAudioManager; |
| 359 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 360 | final AccessibilityManager mAccessibilityManager; |
| 361 | |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 362 | AccessibilityInteractionController mAccessibilityInteractionController; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 363 | |
| 364 | AccessibilityInteractionConnectionManager mAccessibilityInteractionConnectionManager; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 365 | HighContrastTextManager mHighContrastTextManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 366 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 367 | SendWindowContentChangedAccessibilityEvent mSendWindowContentChangedAccessibilityEvent; |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 368 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 369 | HashSet<View> mTempHashSet; |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 370 | |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 371 | private final int mDensity; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 372 | private final int mNoncompatDensity; |
Adam Powell | b08013c | 2010-09-16 16:28:11 -0700 | [diff] [blame] | 373 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 374 | private boolean mInLayout = false; |
| 375 | ArrayList<View> mLayoutRequesters = new ArrayList<View>(); |
| 376 | boolean mHandlingLayoutInLayoutRequest = false; |
| 377 | |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 378 | private int mViewLayoutDirectionInitial; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 379 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 380 | /** Set to true once doDie() has been called. */ |
| 381 | private boolean mRemoved; |
| 382 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 383 | /** |
| 384 | * Consistency verifier for debugging purposes. |
| 385 | */ |
| 386 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 387 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 388 | new InputEventConsistencyVerifier(this, 0) : null; |
| 389 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 390 | static final class SystemUiVisibilityInfo { |
| 391 | int seq; |
| 392 | int globalVisibility; |
| 393 | int localValue; |
| 394 | int localChanges; |
| 395 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 396 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 397 | private String mTag = TAG; |
| 398 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 399 | public ViewRootImpl(Context context, Display display) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 400 | mContext = context; |
| 401 | mWindowSession = WindowManagerGlobal.getWindowSession(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 402 | mDisplay = display; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 403 | mBasePackageName = context.getBasePackageName(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 404 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 405 | mDisplayAdjustments = display.getDisplayAdjustments(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 406 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 407 | mThread = Thread.currentThread(); |
| 408 | mLocation = new WindowLeaked(null); |
| 409 | mLocation.fillInStackTrace(); |
| 410 | mWidth = -1; |
| 411 | mHeight = -1; |
| 412 | mDirty = new Rect(); |
| 413 | mTempRect = new Rect(); |
| 414 | mVisRect = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | mWinFrame = new Rect(); |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 416 | mWindow = new W(this); |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 417 | mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | mViewVisibility = View.GONE; |
| 419 | mTransparentRegion = new Region(); |
| 420 | mPreviousTransparentRegion = new Region(); |
| 421 | 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] | 422 | mAdded = false; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 423 | mAttachInfo = new View.AttachInfo(mWindowSession, mWindow, display, this, mHandler, this); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 424 | mAccessibilityManager = AccessibilityManager.getInstance(context); |
| 425 | mAccessibilityInteractionConnectionManager = |
| 426 | new AccessibilityInteractionConnectionManager(); |
Svetoslav Ganov | 00d0c14 | 2012-02-24 11:30:49 -0800 | [diff] [blame] | 427 | mAccessibilityManager.addAccessibilityStateChangeListener( |
| 428 | mAccessibilityInteractionConnectionManager); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 429 | mHighContrastTextManager = new HighContrastTextManager(); |
| 430 | mAccessibilityManager.addHighTextContrastStateChangeListener( |
| 431 | mHighContrastTextManager); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | mViewConfiguration = ViewConfiguration.get(context); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 433 | mDensity = context.getResources().getDisplayMetrics().densityDpi; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 434 | mNoncompatDensity = context.getResources().getDisplayMetrics().noncompatDensityDpi; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 435 | mFallbackEventHandler = new PhoneFallbackEventHandler(context); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 436 | mChoreographer = Choreographer.getInstance(); |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 437 | mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 438 | loadSystemProperties(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | } |
| 440 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 441 | public static void addFirstDrawHandler(Runnable callback) { |
| 442 | synchronized (sFirstDrawHandlers) { |
| 443 | if (!sFirstDrawComplete) { |
| 444 | sFirstDrawHandlers.add(callback); |
| 445 | } |
| 446 | } |
| 447 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 448 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 449 | public static void addConfigCallback(ComponentCallbacks callback) { |
| 450 | synchronized (sConfigCallbacks) { |
| 451 | sConfigCallbacks.add(callback); |
| 452 | } |
| 453 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 454 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 455 | public void addWindowCallbacks(WindowCallbacks callback) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 456 | if (USE_MT_RENDERER) { |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 457 | synchronized (mWindowCallbacks) { |
| 458 | mWindowCallbacks.add(callback); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 463 | public void removeWindowCallbacks(WindowCallbacks callback) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 464 | if (USE_MT_RENDERER) { |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 465 | synchronized (mWindowCallbacks) { |
| 466 | mWindowCallbacks.remove(callback); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | } |
| 470 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 471 | public void reportDrawFinish() { |
| 472 | if (mWindowDrawCountDown != null) { |
| 473 | mWindowDrawCountDown.countDown(); |
| 474 | } |
| 475 | } |
| 476 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | // FIXME for perf testing only |
| 478 | private boolean mProfile = false; |
| 479 | |
| 480 | /** |
| 481 | * Call this to profile the next traversal call. |
| 482 | * FIXME for perf testing only. Remove eventually |
| 483 | */ |
| 484 | public void profile() { |
| 485 | mProfile = true; |
| 486 | } |
| 487 | |
| 488 | /** |
| 489 | * Indicates whether we are in touch mode. Calling this method triggers an IPC |
| 490 | * call and should be avoided whenever possible. |
| 491 | * |
| 492 | * @return True, if the device is in touch mode, false otherwise. |
| 493 | * |
| 494 | * @hide |
| 495 | */ |
| 496 | static boolean isInTouchMode() { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 497 | IWindowSession windowSession = WindowManagerGlobal.peekWindowSession(); |
| 498 | if (windowSession != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 500 | return windowSession.getInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | } catch (RemoteException e) { |
| 502 | } |
| 503 | } |
| 504 | return false; |
| 505 | } |
| 506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | /** |
| 508 | * We have one child |
| 509 | */ |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 510 | 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] | 511 | synchronized (this) { |
| 512 | if (mView == null) { |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 513 | mView = view; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 514 | |
| 515 | mAttachInfo.mDisplayState = mDisplay.getState(); |
| 516 | mDisplayManager.registerDisplayListener(mDisplayListener, mHandler); |
| 517 | |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 518 | mViewLayoutDirectionInitial = mView.getRawLayoutDirection(); |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 519 | mFallbackEventHandler.setView(view); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 520 | mWindowAttributes.copyFrom(attrs); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 521 | if (mWindowAttributes.packageName == null) { |
| 522 | mWindowAttributes.packageName = mBasePackageName; |
| 523 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 524 | attrs = mWindowAttributes; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 525 | setTag(); |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 526 | // Keep track of the actual window flags supplied by the client. |
| 527 | mClientWindowLayoutFlags = attrs.flags; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 528 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 529 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 530 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 531 | if (view instanceof RootViewSurfaceTaker) { |
| 532 | mSurfaceHolderCallback = |
| 533 | ((RootViewSurfaceTaker)view).willYouTakeTheSurface(); |
| 534 | if (mSurfaceHolderCallback != null) { |
| 535 | mSurfaceHolder = new TakenSurfaceHolder(); |
Dianne Hackborn | 289b9b6 | 2010-07-09 11:44:11 -0700 | [diff] [blame] | 536 | mSurfaceHolder.setFormat(PixelFormat.UNKNOWN); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 537 | } |
| 538 | } |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 539 | |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 540 | // Compute surface insets required to draw at specified Z value. |
| 541 | // TODO: Use real shadow insets for a constant max Z. |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 542 | if (!attrs.hasManualSurfaceInsets) { |
| 543 | final int surfaceInset = (int) Math.ceil(view.getZ() * 2); |
| 544 | attrs.surfaceInsets.set(surfaceInset, surfaceInset, surfaceInset, surfaceInset); |
| 545 | } |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 546 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 547 | CompatibilityInfo compatibilityInfo = mDisplayAdjustments.getCompatibilityInfo(); |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 548 | mTranslator = compatibilityInfo.getTranslator(); |
| 549 | |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 550 | // If the application owns the surface, don't enable hardware acceleration |
| 551 | if (mSurfaceHolder == null) { |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 552 | enableHardwareAcceleration(attrs); |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 553 | } |
| 554 | |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 555 | boolean restore = false; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 556 | if (mTranslator != null) { |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 557 | mSurface.setCompatibilityTranslator(mTranslator); |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 558 | restore = true; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 559 | attrs.backup(); |
| 560 | mTranslator.translateWindowLayout(attrs); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 561 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 562 | if (DEBUG_LAYOUT) Log.d(mTag, "WindowLayout in setView:" + attrs); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 563 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 564 | if (!compatibilityInfo.supportsScreen()) { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 565 | attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 566 | mLastInCompatMode = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 567 | } |
| 568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | mSoftInputMode = attrs.softInputMode; |
| 570 | mWindowAttributesChanged = true; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 571 | mWindowAttributesChangesFlag = WindowManager.LayoutParams.EVERYTHING_CHANGED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | mAttachInfo.mRootView = view; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 573 | mAttachInfo.mScalingRequired = mTranslator != null; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 574 | mAttachInfo.mApplicationScale = |
| 575 | mTranslator == null ? 1.0f : mTranslator.applicationScale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 576 | if (panelParentView != null) { |
| 577 | mAttachInfo.mPanelParentWindowToken |
| 578 | = panelParentView.getApplicationWindowToken(); |
| 579 | } |
| 580 | mAdded = true; |
| 581 | int res; /* = WindowManagerImpl.ADD_OKAY; */ |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | // Schedule the first layout -before- adding to the window |
| 584 | // manager, to make sure we do the relayout before receiving |
| 585 | // any other events from the system. |
| 586 | requestLayout(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 587 | if ((mWindowAttributes.inputFeatures |
| 588 | & WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) { |
| 589 | mInputChannel = new InputChannel(); |
| 590 | } |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 591 | mForceDecorViewVisibility = (mWindowAttributes.privateFlags |
| 592 | & PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | try { |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 594 | mOrigWindowType = mWindowAttributes.type; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 595 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 596 | collectViewAttributes(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 597 | res = mWindowSession.addToDisplay(mWindow, mSeq, mWindowAttributes, |
| 598 | getHostVisibility(), mDisplay.getDisplayId(), |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 599 | mAttachInfo.mContentInsets, mAttachInfo.mStableInsets, |
| 600 | mAttachInfo.mOutsets, mInputChannel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | } catch (RemoteException e) { |
| 602 | mAdded = false; |
| 603 | mView = null; |
| 604 | mAttachInfo.mRootView = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 605 | mInputChannel = null; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 606 | mFallbackEventHandler.setView(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 607 | unscheduleTraversals(); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 608 | setAccessibilityFocus(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | throw new RuntimeException("Adding window failed", e); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 610 | } finally { |
| 611 | if (restore) { |
| 612 | attrs.restore(); |
| 613 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 615 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 616 | if (mTranslator != null) { |
| 617 | mTranslator.translateRectInScreenToAppWindow(mAttachInfo.mContentInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 618 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 619 | mPendingOverscanInsets.set(0, 0, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | mPendingContentInsets.set(mAttachInfo.mContentInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 621 | mPendingStableInsets.set(mAttachInfo.mStableInsets); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 622 | mPendingVisibleInsets.set(0, 0, 0, 0); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 623 | if (DEBUG_LAYOUT) Log.v(mTag, "Added window " + mWindow); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 624 | if (res < WindowManagerGlobal.ADD_OKAY) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | mAttachInfo.mRootView = null; |
| 626 | mAdded = false; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 627 | mFallbackEventHandler.setView(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | unscheduleTraversals(); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 629 | setAccessibilityFocus(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | switch (res) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 631 | case WindowManagerGlobal.ADD_BAD_APP_TOKEN: |
| 632 | case WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN: |
| 633 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 634 | "Unable to add window -- token " + attrs.token |
| 635 | + " is not valid; is your activity running?"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 636 | case WindowManagerGlobal.ADD_NOT_APP_TOKEN: |
| 637 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 638 | "Unable to add window -- token " + attrs.token |
| 639 | + " is not for an application"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 640 | case WindowManagerGlobal.ADD_APP_EXITING: |
| 641 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 642 | "Unable to add window -- app for token " + attrs.token |
| 643 | + " is exiting"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 644 | case WindowManagerGlobal.ADD_DUPLICATE_ADD: |
| 645 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 646 | "Unable to add window -- window " + mWindow |
| 647 | + " has already been added"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 648 | case WindowManagerGlobal.ADD_STARTING_NOT_NEEDED: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | // Silently ignore -- we would have just removed it |
| 650 | // right away, anyway. |
| 651 | return; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 652 | case WindowManagerGlobal.ADD_MULTIPLE_SINGLETON: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 653 | throw new WindowManager.BadTokenException("Unable to add window " |
| 654 | + mWindow + " -- another window of type " |
| 655 | + mWindowAttributes.type + " already exists"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 656 | case WindowManagerGlobal.ADD_PERMISSION_DENIED: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 657 | throw new WindowManager.BadTokenException("Unable to add window " |
| 658 | + mWindow + " -- permission denied for window type " |
| 659 | + mWindowAttributes.type); |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 660 | case WindowManagerGlobal.ADD_INVALID_DISPLAY: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 661 | throw new WindowManager.InvalidDisplayException("Unable to add window " |
| 662 | + mWindow + " -- the specified display can not be found"); |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 663 | case WindowManagerGlobal.ADD_INVALID_TYPE: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 664 | throw new WindowManager.InvalidDisplayException("Unable to add window " |
| 665 | + mWindow + " -- the specified window type " |
| 666 | + mWindowAttributes.type + " is not valid"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | } |
| 668 | throw new RuntimeException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 669 | "Unable to add window -- unknown error code " + res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 670 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 671 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 672 | if (view instanceof RootViewSurfaceTaker) { |
| 673 | mInputQueueCallback = |
| 674 | ((RootViewSurfaceTaker)view).willYouTakeTheInputQueue(); |
| 675 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 676 | if (mInputChannel != null) { |
| 677 | if (mInputQueueCallback != null) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 678 | mInputQueue = new InputQueue(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 679 | mInputQueueCallback.onInputQueueCreated(mInputQueue); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 680 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 681 | mInputEventReceiver = new WindowInputEventReceiver(mInputChannel, |
| 682 | Looper.myLooper()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 683 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | view.assignParent(this); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 686 | mAddedTouchMode = (res & WindowManagerGlobal.ADD_FLAG_IN_TOUCH_MODE) != 0; |
| 687 | mAppVisible = (res & WindowManagerGlobal.ADD_FLAG_APP_VISIBLE) != 0; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 688 | |
| 689 | if (mAccessibilityManager.isEnabled()) { |
| 690 | mAccessibilityInteractionConnectionManager.ensureConnection(); |
| 691 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 692 | |
| 693 | if (view.getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 694 | view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 695 | } |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 696 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 697 | // Set up the input pipeline. |
| 698 | CharSequence counterSuffix = attrs.getTitle(); |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 699 | mSyntheticInputStage = new SyntheticInputStage(); |
| 700 | InputStage viewPostImeStage = new ViewPostImeInputStage(mSyntheticInputStage); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 701 | InputStage nativePostImeStage = new NativePostImeInputStage(viewPostImeStage, |
| 702 | "aq:native-post-ime:" + counterSuffix); |
| 703 | InputStage earlyPostImeStage = new EarlyPostImeInputStage(nativePostImeStage); |
| 704 | InputStage imeStage = new ImeInputStage(earlyPostImeStage, |
| 705 | "aq:ime:" + counterSuffix); |
| 706 | InputStage viewPreImeStage = new ViewPreImeInputStage(imeStage); |
| 707 | InputStage nativePreImeStage = new NativePreImeInputStage(viewPreImeStage, |
| 708 | "aq:native-pre-ime:" + counterSuffix); |
| 709 | |
| 710 | mFirstInputStage = nativePreImeStage; |
| 711 | mFirstPostImeInputStage = earlyPostImeStage; |
| 712 | mPendingInputEventQueueLengthCounterName = "aq:pending:" + counterSuffix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | } |
| 714 | } |
| 715 | } |
| 716 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 717 | private void setTag() { |
| 718 | final String[] split = mWindowAttributes.getTitle().toString().split("\\."); |
| 719 | if (split.length > 0) { |
| 720 | mTag = TAG + "[" + split[split.length - 1] + "]"; |
| 721 | } |
| 722 | } |
| 723 | |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 724 | /** Whether the window is in local focus mode or not */ |
| 725 | private boolean isInLocalFocusMode() { |
| 726 | return (mWindowAttributes.flags & WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE) != 0; |
| 727 | } |
| 728 | |
Dianne Hackborn | 49b043f | 2015-05-07 14:21:38 -0700 | [diff] [blame] | 729 | public int getWindowFlags() { |
| 730 | return mWindowAttributes.flags; |
| 731 | } |
| 732 | |
Dianne Hackborn | ece0f4f | 2015-06-11 13:29:01 -0700 | [diff] [blame] | 733 | public int getDisplayId() { |
| 734 | return mDisplay.getDisplayId(); |
| 735 | } |
| 736 | |
Dianne Hackborn | a7bb6fb | 2015-02-03 18:13:40 -0800 | [diff] [blame] | 737 | public CharSequence getTitle() { |
| 738 | return mWindowAttributes.getTitle(); |
| 739 | } |
| 740 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 741 | void destroyHardwareResources() { |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 742 | if (mAttachInfo.mHardwareRenderer != null) { |
| 743 | mAttachInfo.mHardwareRenderer.destroyHardwareResources(mView); |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 744 | mAttachInfo.mHardwareRenderer.destroy(); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | |
Bo Liu | 845535a | 2014-03-21 12:06:23 -0700 | [diff] [blame] | 748 | public void detachFunctor(long functor) { |
John Reck | 44ac42a | 2014-05-16 14:46:07 -0700 | [diff] [blame] | 749 | if (mAttachInfo.mHardwareRenderer != null) { |
| 750 | // Fence so that any pending invokeFunctor() messages will be processed |
| 751 | // before we return from detachFunctor. |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 752 | mAttachInfo.mHardwareRenderer.stopDrawing(); |
John Reck | 44ac42a | 2014-05-16 14:46:07 -0700 | [diff] [blame] | 753 | } |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 754 | } |
| 755 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 756 | /** |
| 757 | * Schedules the functor for execution in either kModeProcess or |
| 758 | * kModeProcessNoContext, depending on whether or not there is an EGLContext. |
| 759 | * |
| 760 | * @param functor The native functor to invoke |
| 761 | * @param waitForCompletion If true, this will not return until the functor |
| 762 | * has invoked. If false, the functor may be invoked |
| 763 | * asynchronously. |
| 764 | */ |
Hui Shu | 9970aee | 2014-06-23 17:10:30 -0700 | [diff] [blame] | 765 | public void invokeFunctor(long functor, boolean waitForCompletion) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 766 | ThreadedRenderer.invokeFunctor(functor, waitForCompletion); |
Bo Liu | ae738a7 | 2014-04-27 16:22:04 -0700 | [diff] [blame] | 767 | } |
| 768 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 769 | public void registerAnimatingRenderNode(RenderNode animator) { |
| 770 | if (mAttachInfo.mHardwareRenderer != null) { |
| 771 | mAttachInfo.mHardwareRenderer.registerAnimatingRenderNode(animator); |
| 772 | } else { |
| 773 | if (mAttachInfo.mPendingAnimatingRenderNodes == null) { |
| 774 | mAttachInfo.mPendingAnimatingRenderNodes = new ArrayList<RenderNode>(); |
| 775 | } |
| 776 | mAttachInfo.mPendingAnimatingRenderNodes.add(animator); |
| 777 | } |
| 778 | } |
| 779 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 780 | private void enableHardwareAcceleration(WindowManager.LayoutParams attrs) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 781 | mAttachInfo.mHardwareAccelerated = false; |
| 782 | mAttachInfo.mHardwareAccelerationRequested = false; |
Romain Guy | 4f6aff3 | 2011-01-12 16:21:41 -0800 | [diff] [blame] | 783 | |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 784 | // Don't enable hardware acceleration when the application is in compatibility mode |
John Reck | dd58e79 | 2014-04-02 16:54:28 +0000 | [diff] [blame] | 785 | if (mTranslator != null) return; |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 786 | |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 787 | // Try to enable hardware acceleration if requested |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 788 | final boolean hardwareAccelerated = |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 789 | (attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 790 | |
John Reck | dd58e79 | 2014-04-02 16:54:28 +0000 | [diff] [blame] | 791 | if (hardwareAccelerated) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 792 | if (!ThreadedRenderer.isAvailable()) { |
Romain Guy | 1af23a3 | 2011-03-24 16:03:55 -0700 | [diff] [blame] | 793 | return; |
| 794 | } |
| 795 | |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 796 | // Persistent processes (including the system) should not do |
| 797 | // accelerated rendering on low-end devices. In that case, |
| 798 | // sRendererDisabled will be set. In addition, the system process |
| 799 | // itself should never do accelerated rendering. In that case, both |
| 800 | // sRendererDisabled and sSystemRendererDisabled are set. When |
| 801 | // sSystemRendererDisabled is set, PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED |
| 802 | // can be used by code on the system process to escape that and enable |
| 803 | // HW accelerated drawing. (This is basically for the lock screen.) |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 804 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 805 | final boolean fakeHwAccelerated = (attrs.privateFlags & |
| 806 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED) != 0; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 807 | final boolean forceHwAccelerated = (attrs.privateFlags & |
| 808 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED) != 0; |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 809 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 810 | if (fakeHwAccelerated) { |
| 811 | // This is exclusively for the preview windows the window manager |
| 812 | // shows for launching applications, so they will look more like |
| 813 | // the app being launched. |
| 814 | mAttachInfo.mHardwareAccelerationRequested = true; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 815 | } else if (!ThreadedRenderer.sRendererDisabled |
| 816 | || (ThreadedRenderer.sSystemRendererDisabled && forceHwAccelerated)) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 817 | if (mAttachInfo.mHardwareRenderer != null) { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 818 | mAttachInfo.mHardwareRenderer.destroy(); |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 819 | } |
| 820 | |
Alan Viverette | 2b12b58 | 2014-10-29 11:11:40 -0700 | [diff] [blame] | 821 | final Rect insets = attrs.surfaceInsets; |
Alan Viverette | 2cd23e6 | 2014-11-04 17:04:02 -0800 | [diff] [blame] | 822 | final boolean hasSurfaceInsets = insets.left != 0 || insets.right != 0 |
| 823 | || insets.top != 0 || insets.bottom != 0; |
Alan Viverette | 2b12b58 | 2014-10-29 11:11:40 -0700 | [diff] [blame] | 824 | final boolean translucent = attrs.format != PixelFormat.OPAQUE || hasSurfaceInsets; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 825 | mAttachInfo.mHardwareRenderer = ThreadedRenderer.create(mContext, translucent); |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 826 | if (mAttachInfo.mHardwareRenderer != null) { |
| 827 | mAttachInfo.mHardwareRenderer.setName(attrs.getTitle().toString()); |
| 828 | mAttachInfo.mHardwareAccelerated = |
| 829 | mAttachInfo.mHardwareAccelerationRequested = true; |
| 830 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 835 | public View getView() { |
| 836 | return mView; |
| 837 | } |
| 838 | |
| 839 | final WindowLeaked getLocation() { |
| 840 | return mLocation; |
| 841 | } |
| 842 | |
| 843 | void setLayoutParams(WindowManager.LayoutParams attrs, boolean newView) { |
| 844 | synchronized (this) { |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 845 | final int oldInsetLeft = mWindowAttributes.surfaceInsets.left; |
| 846 | final int oldInsetTop = mWindowAttributes.surfaceInsets.top; |
| 847 | final int oldInsetRight = mWindowAttributes.surfaceInsets.right; |
| 848 | final int oldInsetBottom = mWindowAttributes.surfaceInsets.bottom; |
| 849 | final int oldSoftInputMode = mWindowAttributes.softInputMode; |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 850 | final boolean oldHasManualSurfaceInsets = mWindowAttributes.hasManualSurfaceInsets; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 851 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 852 | // Keep track of the actual window flags supplied by the client. |
| 853 | mClientWindowLayoutFlags = attrs.flags; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 854 | |
| 855 | // Preserve compatible window flag if exists. |
| 856 | final int compatibleWindowFlag = mWindowAttributes.privateFlags |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 857 | & WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 858 | |
| 859 | // Transfer over system UI visibility values as they carry current state. |
Craig Mautner | 3fe38c0 | 2012-05-03 17:28:09 -0700 | [diff] [blame] | 860 | attrs.systemUiVisibility = mWindowAttributes.systemUiVisibility; |
| 861 | attrs.subtreeSystemUiVisibility = mWindowAttributes.subtreeSystemUiVisibility; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 862 | |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 863 | mWindowAttributesChangesFlag = mWindowAttributes.copyFrom(attrs); |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 864 | if ((mWindowAttributesChangesFlag |
| 865 | & WindowManager.LayoutParams.TRANSLUCENT_FLAGS_CHANGED) != 0) { |
| 866 | // Recompute system ui visibility. |
| 867 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 868 | } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 869 | if (mWindowAttributes.packageName == null) { |
| 870 | mWindowAttributes.packageName = mBasePackageName; |
| 871 | } |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 872 | mWindowAttributes.privateFlags |= compatibleWindowFlag; |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 873 | |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 874 | // Restore old surface insets. |
| 875 | mWindowAttributes.surfaceInsets.set( |
| 876 | oldInsetLeft, oldInsetTop, oldInsetRight, oldInsetBottom); |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 877 | mWindowAttributes.hasManualSurfaceInsets = oldHasManualSurfaceInsets; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 878 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 879 | applyKeepScreenOnFlag(mWindowAttributes); |
| 880 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 881 | if (newView) { |
| 882 | mSoftInputMode = attrs.softInputMode; |
| 883 | requestLayout(); |
| 884 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 885 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 886 | // Don't lose the mode we last auto-computed. |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 887 | if ((attrs.softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 888 | == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED) { |
| 889 | mWindowAttributes.softInputMode = (mWindowAttributes.softInputMode |
| 890 | & ~WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 891 | | (oldSoftInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 892 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 893 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | mWindowAttributesChanged = true; |
| 895 | scheduleTraversals(); |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | void handleAppVisibility(boolean visible) { |
| 900 | if (mAppVisible != visible) { |
| 901 | mAppVisible = visible; |
| 902 | scheduleTraversals(); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 903 | if (!mAppVisible) { |
| 904 | WindowManagerGlobal.trimForeground(); |
| 905 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | } |
| 907 | } |
| 908 | |
| 909 | void handleGetNewSurface() { |
| 910 | mNewSurfaceNeeded = true; |
| 911 | mFullRedrawNeeded = true; |
| 912 | scheduleTraversals(); |
| 913 | } |
| 914 | |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 915 | private final DisplayListener mDisplayListener = new DisplayListener() { |
| 916 | @Override |
| 917 | public void onDisplayChanged(int displayId) { |
| 918 | if (mView != null && mDisplay.getDisplayId() == displayId) { |
| 919 | final int oldDisplayState = mAttachInfo.mDisplayState; |
| 920 | final int newDisplayState = mDisplay.getState(); |
| 921 | if (oldDisplayState != newDisplayState) { |
| 922 | mAttachInfo.mDisplayState = newDisplayState; |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 923 | pokeDrawLockIfNeeded(); |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 924 | if (oldDisplayState != Display.STATE_UNKNOWN) { |
| 925 | final int oldScreenState = toViewScreenState(oldDisplayState); |
| 926 | final int newScreenState = toViewScreenState(newDisplayState); |
| 927 | if (oldScreenState != newScreenState) { |
| 928 | mView.dispatchScreenStateChanged(newScreenState); |
| 929 | } |
| 930 | if (oldDisplayState == Display.STATE_OFF) { |
| 931 | // Draw was suppressed so we need to for it to happen here. |
| 932 | mFullRedrawNeeded = true; |
| 933 | scheduleTraversals(); |
| 934 | } |
| 935 | } |
| 936 | } |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 937 | } |
| 938 | } |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 939 | |
| 940 | @Override |
| 941 | public void onDisplayRemoved(int displayId) { |
| 942 | } |
| 943 | |
| 944 | @Override |
| 945 | public void onDisplayAdded(int displayId) { |
| 946 | } |
| 947 | |
| 948 | private int toViewScreenState(int displayState) { |
| 949 | return displayState == Display.STATE_OFF ? |
| 950 | View.SCREEN_STATE_OFF : View.SCREEN_STATE_ON; |
| 951 | } |
| 952 | }; |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 953 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 954 | void pokeDrawLockIfNeeded() { |
| 955 | final int displayState = mAttachInfo.mDisplayState; |
| 956 | if (mView != null && mAdded && mTraversalScheduled |
| 957 | && (displayState == Display.STATE_DOZE |
| 958 | || displayState == Display.STATE_DOZE_SUSPEND)) { |
| 959 | try { |
| 960 | mWindowSession.pokeDrawLock(mWindow); |
| 961 | } catch (RemoteException ex) { |
| 962 | // System server died, oh well. |
| 963 | } |
| 964 | } |
| 965 | } |
| 966 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 967 | @Override |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 968 | public void requestFitSystemWindows() { |
| 969 | checkThread(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 970 | mApplyInsetsRequested = true; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 971 | scheduleTraversals(); |
| 972 | } |
| 973 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 974 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | public void requestLayout() { |
Chet Haase | 3efa7b5 | 2012-12-03 08:33:17 -0800 | [diff] [blame] | 976 | if (!mHandlingLayoutInLayoutRequest) { |
| 977 | checkThread(); |
| 978 | mLayoutRequested = true; |
| 979 | scheduleTraversals(); |
| 980 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | } |
| 982 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 983 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 984 | public boolean isLayoutRequested() { |
| 985 | return mLayoutRequested; |
| 986 | } |
| 987 | |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 988 | void invalidate() { |
| 989 | mDirty.set(0, 0, mWidth, mHeight); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 990 | if (!mWillDrawSoon) { |
| 991 | scheduleTraversals(); |
| 992 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 993 | } |
| 994 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 995 | void invalidateWorld(View view) { |
| 996 | view.invalidate(); |
| 997 | if (view instanceof ViewGroup) { |
Romain Guy | f84208f | 2012-09-13 22:50:18 -0700 | [diff] [blame] | 998 | ViewGroup parent = (ViewGroup) view; |
| 999 | for (int i = 0; i < parent.getChildCount(); i++) { |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 1000 | invalidateWorld(parent.getChildAt(i)); |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 1005 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | public void invalidateChild(View child, Rect dirty) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1007 | invalidateChildInParent(null, dirty); |
| 1008 | } |
| 1009 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1010 | @Override |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1011 | public ViewParent invalidateChildInParent(int[] location, Rect dirty) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | checkThread(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1013 | if (DEBUG_DRAW) Log.v(mTag, "Invalidate child: " + dirty); |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1014 | |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1015 | if (dirty == null) { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1016 | invalidate(); |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1017 | return null; |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1018 | } else if (dirty.isEmpty() && !mIsAnimating) { |
Chet Haase | 05e91ed | 2012-07-03 14:17:57 -0700 | [diff] [blame] | 1019 | return null; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1020 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1021 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1022 | if (mCurScrollY != 0 || mTranslator != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | mTempRect.set(dirty); |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1024 | dirty = mTempRect; |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1025 | if (mCurScrollY != 0) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1026 | dirty.offset(0, -mCurScrollY); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1027 | } |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1028 | if (mTranslator != null) { |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1029 | mTranslator.translateRectInAppWindowToScreen(dirty); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1030 | } |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1031 | if (mAttachInfo.mScalingRequired) { |
| 1032 | dirty.inset(-1, -1); |
| 1033 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1035 | |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 1036 | invalidateRectOnScreen(dirty); |
| 1037 | |
| 1038 | return null; |
| 1039 | } |
| 1040 | |
| 1041 | private void invalidateRectOnScreen(Rect dirty) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1042 | final Rect localDirty = mDirty; |
| 1043 | if (!localDirty.isEmpty() && !localDirty.contains(dirty)) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 1044 | mAttachInfo.mSetIgnoreDirtyState = true; |
Romain Guy | 7d69594 | 2010-12-01 17:22:29 -0800 | [diff] [blame] | 1045 | mAttachInfo.mIgnoreDirtyState = true; |
| 1046 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1047 | |
| 1048 | // Add the new dirty rect to the current one |
| 1049 | localDirty.union(dirty.left, dirty.top, dirty.right, dirty.bottom); |
| 1050 | // Intersect with the bounds of the window to skip |
| 1051 | // updates that lie outside of the visible region |
Romain Guy | 7b2f8b8 | 2012-03-19 17:18:54 -0700 | [diff] [blame] | 1052 | final float appScale = mAttachInfo.mApplicationScale; |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1053 | final boolean intersected = localDirty.intersect(0, 0, |
| 1054 | (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f)); |
| 1055 | if (!intersected) { |
Chet Haase | b78ee0e | 2012-10-17 11:32:01 -0700 | [diff] [blame] | 1056 | localDirty.setEmpty(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1057 | } |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1058 | if (!mWillDrawSoon && (intersected || mIsAnimating)) { |
| 1059 | scheduleTraversals(); |
| 1060 | } |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 1061 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1062 | |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 1063 | public void setIsAmbientMode(boolean ambient) { |
| 1064 | mIsAmbientMode = ambient; |
| 1065 | } |
| 1066 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1067 | void setWindowStopped(boolean stopped) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1068 | if (mStopped != stopped) { |
| 1069 | mStopped = stopped; |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1070 | if (!mStopped) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1071 | scheduleTraversals(); |
| 1072 | } |
| 1073 | } |
| 1074 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1076 | /** |
| 1077 | * Block the input events during an Activity Transition. The KEYCODE_BACK event is allowed |
| 1078 | * through to allow quick reversal of the Activity Transition. |
| 1079 | * |
| 1080 | * @param paused true to pause, false to resume. |
| 1081 | */ |
| 1082 | public void setPausedForTransition(boolean paused) { |
| 1083 | mPausedForTransition = paused; |
| 1084 | } |
| 1085 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1086 | @Override |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1087 | public ViewParent getParent() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1088 | return null; |
| 1089 | } |
| 1090 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1091 | @Override |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1092 | 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] | 1093 | if (child != mView) { |
| 1094 | throw new RuntimeException("child is not mine, honest!"); |
| 1095 | } |
| 1096 | // Note: don't apply scroll offset, because we want to know its |
| 1097 | // visibility in the virtual canvas being given to the view hierarchy. |
| 1098 | return r.intersect(0, 0, mWidth, mHeight); |
| 1099 | } |
| 1100 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1101 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | public void bringChildToFront(View child) { |
| 1103 | } |
| 1104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | int getHostVisibility() { |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 1106 | return (mAppVisible || mForceDecorViewVisibility) ? mView.getVisibility() : View.GONE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1108 | |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 1109 | /** |
| 1110 | * Add LayoutTransition to the list of transitions to be started in the next traversal. |
| 1111 | * This list will be cleared after the transitions on the list are start()'ed. These |
| 1112 | * transitionsa re added by LayoutTransition itself when it sets up animations. The setup |
| 1113 | * happens during the layout phase of traversal, which we want to complete before any of the |
| 1114 | * animations are started (because those animations may side-effect properties that layout |
| 1115 | * depends upon, like the bounding rectangles of the affected views). So we add the transition |
| 1116 | * to the list and it is started just prior to starting the drawing phase of traversal. |
| 1117 | * |
| 1118 | * @param transition The LayoutTransition to be started on the next traversal. |
| 1119 | * |
| 1120 | * @hide |
| 1121 | */ |
| 1122 | public void requestTransitionStart(LayoutTransition transition) { |
| 1123 | if (mPendingTransitions == null || !mPendingTransitions.contains(transition)) { |
| 1124 | if (mPendingTransitions == null) { |
| 1125 | mPendingTransitions = new ArrayList<LayoutTransition>(); |
| 1126 | } |
| 1127 | mPendingTransitions.add(transition); |
| 1128 | } |
| 1129 | } |
| 1130 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1131 | /** |
| 1132 | * Notifies the HardwareRenderer that a new frame will be coming soon. |
| 1133 | * Currently only {@link ThreadedRenderer} cares about this, and uses |
| 1134 | * this knowledge to adjust the scheduling of off-thread animations |
| 1135 | */ |
| 1136 | void notifyRendererOfFramePending() { |
| 1137 | if (mAttachInfo.mHardwareRenderer != null) { |
| 1138 | mAttachInfo.mHardwareRenderer.notifyFramePending(); |
| 1139 | } |
| 1140 | } |
| 1141 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1142 | void scheduleTraversals() { |
| 1143 | if (!mTraversalScheduled) { |
| 1144 | mTraversalScheduled = true; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1145 | mTraversalBarrier = mHandler.getLooper().getQueue().postSyncBarrier(); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1146 | mChoreographer.postCallback( |
| 1147 | Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 1148 | if (!mUnbufferedInputDispatch) { |
| 1149 | scheduleConsumeBatchedInput(); |
| 1150 | } |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1151 | notifyRendererOfFramePending(); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 1152 | pokeDrawLockIfNeeded(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1153 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1154 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1155 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1156 | void unscheduleTraversals() { |
| 1157 | if (mTraversalScheduled) { |
| 1158 | mTraversalScheduled = false; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1159 | mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1160 | mChoreographer.removeCallbacks( |
| 1161 | Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | void doTraversal() { |
| 1166 | if (mTraversalScheduled) { |
| 1167 | mTraversalScheduled = false; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1168 | mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1169 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1170 | if (mProfile) { |
| 1171 | Debug.startMethodTracing("ViewAncestor"); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1172 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1173 | |
Chris Craik | e22c59b | 2015-05-21 18:33:37 -0700 | [diff] [blame] | 1174 | performTraversals(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1175 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1176 | if (mProfile) { |
| 1177 | Debug.stopMethodTracing(); |
| 1178 | mProfile = false; |
| 1179 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1180 | } |
| 1181 | } |
| 1182 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1183 | private void applyKeepScreenOnFlag(WindowManager.LayoutParams params) { |
| 1184 | // Update window's global keep screen on flag: if a view has requested |
| 1185 | // that the screen be kept on, then it is always set; otherwise, it is |
| 1186 | // set to whatever the client last requested for the global state. |
| 1187 | if (mAttachInfo.mKeepScreenOn) { |
| 1188 | params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
| 1189 | } else { |
| 1190 | params.flags = (params.flags&~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) |
| 1191 | | (mClientWindowLayoutFlags&WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
| 1192 | } |
| 1193 | } |
| 1194 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1195 | private boolean collectViewAttributes() { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1196 | if (mAttachInfo.mRecomputeGlobalAttributes) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1197 | //Log.i(mTag, "Computing view hierarchy attributes!"); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1198 | mAttachInfo.mRecomputeGlobalAttributes = false; |
| 1199 | boolean oldScreenOn = mAttachInfo.mKeepScreenOn; |
| 1200 | mAttachInfo.mKeepScreenOn = false; |
| 1201 | mAttachInfo.mSystemUiVisibility = 0; |
| 1202 | mAttachInfo.mHasSystemUiListeners = false; |
| 1203 | mView.dispatchCollectViewAttributes(mAttachInfo, 0); |
| 1204 | mAttachInfo.mSystemUiVisibility &= ~mAttachInfo.mDisabledSystemUiVisibility; |
Craig Mautner | 7eac0f5 | 2012-09-13 13:14:14 -0700 | [diff] [blame] | 1205 | WindowManager.LayoutParams params = mWindowAttributes; |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1206 | mAttachInfo.mSystemUiVisibility |= getImpliedSystemUiVisibility(params); |
| 1207 | if (mAttachInfo.mKeepScreenOn != oldScreenOn |
| 1208 | || mAttachInfo.mSystemUiVisibility != params.subtreeSystemUiVisibility |
| 1209 | || mAttachInfo.mHasSystemUiListeners != params.hasSystemUiListeners) { |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1210 | applyKeepScreenOnFlag(params); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1211 | params.subtreeSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
| 1212 | params.hasSystemUiListeners = mAttachInfo.mHasSystemUiListeners; |
| 1213 | mView.dispatchWindowSystemUiVisiblityChanged(mAttachInfo.mSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1214 | return true; |
| 1215 | } |
| 1216 | } |
| 1217 | return false; |
| 1218 | } |
| 1219 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 1220 | private int getImpliedSystemUiVisibility(WindowManager.LayoutParams params) { |
| 1221 | int vis = 0; |
| 1222 | // Translucent decor window flags imply stable system ui visibility. |
| 1223 | if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) != 0) { |
| 1224 | vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 1225 | } |
| 1226 | if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) != 0) { |
| 1227 | vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1228 | } |
| 1229 | return vis; |
| 1230 | } |
| 1231 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1232 | private boolean measureHierarchy(final View host, final WindowManager.LayoutParams lp, |
| 1233 | final Resources res, final int desiredWindowWidth, final int desiredWindowHeight) { |
| 1234 | int childWidthMeasureSpec; |
| 1235 | int childHeightMeasureSpec; |
| 1236 | boolean windowSizeMayChange = false; |
| 1237 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1238 | if (DEBUG_ORIENTATION || DEBUG_LAYOUT) Log.v(mTag, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1239 | "Measuring " + host + " in display " + desiredWindowWidth |
| 1240 | + "x" + desiredWindowHeight + "..."); |
| 1241 | |
| 1242 | boolean goodMeasure = false; |
| 1243 | if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) { |
| 1244 | // On large screens, we don't want to allow dialogs to just |
| 1245 | // stretch to fill the entire width of the screen to display |
| 1246 | // one line of text. First try doing the layout at a smaller |
| 1247 | // size to see if it will fit. |
| 1248 | final DisplayMetrics packageMetrics = res.getDisplayMetrics(); |
| 1249 | res.getValue(com.android.internal.R.dimen.config_prefDialogWidth, mTmpValue, true); |
| 1250 | int baseSize = 0; |
| 1251 | if (mTmpValue.type == TypedValue.TYPE_DIMENSION) { |
| 1252 | baseSize = (int)mTmpValue.getDimension(packageMetrics); |
| 1253 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1254 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": baseSize=" + baseSize); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1255 | if (baseSize != 0 && desiredWindowWidth > baseSize) { |
| 1256 | childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width); |
| 1257 | childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1258 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1259 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured (" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1260 | + host.getMeasuredWidth() + "," + host.getMeasuredHeight() + ")"); |
| 1261 | if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) { |
| 1262 | goodMeasure = true; |
| 1263 | } else { |
| 1264 | // Didn't fit in that size... try expanding a bit. |
| 1265 | baseSize = (baseSize+desiredWindowWidth)/2; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1266 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": next baseSize=" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1267 | + baseSize); |
| 1268 | childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1269 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1270 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured (" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1271 | + host.getMeasuredWidth() + "," + host.getMeasuredHeight() + ")"); |
| 1272 | if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1273 | if (DEBUG_DIALOG) Log.v(mTag, "Good!"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1274 | goodMeasure = true; |
| 1275 | } |
| 1276 | } |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | if (!goodMeasure) { |
| 1281 | childWidthMeasureSpec = getRootMeasureSpec(desiredWindowWidth, lp.width); |
| 1282 | childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1283 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1284 | if (mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) { |
| 1285 | windowSizeMayChange = true; |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | if (DBG) { |
| 1290 | System.out.println("======================================"); |
| 1291 | System.out.println("performTraversals -- after measure"); |
| 1292 | host.debug(); |
| 1293 | } |
| 1294 | |
| 1295 | return windowSizeMayChange; |
| 1296 | } |
| 1297 | |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1298 | /** |
| 1299 | * Modifies the input matrix such that it maps view-local coordinates to |
| 1300 | * on-screen coordinates. |
| 1301 | * |
| 1302 | * @param m input matrix to modify |
| 1303 | */ |
| 1304 | void transformMatrixToGlobal(Matrix m) { |
Dake Gu | 7bf379c | 2014-07-15 16:29:38 -0700 | [diff] [blame] | 1305 | m.preTranslate(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | /** |
| 1309 | * Modifies the input matrix such that it maps on-screen coordinates to |
| 1310 | * view-local coordinates. |
| 1311 | * |
| 1312 | * @param m input matrix to modify |
| 1313 | */ |
| 1314 | void transformMatrixToLocal(Matrix m) { |
Dake Gu | 7bf379c | 2014-07-15 16:29:38 -0700 | [diff] [blame] | 1315 | m.postTranslate(-mAttachInfo.mWindowLeft, -mAttachInfo.mWindowTop); |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1316 | } |
| 1317 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1318 | /* package */ WindowInsets getWindowInsets(boolean forceConstruct) { |
| 1319 | if (mLastWindowInsets == null || forceConstruct) { |
| 1320 | mDispatchContentInsets.set(mAttachInfo.mContentInsets); |
| 1321 | mDispatchStableInsets.set(mAttachInfo.mStableInsets); |
| 1322 | Rect contentInsets = mDispatchContentInsets; |
| 1323 | Rect stableInsets = mDispatchStableInsets; |
| 1324 | // For dispatch we preserve old logic, but for direct requests from Views we allow to |
| 1325 | // immediately use pending insets. |
| 1326 | if (!forceConstruct |
| 1327 | && (!mPendingContentInsets.equals(contentInsets) || |
| 1328 | !mPendingStableInsets.equals(stableInsets))) { |
| 1329 | contentInsets = mPendingContentInsets; |
| 1330 | stableInsets = mPendingStableInsets; |
| 1331 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1332 | Rect outsets = mAttachInfo.mOutsets; |
| 1333 | if (outsets.left > 0 || outsets.top > 0 || outsets.right > 0 || outsets.bottom > 0) { |
| 1334 | contentInsets = new Rect(contentInsets.left + outsets.left, |
| 1335 | contentInsets.top + outsets.top, contentInsets.right + outsets.right, |
| 1336 | contentInsets.bottom + outsets.bottom); |
| 1337 | } |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1338 | mLastWindowInsets = new WindowInsets(contentInsets, |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1339 | null /* windowDecorInsets */, stableInsets, |
| 1340 | mContext.getResources().getConfiguration().isScreenRound()); |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1341 | } |
| 1342 | return mLastWindowInsets; |
| 1343 | } |
| 1344 | |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1345 | void dispatchApplyInsets(View host) { |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1346 | host.dispatchApplyWindowInsets(getWindowInsets(true /* forceConstruct */)); |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1349 | private static boolean shouldUseDisplaySize(final WindowManager.LayoutParams lp) { |
| 1350 | return lp.type == TYPE_STATUS_BAR_PANEL |
| 1351 | || lp.type == TYPE_INPUT_METHOD |
| 1352 | || lp.type == TYPE_VOLUME_OVERLAY; |
| 1353 | } |
| 1354 | |
| 1355 | private int dipToPx(int dip) { |
| 1356 | final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics(); |
| 1357 | return (int) (displayMetrics.density * dip + 0.5f); |
| 1358 | } |
| 1359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1360 | private void performTraversals() { |
| 1361 | // cache mView since it is used so much below... |
| 1362 | final View host = mView; |
| 1363 | |
| 1364 | if (DBG) { |
| 1365 | System.out.println("======================================"); |
| 1366 | System.out.println("performTraversals"); |
| 1367 | host.debug(); |
| 1368 | } |
| 1369 | |
| 1370 | if (host == null || !mAdded) |
| 1371 | return; |
| 1372 | |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 1373 | mIsInTraversal = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1374 | mWillDrawSoon = true; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1375 | boolean windowSizeMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1376 | boolean newSurface = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1377 | boolean surfaceChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1378 | WindowManager.LayoutParams lp = mWindowAttributes; |
| 1379 | |
| 1380 | int desiredWindowWidth; |
| 1381 | int desiredWindowHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1383 | final int viewVisibility = getHostVisibility(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1384 | final boolean viewVisibilityChanged = !mFirst |
| 1385 | && (mViewVisibility != viewVisibility || mNewSurfaceNeeded); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | |
| 1387 | WindowManager.LayoutParams params = null; |
| 1388 | if (mWindowAttributesChanged) { |
| 1389 | mWindowAttributesChanged = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1390 | surfaceChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1391 | params = lp; |
| 1392 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1393 | CompatibilityInfo compatibilityInfo = mDisplayAdjustments.getCompatibilityInfo(); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1394 | if (compatibilityInfo.supportsScreen() == mLastInCompatMode) { |
| 1395 | params = lp; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1396 | mFullRedrawNeeded = true; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1397 | mLayoutRequested = true; |
| 1398 | if (mLastInCompatMode) { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1399 | params.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1400 | mLastInCompatMode = false; |
| 1401 | } else { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1402 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1403 | mLastInCompatMode = true; |
| 1404 | } |
| 1405 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1406 | |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 1407 | mWindowAttributesChangesFlag = 0; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1408 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1409 | Rect frame = mWinFrame; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1410 | if (mFirst) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1411 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1412 | mLayoutRequested = true; |
| 1413 | |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1414 | if (shouldUseDisplaySize(lp)) { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1415 | // NOTE -- system code, won't try to do compat mode. |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1416 | Point size = new Point(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1417 | mDisplay.getRealSize(size); |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1418 | desiredWindowWidth = size.x; |
| 1419 | desiredWindowHeight = size.y; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1420 | } else { |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1421 | Configuration config = mContext.getResources().getConfiguration(); |
| 1422 | desiredWindowWidth = dipToPx(config.screenWidthDp); |
| 1423 | desiredWindowHeight = dipToPx(config.screenHeightDp); |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1424 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | |
Romain Guy | c5d5586 | 2011-01-21 19:01:46 -0800 | [diff] [blame] | 1426 | // We used to use the following condition to choose 32 bits drawing caches: |
| 1427 | // PixelFormat.hasAlpha(lp.format) || lp.format == PixelFormat.RGBX_8888 |
| 1428 | // 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] | 1429 | mAttachInfo.mUse32BitDrawingCache = true; |
| 1430 | mAttachInfo.mHasWindowFocus = false; |
| 1431 | mAttachInfo.mWindowVisibility = viewVisibility; |
| 1432 | mAttachInfo.mRecomputeGlobalAttributes = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1433 | mLastConfiguration.setTo(host.getResources().getConfiguration()); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1434 | mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 1435 | // Set the layout direction if it has not been set before (inherit is the default) |
| 1436 | if (mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) { |
| 1437 | host.setLayoutDirection(mLastConfiguration.getLayoutDirection()); |
| 1438 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1439 | host.dispatchAttachedToWindow(mAttachInfo, 0); |
| 1440 | mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(true); |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1441 | dispatchApplyInsets(host); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1442 | //Log.i(mTag, "Screen on initialized: " + attachInfo.mKeepScreenOn); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | } else { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1445 | desiredWindowWidth = frame.width(); |
| 1446 | desiredWindowHeight = frame.height(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1447 | if (desiredWindowWidth != mWidth || desiredWindowHeight != mHeight) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1448 | if (DEBUG_ORIENTATION) Log.v(mTag, "View " + host + " resized to: " + frame); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1449 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1450 | mLayoutRequested = true; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1451 | windowSizeMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | if (viewVisibilityChanged) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1456 | mAttachInfo.mWindowVisibility = viewVisibility; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1457 | host.dispatchWindowVisibilityChanged(viewVisibility); |
| 1458 | if (viewVisibility != View.VISIBLE || mNewSurfaceNeeded) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1459 | endDragResizing(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1460 | destroyHardwareResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1461 | } |
| 1462 | if (viewVisibility == View.GONE) { |
| 1463 | // After making a window gone, we will count it as being |
| 1464 | // shown for the first time the next time it gets focus. |
| 1465 | mHasHadWindowFocus = false; |
| 1466 | } |
| 1467 | } |
| 1468 | |
Alan Viverette | 7dbc3bf | 2015-01-28 16:14:36 -0800 | [diff] [blame] | 1469 | // Non-visible windows can't hold accessibility focus. |
| 1470 | if (mAttachInfo.mWindowVisibility != View.VISIBLE) { |
| 1471 | host.clearAccessibilityFocus(); |
| 1472 | } |
| 1473 | |
Chet Haase | b78c284 | 2012-04-19 13:39:50 -0700 | [diff] [blame] | 1474 | // 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] | 1475 | getRunQueue().executeActions(mAttachInfo.mHandler); |
Chet Haase | b78c284 | 2012-04-19 13:39:50 -0700 | [diff] [blame] | 1476 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1477 | boolean insetsChanged = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1478 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1479 | boolean layoutRequested = mLayoutRequested && (!mStopped || mReportNextDraw); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1480 | if (layoutRequested) { |
Romain Guy | 15df670 | 2009-08-17 20:17:30 -0700 | [diff] [blame] | 1481 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1482 | final Resources res = mView.getContext().getResources(); |
| 1483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1484 | if (mFirst) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1485 | // make sure touch mode code executes by setting cached value |
| 1486 | // to opposite of the added touch mode. |
| 1487 | mAttachInfo.mInTouchMode = !mAddedTouchMode; |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 1488 | ensureTouchModeLocally(mAddedTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1489 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1490 | if (!mPendingOverscanInsets.equals(mAttachInfo.mOverscanInsets)) { |
| 1491 | insetsChanged = true; |
| 1492 | } |
Dianne Hackborn | fa6b35b | 2011-08-24 17:03:54 -0700 | [diff] [blame] | 1493 | if (!mPendingContentInsets.equals(mAttachInfo.mContentInsets)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | insetsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1496 | if (!mPendingStableInsets.equals(mAttachInfo.mStableInsets)) { |
| 1497 | insetsChanged = true; |
| 1498 | } |
Dianne Hackborn | fa6b35b | 2011-08-24 17:03:54 -0700 | [diff] [blame] | 1499 | if (!mPendingVisibleInsets.equals(mAttachInfo.mVisibleInsets)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1501 | 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] | 1502 | + mAttachInfo.mVisibleInsets); |
| 1503 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1504 | if (!mPendingOutsets.equals(mAttachInfo.mOutsets)) { |
| 1505 | insetsChanged = true; |
| 1506 | } |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1507 | if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT |
| 1508 | || lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) { |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1509 | windowSizeMayChange = true; |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1510 | |
| 1511 | if (shouldUseDisplaySize(lp)) { |
| 1512 | // NOTE -- system code, won't try to do compat mode. |
| 1513 | Point size = new Point(); |
| 1514 | mDisplay.getRealSize(size); |
| 1515 | desiredWindowWidth = size.x; |
| 1516 | desiredWindowHeight = size.y; |
| 1517 | } else { |
| 1518 | Configuration config = res.getConfiguration(); |
| 1519 | desiredWindowWidth = dipToPx(config.screenWidthDp); |
| 1520 | desiredWindowHeight = dipToPx(config.screenHeightDp); |
| 1521 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | } |
| 1523 | } |
| 1524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1525 | // Ask host how big it wants to be |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1526 | windowSizeMayChange |= measureHierarchy(host, lp, res, |
| 1527 | desiredWindowWidth, desiredWindowHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | } |
| 1529 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1530 | if (collectViewAttributes()) { |
| 1531 | params = lp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1532 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1533 | if (mAttachInfo.mForceReportNewAttributes) { |
| 1534 | mAttachInfo.mForceReportNewAttributes = false; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1535 | params = lp; |
| 1536 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1537 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1538 | if (mFirst || mAttachInfo.mViewVisibilityChanged) { |
| 1539 | mAttachInfo.mViewVisibilityChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1540 | int resizeMode = mSoftInputMode & |
| 1541 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 1542 | // If we are in auto resize mode, then we need to determine |
| 1543 | // what mode to use now. |
| 1544 | if (resizeMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1545 | final int N = mAttachInfo.mScrollContainers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1546 | for (int i=0; i<N; i++) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1547 | if (mAttachInfo.mScrollContainers.get(i).isShown()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1548 | resizeMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 1549 | } |
| 1550 | } |
| 1551 | if (resizeMode == 0) { |
| 1552 | resizeMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN; |
| 1553 | } |
| 1554 | if ((lp.softInputMode & |
| 1555 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) != resizeMode) { |
| 1556 | lp.softInputMode = (lp.softInputMode & |
| 1557 | ~WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) | |
| 1558 | resizeMode; |
| 1559 | params = lp; |
| 1560 | } |
| 1561 | } |
| 1562 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1563 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1564 | if (params != null) { |
| 1565 | if ((host.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
| 1566 | if (!PixelFormat.formatHasAlpha(params.format)) { |
| 1567 | params.format = PixelFormat.TRANSLUCENT; |
| 1568 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1569 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1570 | mAttachInfo.mOverscanRequested = (params.flags |
| 1571 | & WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1572 | } |
| 1573 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1574 | if (mApplyInsetsRequested) { |
| 1575 | mApplyInsetsRequested = false; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1576 | mLastOverscanRequested = mAttachInfo.mOverscanRequested; |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1577 | dispatchApplyInsets(host); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1578 | if (mLayoutRequested) { |
| 1579 | // Short-circuit catching a new layout request here, so |
| 1580 | // we don't need to go through two layout passes when things |
| 1581 | // change due to fitting system windows, which can happen a lot. |
| 1582 | windowSizeMayChange |= measureHierarchy(host, lp, |
| 1583 | mView.getContext().getResources(), |
| 1584 | desiredWindowWidth, desiredWindowHeight); |
| 1585 | } |
| 1586 | } |
| 1587 | |
| 1588 | if (layoutRequested) { |
| 1589 | // Clear this now, so that if anything requests a layout in the |
| 1590 | // rest of this function we will catch it and re-run a full |
| 1591 | // layout pass. |
| 1592 | mLayoutRequested = false; |
| 1593 | } |
| 1594 | |
| 1595 | boolean windowShouldResize = layoutRequested && windowSizeMayChange |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1596 | && ((mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) |
Romain Guy | 2e4f426 | 2010-04-06 11:07:52 -0700 | [diff] [blame] | 1597 | || (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT && |
| 1598 | frame.width() < desiredWindowWidth && frame.width() != mWidth) |
| 1599 | || (lp.height == ViewGroup.LayoutParams.WRAP_CONTENT && |
| 1600 | frame.height() < desiredWindowHeight && frame.height() != mHeight)); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1601 | windowShouldResize |= mDragResizing && mResizeMode == RESIZE_MODE_FREEFORM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1602 | |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 1603 | // If the backdrop frame doesn't equal to a frame, we are starting a resize operation, so |
| 1604 | // force it to be resized. |
| 1605 | windowShouldResize |= !mPendingBackDropFrame.equals(mWinFrame); |
| 1606 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1607 | // If the activity was just relaunched, it might have unfrozen the task bounds (while |
| 1608 | // relaunching), so we need to force a call into window manager to pick up the latest |
| 1609 | // bounds. |
| 1610 | windowShouldResize |= mActivityRelaunched; |
| 1611 | |
Jeff Brown | 2e05ec3 | 2013-09-30 15:57:43 -0700 | [diff] [blame] | 1612 | // Determine whether to compute insets. |
| 1613 | // If there are no inset listeners remaining then we may still need to compute |
| 1614 | // 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] | 1615 | final boolean computesInternalInsets = |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1616 | mAttachInfo.mTreeObserver.hasComputeInternalInsetsListeners() |
| 1617 | || mAttachInfo.mHasNonEmptyGivenInternalInsets; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1618 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1619 | boolean insetsPending = false; |
| 1620 | int relayoutResult = 0; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1621 | |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 1622 | final boolean isViewVisible = viewVisibility == View.VISIBLE; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1623 | if (mFirst || windowShouldResize || insetsChanged || |
| 1624 | viewVisibilityChanged || params != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1625 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 1626 | if (isViewVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1627 | // If this window is giving internal insets to the window |
| 1628 | // manager, and it is being added or changing its visibility, |
| 1629 | // then we want to first give the window manager "fake" |
| 1630 | // insets to cause it to effectively ignore the content of |
| 1631 | // the window during layout. This avoids it briefly causing |
| 1632 | // other windows to resize/move based on the raw frame of the |
| 1633 | // window, waiting until we can finish laying out this window |
| 1634 | // and get back to the window manager with the ultimately |
| 1635 | // computed insets. |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1636 | insetsPending = computesInternalInsets && (mFirst || viewVisibilityChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1637 | } |
| 1638 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1639 | if (mSurfaceHolder != null) { |
| 1640 | mSurfaceHolder.mSurfaceLock.lock(); |
| 1641 | mDrawingAllowed = true; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1642 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1643 | |
Romain Guy | c361da8 | 2010-10-25 15:29:10 -0700 | [diff] [blame] | 1644 | boolean hwInitialized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1645 | boolean contentInsetsChanged = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1646 | boolean hadSurface = mSurface.isValid(); |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1647 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1648 | try { |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1649 | if (DEBUG_LAYOUT) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1650 | Log.i(mTag, "host=w:" + host.getMeasuredWidth() + ", h:" + |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1651 | host.getMeasuredHeight() + ", params=" + params); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1652 | } |
Romain Guy | 2a83f00 | 2011-01-18 18:28:21 -0800 | [diff] [blame] | 1653 | |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 1654 | if (mAttachInfo.mHardwareRenderer != null) { |
| 1655 | // relayoutWindow may decide to destroy mSurface. As that decision |
| 1656 | // happens in WindowManager service, we need to be defensive here |
| 1657 | // and stop using the surface in case it gets destroyed. |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 1658 | if (mAttachInfo.mHardwareRenderer.pauseSurface(mSurface)) { |
| 1659 | // Animations were running so we need to push a frame |
| 1660 | // to resume them |
| 1661 | mDirty.set(0, 0, mWidth, mHeight); |
| 1662 | } |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 1663 | mChoreographer.mFrameInfo.addFlags(FrameInfo.FLAG_WINDOW_LAYOUT_CHANGED); |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 1664 | } |
Romain Guy | 2a83f00 | 2011-01-18 18:28:21 -0800 | [diff] [blame] | 1665 | final int surfaceGenerationId = mSurface.getGenerationId(); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1666 | relayoutResult = relayoutWindow(params, viewVisibility, insetsPending); |
| 1667 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1668 | if (DEBUG_LAYOUT) Log.v(mTag, "relayout: frame=" + frame.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1669 | + " overscan=" + mPendingOverscanInsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1670 | + " content=" + mPendingContentInsets.toShortString() |
| 1671 | + " visible=" + mPendingVisibleInsets.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1672 | + " visible=" + mPendingStableInsets.toShortString() |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 1673 | + " outsets=" + mPendingOutsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1674 | + " surface=" + mSurface); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1675 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1676 | if (mPendingConfiguration.seq != 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1677 | if (DEBUG_CONFIGURATION) Log.v(mTag, "Visible with new config: " |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1678 | + mPendingConfiguration); |
riddle_hsu | 164725c | 2015-11-12 14:07:12 +0800 | [diff] [blame] | 1679 | updateConfiguration(new Configuration(mPendingConfiguration), !mFirst); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1680 | mPendingConfiguration.seq = 0; |
| 1681 | } |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 1682 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1683 | final boolean overscanInsetsChanged = !mPendingOverscanInsets.equals( |
| 1684 | mAttachInfo.mOverscanInsets); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1685 | contentInsetsChanged = !mPendingContentInsets.equals( |
| 1686 | mAttachInfo.mContentInsets); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1687 | final boolean visibleInsetsChanged = !mPendingVisibleInsets.equals( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1688 | mAttachInfo.mVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1689 | final boolean stableInsetsChanged = !mPendingStableInsets.equals( |
| 1690 | mAttachInfo.mStableInsets); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1691 | final boolean outsetsChanged = !mPendingOutsets.equals(mAttachInfo.mOutsets); |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1692 | final boolean surfaceSizeChanged = (relayoutResult |
| 1693 | & WindowManagerGlobal.RELAYOUT_RES_SURFACE_RESIZED) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1694 | if (contentInsetsChanged) { |
| 1695 | mAttachInfo.mContentInsets.set(mPendingContentInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1696 | 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] | 1697 | + mAttachInfo.mContentInsets); |
| 1698 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1699 | if (overscanInsetsChanged) { |
| 1700 | mAttachInfo.mOverscanInsets.set(mPendingOverscanInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1701 | if (DEBUG_LAYOUT) Log.v(mTag, "Overscan insets changing to: " |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1702 | + mAttachInfo.mOverscanInsets); |
| 1703 | // Need to relayout with content insets. |
| 1704 | contentInsetsChanged = true; |
| 1705 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1706 | if (stableInsetsChanged) { |
| 1707 | mAttachInfo.mStableInsets.set(mPendingStableInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1708 | if (DEBUG_LAYOUT) Log.v(mTag, "Decor insets changing to: " |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1709 | + mAttachInfo.mStableInsets); |
| 1710 | // Need to relayout with content insets. |
| 1711 | contentInsetsChanged = true; |
| 1712 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1713 | if (contentInsetsChanged || mLastSystemUiVisibility != |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1714 | mAttachInfo.mSystemUiVisibility || mApplyInsetsRequested |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1715 | || mLastOverscanRequested != mAttachInfo.mOverscanRequested |
| 1716 | || outsetsChanged) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1717 | mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1718 | mLastOverscanRequested = mAttachInfo.mOverscanRequested; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1719 | mAttachInfo.mOutsets.set(mPendingOutsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1720 | mApplyInsetsRequested = false; |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1721 | dispatchApplyInsets(host); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1722 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | if (visibleInsetsChanged) { |
| 1724 | mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1725 | 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] | 1726 | + mAttachInfo.mVisibleInsets); |
| 1727 | } |
| 1728 | |
| 1729 | if (!hadSurface) { |
| 1730 | if (mSurface.isValid()) { |
| 1731 | // If we are creating a new surface, then we need to |
| 1732 | // completely redraw it. Also, when we get to the |
| 1733 | // point of drawing it we will hold off and schedule |
| 1734 | // a new traversal instead. This is so we can tell the |
| 1735 | // window manager about all of the windows being displayed |
| 1736 | // before actually drawing them, so it can display then |
| 1737 | // all at once. |
| 1738 | newSurface = true; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1739 | mFullRedrawNeeded = true; |
Jack Palevich | 61a6e68 | 2009-10-09 17:37:50 -0700 | [diff] [blame] | 1740 | mPreviousTransparentRegion.setEmpty(); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1741 | |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 1742 | // Only initialize up-front if transparent regions are not |
| 1743 | // requested, otherwise defer to see if the entire window |
| 1744 | // will be transparent |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1745 | if (mAttachInfo.mHardwareRenderer != null) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1746 | try { |
Romain Guy | 786fc93 | 2012-07-24 16:24:56 -0700 | [diff] [blame] | 1747 | hwInitialized = mAttachInfo.mHardwareRenderer.initialize( |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 1748 | mSurface); |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 1749 | if (hwInitialized && (host.mPrivateFlags |
| 1750 | & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) == 0) { |
| 1751 | // Don't pre-allocate if transparent regions |
| 1752 | // are requested as they may not be needed |
| 1753 | mSurface.allocateBuffers(); |
| 1754 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1755 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 1756 | handleOutOfResourcesException(e); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1757 | return; |
| 1758 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1759 | } |
| 1760 | } |
| 1761 | } else if (!mSurface.isValid()) { |
| 1762 | // If the surface has been removed, then reset the scroll |
| 1763 | // positions. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 1764 | if (mLastScrolledFocus != null) { |
| 1765 | mLastScrolledFocus.clear(); |
| 1766 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1767 | mScrollY = mCurScrollY = 0; |
Adrian Roos | 0e7ae4e | 2014-10-01 15:33:22 +0200 | [diff] [blame] | 1768 | if (mView instanceof RootViewSurfaceTaker) { |
| 1769 | ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY); |
| 1770 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1771 | if (mScroller != null) { |
| 1772 | mScroller.abortAnimation(); |
| 1773 | } |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 1774 | // Our surface is gone |
| 1775 | if (mAttachInfo.mHardwareRenderer != null && |
| 1776 | mAttachInfo.mHardwareRenderer.isEnabled()) { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 1777 | mAttachInfo.mHardwareRenderer.destroy(); |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 1778 | } |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1779 | } else if ((surfaceGenerationId != mSurface.getGenerationId() |
| 1780 | || surfaceSizeChanged) |
| 1781 | && mSurfaceHolder == null |
| 1782 | && mAttachInfo.mHardwareRenderer != null) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1783 | mFullRedrawNeeded = true; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1784 | try { |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1785 | // Need to do updateSurface (which leads to CanvasContext::setSurface and |
| 1786 | // re-create the EGLSurface) if either the Surface changed (as indicated by |
| 1787 | // generation id), or WindowManager changed the surface size. The latter is |
| 1788 | // because on some chips, changing the consumer side's BufferQueue size may |
| 1789 | // not take effect immediately unless we create a new EGLSurface. |
| 1790 | // Note that frame size change doesn't always imply surface size change (eg. |
| 1791 | // drag resizing uses fullscreen surface), need to check surfaceSizeChanged |
| 1792 | // flag from WindowManager. |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 1793 | mAttachInfo.mHardwareRenderer.updateSurface(mSurface); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1794 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 1795 | handleOutOfResourcesException(e); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1796 | return; |
| 1797 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1798 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1799 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1800 | final boolean freeformResizing = (relayoutResult |
| 1801 | & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM) != 0; |
| 1802 | final boolean dockedResizing = (relayoutResult |
| 1803 | & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED) != 0; |
| 1804 | final boolean dragResizing = freeformResizing || dockedResizing; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1805 | if (mDragResizing != dragResizing) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1806 | if (dragResizing) { |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 1807 | startDragResizing(mPendingBackDropFrame); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1808 | mResizeMode = freeformResizing |
| 1809 | ? RESIZE_MODE_FREEFORM |
| 1810 | : RESIZE_MODE_DOCKED_DIVIDER; |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1811 | } else { |
| 1812 | // We shouldn't come here, but if we come we should end the resize. |
| 1813 | endDragResizing(); |
| 1814 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1815 | } |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1816 | if (!USE_MT_RENDERER) { |
| 1817 | if (dragResizing) { |
| 1818 | mCanvasOffsetX = mWinFrame.left; |
| 1819 | mCanvasOffsetY = mWinFrame.top; |
| 1820 | } else { |
| 1821 | mCanvasOffsetX = mCanvasOffsetY = 0; |
| 1822 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1823 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1824 | } catch (RemoteException e) { |
| 1825 | } |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 1826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1827 | if (DEBUG_ORIENTATION) Log.v( |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1828 | TAG, "Relayout returned: frame=" + frame + ", surface=" + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1829 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1830 | mAttachInfo.mWindowLeft = frame.left; |
| 1831 | mAttachInfo.mWindowTop = frame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1832 | |
| 1833 | // !!FIXME!! This next section handles the case where we did not get the |
| 1834 | // window size we asked for. We should avoid this by getting a maximum size from |
| 1835 | // the window session beforehand. |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 1836 | if (mWidth != frame.width() || mHeight != frame.height()) { |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 1837 | mWidth = frame.width(); |
| 1838 | mHeight = frame.height(); |
| 1839 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1840 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1841 | if (mSurfaceHolder != null) { |
| 1842 | // The app owns the surface; tell it about what is going on. |
| 1843 | if (mSurface.isValid()) { |
| 1844 | // XXX .copyFrom() doesn't work! |
| 1845 | //mSurfaceHolder.mSurface.copyFrom(mSurface); |
| 1846 | mSurfaceHolder.mSurface = mSurface; |
| 1847 | } |
Jeff Brown | 30bc34f | 2011-01-25 12:56:56 -0800 | [diff] [blame] | 1848 | mSurfaceHolder.setSurfaceFrameSize(mWidth, mHeight); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1849 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 1850 | if (mSurface.isValid()) { |
| 1851 | if (!hadSurface) { |
| 1852 | mSurfaceHolder.ungetCallbacks(); |
| 1853 | |
| 1854 | mIsCreating = true; |
| 1855 | mSurfaceHolderCallback.surfaceCreated(mSurfaceHolder); |
| 1856 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 1857 | if (callbacks != null) { |
| 1858 | for (SurfaceHolder.Callback c : callbacks) { |
| 1859 | c.surfaceCreated(mSurfaceHolder); |
| 1860 | } |
| 1861 | } |
| 1862 | surfaceChanged = true; |
| 1863 | } |
| 1864 | if (surfaceChanged) { |
| 1865 | mSurfaceHolderCallback.surfaceChanged(mSurfaceHolder, |
| 1866 | lp.format, mWidth, mHeight); |
| 1867 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 1868 | if (callbacks != null) { |
| 1869 | for (SurfaceHolder.Callback c : callbacks) { |
| 1870 | c.surfaceChanged(mSurfaceHolder, lp.format, |
| 1871 | mWidth, mHeight); |
| 1872 | } |
| 1873 | } |
| 1874 | } |
| 1875 | mIsCreating = false; |
| 1876 | } else if (hadSurface) { |
| 1877 | mSurfaceHolder.ungetCallbacks(); |
| 1878 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 1879 | mSurfaceHolderCallback.surfaceDestroyed(mSurfaceHolder); |
| 1880 | if (callbacks != null) { |
| 1881 | for (SurfaceHolder.Callback c : callbacks) { |
| 1882 | c.surfaceDestroyed(mSurfaceHolder); |
| 1883 | } |
| 1884 | } |
| 1885 | mSurfaceHolder.mSurfaceLock.lock(); |
Jozef BABJAK | 93c5b6a | 2011-02-22 09:33:19 +0100 | [diff] [blame] | 1886 | try { |
| 1887 | mSurfaceHolder.mSurface = new Surface(); |
| 1888 | } finally { |
| 1889 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 1890 | } |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1891 | } |
| 1892 | } |
Romain Guy | 53389bd | 2010-09-07 17:16:32 -0700 | [diff] [blame] | 1893 | |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 1894 | final ThreadedRenderer hardwareRenderer = mAttachInfo.mHardwareRenderer; |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 1895 | if (hardwareRenderer != null && hardwareRenderer.isEnabled()) { |
| 1896 | if (hwInitialized |
| 1897 | || mWidth != hardwareRenderer.getWidth() |
| 1898 | || mHeight != hardwareRenderer.getHeight()) { |
| 1899 | hardwareRenderer.setup(mWidth, mHeight, mAttachInfo, |
| 1900 | mWindowAttributes.surfaceInsets); |
Romain Guy | 0398575 | 2011-07-11 15:33:51 -0700 | [diff] [blame] | 1901 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1902 | } |
| 1903 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1904 | if (!mStopped || mReportNextDraw) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1905 | boolean focusChangedDueToTouchMode = ensureTouchModeLocally( |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1906 | (relayoutResult&WindowManagerGlobal.RELAYOUT_RES_IN_TOUCH_MODE) != 0); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1907 | if (focusChangedDueToTouchMode || mWidth != host.getMeasuredWidth() |
| 1908 | || mHeight != host.getMeasuredHeight() || contentInsetsChanged) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1909 | int childWidthMeasureSpec = getRootMeasureSpec(mWidth, lp.width); |
| 1910 | int childHeightMeasureSpec = getRootMeasureSpec(mHeight, lp.height); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1911 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1912 | if (DEBUG_LAYOUT) Log.v(mTag, "Ooops, something changed! mWidth=" |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1913 | + mWidth + " measuredWidth=" + host.getMeasuredWidth() |
| 1914 | + " mHeight=" + mHeight |
| 1915 | + " measuredHeight=" + host.getMeasuredHeight() |
| 1916 | + " coveredInsetsChanged=" + contentInsetsChanged); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1917 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1918 | // Ask host how big it wants to be |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1919 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1920 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1921 | // Implementation of weights from WindowManager.LayoutParams |
| 1922 | // We just grow the dimensions as needed and re-measure if |
| 1923 | // needs be |
| 1924 | int width = host.getMeasuredWidth(); |
| 1925 | int height = host.getMeasuredHeight(); |
| 1926 | boolean measureAgain = false; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1927 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1928 | if (lp.horizontalWeight > 0.0f) { |
| 1929 | width += (int) ((mWidth - width) * lp.horizontalWeight); |
| 1930 | childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(width, |
| 1931 | MeasureSpec.EXACTLY); |
| 1932 | measureAgain = true; |
| 1933 | } |
| 1934 | if (lp.verticalWeight > 0.0f) { |
| 1935 | height += (int) ((mHeight - height) * lp.verticalWeight); |
| 1936 | childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, |
| 1937 | MeasureSpec.EXACTLY); |
| 1938 | measureAgain = true; |
| 1939 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1940 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1941 | if (measureAgain) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1942 | if (DEBUG_LAYOUT) Log.v(mTag, |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1943 | "And hey let's measure once more: width=" + width |
| 1944 | + " height=" + height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1945 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1946 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1947 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1948 | layoutRequested = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1949 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1950 | } |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 1951 | } else { |
| 1952 | // Not the first pass and no window/insets/visibility change but the window |
| 1953 | // may have moved and we need check that and if so to update the left and right |
| 1954 | // in the attach info. We translate only the window frame since on window move |
| 1955 | // the window manager tells us only for the new frame but the insets are the |
| 1956 | // same and we do not want to translate them more than once. |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 1957 | maybeHandleWindowMove(frame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1958 | } |
| 1959 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1960 | final boolean didLayout = layoutRequested && (!mStopped || mReportNextDraw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1961 | boolean triggerGlobalLayoutListener = didLayout |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1962 | || mAttachInfo.mRecomputeGlobalAttributes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1963 | if (didLayout) { |
Chet Haase | 3efa7b5 | 2012-12-03 08:33:17 -0800 | [diff] [blame] | 1964 | performLayout(lp, desiredWindowWidth, desiredWindowHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1965 | |
Mathias Agopian | 54e3d384 | 2013-04-12 15:13:12 -0700 | [diff] [blame] | 1966 | // 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] | 1967 | // We can compute the transparent area |
| 1968 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1969 | if ((host.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1970 | // start out transparent |
| 1971 | // TODO: AVOID THAT CALL BY CACHING THE RESULT? |
| 1972 | host.getLocationInWindow(mTmpLocation); |
| 1973 | mTransparentRegion.set(mTmpLocation[0], mTmpLocation[1], |
| 1974 | mTmpLocation[0] + host.mRight - host.mLeft, |
| 1975 | mTmpLocation[1] + host.mBottom - host.mTop); |
| 1976 | |
| 1977 | host.gatherTransparentRegion(mTransparentRegion); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1978 | if (mTranslator != null) { |
| 1979 | mTranslator.translateRegionInWindowToScreen(mTransparentRegion); |
| 1980 | } |
| 1981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1982 | if (!mTransparentRegion.equals(mPreviousTransparentRegion)) { |
| 1983 | mPreviousTransparentRegion.set(mTransparentRegion); |
Mathias Agopian | 54e3d384 | 2013-04-12 15:13:12 -0700 | [diff] [blame] | 1984 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1985 | // reconfigure window manager |
| 1986 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1987 | mWindowSession.setTransparentRegion(mWindow, mTransparentRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1988 | } catch (RemoteException e) { |
| 1989 | } |
| 1990 | } |
| 1991 | } |
| 1992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1993 | if (DBG) { |
| 1994 | System.out.println("======================================"); |
Chet Haase | 4610eef | 2015-12-03 07:38:11 -0800 | [diff] [blame] | 1995 | System.out.println("performTraversals -- after setFrame"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1996 | host.debug(); |
| 1997 | } |
| 1998 | } |
| 1999 | |
| 2000 | if (triggerGlobalLayoutListener) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2001 | mAttachInfo.mRecomputeGlobalAttributes = false; |
| 2002 | mAttachInfo.mTreeObserver.dispatchOnGlobalLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | if (computesInternalInsets) { |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2006 | // Clear the original insets. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2007 | final ViewTreeObserver.InternalInsetsInfo insets = mAttachInfo.mGivenInternalInsets; |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2008 | insets.reset(); |
| 2009 | |
| 2010 | // Compute new insets in place. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2011 | mAttachInfo.mTreeObserver.dispatchOnComputeInternalInsets(insets); |
| 2012 | mAttachInfo.mHasNonEmptyGivenInternalInsets = !insets.isEmpty(); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2013 | |
| 2014 | // Tell the window manager. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2015 | if (insetsPending || !mLastGivenInsets.equals(insets)) { |
| 2016 | mLastGivenInsets.set(insets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2017 | |
| 2018 | // Translate insets to screen coordinates if needed. |
| 2019 | final Rect contentInsets; |
| 2020 | final Rect visibleInsets; |
| 2021 | final Region touchableRegion; |
| 2022 | if (mTranslator != null) { |
| 2023 | contentInsets = mTranslator.getTranslatedContentInsets(insets.contentInsets); |
| 2024 | visibleInsets = mTranslator.getTranslatedVisibleInsets(insets.visibleInsets); |
| 2025 | touchableRegion = mTranslator.getTranslatedTouchableArea(insets.touchableRegion); |
| 2026 | } else { |
| 2027 | contentInsets = insets.contentInsets; |
| 2028 | visibleInsets = insets.visibleInsets; |
| 2029 | touchableRegion = insets.touchableRegion; |
| 2030 | } |
| 2031 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2032 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2033 | mWindowSession.setInsets(mWindow, insets.mTouchableInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2034 | contentInsets, visibleInsets, touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2035 | } catch (RemoteException e) { |
| 2036 | } |
| 2037 | } |
| 2038 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2040 | if (mFirst) { |
| 2041 | // handle first focus request |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2042 | 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] | 2043 | + mView.hasFocus()); |
| 2044 | if (mView != null) { |
| 2045 | if (!mView.hasFocus()) { |
| 2046 | mView.requestFocus(View.FOCUS_FORWARD); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2047 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: requested focused view=" |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2048 | + mView.findFocus()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2049 | } else { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2050 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: existing focused view=" |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2051 | + mView.findFocus()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2052 | } |
| 2053 | } |
| 2054 | } |
| 2055 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2056 | final boolean changedVisibility = (viewVisibilityChanged || mFirst) && isViewVisible; |
| 2057 | final boolean hasWindowFocus = mAttachInfo.mHasWindowFocus && isViewVisible; |
| 2058 | final boolean regainedFocus = hasWindowFocus && mLostWindowFocus; |
| 2059 | if (regainedFocus) { |
| 2060 | mLostWindowFocus = false; |
| 2061 | } else if (!hasWindowFocus && mHadWindowFocus) { |
| 2062 | mLostWindowFocus = true; |
| 2063 | } |
| 2064 | |
| 2065 | if (changedVisibility || regainedFocus) { |
| 2066 | host.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 2067 | } |
| 2068 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2069 | mFirst = false; |
| 2070 | mWillDrawSoon = false; |
| 2071 | mNewSurfaceNeeded = false; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 2072 | mActivityRelaunched = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2073 | mViewVisibility = viewVisibility; |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2074 | mHadWindowFocus = hasWindowFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2075 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2076 | if (hasWindowFocus && !isInLocalFocusMode()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2077 | final boolean imTarget = WindowManager.LayoutParams |
| 2078 | .mayUseInputMethod(mWindowAttributes.flags); |
| 2079 | if (imTarget != mLastWasImTarget) { |
| 2080 | mLastWasImTarget = imTarget; |
| 2081 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 2082 | if (imm != null && imTarget) { |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2083 | imm.onPreWindowFocus(mView, hasWindowFocus); |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 2084 | imm.onPostWindowFocus(mView, mView.findFocus(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2085 | mWindowAttributes.softInputMode, |
| 2086 | !mHasHadWindowFocus, mWindowAttributes.flags); |
| 2087 | } |
| 2088 | } |
| 2089 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2090 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2091 | // Remember if we must report the next draw. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2092 | if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2093 | mReportNextDraw = true; |
| 2094 | } |
| 2095 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2096 | boolean cancelDraw = mAttachInfo.mTreeObserver.dispatchOnPreDraw() || !isViewVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2097 | |
Chet Haase | 61158c6 | 2011-09-06 22:19:45 -0700 | [diff] [blame] | 2098 | if (!cancelDraw && !newSurface) { |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2099 | if (mPendingTransitions != null && mPendingTransitions.size() > 0) { |
| 2100 | for (int i = 0; i < mPendingTransitions.size(); ++i) { |
| 2101 | mPendingTransitions.get(i).startChangingAnimations(); |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2102 | } |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2103 | mPendingTransitions.clear(); |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2104 | } |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2105 | |
| 2106 | performDraw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | } else { |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2108 | if (isViewVisible) { |
Chris Wren | 78cb7cf | 2012-05-15 12:36:44 -0400 | [diff] [blame] | 2109 | // Try again |
| 2110 | scheduleTraversals(); |
| 2111 | } else if (mPendingTransitions != null && mPendingTransitions.size() > 0) { |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2112 | for (int i = 0; i < mPendingTransitions.size(); ++i) { |
| 2113 | mPendingTransitions.get(i).endChangingAnimations(); |
| 2114 | } |
| 2115 | mPendingTransitions.clear(); |
| 2116 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2117 | } |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 2118 | |
| 2119 | mIsInTraversal = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2120 | } |
| 2121 | |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2122 | private void maybeHandleWindowMove(Rect frame) { |
| 2123 | |
| 2124 | // TODO: Well, we are checking whether the frame has changed similarly |
| 2125 | // to how this is done for the insets. This is however incorrect since |
| 2126 | // the insets and the frame are translated. For example, the old frame |
| 2127 | // was (1, 1 - 1, 1) and was translated to say (2, 2 - 2, 2), now the new |
| 2128 | // reported frame is (2, 2 - 2, 2) which implies no change but this is not |
| 2129 | // true since we are comparing a not translated value to a translated one. |
| 2130 | // This scenario is rare but we may want to fix that. |
| 2131 | |
| 2132 | final boolean windowMoved = mAttachInfo.mWindowLeft != frame.left |
| 2133 | || mAttachInfo.mWindowTop != frame.top; |
| 2134 | if (windowMoved) { |
| 2135 | if (mTranslator != null) { |
| 2136 | mTranslator.translateRectInScreenToAppWinFrame(frame); |
| 2137 | } |
| 2138 | mAttachInfo.mWindowLeft = frame.left; |
| 2139 | mAttachInfo.mWindowTop = frame.top; |
| 2140 | |
| 2141 | // Update the light position for the new window offsets. |
| 2142 | if (mAttachInfo.mHardwareRenderer != null) { |
| 2143 | mAttachInfo.mHardwareRenderer.setLightCenter(mAttachInfo); |
| 2144 | } |
| 2145 | } |
| 2146 | } |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2147 | private void handleOutOfResourcesException(Surface.OutOfResourcesException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2148 | Log.e(mTag, "OutOfResourcesException initializing HW surface", e); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2149 | try { |
| 2150 | if (!mWindowSession.outOfMemory(mWindow) && |
| 2151 | Process.myUid() != Process.SYSTEM_UID) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2152 | Slog.w(mTag, "No processes killed for memory; killing self"); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2153 | Process.killProcess(Process.myPid()); |
| 2154 | } |
| 2155 | } catch (RemoteException ex) { |
| 2156 | } |
| 2157 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2158 | } |
| 2159 | |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2160 | private void performMeasure(int childWidthMeasureSpec, int childHeightMeasureSpec) { |
| 2161 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "measure"); |
| 2162 | try { |
| 2163 | mView.measure(childWidthMeasureSpec, childHeightMeasureSpec); |
| 2164 | } finally { |
| 2165 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2166 | } |
| 2167 | } |
| 2168 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2169 | /** |
| 2170 | * Called by {@link android.view.View#isInLayout()} to determine whether the view hierarchy |
| 2171 | * is currently undergoing a layout pass. |
| 2172 | * |
| 2173 | * @return whether the view hierarchy is currently undergoing a layout pass |
| 2174 | */ |
| 2175 | boolean isInLayout() { |
| 2176 | return mInLayout; |
| 2177 | } |
| 2178 | |
| 2179 | /** |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2180 | * Called by {@link android.view.View#requestLayout()} if the view hierarchy is currently |
| 2181 | * undergoing a layout pass. requestLayout() should not generally be called during layout, |
| 2182 | * unless the container hierarchy knows what it is doing (i.e., it is fine as long as |
| 2183 | * all children in that container hierarchy are measured and laid out at the end of the layout |
| 2184 | * pass for that container). If requestLayout() is called anyway, we handle it correctly |
| 2185 | * by registering all requesters during a frame as it proceeds. At the end of the frame, |
| 2186 | * we check all of those views to see if any still have pending layout requests, which |
| 2187 | * indicates that they were not correctly handled by their container hierarchy. If that is |
| 2188 | * the case, we clear all such flags in the tree, to remove the buggy flag state that leads |
| 2189 | * 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] | 2190 | * 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] | 2191 | * requests to the next frame to avoid possible infinite loops. |
| 2192 | * |
| 2193 | * <p>The return value from this method indicates whether the request should proceed |
| 2194 | * (if it is a request during the first layout pass) or should be skipped and posted to the |
| 2195 | * 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] | 2196 | * |
| 2197 | * @param view the view that requested the layout. |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2198 | * |
| 2199 | * @return true if request should proceed, false otherwise. |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2200 | */ |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2201 | boolean requestLayoutDuringLayout(final View view) { |
| 2202 | if (view.mParent == null || view.mAttachInfo == null) { |
| 2203 | // Would not normally trigger another layout, so just let it pass through as usual |
| 2204 | return true; |
| 2205 | } |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2206 | if (!mLayoutRequesters.contains(view)) { |
| 2207 | mLayoutRequesters.add(view); |
| 2208 | } |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2209 | if (!mHandlingLayoutInLayoutRequest) { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2210 | // Let the request proceed normally; it will be processed in a second layout pass |
| 2211 | // if necessary |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2212 | return true; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2213 | } else { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2214 | // Don't let the request proceed during the second layout pass. |
| 2215 | // It will post to the next frame instead. |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2216 | return false; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2217 | } |
| 2218 | } |
| 2219 | |
Chet Haase | 3efa7b5 | 2012-12-03 08:33:17 -0800 | [diff] [blame] | 2220 | private void performLayout(WindowManager.LayoutParams lp, int desiredWindowWidth, |
| 2221 | int desiredWindowHeight) { |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2222 | mLayoutRequested = false; |
| 2223 | mScrollMayChange = true; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2224 | mInLayout = true; |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2225 | |
| 2226 | final View host = mView; |
| 2227 | if (DEBUG_ORIENTATION || DEBUG_LAYOUT) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2228 | Log.v(mTag, "Laying out " + host + " to (" + |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2229 | host.getMeasuredWidth() + ", " + host.getMeasuredHeight() + ")"); |
| 2230 | } |
| 2231 | |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2232 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "layout"); |
| 2233 | try { |
| 2234 | host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2235 | |
Chet Haase | d5a8352 | 2012-11-21 16:24:44 -0800 | [diff] [blame] | 2236 | mInLayout = false; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2237 | int numViewsRequestingLayout = mLayoutRequesters.size(); |
| 2238 | if (numViewsRequestingLayout > 0) { |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2239 | // requestLayout() was called during layout. |
| 2240 | // If no layout-request flags are set on the requesting views, there is no problem. |
| 2241 | // If some requests are still pending, then we need to clear those flags and do |
| 2242 | // a full request/measure/layout pass to handle this situation. |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2243 | ArrayList<View> validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, |
| 2244 | false); |
| 2245 | if (validLayoutRequesters != null) { |
| 2246 | // Set this flag to indicate that any further requests are happening during |
| 2247 | // the second pass, which may result in posting those requests to the next |
| 2248 | // frame instead |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2249 | mHandlingLayoutInLayoutRequest = true; |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2250 | |
| 2251 | // Process fresh layout requests, then measure and layout |
| 2252 | int numValidRequests = validLayoutRequesters.size(); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2253 | for (int i = 0; i < numValidRequests; ++i) { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2254 | final View view = validLayoutRequesters.get(i); |
| 2255 | Log.w("View", "requestLayout() improperly called by " + view + |
| 2256 | " during layout: running second layout pass"); |
| 2257 | view.requestLayout(); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2258 | } |
| 2259 | measureHierarchy(host, lp, mView.getContext().getResources(), |
| 2260 | desiredWindowWidth, desiredWindowHeight); |
| 2261 | mInLayout = true; |
| 2262 | host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2263 | |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2264 | mHandlingLayoutInLayoutRequest = false; |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2265 | |
| 2266 | // Check the valid requests again, this time without checking/clearing the |
| 2267 | // layout flags, since requests happening during the second pass get noop'd |
| 2268 | validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, true); |
| 2269 | if (validLayoutRequesters != null) { |
| 2270 | final ArrayList<View> finalRequesters = validLayoutRequesters; |
| 2271 | // Post second-pass requests to the next frame |
| 2272 | getRunQueue().post(new Runnable() { |
| 2273 | @Override |
| 2274 | public void run() { |
| 2275 | int numValidRequests = finalRequesters.size(); |
| 2276 | for (int i = 0; i < numValidRequests; ++i) { |
| 2277 | final View view = finalRequesters.get(i); |
| 2278 | Log.w("View", "requestLayout() improperly called by " + view + |
| 2279 | " during second layout pass: posting in next frame"); |
| 2280 | view.requestLayout(); |
| 2281 | } |
| 2282 | } |
| 2283 | }); |
| 2284 | } |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2285 | } |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2286 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2287 | } |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2288 | } finally { |
| 2289 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2290 | } |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2291 | mInLayout = false; |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2294 | /** |
| 2295 | * This method is called during layout when there have been calls to requestLayout() during |
| 2296 | * layout. It walks through the list of views that requested layout to determine which ones |
| 2297 | * still need it, based on visibility in the hierarchy and whether they have already been |
| 2298 | * handled (as is usually the case with ListView children). |
| 2299 | * |
| 2300 | * @param layoutRequesters The list of views that requested layout during layout |
| 2301 | * @param secondLayoutRequests Whether the requests were issued during the second layout pass. |
| 2302 | * If so, the FORCE_LAYOUT flag was not set on requesters. |
| 2303 | * @return A list of the actual views that still need to be laid out. |
| 2304 | */ |
| 2305 | private ArrayList<View> getValidLayoutRequesters(ArrayList<View> layoutRequesters, |
| 2306 | boolean secondLayoutRequests) { |
| 2307 | |
| 2308 | int numViewsRequestingLayout = layoutRequesters.size(); |
| 2309 | ArrayList<View> validLayoutRequesters = null; |
| 2310 | for (int i = 0; i < numViewsRequestingLayout; ++i) { |
| 2311 | View view = layoutRequesters.get(i); |
| 2312 | if (view != null && view.mAttachInfo != null && view.mParent != null && |
| 2313 | (secondLayoutRequests || (view.mPrivateFlags & View.PFLAG_FORCE_LAYOUT) == |
| 2314 | View.PFLAG_FORCE_LAYOUT)) { |
| 2315 | boolean gone = false; |
| 2316 | View parent = view; |
| 2317 | // Only trigger new requests for views in a non-GONE hierarchy |
| 2318 | while (parent != null) { |
| 2319 | if ((parent.mViewFlags & View.VISIBILITY_MASK) == View.GONE) { |
| 2320 | gone = true; |
| 2321 | break; |
| 2322 | } |
| 2323 | if (parent.mParent instanceof View) { |
| 2324 | parent = (View) parent.mParent; |
| 2325 | } else { |
| 2326 | parent = null; |
| 2327 | } |
| 2328 | } |
| 2329 | if (!gone) { |
| 2330 | if (validLayoutRequesters == null) { |
| 2331 | validLayoutRequesters = new ArrayList<View>(); |
| 2332 | } |
| 2333 | validLayoutRequesters.add(view); |
| 2334 | } |
| 2335 | } |
| 2336 | } |
| 2337 | if (!secondLayoutRequests) { |
| 2338 | // If we're checking the layout flags, then we need to clean them up also |
| 2339 | for (int i = 0; i < numViewsRequestingLayout; ++i) { |
| 2340 | View view = layoutRequesters.get(i); |
| 2341 | while (view != null && |
| 2342 | (view.mPrivateFlags & View.PFLAG_FORCE_LAYOUT) != 0) { |
| 2343 | view.mPrivateFlags &= ~View.PFLAG_FORCE_LAYOUT; |
| 2344 | if (view.mParent instanceof View) { |
| 2345 | view = (View) view.mParent; |
| 2346 | } else { |
| 2347 | view = null; |
| 2348 | } |
| 2349 | } |
| 2350 | } |
| 2351 | } |
| 2352 | layoutRequesters.clear(); |
| 2353 | return validLayoutRequesters; |
| 2354 | } |
| 2355 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2356 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2357 | public void requestTransparentRegion(View child) { |
| 2358 | // the test below should not fail unless someone is messing with us |
| 2359 | checkThread(); |
| 2360 | if (mView == child) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2361 | mView.mPrivateFlags |= View.PFLAG_REQUEST_TRANSPARENT_REGIONS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2362 | // Need to make sure we re-evaluate the window attributes next |
| 2363 | // time around, to ensure the window has the correct format. |
| 2364 | mWindowAttributesChanged = true; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 2365 | mWindowAttributesChangesFlag = 0; |
Mathias Agopian | 1bd80ad | 2010-11-04 17:13:39 -0700 | [diff] [blame] | 2366 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | /** |
| 2371 | * Figures out the measure spec for the root view in a window based on it's |
| 2372 | * layout params. |
| 2373 | * |
| 2374 | * @param windowSize |
| 2375 | * The available width or height of the window |
| 2376 | * |
| 2377 | * @param rootDimension |
| 2378 | * The layout params for one dimension (width or height) of the |
| 2379 | * window. |
| 2380 | * |
| 2381 | * @return The measure spec to use to measure the root view. |
| 2382 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 2383 | private static int getRootMeasureSpec(int windowSize, int rootDimension) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2384 | int measureSpec; |
| 2385 | switch (rootDimension) { |
| 2386 | |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 2387 | case ViewGroup.LayoutParams.MATCH_PARENT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2388 | // Window can't resize. Force root view to be windowSize. |
| 2389 | measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.EXACTLY); |
| 2390 | break; |
| 2391 | case ViewGroup.LayoutParams.WRAP_CONTENT: |
| 2392 | // Window can resize. Set max size for root view. |
| 2393 | measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.AT_MOST); |
| 2394 | break; |
| 2395 | default: |
| 2396 | // Window wants to be an exact size. Force root view to be that size. |
| 2397 | measureSpec = MeasureSpec.makeMeasureSpec(rootDimension, MeasureSpec.EXACTLY); |
| 2398 | break; |
| 2399 | } |
| 2400 | return measureSpec; |
| 2401 | } |
| 2402 | |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2403 | int mHardwareXOffset; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2404 | int mHardwareYOffset; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2405 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2406 | @Override |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 2407 | public void onHardwarePreDraw(DisplayListCanvas canvas) { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2408 | canvas.translate(-mHardwareXOffset, -mHardwareYOffset); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2409 | } |
| 2410 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2411 | @Override |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 2412 | public void onHardwarePostDraw(DisplayListCanvas canvas) { |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2413 | drawAccessibilityFocusedDrawableIfNeeded(canvas); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2414 | } |
| 2415 | |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 2416 | /** |
| 2417 | * @hide |
| 2418 | */ |
| 2419 | void outputDisplayList(View view) { |
Chris Craik | 356b5fe | 2015-07-07 10:39:36 -0700 | [diff] [blame] | 2420 | view.mRenderNode.output(); |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 2421 | if (mAttachInfo.mHardwareRenderer != null) { |
| 2422 | ((ThreadedRenderer)mAttachInfo.mHardwareRenderer).serializeDisplayListTree(); |
| 2423 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | /** |
| 2427 | * @see #PROPERTY_PROFILE_RENDERING |
| 2428 | */ |
| 2429 | private void profileRendering(boolean enabled) { |
| 2430 | if (mProfileRendering) { |
| 2431 | mRenderProfilingEnabled = enabled; |
Chris Craik | ae4f3204 | 2013-02-07 12:57:10 -0800 | [diff] [blame] | 2432 | |
| 2433 | if (mRenderProfiler != null) { |
| 2434 | mChoreographer.removeFrameCallback(mRenderProfiler); |
| 2435 | } |
| 2436 | if (mRenderProfilingEnabled) { |
| 2437 | if (mRenderProfiler == null) { |
| 2438 | mRenderProfiler = new Choreographer.FrameCallback() { |
| 2439 | @Override |
| 2440 | public void doFrame(long frameTimeNanos) { |
| 2441 | mDirty.set(0, 0, mWidth, mHeight); |
| 2442 | scheduleTraversals(); |
| 2443 | if (mRenderProfilingEnabled) { |
| 2444 | mChoreographer.postFrameCallback(mRenderProfiler); |
| 2445 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2446 | } |
Chris Craik | ae4f3204 | 2013-02-07 12:57:10 -0800 | [diff] [blame] | 2447 | }; |
| 2448 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 2449 | mChoreographer.postFrameCallback(mRenderProfiler); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2450 | } else { |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2451 | mRenderProfiler = null; |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 2452 | } |
| 2453 | } |
| 2454 | } |
| 2455 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2456 | /** |
| 2457 | * Called from draw() when DEBUG_FPS is enabled |
| 2458 | */ |
| 2459 | private void trackFPS() { |
| 2460 | // Tracks frames per second drawn. First value in a series of draws may be bogus |
| 2461 | // because it down not account for the intervening idle time |
| 2462 | long nowTime = System.currentTimeMillis(); |
| 2463 | if (mFpsStartTime < 0) { |
| 2464 | mFpsStartTime = mFpsPrevTime = nowTime; |
| 2465 | mFpsNumFrames = 0; |
| 2466 | } else { |
| 2467 | ++mFpsNumFrames; |
| 2468 | String thisHash = Integer.toHexString(System.identityHashCode(this)); |
| 2469 | long frameTime = nowTime - mFpsPrevTime; |
| 2470 | long totalTime = nowTime - mFpsStartTime; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2471 | Log.v(mTag, "0x" + thisHash + "\tFrame time:\t" + frameTime); |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2472 | mFpsPrevTime = nowTime; |
| 2473 | if (totalTime > 1000) { |
| 2474 | float fps = (float) mFpsNumFrames * 1000 / totalTime; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2475 | Log.v(mTag, "0x" + thisHash + "\tFPS:\t" + fps); |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2476 | mFpsStartTime = nowTime; |
| 2477 | mFpsNumFrames = 0; |
| 2478 | } |
| 2479 | } |
| 2480 | } |
| 2481 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2482 | private void performDraw() { |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 2483 | if (mAttachInfo.mDisplayState == Display.STATE_OFF && !mReportNextDraw) { |
Craig Mautner | 006f0e4 | 2012-03-21 11:00:32 -0700 | [diff] [blame] | 2484 | return; |
| 2485 | } |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 2486 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2487 | final boolean fullRedrawNeeded = mFullRedrawNeeded; |
| 2488 | mFullRedrawNeeded = false; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2489 | |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 2490 | mIsDrawing = true; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2491 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "draw"); |
| 2492 | try { |
| 2493 | draw(fullRedrawNeeded); |
| 2494 | } finally { |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 2495 | mIsDrawing = false; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2496 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2497 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2498 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 2499 | // For whatever reason we didn't create a HardwareRenderer, end any |
| 2500 | // hardware animations that are now dangling |
| 2501 | if (mAttachInfo.mPendingAnimatingRenderNodes != null) { |
| 2502 | final int count = mAttachInfo.mPendingAnimatingRenderNodes.size(); |
| 2503 | for (int i = 0; i < count; i++) { |
| 2504 | mAttachInfo.mPendingAnimatingRenderNodes.get(i).endAllAnimators(); |
| 2505 | } |
| 2506 | mAttachInfo.mPendingAnimatingRenderNodes.clear(); |
| 2507 | } |
| 2508 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2509 | if (mReportNextDraw) { |
| 2510 | mReportNextDraw = false; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2511 | |
| 2512 | // if we're using multi-thread renderer, wait for the window frame draws |
| 2513 | if (mWindowDrawCountDown != null) { |
| 2514 | try { |
| 2515 | mWindowDrawCountDown.await(); |
| 2516 | } catch (InterruptedException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2517 | Log.e(mTag, "Window redraw count down interruped!"); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2518 | } |
| 2519 | mWindowDrawCountDown = null; |
| 2520 | } |
| 2521 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 2522 | if (mAttachInfo.mHardwareRenderer != null) { |
| 2523 | mAttachInfo.mHardwareRenderer.fence(); |
| 2524 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2525 | |
| 2526 | if (LOCAL_LOGV) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2527 | Log.v(mTag, "FINISHED DRAWING: " + mWindowAttributes.getTitle()); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2528 | } |
| 2529 | if (mSurfaceHolder != null && mSurface.isValid()) { |
| 2530 | mSurfaceHolderCallback.surfaceRedrawNeeded(mSurfaceHolder); |
| 2531 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 2532 | if (callbacks != null) { |
| 2533 | for (SurfaceHolder.Callback c : callbacks) { |
| 2534 | if (c instanceof SurfaceHolder.Callback2) { |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 2535 | ((SurfaceHolder.Callback2)c).surfaceRedrawNeeded(mSurfaceHolder); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2536 | } |
| 2537 | } |
| 2538 | } |
| 2539 | } |
| 2540 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2541 | mWindowSession.finishDrawing(mWindow); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2542 | } catch (RemoteException e) { |
| 2543 | } |
| 2544 | } |
| 2545 | } |
| 2546 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2547 | private void draw(boolean fullRedrawNeeded) { |
| 2548 | Surface surface = mSurface; |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 2549 | if (!surface.isValid()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | return; |
| 2551 | } |
| 2552 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2553 | if (DEBUG_FPS) { |
| 2554 | trackFPS(); |
| 2555 | } |
| 2556 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2557 | if (!sFirstDrawComplete) { |
| 2558 | synchronized (sFirstDrawHandlers) { |
| 2559 | sFirstDrawComplete = true; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 2560 | final int count = sFirstDrawHandlers.size(); |
| 2561 | for (int i = 0; i< count; i++) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 2562 | mHandler.post(sFirstDrawHandlers.get(i)); |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2563 | } |
| 2564 | } |
| 2565 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2567 | scrollToRectOrFocus(null, false); |
| 2568 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2569 | if (mAttachInfo.mViewScrollChanged) { |
| 2570 | mAttachInfo.mViewScrollChanged = false; |
| 2571 | mAttachInfo.mTreeObserver.dispatchOnScrollChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2572 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2573 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2574 | boolean animating = mScroller != null && mScroller.computeScrollOffset(); |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2575 | final int curScrollY; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2576 | if (animating) { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2577 | curScrollY = mScroller.getCurrY(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2578 | } else { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2579 | curScrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2580 | } |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2581 | if (mCurScrollY != curScrollY) { |
| 2582 | mCurScrollY = curScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2583 | fullRedrawNeeded = true; |
Adrian Roos | 0e7ae4e | 2014-10-01 15:33:22 +0200 | [diff] [blame] | 2584 | if (mView instanceof RootViewSurfaceTaker) { |
| 2585 | ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY); |
| 2586 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2587 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2588 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2589 | final float appScale = mAttachInfo.mApplicationScale; |
| 2590 | final boolean scalingRequired = mAttachInfo.mScalingRequired; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2591 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2592 | int resizeAlpha = 0; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2593 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2594 | final Rect dirty = mDirty; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2595 | if (mSurfaceHolder != null) { |
| 2596 | // The app owns the surface, we won't draw. |
| 2597 | dirty.setEmpty(); |
Derek Sollenberger | 8d94835 | 2015-07-16 09:27:59 -0400 | [diff] [blame] | 2598 | if (animating && mScroller != null) { |
| 2599 | mScroller.abortAnimation(); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2600 | } |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2601 | return; |
| 2602 | } |
Romain Guy | 58ef7fb | 2010-09-13 12:52:37 -0700 | [diff] [blame] | 2603 | |
| 2604 | if (fullRedrawNeeded) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2605 | mAttachInfo.mIgnoreDirtyState = true; |
Romain Guy | c3166e1 | 2011-08-08 15:00:03 -0700 | [diff] [blame] | 2606 | 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] | 2607 | } |
Chet Haase | ad4f703 | 2011-06-22 09:18:31 -0700 | [diff] [blame] | 2608 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2609 | if (DEBUG_ORIENTATION || DEBUG_DRAW) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2610 | Log.v(mTag, "Draw " + mView + "/" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2611 | + mWindowAttributes.getTitle() |
| 2612 | + ": dirty={" + dirty.left + "," + dirty.top |
| 2613 | + "," + dirty.right + "," + dirty.bottom + "} surface=" |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 2614 | + surface + " surface.isValid()=" + surface.isValid() + ", appScale:" + |
| 2615 | appScale + ", width=" + mWidth + ", height=" + mHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2616 | } |
| 2617 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2618 | mAttachInfo.mTreeObserver.dispatchOnDraw(); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2619 | |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2620 | int xOffset = -mCanvasOffsetX; |
| 2621 | int yOffset = -mCanvasOffsetY + curScrollY; |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2622 | final WindowManager.LayoutParams params = mWindowAttributes; |
| 2623 | final Rect surfaceInsets = params != null ? params.surfaceInsets : null; |
| 2624 | if (surfaceInsets != null) { |
| 2625 | xOffset -= surfaceInsets.left; |
| 2626 | yOffset -= surfaceInsets.top; |
| 2627 | |
| 2628 | // Offset dirty rect for surface insets. |
| 2629 | dirty.offset(surfaceInsets.left, surfaceInsets.right); |
| 2630 | } |
| 2631 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2632 | boolean accessibilityFocusDirty = false; |
| 2633 | final Drawable drawable = mAttachInfo.mAccessibilityFocusDrawable; |
| 2634 | if (drawable != null) { |
| 2635 | final Rect bounds = mAttachInfo.mTmpInvalRect; |
| 2636 | final boolean hasFocus = getAccessibilityFocusedRect(bounds); |
| 2637 | if (!hasFocus) { |
| 2638 | bounds.setEmpty(); |
| 2639 | } |
| 2640 | if (!bounds.equals(drawable.getBounds())) { |
| 2641 | accessibilityFocusDirty = true; |
| 2642 | } |
| 2643 | } |
| 2644 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 2645 | mAttachInfo.mDrawingTime = |
| 2646 | mChoreographer.getFrameTimeNanos() / TimeUtils.NANOS_PER_MS; |
| 2647 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2648 | if (!dirty.isEmpty() || mIsAnimating || accessibilityFocusDirty) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2649 | if (mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled()) { |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2650 | // If accessibility focus moved, always invalidate the root. |
| 2651 | boolean invalidateRoot = accessibilityFocusDirty; |
| 2652 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2653 | // Draw with hardware renderer. |
| 2654 | mIsAnimating = false; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2655 | |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 2656 | if (mHardwareYOffset != yOffset || mHardwareXOffset != xOffset) { |
| 2657 | mHardwareYOffset = yOffset; |
| 2658 | mHardwareXOffset = xOffset; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2659 | invalidateRoot = true; |
Alan Viverette | f6cf1a0 | 2014-08-11 14:13:02 -0700 | [diff] [blame] | 2660 | } |
| 2661 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2662 | if (invalidateRoot) { |
| 2663 | mAttachInfo.mHardwareRenderer.invalidateRoot(); |
| 2664 | } |
| 2665 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2666 | dirty.setEmpty(); |
| 2667 | |
Skuhne | 980ee47 | 2015-10-06 11:31:31 -0700 | [diff] [blame] | 2668 | // Stage the content drawn size now. It will be transferred to the renderer |
| 2669 | // shortly before the draw commands get send to the renderer. |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2670 | final boolean updated = updateContentDrawBounds(); |
| 2671 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2672 | mAttachInfo.mHardwareRenderer.draw(mView, mAttachInfo, this); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2673 | |
| 2674 | if (updated) { |
| 2675 | requestDrawWindow(); |
| 2676 | } |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2677 | } else { |
| 2678 | // If we get here with a disabled & requested hardware renderer, something went |
| 2679 | // wrong (an invalidate posted right before we destroyed the hardware surface |
| 2680 | // for instance) so we should just bail out. Locking the surface with software |
| 2681 | // rendering at this point would lock it forever and prevent hardware renderer |
| 2682 | // from doing its job when it comes back. |
| 2683 | // Before we request a new frame we must however attempt to reinitiliaze the |
| 2684 | // hardware renderer if it's in requested state. This would happen after an |
| 2685 | // eglTerminate() for instance. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2686 | if (mAttachInfo.mHardwareRenderer != null && |
| 2687 | !mAttachInfo.mHardwareRenderer.isEnabled() && |
| 2688 | mAttachInfo.mHardwareRenderer.isRequested()) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2689 | |
| 2690 | try { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2691 | mAttachInfo.mHardwareRenderer.initializeIfNeeded( |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 2692 | mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2693 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2694 | handleOutOfResourcesException(e); |
| 2695 | return; |
| 2696 | } |
| 2697 | |
| 2698 | mFullRedrawNeeded = true; |
| 2699 | scheduleTraversals(); |
| 2700 | return; |
| 2701 | } |
| 2702 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2703 | if (!drawSoftware(surface, mAttachInfo, xOffset, yOffset, scalingRequired, dirty)) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2704 | return; |
| 2705 | } |
Jeff Brown | 95db2b2 | 2011-11-30 19:54:41 -0800 | [diff] [blame] | 2706 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2707 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2708 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2709 | if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2710 | mFullRedrawNeeded = true; |
| 2711 | scheduleTraversals(); |
| 2712 | } |
| 2713 | } |
| 2714 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2715 | /** |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2716 | * @return true if drawing was successful, false if an error occurred |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2717 | */ |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2718 | private boolean drawSoftware(Surface surface, AttachInfo attachInfo, int xoff, int yoff, |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2719 | boolean scalingRequired, Rect dirty) { |
| 2720 | |
| 2721 | // Draw with software renderer. |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2722 | final Canvas canvas; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2723 | try { |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2724 | final int left = dirty.left; |
| 2725 | final int top = dirty.top; |
| 2726 | final int right = dirty.right; |
| 2727 | final int bottom = dirty.bottom; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2728 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2729 | canvas = mSurface.lockCanvas(dirty); |
| 2730 | |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 2731 | // The dirty rectangle can be modified by Surface.lockCanvas() |
| 2732 | //noinspection ConstantConditions |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2733 | if (left != dirty.left || top != dirty.top || right != dirty.right |
| 2734 | || bottom != dirty.bottom) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2735 | attachInfo.mIgnoreDirtyState = true; |
| 2736 | } |
| 2737 | |
| 2738 | // TODO: Do this in native |
| 2739 | canvas.setDensity(mDensity); |
| 2740 | } catch (Surface.OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2741 | handleOutOfResourcesException(e); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2742 | return false; |
| 2743 | } catch (IllegalArgumentException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2744 | Log.e(mTag, "Could not lock surface", e); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2745 | // Don't assume this is due to out of memory, it could be |
| 2746 | // something else, and if it is something else then we could |
| 2747 | // kill stuff (or ourself) for no reason. |
| 2748 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2749 | return false; |
| 2750 | } |
| 2751 | |
| 2752 | try { |
| 2753 | if (DEBUG_ORIENTATION || DEBUG_DRAW) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2754 | Log.v(mTag, "Surface " + surface + " drawing to bitmap w=" |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2755 | + canvas.getWidth() + ", h=" + canvas.getHeight()); |
| 2756 | //canvas.drawARGB(255, 255, 0, 0); |
| 2757 | } |
| 2758 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2759 | // If this bitmap's format includes an alpha channel, we |
| 2760 | // need to clear it before drawing so that the child will |
| 2761 | // properly re-composite its drawing on a transparent |
| 2762 | // background. This automatically respects the clip/dirty region |
| 2763 | // or |
| 2764 | // If we are applying an offset, we need to clear the area |
| 2765 | // where the offset doesn't appear to avoid having garbage |
| 2766 | // left in the blank areas. |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2767 | if (!canvas.isOpaque() || yoff != 0 || xoff != 0) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2768 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 2769 | } |
| 2770 | |
| 2771 | dirty.setEmpty(); |
| 2772 | mIsAnimating = false; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2773 | mView.mPrivateFlags |= View.PFLAG_DRAWN; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2774 | |
| 2775 | if (DEBUG_DRAW) { |
| 2776 | Context cxt = mView.getContext(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2777 | Log.i(mTag, "Drawing: package:" + cxt.getPackageName() + |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2778 | ", metrics=" + cxt.getResources().getDisplayMetrics() + |
| 2779 | ", compatibilityInfo=" + cxt.getResources().getCompatibilityInfo()); |
| 2780 | } |
| 2781 | try { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2782 | canvas.translate(-xoff, -yoff); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2783 | if (mTranslator != null) { |
| 2784 | mTranslator.translateCanvas(canvas); |
| 2785 | } |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 2786 | canvas.setScreenDensity(scalingRequired ? mNoncompatDensity : 0); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2787 | attachInfo.mSetIgnoreDirtyState = false; |
| 2788 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2789 | mView.draw(canvas); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2790 | |
| 2791 | drawAccessibilityFocusedDrawableIfNeeded(canvas); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2792 | } finally { |
| 2793 | if (!attachInfo.mSetIgnoreDirtyState) { |
| 2794 | // Only clear the flag if it was not set during the mView.draw() call |
| 2795 | attachInfo.mIgnoreDirtyState = false; |
| 2796 | } |
| 2797 | } |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2798 | } finally { |
Romain Guy | dddcd22 | 2012-05-18 15:33:57 -0700 | [diff] [blame] | 2799 | try { |
| 2800 | surface.unlockCanvasAndPost(canvas); |
| 2801 | } catch (IllegalArgumentException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2802 | Log.e(mTag, "Could not unlock surface", e); |
Romain Guy | dddcd22 | 2012-05-18 15:33:57 -0700 | [diff] [blame] | 2803 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2804 | //noinspection ReturnInsideFinallyBlock |
| 2805 | return false; |
| 2806 | } |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2807 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2808 | if (LOCAL_LOGV) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2809 | Log.v(mTag, "Surface " + surface + " unlockCanvasAndPost"); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2810 | } |
| 2811 | } |
| 2812 | return true; |
| 2813 | } |
| 2814 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2815 | /** |
| 2816 | * We want to draw a highlight around the current accessibility focused. |
| 2817 | * Since adding a style for all possible view is not a viable option we |
| 2818 | * have this specialized drawing method. |
| 2819 | * |
| 2820 | * Note: We are doing this here to be able to draw the highlight for |
| 2821 | * virtual views in addition to real ones. |
| 2822 | * |
| 2823 | * @param canvas The canvas on which to draw. |
| 2824 | */ |
| 2825 | private void drawAccessibilityFocusedDrawableIfNeeded(Canvas canvas) { |
| 2826 | final Rect bounds = mAttachInfo.mTmpInvalRect; |
| 2827 | if (getAccessibilityFocusedRect(bounds)) { |
| 2828 | final Drawable drawable = getAccessibilityFocusedDrawable(); |
| 2829 | if (drawable != null) { |
| 2830 | drawable.setBounds(bounds); |
| 2831 | drawable.draw(canvas); |
| 2832 | } |
| 2833 | } else if (mAttachInfo.mAccessibilityFocusDrawable != null) { |
| 2834 | mAttachInfo.mAccessibilityFocusDrawable.setBounds(0, 0, 0, 0); |
| 2835 | } |
| 2836 | } |
| 2837 | |
| 2838 | private boolean getAccessibilityFocusedRect(Rect bounds) { |
| 2839 | final AccessibilityManager manager = AccessibilityManager.getInstance(mView.mContext); |
| 2840 | if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) { |
| 2841 | return false; |
| 2842 | } |
| 2843 | |
| 2844 | final View host = mAccessibilityFocusedHost; |
| 2845 | if (host == null || host.mAttachInfo == null) { |
| 2846 | return false; |
| 2847 | } |
| 2848 | |
| 2849 | final AccessibilityNodeProvider provider = host.getAccessibilityNodeProvider(); |
| 2850 | if (provider == null) { |
Svetoslav | ded133c | 2015-01-30 20:28:41 -0800 | [diff] [blame] | 2851 | host.getBoundsOnScreen(bounds, true); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2852 | } else if (mAccessibilityFocusedVirtualView != null) { |
| 2853 | mAccessibilityFocusedVirtualView.getBoundsInScreen(bounds); |
| 2854 | } else { |
| 2855 | return false; |
| 2856 | } |
| 2857 | |
Alan Viverette | 2232add | 2015-05-26 15:24:18 -0700 | [diff] [blame] | 2858 | // Transform the rect into window-relative coordinates. |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2859 | final AttachInfo attachInfo = mAttachInfo; |
Alan Viverette | 2232add | 2015-05-26 15:24:18 -0700 | [diff] [blame] | 2860 | bounds.offset(0, attachInfo.mViewRootImpl.mScrollY); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2861 | bounds.offset(-attachInfo.mWindowLeft, -attachInfo.mWindowTop); |
Doris Liu | 9607fbe | 2015-05-28 17:17:28 -0700 | [diff] [blame] | 2862 | if (!bounds.intersect(0, 0, attachInfo.mViewRootImpl.mWidth, |
| 2863 | attachInfo.mViewRootImpl.mHeight)) { |
| 2864 | // If no intersection, set bounds to empty. |
| 2865 | bounds.setEmpty(); |
| 2866 | } |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2867 | return !bounds.isEmpty(); |
| 2868 | } |
| 2869 | |
| 2870 | private Drawable getAccessibilityFocusedDrawable() { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2871 | // Lazily load the accessibility focus drawable. |
| 2872 | if (mAttachInfo.mAccessibilityFocusDrawable == null) { |
Alan Viverette | f6cf1a0 | 2014-08-11 14:13:02 -0700 | [diff] [blame] | 2873 | final TypedValue value = new TypedValue(); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2874 | final boolean resolved = mView.mContext.getTheme().resolveAttribute( |
| 2875 | R.attr.accessibilityFocusedDrawable, value, true); |
| 2876 | if (resolved) { |
| 2877 | mAttachInfo.mAccessibilityFocusDrawable = |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 2878 | mView.mContext.getDrawable(value.resourceId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2879 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2880 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2881 | return mAttachInfo.mAccessibilityFocusDrawable; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2882 | } |
| 2883 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2884 | boolean scrollToRectOrFocus(Rect rectangle, boolean immediate) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2885 | final Rect ci = mAttachInfo.mContentInsets; |
| 2886 | final Rect vi = mAttachInfo.mVisibleInsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | int scrollY = 0; |
| 2888 | boolean handled = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2889 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2890 | if (vi.left > ci.left || vi.top > ci.top |
| 2891 | || vi.right > ci.right || vi.bottom > ci.bottom) { |
| 2892 | // We'll assume that we aren't going to change the scroll |
| 2893 | // offset, since we want to avoid that unless it is actually |
| 2894 | // going to make the focus visible... otherwise we scroll |
| 2895 | // all over the place. |
| 2896 | scrollY = mScrollY; |
| 2897 | // We can be called for two different situations: during a draw, |
| 2898 | // to update the scroll position if the focus has changed (in which |
| 2899 | // case 'rectangle' is null), or in response to a |
| 2900 | // requestChildRectangleOnScreen() call (in which case 'rectangle' |
| 2901 | // is non-null and we just want to scroll to whatever that |
| 2902 | // rectangle is). |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 2903 | final View focus = mView.findFocus(); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2904 | if (focus == null) { |
Romain Guy | e8b1652 | 2009-07-14 13:06:42 -0700 | [diff] [blame] | 2905 | return false; |
| 2906 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2907 | View lastScrolledFocus = (mLastScrolledFocus != null) ? mLastScrolledFocus.get() : null; |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 2908 | if (focus != lastScrolledFocus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2909 | // If the focus has changed, then ignore any requests to scroll |
| 2910 | // to a rectangle; first we want to make sure the entire focus |
| 2911 | // view is visible. |
| 2912 | rectangle = null; |
| 2913 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2914 | 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] | 2915 | + " rectangle=" + rectangle + " ci=" + ci |
| 2916 | + " vi=" + vi); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2917 | if (focus == lastScrolledFocus && !mScrollMayChange && rectangle == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2918 | // Optimization: if the focus hasn't changed since last |
| 2919 | // time, and no layout has happened, then just leave things |
| 2920 | // as they are. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2921 | 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] | 2922 | + mScrollY + " vi=" + vi.toShortString()); |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 2923 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2924 | // We need to determine if the currently focused view is |
| 2925 | // within the visible part of the window and, if not, apply |
| 2926 | // a pan so it can be seen. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2927 | mLastScrolledFocus = new WeakReference<View>(focus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2928 | mScrollMayChange = false; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2929 | 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] | 2930 | // Try to find the rectangle from the focus view. |
| 2931 | if (focus.getGlobalVisibleRect(mVisRect, null)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2932 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Root w=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2933 | + mView.getWidth() + " h=" + mView.getHeight() |
| 2934 | + " ci=" + ci.toShortString() |
| 2935 | + " vi=" + vi.toShortString()); |
| 2936 | if (rectangle == null) { |
| 2937 | focus.getFocusedRect(mTempRect); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2938 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Focus " + focus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2939 | + ": focusRect=" + mTempRect.toShortString()); |
Dianne Hackborn | 1c6a894 | 2010-03-23 16:34:20 -0700 | [diff] [blame] | 2940 | if (mView instanceof ViewGroup) { |
| 2941 | ((ViewGroup) mView).offsetDescendantRectToMyCoords( |
| 2942 | focus, mTempRect); |
| 2943 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2944 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2945 | "Focus in window: focusRect=" |
| 2946 | + mTempRect.toShortString() |
| 2947 | + " visRect=" + mVisRect.toShortString()); |
| 2948 | } else { |
| 2949 | mTempRect.set(rectangle); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2950 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2951 | "Request scroll to rect: " |
| 2952 | + mTempRect.toShortString() |
| 2953 | + " visRect=" + mVisRect.toShortString()); |
| 2954 | } |
| 2955 | if (mTempRect.intersect(mVisRect)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2956 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2957 | "Focus window visible rect: " |
| 2958 | + mTempRect.toShortString()); |
| 2959 | if (mTempRect.height() > |
| 2960 | (mView.getHeight()-vi.top-vi.bottom)) { |
| 2961 | // If the focus simply is not going to fit, then |
| 2962 | // best is probably just to leave things as-is. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2963 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2964 | "Too tall; leaving scrollY=" + scrollY); |
| 2965 | } else if ((mTempRect.top-scrollY) < vi.top) { |
| 2966 | scrollY -= vi.top - (mTempRect.top-scrollY); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2967 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2968 | "Top covered; scrollY=" + scrollY); |
| 2969 | } else if ((mTempRect.bottom-scrollY) |
| 2970 | > (mView.getHeight()-vi.bottom)) { |
| 2971 | scrollY += (mTempRect.bottom-scrollY) |
| 2972 | - (mView.getHeight()-vi.bottom); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2973 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2974 | "Bottom covered; scrollY=" + scrollY); |
| 2975 | } |
| 2976 | handled = true; |
| 2977 | } |
| 2978 | } |
| 2979 | } |
| 2980 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2982 | if (scrollY != mScrollY) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2983 | 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] | 2984 | + mScrollY + " , new=" + scrollY); |
Derek Sollenberger | 8d94835 | 2015-07-16 09:27:59 -0400 | [diff] [blame] | 2985 | if (!immediate) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | if (mScroller == null) { |
| 2987 | mScroller = new Scroller(mView.getContext()); |
| 2988 | } |
| 2989 | mScroller.startScroll(0, mScrollY, 0, scrollY-mScrollY); |
| 2990 | } else if (mScroller != null) { |
| 2991 | mScroller.abortAnimation(); |
| 2992 | } |
| 2993 | mScrollY = scrollY; |
| 2994 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2995 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2996 | return handled; |
| 2997 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2998 | |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 2999 | /** |
| 3000 | * @hide |
| 3001 | */ |
| 3002 | public View getAccessibilityFocusedHost() { |
| 3003 | return mAccessibilityFocusedHost; |
| 3004 | } |
| 3005 | |
| 3006 | /** |
| 3007 | * @hide |
| 3008 | */ |
| 3009 | public AccessibilityNodeInfo getAccessibilityFocusedVirtualView() { |
| 3010 | return mAccessibilityFocusedVirtualView; |
| 3011 | } |
| 3012 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3013 | void setAccessibilityFocus(View view, AccessibilityNodeInfo node) { |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3014 | // If we have a virtual view with accessibility focus we need |
| 3015 | // to clear the focus and invalidate the virtual view bounds. |
| 3016 | if (mAccessibilityFocusedVirtualView != null) { |
| 3017 | |
| 3018 | AccessibilityNodeInfo focusNode = mAccessibilityFocusedVirtualView; |
| 3019 | View focusHost = mAccessibilityFocusedHost; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3020 | |
| 3021 | // Wipe the state of the current accessibility focus since |
| 3022 | // the call into the provider to clear accessibility focus |
| 3023 | // will fire an accessibility event which will end up calling |
| 3024 | // this method and we want to have clean state when this |
| 3025 | // invocation happens. |
| 3026 | mAccessibilityFocusedHost = null; |
| 3027 | mAccessibilityFocusedVirtualView = null; |
| 3028 | |
Alan Viverette | 239a0c0 | 2013-05-07 17:17:35 -0700 | [diff] [blame] | 3029 | // Clear accessibility focus on the host after clearing state since |
| 3030 | // this method may be reentrant. |
| 3031 | focusHost.clearAccessibilityFocusNoCallbacks(); |
| 3032 | |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3033 | AccessibilityNodeProvider provider = focusHost.getAccessibilityNodeProvider(); |
| 3034 | if (provider != null) { |
| 3035 | // Invalidate the area of the cleared accessibility focus. |
| 3036 | focusNode.getBoundsInParent(mTempRect); |
| 3037 | focusHost.invalidate(mTempRect); |
| 3038 | // Clear accessibility focus in the virtual node. |
| 3039 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 3040 | focusNode.getSourceNodeId()); |
| 3041 | provider.performAction(virtualNodeId, |
| 3042 | AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null); |
| 3043 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3044 | focusNode.recycle(); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3045 | } |
| 3046 | if (mAccessibilityFocusedHost != null) { |
| 3047 | // Clear accessibility focus in the view. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3048 | mAccessibilityFocusedHost.clearAccessibilityFocusNoCallbacks(); |
| 3049 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3050 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3051 | // Set the new focus host and node. |
| 3052 | mAccessibilityFocusedHost = view; |
| 3053 | mAccessibilityFocusedVirtualView = node; |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 3054 | |
| 3055 | if (mAttachInfo.mHardwareRenderer != null) { |
| 3056 | mAttachInfo.mHardwareRenderer.invalidateRoot(); |
| 3057 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3060 | void setPointerCapture(View view) { |
| 3061 | if (!mAttachInfo.mHasWindowFocus) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3062 | Log.w(mTag, "Can't set capture if it's not focused."); |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3063 | return; |
| 3064 | } |
| 3065 | if (mCapturingView == view) { |
| 3066 | return; |
| 3067 | } |
| 3068 | mCapturingView = view; |
| 3069 | InputManager.getInstance().setPointerIconDetached(true); |
| 3070 | } |
| 3071 | |
| 3072 | void releasePointerCapture(View view) { |
| 3073 | if (mCapturingView != view || mCapturingView == null) { |
| 3074 | return; |
| 3075 | } |
| 3076 | |
| 3077 | mCapturingView = null; |
| 3078 | InputManager.getInstance().setPointerIconDetached(false); |
| 3079 | } |
| 3080 | |
| 3081 | boolean hasPointerCapture(View view) { |
| 3082 | return view != null && mCapturingView == view; |
| 3083 | } |
| 3084 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3085 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3086 | public void requestChildFocus(View child, View focused) { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3087 | if (DEBUG_INPUT_RESIZE) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3088 | Log.v(mTag, "Request child focus: focus now " + focused); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3089 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3090 | checkThread(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3091 | scheduleTraversals(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3092 | } |
| 3093 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3094 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3095 | public void clearChildFocus(View child) { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3096 | if (DEBUG_INPUT_RESIZE) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3097 | Log.v(mTag, "Clearing child focus"); |
Amith Yamasani | 73eb97f | 2012-02-14 15:45:15 -0800 | [diff] [blame] | 3098 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3099 | checkThread(); |
| 3100 | scheduleTraversals(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3101 | } |
Amith Yamasani | 73eb97f | 2012-02-14 15:45:15 -0800 | [diff] [blame] | 3102 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3103 | @Override |
| 3104 | public ViewParent getParentForAccessibility() { |
| 3105 | return null; |
| 3106 | } |
| 3107 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3108 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3109 | public void focusableViewAvailable(View v) { |
| 3110 | checkThread(); |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3111 | if (mView != null) { |
| 3112 | if (!mView.hasFocus()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3113 | v.requestFocus(); |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3114 | } else { |
| 3115 | // the one case where will transfer focus away from the current one |
| 3116 | // is if the current view is a view group that prefers to give focus |
| 3117 | // to its children first AND the view is a descendant of it. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3118 | View focused = mView.findFocus(); |
| 3119 | if (focused instanceof ViewGroup) { |
| 3120 | ViewGroup group = (ViewGroup) focused; |
| 3121 | if (group.getDescendantFocusability() == ViewGroup.FOCUS_AFTER_DESCENDANTS |
| 3122 | && isViewDescendantOf(v, focused)) { |
| 3123 | v.requestFocus(); |
| 3124 | } |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3125 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3126 | } |
| 3127 | } |
| 3128 | } |
| 3129 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3130 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3131 | public void recomputeViewAttributes(View child) { |
| 3132 | checkThread(); |
| 3133 | if (mView == child) { |
| 3134 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 3135 | if (!mWillDrawSoon) { |
| 3136 | scheduleTraversals(); |
| 3137 | } |
| 3138 | } |
| 3139 | } |
| 3140 | |
| 3141 | void dispatchDetachedFromWindow() { |
Romain Guy | 90fc03b | 2011-01-16 13:07:15 -0800 | [diff] [blame] | 3142 | if (mView != null && mView.mAttachInfo != null) { |
Dianne Hackborn | 961cae9 | 2013-03-20 14:59:43 -0700 | [diff] [blame] | 3143 | mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3144 | mView.dispatchDetachedFromWindow(); |
| 3145 | } |
| 3146 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3147 | mAccessibilityInteractionConnectionManager.ensureNoConnection(); |
| 3148 | mAccessibilityManager.removeAccessibilityStateChangeListener( |
| 3149 | mAccessibilityInteractionConnectionManager); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 3150 | mAccessibilityManager.removeHighTextContrastStateChangeListener( |
| 3151 | mHighContrastTextManager); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 3152 | removeSendWindowContentChangedCallback(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3153 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3154 | destroyHardwareRenderer(); |
| 3155 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3156 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3157 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 3158 | mView.assignParent(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3159 | mView = null; |
| 3160 | mAttachInfo.mRootView = null; |
| 3161 | |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3162 | if (mCapturingView != null) { |
| 3163 | releasePointerCapture(mCapturingView); |
| 3164 | } |
| 3165 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 3166 | mSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3167 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3168 | if (mInputQueueCallback != null && mInputQueue != null) { |
| 3169 | mInputQueueCallback.onInputQueueDestroyed(mInputQueue); |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3170 | mInputQueue.dispose(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3171 | mInputQueueCallback = null; |
| 3172 | mInputQueue = null; |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3173 | } |
| 3174 | if (mInputEventReceiver != null) { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3175 | mInputEventReceiver.dispose(); |
| 3176 | mInputEventReceiver = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3177 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3178 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3179 | mWindowSession.remove(mWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3180 | } catch (RemoteException e) { |
| 3181 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3182 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3183 | // Dispose the input channel after removing the window so the Window Manager |
| 3184 | // doesn't interpret the input channel being closed as an abnormal termination. |
| 3185 | if (mInputChannel != null) { |
| 3186 | mInputChannel.dispose(); |
| 3187 | mInputChannel = null; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3188 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3189 | |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 3190 | mDisplayManager.unregisterDisplayListener(mDisplayListener); |
| 3191 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 3192 | unscheduleTraversals(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3193 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3194 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3195 | void updateConfiguration(Configuration config, boolean force) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3196 | if (DEBUG_CONFIGURATION) Log.v(mTag, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3197 | "Applying new config to window " |
| 3198 | + mWindowAttributes.getTitle() |
| 3199 | + ": " + config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3200 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 3201 | CompatibilityInfo ci = mDisplayAdjustments.getCompatibilityInfo(); |
| 3202 | if (!ci.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3203 | config = new Configuration(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3204 | ci.applyToConfiguration(mNoncompatDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3205 | } |
| 3206 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3207 | synchronized (sConfigCallbacks) { |
| 3208 | for (int i=sConfigCallbacks.size()-1; i>=0; i--) { |
| 3209 | sConfigCallbacks.get(i).onConfigurationChanged(config); |
| 3210 | } |
| 3211 | } |
| 3212 | if (mView != null) { |
| 3213 | // At this point the resources have been updated to |
| 3214 | // have the most recent config, whatever that is. Use |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3215 | // the one in them which may be newer. |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3216 | config = mView.getResources().getConfiguration(); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3217 | if (force || mLastConfiguration.diff(config) != 0) { |
Fabrice Di Meglio | cf12897 | 2012-10-16 20:51:12 -0700 | [diff] [blame] | 3218 | final int lastLayoutDirection = mLastConfiguration.getLayoutDirection(); |
| 3219 | final int currentLayoutDirection = config.getLayoutDirection(); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3220 | mLastConfiguration.setTo(config); |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 3221 | if (lastLayoutDirection != currentLayoutDirection && |
| 3222 | mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) { |
Fabrice Di Meglio | cf12897 | 2012-10-16 20:51:12 -0700 | [diff] [blame] | 3223 | mView.setLayoutDirection(currentLayoutDirection); |
| 3224 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3225 | mView.dispatchConfigurationChanged(config); |
| 3226 | } |
| 3227 | } |
| 3228 | } |
John Reck | 05e8584 | 2014-04-23 14:48:28 -0700 | [diff] [blame] | 3229 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3230 | /** |
| 3231 | * Return true if child is an ancestor of parent, (or equal to the parent). |
| 3232 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3233 | public static boolean isViewDescendantOf(View child, View parent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3234 | if (child == parent) { |
| 3235 | return true; |
| 3236 | } |
| 3237 | |
| 3238 | final ViewParent theParent = child.getParent(); |
| 3239 | return (theParent instanceof ViewGroup) && isViewDescendantOf((View) theParent, parent); |
| 3240 | } |
| 3241 | |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 3242 | private static void forceLayout(View view) { |
| 3243 | view.forceLayout(); |
| 3244 | if (view instanceof ViewGroup) { |
| 3245 | ViewGroup group = (ViewGroup) view; |
| 3246 | final int count = group.getChildCount(); |
| 3247 | for (int i = 0; i < count; i++) { |
| 3248 | forceLayout(group.getChildAt(i)); |
| 3249 | } |
| 3250 | } |
| 3251 | } |
| 3252 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3253 | private final static int MSG_INVALIDATE = 1; |
| 3254 | private final static int MSG_INVALIDATE_RECT = 2; |
| 3255 | private final static int MSG_DIE = 3; |
| 3256 | private final static int MSG_RESIZED = 4; |
| 3257 | private final static int MSG_RESIZED_REPORT = 5; |
| 3258 | private final static int MSG_WINDOW_FOCUS_CHANGED = 6; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3259 | private final static int MSG_DISPATCH_INPUT_EVENT = 7; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3260 | private final static int MSG_DISPATCH_APP_VISIBILITY = 8; |
| 3261 | private final static int MSG_DISPATCH_GET_NEW_SURFACE = 9; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3262 | private final static int MSG_DISPATCH_KEY_FROM_IME = 11; |
| 3263 | private final static int MSG_FINISH_INPUT_CONNECTION = 12; |
| 3264 | private final static int MSG_CHECK_FOCUS = 13; |
| 3265 | private final static int MSG_CLOSE_SYSTEM_DIALOGS = 14; |
| 3266 | private final static int MSG_DISPATCH_DRAG_EVENT = 15; |
| 3267 | private final static int MSG_DISPATCH_DRAG_LOCATION_EVENT = 16; |
| 3268 | private final static int MSG_DISPATCH_SYSTEM_UI_VISIBILITY = 17; |
| 3269 | private final static int MSG_UPDATE_CONFIGURATION = 18; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3270 | private final static int MSG_PROCESS_INPUT_EVENTS = 19; |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 3271 | private final static int MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST = 21; |
Jorim Jaggi | 827e0fa | 2015-05-07 11:41:41 -0700 | [diff] [blame] | 3272 | private final static int MSG_INVALIDATE_WORLD = 22; |
| 3273 | private final static int MSG_WINDOW_MOVED = 23; |
| 3274 | private final static int MSG_SYNTHESIZE_INPUT_EVENT = 24; |
| 3275 | private final static int MSG_DISPATCH_WINDOW_SHOWN = 25; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 3276 | private final static int MSG_REQUEST_KEYBOARD_SHORTCUTS = 26; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3277 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3278 | final class ViewRootHandler extends Handler { |
| 3279 | @Override |
| 3280 | public String getMessageName(Message message) { |
| 3281 | switch (message.what) { |
| 3282 | case MSG_INVALIDATE: |
| 3283 | return "MSG_INVALIDATE"; |
| 3284 | case MSG_INVALIDATE_RECT: |
| 3285 | return "MSG_INVALIDATE_RECT"; |
| 3286 | case MSG_DIE: |
| 3287 | return "MSG_DIE"; |
| 3288 | case MSG_RESIZED: |
| 3289 | return "MSG_RESIZED"; |
| 3290 | case MSG_RESIZED_REPORT: |
| 3291 | return "MSG_RESIZED_REPORT"; |
| 3292 | case MSG_WINDOW_FOCUS_CHANGED: |
| 3293 | return "MSG_WINDOW_FOCUS_CHANGED"; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3294 | case MSG_DISPATCH_INPUT_EVENT: |
| 3295 | return "MSG_DISPATCH_INPUT_EVENT"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3296 | case MSG_DISPATCH_APP_VISIBILITY: |
| 3297 | return "MSG_DISPATCH_APP_VISIBILITY"; |
| 3298 | case MSG_DISPATCH_GET_NEW_SURFACE: |
| 3299 | return "MSG_DISPATCH_GET_NEW_SURFACE"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3300 | case MSG_DISPATCH_KEY_FROM_IME: |
| 3301 | return "MSG_DISPATCH_KEY_FROM_IME"; |
| 3302 | case MSG_FINISH_INPUT_CONNECTION: |
| 3303 | return "MSG_FINISH_INPUT_CONNECTION"; |
| 3304 | case MSG_CHECK_FOCUS: |
| 3305 | return "MSG_CHECK_FOCUS"; |
| 3306 | case MSG_CLOSE_SYSTEM_DIALOGS: |
| 3307 | return "MSG_CLOSE_SYSTEM_DIALOGS"; |
| 3308 | case MSG_DISPATCH_DRAG_EVENT: |
| 3309 | return "MSG_DISPATCH_DRAG_EVENT"; |
| 3310 | case MSG_DISPATCH_DRAG_LOCATION_EVENT: |
| 3311 | return "MSG_DISPATCH_DRAG_LOCATION_EVENT"; |
| 3312 | case MSG_DISPATCH_SYSTEM_UI_VISIBILITY: |
| 3313 | return "MSG_DISPATCH_SYSTEM_UI_VISIBILITY"; |
| 3314 | case MSG_UPDATE_CONFIGURATION: |
| 3315 | return "MSG_UPDATE_CONFIGURATION"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3316 | case MSG_PROCESS_INPUT_EVENTS: |
| 3317 | return "MSG_PROCESS_INPUT_EVENTS"; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 3318 | case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST: |
| 3319 | return "MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST"; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 3320 | case MSG_WINDOW_MOVED: |
| 3321 | return "MSG_WINDOW_MOVED"; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 3322 | case MSG_SYNTHESIZE_INPUT_EVENT: |
| 3323 | return "MSG_SYNTHESIZE_INPUT_EVENT"; |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 3324 | case MSG_DISPATCH_WINDOW_SHOWN: |
| 3325 | return "MSG_DISPATCH_WINDOW_SHOWN"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3326 | } |
| 3327 | return super.getMessageName(message); |
Romain Guy | f928469 | 2011-07-13 18:46:21 -0700 | [diff] [blame] | 3328 | } |
Romain Guy | f928469 | 2011-07-13 18:46:21 -0700 | [diff] [blame] | 3329 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3330 | @Override |
| 3331 | public void handleMessage(Message msg) { |
| 3332 | switch (msg.what) { |
| 3333 | case MSG_INVALIDATE: |
| 3334 | ((View) msg.obj).invalidate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3335 | break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3336 | case MSG_INVALIDATE_RECT: |
| 3337 | final View.AttachInfo.InvalidateInfo info = (View.AttachInfo.InvalidateInfo) msg.obj; |
| 3338 | info.target.invalidate(info.left, info.top, info.right, info.bottom); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 3339 | info.recycle(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3340 | break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3341 | case MSG_PROCESS_INPUT_EVENTS: |
| 3342 | mProcessInputEventsScheduled = false; |
| 3343 | doProcessInputEvents(); |
| 3344 | break; |
| 3345 | case MSG_DISPATCH_APP_VISIBILITY: |
| 3346 | handleAppVisibility(msg.arg1 != 0); |
| 3347 | break; |
| 3348 | case MSG_DISPATCH_GET_NEW_SURFACE: |
| 3349 | handleGetNewSurface(); |
| 3350 | break; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3351 | case MSG_RESIZED: { |
| 3352 | // Recycled in the fall through... |
| 3353 | SomeArgs args = (SomeArgs) msg.obj; |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 3354 | if (mWinFrame.equals(args.arg1) |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3355 | && mPendingOverscanInsets.equals(args.arg5) |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 3356 | && mPendingContentInsets.equals(args.arg2) |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3357 | && mPendingStableInsets.equals(args.arg6) |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 3358 | && mPendingVisibleInsets.equals(args.arg3) |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3359 | && mPendingOutsets.equals(args.arg7) |
Jorim Jaggi | 0fe356e | 2016-01-05 14:43:25 +0100 | [diff] [blame] | 3360 | && mPendingBackDropFrame.equals(args.arg8) |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 3361 | && args.arg4 == null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3362 | break; |
Romain Guy | cdb8667 | 2010-03-18 18:54:50 -0700 | [diff] [blame] | 3363 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3364 | } // fall through... |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3365 | case MSG_RESIZED_REPORT: |
| 3366 | if (mAdded) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3367 | SomeArgs args = (SomeArgs) msg.obj; |
| 3368 | |
| 3369 | Configuration config = (Configuration) args.arg4; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3370 | if (config != null) { |
| 3371 | updateConfiguration(config, false); |
| 3372 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3373 | |
| 3374 | mWinFrame.set((Rect) args.arg1); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3375 | mPendingOverscanInsets.set((Rect) args.arg5); |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3376 | mPendingContentInsets.set((Rect) args.arg2); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3377 | mPendingStableInsets.set((Rect) args.arg6); |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3378 | mPendingVisibleInsets.set((Rect) args.arg3); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3379 | mPendingOutsets.set((Rect) args.arg7); |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 3380 | mPendingBackDropFrame.set((Rect) args.arg8); |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3381 | |
| 3382 | args.recycle(); |
| 3383 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3384 | if (msg.what == MSG_RESIZED_REPORT) { |
| 3385 | mReportNextDraw = true; |
| 3386 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 3387 | |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 3388 | if (mView != null) { |
| 3389 | forceLayout(mView); |
| 3390 | } |
| 3391 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3392 | requestLayout(); |
| 3393 | } |
| 3394 | break; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 3395 | case MSG_WINDOW_MOVED: |
| 3396 | if (mAdded) { |
| 3397 | final int w = mWinFrame.width(); |
| 3398 | final int h = mWinFrame.height(); |
| 3399 | final int l = msg.arg1; |
| 3400 | final int t = msg.arg2; |
| 3401 | mWinFrame.left = l; |
| 3402 | mWinFrame.right = l + w; |
| 3403 | mWinFrame.top = t; |
| 3404 | mWinFrame.bottom = t + h; |
| 3405 | |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 3406 | mPendingBackDropFrame.set(mWinFrame); |
| 3407 | |
Jorim Jaggi | 844e171 | 2016-01-13 17:39:25 -0800 | [diff] [blame] | 3408 | // Suppress layouts during resizing - a correct layout will happen when resizing |
| 3409 | // is done, and this just increases system load. |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3410 | boolean isDockedDivider = mWindowAttributes.type == TYPE_DOCK_DIVIDER; |
| 3411 | boolean suppress = (mDragResizing && mResizeMode == RESIZE_MODE_DOCKED_DIVIDER) |
| 3412 | || isDockedDivider; |
Jorim Jaggi | 844e171 | 2016-01-13 17:39:25 -0800 | [diff] [blame] | 3413 | if (!suppress) { |
| 3414 | if (mView != null) { |
| 3415 | forceLayout(mView); |
| 3416 | } |
| 3417 | requestLayout(); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3418 | } else { |
| 3419 | maybeHandleWindowMove(mWinFrame); |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 3420 | } |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 3421 | } |
| 3422 | break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3423 | case MSG_WINDOW_FOCUS_CHANGED: { |
| 3424 | if (mAdded) { |
| 3425 | boolean hasWindowFocus = msg.arg1 != 0; |
| 3426 | mAttachInfo.mHasWindowFocus = hasWindowFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3427 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3428 | profileRendering(hasWindowFocus); |
| 3429 | |
| 3430 | if (hasWindowFocus) { |
| 3431 | boolean inTouchMode = msg.arg2 != 0; |
| 3432 | ensureTouchModeLocally(inTouchMode); |
| 3433 | |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 3434 | if (mAttachInfo.mHardwareRenderer != null && mSurface.isValid()){ |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3435 | mFullRedrawNeeded = true; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3436 | try { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3437 | final WindowManager.LayoutParams lp = mWindowAttributes; |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 3438 | final Rect surfaceInsets = lp != null ? lp.surfaceInsets : null; |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3439 | mAttachInfo.mHardwareRenderer.initializeIfNeeded( |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 3440 | mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3441 | } catch (OutOfResourcesException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3442 | Log.e(mTag, "OutOfResourcesException locking surface", e); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3443 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3444 | if (!mWindowSession.outOfMemory(mWindow)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3445 | Slog.w(mTag, "No processes killed for memory; killing self"); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3446 | Process.killProcess(Process.myPid()); |
| 3447 | } |
| 3448 | } catch (RemoteException ex) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3449 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3450 | // Retry in a bit. |
| 3451 | sendMessageDelayed(obtainMessage(msg.what, msg.arg1, msg.arg2), 500); |
| 3452 | return; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3453 | } |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3454 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3455 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3456 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3457 | mLastWasImTarget = WindowManager.LayoutParams |
| 3458 | .mayUseInputMethod(mWindowAttributes.flags); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3459 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3460 | InputMethodManager imm = InputMethodManager.peekInstance(); |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 3461 | if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) { |
| 3462 | imm.onPreWindowFocus(mView, hasWindowFocus); |
| 3463 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3464 | if (mView != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3465 | mAttachInfo.mKeyDispatchState.reset(); |
| 3466 | mView.dispatchWindowFocusChanged(hasWindowFocus); |
Dianne Hackborn | 961cae9 | 2013-03-20 14:59:43 -0700 | [diff] [blame] | 3467 | mAttachInfo.mTreeObserver.dispatchOnWindowFocusChange(hasWindowFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3468 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3469 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3470 | // Note: must be done after the focus change callbacks, |
| 3471 | // so all of the view state is set up correctly. |
| 3472 | if (hasWindowFocus) { |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3473 | if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) { |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 3474 | imm.onPostWindowFocus(mView, mView.findFocus(), |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3475 | mWindowAttributes.softInputMode, |
| 3476 | !mHasHadWindowFocus, mWindowAttributes.flags); |
| 3477 | } |
| 3478 | // Clear the forward bit. We can just do this directly, since |
| 3479 | // the window manager doesn't care about it. |
| 3480 | mWindowAttributes.softInputMode &= |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3481 | ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3482 | ((WindowManager.LayoutParams)mView.getLayoutParams()) |
| 3483 | .softInputMode &= |
| 3484 | ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION; |
| 3485 | mHasHadWindowFocus = true; |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3486 | } else if (mCapturingView != null) { |
| 3487 | releasePointerCapture(mCapturingView); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3488 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3489 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3490 | } break; |
| 3491 | case MSG_DIE: |
| 3492 | doDie(); |
| 3493 | break; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3494 | case MSG_DISPATCH_INPUT_EVENT: { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 3495 | SomeArgs args = (SomeArgs)msg.obj; |
| 3496 | InputEvent event = (InputEvent)args.arg1; |
| 3497 | InputEventReceiver receiver = (InputEventReceiver)args.arg2; |
| 3498 | enqueueInputEvent(event, receiver, 0, true); |
| 3499 | args.recycle(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3500 | } break; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 3501 | case MSG_SYNTHESIZE_INPUT_EVENT: { |
| 3502 | InputEvent event = (InputEvent)msg.obj; |
| 3503 | enqueueInputEvent(event, null, QueuedInputEvent.FLAG_UNHANDLED, true); |
| 3504 | } break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3505 | case MSG_DISPATCH_KEY_FROM_IME: { |
| 3506 | if (LOCAL_LOGV) Log.v( |
| 3507 | TAG, "Dispatching key " |
| 3508 | + msg.obj + " from IME to " + mView); |
| 3509 | KeyEvent event = (KeyEvent)msg.obj; |
| 3510 | if ((event.getFlags()&KeyEvent.FLAG_FROM_SYSTEM) != 0) { |
| 3511 | // The IME is trying to say this event is from the |
| 3512 | // system! Bad bad bad! |
| 3513 | //noinspection UnusedAssignment |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 3514 | event = KeyEvent.changeFlags(event, event.getFlags() & |
| 3515 | ~KeyEvent.FLAG_FROM_SYSTEM); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3516 | } |
| 3517 | enqueueInputEvent(event, null, QueuedInputEvent.FLAG_DELIVER_POST_IME, true); |
| 3518 | } break; |
| 3519 | case MSG_FINISH_INPUT_CONNECTION: { |
| 3520 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 3521 | if (imm != null) { |
| 3522 | imm.reportFinishInputConnection((InputConnection)msg.obj); |
| 3523 | } |
| 3524 | } break; |
| 3525 | case MSG_CHECK_FOCUS: { |
| 3526 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 3527 | if (imm != null) { |
| 3528 | imm.checkFocus(); |
| 3529 | } |
| 3530 | } break; |
| 3531 | case MSG_CLOSE_SYSTEM_DIALOGS: { |
| 3532 | if (mView != null) { |
| 3533 | mView.onCloseSystemDialogs((String)msg.obj); |
| 3534 | } |
| 3535 | } break; |
| 3536 | case MSG_DISPATCH_DRAG_EVENT: |
| 3537 | case MSG_DISPATCH_DRAG_LOCATION_EVENT: { |
| 3538 | DragEvent event = (DragEvent)msg.obj; |
| 3539 | event.mLocalState = mLocalDragState; // only present when this app called startDrag() |
| 3540 | handleDragEvent(event); |
| 3541 | } break; |
| 3542 | case MSG_DISPATCH_SYSTEM_UI_VISIBILITY: { |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 3543 | handleDispatchSystemUiVisibilityChanged((SystemUiVisibilityInfo) msg.obj); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3544 | } break; |
| 3545 | case MSG_UPDATE_CONFIGURATION: { |
| 3546 | Configuration config = (Configuration)msg.obj; |
| 3547 | if (config.isOtherSeqNewer(mLastConfiguration)) { |
| 3548 | config = mLastConfiguration; |
| 3549 | } |
| 3550 | updateConfiguration(config, false); |
| 3551 | } break; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 3552 | case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3553 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 3554 | } break; |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 3555 | case MSG_INVALIDATE_WORLD: { |
Romain Guy | f84208f | 2012-09-13 22:50:18 -0700 | [diff] [blame] | 3556 | if (mView != null) { |
| 3557 | invalidateWorld(mView); |
| 3558 | } |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 3559 | } break; |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 3560 | case MSG_DISPATCH_WINDOW_SHOWN: { |
| 3561 | handleDispatchWindowShown(); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 3562 | } break; |
| 3563 | case MSG_REQUEST_KEYBOARD_SHORTCUTS: { |
| 3564 | IResultReceiver receiver = (IResultReceiver) msg.obj; |
| 3565 | handleRequestKeyboardShortcuts(receiver); |
| 3566 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3567 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | } |
| 3569 | } |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 3570 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3571 | final ViewRootHandler mHandler = new ViewRootHandler(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3573 | /** |
| 3574 | * Something in the current window tells us we need to change the touch mode. For |
| 3575 | * example, we are not in touch mode, and the user touches the screen. |
| 3576 | * |
| 3577 | * If the touch mode has changed, tell the window manager, and handle it locally. |
| 3578 | * |
| 3579 | * @param inTouchMode Whether we want to be in touch mode. |
| 3580 | * @return True if the touch mode changed and focus changed was changed as a result |
| 3581 | */ |
| 3582 | boolean ensureTouchMode(boolean inTouchMode) { |
| 3583 | if (DBG) Log.d("touchmode", "ensureTouchMode(" + inTouchMode + "), current " |
| 3584 | + "touch mode is " + mAttachInfo.mInTouchMode); |
| 3585 | if (mAttachInfo.mInTouchMode == inTouchMode) return false; |
| 3586 | |
| 3587 | // tell the window manager |
| 3588 | try { |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3589 | if (!isInLocalFocusMode()) { |
| 3590 | mWindowSession.setInTouchMode(inTouchMode); |
| 3591 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3592 | } catch (RemoteException e) { |
| 3593 | throw new RuntimeException(e); |
| 3594 | } |
| 3595 | |
| 3596 | // handle the change |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3597 | return ensureTouchModeLocally(inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | /** |
| 3601 | * Ensure that the touch mode for this window is set, and if it is changing, |
| 3602 | * take the appropriate action. |
| 3603 | * @param inTouchMode Whether we want to be in touch mode. |
| 3604 | * @return True if the touch mode changed and focus changed was changed as a result |
| 3605 | */ |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3606 | private boolean ensureTouchModeLocally(boolean inTouchMode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3607 | if (DBG) Log.d("touchmode", "ensureTouchModeLocally(" + inTouchMode + "), current " |
| 3608 | + "touch mode is " + mAttachInfo.mInTouchMode); |
| 3609 | |
| 3610 | if (mAttachInfo.mInTouchMode == inTouchMode) return false; |
| 3611 | |
| 3612 | mAttachInfo.mInTouchMode = inTouchMode; |
| 3613 | mAttachInfo.mTreeObserver.dispatchOnTouchModeChanged(inTouchMode); |
| 3614 | |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3615 | return (inTouchMode) ? enterTouchMode() : leaveTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | private boolean enterTouchMode() { |
Alan Viverette | ed7821a | 2013-07-24 15:49:23 -0700 | [diff] [blame] | 3619 | if (mView != null && mView.hasFocus()) { |
| 3620 | // note: not relying on mFocusedView here because this could |
| 3621 | // be when the window is first being added, and mFocused isn't |
| 3622 | // set yet. |
| 3623 | final View focused = mView.findFocus(); |
| 3624 | if (focused != null && !focused.isFocusableInTouchMode()) { |
| 3625 | final ViewGroup ancestorToTakeFocus = findAncestorToTakeFocusInTouchMode(focused); |
| 3626 | if (ancestorToTakeFocus != null) { |
| 3627 | // there is an ancestor that wants focus after its |
| 3628 | // descendants that is focusable in touch mode.. give it |
| 3629 | // focus |
| 3630 | return ancestorToTakeFocus.requestFocus(); |
| 3631 | } else { |
Alan Viverette | 973f3b4 | 2013-08-13 16:57:28 -0700 | [diff] [blame] | 3632 | // There's nothing to focus. Clear and propagate through the |
| 3633 | // hierarchy, but don't attempt to place new focus. |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 3634 | focused.clearFocusInternal(null, true, false); |
Alan Viverette | ed7821a | 2013-07-24 15:49:23 -0700 | [diff] [blame] | 3635 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3636 | } |
| 3637 | } |
| 3638 | } |
| 3639 | return false; |
| 3640 | } |
| 3641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3642 | /** |
| 3643 | * Find an ancestor of focused that wants focus after its descendants and is |
| 3644 | * focusable in touch mode. |
| 3645 | * @param focused The currently focused view. |
| 3646 | * @return An appropriate view, or null if no such view exists. |
| 3647 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3648 | private static ViewGroup findAncestorToTakeFocusInTouchMode(View focused) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3649 | ViewParent parent = focused.getParent(); |
| 3650 | while (parent instanceof ViewGroup) { |
| 3651 | final ViewGroup vgParent = (ViewGroup) parent; |
| 3652 | if (vgParent.getDescendantFocusability() == ViewGroup.FOCUS_AFTER_DESCENDANTS |
| 3653 | && vgParent.isFocusableInTouchMode()) { |
| 3654 | return vgParent; |
| 3655 | } |
| 3656 | if (vgParent.isRootNamespace()) { |
| 3657 | return null; |
| 3658 | } else { |
| 3659 | parent = vgParent.getParent(); |
| 3660 | } |
| 3661 | } |
| 3662 | return null; |
| 3663 | } |
| 3664 | |
| 3665 | private boolean leaveTouchMode() { |
| 3666 | if (mView != null) { |
| 3667 | if (mView.hasFocus()) { |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3668 | View focusedView = mView.findFocus(); |
| 3669 | if (!(focusedView instanceof ViewGroup)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | // some view has focus, let it keep it |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 3671 | return false; |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3672 | } else if (((ViewGroup) focusedView).getDescendantFocusability() != |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3673 | ViewGroup.FOCUS_AFTER_DESCENDANTS) { |
| 3674 | // some view group has focus, and doesn't prefer its children |
| 3675 | // over itself for focus, so let them keep it. |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 3676 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3677 | } |
| 3678 | } |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 3679 | |
| 3680 | // find the best view to give focus to in this brave new non-touch-mode |
| 3681 | // world |
| 3682 | final View focused = focusSearch(null, View.FOCUS_DOWN); |
| 3683 | if (focused != null) { |
| 3684 | return focused.requestFocus(View.FOCUS_DOWN); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3685 | } |
| 3686 | } |
| 3687 | return false; |
| 3688 | } |
| 3689 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3690 | /** |
| 3691 | * Base class for implementing a stage in the chain of responsibility |
| 3692 | * for processing input events. |
| 3693 | * <p> |
| 3694 | * Events are delivered to the stage by the {@link #deliver} method. The stage |
| 3695 | * then has the choice of finishing the event or forwarding it to the next stage. |
| 3696 | * </p> |
| 3697 | */ |
| 3698 | abstract class InputStage { |
| 3699 | private final InputStage mNext; |
| 3700 | |
| 3701 | protected static final int FORWARD = 0; |
| 3702 | protected static final int FINISH_HANDLED = 1; |
| 3703 | protected static final int FINISH_NOT_HANDLED = 2; |
| 3704 | |
| 3705 | /** |
| 3706 | * Creates an input stage. |
| 3707 | * @param next The next stage to which events should be forwarded. |
| 3708 | */ |
| 3709 | public InputStage(InputStage next) { |
| 3710 | mNext = next; |
| 3711 | } |
| 3712 | |
| 3713 | /** |
| 3714 | * Delivers an event to be processed. |
| 3715 | */ |
| 3716 | public final void deliver(QueuedInputEvent q) { |
| 3717 | if ((q.mFlags & QueuedInputEvent.FLAG_FINISHED) != 0) { |
| 3718 | forward(q); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 3719 | } else if (shouldDropInputEvent(q)) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3720 | finish(q, false); |
| 3721 | } else { |
| 3722 | apply(q, onProcess(q)); |
| 3723 | } |
| 3724 | } |
| 3725 | |
| 3726 | /** |
| 3727 | * Marks the the input event as finished then forwards it to the next stage. |
| 3728 | */ |
| 3729 | protected void finish(QueuedInputEvent q, boolean handled) { |
| 3730 | q.mFlags |= QueuedInputEvent.FLAG_FINISHED; |
| 3731 | if (handled) { |
| 3732 | q.mFlags |= QueuedInputEvent.FLAG_FINISHED_HANDLED; |
| 3733 | } |
| 3734 | forward(q); |
| 3735 | } |
| 3736 | |
| 3737 | /** |
| 3738 | * Forwards the event to the next stage. |
| 3739 | */ |
| 3740 | protected void forward(QueuedInputEvent q) { |
| 3741 | onDeliverToNext(q); |
| 3742 | } |
| 3743 | |
| 3744 | /** |
| 3745 | * Applies a result code from {@link #onProcess} to the specified event. |
| 3746 | */ |
| 3747 | protected void apply(QueuedInputEvent q, int result) { |
| 3748 | if (result == FORWARD) { |
| 3749 | forward(q); |
| 3750 | } else if (result == FINISH_HANDLED) { |
| 3751 | finish(q, true); |
| 3752 | } else if (result == FINISH_NOT_HANDLED) { |
| 3753 | finish(q, false); |
| 3754 | } else { |
| 3755 | throw new IllegalArgumentException("Invalid result: " + result); |
| 3756 | } |
| 3757 | } |
| 3758 | |
| 3759 | /** |
| 3760 | * Called when an event is ready to be processed. |
| 3761 | * @return A result code indicating how the event was handled. |
| 3762 | */ |
| 3763 | protected int onProcess(QueuedInputEvent q) { |
| 3764 | return FORWARD; |
| 3765 | } |
| 3766 | |
| 3767 | /** |
| 3768 | * Called when an event is being delivered to the next stage. |
| 3769 | */ |
| 3770 | protected void onDeliverToNext(QueuedInputEvent q) { |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 3771 | if (DEBUG_INPUT_STAGES) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3772 | Log.v(mTag, "Done with " + getClass().getSimpleName() + ". " + q); |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 3773 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3774 | if (mNext != null) { |
| 3775 | mNext.deliver(q); |
| 3776 | } else { |
| 3777 | finishInputEvent(q); |
| 3778 | } |
| 3779 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 3780 | |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 3781 | protected boolean shouldDropInputEvent(QueuedInputEvent q) { |
| 3782 | if (mView == null || !mAdded) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3783 | 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] | 3784 | return true; |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 3785 | } else if ((!mAttachInfo.mHasWindowFocus |
| 3786 | && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) || mStopped |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 3787 | || mIsAmbientMode || (mPausedForTransition && !isBack(q.mEvent))) { |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 3788 | // This is a focus event and the window doesn't currently have input focus or |
| 3789 | // has stopped. This could be an event that came back from the previous stage |
| 3790 | // but the window has lost focus or stopped in the meantime. |
| 3791 | if (isTerminalInputEvent(q.mEvent)) { |
| 3792 | // Don't drop terminal input events, however mark them as canceled. |
| 3793 | q.mEvent.cancel(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3794 | Slog.w(mTag, "Cancelling event due to no window focus: " + q.mEvent); |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 3795 | return false; |
| 3796 | } |
| 3797 | |
| 3798 | // Drop non-terminal input events. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3799 | Slog.w(mTag, "Dropping event due to no window focus: " + q.mEvent); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 3800 | return true; |
| 3801 | } |
| 3802 | return false; |
| 3803 | } |
| 3804 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 3805 | void dump(String prefix, PrintWriter writer) { |
| 3806 | if (mNext != null) { |
| 3807 | mNext.dump(prefix, writer); |
| 3808 | } |
| 3809 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 3810 | |
| 3811 | private boolean isBack(InputEvent event) { |
| 3812 | if (event instanceof KeyEvent) { |
| 3813 | return ((KeyEvent) event).getKeyCode() == KeyEvent.KEYCODE_BACK; |
| 3814 | } else { |
| 3815 | return false; |
| 3816 | } |
| 3817 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3818 | } |
| 3819 | |
| 3820 | /** |
| 3821 | * Base class for implementing an input pipeline stage that supports |
| 3822 | * asynchronous and out-of-order processing of input events. |
| 3823 | * <p> |
| 3824 | * In addition to what a normal input stage can do, an asynchronous |
| 3825 | * input stage may also defer an input event that has been delivered to it |
| 3826 | * and finish or forward it later. |
| 3827 | * </p> |
| 3828 | */ |
| 3829 | abstract class AsyncInputStage extends InputStage { |
| 3830 | private final String mTraceCounter; |
| 3831 | |
| 3832 | private QueuedInputEvent mQueueHead; |
| 3833 | private QueuedInputEvent mQueueTail; |
| 3834 | private int mQueueLength; |
| 3835 | |
| 3836 | protected static final int DEFER = 3; |
| 3837 | |
| 3838 | /** |
| 3839 | * Creates an asynchronous input stage. |
| 3840 | * @param next The next stage to which events should be forwarded. |
| 3841 | * @param traceCounter The name of a counter to record the size of |
| 3842 | * the queue of pending events. |
| 3843 | */ |
| 3844 | public AsyncInputStage(InputStage next, String traceCounter) { |
| 3845 | super(next); |
| 3846 | mTraceCounter = traceCounter; |
| 3847 | } |
| 3848 | |
| 3849 | /** |
| 3850 | * Marks the event as deferred, which is to say that it will be handled |
| 3851 | * asynchronously. The caller is responsible for calling {@link #forward} |
| 3852 | * or {@link #finish} later when it is done handling the event. |
| 3853 | */ |
| 3854 | protected void defer(QueuedInputEvent q) { |
| 3855 | q.mFlags |= QueuedInputEvent.FLAG_DEFERRED; |
| 3856 | enqueue(q); |
| 3857 | } |
| 3858 | |
| 3859 | @Override |
| 3860 | protected void forward(QueuedInputEvent q) { |
| 3861 | // Clear the deferred flag. |
| 3862 | q.mFlags &= ~QueuedInputEvent.FLAG_DEFERRED; |
| 3863 | |
| 3864 | // Fast path if the queue is empty. |
| 3865 | QueuedInputEvent curr = mQueueHead; |
| 3866 | if (curr == null) { |
| 3867 | super.forward(q); |
| 3868 | return; |
| 3869 | } |
| 3870 | |
| 3871 | // Determine whether the event must be serialized behind any others |
| 3872 | // before it can be delivered to the next stage. This is done because |
| 3873 | // deferred events might be handled out of order by the stage. |
| 3874 | final int deviceId = q.mEvent.getDeviceId(); |
| 3875 | QueuedInputEvent prev = null; |
| 3876 | boolean blocked = false; |
| 3877 | while (curr != null && curr != q) { |
| 3878 | if (!blocked && deviceId == curr.mEvent.getDeviceId()) { |
| 3879 | blocked = true; |
| 3880 | } |
| 3881 | prev = curr; |
| 3882 | curr = curr.mNext; |
| 3883 | } |
| 3884 | |
| 3885 | // If the event is blocked, then leave it in the queue to be delivered later. |
| 3886 | // Note that the event might not yet be in the queue if it was not previously |
| 3887 | // deferred so we will enqueue it if needed. |
| 3888 | if (blocked) { |
| 3889 | if (curr == null) { |
| 3890 | enqueue(q); |
| 3891 | } |
| 3892 | return; |
| 3893 | } |
| 3894 | |
| 3895 | // The event is not blocked. Deliver it immediately. |
| 3896 | if (curr != null) { |
| 3897 | curr = curr.mNext; |
| 3898 | dequeue(q, prev); |
| 3899 | } |
| 3900 | super.forward(q); |
| 3901 | |
| 3902 | // Dequeuing this event may have unblocked successors. Deliver them. |
| 3903 | while (curr != null) { |
| 3904 | if (deviceId == curr.mEvent.getDeviceId()) { |
| 3905 | if ((curr.mFlags & QueuedInputEvent.FLAG_DEFERRED) != 0) { |
| 3906 | break; |
| 3907 | } |
| 3908 | QueuedInputEvent next = curr.mNext; |
| 3909 | dequeue(curr, prev); |
| 3910 | super.forward(curr); |
| 3911 | curr = next; |
| 3912 | } else { |
| 3913 | prev = curr; |
| 3914 | curr = curr.mNext; |
| 3915 | } |
| 3916 | } |
| 3917 | } |
| 3918 | |
| 3919 | @Override |
| 3920 | protected void apply(QueuedInputEvent q, int result) { |
| 3921 | if (result == DEFER) { |
| 3922 | defer(q); |
| 3923 | } else { |
| 3924 | super.apply(q, result); |
| 3925 | } |
| 3926 | } |
| 3927 | |
| 3928 | private void enqueue(QueuedInputEvent q) { |
| 3929 | if (mQueueTail == null) { |
| 3930 | mQueueHead = q; |
| 3931 | mQueueTail = q; |
| 3932 | } else { |
| 3933 | mQueueTail.mNext = q; |
| 3934 | mQueueTail = q; |
| 3935 | } |
| 3936 | |
| 3937 | mQueueLength += 1; |
| 3938 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mTraceCounter, mQueueLength); |
| 3939 | } |
| 3940 | |
| 3941 | private void dequeue(QueuedInputEvent q, QueuedInputEvent prev) { |
| 3942 | if (prev == null) { |
| 3943 | mQueueHead = q.mNext; |
| 3944 | } else { |
| 3945 | prev.mNext = q.mNext; |
| 3946 | } |
| 3947 | if (mQueueTail == q) { |
| 3948 | mQueueTail = prev; |
| 3949 | } |
| 3950 | q.mNext = null; |
| 3951 | |
| 3952 | mQueueLength -= 1; |
| 3953 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mTraceCounter, mQueueLength); |
| 3954 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 3955 | |
| 3956 | @Override |
| 3957 | void dump(String prefix, PrintWriter writer) { |
| 3958 | writer.print(prefix); |
| 3959 | writer.print(getClass().getName()); |
| 3960 | writer.print(": mQueueLength="); |
| 3961 | writer.println(mQueueLength); |
| 3962 | |
| 3963 | super.dump(prefix, writer); |
| 3964 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | /** |
| 3968 | * Delivers pre-ime input events to a native activity. |
| 3969 | * Does not support pointer events. |
| 3970 | */ |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3971 | final class NativePreImeInputStage extends AsyncInputStage |
| 3972 | implements InputQueue.FinishedInputEventCallback { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3973 | public NativePreImeInputStage(InputStage next, String traceCounter) { |
| 3974 | super(next, traceCounter); |
| 3975 | } |
| 3976 | |
| 3977 | @Override |
| 3978 | protected int onProcess(QueuedInputEvent q) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3979 | if (mInputQueue != null && q.mEvent instanceof KeyEvent) { |
| 3980 | mInputQueue.sendInputEvent(q.mEvent, q, true, this); |
| 3981 | return DEFER; |
| 3982 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3983 | return FORWARD; |
| 3984 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3985 | |
| 3986 | @Override |
| 3987 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 3988 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 3989 | if (handled) { |
| 3990 | finish(q, true); |
| 3991 | return; |
| 3992 | } |
| 3993 | forward(q); |
| 3994 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3995 | } |
| 3996 | |
| 3997 | /** |
| 3998 | * Delivers pre-ime input events to the view hierarchy. |
| 3999 | * Does not support pointer events. |
| 4000 | */ |
| 4001 | final class ViewPreImeInputStage extends InputStage { |
| 4002 | public ViewPreImeInputStage(InputStage next) { |
| 4003 | super(next); |
| 4004 | } |
| 4005 | |
| 4006 | @Override |
| 4007 | protected int onProcess(QueuedInputEvent q) { |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4008 | if (q.mEvent instanceof KeyEvent) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4009 | return processKeyEvent(q); |
| 4010 | } |
| 4011 | return FORWARD; |
| 4012 | } |
| 4013 | |
| 4014 | private int processKeyEvent(QueuedInputEvent q) { |
| 4015 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4016 | if (mView.dispatchKeyEventPreIme(event)) { |
| 4017 | return FINISH_HANDLED; |
| 4018 | } |
| 4019 | return FORWARD; |
| 4020 | } |
| 4021 | } |
| 4022 | |
| 4023 | /** |
| 4024 | * Delivers input events to the ime. |
| 4025 | * Does not support pointer events. |
| 4026 | */ |
| 4027 | final class ImeInputStage extends AsyncInputStage |
| 4028 | implements InputMethodManager.FinishedInputEventCallback { |
| 4029 | public ImeInputStage(InputStage next, String traceCounter) { |
| 4030 | super(next, traceCounter); |
| 4031 | } |
| 4032 | |
| 4033 | @Override |
| 4034 | protected int onProcess(QueuedInputEvent q) { |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 4035 | if (mLastWasImTarget && !isInLocalFocusMode()) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4036 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4037 | if (imm != null) { |
| 4038 | final InputEvent event = q.mEvent; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4039 | if (DEBUG_IMF) Log.v(mTag, "Sending input event to IME: " + event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4040 | int result = imm.dispatchInputEvent(event, q, this, mHandler); |
| 4041 | if (result == InputMethodManager.DISPATCH_HANDLED) { |
| 4042 | return FINISH_HANDLED; |
| 4043 | } else if (result == InputMethodManager.DISPATCH_NOT_HANDLED) { |
Adam Lesinski | c0f6eed | 2013-10-28 16:03:19 -0700 | [diff] [blame] | 4044 | // The IME could not handle it, so skip along to the next InputStage |
| 4045 | return FORWARD; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4046 | } else { |
| 4047 | return DEFER; // callback will be invoked later |
| 4048 | } |
| 4049 | } |
| 4050 | } |
| 4051 | return FORWARD; |
| 4052 | } |
| 4053 | |
| 4054 | @Override |
| 4055 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4056 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4057 | if (handled) { |
| 4058 | finish(q, true); |
| 4059 | return; |
| 4060 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4061 | forward(q); |
| 4062 | } |
| 4063 | } |
| 4064 | |
| 4065 | /** |
| 4066 | * Performs early processing of post-ime input events. |
| 4067 | */ |
| 4068 | final class EarlyPostImeInputStage extends InputStage { |
| 4069 | public EarlyPostImeInputStage(InputStage next) { |
| 4070 | super(next); |
| 4071 | } |
| 4072 | |
| 4073 | @Override |
| 4074 | protected int onProcess(QueuedInputEvent q) { |
| 4075 | if (q.mEvent instanceof KeyEvent) { |
| 4076 | return processKeyEvent(q); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4077 | } else { |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4078 | final int source = q.mEvent.getSource(); |
| 4079 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4080 | return processPointerEvent(q); |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4081 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4082 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4083 | return FORWARD; |
| 4084 | } |
| 4085 | |
| 4086 | private int processKeyEvent(QueuedInputEvent q) { |
| 4087 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4088 | |
| 4089 | // If the key's purpose is to exit touch mode then we consume it |
| 4090 | // and consider it handled. |
| 4091 | if (checkForLeavingTouchModeAndConsume(event)) { |
| 4092 | return FINISH_HANDLED; |
| 4093 | } |
| 4094 | |
| 4095 | // Make sure the fallback event policy sees all keys that will be |
| 4096 | // delivered to the view hierarchy. |
| 4097 | mFallbackEventHandler.preDispatchKeyEvent(event); |
| 4098 | return FORWARD; |
| 4099 | } |
| 4100 | |
| 4101 | private int processPointerEvent(QueuedInputEvent q) { |
| 4102 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4103 | |
| 4104 | // Translate the pointer event for compatibility, if needed. |
| 4105 | if (mTranslator != null) { |
| 4106 | mTranslator.translateEventInScreenToAppWindow(event); |
| 4107 | } |
| 4108 | |
| 4109 | // Enter touch mode on down or scroll. |
| 4110 | final int action = event.getAction(); |
| 4111 | if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_SCROLL) { |
| 4112 | ensureTouchMode(true); |
| 4113 | } |
| 4114 | |
| 4115 | // Offset the scroll position. |
| 4116 | if (mCurScrollY != 0) { |
| 4117 | event.offsetLocation(0, mCurScrollY); |
| 4118 | } |
| 4119 | |
| 4120 | // Remember the touch position for possible drag-initiation. |
| 4121 | if (event.isTouchEvent()) { |
| 4122 | mLastTouchPoint.x = event.getRawX(); |
| 4123 | mLastTouchPoint.y = event.getRawY(); |
| 4124 | } |
| 4125 | return FORWARD; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4126 | } |
| 4127 | } |
| 4128 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4129 | /** |
| 4130 | * Delivers post-ime input events to a native activity. |
| 4131 | */ |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4132 | final class NativePostImeInputStage extends AsyncInputStage |
| 4133 | implements InputQueue.FinishedInputEventCallback { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4134 | public NativePostImeInputStage(InputStage next, String traceCounter) { |
| 4135 | super(next, traceCounter); |
| 4136 | } |
| 4137 | |
| 4138 | @Override |
| 4139 | protected int onProcess(QueuedInputEvent q) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4140 | if (mInputQueue != null) { |
| 4141 | mInputQueue.sendInputEvent(q.mEvent, q, false, this); |
| 4142 | return DEFER; |
| 4143 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4144 | return FORWARD; |
| 4145 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4146 | |
| 4147 | @Override |
| 4148 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4149 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4150 | if (handled) { |
| 4151 | finish(q, true); |
| 4152 | return; |
| 4153 | } |
| 4154 | forward(q); |
| 4155 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | /** |
| 4159 | * Delivers post-ime input events to the view hierarchy. |
| 4160 | */ |
| 4161 | final class ViewPostImeInputStage extends InputStage { |
| 4162 | public ViewPostImeInputStage(InputStage next) { |
| 4163 | super(next); |
| 4164 | } |
| 4165 | |
| 4166 | @Override |
| 4167 | protected int onProcess(QueuedInputEvent q) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4168 | if (q.mEvent instanceof KeyEvent) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4169 | return processKeyEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4170 | } else { |
| 4171 | final int source = q.mEvent.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4172 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 4173 | return processPointerEvent(q); |
| 4174 | } else if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
| 4175 | return processTrackballEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4176 | } else { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4177 | return processGenericMotionEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4178 | } |
| 4179 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4180 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4181 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 4182 | @Override |
| 4183 | protected void onDeliverToNext(QueuedInputEvent q) { |
| 4184 | if (mUnbufferedInputDispatch |
| 4185 | && q.mEvent instanceof MotionEvent |
| 4186 | && ((MotionEvent)q.mEvent).isTouchEvent() |
| 4187 | && isTerminalInputEvent(q.mEvent)) { |
| 4188 | mUnbufferedInputDispatch = false; |
| 4189 | scheduleConsumeBatchedInput(); |
| 4190 | } |
| 4191 | super.onDeliverToNext(q); |
| 4192 | } |
| 4193 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4194 | private int processKeyEvent(QueuedInputEvent q) { |
| 4195 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4196 | |
| 4197 | // Deliver the key to the view hierarchy. |
| 4198 | if (mView.dispatchKeyEvent(event)) { |
| 4199 | return FINISH_HANDLED; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4200 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4201 | |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4202 | if (shouldDropInputEvent(q)) { |
| 4203 | return FINISH_NOT_HANDLED; |
| 4204 | } |
| 4205 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4206 | // If the Control modifier is held, try to interpret the key as a shortcut. |
| 4207 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 4208 | && event.isCtrlPressed() |
| 4209 | && event.getRepeatCount() == 0 |
| 4210 | && !KeyEvent.isModifierKey(event.getKeyCode())) { |
| 4211 | if (mView.dispatchKeyShortcutEvent(event)) { |
| 4212 | return FINISH_HANDLED; |
| 4213 | } |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4214 | if (shouldDropInputEvent(q)) { |
| 4215 | return FINISH_NOT_HANDLED; |
| 4216 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4217 | } |
| 4218 | |
| 4219 | // Apply the fallback event policy. |
| 4220 | if (mFallbackEventHandler.dispatchKeyEvent(event)) { |
| 4221 | return FINISH_HANDLED; |
| 4222 | } |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4223 | if (shouldDropInputEvent(q)) { |
| 4224 | return FINISH_NOT_HANDLED; |
| 4225 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4226 | |
| 4227 | // Handle automatic focus changes. |
| 4228 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 4229 | int direction = 0; |
| 4230 | switch (event.getKeyCode()) { |
| 4231 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 4232 | if (event.hasNoModifiers()) { |
| 4233 | direction = View.FOCUS_LEFT; |
| 4234 | } |
| 4235 | break; |
| 4236 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 4237 | if (event.hasNoModifiers()) { |
| 4238 | direction = View.FOCUS_RIGHT; |
| 4239 | } |
| 4240 | break; |
| 4241 | case KeyEvent.KEYCODE_DPAD_UP: |
| 4242 | if (event.hasNoModifiers()) { |
| 4243 | direction = View.FOCUS_UP; |
| 4244 | } |
| 4245 | break; |
| 4246 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 4247 | if (event.hasNoModifiers()) { |
| 4248 | direction = View.FOCUS_DOWN; |
| 4249 | } |
| 4250 | break; |
| 4251 | case KeyEvent.KEYCODE_TAB: |
| 4252 | if (event.hasNoModifiers()) { |
| 4253 | direction = View.FOCUS_FORWARD; |
| 4254 | } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) { |
| 4255 | direction = View.FOCUS_BACKWARD; |
| 4256 | } |
| 4257 | break; |
| 4258 | } |
| 4259 | if (direction != 0) { |
| 4260 | View focused = mView.findFocus(); |
| 4261 | if (focused != null) { |
| 4262 | View v = focused.focusSearch(direction); |
| 4263 | if (v != null && v != focused) { |
| 4264 | // do the math the get the interesting rect |
| 4265 | // of previous focused into the coord system of |
| 4266 | // newly focused view |
| 4267 | focused.getFocusedRect(mTempRect); |
| 4268 | if (mView instanceof ViewGroup) { |
| 4269 | ((ViewGroup) mView).offsetDescendantRectToMyCoords( |
| 4270 | focused, mTempRect); |
| 4271 | ((ViewGroup) mView).offsetRectIntoDescendantCoords( |
| 4272 | v, mTempRect); |
| 4273 | } |
| 4274 | if (v.requestFocus(direction, mTempRect)) { |
| 4275 | playSoundEffect(SoundEffectConstants |
| 4276 | .getContantForFocusDirection(direction)); |
| 4277 | return FINISH_HANDLED; |
| 4278 | } |
| 4279 | } |
| 4280 | |
| 4281 | // Give the focused view a last chance to handle the dpad key. |
| 4282 | if (mView.dispatchUnhandledMove(focused, direction)) { |
| 4283 | return FINISH_HANDLED; |
| 4284 | } |
| 4285 | } else { |
| 4286 | // find the best view to give focus to in this non-touch-mode with no-focus |
| 4287 | View v = focusSearch(null, direction); |
| 4288 | if (v != null && v.requestFocus(direction)) { |
| 4289 | return FINISH_HANDLED; |
| 4290 | } |
| 4291 | } |
| 4292 | } |
| 4293 | } |
| 4294 | return FORWARD; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4295 | } |
| 4296 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4297 | private int processPointerEvent(QueuedInputEvent q) { |
| 4298 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4299 | |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 4300 | if (event.getPointerCount() == 1 |
| 4301 | && event.isFromSource(InputDevice.SOURCE_MOUSE)) { |
| 4302 | if (event.getActionMasked() == MotionEvent.ACTION_HOVER_ENTER |
| 4303 | || event.getActionMasked() == MotionEvent.ACTION_HOVER_EXIT) { |
| 4304 | // Other apps or the window manager may change the icon shape outside of |
| 4305 | // this app, therefore the icon shape has to be reset on enter/exit event. |
| 4306 | mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
| 4307 | } |
| 4308 | |
| 4309 | final float x = event.getX(); |
| 4310 | final float y = event.getY(); |
Jun Mukai | 76c4a12 | 2015-10-19 15:51:28 -0700 | [diff] [blame] | 4311 | if (event.getActionMasked() != MotionEvent.ACTION_HOVER_EXIT |
| 4312 | && x >= 0 && x < mView.getWidth() && y >= 0 && y < mView.getHeight()) { |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 4313 | PointerIcon pointerIcon = mView.getPointerIcon(event, x, y); |
| 4314 | int pointerShape = (pointerIcon != null) ? |
| 4315 | pointerIcon.getStyle() : PointerIcon.STYLE_DEFAULT; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 4316 | |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 4317 | final InputDevice inputDevice = event.getDevice(); |
| 4318 | if (inputDevice != null) { |
| 4319 | if (mPointerIconShape != pointerShape) { |
| 4320 | mPointerIconShape = pointerShape; |
| 4321 | if (mPointerIconShape != PointerIcon.STYLE_CUSTOM) { |
| 4322 | mCustomPointerIcon = null; |
| 4323 | inputDevice.setPointerShape(pointerShape); |
| 4324 | } |
| 4325 | } |
| 4326 | if (mPointerIconShape == PointerIcon.STYLE_CUSTOM && |
| 4327 | !pointerIcon.equals(mCustomPointerIcon)) { |
| 4328 | mCustomPointerIcon = pointerIcon; |
| 4329 | inputDevice.setCustomPointerIcon(mCustomPointerIcon); |
Keisuke Kuroyanagi | 9a4450b | 2015-10-27 17:29:53 +0900 | [diff] [blame] | 4330 | } |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 4331 | } |
Jun Mukai | 41aab00 | 2015-10-01 23:18:47 -0700 | [diff] [blame] | 4332 | } else if (event.getActionMasked() == MotionEvent.ACTION_HOVER_MOVE) { |
| 4333 | mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 4334 | } |
| 4335 | } |
| 4336 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 4337 | mAttachInfo.mUnbufferedDispatchRequested = false; |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 4338 | final View eventTarget = |
| 4339 | (event.isFromSource(InputDevice.SOURCE_MOUSE) && mCapturingView != null) ? |
| 4340 | mCapturingView : mView; |
| 4341 | boolean handled = eventTarget.dispatchPointerEvent(event); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 4342 | if (mAttachInfo.mUnbufferedDispatchRequested && !mUnbufferedInputDispatch) { |
| 4343 | mUnbufferedInputDispatch = true; |
| 4344 | if (mConsumeBatchedInputScheduled) { |
| 4345 | scheduleConsumeBatchedInputImmediately(); |
| 4346 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4347 | } |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 4348 | return handled ? FINISH_HANDLED : FORWARD; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4349 | } |
| 4350 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4351 | private int processTrackballEvent(QueuedInputEvent q) { |
| 4352 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4353 | |
| 4354 | if (mView.dispatchTrackballEvent(event)) { |
| 4355 | return FINISH_HANDLED; |
| 4356 | } |
| 4357 | return FORWARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4358 | } |
| 4359 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4360 | private int processGenericMotionEvent(QueuedInputEvent q) { |
| 4361 | final MotionEvent event = (MotionEvent)q.mEvent; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4362 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4363 | // Deliver the event to the view. |
| 4364 | if (mView.dispatchGenericMotionEvent(event)) { |
| 4365 | return FINISH_HANDLED; |
| 4366 | } |
| 4367 | return FORWARD; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4368 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4369 | } |
| 4370 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4371 | /** |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4372 | * Performs synthesis of new input events from unhandled input events. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4373 | */ |
| 4374 | final class SyntheticInputStage extends InputStage { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4375 | private final SyntheticTrackballHandler mTrackball = new SyntheticTrackballHandler(); |
| 4376 | private final SyntheticJoystickHandler mJoystick = new SyntheticJoystickHandler(); |
| 4377 | private final SyntheticTouchNavigationHandler mTouchNavigation = |
| 4378 | new SyntheticTouchNavigationHandler(); |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4379 | private final SyntheticKeyboardHandler mKeyboard = new SyntheticKeyboardHandler(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4380 | |
| 4381 | public SyntheticInputStage() { |
| 4382 | super(null); |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4383 | } |
| 4384 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4385 | @Override |
| 4386 | protected int onProcess(QueuedInputEvent q) { |
| 4387 | q.mFlags |= QueuedInputEvent.FLAG_RESYNTHESIZED; |
| 4388 | if (q.mEvent instanceof MotionEvent) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4389 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4390 | final int source = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4391 | if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4392 | mTrackball.process(event); |
| 4393 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4394 | } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4395 | mJoystick.process(event); |
| 4396 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4397 | } else if ((source & InputDevice.SOURCE_TOUCH_NAVIGATION) |
| 4398 | == InputDevice.SOURCE_TOUCH_NAVIGATION) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4399 | mTouchNavigation.process(event); |
| 4400 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4401 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4402 | } else if ((q.mFlags & QueuedInputEvent.FLAG_UNHANDLED) != 0) { |
| 4403 | mKeyboard.process((KeyEvent)q.mEvent); |
| 4404 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4405 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4406 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4407 | return FORWARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4408 | } |
| 4409 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4410 | @Override |
| 4411 | protected void onDeliverToNext(QueuedInputEvent q) { |
| 4412 | if ((q.mFlags & QueuedInputEvent.FLAG_RESYNTHESIZED) == 0) { |
| 4413 | // Cancel related synthetic events if any prior stage has handled the event. |
| 4414 | if (q.mEvent instanceof MotionEvent) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4415 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4416 | final int source = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4417 | if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4418 | mTrackball.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4419 | } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4420 | mJoystick.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4421 | } else if ((source & InputDevice.SOURCE_TOUCH_NAVIGATION) |
| 4422 | == InputDevice.SOURCE_TOUCH_NAVIGATION) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4423 | mTouchNavigation.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4424 | } |
| 4425 | } |
| 4426 | } |
| 4427 | super.onDeliverToNext(q); |
| 4428 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4429 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4430 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4431 | /** |
| 4432 | * Creates dpad events from unhandled trackball movements. |
| 4433 | */ |
| 4434 | final class SyntheticTrackballHandler { |
| 4435 | private final TrackballAxis mX = new TrackballAxis(); |
| 4436 | private final TrackballAxis mY = new TrackballAxis(); |
| 4437 | private long mLastTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4438 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4439 | public void process(MotionEvent event) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4440 | // Translate the trackball event into DPAD keys and try to deliver those. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4441 | long curTime = SystemClock.uptimeMillis(); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4442 | if ((mLastTime + MAX_TRACKBALL_DELAY) < curTime) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4443 | // It has been too long since the last movement, |
| 4444 | // so restart at the beginning. |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4445 | mX.reset(0); |
| 4446 | mY.reset(0); |
| 4447 | mLastTime = curTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4448 | } |
| 4449 | |
| 4450 | final int action = event.getAction(); |
| 4451 | final int metaState = event.getMetaState(); |
| 4452 | switch (action) { |
| 4453 | case MotionEvent.ACTION_DOWN: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4454 | mX.reset(2); |
| 4455 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4456 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4457 | KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER, 0, metaState, |
| 4458 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4459 | InputDevice.SOURCE_KEYBOARD)); |
| 4460 | break; |
| 4461 | case MotionEvent.ACTION_UP: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4462 | mX.reset(2); |
| 4463 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4464 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4465 | KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER, 0, metaState, |
| 4466 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4467 | InputDevice.SOURCE_KEYBOARD)); |
| 4468 | break; |
| 4469 | } |
| 4470 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4471 | if (DEBUG_TRACKBALL) Log.v(mTag, "TB X=" + mX.position + " step=" |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4472 | + mX.step + " dir=" + mX.dir + " acc=" + mX.acceleration |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4473 | + " move=" + event.getX() |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4474 | + " / Y=" + mY.position + " step=" |
| 4475 | + mY.step + " dir=" + mY.dir + " acc=" + mY.acceleration |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4476 | + " move=" + event.getY()); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4477 | final float xOff = mX.collect(event.getX(), event.getEventTime(), "X"); |
| 4478 | final float yOff = mY.collect(event.getY(), event.getEventTime(), "Y"); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4479 | |
| 4480 | // Generate DPAD events based on the trackball movement. |
| 4481 | // We pick the axis that has moved the most as the direction of |
| 4482 | // the DPAD. When we generate DPAD events for one axis, then the |
| 4483 | // other axis is reset -- we don't want to perform DPAD jumps due |
| 4484 | // to slight movements in the trackball when making major movements |
| 4485 | // along the other axis. |
| 4486 | int keycode = 0; |
| 4487 | int movement = 0; |
| 4488 | float accel = 1; |
| 4489 | if (xOff > yOff) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4490 | movement = mX.generate(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4491 | if (movement != 0) { |
| 4492 | keycode = movement > 0 ? KeyEvent.KEYCODE_DPAD_RIGHT |
| 4493 | : KeyEvent.KEYCODE_DPAD_LEFT; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4494 | accel = mX.acceleration; |
| 4495 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4496 | } |
| 4497 | } else if (yOff > 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4498 | movement = mY.generate(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4499 | if (movement != 0) { |
| 4500 | keycode = movement > 0 ? KeyEvent.KEYCODE_DPAD_DOWN |
| 4501 | : KeyEvent.KEYCODE_DPAD_UP; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4502 | accel = mY.acceleration; |
| 4503 | mX.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4504 | } |
| 4505 | } |
| 4506 | |
| 4507 | if (keycode != 0) { |
| 4508 | if (movement < 0) movement = -movement; |
| 4509 | int accelMovement = (int)(movement * accel); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4510 | if (DEBUG_TRACKBALL) Log.v(mTag, "Move: movement=" + movement |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4511 | + " accelMovement=" + accelMovement |
| 4512 | + " accel=" + accel); |
| 4513 | if (accelMovement > movement) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4514 | if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: " |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4515 | + keycode); |
| 4516 | movement--; |
| 4517 | int repeatCount = accelMovement - movement; |
| 4518 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4519 | KeyEvent.ACTION_MULTIPLE, keycode, repeatCount, metaState, |
| 4520 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4521 | InputDevice.SOURCE_KEYBOARD)); |
| 4522 | } |
| 4523 | while (movement > 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4524 | if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: " |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4525 | + keycode); |
| 4526 | movement--; |
| 4527 | curTime = SystemClock.uptimeMillis(); |
| 4528 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4529 | KeyEvent.ACTION_DOWN, keycode, 0, metaState, |
| 4530 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4531 | InputDevice.SOURCE_KEYBOARD)); |
| 4532 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4533 | KeyEvent.ACTION_UP, keycode, 0, metaState, |
| 4534 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4535 | InputDevice.SOURCE_KEYBOARD)); |
| 4536 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4537 | mLastTime = curTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4538 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4539 | } |
| 4540 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4541 | public void cancel(MotionEvent event) { |
| 4542 | mLastTime = Integer.MIN_VALUE; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4543 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4544 | // If we reach this, we consumed a trackball event. |
| 4545 | // Because we will not translate the trackball event into a key event, |
| 4546 | // touch mode will not exit, so we exit touch mode here. |
| 4547 | if (mView != null && mAdded) { |
| 4548 | ensureTouchMode(false); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4549 | } |
| 4550 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4551 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4552 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4553 | /** |
| 4554 | * Maintains state information for a single trackball axis, generating |
| 4555 | * discrete (DPAD) movements based on raw trackball motion. |
| 4556 | */ |
| 4557 | static final class TrackballAxis { |
| 4558 | /** |
| 4559 | * The maximum amount of acceleration we will apply. |
| 4560 | */ |
| 4561 | static final float MAX_ACCELERATION = 20; |
| 4562 | |
| 4563 | /** |
| 4564 | * The maximum amount of time (in milliseconds) between events in order |
| 4565 | * for us to consider the user to be doing fast trackball movements, |
| 4566 | * and thus apply an acceleration. |
| 4567 | */ |
| 4568 | static final long FAST_MOVE_TIME = 150; |
| 4569 | |
| 4570 | /** |
| 4571 | * Scaling factor to the time (in milliseconds) between events to how |
| 4572 | * much to multiple/divide the current acceleration. When movement |
| 4573 | * is < FAST_MOVE_TIME this multiplies the acceleration; when > |
| 4574 | * FAST_MOVE_TIME it divides it. |
| 4575 | */ |
| 4576 | static final float ACCEL_MOVE_SCALING_FACTOR = (1.0f/40); |
| 4577 | |
| 4578 | static final float FIRST_MOVEMENT_THRESHOLD = 0.5f; |
| 4579 | static final float SECOND_CUMULATIVE_MOVEMENT_THRESHOLD = 2.0f; |
| 4580 | static final float SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD = 1.0f; |
| 4581 | |
| 4582 | float position; |
| 4583 | float acceleration = 1; |
| 4584 | long lastMoveTime = 0; |
| 4585 | int step; |
| 4586 | int dir; |
| 4587 | int nonAccelMovement; |
| 4588 | |
| 4589 | void reset(int _step) { |
| 4590 | position = 0; |
| 4591 | acceleration = 1; |
| 4592 | lastMoveTime = 0; |
| 4593 | step = _step; |
| 4594 | dir = 0; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 4595 | } |
| 4596 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4597 | /** |
| 4598 | * Add trackball movement into the state. If the direction of movement |
| 4599 | * has been reversed, the state is reset before adding the |
| 4600 | * movement (so that you don't have to compensate for any previously |
| 4601 | * collected movement before see the result of the movement in the |
| 4602 | * new direction). |
| 4603 | * |
| 4604 | * @return Returns the absolute value of the amount of movement |
| 4605 | * collected so far. |
| 4606 | */ |
| 4607 | float collect(float off, long time, String axis) { |
| 4608 | long normTime; |
| 4609 | if (off > 0) { |
| 4610 | normTime = (long)(off * FAST_MOVE_TIME); |
| 4611 | if (dir < 0) { |
| 4612 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " reversed to positive!"); |
| 4613 | position = 0; |
| 4614 | step = 0; |
| 4615 | acceleration = 1; |
| 4616 | lastMoveTime = 0; |
| 4617 | } |
| 4618 | dir = 1; |
| 4619 | } else if (off < 0) { |
| 4620 | normTime = (long)((-off) * FAST_MOVE_TIME); |
| 4621 | if (dir > 0) { |
| 4622 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " reversed to negative!"); |
| 4623 | position = 0; |
| 4624 | step = 0; |
| 4625 | acceleration = 1; |
| 4626 | lastMoveTime = 0; |
| 4627 | } |
| 4628 | dir = -1; |
| 4629 | } else { |
| 4630 | normTime = 0; |
| 4631 | } |
| 4632 | |
| 4633 | // The number of milliseconds between each movement that is |
| 4634 | // considered "normal" and will not result in any acceleration |
| 4635 | // or deceleration, scaled by the offset we have here. |
| 4636 | if (normTime > 0) { |
| 4637 | long delta = time - lastMoveTime; |
| 4638 | lastMoveTime = time; |
| 4639 | float acc = acceleration; |
| 4640 | if (delta < normTime) { |
| 4641 | // The user is scrolling rapidly, so increase acceleration. |
| 4642 | float scale = (normTime-delta) * ACCEL_MOVE_SCALING_FACTOR; |
| 4643 | if (scale > 1) acc *= scale; |
| 4644 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " accelerate: off=" |
| 4645 | + off + " normTime=" + normTime + " delta=" + delta |
| 4646 | + " scale=" + scale + " acc=" + acc); |
| 4647 | acceleration = acc < MAX_ACCELERATION ? acc : MAX_ACCELERATION; |
| 4648 | } else { |
| 4649 | // The user is scrolling slowly, so decrease acceleration. |
| 4650 | float scale = (delta-normTime) * ACCEL_MOVE_SCALING_FACTOR; |
| 4651 | if (scale > 1) acc /= scale; |
| 4652 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " deccelerate: off=" |
| 4653 | + off + " normTime=" + normTime + " delta=" + delta |
| 4654 | + " scale=" + scale + " acc=" + acc); |
| 4655 | acceleration = acc > 1 ? acc : 1; |
| 4656 | } |
| 4657 | } |
| 4658 | position += off; |
| 4659 | return Math.abs(position); |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 4660 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4661 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4662 | /** |
| 4663 | * Generate the number of discrete movement events appropriate for |
| 4664 | * the currently collected trackball movement. |
| 4665 | * |
| 4666 | * @return Returns the number of discrete movements, either positive |
| 4667 | * or negative, or 0 if there is not enough trackball movement yet |
| 4668 | * for a discrete movement. |
| 4669 | */ |
| 4670 | int generate() { |
| 4671 | int movement = 0; |
| 4672 | nonAccelMovement = 0; |
| 4673 | do { |
| 4674 | final int dir = position >= 0 ? 1 : -1; |
| 4675 | switch (step) { |
| 4676 | // If we are going to execute the first step, then we want |
| 4677 | // to do this as soon as possible instead of waiting for |
| 4678 | // a full movement, in order to make things look responsive. |
| 4679 | case 0: |
| 4680 | if (Math.abs(position) < FIRST_MOVEMENT_THRESHOLD) { |
| 4681 | return movement; |
| 4682 | } |
| 4683 | movement += dir; |
| 4684 | nonAccelMovement += dir; |
| 4685 | step = 1; |
| 4686 | break; |
| 4687 | // If we have generated the first movement, then we need |
| 4688 | // to wait for the second complete trackball motion before |
| 4689 | // generating the second discrete movement. |
| 4690 | case 1: |
| 4691 | if (Math.abs(position) < SECOND_CUMULATIVE_MOVEMENT_THRESHOLD) { |
| 4692 | return movement; |
| 4693 | } |
| 4694 | movement += dir; |
| 4695 | nonAccelMovement += dir; |
| 4696 | position -= SECOND_CUMULATIVE_MOVEMENT_THRESHOLD * dir; |
| 4697 | step = 2; |
| 4698 | break; |
| 4699 | // After the first two, we generate discrete movements |
| 4700 | // consistently with the trackball, applying an acceleration |
| 4701 | // if the trackball is moving quickly. This is a simple |
| 4702 | // acceleration on top of what we already compute based |
| 4703 | // on how quickly the wheel is being turned, to apply |
| 4704 | // a longer increasing acceleration to continuous movement |
| 4705 | // in one direction. |
| 4706 | default: |
| 4707 | if (Math.abs(position) < SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD) { |
| 4708 | return movement; |
| 4709 | } |
| 4710 | movement += dir; |
| 4711 | position -= dir * SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD; |
| 4712 | float acc = acceleration; |
| 4713 | acc *= 1.1f; |
| 4714 | acceleration = acc < MAX_ACCELERATION ? acc : acceleration; |
| 4715 | break; |
| 4716 | } |
| 4717 | } while (true); |
| 4718 | } |
| 4719 | } |
| 4720 | |
| 4721 | /** |
| 4722 | * Creates dpad events from unhandled joystick movements. |
| 4723 | */ |
| 4724 | final class SyntheticJoystickHandler extends Handler { |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4725 | private final static String TAG = "SyntheticJoystickHandler"; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4726 | private final static int MSG_ENQUEUE_X_AXIS_KEY_REPEAT = 1; |
| 4727 | private final static int MSG_ENQUEUE_Y_AXIS_KEY_REPEAT = 2; |
| 4728 | |
| 4729 | private int mLastXDirection; |
| 4730 | private int mLastYDirection; |
| 4731 | private int mLastXKeyCode; |
| 4732 | private int mLastYKeyCode; |
| 4733 | |
| 4734 | public SyntheticJoystickHandler() { |
| 4735 | super(true); |
| 4736 | } |
| 4737 | |
| 4738 | @Override |
| 4739 | public void handleMessage(Message msg) { |
| 4740 | switch (msg.what) { |
| 4741 | case MSG_ENQUEUE_X_AXIS_KEY_REPEAT: |
| 4742 | case MSG_ENQUEUE_Y_AXIS_KEY_REPEAT: { |
| 4743 | KeyEvent oldEvent = (KeyEvent)msg.obj; |
| 4744 | KeyEvent e = KeyEvent.changeTimeRepeat(oldEvent, |
| 4745 | SystemClock.uptimeMillis(), |
| 4746 | oldEvent.getRepeatCount() + 1); |
| 4747 | if (mAttachInfo.mHasWindowFocus) { |
| 4748 | enqueueInputEvent(e); |
| 4749 | Message m = obtainMessage(msg.what, e); |
| 4750 | m.setAsynchronous(true); |
| 4751 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatDelay()); |
| 4752 | } |
| 4753 | } break; |
| 4754 | } |
| 4755 | } |
| 4756 | |
| 4757 | public void process(MotionEvent event) { |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4758 | switch(event.getActionMasked()) { |
| 4759 | case MotionEvent.ACTION_CANCEL: |
| 4760 | cancel(event); |
| 4761 | break; |
| 4762 | case MotionEvent.ACTION_MOVE: |
| 4763 | update(event, true); |
| 4764 | break; |
| 4765 | default: |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4766 | Log.w(mTag, "Unexpected action: " + event.getActionMasked()); |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4767 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4768 | } |
| 4769 | |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4770 | private void cancel(MotionEvent event) { |
| 4771 | removeMessages(MSG_ENQUEUE_X_AXIS_KEY_REPEAT); |
| 4772 | removeMessages(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4773 | update(event, false); |
| 4774 | } |
| 4775 | |
| 4776 | private void update(MotionEvent event, boolean synthesizeNewKeys) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4777 | final long time = event.getEventTime(); |
| 4778 | final int metaState = event.getMetaState(); |
| 4779 | final int deviceId = event.getDeviceId(); |
| 4780 | final int source = event.getSource(); |
| 4781 | |
| 4782 | int xDirection = joystickAxisValueToDirection( |
| 4783 | event.getAxisValue(MotionEvent.AXIS_HAT_X)); |
| 4784 | if (xDirection == 0) { |
| 4785 | xDirection = joystickAxisValueToDirection(event.getX()); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4786 | } |
| 4787 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4788 | int yDirection = joystickAxisValueToDirection( |
| 4789 | event.getAxisValue(MotionEvent.AXIS_HAT_Y)); |
| 4790 | if (yDirection == 0) { |
| 4791 | yDirection = joystickAxisValueToDirection(event.getY()); |
| 4792 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4793 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4794 | if (xDirection != mLastXDirection) { |
| 4795 | if (mLastXKeyCode != 0) { |
| 4796 | removeMessages(MSG_ENQUEUE_X_AXIS_KEY_REPEAT); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4797 | enqueueInputEvent(new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4798 | KeyEvent.ACTION_UP, mLastXKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4799 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source)); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4800 | mLastXKeyCode = 0; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4801 | } |
| 4802 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4803 | mLastXDirection = xDirection; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4804 | |
| 4805 | if (xDirection != 0 && synthesizeNewKeys) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4806 | mLastXKeyCode = xDirection > 0 |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4807 | ? KeyEvent.KEYCODE_DPAD_RIGHT : KeyEvent.KEYCODE_DPAD_LEFT; |
| 4808 | final KeyEvent e = new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4809 | KeyEvent.ACTION_DOWN, mLastXKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4810 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source); |
| 4811 | enqueueInputEvent(e); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4812 | Message m = obtainMessage(MSG_ENQUEUE_X_AXIS_KEY_REPEAT, e); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4813 | m.setAsynchronous(true); |
Michael Wright | b961852 | 2013-04-10 15:20:56 -0700 | [diff] [blame] | 4814 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatTimeout()); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4815 | } |
| 4816 | } |
| 4817 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4818 | if (yDirection != mLastYDirection) { |
| 4819 | if (mLastYKeyCode != 0) { |
| 4820 | removeMessages(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4821 | enqueueInputEvent(new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4822 | KeyEvent.ACTION_UP, mLastYKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4823 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source)); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4824 | mLastYKeyCode = 0; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4825 | } |
| 4826 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4827 | mLastYDirection = yDirection; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4828 | |
| 4829 | if (yDirection != 0 && synthesizeNewKeys) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4830 | mLastYKeyCode = yDirection > 0 |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4831 | ? KeyEvent.KEYCODE_DPAD_DOWN : KeyEvent.KEYCODE_DPAD_UP; |
| 4832 | final KeyEvent e = new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4833 | KeyEvent.ACTION_DOWN, mLastYKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4834 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source); |
| 4835 | enqueueInputEvent(e); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4836 | Message m = obtainMessage(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT, e); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4837 | m.setAsynchronous(true); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4838 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatTimeout()); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4839 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4840 | } |
| 4841 | } |
| 4842 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4843 | private int joystickAxisValueToDirection(float value) { |
| 4844 | if (value >= 0.5f) { |
| 4845 | return 1; |
| 4846 | } else if (value <= -0.5f) { |
| 4847 | return -1; |
| 4848 | } else { |
| 4849 | return 0; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4850 | } |
| 4851 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4852 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4853 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4854 | /** |
| 4855 | * Creates dpad events from unhandled touch navigation movements. |
| 4856 | */ |
| 4857 | final class SyntheticTouchNavigationHandler extends Handler { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4858 | private static final String LOCAL_TAG = "SyntheticTouchNavigationHandler"; |
| 4859 | private static final boolean LOCAL_DEBUG = false; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4860 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4861 | // Assumed nominal width and height in millimeters of a touch navigation pad, |
| 4862 | // if no resolution information is available from the input system. |
| 4863 | private static final float DEFAULT_WIDTH_MILLIMETERS = 48; |
| 4864 | private static final float DEFAULT_HEIGHT_MILLIMETERS = 48; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4865 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4866 | /* TODO: These constants should eventually be moved to ViewConfiguration. */ |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4867 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4868 | // The nominal distance traveled to move by one unit. |
| 4869 | private static final int TICK_DISTANCE_MILLIMETERS = 12; |
| 4870 | |
| 4871 | // Minimum and maximum fling velocity in ticks per second. |
| 4872 | // The minimum velocity should be set such that we perform enough ticks per |
| 4873 | // second that the fling appears to be fluid. For example, if we set the minimum |
| 4874 | // to 2 ticks per second, then there may be up to half a second delay between the next |
| 4875 | // to last and last ticks which is noticeably discrete and jerky. This value should |
| 4876 | // probably not be set to anything less than about 4. |
| 4877 | // If fling accuracy is a problem then consider tuning the tick distance instead. |
| 4878 | private static final float MIN_FLING_VELOCITY_TICKS_PER_SECOND = 6f; |
| 4879 | private static final float MAX_FLING_VELOCITY_TICKS_PER_SECOND = 20f; |
| 4880 | |
| 4881 | // Fling velocity decay factor applied after each new key is emitted. |
| 4882 | // This parameter controls the deceleration and overall duration of the fling. |
| 4883 | // The fling stops automatically when its velocity drops below the minimum |
| 4884 | // fling velocity defined above. |
| 4885 | private static final float FLING_TICK_DECAY = 0.8f; |
| 4886 | |
| 4887 | /* The input device that we are tracking. */ |
| 4888 | |
| 4889 | private int mCurrentDeviceId = -1; |
| 4890 | private int mCurrentSource; |
| 4891 | private boolean mCurrentDeviceSupported; |
| 4892 | |
| 4893 | /* Configuration for the current input device. */ |
| 4894 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4895 | // The scaled tick distance. A movement of this amount should generally translate |
| 4896 | // into a single dpad event in a given direction. |
| 4897 | private float mConfigTickDistance; |
| 4898 | |
| 4899 | // The minimum and maximum scaled fling velocity. |
| 4900 | private float mConfigMinFlingVelocity; |
| 4901 | private float mConfigMaxFlingVelocity; |
| 4902 | |
| 4903 | /* Tracking state. */ |
| 4904 | |
| 4905 | // The velocity tracker for detecting flings. |
| 4906 | private VelocityTracker mVelocityTracker; |
| 4907 | |
| 4908 | // The active pointer id, or -1 if none. |
| 4909 | private int mActivePointerId = -1; |
| 4910 | |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 4911 | // Location where tracking started. |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4912 | private float mStartX; |
| 4913 | private float mStartY; |
| 4914 | |
| 4915 | // Most recently observed position. |
| 4916 | private float mLastX; |
| 4917 | private float mLastY; |
| 4918 | |
| 4919 | // Accumulated movement delta since the last direction key was sent. |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4920 | private float mAccumulatedX; |
| 4921 | private float mAccumulatedY; |
| 4922 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4923 | // Set to true if any movement was delivered to the app. |
| 4924 | // Implies that tap slop was exceeded. |
| 4925 | private boolean mConsumedMovement; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4926 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4927 | // The most recently sent key down event. |
| 4928 | // The keycode remains set until the direction changes or a fling ends |
| 4929 | // so that repeated key events may be generated as required. |
| 4930 | private long mPendingKeyDownTime; |
| 4931 | private int mPendingKeyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 4932 | private int mPendingKeyRepeatCount; |
| 4933 | private int mPendingKeyMetaState; |
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 | // The current fling velocity while a fling is in progress. |
| 4936 | private boolean mFlinging; |
| 4937 | private float mFlingVelocity; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4938 | |
| 4939 | public SyntheticTouchNavigationHandler() { |
| 4940 | super(true); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4941 | } |
| 4942 | |
| 4943 | public void process(MotionEvent event) { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4944 | // Update the current device information. |
| 4945 | final long time = event.getEventTime(); |
| 4946 | final int deviceId = event.getDeviceId(); |
| 4947 | final int source = event.getSource(); |
| 4948 | if (mCurrentDeviceId != deviceId || mCurrentSource != source) { |
| 4949 | finishKeys(time); |
| 4950 | finishTracking(time); |
| 4951 | mCurrentDeviceId = deviceId; |
| 4952 | mCurrentSource = source; |
| 4953 | mCurrentDeviceSupported = false; |
| 4954 | InputDevice device = event.getDevice(); |
| 4955 | if (device != null) { |
| 4956 | // In order to support an input device, we must know certain |
| 4957 | // characteristics about it, such as its size and resolution. |
| 4958 | InputDevice.MotionRange xRange = device.getMotionRange(MotionEvent.AXIS_X); |
| 4959 | InputDevice.MotionRange yRange = device.getMotionRange(MotionEvent.AXIS_Y); |
| 4960 | if (xRange != null && yRange != null) { |
| 4961 | mCurrentDeviceSupported = true; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4962 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4963 | // Infer the resolution if it not actually known. |
| 4964 | float xRes = xRange.getResolution(); |
| 4965 | if (xRes <= 0) { |
| 4966 | xRes = xRange.getRange() / DEFAULT_WIDTH_MILLIMETERS; |
| 4967 | } |
| 4968 | float yRes = yRange.getResolution(); |
| 4969 | if (yRes <= 0) { |
| 4970 | yRes = yRange.getRange() / DEFAULT_HEIGHT_MILLIMETERS; |
| 4971 | } |
| 4972 | float nominalRes = (xRes + yRes) * 0.5f; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4973 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4974 | // Precompute all of the configuration thresholds we will need. |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4975 | mConfigTickDistance = TICK_DISTANCE_MILLIMETERS * nominalRes; |
| 4976 | mConfigMinFlingVelocity = |
| 4977 | MIN_FLING_VELOCITY_TICKS_PER_SECOND * mConfigTickDistance; |
| 4978 | mConfigMaxFlingVelocity = |
| 4979 | MAX_FLING_VELOCITY_TICKS_PER_SECOND * mConfigTickDistance; |
| 4980 | |
| 4981 | if (LOCAL_DEBUG) { |
| 4982 | Log.d(LOCAL_TAG, "Configured device " + mCurrentDeviceId |
| 4983 | + " (" + Integer.toHexString(mCurrentSource) + "): " |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4984 | + ", mConfigTickDistance=" + mConfigTickDistance |
| 4985 | + ", mConfigMinFlingVelocity=" + mConfigMinFlingVelocity |
| 4986 | + ", mConfigMaxFlingVelocity=" + mConfigMaxFlingVelocity); |
| 4987 | } |
| 4988 | } |
| 4989 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4990 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4991 | if (!mCurrentDeviceSupported) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4992 | return; |
| 4993 | } |
| 4994 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4995 | // Handle the event. |
| 4996 | final int action = event.getActionMasked(); |
| 4997 | switch (action) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4998 | case MotionEvent.ACTION_DOWN: { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4999 | boolean caughtFling = mFlinging; |
| 5000 | finishKeys(time); |
| 5001 | finishTracking(time); |
| 5002 | mActivePointerId = event.getPointerId(0); |
| 5003 | mVelocityTracker = VelocityTracker.obtain(); |
| 5004 | mVelocityTracker.addMovement(event); |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5005 | mStartX = event.getX(); |
| 5006 | mStartY = event.getY(); |
| 5007 | mLastX = mStartX; |
| 5008 | mLastY = mStartY; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5009 | mAccumulatedX = 0; |
| 5010 | mAccumulatedY = 0; |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5011 | |
| 5012 | // If we caught a fling, then pretend that the tap slop has already |
| 5013 | // been exceeded to suppress taps whose only purpose is to stop the fling. |
| 5014 | mConsumedMovement = caughtFling; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5015 | break; |
| 5016 | } |
| 5017 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5018 | case MotionEvent.ACTION_MOVE: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5019 | case MotionEvent.ACTION_UP: { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5020 | if (mActivePointerId < 0) { |
| 5021 | break; |
| 5022 | } |
| 5023 | final int index = event.findPointerIndex(mActivePointerId); |
| 5024 | if (index < 0) { |
| 5025 | finishKeys(time); |
| 5026 | finishTracking(time); |
| 5027 | break; |
| 5028 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5029 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5030 | mVelocityTracker.addMovement(event); |
| 5031 | final float x = event.getX(index); |
| 5032 | final float y = event.getY(index); |
| 5033 | mAccumulatedX += x - mLastX; |
| 5034 | mAccumulatedY += y - mLastY; |
| 5035 | mLastX = x; |
| 5036 | mLastY = y; |
| 5037 | |
| 5038 | // Consume any accumulated movement so far. |
| 5039 | final int metaState = event.getMetaState(); |
| 5040 | consumeAccumulatedMovement(time, metaState); |
| 5041 | |
| 5042 | // Detect taps and flings. |
| 5043 | if (action == MotionEvent.ACTION_UP) { |
Michael Wright | 88d7f79 | 2013-08-27 15:45:42 -0700 | [diff] [blame] | 5044 | if (mConsumedMovement && mPendingKeyCode != KeyEvent.KEYCODE_UNKNOWN) { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5045 | // It might be a fling. |
| 5046 | mVelocityTracker.computeCurrentVelocity(1000, mConfigMaxFlingVelocity); |
| 5047 | final float vx = mVelocityTracker.getXVelocity(mActivePointerId); |
| 5048 | final float vy = mVelocityTracker.getYVelocity(mActivePointerId); |
| 5049 | if (!startFling(time, vx, vy)) { |
| 5050 | finishKeys(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5051 | } |
| 5052 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5053 | finishTracking(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5054 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5055 | break; |
| 5056 | } |
| 5057 | |
| 5058 | case MotionEvent.ACTION_CANCEL: { |
| 5059 | finishKeys(time); |
| 5060 | finishTracking(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5061 | break; |
| 5062 | } |
| 5063 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5064 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5065 | |
| 5066 | public void cancel(MotionEvent event) { |
| 5067 | if (mCurrentDeviceId == event.getDeviceId() |
| 5068 | && mCurrentSource == event.getSource()) { |
| 5069 | final long time = event.getEventTime(); |
| 5070 | finishKeys(time); |
| 5071 | finishTracking(time); |
| 5072 | } |
| 5073 | } |
| 5074 | |
| 5075 | private void finishKeys(long time) { |
| 5076 | cancelFling(); |
| 5077 | sendKeyUp(time); |
| 5078 | } |
| 5079 | |
| 5080 | private void finishTracking(long time) { |
| 5081 | if (mActivePointerId >= 0) { |
| 5082 | mActivePointerId = -1; |
| 5083 | mVelocityTracker.recycle(); |
| 5084 | mVelocityTracker = null; |
| 5085 | } |
| 5086 | } |
| 5087 | |
| 5088 | private void consumeAccumulatedMovement(long time, int metaState) { |
| 5089 | final float absX = Math.abs(mAccumulatedX); |
| 5090 | final float absY = Math.abs(mAccumulatedY); |
| 5091 | if (absX >= absY) { |
| 5092 | if (absX >= mConfigTickDistance) { |
| 5093 | mAccumulatedX = consumeAccumulatedMovement(time, metaState, mAccumulatedX, |
| 5094 | KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_RIGHT); |
| 5095 | mAccumulatedY = 0; |
| 5096 | mConsumedMovement = true; |
| 5097 | } |
| 5098 | } else { |
| 5099 | if (absY >= mConfigTickDistance) { |
| 5100 | mAccumulatedY = consumeAccumulatedMovement(time, metaState, mAccumulatedY, |
| 5101 | KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN); |
| 5102 | mAccumulatedX = 0; |
| 5103 | mConsumedMovement = true; |
| 5104 | } |
| 5105 | } |
| 5106 | } |
| 5107 | |
| 5108 | private float consumeAccumulatedMovement(long time, int metaState, |
| 5109 | float accumulator, int negativeKeyCode, int positiveKeyCode) { |
| 5110 | while (accumulator <= -mConfigTickDistance) { |
| 5111 | sendKeyDownOrRepeat(time, negativeKeyCode, metaState); |
| 5112 | accumulator += mConfigTickDistance; |
| 5113 | } |
| 5114 | while (accumulator >= mConfigTickDistance) { |
| 5115 | sendKeyDownOrRepeat(time, positiveKeyCode, metaState); |
| 5116 | accumulator -= mConfigTickDistance; |
| 5117 | } |
| 5118 | return accumulator; |
| 5119 | } |
| 5120 | |
| 5121 | private void sendKeyDownOrRepeat(long time, int keyCode, int metaState) { |
| 5122 | if (mPendingKeyCode != keyCode) { |
| 5123 | sendKeyUp(time); |
| 5124 | mPendingKeyDownTime = time; |
| 5125 | mPendingKeyCode = keyCode; |
| 5126 | mPendingKeyRepeatCount = 0; |
| 5127 | } else { |
| 5128 | mPendingKeyRepeatCount += 1; |
| 5129 | } |
| 5130 | mPendingKeyMetaState = metaState; |
| 5131 | |
| 5132 | // Note: Normally we would pass FLAG_LONG_PRESS when the repeat count is 1 |
| 5133 | // but it doesn't quite make sense when simulating the events in this way. |
| 5134 | if (LOCAL_DEBUG) { |
| 5135 | Log.d(LOCAL_TAG, "Sending key down: keyCode=" + mPendingKeyCode |
| 5136 | + ", repeatCount=" + mPendingKeyRepeatCount |
| 5137 | + ", metaState=" + Integer.toHexString(mPendingKeyMetaState)); |
| 5138 | } |
| 5139 | enqueueInputEvent(new KeyEvent(mPendingKeyDownTime, time, |
| 5140 | KeyEvent.ACTION_DOWN, mPendingKeyCode, mPendingKeyRepeatCount, |
| 5141 | mPendingKeyMetaState, mCurrentDeviceId, |
| 5142 | KeyEvent.FLAG_FALLBACK, mCurrentSource)); |
| 5143 | } |
| 5144 | |
| 5145 | private void sendKeyUp(long time) { |
| 5146 | if (mPendingKeyCode != KeyEvent.KEYCODE_UNKNOWN) { |
| 5147 | if (LOCAL_DEBUG) { |
| 5148 | Log.d(LOCAL_TAG, "Sending key up: keyCode=" + mPendingKeyCode |
| 5149 | + ", metaState=" + Integer.toHexString(mPendingKeyMetaState)); |
| 5150 | } |
| 5151 | enqueueInputEvent(new KeyEvent(mPendingKeyDownTime, time, |
| 5152 | KeyEvent.ACTION_UP, mPendingKeyCode, 0, mPendingKeyMetaState, |
| 5153 | mCurrentDeviceId, 0, KeyEvent.FLAG_FALLBACK, |
| 5154 | mCurrentSource)); |
| 5155 | mPendingKeyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 5156 | } |
| 5157 | } |
| 5158 | |
| 5159 | private boolean startFling(long time, float vx, float vy) { |
| 5160 | if (LOCAL_DEBUG) { |
| 5161 | Log.d(LOCAL_TAG, "Considering fling: vx=" + vx + ", vy=" + vy |
| 5162 | + ", min=" + mConfigMinFlingVelocity); |
| 5163 | } |
| 5164 | |
| 5165 | // Flings must be oriented in the same direction as the preceding movements. |
| 5166 | switch (mPendingKeyCode) { |
| 5167 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 5168 | if (-vx >= mConfigMinFlingVelocity |
| 5169 | && Math.abs(vy) < mConfigMinFlingVelocity) { |
| 5170 | mFlingVelocity = -vx; |
| 5171 | break; |
| 5172 | } |
| 5173 | return false; |
| 5174 | |
| 5175 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 5176 | if (vx >= mConfigMinFlingVelocity |
| 5177 | && Math.abs(vy) < mConfigMinFlingVelocity) { |
| 5178 | mFlingVelocity = vx; |
| 5179 | break; |
| 5180 | } |
| 5181 | return false; |
| 5182 | |
| 5183 | case KeyEvent.KEYCODE_DPAD_UP: |
| 5184 | if (-vy >= mConfigMinFlingVelocity |
| 5185 | && Math.abs(vx) < mConfigMinFlingVelocity) { |
| 5186 | mFlingVelocity = -vy; |
| 5187 | break; |
| 5188 | } |
| 5189 | return false; |
| 5190 | |
| 5191 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 5192 | if (vy >= mConfigMinFlingVelocity |
| 5193 | && Math.abs(vx) < mConfigMinFlingVelocity) { |
| 5194 | mFlingVelocity = vy; |
| 5195 | break; |
| 5196 | } |
| 5197 | return false; |
| 5198 | } |
| 5199 | |
| 5200 | // Post the first fling event. |
| 5201 | mFlinging = postFling(time); |
| 5202 | return mFlinging; |
| 5203 | } |
| 5204 | |
| 5205 | private boolean postFling(long time) { |
| 5206 | // The idea here is to estimate the time when the pointer would have |
| 5207 | // traveled one tick distance unit given the current fling velocity. |
| 5208 | // This effect creates continuity of motion. |
| 5209 | if (mFlingVelocity >= mConfigMinFlingVelocity) { |
| 5210 | long delay = (long)(mConfigTickDistance / mFlingVelocity * 1000); |
| 5211 | postAtTime(mFlingRunnable, time + delay); |
| 5212 | if (LOCAL_DEBUG) { |
| 5213 | Log.d(LOCAL_TAG, "Posted fling: velocity=" |
| 5214 | + mFlingVelocity + ", delay=" + delay |
| 5215 | + ", keyCode=" + mPendingKeyCode); |
| 5216 | } |
| 5217 | return true; |
| 5218 | } |
| 5219 | return false; |
| 5220 | } |
| 5221 | |
| 5222 | private void cancelFling() { |
| 5223 | if (mFlinging) { |
| 5224 | removeCallbacks(mFlingRunnable); |
| 5225 | mFlinging = false; |
| 5226 | } |
| 5227 | } |
| 5228 | |
| 5229 | private final Runnable mFlingRunnable = new Runnable() { |
| 5230 | @Override |
| 5231 | public void run() { |
| 5232 | final long time = SystemClock.uptimeMillis(); |
| 5233 | sendKeyDownOrRepeat(time, mPendingKeyCode, mPendingKeyMetaState); |
| 5234 | mFlingVelocity *= FLING_TICK_DECAY; |
| 5235 | if (!postFling(time)) { |
| 5236 | mFlinging = false; |
| 5237 | finishKeys(time); |
| 5238 | } |
| 5239 | } |
| 5240 | }; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5241 | } |
| 5242 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5243 | final class SyntheticKeyboardHandler { |
| 5244 | public void process(KeyEvent event) { |
| 5245 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) != 0) { |
| 5246 | return; |
| 5247 | } |
| 5248 | |
| 5249 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 5250 | final int keyCode = event.getKeyCode(); |
| 5251 | final int metaState = event.getMetaState(); |
| 5252 | |
| 5253 | // Check for fallback actions specified by the key character map. |
| 5254 | KeyCharacterMap.FallbackAction fallbackAction = |
| 5255 | kcm.getFallbackAction(keyCode, metaState); |
| 5256 | if (fallbackAction != null) { |
| 5257 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 5258 | KeyEvent fallbackEvent = KeyEvent.obtain( |
| 5259 | event.getDownTime(), event.getEventTime(), |
| 5260 | event.getAction(), fallbackAction.keyCode, |
| 5261 | event.getRepeatCount(), fallbackAction.metaState, |
| 5262 | event.getDeviceId(), event.getScanCode(), |
| 5263 | flags, event.getSource(), null); |
| 5264 | fallbackAction.recycle(); |
| 5265 | enqueueInputEvent(fallbackEvent); |
| 5266 | } |
| 5267 | } |
| 5268 | } |
| 5269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5270 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5271 | * Returns true if the key is used for keyboard navigation. |
| 5272 | * @param keyEvent The key event. |
| 5273 | * @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] | 5274 | */ |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5275 | private static boolean isNavigationKey(KeyEvent keyEvent) { |
| 5276 | switch (keyEvent.getKeyCode()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5277 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 5278 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 5279 | case KeyEvent.KEYCODE_DPAD_UP: |
| 5280 | case KeyEvent.KEYCODE_DPAD_DOWN: |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5281 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 5282 | case KeyEvent.KEYCODE_PAGE_UP: |
| 5283 | case KeyEvent.KEYCODE_PAGE_DOWN: |
| 5284 | case KeyEvent.KEYCODE_MOVE_HOME: |
| 5285 | case KeyEvent.KEYCODE_MOVE_END: |
| 5286 | case KeyEvent.KEYCODE_TAB: |
| 5287 | case KeyEvent.KEYCODE_SPACE: |
| 5288 | case KeyEvent.KEYCODE_ENTER: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5289 | return true; |
| 5290 | } |
| 5291 | return false; |
| 5292 | } |
| 5293 | |
| 5294 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5295 | * Returns true if the key is used for typing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5296 | * @param keyEvent The key event. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5297 | * @return True if the key is used for typing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5298 | */ |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5299 | private static boolean isTypingKey(KeyEvent keyEvent) { |
| 5300 | return keyEvent.getUnicodeChar() > 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5301 | } |
| 5302 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5303 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5304 | * 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] | 5305 | * @param event The key event. |
| 5306 | * @return Whether this key event should be consumed (meaning the act of |
| 5307 | * leaving touch mode alone is considered the event). |
| 5308 | */ |
| 5309 | private boolean checkForLeavingTouchModeAndConsume(KeyEvent event) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5310 | // Only relevant in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5311 | if (!mAttachInfo.mInTouchMode) { |
| 5312 | return false; |
| 5313 | } |
| 5314 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5315 | // Only consider leaving touch mode on DOWN or MULTIPLE actions, never on UP. |
| 5316 | final int action = event.getAction(); |
| 5317 | if (action != KeyEvent.ACTION_DOWN && action != KeyEvent.ACTION_MULTIPLE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5318 | return false; |
| 5319 | } |
| 5320 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5321 | // Don't leave touch mode if the IME told us not to. |
| 5322 | if ((event.getFlags() & KeyEvent.FLAG_KEEP_TOUCH_MODE) != 0) { |
| 5323 | return false; |
| 5324 | } |
| 5325 | |
| 5326 | // If the key can be used for keyboard navigation then leave touch mode |
| 5327 | // and select a focused view if needed (in ensureTouchMode). |
| 5328 | // When a new focused view is selected, we consume the navigation key because |
| 5329 | // navigation doesn't make much sense unless a view already has focus so |
| 5330 | // the key's purpose is to set focus. |
| 5331 | if (isNavigationKey(event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5332 | return ensureTouchMode(false); |
| 5333 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5334 | |
| 5335 | // If the key can be used for typing then leave touch mode |
| 5336 | // and select a focused view if needed (in ensureTouchMode). |
| 5337 | // Always allow the view to process the typing key. |
| 5338 | if (isTypingKey(event)) { |
| 5339 | ensureTouchMode(false); |
| 5340 | return false; |
| 5341 | } |
| 5342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5343 | return false; |
| 5344 | } |
| 5345 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5346 | /* drag/drop */ |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5347 | void setLocalDragState(Object obj) { |
| 5348 | mLocalDragState = obj; |
| 5349 | } |
| 5350 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5351 | private void handleDragEvent(DragEvent event) { |
| 5352 | // From the root, only drag start/end/location are dispatched. entered/exited |
| 5353 | // are determined and dispatched by the viewgroup hierarchy, who then report |
| 5354 | // that back here for ultimate reporting back to the framework. |
| 5355 | if (mView != null && mAdded) { |
| 5356 | final int what = event.mAction; |
| 5357 | |
| 5358 | if (what == DragEvent.ACTION_DRAG_EXITED) { |
| 5359 | // A direct EXITED event means that the window manager knows we've just crossed |
| 5360 | // a window boundary, so the current drag target within this one must have |
| 5361 | // just been exited. Send it the usual notifications and then we're done |
| 5362 | // for now. |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 5363 | mView.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5364 | } else { |
| 5365 | // Cache the drag description when the operation starts, then fill it in |
| 5366 | // on subsequent calls as a convenience |
| 5367 | if (what == DragEvent.ACTION_DRAG_STARTED) { |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 5368 | mCurrentDragView = null; // Start the current-recipient tracking |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5369 | mDragDescription = event.mClipDescription; |
| 5370 | } else { |
| 5371 | event.mClipDescription = mDragDescription; |
| 5372 | } |
| 5373 | |
| 5374 | // For events with a [screen] location, translate into window coordinates |
| 5375 | if ((what == DragEvent.ACTION_DRAG_LOCATION) || (what == DragEvent.ACTION_DROP)) { |
| 5376 | mDragPoint.set(event.mX, event.mY); |
| 5377 | if (mTranslator != null) { |
| 5378 | mTranslator.translatePointInScreenToAppWindow(mDragPoint); |
| 5379 | } |
| 5380 | |
| 5381 | if (mCurScrollY != 0) { |
| 5382 | mDragPoint.offset(0, mCurScrollY); |
| 5383 | } |
| 5384 | |
| 5385 | event.mX = mDragPoint.x; |
| 5386 | event.mY = mDragPoint.y; |
| 5387 | } |
| 5388 | |
| 5389 | // Remember who the current drag target is pre-dispatch |
| 5390 | final View prevDragView = mCurrentDragView; |
| 5391 | |
| 5392 | // Now dispatch the drag/drop event |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5393 | boolean result = mView.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5394 | |
| 5395 | // If we changed apparent drag target, tell the OS about it |
| 5396 | if (prevDragView != mCurrentDragView) { |
| 5397 | try { |
| 5398 | if (prevDragView != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5399 | mWindowSession.dragRecipientExited(mWindow); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5400 | } |
| 5401 | if (mCurrentDragView != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5402 | mWindowSession.dragRecipientEntered(mWindow); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5403 | } |
| 5404 | } catch (RemoteException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5405 | Slog.e(mTag, "Unable to note drag target change"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5406 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5407 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5408 | |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5409 | // Report the drop result when we're done |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5410 | if (what == DragEvent.ACTION_DROP) { |
Christopher Tate | 1fc014f | 2011-01-19 12:56:26 -0800 | [diff] [blame] | 5411 | mDragDescription = null; |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5412 | try { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5413 | Log.i(mTag, "Reporting drop result: " + result); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5414 | mWindowSession.reportDropResult(mWindow, result); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5415 | } catch (RemoteException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5416 | Log.e(mTag, "Unable to report drop result"); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5417 | } |
| 5418 | } |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5419 | |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 5420 | // When the drag operation ends, reset drag-related state |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5421 | if (what == DragEvent.ACTION_DRAG_ENDED) { |
| 5422 | setLocalDragState(null); |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 5423 | mAttachInfo.mDragToken = null; |
Vladislav Kaznacheev | 4f63974 | 2015-11-18 13:21:35 -0800 | [diff] [blame] | 5424 | if (mAttachInfo.mDragSurface != null) { |
| 5425 | mAttachInfo.mDragSurface.release(); |
| 5426 | mAttachInfo.mDragSurface = null; |
| 5427 | } |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5428 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5429 | } |
| 5430 | } |
| 5431 | event.recycle(); |
| 5432 | } |
| 5433 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5434 | public void handleDispatchSystemUiVisibilityChanged(SystemUiVisibilityInfo args) { |
| 5435 | if (mSeq != args.seq) { |
| 5436 | // The sequence has changed, so we need to update our value and make |
| 5437 | // sure to do a traversal afterward so the window manager is given our |
| 5438 | // most recent data. |
| 5439 | mSeq = args.seq; |
| 5440 | mAttachInfo.mForceReportNewAttributes = true; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5441 | scheduleTraversals(); |
Joe Onorato | 14782f7 | 2011-01-25 19:53:17 -0800 | [diff] [blame] | 5442 | } |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5443 | if (mView == null) return; |
| 5444 | if (args.localChanges != 0) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5445 | mView.updateLocalSystemUiVisibility(args.localValue, args.localChanges); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5446 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 5447 | |
| 5448 | int visibility = args.globalVisibility&View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 5449 | if (visibility != mAttachInfo.mGlobalSystemUiVisibility) { |
| 5450 | mAttachInfo.mGlobalSystemUiVisibility = visibility; |
| 5451 | mView.dispatchSystemUiVisibilityChanged(visibility); |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5452 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5453 | } |
| 5454 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 5455 | public void handleDispatchWindowShown() { |
| 5456 | mAttachInfo.mTreeObserver.dispatchOnWindowShown(); |
| 5457 | } |
| 5458 | |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 5459 | public void handleRequestKeyboardShortcuts(IResultReceiver receiver) { |
| 5460 | Bundle data = new Bundle(); |
| 5461 | ArrayList<KeyboardShortcutGroup> list = new ArrayList<>(); |
| 5462 | if (mView != null) { |
| 5463 | mView.requestKeyboardShortcuts(list); |
| 5464 | } |
| 5465 | data.putParcelableArrayList(WindowManager.PARCEL_KEY_SHORTCUTS_ARRAY, list); |
| 5466 | try { |
| 5467 | receiver.send(0, data); |
| 5468 | } catch (RemoteException e) { |
| 5469 | } |
| 5470 | } |
| 5471 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5472 | public void getLastTouchPoint(Point outLocation) { |
| 5473 | outLocation.x = (int) mLastTouchPoint.x; |
| 5474 | outLocation.y = (int) mLastTouchPoint.y; |
| 5475 | } |
| 5476 | |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 5477 | public void setDragFocus(View newDragTarget) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5478 | if (mCurrentDragView != newDragTarget) { |
Chris Tate | 048691c | 2010-10-12 17:39:18 -0700 | [diff] [blame] | 5479 | mCurrentDragView = newDragTarget; |
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 | } |
| 5482 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5483 | private AudioManager getAudioManager() { |
| 5484 | if (mView == null) { |
| 5485 | throw new IllegalStateException("getAudioManager called when there is no mView"); |
| 5486 | } |
| 5487 | if (mAudioManager == null) { |
| 5488 | mAudioManager = (AudioManager) mView.getContext().getSystemService(Context.AUDIO_SERVICE); |
| 5489 | } |
| 5490 | return mAudioManager; |
| 5491 | } |
| 5492 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5493 | public AccessibilityInteractionController getAccessibilityInteractionController() { |
| 5494 | if (mView == null) { |
| 5495 | throw new IllegalStateException("getAccessibilityInteractionController" |
| 5496 | + " called when there is no mView"); |
| 5497 | } |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 5498 | if (mAccessibilityInteractionController == null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5499 | mAccessibilityInteractionController = new AccessibilityInteractionController(this); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5500 | } |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 5501 | return mAccessibilityInteractionController; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5502 | } |
| 5503 | |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 5504 | private int relayoutWindow(WindowManager.LayoutParams params, int viewVisibility, |
| 5505 | boolean insetsPending) throws RemoteException { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5506 | |
| 5507 | float appScale = mAttachInfo.mApplicationScale; |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5508 | boolean restore = false; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5509 | if (params != null && mTranslator != null) { |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 5510 | restore = true; |
| 5511 | params.backup(); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5512 | mTranslator.translateWindowLayout(params); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5513 | } |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5514 | if (params != null) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5515 | if (DBG) Log.d(mTag, "WindowLayout in layoutWindow:" + params); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5516 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 5517 | mPendingConfiguration.seq = 0; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5518 | //Log.d(mTag, ">>>>>> CALLING relayout"); |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 5519 | if (params != null && mOrigWindowType != params.type) { |
| 5520 | // For compatibility with old apps, don't crash here. |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 5521 | if (mTargetSdkVersion < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5522 | Slog.w(mTag, "Window type can not be changed after " |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 5523 | + "the window is added; ignoring change of " + mView); |
| 5524 | params.type = mOrigWindowType; |
| 5525 | } |
| 5526 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5527 | int relayoutResult = mWindowSession.relayout( |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5528 | mWindow, mSeq, params, |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 5529 | (int) (mView.getMeasuredWidth() * appScale + 0.5f), |
| 5530 | (int) (mView.getMeasuredHeight() * appScale + 0.5f), |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5531 | viewVisibility, insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5532 | mWinFrame, mPendingOverscanInsets, mPendingContentInsets, mPendingVisibleInsets, |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 5533 | mPendingStableInsets, mPendingOutsets, mPendingBackDropFrame, mPendingConfiguration, |
| 5534 | mSurface); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5535 | //Log.d(mTag, "<<<<<< BACK FROM relayout"); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5536 | if (restore) { |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 5537 | params.restore(); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5538 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5539 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5540 | if (mTranslator != null) { |
| 5541 | mTranslator.translateRectInScreenToAppWinFrame(mWinFrame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5542 | mTranslator.translateRectInScreenToAppWindow(mPendingOverscanInsets); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5543 | mTranslator.translateRectInScreenToAppWindow(mPendingContentInsets); |
| 5544 | mTranslator.translateRectInScreenToAppWindow(mPendingVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 5545 | mTranslator.translateRectInScreenToAppWindow(mPendingStableInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5546 | } |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 5547 | return relayoutResult; |
| 5548 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5549 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5550 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5551 | * {@inheritDoc} |
| 5552 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5553 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5554 | public void playSoundEffect(int effectId) { |
| 5555 | checkThread(); |
| 5556 | |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 5557 | try { |
| 5558 | final AudioManager audioManager = getAudioManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5559 | |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 5560 | switch (effectId) { |
| 5561 | case SoundEffectConstants.CLICK: |
| 5562 | audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK); |
| 5563 | return; |
| 5564 | case SoundEffectConstants.NAVIGATION_DOWN: |
| 5565 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_DOWN); |
| 5566 | return; |
| 5567 | case SoundEffectConstants.NAVIGATION_LEFT: |
| 5568 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_LEFT); |
| 5569 | return; |
| 5570 | case SoundEffectConstants.NAVIGATION_RIGHT: |
| 5571 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_RIGHT); |
| 5572 | return; |
| 5573 | case SoundEffectConstants.NAVIGATION_UP: |
| 5574 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_UP); |
| 5575 | return; |
| 5576 | default: |
| 5577 | throw new IllegalArgumentException("unknown effect id " + effectId + |
| 5578 | " not defined in " + SoundEffectConstants.class.getCanonicalName()); |
| 5579 | } |
| 5580 | } catch (IllegalStateException e) { |
| 5581 | // Exception thrown by getAudioManager() when mView is null |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5582 | 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] | 5583 | e.printStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5584 | } |
| 5585 | } |
| 5586 | |
| 5587 | /** |
| 5588 | * {@inheritDoc} |
| 5589 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5590 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5591 | public boolean performHapticFeedback(int effectId, boolean always) { |
| 5592 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5593 | return mWindowSession.performHapticFeedback(mWindow, effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5594 | } catch (RemoteException e) { |
| 5595 | return false; |
| 5596 | } |
| 5597 | } |
| 5598 | |
| 5599 | /** |
| 5600 | * {@inheritDoc} |
| 5601 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5602 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5603 | public View focusSearch(View focused, int direction) { |
| 5604 | checkThread(); |
| 5605 | if (!(mView instanceof ViewGroup)) { |
| 5606 | return null; |
| 5607 | } |
| 5608 | return FocusFinder.getInstance().findNextFocus((ViewGroup) mView, focused, direction); |
| 5609 | } |
| 5610 | |
| 5611 | public void debug() { |
| 5612 | mView.debug(); |
| 5613 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5614 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5615 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 5616 | String innerPrefix = prefix + " "; |
| 5617 | writer.print(prefix); writer.println("ViewRoot:"); |
| 5618 | writer.print(innerPrefix); writer.print("mAdded="); writer.print(mAdded); |
| 5619 | writer.print(" mRemoved="); writer.println(mRemoved); |
| 5620 | writer.print(innerPrefix); writer.print("mConsumeBatchedInputScheduled="); |
| 5621 | writer.println(mConsumeBatchedInputScheduled); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 5622 | writer.print(innerPrefix); writer.print("mConsumeBatchedInputImmediatelyScheduled="); |
| 5623 | writer.println(mConsumeBatchedInputImmediatelyScheduled); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5624 | writer.print(innerPrefix); writer.print("mPendingInputEventCount="); |
| 5625 | writer.println(mPendingInputEventCount); |
| 5626 | writer.print(innerPrefix); writer.print("mProcessInputEventsScheduled="); |
| 5627 | writer.println(mProcessInputEventsScheduled); |
| 5628 | writer.print(innerPrefix); writer.print("mTraversalScheduled="); |
| 5629 | writer.print(mTraversalScheduled); |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 5630 | writer.print(innerPrefix); writer.print("mIsAmbientMode="); |
| 5631 | writer.print(mIsAmbientMode); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5632 | if (mTraversalScheduled) { |
| 5633 | writer.print(" (barrier="); writer.print(mTraversalBarrier); writer.println(")"); |
| 5634 | } else { |
| 5635 | writer.println(); |
| 5636 | } |
| 5637 | mFirstInputStage.dump(innerPrefix, writer); |
| 5638 | |
| 5639 | mChoreographer.dump(prefix, writer); |
| 5640 | |
| 5641 | writer.print(prefix); writer.println("View Hierarchy:"); |
| 5642 | dumpViewHierarchy(innerPrefix, writer, mView); |
| 5643 | } |
| 5644 | |
| 5645 | private void dumpViewHierarchy(String prefix, PrintWriter writer, View view) { |
| 5646 | writer.print(prefix); |
| 5647 | if (view == null) { |
| 5648 | writer.println("null"); |
| 5649 | return; |
| 5650 | } |
| 5651 | writer.println(view.toString()); |
| 5652 | if (!(view instanceof ViewGroup)) { |
| 5653 | return; |
| 5654 | } |
| 5655 | ViewGroup grp = (ViewGroup)view; |
| 5656 | final int N = grp.getChildCount(); |
| 5657 | if (N <= 0) { |
| 5658 | return; |
| 5659 | } |
| 5660 | prefix = prefix + " "; |
| 5661 | for (int i=0; i<N; i++) { |
| 5662 | dumpViewHierarchy(prefix, writer, grp.getChildAt(i)); |
| 5663 | } |
| 5664 | } |
| 5665 | |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 5666 | public void dumpGfxInfo(int[] info) { |
Romain Guy | 54ab347 | 2012-06-14 12:52:53 -0700 | [diff] [blame] | 5667 | info[0] = info[1] = 0; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5668 | if (mView != null) { |
| 5669 | getGfxInfo(mView, info); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5670 | } |
| 5671 | } |
| 5672 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5673 | private static void getGfxInfo(View view, int[] info) { |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 5674 | RenderNode renderNode = view.mRenderNode; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5675 | info[0]++; |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 5676 | if (renderNode != null) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 5677 | info[1] += renderNode.getDebugSize(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5678 | } |
| 5679 | |
| 5680 | if (view instanceof ViewGroup) { |
| 5681 | ViewGroup group = (ViewGroup) view; |
| 5682 | |
| 5683 | int count = group.getChildCount(); |
| 5684 | for (int i = 0; i < count; i++) { |
| 5685 | getGfxInfo(group.getChildAt(i), info); |
| 5686 | } |
| 5687 | } |
| 5688 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5689 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5690 | /** |
| 5691 | * @param immediate True, do now if not in traversal. False, put on queue and do later. |
| 5692 | * @return True, request has been queued. False, request has been completed. |
| 5693 | */ |
| 5694 | boolean die(boolean immediate) { |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 5695 | // Make sure we do execute immediately if we are in the middle of a traversal or the damage |
| 5696 | // done by dispatchDetachedFromWindow will cause havoc on return. |
| 5697 | if (immediate && !mIsInTraversal) { |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 5698 | doDie(); |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5699 | return false; |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 5700 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5701 | |
| 5702 | if (!mIsDrawing) { |
| 5703 | destroyHardwareRenderer(); |
| 5704 | } else { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5705 | Log.e(mTag, "Attempting to destroy the window while drawing!\n" + |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5706 | " window=" + this + ", title=" + mWindowAttributes.getTitle()); |
| 5707 | } |
| 5708 | mHandler.sendEmptyMessage(MSG_DIE); |
| 5709 | return true; |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 5710 | } |
| 5711 | |
| 5712 | void doDie() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5713 | checkThread(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5714 | 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] | 5715 | synchronized (this) { |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5716 | if (mRemoved) { |
| 5717 | return; |
| 5718 | } |
| 5719 | mRemoved = true; |
Romain Guy | 16260e7 | 2011-09-01 14:26:11 -0700 | [diff] [blame] | 5720 | if (mAdded) { |
Romain Guy | 16260e7 | 2011-09-01 14:26:11 -0700 | [diff] [blame] | 5721 | dispatchDetachedFromWindow(); |
| 5722 | } |
| 5723 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5724 | if (mAdded && !mFirst) { |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 5725 | destroyHardwareRenderer(); |
| 5726 | |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5727 | if (mView != null) { |
| 5728 | int viewVisibility = mView.getVisibility(); |
| 5729 | boolean viewVisibilityChanged = mViewVisibility != viewVisibility; |
| 5730 | if (mWindowAttributesChanged || viewVisibilityChanged) { |
| 5731 | // If layout params have been changed, first give them |
| 5732 | // to the window manager to make sure it has the correct |
| 5733 | // animation info. |
| 5734 | try { |
| 5735 | if ((relayoutWindow(mWindowAttributes, viewVisibility, false) |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5736 | & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { |
| 5737 | mWindowSession.finishDrawing(mWindow); |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5738 | } |
| 5739 | } catch (RemoteException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5740 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5741 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5742 | |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5743 | mSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5744 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5745 | } |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5746 | |
| 5747 | mAdded = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5748 | } |
Craig Mautner | 05eb730 | 2013-06-03 17:24:21 -0700 | [diff] [blame] | 5749 | WindowManagerGlobal.getInstance().doRemoveView(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5750 | } |
| 5751 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5752 | public void requestUpdateConfiguration(Configuration config) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 5753 | Message msg = mHandler.obtainMessage(MSG_UPDATE_CONFIGURATION, config); |
| 5754 | mHandler.sendMessage(msg); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5755 | } |
| 5756 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 5757 | public void loadSystemProperties() { |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 5758 | mHandler.post(new Runnable() { |
| 5759 | @Override |
| 5760 | public void run() { |
| 5761 | // Profiling |
| 5762 | mProfileRendering = SystemProperties.getBoolean(PROPERTY_PROFILE_RENDERING, false); |
| 5763 | profileRendering(mAttachInfo.mHasWindowFocus); |
| 5764 | |
| 5765 | // Hardware rendering |
| 5766 | if (mAttachInfo.mHardwareRenderer != null) { |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 5767 | if (mAttachInfo.mHardwareRenderer.loadSystemProperties()) { |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 5768 | invalidate(); |
| 5769 | } |
| 5770 | } |
| 5771 | |
| 5772 | // Layout debugging |
| 5773 | boolean layout = SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false); |
| 5774 | if (layout != mAttachInfo.mDebugLayout) { |
| 5775 | mAttachInfo.mDebugLayout = layout; |
| 5776 | if (!mHandler.hasMessages(MSG_INVALIDATE_WORLD)) { |
| 5777 | mHandler.sendEmptyMessageDelayed(MSG_INVALIDATE_WORLD, 200); |
| 5778 | } |
| 5779 | } |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 5780 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 5781 | }); |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 5782 | } |
| 5783 | |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 5784 | private void destroyHardwareRenderer() { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5785 | ThreadedRenderer hardwareRenderer = mAttachInfo.mHardwareRenderer; |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5786 | |
| 5787 | if (hardwareRenderer != null) { |
| 5788 | if (mView != null) { |
| 5789 | hardwareRenderer.destroyHardwareResources(mView); |
| 5790 | } |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 5791 | hardwareRenderer.destroy(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5792 | hardwareRenderer.setRequested(false); |
| 5793 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 5794 | mAttachInfo.mHardwareRenderer = null; |
| 5795 | mAttachInfo.mHardwareAccelerated = false; |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 5796 | } |
| 5797 | } |
| 5798 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 5799 | public void dispatchFinishInputConnection(InputConnection connection) { |
| 5800 | Message msg = mHandler.obtainMessage(MSG_FINISH_INPUT_CONNECTION, connection); |
| 5801 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5802 | } |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5803 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5804 | public void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5805 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 5806 | Configuration newConfig, Rect backDropFrame) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5807 | if (DEBUG_LAYOUT) Log.v(mTag, "Resizing " + this + ": frame=" + frame.toShortString() |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5808 | + " contentInsets=" + contentInsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5809 | + " visibleInsets=" + visibleInsets.toShortString() |
Chong Zhang | d153c4f | 2015-11-06 20:26:40 -0800 | [diff] [blame] | 5810 | + " reportDraw=" + reportDraw |
| 5811 | + " backDropFrame=" + backDropFrame); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 5812 | |
| 5813 | // Tell all listeners that we are resizing the window so that the chrome can get |
| 5814 | // updated as fast as possible on a separate thread, |
| 5815 | if (mDragResizing) { |
| 5816 | synchronized (mWindowCallbacks) { |
| 5817 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 5818 | mWindowCallbacks.get(i).onWindowSizeIsChanging(backDropFrame); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 5819 | } |
| 5820 | } |
| 5821 | } |
| 5822 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5823 | Message msg = mHandler.obtainMessage(reportDraw ? MSG_RESIZED_REPORT : MSG_RESIZED); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5824 | if (mTranslator != null) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5825 | mTranslator.translateRectInScreenToAppWindow(frame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5826 | mTranslator.translateRectInScreenToAppWindow(overscanInsets); |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 5827 | mTranslator.translateRectInScreenToAppWindow(contentInsets); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5828 | mTranslator.translateRectInScreenToAppWindow(visibleInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5829 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5830 | SomeArgs args = SomeArgs.obtain(); |
| 5831 | final boolean sameProcessCall = (Binder.getCallingPid() == android.os.Process.myPid()); |
| 5832 | args.arg1 = sameProcessCall ? new Rect(frame) : frame; |
| 5833 | args.arg2 = sameProcessCall ? new Rect(contentInsets) : contentInsets; |
| 5834 | args.arg3 = sameProcessCall ? new Rect(visibleInsets) : visibleInsets; |
| 5835 | args.arg4 = sameProcessCall && newConfig != null ? new Configuration(newConfig) : newConfig; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5836 | args.arg5 = sameProcessCall ? new Rect(overscanInsets) : overscanInsets; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 5837 | args.arg6 = sameProcessCall ? new Rect(stableInsets) : stableInsets; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5838 | args.arg7 = sameProcessCall ? new Rect(outsets) : outsets; |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 5839 | args.arg8 = sameProcessCall ? new Rect(backDropFrame) : backDropFrame; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5840 | msg.obj = args; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 5841 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5842 | } |
Chet Haase | 1f4786b | 2011-11-02 10:51:52 -0700 | [diff] [blame] | 5843 | |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 5844 | public void dispatchMoved(int newX, int newY) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5845 | 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] | 5846 | if (mTranslator != null) { |
| 5847 | PointF point = new PointF(newX, newY); |
| 5848 | mTranslator.translatePointInScreenToAppWindow(point); |
| 5849 | newX = (int) (point.x + 0.5); |
| 5850 | newY = (int) (point.y + 0.5); |
| 5851 | } |
| 5852 | Message msg = mHandler.obtainMessage(MSG_WINDOW_MOVED, newX, newY); |
| 5853 | mHandler.sendMessage(msg); |
| 5854 | } |
| 5855 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5856 | /** |
| 5857 | * Represents a pending input event that is waiting in a queue. |
| 5858 | * |
| 5859 | * Input events are processed in serial order by the timestamp specified by |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 5860 | * {@link InputEvent#getEventTimeNano()}. In general, the input dispatcher delivers |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5861 | * one input event to the application at a time and waits for the application |
| 5862 | * to finish handling it before delivering the next one. |
| 5863 | * |
| 5864 | * However, because the application or IME can synthesize and inject multiple |
| 5865 | * key events at a time without going through the input dispatcher, we end up |
| 5866 | * needing a queue on the application's side. |
| 5867 | */ |
| 5868 | private static final class QueuedInputEvent { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5869 | public static final int FLAG_DELIVER_POST_IME = 1 << 0; |
| 5870 | public static final int FLAG_DEFERRED = 1 << 1; |
| 5871 | public static final int FLAG_FINISHED = 1 << 2; |
| 5872 | public static final int FLAG_FINISHED_HANDLED = 1 << 3; |
| 5873 | public static final int FLAG_RESYNTHESIZED = 1 << 4; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5874 | public static final int FLAG_UNHANDLED = 1 << 5; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5875 | |
| 5876 | public QueuedInputEvent mNext; |
| 5877 | |
| 5878 | public InputEvent mEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 5879 | public InputEventReceiver mReceiver; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5880 | public int mFlags; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5881 | |
| 5882 | public boolean shouldSkipIme() { |
| 5883 | if ((mFlags & FLAG_DELIVER_POST_IME) != 0) { |
| 5884 | return true; |
| 5885 | } |
| 5886 | return mEvent instanceof MotionEvent |
| 5887 | && mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER); |
| 5888 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5889 | |
| 5890 | public boolean shouldSendToSynthesizer() { |
| 5891 | if ((mFlags & FLAG_UNHANDLED) != 0) { |
| 5892 | return true; |
| 5893 | } |
| 5894 | |
| 5895 | return false; |
| 5896 | } |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 5897 | |
| 5898 | @Override |
| 5899 | public String toString() { |
| 5900 | StringBuilder sb = new StringBuilder("QueuedInputEvent{flags="); |
| 5901 | boolean hasPrevious = false; |
| 5902 | hasPrevious = flagToString("DELIVER_POST_IME", FLAG_DELIVER_POST_IME, hasPrevious, sb); |
| 5903 | hasPrevious = flagToString("DEFERRED", FLAG_DEFERRED, hasPrevious, sb); |
| 5904 | hasPrevious = flagToString("FINISHED", FLAG_FINISHED, hasPrevious, sb); |
| 5905 | hasPrevious = flagToString("FINISHED_HANDLED", FLAG_FINISHED_HANDLED, hasPrevious, sb); |
| 5906 | hasPrevious = flagToString("RESYNTHESIZED", FLAG_RESYNTHESIZED, hasPrevious, sb); |
| 5907 | hasPrevious = flagToString("UNHANDLED", FLAG_UNHANDLED, hasPrevious, sb); |
| 5908 | if (!hasPrevious) { |
| 5909 | sb.append("0"); |
| 5910 | } |
| 5911 | sb.append(", hasNextQueuedEvent=" + (mEvent != null ? "true" : "false")); |
| 5912 | sb.append(", hasInputEventReceiver=" + (mReceiver != null ? "true" : "false")); |
| 5913 | sb.append(", mEvent=" + mEvent + "}"); |
| 5914 | return sb.toString(); |
| 5915 | } |
| 5916 | |
| 5917 | private boolean flagToString(String name, int flag, |
| 5918 | boolean hasPrevious, StringBuilder sb) { |
| 5919 | if ((mFlags & flag) != 0) { |
| 5920 | if (hasPrevious) { |
| 5921 | sb.append("|"); |
| 5922 | } |
| 5923 | sb.append(name); |
| 5924 | return true; |
| 5925 | } |
| 5926 | return hasPrevious; |
| 5927 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5928 | } |
| 5929 | |
| 5930 | private QueuedInputEvent obtainQueuedInputEvent(InputEvent event, |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 5931 | InputEventReceiver receiver, int flags) { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5932 | QueuedInputEvent q = mQueuedInputEventPool; |
| 5933 | if (q != null) { |
| 5934 | mQueuedInputEventPoolSize -= 1; |
| 5935 | mQueuedInputEventPool = q.mNext; |
| 5936 | q.mNext = null; |
| 5937 | } else { |
| 5938 | q = new QueuedInputEvent(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5939 | } |
| 5940 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5941 | q.mEvent = event; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 5942 | q.mReceiver = receiver; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5943 | q.mFlags = flags; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5944 | return q; |
| 5945 | } |
| 5946 | |
| 5947 | private void recycleQueuedInputEvent(QueuedInputEvent q) { |
| 5948 | q.mEvent = null; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 5949 | q.mReceiver = null; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5950 | |
| 5951 | if (mQueuedInputEventPoolSize < MAX_QUEUED_INPUT_EVENT_POOL_SIZE) { |
| 5952 | mQueuedInputEventPoolSize += 1; |
| 5953 | q.mNext = mQueuedInputEventPool; |
| 5954 | mQueuedInputEventPool = q; |
| 5955 | } |
| 5956 | } |
| 5957 | |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 5958 | void enqueueInputEvent(InputEvent event) { |
| 5959 | enqueueInputEvent(event, null, 0, false); |
| 5960 | } |
| 5961 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5962 | void enqueueInputEvent(InputEvent event, |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 5963 | InputEventReceiver receiver, int flags, boolean processImmediately) { |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 5964 | adjustInputEventForCompatibility(event); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 5965 | QueuedInputEvent q = obtainQueuedInputEvent(event, receiver, flags); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5966 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5967 | // Always enqueue the input event in order, regardless of its time stamp. |
| 5968 | // We do this because the application or the IME may inject key events |
| 5969 | // in response to touch events and we want to ensure that the injected keys |
| 5970 | // are processed in the order they were received and we cannot trust that |
| 5971 | // the time stamp of injected events are monotonic. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 5972 | QueuedInputEvent last = mPendingInputEventTail; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5973 | if (last == null) { |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 5974 | mPendingInputEventHead = q; |
| 5975 | mPendingInputEventTail = q; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5976 | } else { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5977 | last.mNext = q; |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 5978 | mPendingInputEventTail = q; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5979 | } |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 5980 | mPendingInputEventCount += 1; |
| 5981 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mPendingInputEventQueueLengthCounterName, |
| 5982 | mPendingInputEventCount); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5983 | |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 5984 | if (processImmediately) { |
| 5985 | doProcessInputEvents(); |
| 5986 | } else { |
| 5987 | scheduleProcessInputEvents(); |
| 5988 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5989 | } |
| 5990 | |
| 5991 | private void scheduleProcessInputEvents() { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 5992 | if (!mProcessInputEventsScheduled) { |
| 5993 | mProcessInputEventsScheduled = true; |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 5994 | Message msg = mHandler.obtainMessage(MSG_PROCESS_INPUT_EVENTS); |
| 5995 | msg.setAsynchronous(true); |
| 5996 | mHandler.sendMessage(msg); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5997 | } |
| 5998 | } |
| 5999 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6000 | void doProcessInputEvents() { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6001 | // Deliver all pending input events in the queue. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6002 | while (mPendingInputEventHead != null) { |
| 6003 | QueuedInputEvent q = mPendingInputEventHead; |
| 6004 | mPendingInputEventHead = q.mNext; |
| 6005 | if (mPendingInputEventHead == null) { |
| 6006 | mPendingInputEventTail = null; |
| 6007 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6008 | q.mNext = null; |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6009 | |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 6010 | mPendingInputEventCount -= 1; |
| 6011 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mPendingInputEventQueueLengthCounterName, |
| 6012 | mPendingInputEventCount); |
| 6013 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 6014 | long eventTime = q.mEvent.getEventTimeNano(); |
| 6015 | long oldestEventTime = eventTime; |
| 6016 | if (q.mEvent instanceof MotionEvent) { |
| 6017 | MotionEvent me = (MotionEvent)q.mEvent; |
| 6018 | if (me.getHistorySize() > 0) { |
| 6019 | oldestEventTime = me.getHistoricalEventTimeNano(0); |
| 6020 | } |
| 6021 | } |
| 6022 | mChoreographer.mFrameInfo.updateInputEventTime(eventTime, oldestEventTime); |
| 6023 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6024 | deliverInputEvent(q); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6025 | } |
| 6026 | |
| 6027 | // We are done processing all input events that we can process right now |
| 6028 | // so we can clear the pending flag immediately. |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 6029 | if (mProcessInputEventsScheduled) { |
| 6030 | mProcessInputEventsScheduled = false; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6031 | mHandler.removeMessages(MSG_PROCESS_INPUT_EVENTS); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6032 | } |
| 6033 | } |
| 6034 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6035 | private void deliverInputEvent(QueuedInputEvent q) { |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6036 | Trace.asyncTraceBegin(Trace.TRACE_TAG_VIEW, "deliverInputEvent", |
| 6037 | q.mEvent.getSequenceNumber()); |
| 6038 | if (mInputEventConsistencyVerifier != null) { |
| 6039 | mInputEventConsistencyVerifier.onInputEvent(q.mEvent, 0); |
| 6040 | } |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6041 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6042 | InputStage stage; |
| 6043 | if (q.shouldSendToSynthesizer()) { |
| 6044 | stage = mSyntheticInputStage; |
| 6045 | } else { |
| 6046 | stage = q.shouldSkipIme() ? mFirstPostImeInputStage : mFirstInputStage; |
| 6047 | } |
| 6048 | |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6049 | if (stage != null) { |
| 6050 | stage.deliver(q); |
| 6051 | } else { |
| 6052 | finishInputEvent(q); |
Michael Wright | bf02096 | 2013-03-28 17:27:50 -0700 | [diff] [blame] | 6053 | } |
Michael Wright | bf02096 | 2013-03-28 17:27:50 -0700 | [diff] [blame] | 6054 | } |
| 6055 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6056 | private void finishInputEvent(QueuedInputEvent q) { |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6057 | Trace.asyncTraceEnd(Trace.TRACE_TAG_VIEW, "deliverInputEvent", |
| 6058 | q.mEvent.getSequenceNumber()); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6059 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6060 | if (q.mReceiver != null) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6061 | boolean handled = (q.mFlags & QueuedInputEvent.FLAG_FINISHED_HANDLED) != 0; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6062 | q.mReceiver.finishInputEvent(q.mEvent, handled); |
Jeff Brown | 92cc2d8 | 2011-12-02 01:19:47 -0800 | [diff] [blame] | 6063 | } else { |
| 6064 | q.mEvent.recycleIfNeededAfterDispatch(); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6065 | } |
| 6066 | |
| 6067 | recycleQueuedInputEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6068 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6069 | |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6070 | private void adjustInputEventForCompatibility(InputEvent e) { |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6071 | if (mTargetSdkVersion < Build.VERSION_CODES.M && e instanceof MotionEvent) { |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6072 | MotionEvent motion = (MotionEvent) e; |
| 6073 | final int mask = |
| 6074 | MotionEvent.BUTTON_STYLUS_PRIMARY | MotionEvent.BUTTON_STYLUS_SECONDARY; |
| 6075 | final int buttonState = motion.getButtonState(); |
| 6076 | final int compatButtonState = (buttonState & mask) >> 4; |
| 6077 | if (compatButtonState != 0) { |
| 6078 | motion.setButtonState(buttonState | compatButtonState); |
| 6079 | } |
| 6080 | } |
| 6081 | } |
| 6082 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6083 | static boolean isTerminalInputEvent(InputEvent event) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6084 | if (event instanceof KeyEvent) { |
| 6085 | final KeyEvent keyEvent = (KeyEvent)event; |
| 6086 | return keyEvent.getAction() == KeyEvent.ACTION_UP; |
| 6087 | } else { |
| 6088 | final MotionEvent motionEvent = (MotionEvent)event; |
| 6089 | final int action = motionEvent.getAction(); |
| 6090 | return action == MotionEvent.ACTION_UP |
| 6091 | || action == MotionEvent.ACTION_CANCEL |
| 6092 | || action == MotionEvent.ACTION_HOVER_EXIT; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6093 | } |
| 6094 | } |
| 6095 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6096 | void scheduleConsumeBatchedInput() { |
| 6097 | if (!mConsumeBatchedInputScheduled) { |
| 6098 | mConsumeBatchedInputScheduled = true; |
| 6099 | mChoreographer.postCallback(Choreographer.CALLBACK_INPUT, |
| 6100 | mConsumedBatchedInputRunnable, null); |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 6101 | } |
| 6102 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6103 | |
| 6104 | void unscheduleConsumeBatchedInput() { |
| 6105 | if (mConsumeBatchedInputScheduled) { |
| 6106 | mConsumeBatchedInputScheduled = false; |
| 6107 | mChoreographer.removeCallbacks(Choreographer.CALLBACK_INPUT, |
| 6108 | mConsumedBatchedInputRunnable, null); |
| 6109 | } |
| 6110 | } |
| 6111 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6112 | void scheduleConsumeBatchedInputImmediately() { |
| 6113 | if (!mConsumeBatchedInputImmediatelyScheduled) { |
| 6114 | unscheduleConsumeBatchedInput(); |
| 6115 | mConsumeBatchedInputImmediatelyScheduled = true; |
| 6116 | mHandler.post(mConsumeBatchedInputImmediatelyRunnable); |
| 6117 | } |
| 6118 | } |
| 6119 | |
Jeff Brown | 771526c | 2012-04-27 15:13:25 -0700 | [diff] [blame] | 6120 | void doConsumeBatchedInput(long frameTimeNanos) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6121 | if (mConsumeBatchedInputScheduled) { |
| 6122 | mConsumeBatchedInputScheduled = false; |
Jeff Brown | 330314c | 2012-04-27 02:20:22 -0700 | [diff] [blame] | 6123 | if (mInputEventReceiver != null) { |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6124 | if (mInputEventReceiver.consumeBatchedInputEvents(frameTimeNanos) |
| 6125 | && frameTimeNanos != -1) { |
Michael Wright | 62ce65d | 2013-10-25 14:50:36 -0700 | [diff] [blame] | 6126 | // If we consumed a batch here, we want to go ahead and schedule the |
| 6127 | // consumption of batched input events on the next frame. Otherwise, we would |
| 6128 | // 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] | 6129 | // things occurring in the process. If the frame time is -1, however, then |
| 6130 | // 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] | 6131 | scheduleConsumeBatchedInput(); |
| 6132 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6133 | } |
Jeff Brown | 330314c | 2012-04-27 02:20:22 -0700 | [diff] [blame] | 6134 | doProcessInputEvents(); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6135 | } |
| 6136 | } |
| 6137 | |
| 6138 | final class TraversalRunnable implements Runnable { |
| 6139 | @Override |
| 6140 | public void run() { |
| 6141 | doTraversal(); |
| 6142 | } |
| 6143 | } |
| 6144 | final TraversalRunnable mTraversalRunnable = new TraversalRunnable(); |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 6145 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6146 | final class WindowInputEventReceiver extends InputEventReceiver { |
| 6147 | public WindowInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 6148 | super(inputChannel, looper); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6149 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6150 | |
| 6151 | @Override |
| 6152 | public void onInputEvent(InputEvent event) { |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6153 | enqueueInputEvent(event, this, 0, true); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6154 | } |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 6155 | |
| 6156 | @Override |
| 6157 | public void onBatchedInputEventPending() { |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6158 | if (mUnbufferedInputDispatch) { |
| 6159 | super.onBatchedInputEventPending(); |
| 6160 | } else { |
| 6161 | scheduleConsumeBatchedInput(); |
| 6162 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6163 | } |
| 6164 | |
| 6165 | @Override |
| 6166 | public void dispose() { |
| 6167 | unscheduleConsumeBatchedInput(); |
| 6168 | super.dispose(); |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 6169 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6170 | } |
| 6171 | WindowInputEventReceiver mInputEventReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6172 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6173 | final class ConsumeBatchedInputRunnable implements Runnable { |
| 6174 | @Override |
| 6175 | public void run() { |
Jeff Brown | 771526c | 2012-04-27 15:13:25 -0700 | [diff] [blame] | 6176 | doConsumeBatchedInput(mChoreographer.getFrameTimeNanos()); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6177 | } |
| 6178 | } |
| 6179 | final ConsumeBatchedInputRunnable mConsumedBatchedInputRunnable = |
| 6180 | new ConsumeBatchedInputRunnable(); |
| 6181 | boolean mConsumeBatchedInputScheduled; |
| 6182 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6183 | final class ConsumeBatchedInputImmediatelyRunnable implements Runnable { |
| 6184 | @Override |
| 6185 | public void run() { |
| 6186 | doConsumeBatchedInput(-1); |
| 6187 | } |
| 6188 | } |
| 6189 | final ConsumeBatchedInputImmediatelyRunnable mConsumeBatchedInputImmediatelyRunnable = |
| 6190 | new ConsumeBatchedInputImmediatelyRunnable(); |
| 6191 | boolean mConsumeBatchedInputImmediatelyScheduled; |
| 6192 | |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6193 | final class InvalidateOnAnimationRunnable implements Runnable { |
| 6194 | private boolean mPosted; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6195 | private final ArrayList<View> mViews = new ArrayList<View>(); |
| 6196 | private final ArrayList<AttachInfo.InvalidateInfo> mViewRects = |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6197 | new ArrayList<AttachInfo.InvalidateInfo>(); |
| 6198 | private View[] mTempViews; |
| 6199 | private AttachInfo.InvalidateInfo[] mTempViewRects; |
| 6200 | |
| 6201 | public void addView(View view) { |
| 6202 | synchronized (this) { |
| 6203 | mViews.add(view); |
| 6204 | postIfNeededLocked(); |
| 6205 | } |
| 6206 | } |
| 6207 | |
| 6208 | public void addViewRect(AttachInfo.InvalidateInfo info) { |
| 6209 | synchronized (this) { |
| 6210 | mViewRects.add(info); |
| 6211 | postIfNeededLocked(); |
| 6212 | } |
| 6213 | } |
| 6214 | |
| 6215 | public void removeView(View view) { |
| 6216 | synchronized (this) { |
| 6217 | mViews.remove(view); |
| 6218 | |
| 6219 | for (int i = mViewRects.size(); i-- > 0; ) { |
| 6220 | AttachInfo.InvalidateInfo info = mViewRects.get(i); |
| 6221 | if (info.target == view) { |
| 6222 | mViewRects.remove(i); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 6223 | info.recycle(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6224 | } |
| 6225 | } |
| 6226 | |
| 6227 | if (mPosted && mViews.isEmpty() && mViewRects.isEmpty()) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6228 | mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, this, null); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6229 | mPosted = false; |
| 6230 | } |
| 6231 | } |
| 6232 | } |
| 6233 | |
| 6234 | @Override |
| 6235 | public void run() { |
| 6236 | final int viewCount; |
| 6237 | final int viewRectCount; |
| 6238 | synchronized (this) { |
| 6239 | mPosted = false; |
| 6240 | |
| 6241 | viewCount = mViews.size(); |
| 6242 | if (viewCount != 0) { |
| 6243 | mTempViews = mViews.toArray(mTempViews != null |
| 6244 | ? mTempViews : new View[viewCount]); |
| 6245 | mViews.clear(); |
| 6246 | } |
| 6247 | |
| 6248 | viewRectCount = mViewRects.size(); |
| 6249 | if (viewRectCount != 0) { |
| 6250 | mTempViewRects = mViewRects.toArray(mTempViewRects != null |
| 6251 | ? mTempViewRects : new AttachInfo.InvalidateInfo[viewRectCount]); |
| 6252 | mViewRects.clear(); |
| 6253 | } |
| 6254 | } |
| 6255 | |
| 6256 | for (int i = 0; i < viewCount; i++) { |
| 6257 | mTempViews[i].invalidate(); |
Adam Powell | 3e3c4ee | 2012-05-16 17:34:21 -0700 | [diff] [blame] | 6258 | mTempViews[i] = null; |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6259 | } |
| 6260 | |
| 6261 | for (int i = 0; i < viewRectCount; i++) { |
| 6262 | final View.AttachInfo.InvalidateInfo info = mTempViewRects[i]; |
| 6263 | info.target.invalidate(info.left, info.top, info.right, info.bottom); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 6264 | info.recycle(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6265 | } |
| 6266 | } |
| 6267 | |
| 6268 | private void postIfNeededLocked() { |
| 6269 | if (!mPosted) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6270 | mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, this, null); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6271 | mPosted = true; |
| 6272 | } |
| 6273 | } |
| 6274 | } |
| 6275 | final InvalidateOnAnimationRunnable mInvalidateOnAnimationRunnable = |
| 6276 | new InvalidateOnAnimationRunnable(); |
| 6277 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6278 | public void dispatchInvalidateDelayed(View view, long delayMilliseconds) { |
| 6279 | Message msg = mHandler.obtainMessage(MSG_INVALIDATE, view); |
| 6280 | mHandler.sendMessageDelayed(msg, delayMilliseconds); |
| 6281 | } |
| 6282 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6283 | public void dispatchInvalidateRectDelayed(AttachInfo.InvalidateInfo info, |
| 6284 | long delayMilliseconds) { |
| 6285 | final Message msg = mHandler.obtainMessage(MSG_INVALIDATE_RECT, info); |
| 6286 | mHandler.sendMessageDelayed(msg, delayMilliseconds); |
| 6287 | } |
| 6288 | |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6289 | public void dispatchInvalidateOnAnimation(View view) { |
| 6290 | mInvalidateOnAnimationRunnable.addView(view); |
| 6291 | } |
| 6292 | |
| 6293 | public void dispatchInvalidateRectOnAnimation(AttachInfo.InvalidateInfo info) { |
| 6294 | mInvalidateOnAnimationRunnable.addViewRect(info); |
| 6295 | } |
| 6296 | |
| 6297 | public void cancelInvalidate(View view) { |
| 6298 | mHandler.removeMessages(MSG_INVALIDATE, view); |
| 6299 | // fixme: might leak the AttachInfo.InvalidateInfo objects instead of returning |
| 6300 | // them to the pool |
| 6301 | mHandler.removeMessages(MSG_INVALIDATE_RECT, view); |
| 6302 | mInvalidateOnAnimationRunnable.removeView(view); |
| 6303 | } |
| 6304 | |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 6305 | public void dispatchInputEvent(InputEvent event) { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 6306 | dispatchInputEvent(event, null); |
| 6307 | } |
| 6308 | |
| 6309 | public void dispatchInputEvent(InputEvent event, InputEventReceiver receiver) { |
| 6310 | SomeArgs args = SomeArgs.obtain(); |
| 6311 | args.arg1 = event; |
| 6312 | args.arg2 = receiver; |
| 6313 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_INPUT_EVENT, args); |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 6314 | msg.setAsynchronous(true); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6315 | mHandler.sendMessage(msg); |
| 6316 | } |
| 6317 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6318 | public void synthesizeInputEvent(InputEvent event) { |
| 6319 | Message msg = mHandler.obtainMessage(MSG_SYNTHESIZE_INPUT_EVENT, event); |
| 6320 | msg.setAsynchronous(true); |
| 6321 | mHandler.sendMessage(msg); |
| 6322 | } |
| 6323 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6324 | public void dispatchKeyFromIme(KeyEvent event) { |
| 6325 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_KEY_FROM_IME, event); |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 6326 | msg.setAsynchronous(true); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6327 | mHandler.sendMessage(msg); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6328 | } |
| 6329 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6330 | /** |
| 6331 | * Reinject unhandled {@link InputEvent}s in order to synthesize fallbacks events. |
| 6332 | * |
| 6333 | * Note that it is the responsibility of the caller of this API to recycle the InputEvent it |
| 6334 | * passes in. |
| 6335 | */ |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6336 | public void dispatchUnhandledInputEvent(InputEvent event) { |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6337 | if (event instanceof MotionEvent) { |
| 6338 | event = MotionEvent.obtain((MotionEvent) event); |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6339 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6340 | synthesizeInputEvent(event); |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6341 | } |
| 6342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6343 | public void dispatchAppVisibility(boolean visible) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6344 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_APP_VISIBILITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6345 | msg.arg1 = visible ? 1 : 0; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6346 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6347 | } |
| 6348 | |
| 6349 | public void dispatchGetNewSurface() { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6350 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_GET_NEW_SURFACE); |
| 6351 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6352 | } |
| 6353 | |
| 6354 | public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { |
| 6355 | Message msg = Message.obtain(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6356 | msg.what = MSG_WINDOW_FOCUS_CHANGED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6357 | msg.arg1 = hasFocus ? 1 : 0; |
| 6358 | msg.arg2 = inTouchMode ? 1 : 0; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6359 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6360 | } |
| 6361 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 6362 | public void dispatchWindowShown() { |
| 6363 | mHandler.sendEmptyMessage(MSG_DISPATCH_WINDOW_SHOWN); |
| 6364 | } |
| 6365 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6366 | public void dispatchCloseSystemDialogs(String reason) { |
| 6367 | Message msg = Message.obtain(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6368 | msg.what = MSG_CLOSE_SYSTEM_DIALOGS; |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6369 | msg.obj = reason; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6370 | mHandler.sendMessage(msg); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6371 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6372 | |
| 6373 | public void dispatchDragEvent(DragEvent event) { |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6374 | final int what; |
| 6375 | if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6376 | what = MSG_DISPATCH_DRAG_LOCATION_EVENT; |
| 6377 | mHandler.removeMessages(what); |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6378 | } else { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6379 | what = MSG_DISPATCH_DRAG_EVENT; |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6380 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6381 | Message msg = mHandler.obtainMessage(what, event); |
| 6382 | mHandler.sendMessage(msg); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6383 | } |
| 6384 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6385 | public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, |
| 6386 | int localValue, int localChanges) { |
| 6387 | SystemUiVisibilityInfo args = new SystemUiVisibilityInfo(); |
| 6388 | args.seq = seq; |
| 6389 | args.globalVisibility = globalVisibility; |
| 6390 | args.localValue = localValue; |
| 6391 | args.localChanges = localChanges; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6392 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DISPATCH_SYSTEM_UI_VISIBILITY, args)); |
| 6393 | } |
| 6394 | |
| 6395 | public void dispatchCheckFocus() { |
| 6396 | if (!mHandler.hasMessages(MSG_CHECK_FOCUS)) { |
| 6397 | // This will result in a call to checkFocus() below. |
| 6398 | mHandler.sendEmptyMessage(MSG_CHECK_FOCUS); |
| 6399 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6400 | } |
| 6401 | |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 6402 | public void dispatchRequestKeyboardShortcuts(IResultReceiver receiver) { |
| 6403 | mHandler.obtainMessage(MSG_REQUEST_KEYBOARD_SHORTCUTS, receiver).sendToTarget(); |
| 6404 | } |
| 6405 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6406 | /** |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6407 | * Post a callback to send a |
| 6408 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6409 | * This event is send at most once every |
| 6410 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6411 | */ |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 6412 | private void postSendWindowContentChangedCallback(View source, int changeType) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6413 | if (mSendWindowContentChangedAccessibilityEvent == null) { |
| 6414 | mSendWindowContentChangedAccessibilityEvent = |
| 6415 | new SendWindowContentChangedAccessibilityEvent(); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6416 | } |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 6417 | mSendWindowContentChangedAccessibilityEvent.runOrPost(source, changeType); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6418 | } |
| 6419 | |
| 6420 | /** |
| 6421 | * Remove a posted callback to send a |
| 6422 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. |
| 6423 | */ |
| 6424 | private void removeSendWindowContentChangedCallback() { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6425 | if (mSendWindowContentChangedAccessibilityEvent != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6426 | mHandler.removeCallbacks(mSendWindowContentChangedAccessibilityEvent); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6427 | } |
| 6428 | } |
| 6429 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6430 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6431 | public boolean showContextMenuForChild(View originalView) { |
| 6432 | return false; |
| 6433 | } |
| 6434 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6435 | @Override |
Oren Blasberg | ed39126 | 2015-09-01 12:12:51 -0700 | [diff] [blame] | 6436 | public boolean showContextMenuForChild(View originalView, float x, float y) { |
| 6437 | return false; |
| 6438 | } |
| 6439 | |
| 6440 | @Override |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 6441 | public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) { |
| 6442 | return null; |
| 6443 | } |
| 6444 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6445 | @Override |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 6446 | public ActionMode startActionModeForChild( |
| 6447 | View originalView, ActionMode.Callback callback, int type) { |
| 6448 | return null; |
| 6449 | } |
| 6450 | |
| 6451 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6452 | public void createContextMenu(ContextMenu menu) { |
| 6453 | } |
| 6454 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6455 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6456 | public void childDrawableStateChanged(View child) { |
| 6457 | } |
| 6458 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6459 | @Override |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6460 | public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 6461 | if (mView == null || mStopped || mPausedForTransition) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6462 | return false; |
| 6463 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6464 | // Intercept accessibility focus events fired by virtual nodes to keep |
| 6465 | // track of accessibility focus position in such nodes. |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6466 | final int eventType = event.getEventType(); |
| 6467 | switch (eventType) { |
| 6468 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6469 | final long sourceNodeId = event.getSourceNodeId(); |
| 6470 | final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 6471 | sourceNodeId); |
| 6472 | View source = mView.findViewByAccessibilityId(accessibilityViewId); |
| 6473 | if (source != null) { |
| 6474 | AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider(); |
| 6475 | if (provider != null) { |
Svetoslav | b3ba1d4 | 2014-09-26 15:20:40 -0700 | [diff] [blame] | 6476 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 6477 | sourceNodeId); |
| 6478 | final AccessibilityNodeInfo node; |
| 6479 | if (virtualNodeId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
| 6480 | node = provider.createAccessibilityNodeInfo( |
| 6481 | AccessibilityNodeProvider.HOST_VIEW_ID); |
| 6482 | } else { |
| 6483 | node = provider.createAccessibilityNodeInfo(virtualNodeId); |
| 6484 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6485 | setAccessibilityFocus(source, node); |
| 6486 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6487 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6488 | } break; |
| 6489 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6490 | final long sourceNodeId = event.getSourceNodeId(); |
| 6491 | final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 6492 | sourceNodeId); |
| 6493 | View source = mView.findViewByAccessibilityId(accessibilityViewId); |
| 6494 | if (source != null) { |
| 6495 | AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider(); |
| 6496 | if (provider != null) { |
| 6497 | setAccessibilityFocus(null, null); |
| 6498 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6499 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6500 | } break; |
Svetoslav | f0c758b | 2014-09-03 17:47:37 -0700 | [diff] [blame] | 6501 | |
| 6502 | |
| 6503 | case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: { |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6504 | handleWindowContentChangedEvent(event); |
Svetoslav | f0c758b | 2014-09-03 17:47:37 -0700 | [diff] [blame] | 6505 | } break; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6506 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6507 | mAccessibilityManager.sendAccessibilityEvent(event); |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6508 | return true; |
| 6509 | } |
| 6510 | |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6511 | /** |
| 6512 | * Updates the focused virtual view, when necessary, in response to a |
| 6513 | * content changed event. |
| 6514 | * <p> |
| 6515 | * This is necessary to get updated bounds after a position change. |
| 6516 | * |
| 6517 | * @param event an accessibility event of type |
| 6518 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} |
| 6519 | */ |
| 6520 | private void handleWindowContentChangedEvent(AccessibilityEvent event) { |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6521 | final View focusedHost = mAccessibilityFocusedHost; |
| 6522 | if (focusedHost == null || mAccessibilityFocusedVirtualView == null) { |
| 6523 | // No virtual view focused, nothing to do here. |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6524 | return; |
| 6525 | } |
| 6526 | |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6527 | final AccessibilityNodeProvider provider = focusedHost.getAccessibilityNodeProvider(); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6528 | if (provider == null) { |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6529 | // Error state: virtual view with no provider. Clear focus. |
| 6530 | mAccessibilityFocusedHost = null; |
| 6531 | mAccessibilityFocusedVirtualView = null; |
| 6532 | focusedHost.clearAccessibilityFocusNoCallbacks(); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6533 | return; |
| 6534 | } |
| 6535 | |
| 6536 | // We only care about change types that may affect the bounds of the |
| 6537 | // focused virtual view. |
| 6538 | final int changes = event.getContentChangeTypes(); |
| 6539 | if ((changes & AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE) == 0 |
| 6540 | && changes != AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED) { |
| 6541 | return; |
| 6542 | } |
| 6543 | |
| 6544 | final long eventSourceNodeId = event.getSourceNodeId(); |
| 6545 | final int changedViewId = AccessibilityNodeInfo.getAccessibilityViewId(eventSourceNodeId); |
| 6546 | |
| 6547 | // Search up the tree for subtree containment. |
| 6548 | boolean hostInSubtree = false; |
| 6549 | View root = mAccessibilityFocusedHost; |
| 6550 | while (root != null && !hostInSubtree) { |
| 6551 | if (changedViewId == root.getAccessibilityViewId()) { |
| 6552 | hostInSubtree = true; |
| 6553 | } else { |
| 6554 | final ViewParent parent = root.getParent(); |
| 6555 | if (parent instanceof View) { |
| 6556 | root = (View) parent; |
| 6557 | } else { |
| 6558 | root = null; |
| 6559 | } |
| 6560 | } |
| 6561 | } |
| 6562 | |
| 6563 | // We care only about changes in subtrees containing the host view. |
| 6564 | if (!hostInSubtree) { |
| 6565 | return; |
| 6566 | } |
| 6567 | |
| 6568 | final long focusedSourceNodeId = mAccessibilityFocusedVirtualView.getSourceNodeId(); |
| 6569 | int focusedChildId = AccessibilityNodeInfo.getVirtualDescendantId(focusedSourceNodeId); |
| 6570 | if (focusedChildId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
| 6571 | // TODO: Should we clear the focused virtual view? |
| 6572 | focusedChildId = AccessibilityNodeProvider.HOST_VIEW_ID; |
| 6573 | } |
| 6574 | |
| 6575 | // Refresh the node for the focused virtual view. |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 6576 | final Rect oldBounds = mTempRect; |
| 6577 | mAccessibilityFocusedVirtualView.getBoundsInScreen(oldBounds); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6578 | mAccessibilityFocusedVirtualView = provider.createAccessibilityNodeInfo(focusedChildId); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6579 | if (mAccessibilityFocusedVirtualView == null) { |
| 6580 | // Error state: The node no longer exists. Clear focus. |
| 6581 | mAccessibilityFocusedHost = null; |
| 6582 | focusedHost.clearAccessibilityFocusNoCallbacks(); |
| 6583 | |
| 6584 | // This will probably fail, but try to keep the provider's internal |
| 6585 | // state consistent by clearing focus. |
| 6586 | provider.performAction(focusedChildId, |
| 6587 | AccessibilityAction.ACTION_CLEAR_ACCESSIBILITY_FOCUS.getId(), null); |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 6588 | invalidateRectOnScreen(oldBounds); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6589 | } else { |
| 6590 | // The node was refreshed, invalidate bounds if necessary. |
| 6591 | final Rect newBounds = mAccessibilityFocusedVirtualView.getBoundsInScreen(); |
| 6592 | if (!oldBounds.equals(newBounds)) { |
| 6593 | oldBounds.union(newBounds); |
| 6594 | invalidateRectOnScreen(oldBounds); |
| 6595 | } |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 6596 | } |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6597 | } |
| 6598 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6599 | @Override |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 6600 | public void notifySubtreeAccessibilityStateChanged(View child, View source, int changeType) { |
| 6601 | postSendWindowContentChangedCallback(source, changeType); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6602 | } |
| 6603 | |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 6604 | @Override |
| 6605 | public boolean canResolveLayoutDirection() { |
| 6606 | return true; |
| 6607 | } |
| 6608 | |
| 6609 | @Override |
| 6610 | public boolean isLayoutDirectionResolved() { |
| 6611 | return true; |
| 6612 | } |
| 6613 | |
| 6614 | @Override |
| 6615 | public int getLayoutDirection() { |
| 6616 | return View.LAYOUT_DIRECTION_RESOLVED_DEFAULT; |
| 6617 | } |
| 6618 | |
| 6619 | @Override |
| 6620 | public boolean canResolveTextDirection() { |
| 6621 | return true; |
| 6622 | } |
| 6623 | |
| 6624 | @Override |
| 6625 | public boolean isTextDirectionResolved() { |
| 6626 | return true; |
| 6627 | } |
| 6628 | |
| 6629 | @Override |
| 6630 | public int getTextDirection() { |
| 6631 | return View.TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 6632 | } |
| 6633 | |
| 6634 | @Override |
| 6635 | public boolean canResolveTextAlignment() { |
| 6636 | return true; |
| 6637 | } |
| 6638 | |
| 6639 | @Override |
| 6640 | public boolean isTextAlignmentResolved() { |
| 6641 | return true; |
| 6642 | } |
| 6643 | |
| 6644 | @Override |
| 6645 | public int getTextAlignment() { |
| 6646 | return View.TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 6647 | } |
| 6648 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6649 | private View getCommonPredecessor(View first, View second) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 6650 | if (mTempHashSet == null) { |
| 6651 | mTempHashSet = new HashSet<View>(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6652 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 6653 | HashSet<View> seen = mTempHashSet; |
| 6654 | seen.clear(); |
| 6655 | View firstCurrent = first; |
| 6656 | while (firstCurrent != null) { |
| 6657 | seen.add(firstCurrent); |
| 6658 | ViewParent firstCurrentParent = firstCurrent.mParent; |
| 6659 | if (firstCurrentParent instanceof View) { |
| 6660 | firstCurrent = (View) firstCurrentParent; |
| 6661 | } else { |
| 6662 | firstCurrent = null; |
| 6663 | } |
| 6664 | } |
| 6665 | View secondCurrent = second; |
| 6666 | while (secondCurrent != null) { |
| 6667 | if (seen.contains(secondCurrent)) { |
| 6668 | seen.clear(); |
| 6669 | return secondCurrent; |
| 6670 | } |
| 6671 | ViewParent secondCurrentParent = secondCurrent.mParent; |
| 6672 | if (secondCurrentParent instanceof View) { |
| 6673 | secondCurrent = (View) secondCurrentParent; |
| 6674 | } else { |
| 6675 | secondCurrent = null; |
| 6676 | } |
| 6677 | } |
| 6678 | seen.clear(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6679 | return null; |
| 6680 | } |
| 6681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6682 | void checkThread() { |
| 6683 | if (mThread != Thread.currentThread()) { |
| 6684 | throw new CalledFromWrongThreadException( |
| 6685 | "Only the original thread that created a view hierarchy can touch its views."); |
| 6686 | } |
| 6687 | } |
| 6688 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6689 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6690 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 6691 | // 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] | 6692 | } |
| 6693 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6694 | @Override |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6695 | public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { |
| 6696 | final boolean scrolled = scrollToRectOrFocus(rectangle, immediate); |
| 6697 | if (rectangle != null) { |
| 6698 | mTempRect.set(rectangle); |
| 6699 | mTempRect.offset(0, -mCurScrollY); |
| 6700 | mTempRect.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
| 6701 | try { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 6702 | mWindowSession.onRectangleOnScreenRequested(mWindow, mTempRect); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6703 | } catch (RemoteException re) { |
| 6704 | /* ignore */ |
| 6705 | } |
| 6706 | } |
| 6707 | return scrolled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6708 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6709 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6710 | @Override |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 6711 | public void childHasTransientStateChanged(View child, boolean hasTransientState) { |
| 6712 | // Do nothing. |
| 6713 | } |
| 6714 | |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 6715 | @Override |
| 6716 | public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) { |
| 6717 | return false; |
| 6718 | } |
| 6719 | |
| 6720 | @Override |
| 6721 | public void onStopNestedScroll(View target) { |
| 6722 | } |
| 6723 | |
| 6724 | @Override |
| 6725 | public void onNestedScrollAccepted(View child, View target, int nestedScrollAxes) { |
| 6726 | } |
| 6727 | |
| 6728 | @Override |
| 6729 | public void onNestedScroll(View target, int dxConsumed, int dyConsumed, |
| 6730 | int dxUnconsumed, int dyUnconsumed) { |
| 6731 | } |
| 6732 | |
| 6733 | @Override |
| 6734 | public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { |
| 6735 | } |
| 6736 | |
| 6737 | @Override |
Adam Powell | b36e4f9 | 2014-05-01 10:23:33 -0700 | [diff] [blame] | 6738 | public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) { |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 6739 | return false; |
| 6740 | } |
| 6741 | |
Adam Powell | b72be59 | 2014-07-16 21:41:31 -0700 | [diff] [blame] | 6742 | @Override |
| 6743 | public boolean onNestedPreFling(View target, float velocityX, float velocityY) { |
| 6744 | return false; |
| 6745 | } |
| 6746 | |
Adam Powell | b6ab098 | 2015-01-07 17:00:12 -0800 | [diff] [blame] | 6747 | @Override |
| 6748 | public boolean onNestedPrePerformAccessibilityAction(View target, int action, Bundle args) { |
| 6749 | return false; |
| 6750 | } |
| 6751 | |
Jorim Jaggi | b774e55 | 2015-08-24 14:52:45 -0700 | [diff] [blame] | 6752 | /** |
| 6753 | * Force the window to report its next draw. |
| 6754 | * <p> |
| 6755 | * This method is only supposed to be used to speed up the interaction from SystemUI and window |
| 6756 | * manager when waiting for the first frame to be drawn when turning on the screen. DO NOT USE |
| 6757 | * unless you fully understand this interaction. |
| 6758 | * @hide |
| 6759 | */ |
| 6760 | public void setReportNextDraw() { |
| 6761 | mReportNextDraw = true; |
| 6762 | invalidate(); |
| 6763 | } |
| 6764 | |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 6765 | void changeCanvasOpacity(boolean opaque) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6766 | Log.d(mTag, "changeCanvasOpacity: opaque=" + opaque); |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 6767 | if (mAttachInfo.mHardwareRenderer != null) { |
| 6768 | mAttachInfo.mHardwareRenderer.setOpaque(opaque); |
| 6769 | } |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 6770 | } |
| 6771 | |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 6772 | long getNextFrameNumber() { |
| 6773 | long frameNumber = -1; |
| 6774 | if (mSurfaceHolder != null) { |
| 6775 | mSurfaceHolder.mSurfaceLock.lock(); |
| 6776 | } |
| 6777 | if (mSurface.isValid()) { |
| 6778 | frameNumber = mSurface.getNextFrameNumber(); |
| 6779 | } |
| 6780 | if (mSurfaceHolder != null) { |
| 6781 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 6782 | } |
| 6783 | return frameNumber; |
| 6784 | } |
| 6785 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6786 | class TakenSurfaceHolder extends BaseSurfaceHolder { |
| 6787 | @Override |
| 6788 | public boolean onAllowLockCanvas() { |
| 6789 | return mDrawingAllowed; |
| 6790 | } |
| 6791 | |
| 6792 | @Override |
| 6793 | public void onRelayoutContainer() { |
| 6794 | // Not currently interesting -- from changing between fixed and layout size. |
| 6795 | } |
| 6796 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6797 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6798 | public void setFormat(int format) { |
| 6799 | ((RootViewSurfaceTaker)mView).setSurfaceFormat(format); |
| 6800 | } |
| 6801 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6802 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6803 | public void setType(int type) { |
| 6804 | ((RootViewSurfaceTaker)mView).setSurfaceType(type); |
| 6805 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6806 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6807 | @Override |
| 6808 | public void onUpdateSurface() { |
| 6809 | // We take care of format and type changes on our own. |
| 6810 | throw new IllegalStateException("Shouldn't be here"); |
| 6811 | } |
| 6812 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6813 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6814 | public boolean isCreating() { |
| 6815 | return mIsCreating; |
| 6816 | } |
| 6817 | |
| 6818 | @Override |
| 6819 | public void setFixedSize(int width, int height) { |
| 6820 | throw new UnsupportedOperationException( |
| 6821 | "Currently only support sizing from layout"); |
| 6822 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6823 | |
| 6824 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6825 | public void setKeepScreenOn(boolean screenOn) { |
| 6826 | ((RootViewSurfaceTaker)mView).setSurfaceKeepScreenOn(screenOn); |
| 6827 | } |
| 6828 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6829 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6830 | static class W extends IWindow.Stub { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6831 | private final WeakReference<ViewRootImpl> mViewAncestor; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6832 | private final IWindowSession mWindowSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6833 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6834 | W(ViewRootImpl viewAncestor) { |
| 6835 | mViewAncestor = new WeakReference<ViewRootImpl>(viewAncestor); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6836 | mWindowSession = viewAncestor.mWindowSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6837 | } |
| 6838 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6839 | @Override |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6840 | public void resized(Rect frame, Rect overscanInsets, Rect contentInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 6841 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 6842 | Configuration newConfig, Rect backDropFrame) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6843 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6844 | if (viewAncestor != null) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6845 | viewAncestor.dispatchResized(frame, overscanInsets, contentInsets, |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 6846 | visibleInsets, stableInsets, outsets, reportDraw, newConfig, backDropFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6847 | } |
| 6848 | } |
| 6849 | |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 6850 | @Override |
| 6851 | public void moved(int newX, int newY) { |
| 6852 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 6853 | if (viewAncestor != null) { |
| 6854 | viewAncestor.dispatchMoved(newX, newY); |
| 6855 | } |
| 6856 | } |
| 6857 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6858 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6859 | public void dispatchAppVisibility(boolean visible) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6860 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6861 | if (viewAncestor != null) { |
| 6862 | viewAncestor.dispatchAppVisibility(visible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6863 | } |
| 6864 | } |
| 6865 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6866 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6867 | public void dispatchGetNewSurface() { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6868 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6869 | if (viewAncestor != null) { |
| 6870 | viewAncestor.dispatchGetNewSurface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6871 | } |
| 6872 | } |
| 6873 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6874 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6875 | public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6876 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6877 | if (viewAncestor != null) { |
| 6878 | viewAncestor.windowFocusChanged(hasFocus, inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6879 | } |
| 6880 | } |
| 6881 | |
| 6882 | private static int checkCallingPermission(String permission) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6883 | try { |
| 6884 | return ActivityManagerNative.getDefault().checkPermission( |
| 6885 | permission, Binder.getCallingPid(), Binder.getCallingUid()); |
| 6886 | } catch (RemoteException e) { |
| 6887 | return PackageManager.PERMISSION_DENIED; |
| 6888 | } |
| 6889 | } |
| 6890 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6891 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6892 | public void executeCommand(String command, String parameters, ParcelFileDescriptor out) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6893 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6894 | if (viewAncestor != null) { |
| 6895 | final View view = viewAncestor.mView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6896 | if (view != null) { |
| 6897 | if (checkCallingPermission(Manifest.permission.DUMP) != |
| 6898 | PackageManager.PERMISSION_GRANTED) { |
| 6899 | throw new SecurityException("Insufficient permissions to invoke" |
| 6900 | + " executeCommand() from pid=" + Binder.getCallingPid() |
| 6901 | + ", uid=" + Binder.getCallingUid()); |
| 6902 | } |
| 6903 | |
| 6904 | OutputStream clientStream = null; |
| 6905 | try { |
| 6906 | clientStream = new ParcelFileDescriptor.AutoCloseOutputStream(out); |
| 6907 | ViewDebug.dispatchCommand(view, command, parameters, clientStream); |
| 6908 | } catch (IOException e) { |
| 6909 | e.printStackTrace(); |
| 6910 | } finally { |
| 6911 | if (clientStream != null) { |
| 6912 | try { |
| 6913 | clientStream.close(); |
| 6914 | } catch (IOException e) { |
| 6915 | e.printStackTrace(); |
| 6916 | } |
| 6917 | } |
| 6918 | } |
| 6919 | } |
| 6920 | } |
| 6921 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6922 | |
| 6923 | @Override |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6924 | public void closeSystemDialogs(String reason) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6925 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6926 | if (viewAncestor != null) { |
| 6927 | viewAncestor.dispatchCloseSystemDialogs(reason); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6928 | } |
| 6929 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6930 | |
| 6931 | @Override |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6932 | public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep, |
| 6933 | boolean sync) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6934 | if (sync) { |
| 6935 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6936 | mWindowSession.wallpaperOffsetsComplete(asBinder()); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6937 | } catch (RemoteException e) { |
| 6938 | } |
| 6939 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6940 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6941 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6942 | @Override |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6943 | public void dispatchWallpaperCommand(String action, int x, int y, |
| 6944 | int z, Bundle extras, boolean sync) { |
| 6945 | if (sync) { |
| 6946 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6947 | mWindowSession.wallpaperCommandComplete(asBinder(), null); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6948 | } catch (RemoteException e) { |
| 6949 | } |
| 6950 | } |
| 6951 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6952 | |
| 6953 | /* Drag/drop */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6954 | @Override |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6955 | public void dispatchDragEvent(DragEvent event) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6956 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6957 | if (viewAncestor != null) { |
| 6958 | viewAncestor.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6959 | } |
| 6960 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6961 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6962 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6963 | public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, |
| 6964 | int localValue, int localChanges) { |
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) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6967 | viewAncestor.dispatchSystemUiVisibilityChanged(seq, globalVisibility, |
| 6968 | localValue, localChanges); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6969 | } |
| 6970 | } |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 6971 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6972 | @Override |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 6973 | public void dispatchWindowShown() { |
| 6974 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 6975 | if (viewAncestor != null) { |
| 6976 | viewAncestor.dispatchWindowShown(); |
| 6977 | } |
| 6978 | } |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 6979 | |
| 6980 | @Override |
| 6981 | public void requestAppKeyboardShortcuts(IResultReceiver receiver) { |
| 6982 | ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 6983 | if (viewAncestor != null) { |
| 6984 | viewAncestor.dispatchRequestKeyboardShortcuts(receiver); |
| 6985 | } |
| 6986 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6987 | } |
| 6988 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6989 | public static final class CalledFromWrongThreadException extends AndroidRuntimeException { |
| 6990 | public CalledFromWrongThreadException(String msg) { |
| 6991 | super(msg); |
| 6992 | } |
| 6993 | } |
| 6994 | |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 6995 | static HandlerActionQueue getRunQueue() { |
| 6996 | HandlerActionQueue rq = sRunQueues.get(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6997 | if (rq != null) { |
| 6998 | return rq; |
| 6999 | } |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 7000 | rq = new HandlerActionQueue(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7001 | sRunQueues.set(rq); |
| 7002 | return rq; |
| 7003 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7004 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7005 | /** |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7006 | * Start a drag resizing which will inform all listeners that a window resize is taking place. |
| 7007 | */ |
| 7008 | private void startDragResizing(Rect initialBounds) { |
| 7009 | if (!mDragResizing) { |
| 7010 | mDragResizing = true; |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 7011 | synchronized (mWindowCallbacks) { |
| 7012 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7013 | mWindowCallbacks.get(i).onWindowDragResizeStart(initialBounds); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7014 | } |
| 7015 | } |
| 7016 | mFullRedrawNeeded = true; |
| 7017 | } |
| 7018 | } |
| 7019 | |
| 7020 | /** |
| 7021 | * End a drag resize which will inform all listeners that a window resize has ended. |
| 7022 | */ |
| 7023 | private void endDragResizing() { |
| 7024 | if (mDragResizing) { |
| 7025 | mDragResizing = false; |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 7026 | synchronized (mWindowCallbacks) { |
| 7027 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7028 | mWindowCallbacks.get(i).onWindowDragResizeEnd(); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7029 | } |
| 7030 | } |
| 7031 | mFullRedrawNeeded = true; |
| 7032 | } |
| 7033 | } |
| 7034 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 7035 | private boolean updateContentDrawBounds() { |
| 7036 | boolean updated = false; |
| 7037 | synchronized (mWindowCallbacks) { |
| 7038 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7039 | updated |= mWindowCallbacks.get(i).onContentDrawn( |
| 7040 | mWindowAttributes.surfaceInsets.left, |
| 7041 | mWindowAttributes.surfaceInsets.top, |
| 7042 | mWidth, mHeight); |
| 7043 | } |
| 7044 | } |
| 7045 | return updated | (mDragResizing && mReportNextDraw); |
| 7046 | } |
| 7047 | |
| 7048 | private void requestDrawWindow() { |
| 7049 | if (mReportNextDraw) { |
| 7050 | mWindowDrawCountDown = new CountDownLatch(mWindowCallbacks.size()); |
| 7051 | } |
| 7052 | synchronized (mWindowCallbacks) { |
| 7053 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7054 | mWindowCallbacks.get(i).onRequestDraw(mReportNextDraw); |
| 7055 | } |
| 7056 | } |
| 7057 | } |
| 7058 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7059 | /** |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 7060 | * Tells this instance that its corresponding activity has just relaunched. In this case, we |
| 7061 | * need to force a relayout of the window to make sure we get the correct bounds from window |
| 7062 | * manager. |
| 7063 | */ |
| 7064 | public void reportActivityRelaunched() { |
| 7065 | mActivityRelaunched = true; |
| 7066 | } |
| 7067 | |
| 7068 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7069 | * Class for managing the accessibility interaction connection |
| 7070 | * based on the global accessibility state. |
| 7071 | */ |
| 7072 | final class AccessibilityInteractionConnectionManager |
| 7073 | implements AccessibilityStateChangeListener { |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7074 | @Override |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7075 | public void onAccessibilityStateChanged(boolean enabled) { |
| 7076 | if (enabled) { |
| 7077 | ensureConnection(); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7078 | if (mAttachInfo.mHasWindowFocus) { |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 7079 | mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 7080 | View focusedView = mView.findFocus(); |
| 7081 | if (focusedView != null && focusedView != mView) { |
| 7082 | focusedView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 7083 | } |
| 7084 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7085 | } else { |
| 7086 | ensureNoConnection(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 7087 | mHandler.obtainMessage(MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST).sendToTarget(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7088 | } |
| 7089 | } |
| 7090 | |
| 7091 | public void ensureConnection() { |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7092 | final boolean registered = |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 7093 | mAttachInfo.mAccessibilityWindowId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7094 | if (!registered) { |
| 7095 | mAttachInfo.mAccessibilityWindowId = |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 7096 | mAccessibilityManager.addAccessibilityInteractionConnection(mWindow, |
| 7097 | new AccessibilityInteractionConnection(ViewRootImpl.this)); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7098 | } |
| 7099 | } |
| 7100 | |
| 7101 | public void ensureNoConnection() { |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 7102 | final boolean registered = |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 7103 | mAttachInfo.mAccessibilityWindowId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7104 | if (registered) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 7105 | mAttachInfo.mAccessibilityWindowId = AccessibilityNodeInfo.UNDEFINED_ITEM_ID; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7106 | mAccessibilityManager.removeAccessibilityInteractionConnection(mWindow); |
| 7107 | } |
| 7108 | } |
| 7109 | } |
| 7110 | |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7111 | final class HighContrastTextManager implements HighTextContrastChangeListener { |
| 7112 | HighContrastTextManager() { |
| 7113 | mAttachInfo.mHighContrastText = mAccessibilityManager.isHighTextContrastEnabled(); |
| 7114 | } |
| 7115 | @Override |
| 7116 | public void onHighTextContrastStateChanged(boolean enabled) { |
| 7117 | mAttachInfo.mHighContrastText = enabled; |
| 7118 | |
| 7119 | // Destroy Displaylists so they can be recreated with high contrast recordings |
| 7120 | destroyHardwareResources(); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 7121 | |
| 7122 | // Schedule redraw, which will rerecord + redraw all text |
| 7123 | invalidate(); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7124 | } |
| 7125 | } |
| 7126 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7127 | /** |
| 7128 | * This class is an interface this ViewAncestor provides to the |
| 7129 | * AccessibilityManagerService to the latter can interact with |
| 7130 | * the view hierarchy in this ViewAncestor. |
| 7131 | */ |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7132 | static final class AccessibilityInteractionConnection |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7133 | extends IAccessibilityInteractionConnection.Stub { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7134 | private final WeakReference<ViewRootImpl> mViewRootImpl; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7135 | |
Svetoslav Ganov | f79f476 | 2011-10-28 15:40:32 -0700 | [diff] [blame] | 7136 | AccessibilityInteractionConnection(ViewRootImpl viewRootImpl) { |
| 7137 | mViewRootImpl = new WeakReference<ViewRootImpl>(viewRootImpl); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7138 | } |
| 7139 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7140 | @Override |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7141 | public void findAccessibilityNodeInfoByAccessibilityId(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7142 | Region interactiveRegion, int interactionId, |
| 7143 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7144 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7145 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7146 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7147 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7148 | .findAccessibilityNodeInfoByAccessibilityIdClientThread(accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7149 | interactiveRegion, interactionId, callback, flags, interrogatingPid, |
| 7150 | interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7151 | } else { |
| 7152 | // We cannot make the call and notify the caller so it does not wait. |
| 7153 | try { |
| 7154 | callback.setFindAccessibilityNodeInfosResult(null, interactionId); |
| 7155 | } catch (RemoteException re) { |
| 7156 | /* best effort - ignore */ |
| 7157 | } |
Svetoslav Ganov | 601ad80 | 2011-06-09 14:47:38 -0700 | [diff] [blame] | 7158 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7159 | } |
| 7160 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7161 | @Override |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7162 | public void performAccessibilityAction(long accessibilityNodeId, int action, |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 7163 | Bundle arguments, int interactionId, |
| 7164 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 7165 | int interrogatingPid, long interrogatingTid) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7166 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7167 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7168 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 7169 | .performAccessibilityActionClientThread(accessibilityNodeId, action, arguments, |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 7170 | interactionId, callback, flags, interrogatingPid, interrogatingTid); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7171 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7172 | // 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] | 7173 | try { |
| 7174 | callback.setPerformAccessibilityActionResult(false, interactionId); |
| 7175 | } catch (RemoteException re) { |
| 7176 | /* best effort - ignore */ |
| 7177 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7178 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7179 | } |
| 7180 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7181 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7182 | public void findAccessibilityNodeInfosByViewId(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7183 | String viewId, Region interactiveRegion, int interactionId, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7184 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7185 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7186 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7187 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7188 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7189 | .findAccessibilityNodeInfosByViewIdClientThread(accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7190 | viewId, interactiveRegion, interactionId, callback, flags, |
| 7191 | interrogatingPid, interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7192 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7193 | // 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] | 7194 | try { |
| 7195 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
| 7196 | } catch (RemoteException re) { |
| 7197 | /* best effort - ignore */ |
| 7198 | } |
| 7199 | } |
| 7200 | } |
| 7201 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7202 | @Override |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7203 | public void findAccessibilityNodeInfosByText(long accessibilityNodeId, String text, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7204 | Region interactiveRegion, int interactionId, |
| 7205 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7206 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7207 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7208 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7209 | viewRootImpl.getAccessibilityInteractionController() |
| 7210 | .findAccessibilityNodeInfosByTextClientThread(accessibilityNodeId, text, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7211 | interactiveRegion, interactionId, callback, flags, interrogatingPid, |
| 7212 | interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7213 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7214 | // 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] | 7215 | try { |
| 7216 | callback.setFindAccessibilityNodeInfosResult(null, interactionId); |
| 7217 | } catch (RemoteException re) { |
| 7218 | /* best effort - ignore */ |
| 7219 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7220 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7221 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7222 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7223 | @Override |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7224 | public void findFocus(long accessibilityNodeId, int focusType, Region interactiveRegion, |
| 7225 | int interactionId, IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7226 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7227 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7228 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7229 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7230 | .findFocusClientThread(accessibilityNodeId, focusType, interactiveRegion, |
| 7231 | interactionId, callback, flags, interrogatingPid, interrogatingTid, |
| 7232 | spec); |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 7233 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7234 | // 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] | 7235 | try { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7236 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7237 | } catch (RemoteException re) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7238 | /* best effort - ignore */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7239 | } |
| 7240 | } |
| 7241 | } |
| 7242 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7243 | @Override |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7244 | public void focusSearch(long accessibilityNodeId, int direction, Region interactiveRegion, |
| 7245 | int interactionId, IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7246 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7247 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7248 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7249 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7250 | .focusSearchClientThread(accessibilityNodeId, direction, interactiveRegion, |
| 7251 | interactionId, callback, flags, interrogatingPid, interrogatingTid, |
| 7252 | spec); |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 7253 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7254 | // 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] | 7255 | try { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7256 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7257 | } catch (RemoteException re) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7258 | /* best effort - ignore */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7259 | } |
| 7260 | } |
| 7261 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7262 | } |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7263 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7264 | private class SendWindowContentChangedAccessibilityEvent implements Runnable { |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7265 | private int mChangeTypes = 0; |
| 7266 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7267 | public View mSource; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7268 | public long mLastEventTimeMillis; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7269 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7270 | @Override |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7271 | public void run() { |
Svetoslav | 8d820ecf | 2013-07-15 17:12:41 -0700 | [diff] [blame] | 7272 | // The accessibility may be turned off while we were waiting so check again. |
| 7273 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 7274 | mLastEventTimeMillis = SystemClock.uptimeMillis(); |
| 7275 | AccessibilityEvent event = AccessibilityEvent.obtain(); |
| 7276 | event.setEventType(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7277 | event.setContentChangeTypes(mChangeTypes); |
Svetoslav | 8d820ecf | 2013-07-15 17:12:41 -0700 | [diff] [blame] | 7278 | mSource.sendAccessibilityEventUnchecked(event); |
| 7279 | } else { |
| 7280 | mLastEventTimeMillis = 0; |
| 7281 | } |
| 7282 | // In any case reset to initial state. |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7283 | mSource.resetSubtreeAccessibilityStateChanged(); |
| 7284 | mSource = null; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7285 | mChangeTypes = 0; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7286 | } |
| 7287 | |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7288 | public void runOrPost(View source, int changeType) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7289 | if (mSource != null) { |
Svetoslav | 9dafebb | 2013-06-18 16:29:25 -0700 | [diff] [blame] | 7290 | // If there is no common predecessor, then mSource points to |
| 7291 | // a removed view, hence in this case always prefer the source. |
| 7292 | View predecessor = getCommonPredecessor(mSource, source); |
| 7293 | mSource = (predecessor != null) ? predecessor : source; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7294 | mChangeTypes |= changeType; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7295 | return; |
| 7296 | } |
| 7297 | mSource = source; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7298 | mChangeTypes = changeType; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7299 | final long timeSinceLastMillis = SystemClock.uptimeMillis() - mLastEventTimeMillis; |
| 7300 | final long minEventIntevalMillis = |
| 7301 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval(); |
| 7302 | if (timeSinceLastMillis >= minEventIntevalMillis) { |
Svetoslav | 9dafebb | 2013-06-18 16:29:25 -0700 | [diff] [blame] | 7303 | mSource.removeCallbacks(this); |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7304 | run(); |
| 7305 | } else { |
| 7306 | mSource.postDelayed(this, minEventIntevalMillis - timeSinceLastMillis); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7307 | } |
| 7308 | } |
| 7309 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7310 | } |