| | | | |
| Offset 1, 80 lines modified | Offset 1, 485 lines modified |
| | |
| 1 | package·com.android.car.ui; | 1 | package·com.android.car.ui; |
| | |
| | 2 | import·android.content.res.TypedArray; |
| | 3 | import·android.view.accessibility.AccessibilityNodeInfo; |
| | 4 | import·com.android.car.ui.utils.CarUiUtils; |
| 2 | import·android.graphics.Canvas; | 5 | import·android.graphics.Canvas; |
| 3 | import·android.view.View; | 6 | import·android.view.ViewGroup; |
| 4 | import·android.view.ViewTreeObserver$OnGlobalFocusChangeListener; | 7 | import·android.view.ViewTreeObserver$OnGlobalFocusChangeListener; |
| | 8 | import·android.util.Log; |
| | 9 | import·java.util.Iterator; |
| | 10 | import·java.util.HashMap; |
| | 11 | import·android.content.res.Resources; |
| | 12 | import·android.os.Bundle; |
| | 13 | import·android.view.ViewParent; |
| | 14 | import·android.os.SystemClock; |
| | 15 | import·com.android.car.ui.utils.ViewUtils; |
| 5 | import·android.util.AttributeSet; | 16 | import·android.util.AttributeSet; |
| 6 | import·android.content.Context; | 17 | import·android.content.Context; |
| | 18 | import·java.util.Arrays; |
| | 19 | import·java.util.Map; |
| | 20 | import·android.view.View; |
| 7 | import·android.graphics.drawable.Drawable; | 21 | import·android.graphics.drawable.Drawable; |
| | 22 | import·java.util.List; |
| 8 | import·android.widget.LinearLayout; | 23 | import·android.widget.LinearLayout; |
| | |
| 9 | public·class·FocusArea·extends·LinearLayout | 24 | public·class·FocusArea·extends·LinearLayout |
| 10 | { | 25 | { |
| | 26 | ····private·static·final·int·INVALID_DIMEN·=·255; |
| | 27 | ····private·static·final·int·INVALID_DIRECTION·=·255; |
| | 28 | ····private·static·final·List·NUDGE_DIRECTIONS; |
| | 29 | ····private·static·final·String·TAG·=·"FocusArea"; |
| 11 | ····private·Drawable·mBackgroundHighlight; | 30 | ····private·Drawable·mBackgroundHighlight; |
| | 31 | ····private·int·mBottomOffset; |
| | 32 | ····private·boolean·mClearFocusAreaHistoryWhenRotating; |
| | 33 | ····private·int·mDefaultFocusId; |
| | 34 | ····private·boolean·mDefaultFocusOverridesHistory; |
| | 35 | ····private·View·mDefaultFocusView; |
| 12 | ····private·boolean·mEnableBackgroundHighlight; | 36 | ····private·boolean·mEnableBackgroundHighlight; |
| 13 | ····private·boolean·mEnableForegroundHighlight; | 37 | ····private·boolean·mEnableForegroundHighlight; |
| | 38 | ····private·View·mFocusedView; |
| 14 | ····private·Drawable·mForegroundHighlight; | 39 | ····private·Drawable·mForegroundHighlight; |
| 15 | ····private·boolean·mHasFocus; | 40 | ····private·boolean·mHasFocus; |
| | 41 | ····private·int·mLeftOffset; |
| | 42 | ····private·int·mNudgeShortcutDirection; |
| | 43 | ····private·int·mNudgeShortcutId; |
| | 44 | ····private·View·mNudgeShortcutView; |
| 16 | ····private·int·mPaddingBottom; | 45 | ····private·int·mPaddingBottom; |
| 17 | ····private·int·mPaddingLeft; | 46 | ····private·int·mPaddingLeft; |
| 18 | ····private·int·mPaddingRight; | 47 | ····private·int·mPaddingRight; |
| 19 | ····private·int·mPaddingTop; | 48 | ····private·int·mPaddingTop; |
| | 49 | ····private·FocusArea·mPreviousFocusArea; |
| | 50 | ····private·int·mRightOffset; |
| | 51 | ····private·RotaryCache·mRotaryCache; |
| | 52 | ····private·boolean·mRtl; |
| | 53 | ····private·Map·mSpecifiedNudgeFocusAreaMap; |
| | 54 | ····private·Map·mSpecifiedNudgeIdMap; |
| | 55 | ····private·int·mTopOffset; |
| | 56 | ···· |
| | 57 | ····static·{ |
| | 58 | ········NUDGE_DIRECTIONS·=·Arrays.asList(17,·66,·33,·130); |
| | 59 | ····} |
| 20 | ···· | 60 | ···· |
| 21 | ····public·FocusArea(final·Context·context)·{ | 61 | ····public·FocusArea(final·Context·context)·{ |
| 22 | ········super(context); | 62 | ········super(context); |
| 23 | ········this.init(); | 63 | ········this.init(context,·null); |
| 24 | ····} | 64 | ····} |
| 25 | ···· | 65 | ···· |
| 26 | ····public·FocusArea(final·Context·context,·final·AttributeSet·set)·{ | 66 | ····public·FocusArea(final·Context·context,·final·AttributeSet·set)·{ |
| 27 | ········super(context,·set); | 67 | ········super(context,·set); |
| 28 | ········this.init(); | 68 | ········this.init(context,·set); |
| 29 | ····} | 69 | ····} |
| 30 | ···· | 70 | ···· |
| 31 | ····public·FocusArea(final·Context·context,·final·AttributeSet·set,·final·int·n)·{ | 71 | ····public·FocusArea(final·Context·context,·final·AttributeSet·set,·final·int·n)·{ |
| 32 | ········super(context,·set,·n); | 72 | ········super(context,·set,·n); |
| 33 | ········this.init(); | 73 | ········this.init(context,·set); |
| 34 | ····} | 74 | ····} |
| 35 | ···· | 75 | ···· |
| 36 | ····public·FocusArea(final·Context·context,·final·AttributeSet·set,·final·int·n,·final·int·n2)·{ | 76 | ····public·FocusArea(final·Context·context,·final·AttributeSet·set,·final·int·n,·final·int·n2)·{ |
| 37 | ········super(context,·set,·n,·n2); | 77 | ········super(context,·set,·n,·n2); |
| 38 | ········this.init(); | 78 | ········this.init(context,·set); |
| | 79 | ····} |
| | 80 | ···· |
| | 81 | ····private·boolean·focusDefaultFocusView()·{ |
| | 82 | ········return·this.requestFocus(this.mDefaultFocusView); |
| | 83 | ····} |
| | 84 | ···· |
| | 85 | ····private·boolean·focusOnDescendant()·{ |
| | 86 | ········final·boolean·focusOnFocusedByDefaultView·=·this.focusOnFocusedByDefaultView(); |
| | 87 | ········final·boolean·b·=·true; |
| | 88 | ········if·(focusOnFocusedByDefaultView)·{ |
| | 89 | ············return·b; |
| | 90 | ········} |
| | 91 | ········if·(this.focusOnPrimaryFocusView())·{ |
| | 92 | ············return·b; |
| | 93 | ········} |
| | 94 | ········if·(this.mDefaultFocusOverridesHistory)·{ |
| | 95 | ············if·(this.focusDefaultFocusView()·||·this.focusOnLastFocusedView())·{ |
| | 96 | ················return·b; |
| | 97 | ············} |
| | 98 | ········} |
| | 99 | ········else·if·(this.focusOnLastFocusedView()·||·this.focusDefaultFocusView())·{ |
| | 100 | ············return·b; |
| | 101 | ········} |
| | 102 | ········return·this.focusOnFirstFocusableView(); |
| | 103 | ····} |
| | 104 | ···· |
| | 105 | ····private·boolean·focusOnFirstFocusableView()·{ |
| | 106 | ········return·this.requestFocus(ViewUtils.findFocusableDescendant((View)this)); |
| | 107 | ····} |
| | 108 | ···· |
| | 109 | ····private·boolean·focusOnFocusedByDefaultView()·{ |
| | 110 | ········return·this.requestFocus(ViewUtils.findFocusedByDefaultView((View)this)); |
| | 111 | ····} |
| | 112 | ···· |
| | 113 | ····private·boolean·focusOnLastFocusedView()·{ |
| | 114 | ········return·this.requestFocus(this.mRotaryCache.getFocusedView(SystemClock.uptimeMillis())); |
| | 115 | ····} |
| | 116 | ···· |
| | 117 | ····private·boolean·focusOnPrimaryFocusView()·{ |
| | 118 | ········return·this.requestFocus(ViewUtils.findPrimaryFocusView((View)this)); |
| | 119 | ····} |
| | 120 | ···· |
| | 121 | ····private·static·FocusArea·getAncestorFocusArea(final·View·view)·{ |
| | 122 | ········for·(ViewParent·viewParent·=·view.getParent();·viewParent·!=·null;·viewParent·=·viewParent.getParent())·{ |
| | 123 | ············if·(viewParent·instanceof·FocusArea)·{ |
| | 124 | ················return·(FocusArea)viewParent; |
| | 125 | ············} |
| | 126 | ········} |
| | 127 | ········return·null; |
| | 128 | ····} |
| | 129 | ···· |
| | 130 | ····private·static·int·getNudgeDirection(final·Bundle·bundle)·{ |
| | 131 | ········int·int1·=·-1; |
| | 132 | ········if·(bundle·!=·null)·{ |
| | 133 | ············int1·=·bundle.getInt("com.android.car.ui.utils.NUDGE_DIRECTION",·int1); |
| | 134 | ········} |
| | 135 | ········return·int1; |
| | 136 | ····} |
| | 137 | ···· |
| | 138 | ····private·static·int·getOppositeDirection(final·int·n)·{ |
| | 139 | ········final·int·n2·=·66; |
| | 140 | ········final·int·n3·=·17; |
| | 141 | ········if·(n·==·n3)·{ |
| | 142 | ············return·n2; |
| | 143 | ········} |
| | 144 | ········final·int·n4·=·130; |
| | 145 | ········final·int·n5·=·33; |
| | 146 | ········if·(n·==·n5)·{ |
| | 147 | ············return·n4; |
| | 148 | ········} |
| | 149 | ········if·(n·==·n2)·{ |
| | 150 | ············return·n3; |
| | 151 | ········} |
| | 152 | ········if·(n·==·n4)·{ |
| | 153 | ············return·n5; |
| | 154 | ········} |
| | 155 | ········throw·new·IllegalArgumentException("direction·must·be·FOCUS_UP,·FOCUS_DOWN,·FOCUS_LEFT,·or·FOCUS_RIGHT."); |
| | 156 | ····} |
| | 157 | ···· |
| | 158 | ····private·FocusArea·getSpecifiedFocusArea(final·int·n)·{ |
| | 159 | ········this.maybeInitializeSpecifiedFocusAreas(); |
| | 160 | ········return·this.mSpecifiedNudgeFocusAreaMap.get(n); |
| 39 | ····} | 161 | ····} |
| 40 | ···· | 162 | ···· |
| 41 | ····private·void·init()·{ | 163 | ····private·void·init(final·Context·context,·final·AttributeSet·set)·{ |
| 42 | ········this.mEnableForegroundHighlight·=·this.getContext().getResources().getBoolean(R$bool.car_ui_enable_focus_area_foreground_highlight); | 164 | ········final·Resources·resources·=·this.getContext().getResources(); |
| 43 | ········this.mEnableBackgroundHighlight·=·this.getContext().getResources().getBoolean(R$bool.car_ui_enable_focus_area_background_highlight); | 165 | ········this.mEnableForegroundHighlight·=·resources.getBoolean(R$bool.car_ui_enable_focus_area_foreground_highlight); |
| 44 | ········this.mForegroundHighlight·=·this.getContext().getResources().getDrawable(R$drawable.car_ui_focus_area_foreground_highlight,·this.getContext().getTheme()); | 166 | ········this.mEnableBackgroundHighlight·=·resources.getBoolean(R$bool.car_ui_enable_focus_area_background_highlight); |
| 45 | ········this.mBackgroundHighlight·=·this.getContext().getResources().getDrawable(R$drawable.car_ui_focus_area_background_highlight,·this.getContext().getTheme()); | 167 | ········this.mForegroundHighlight·=·resources.getDrawable(R$drawable.car_ui_focus_area_foreground_highlight,·this.getContext().getTheme()); |
| | 168 | ········this.mBackgroundHighlight·=·resources.getDrawable(R$drawable.car_ui_focus_area_background_highlight,·this.getContext().getTheme()); |
| | 169 | ········this.mDefaultFocusOverridesHistory·=·resources.getBoolean(R$bool.car_ui_focus_area_default_focus_overrides_history); |
| | 170 | ········this.mClearFocusAreaHistoryWhenRotating·=·resources.getBoolean(R$bool.car_ui_clear_focus_area_history_when_rotating); |
| | 171 | ········this.mRotaryCache·=·new·RotaryCache(resources.getInteger(R$integer.car_ui_focus_history_cache_type),·resources.getInteger(R$integer.car_ui_focus_history_expiration_period_ms),·resources.getInteger(R$integer.car_ui_focus_area_history_cache_type),·resources.getInteger(R$integer.car_ui_focus_area_history_expiration_period_ms)); |
| 46 | ········this.setImportantForAccessibility(1); | 172 | ········this.setImportantForAccessibility(1); |
| 47 | ········this.setWillNotDraw(false); | 173 | ········this.setWillNotDraw(false); |
| 48 | ········this.getViewTreeObserver().addOnGlobalFocusChangeListener((ViewTreeObserver$OnGlobalFocusChangeListener)new·-$$Lambda$FocusArea$Mt3bujuVuhIqHFNk5yQVNfMwfXs(this)); | 174 | ········this.registerFocusChangeListener(); |
| | 175 | ········this.initAttrs(context,·set); |
| | 176 | ····} |
| | 177 | ···· |
| | 178 | ····private·void·initAttrs(Context·obtainStyledAttributes,·final·AttributeSet·set)·{ |
| | 179 | ········if·(set·==·null)·{ |
| | 180 | ············return; |
| | 181 | ········} |
| | 182 | ········obtainStyledAttributes·=·(Context)obtainStyledAttributes.obtainStyledAttributes(set,·R$styleable.FocusArea); |
| | 183 | ········try·{ |
| | 184 | ············final·int·focusArea_defaultFocus·=·R$styleable.FocusArea_defaultFocus; |
| | 185 | ············final·int·n·=·-1; |
| | 186 | ············this.mDefaultFocusId·=·((TypedArray)obtainStyledAttributes).getResourceId(focusArea_defaultFocus,·n); |
| | 187 | ············int·n2·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_highlightPaddingStart,·n); |
| | 188 | ············boolean·b·=·false; |
| | 189 | ············if·(n2·==·n)·{ |
| | 190 | ················n2·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_highlightPaddingHorizontal,·0); |
| | 191 | ············} |
| | 192 | ············int·n3·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_highlightPaddingEnd,·n); |
| | 193 | ············if·(n3·==·n)·{ |
| | 194 | ················n3·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_highlightPaddingHorizontal,·0); |
| | 195 | ············} |
| | 196 | ············final·int·layoutDirection·=·this.getLayoutDirection(); |
| | 197 | ············final·boolean·b2·=·true; |
| | 198 | ············final·boolean·mRtl·=·layoutDirection·==·(b2·?·1·:·0)·&&·b2; |
| | 199 | ············this.mRtl·=·mRtl; |
| | 200 | ············int·mPaddingLeft; |
| | 201 | ············if·(mRtl)·{ |
| | 202 | ················mPaddingLeft·=·n3; |
| | 203 | ············} |
| | 204 | ············else·{ |
| | 205 | ················mPaddingLeft·=·n2; |
| | 206 | ············} |
| | 207 | ············this.mPaddingLeft·=·mPaddingLeft; |
| | 208 | ············int·mPaddingRight; |
| | 209 | ············if·(this.mRtl)·{ |
| | 210 | ················mPaddingRight·=·n2; |
| | 211 | ············} |
| | 212 | ············else·{ |
| | 213 | ················mPaddingRight·=·n3; |
| | 214 | ············} |
| | 215 | ············this.mPaddingRight·=·mPaddingRight; |
| | 216 | ············final·int·dimensionPixelSize·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_highlightPaddingTop,·n); |
| | 217 | ············this.mPaddingTop·=·dimensionPixelSize; |
| | 218 | ············if·(dimensionPixelSize·==·n)·{ |
| | 219 | ················this.mPaddingTop·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_highlightPaddingVertical,·0); |
| | 220 | ············} |
| | 221 | ············if·((this.mPaddingBottom·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_highlightPaddingBottom,·n))·==·n)·{ |
| | 222 | ················this.mPaddingBottom·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_highlightPaddingVertical,·0); |
| | 223 | ············} |
| | 224 | ············int·mRightOffset·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_startBoundOffset,·n); |
| | 225 | ············if·(mRightOffset·==·n)·{ |
| | 226 | ················mRightOffset·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_horizontalBoundOffset,·n2); |
| | 227 | ············} |
| | 228 | ············int·n4·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_endBoundOffset,·n); |
| | 229 | ············if·(n4·==·n)·{ |
| | 230 | ················n4·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_horizontalBoundOffset,·n3); |
| | 231 | ············} |
| | 232 | ············int·mLeftOffset; |
| | 233 | ············if·(this.mRtl)·{ |
| | 234 | ················mLeftOffset·=·n4; |
| | 235 | ············} |
| | 236 | ············else·{ |
| | 237 | ················mLeftOffset·=·mRightOffset; |
| | 238 | ············} |
| | 239 | ············this.mLeftOffset·=·mLeftOffset; |
| | 240 | ············if·(!this.mRtl)·{ |
| | 241 | ················mRightOffset·=·n4; |
| | 242 | ············} |
| | 243 | ············this.mRightOffset·=·mRightOffset; |
| | 244 | ············final·int·dimensionPixelSize2·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_topBoundOffset,·n); |
| | 245 | ············this.mTopOffset·=·dimensionPixelSize2; |
| | 246 | ············if·(dimensionPixelSize2·==·n)·{ |
| | 247 | ················this.mTopOffset·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_verticalBoundOffset,·this.mPaddingTop); |
| | 248 | ············} |
| | 249 | ············if·((this.mBottomOffset·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_bottomBoundOffset,·n))·==·n)·{ |
| | 250 | ················this.mBottomOffset·=·((TypedArray)obtainStyledAttributes).getDimensionPixelSize(R$styleable.FocusArea_verticalBoundOffset,·this.mPaddingBottom); |
| | 251 | ············} |
| | 252 | ············this.mNudgeShortcutId·=·((TypedArray)obtainStyledAttributes).getResourceId(R$styleable.FocusArea_nudgeShortcut,·n); |
| | 253 | ············this.mNudgeShortcutDirection·=·((TypedArray)obtainStyledAttributes).getInt(R$styleable.FocusArea_nudgeShortcutDirection,·n); |
| | 254 | ············final·boolean·b3·=·this.mNudgeShortcutId·==·n·&&·b2; |
| | 255 | ············if·(this.mNudgeShortcutDirection·==·n)·{ |
| | 256 | ················b·=·b2; |
| | 257 | ············} |
| | 258 | ············if·(!(b3·^·b))·{ |
| | 259 | ················(this.mSpecifiedNudgeIdMap·=·new·HashMap()).put(17,·((TypedArray)obtainStyledAttributes).getResourceId(R$styleable.FocusArea_nudgeLeft,·n)); |
| | 260 | ················this.mSpecifiedNudgeIdMap.put(66,·((TypedArray)obtainStyledAttributes).getResourceId(R$styleable.FocusArea_nudgeRight,·n)); |
| | 261 | ················this.mSpecifiedNudgeIdMap.put(33,·((TypedArray)obtainStyledAttributes).getResourceId(R$styleable.FocusArea_nudgeUp,·n)); |
| | 262 | ················this.mSpecifiedNudgeIdMap.put(130,·((TypedArray)obtainStyledAttributes).getResourceId(R$styleable.FocusArea_nudgeDown,·n)); |
| | 263 | ················return; |
| | 264 | ············} |
| | 265 | ············throw·new·IllegalStateException("nudgeShortcut·and·nudgeShortcutDirection·must·be·specified·together"); |
| | 266 | ········} |
| | 267 | ········finally·{ |
| | 268 | ············((TypedArray)obtainStyledAttributes).recycle(); |
| | 269 | ········} |
| | 270 | ····} |
| | 271 | ···· |
| | 272 | ····private·void·maybeClearFocusAreaHistory(final·boolean·b,·final·View·view)·{ |
| | 273 | ········if·(!this.mClearFocusAreaHistoryWhenRotating)·{ |
| | 274 | ············return; |
| | 275 | ········} |
| | 276 | ········if·(b)·{ |
| | 277 | ············if·(view·!=·null)·{ |
| | 278 | ················if·(getAncestorFocusArea(view)·!=·this)·{ |
| | 279 | ····················return; |
| | 280 | ················} |
| | 281 | ················this.mRotaryCache.clearFocusAreaHistory(); |
| | 282 | ············} |
| | 283 | ········} |
| | 284 | ····} |
| | 285 | ···· |
| | 286 | ····private·void·maybeInitializeSpecifiedFocusAreas()·{ |
| | 287 | ········if·(this.mSpecifiedNudgeFocusAreaMap·!=·null)·{ |
| | 288 | ············return; |
| | 289 | ········} |
| | 290 | ········final·View·rootView·=·this.getRootView(); |
| | 291 | ········this.mSpecifiedNudgeFocusAreaMap·=·new·HashMap(); |
| | 292 | ········for·(final·Integer·n·:·FocusArea.NUDGE_DIRECTIONS)·{ |
| | 293 | ············this.mSpecifiedNudgeFocusAreaMap.put(n,·rootView.findViewById((int)(Integer)this.mSpecifiedNudgeIdMap.get(n))); |
| | 294 | ········} |
| | 295 | ····} |
| | 296 | ···· |
| | 297 | ····private·void·maybeUpdateFocusAreaHighlight(final·boolean·b)·{ |
| | 298 | ········if·(!this.mEnableBackgroundHighlight·&&·!this.mEnableForegroundHighlight)·{ |
| | 299 | ············return; |
| | 300 | ········} |
| | 301 | ········if·(this.mHasFocus·!=·b)·{ |
| | 302 | ············this.invalidate(); |
| | 303 | ········} |
| | 304 | ····} |
| | 305 | ···· |
| | 306 | ····private·void·maybeUpdatePreviousFocusArea(final·boolean·b,·final·View·view)·{ |
| | 307 | ········if·(!this.mHasFocus·&&·b)·{ |
| | 308 | ············if·(view·!=·null)·{ |
| | 309 | ················if·((this.mPreviousFocusArea·=·getAncestorFocusArea(view))·==·null)·{ |
| | 310 | ····················final·StringBuilder·sb·=·new·StringBuilder(); |
| | 311 | ····················sb.append("No·parent·FocusArea·for·"); |
| | 312 | ····················sb.append(view); |
| | 313 | ····················Log.w("FocusArea",·sb.toString()); |
| | 314 | ················} |
| | 315 | ············} |
| | 316 | ········} |
| | 317 | ····} |
| | 318 | ···· |
| | 319 | ····private·boolean·nudgeToAnotherFocusArea(final·Bundle·bundle)·{ |
| | 320 | ········final·int·nudgeDirection·=·getNudgeDirection(bundle); |
| | 321 | ········final·long·uptimeMillis·=·SystemClock.uptimeMillis(); |
| | 322 | ········final·FocusArea·specifiedFocusArea·=·this.getSpecifiedFocusArea(nudgeDirection); |
| | 323 | ········boolean·b·=·true; |
| | 324 | ········final·boolean·b2·=·specifiedFocusArea·!=·null·&&·specifiedFocusArea.focusOnDescendant()·&&·b; |
| | 325 | ········FocusArea·focusArea; |
| | 326 | ········boolean·b3; |
| | 327 | ········if·(!b2)·{ |
| | 328 | ············final·FocusArea·cachedFocusArea·=·this.mRotaryCache.getCachedFocusArea(nudgeDirection,·uptimeMillis); |
| | 329 | ············if·(cachedFocusArea·==·null·||·!cachedFocusArea.focusOnDescendant())·{ |
| | 330 | ················b·=·false; |
| | 331 | ············} |
| | 332 | ············focusArea·=·cachedFocusArea; |
| | 333 | ············b3·=·b; |
| | 334 | ········} |
| | 335 | ········else·{ |
| | 336 | ············focusArea·=·specifiedFocusArea; |
| | 337 | ············b3·=·b2; |
| | 338 | ········} |
| | 339 | ········if·(b3)·{ |
| | 340 | ············this.saveFocusAreaHistory(nudgeDirection,·this,·focusArea,·uptimeMillis); |
| | 341 | ········} |
| | 342 | ········return·b3; |
| | 343 | ····} |
| | 344 | ···· |
| | 345 | ····private·boolean·nudgeToShortcutView(final·Bundle·bundle)·{ |
| | 346 | ········final·int·mNudgeShortcutDirection·=·this.mNudgeShortcutDirection; |
| | 347 | ········final·int·n·=·-1; |
| | 348 | ········return·mNudgeShortcutDirection·!=·n·&&·(bundle·!=·null·&&·bundle.getInt("com.android.car.ui.utils.NUDGE_DIRECTION",·n)·==·this.mNudgeShortcutDirection)·&&·!this.mNudgeShortcutView.isFocused()·&&·this.requestFocus(this.mNudgeShortcutView); |
| | 349 | ····} |
| | 350 | ···· |
| | 351 | ····private·void·registerFocusChangeListener()·{ |
| | 352 | ········this.getViewTreeObserver().addOnGlobalFocusChangeListener((ViewTreeObserver$OnGlobalFocusChangeListener)new·-$$Lambda$FocusArea$7x79I33igF0gDSKGrgNpHjao0QM(this)); |
| | 353 | ····} |
| | 354 | ···· |
| | 355 | ····private·boolean·requestFocus(final·View·view)·{ |
| | 356 | ········return·view·!=·null·&&·view.isAttachedToWindow()·&&·view.performAccessibilityAction(1,·(Bundle)null); |
| | 357 | ····} |
| | 358 | ···· |
| | 359 | ····private·void·saveFocusAreaHistory(int·oppositeDirection,·final·FocusArea·focusArea,·final·FocusArea·focusArea2,·final·long·n)·{ |
| | 360 | ········focusArea.mRotaryCache.saveFocusArea(oppositeDirection,·focusArea2,·n); |
| | 361 | ········oppositeDirection·=·getOppositeDirection(oppositeDirection); |
| | 362 | ········focusArea2.mRotaryCache.saveFocusArea(oppositeDirection,·focusArea,·n); |
| | 363 | ····} |
| | 364 | ···· |
| | 365 | ····private·void·saveFocusHistory(final·boolean·b)·{ |
| | 366 | ········if·(!b)·{ |
| | 367 | ············this.mRotaryCache.saveFocusedView(this.mFocusedView,·SystemClock.uptimeMillis()); |
| | 368 | ············this.mFocusedView·=·null; |
| | 369 | ············return; |
| | 370 | ········} |
| | 371 | ········Object·mFocusedView·=·this.getFocusedChild(); |
| | 372 | ········while·(mFocusedView·!=·null·&&·!((View)mFocusedView).isFocused())·{ |
| | 373 | ············if·(mFocusedView·instanceof·ViewGroup)·{ |
| | 374 | ················mFocusedView·=·((ViewGroup)mFocusedView).getFocusedChild(); |
| | 375 | ············} |
| | 376 | ············else·{ |
| | 377 | ················mFocusedView·=·null; |
| | 378 | ············} |
| | 379 | ········} |
| | 380 | ········this.mFocusedView·=·(View)mFocusedView; |
| 49 | ····} | 381 | ····} |
| 50 | ···· | 382 | ···· |
| 51 | ····public·void·draw(final·Canvas·canvas)·{ | 383 | ····public·void·draw(final·Canvas·canvas)·{ |
| 52 | ········super.draw(canvas); | 384 | ········super.draw(canvas); |
| 53 | ········if·(this.mEnableForegroundHighlight·&&·this.mHasFocus)·{ | 385 | ········if·(this.mEnableForegroundHighlight·&&·this.mHasFocus·&&·!this.isInTouchMode())·{ |
| 54 | ············this.mForegroundHighlight.setBounds(this.mPaddingLeft·+·this.getScrollX(),·this.mPaddingTop·+·this.getScrollY(),·this.getScrollX()·+·this.getWidth()·-·this.mPaddingRight,·this.getScrollY()·+·this.getHeight()·-·this.mPaddingBottom); | 386 | ············this.mForegroundHighlight.setBounds(this.mPaddingLeft·+·this.getScrollX(),·this.mPaddingTop·+·this.getScrollY(),·this.getScrollX()·+·this.getWidth()·-·this.mPaddingRight,·this.getScrollY()·+·this.getHeight()·-·this.mPaddingBottom); |
| 55 | ············this.mForegroundHighlight.draw(canvas); | 387 | ············this.mForegroundHighlight.draw(canvas); |
| 56 | ········} | 388 | ········} |
| 57 | ····} | 389 | ····} |
| 58 | ···· | 390 | ···· |
| | 391 | ····void·enableForegroundHighlight()·{ |
| | 392 | ········this.mEnableForegroundHighlight·=·true; |
| | 393 | ····} |
| | 394 | ···· |
| 59 | ····public·CharSequence·getAccessibilityClassName()·{ | 395 | ····public·CharSequence·getAccessibilityClassName()·{ |
| 60 | ········return·FocusArea.class.getName(); | 396 | ········return·FocusArea.class.getName(); |
| 61 | ····} | 397 | ····} |
| 62 | ···· | 398 | ···· |
| 63 | ····public·void·onDraw(final·Canvas·canvas)·{ | 399 | ····public·void·onDraw(final·Canvas·canvas)·{ |
| 64 | ········super.onDraw(canvas); | 400 | ········super.onDraw(canvas); |
| 65 | ········if·(this.mEnableBackgroundHighlight·&&·this.mHasFocus)·{ | 401 | ········if·(this.mEnableBackgroundHighlight·&&·this.mHasFocus·&&·!this.isInTouchMode())·{ |
| 66 | ············this.mBackgroundHighlight.setBounds(this.mPaddingLeft·+·this.getScrollX(),·this.mPaddingTop·+·this.getScrollY(),·this.getScrollX()·+·this.getWidth()·-·this.mPaddingRight,·this.getScrollY()·+·this.getHeight()·-·this.mPaddingBottom); | 402 | ············this.mBackgroundHighlight.setBounds(this.mPaddingLeft·+·this.getScrollX(),·this.mPaddingTop·+·this.getScrollY(),·this.getScrollX()·+·this.getWidth()·-·this.mPaddingRight,·this.getScrollY()·+·this.getHeight()·-·this.mPaddingBottom); |
| 67 | ············this.mBackgroundHighlight.draw(canvas); | 403 | ············this.mBackgroundHighlight.draw(canvas); |
| 68 | ········} | 404 | ········} |
| 69 | ····} | 405 | ····} |
| 70 | ···· | 406 | ···· |
| | 407 | ····protected·void·onFinishInflate()·{ |
| | 408 | ········super.onFinishInflate(); |
| | 409 | ········final·int·mDefaultFocusId·=·this.mDefaultFocusId; |
| | 410 | ········final·int·n·=·-1; |
| | 411 | ········if·(mDefaultFocusId·!=·n)·{ |
| | 412 | ············this.mDefaultFocusView·=·CarUiUtils.requireViewByRefId((View)this,·mDefaultFocusId); |
| | 413 | ········} |
| | 414 | ········final·int·mNudgeShortcutId·=·this.mNudgeShortcutId; |
| | 415 | ········if·(mNudgeShortcutId·!=·n)·{ |
| | 416 | ············this.mNudgeShortcutView·=·CarUiUtils.requireViewByRefId((View)this,·mNudgeShortcutId); |
| | 417 | ········} |
| | 418 | ····} |
| | 419 | ···· |
| | 420 | ····public·void·onInitializeAccessibilityNodeInfo(final·AccessibilityNodeInfo·accessibilityNodeInfo)·{ |
| | 421 | ········super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo); |
| | 422 | ········final·Bundle·extras·=·accessibilityNodeInfo.getExtras(); |
| | 423 | ········extras.putInt("com.android.car.ui.utils.FOCUS_AREA_LEFT_BOUND_OFFSET",·this.mLeftOffset); |
| | 424 | ········extras.putInt("com.android.car.ui.utils.FOCUS_AREA_RIGHT_BOUND_OFFSET",·this.mRightOffset); |
| | 425 | ········extras.putInt("com.android.car.ui.utils.FOCUS_AREA_TOP_BOUND_OFFSET",·this.mTopOffset); |
| | 426 | ········extras.putInt("com.android.car.ui.utils.FOCUS_AREA_BOTTOM_BOUND_OFFSET",·this.mBottomOffset); |
| | 427 | ····} |
| | 428 | ···· |
| | 429 | ····protected·void·onLayout(final·boolean·b,·int·mLeftOffset,·final·int·n,·final·int·n2,·final·int·n3)·{ |
| | 430 | ········super.onLayout(b,·mLeftOffset,·n,·n2,·n3); |
| | 431 | ········final·int·layoutDirection·=·this.getLayoutDirection(); |
| | 432 | ········mLeftOffset·=·1; |
| | 433 | ········if·(layoutDirection·!=·mLeftOffset)·{ |
| | 434 | ············mLeftOffset·=·0; |
| | 435 | ········} |
| | 436 | ········if·((this.mRtl·?·1·:·0)·!=·mLeftOffset)·{ |
| | 437 | ············this.mRtl·=·(mLeftOffset·!=·0); |
| | 438 | ············final·int·mPaddingLeft·=·this.mPaddingLeft; |
| | 439 | ············mLeftOffset·=·this.mPaddingRight; |
| | 440 | ············this.mPaddingLeft·=·mLeftOffset; |
| | 441 | ············this.mPaddingRight·=·mPaddingLeft; |
| | 442 | ············final·int·mLeftOffset2·=·this.mLeftOffset; |
| | 443 | ············mLeftOffset·=·this.mRightOffset; |
| | 444 | ············this.mLeftOffset·=·mLeftOffset; |
| | 445 | ············this.mRightOffset·=·mLeftOffset2; |
| | 446 | ········} |
| | 447 | ····} |
| | 448 | ···· |
| | 449 | ····public·boolean·performAccessibilityAction(int·focusOnDescendant,·final·Bundle·bundle)·{ |
| | 450 | ········if·(focusOnDescendant·==·1)·{ |
| | 451 | ············focusOnDescendant·=·(this.focusOnDescendant()·?·1·:·0); |
| | 452 | ············if·(focusOnDescendant·!=·0·&&·this.mPreviousFocusArea·!=·null)·{ |
| | 453 | ················final·int·nudgeDirection·=·getNudgeDirection(bundle); |
| | 454 | ················if·(nudgeDirection·!=·-1)·{ |
| | 455 | ····················this.saveFocusAreaHistory(nudgeDirection,·this.mPreviousFocusArea,·this,·SystemClock.uptimeMillis()); |
| | 456 | ················} |
| | 457 | ············} |
| | 458 | ············return·focusOnDescendant·!=·0; |
| | 459 | ········} |
| | 460 | ········if·(focusOnDescendant·==·16777216)·{ |
| | 461 | ············return·this.nudgeToShortcutView(bundle); |
| | 462 | ········} |
| | 463 | ········if·(focusOnDescendant·!=·33554432)·{ |
| | 464 | ············return·super.performAccessibilityAction(focusOnDescendant,·bundle); |
| | 465 | ········} |
| | 466 | ········return·this.nudgeToAnotherFocusArea(bundle); |
| | 467 | ····} |
| | 468 | ···· |
| | 469 | ····public·void·setBoundsOffset(final·int·mLeftOffset,·final·int·mTopOffset,·final·int·mRightOffset,·final·int·mBottomOffset)·{ |
| | 470 | ········this.mLeftOffset·=·mLeftOffset; |
| | 471 | ········this.mTopOffset·=·mTopOffset; |
| | 472 | ········this.mRightOffset·=·mRightOffset; |
| | 473 | ········this.mBottomOffset·=·mBottomOffset; |
| | 474 | ····} |
| | 475 | ···· |
| 71 | ····public·void·setHighlightPadding(final·int·mPaddingLeft,·final·int·mPaddingTop,·final·int·mPaddingRight,·final·int·mPaddingBottom)·{ | 476 | ····public·void·setHighlightPadding(final·int·mPaddingLeft,·final·int·mPaddingTop,·final·int·mPaddingRight,·final·int·mPaddingBottom)·{ |
| 72 | ········if·(this.mPaddingLeft·==·mPaddingLeft·&&·this.mPaddingTop·==·mPaddingTop·&&·this.mPaddingRight·==·mPaddingRight·&&·this.mPaddingBottom·==·mPaddingBottom)·{ | 477 | ········if·(this.mPaddingLeft·==·mPaddingLeft·&&·this.mPaddingTop·==·mPaddingTop·&&·this.mPaddingRight·==·mPaddingRight·&&·this.mPaddingBottom·==·mPaddingBottom)·{ |
| 73 | ············return; | 478 | ············return; |
| 74 | ········} | 479 | ········} |
| 75 | ········this.mPaddingLeft·=·mPaddingLeft; | 480 | ········this.mPaddingLeft·=·mPaddingLeft; |
| 76 | ········this.mPaddingTop·=·mPaddingTop; | 481 | ········this.mPaddingTop·=·mPaddingTop; |
| 77 | ········this.mPaddingRight·=·mPaddingRight; | 482 | ········this.mPaddingRight·=·mPaddingRight; |