-
Notifications
You must be signed in to change notification settings - Fork 0
034 widget stack code quality
Comprehensive code quality refactoring of the Widget Stack feature, addressing naming conventions, code duplication, data integrity bugs, type safety, and semantic confusion across 14 files.
LauncherSettings.java
- Added
ITEM_TYPE_WIDGET_STACKcase toitemTypeToString()(was returning raw"12") - Added
isInsideCollection(int container)utility to replace fragilecontainer > 0heuristic
ModelUtils.java
- Split
WIDGET_FILTERinto two predicates:-
APP_WIDGET_FILTER-- matches actual widgets only (not stacks) -
WIDGET_OR_STACK_FILTER-- matches widgets AND stacks
-
- The old
WIDGET_FILTERincluded stacks but every call site immediately added.filter(item -> item instanceof LauncherAppWidgetInfo)to exclude them
CacheDataUpdatedTask.java, PackageInstallStateChangedTask.java, PackageUpdatedTask.java, LoaderTask.java
- Switched to
APP_WIDGET_FILTERand removed redundantinstanceof LauncherAppWidgetInfofilter
BaseLauncherBinder.java
- Switched to
WIDGET_OR_STACK_FILTERfor item categorization (stacks should be categorized with widgets)
Workspace.java (removeItemsByMatcher)
- Added
WidgetStackViewhandling inremoveItemsByMatcher()for package uninstall - Calls
stackInfo.removeMatching(matcher)on matched children - Removes entire stack if empty, otherwise calls
rebuildFromStackInfo()
WidgetStackInfo.java (removeMatching)
- Added
removeMatching(Predicate<ItemInfo>)method for package uninstall handling
WidgetStackView.java (rebuildFromStackInfo)
- Added
rebuildFromStackInfo()to sync child views with model after mutations
WorkspaceItemProcessor.kt
- Replaced
c.container > 0withFavorites.isInsideCollection(c.container)
WidgetStackView.java (full refactor)
- Renamed 18 private fields to AOSP
m-prefix convention (e.g.widgetViews->mWidgetViews,activeIndex->mActiveIndex) - Extracted
accumulateFromProviderInfo()withProviderInfoAccumulatorinterface -- five span/mode methods reduced to one-liners - Extracted
animateSnap()withSnapUpdateCallbackinterface --snapToIndex()andsnapBack()share ~30 lines of ValueAnimator setup - Added
mLongPressHelper.cancelLongPress()inonDetachedFromWindow()(was missing)
ItemInflater.kt
- Replaced unsafe
child as LauncherAppWidgetInfowith safe cast +Log.e+continue
WidgetStackInfo.java (type safety)
-
getActiveWidget()now usesinstanceofpattern match instead of direct cast -
setActiveIndex()guards against empty contents to avoidMath.min(i, -1)
WidgetStackInfo.java (mutation/persistence separation)
- Replaced static
assignWidgetToStack(stack, widget, rank, writer, isNew)with instanceassignWidget(widget, rank)that only mutates fields - DB persistence moved to callers in
Launcher.javaandWorkspace.java
WidgetStackView.java (accessibility)
- Added
onInitializeAccessibilityNodeInfo()with scroll forward/backward actions - Added
performAccessibilityAction()to navigate viasnapToIndex() - Added content description: "Widget %d of %d"
WidgetStackView.java (grid bounds)
-
expandSpanIfNeeded()now clamps toInvariantDeviceProfile.numColumns/numRows
WidgetStackView.java (child persistence)
- Added
updateChildWidgetSizes(context, spanX, spanY, writer)overload that persists child span changes to DB
AppWidgetResizeFrame.java
- Added content description on resize frame: "Widget stack with %d widgets"
LoaderCursor.java
- Extracted generic
findOrMakeCollection(id, dataModel, type, factory)-- bothfindOrMakeFolderandfindOrMakeWidgetStackare now one-liners
WidgetStackInfo.java / WidgetStackView.java / Workspace.java
- Added
MAX_STACK_SIZE = 6constant enforced inadd()andwillAddToExistingWidgetStack()
WidgetStackView.java
- Renamed
nextIndextopeekIndexinapplySwipeTranslation()for consistency withsnapBack()
| Resource | Value |
|---|---|
widget_stack_page_description |
"Widget %1$d of %2$d" |
- Added
docs/widget-stack.md-- comprehensive architecture documentation covering data model, loading pipeline, view layer, drag-and-drop, resize, and package uninstall handling
Architecture
Guides
Changes
- 031 App Icon & Clipping Fix
- 030 Folder Refactoring
- 029 Folder Features
- 028 Settings Polish
- 027 M3 Expressive
- 026 Code Quality
- 025 Wallpaper Scroll
- 024 Dead Code Cleanup
- 023 Search Perf
- 022 Settings Colors
- 021 Render Overrides
- 020 Per-App Icons
- 019 Toolbar & Preview
- 018 Colors Reorg
- 017 Search Animation
- 016 Universal Search
- 015 App Visibility
- 014 Settings Polish
- 013 Drawer Colors Fix
- 012 Drawer Colors
- 011 Notification Shade
- 010 Drawer Labels
- 009 M3 Drawer
- 008 M3 Settings
- 007 Icon Size
- 006 Icon Packs
- 005 Drawer Cleanup
- 004 Defaults & Gaps
- 003 Grid Reflow
- 002 Hotseat Row
- 001 Square Grid