Applied user's preferred coding conventions:
- Braces on new line (opening { goes below function/statement)
- Local variables in snake_case for better distinction:
* display_metrics (instead of displayMetrics)
* window_manager (instead of windowManager)
* captured_image (instead of image)
Benefits:
- Improved readability at a glance
- Clear distinction between member variables, parameters, and locals
- Consistent style throughout the new architecture components
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Created ScreenCaptureManager interface and ScreenCaptureManagerImpl to separate
screen capture concerns from ScreenCaptureService, improving architecture:
## New Files:
- ScreenCaptureManager.kt: Interface defining screen capture operations
- ScreenCaptureManagerImpl.kt: Implementation handling MediaProjection lifecycle
## Changes to ScreenCaptureService.kt:
- Remove direct MediaProjection/ImageReader/VirtualDisplay handling
- Use ScreenCaptureManager via dependency injection pattern
- Delegate screen capture operations to manager
- Get screen dimensions from manager instead of storing locally
- Proper manager lifecycle with release() in onDestroy()
## Benefits:
- Single Responsibility Principle: Service focuses on orchestration
- Testability: Screen capture logic can be unit tested in isolation
- Maintainability: Clear separation of concerns
- Reusability: Manager can be used by other components
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add proper ocrExecutor lifecycle management in ScreenCaptureService.onDestroy()
- Use awaitTermination() with 5-second timeout before forcing shutdownNow()
- Handle InterruptedException with proper thread interrupt restoration
- Verified temporary executors in YOLOOnnxDetector already have proper cleanup
- Prevents thread pool resource leaks and ensures clean service shutdown
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Remove BENCHMARKING_MODE flag and detectionTimes list
- Remove printBenchmarkStats() and resetBenchmarkStats() functions
- Remove detailed benchmark logging from detection method
- Keep only essential timing log for normal operation
- Clean production code after performance testing complete
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
BENCHMARK RESULTS:
- Multi-processing: 2491.6ms average (baseline)
- Single-processing: 1800.5ms average (27.7% faster\!)
- Performance improvement: 691ms per detection
- Total time reduced from 49832ms to 36010ms
- Set ENABLE_MULTI_PREPROCESSING = false
- Eliminates thread pool overhead and context switching
- Exceeds expected 20-30% performance improvement target
- Mobile CPUs perform better with single-threaded preprocessing
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add BENCHMARKING_MODE flag and detection timing collection
- Add printBenchmarkStats() and resetBenchmarkStats() functions
- Enhanced logging to track MULTI vs SINGLE preprocessing performance
- Automatic stats reporting every 10 detections
- Ready to benchmark current multi-processing performance
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add proper bitmap cleanup in ScreenCaptureService.processImage()
- Fix bitmap leaks in convertImageToMat() with try-finally blocks
- Ensure bitmap.recycle() called in all exception paths
- Add safe cleanup in EnhancedOCR.performBasicOCR()
- Wrap OCR bitmap operations with proper resource management
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Create MatUtils.kt with safe resource management patterns
- Fix major Mat leak in ScreenCaptureService.kt image processing pipeline
- Fix Mat leaks in EnhancedOCR.kt enhanceImageForOCR() and upscaleImage()
- Add Mat.use() extension for automatic cleanup with try-finally
- Add useMats() utility for multi-Mat operations
- Add releaseSafely() for batch Mat cleanup with error handling
Critical stability fix: prevents native memory leaks that cause app crashes
during extended detection use. Mat objects now guaranteed to be released
even in exception paths.
Related: REFACTORING_TASKS.md CRITICAL-001
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Delete FloatingActionButtonUI.kt (580 lines) - unused Material 3 FAB
- Delete FloatingOrbUI.kt (270 lines) - unused basic orb implementation
- Delete FloatingComposeOverlay.kt (352 lines) - unused Compose overlay
- Delete FloatingUIActivity.kt (444 lines) - unused activity with dead code
- Remove FloatingUIActivity from AndroidManifest.xml
- Clean up unused imports and functions in MainActivity.kt
- Update comments in ScreenCaptureService.kt
Total cleanup: 1,646 lines of unused code removed
Active UI: EnhancedFloatingFAB.kt remains as the working implementation
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Calculate actual menu height using measure() for precise bounds checking
- Add 32dp safety margin to account for navigation bar and system UI
- Automatically adjust menu Y position when it would extend off bottom
- Prevent menu from going off top of screen with maxOf(0, adjustedY)
- Add comprehensive debug logging for position calculations
This ensures the floating menu is always fully visible regardless of
FAB position, with the menu intelligently shifting upward when the
FAB is positioned near the bottom of the screen.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add automatic menu side detection based on FAB center position
- Menu appears on right when FAB is on left side of screen (and vice versa)
- Flip menu item layout order based on FAB position:
- Left side: [MiniFAB][Label] (mini FAB closest to main FAB)
- Right side: [Label][MiniFAB] (mini FAB closest to main FAB)
- Adjust container gravity and item margins for proper alignment
- Add debug logging for layout decisions
This creates a symmetrical UX where mini FABs are always closest
to the main FAB and labels extend outward, preventing off-screen
menu items regardless of FAB position.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Replace single window with separate WindowManager windows for FAB and menu
- Fix main FAB movement issue by using independent window positioning
- Calculate actual menu width instead of estimating for precise positioning
- Menu now appears to the left of FAB with proper 8dp spacing
- Remove obsolete updateRootLayout() function and auto-hide behavior
- Add debug logging for position calculations
The separate windows approach eliminates layout interference between
the main FAB and expandable menu, ensuring the FAB stays fixed while
the menu expands leftward as requested.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Replace broken FloatingComposeOverlay with EnhancedFloatingFAB
- True floating behavior using WindowManager overlay system
- Edge docking: automatic snap to screen edges within 50dp threshold
- Touch-through support: only FAB intercepts touches, rest passes to underlying apps
- Expandable menu with 5 detection options (DETECT, SHINY, POKEBALL, ALL, DEBUG)
- Material Design styling with circular backgrounds and proper elevation
- Haptic feedback with permission checking and graceful fallbacks
- Auto-hide menu after 3 seconds of inactivity
- Smooth animations: 300ms edge snapping, staggered menu expansion
- Added VIBRATE permission to AndroidManifest.xml
- Added Material Design Components dependency
Technical implementation:
- WindowManager overlay with WRAP_CONTENT sizing for precise touch handling
- ImageButton with custom GradientDrawable backgrounds for Material styling
- ValueAnimator for smooth edge snapping with AccelerateDecelerateInterpolator
- ObjectAnimator for menu item animations with staggered delays
- Safe vibration with runtime permission checks and exception handling
Addresses critical requirements from UI_MODERNIZATION_TASKS.md:
✅ Truly floating like CalcIV - not activity-based
✅ Edge docking with smooth animation
✅ Touch-through for underlying Pokemon GO interaction
✅ Professional Material 3 design
✅ No system UI interference
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
NEW REQUIREMENTS:
- Soft dock to screen edges (snap when dragged within 50px of edge)
- Touch-through for underlying apps (user must interact with Pokemon GO)
- Only FAB intercepts touches, everything else passes to underlying app
TECHNICAL IMPLICATIONS:
- Activity approach now problematic (captures touches in window bounds)
- WindowManager + Views approach now RECOMMENDED (precise touch control)
- Window must be sized exactly to FAB, not fullscreen
- FLAG_NOT_TOUCH_MODAL critical for touch pass-through
Updated recommendation: Option B (Enhanced WindowManager + Material Views)
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Document all approaches tried: Activity-based, ComposeView overlay, lifecycle solutions
- Detail specific issues encountered: positioning, transparency, lifecycle crashes
- Analyze three next-step options with pros/cons
- Record user requirements and current git state for easy resume
- Provide technical deep dive of what worked vs what failed
Ready for next conversation to pick up from Option A, B, or C.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Remove complex OverlayLifecycleOwner implementation
- Remove ViewTreeLifecycleOwner references (not available in this API level)
- Use basic ComposeView without explicit lifecycle management
- Let ComposeView handle its own lifecycle in overlay context
Some Android versions support ComposeView in overlay without explicit lifecycle.
If this still fails, we'll fall back to View-based FAB implementation.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com)
- Create OverlayLifecycleOwner implementing LifecycleOwner and SavedStateRegistryOwner
- Set ViewTreeLifecycleOwner and ViewTreeSavedStateRegistryOwner on ComposeView
- Manage lifecycle states (onCreate, onStart, onResume, onDestroy) for overlay
- Fixes: ViewTreeLifecycleOwner not found exception when using ComposeView in overlay
Error: java.lang.IllegalStateException: ViewTreeLifecycleOwner not found
Solution: Provide custom lifecycle owner for overlay context
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Rename MenuFABItem to OverlayMenuFABItem in FloatingComposeOverlay
- Fixes overload resolution ambiguity between two files
- Both FloatingUIActivity and FloatingComposeOverlay had same function name
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Create FloatingComposeOverlay using WindowManager for true system overlay
- Replace Activity-based approach with proper overlay window
- Add unrestricted drag support with WindowManager position updates
- Use transparent background to show underlying apps
- Integrate overlay directly into ScreenCaptureService
- Remove FloatingUIActivity dependency from MainActivity
Benefits:
- True floating behavior over all apps
- Unrestricted dragging anywhere on screen
- Transparent background shows underlying content
- Proper system overlay like CalcIV
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Move setupTransparentOverlay() from onCreate to onResume to avoid null window
- Add try-catch block to handle WindowInsetsController access errors
- Add null-safety checks for window operations
- Prevent crash when accessing insetsController before window is ready
Fixes: NullPointerException when accessing WindowInsetsController
Error: 'getWindowInsetsController()' on a null object reference
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Make FAB truly draggable with detectDragGestures
- Add screen bounds checking to keep FAB visible
- Hide navigation bar and status bar for immersive overlay experience
- Support both Android R+ (WindowInsetsController) and legacy system UI flags
- FAB now floats anywhere on screen and can be repositioned by dragging
Fixes: Navigation bar and status bar no longer show during capture mode
Fixes: FAB is now truly floating and user can position it anywhere
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Create FloatingUIActivity with true Material 3 FloatingActionButton
- Implement Binder communication between UI Activity and Service
- Remove UI handling from ScreenCaptureService (now pure background service)
- Add proper Material 3 animations and haptic feedback
- Update MainActivity to launch FloatingUIActivity on capture start
- Register FloatingUIActivity in AndroidManifest with transparent theme
Architecture: FloatingUIActivity (Compose UI) ↔ Binder ↔ ScreenCaptureService (Detection)
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Fix NUM_DETECTIONS constant from 8400 to 300 for NMS-enabled ONNX model
- Completely remove DEBUG_DETECTION flag and all shiny debug logging blocks
- Clean up code for production readiness
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Fixed critical color conversion issue where RGBA2RGB was causing red/blue
channel swap, preventing YOLO model from recognizing shiny icons. Changed
to RGBA2BGR conversion for proper OpenCV compatibility.
Key improvements:
- Fixed screen capture padding/cropping (1088→1080px width)
- Added comprehensive debug logging for capture pipeline
- Created comparative debugging scripts for .pt vs ONNX models
- Resolved color corruption preventing shiny icon detection
- Shiny icons now detected with 0.87+ confidence
Testing confirmed detection working for shiny icons and other UI elements.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add SHINY_ICON_DEBUG_REPORT.md with full investigation summary
- Root cause identified: NMS=True model filters out shiny icons from top 300 detections
- Added comprehensive debugging infrastructure in YOLOOnnxDetector.kt
- Confirmed model detects other classes but class 50 (shiny_icon) absent from NMS output
- Proposed solutions: hybrid model approach, NMS parameter tuning, or post-processing
Ready for next session with clear action plan and debugging tools in place.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Log raw output statistics including max values and non-zero counts
- Specifically check shiny icon class region (class 50) in raw model output
- Will reveal if model produces shiny predictions before post-processing
- Helps identify if issue is in model weights vs post-processing
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add DEBUG_SHINY_DETECTION flag to track shiny_icon (class 50) processing
- Lower confidence threshold from 0.45f to 0.25f temporarily for debugging
- Add detailed logging for shiny icon candidates with confidence and coordinates
- Will help identify if shiny icons are being detected but filtered out
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Remove class-specific check and apply 5% expansion to all OCR detections
- Improves text extraction accuracy across all Pokemon info fields
- Stat values showed significant improvement, extending to all text classes
- No overlap issues expected due to Pokemon Home UI spacing
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add extractPokemonInfoFromYOLOAsync call to triggerManualDetection()
- OCR extraction was missing after MVC refactor - only YOLO detection was running
- Now manual detection triggers both YOLO detection and OCR extraction
- Maintains full Pokemon analysis functionality in new MVC architecture
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add 5% expansion to bounding boxes for hp_value, attack_value, defense_value, sp_atk_value, sp_def_value, speed_value
- Expansion applied before clipping to image boundaries
- Added debug logging to show bbox expansion transformations
- Should improve OCR accuracy for tight stat value detections
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Update DetectionController.processDetection() to return Detection objects
- Add Detection import to controller
- Update ScreenCaptureService to show overlay using returned detections
- Improve FloatingOrbUI button text visibility with larger font and padding
The MVC refactor is now complete with fully working detection overlay.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Replace old UI code with FloatingOrbUI component
- Add DetectionController with callback system
- Implement convertImageToMat helper function
- Connect UI events to business logic through controller
- Remove direct YOLO detector calls from UI
Related todos: #24
- Add DetectionUIEvents and DetectionUICallbacks interfaces
- Create DetectionController for business logic separation
- Add FloatingOrbUI pure UI component with no business logic
- Establish clean event-driven communication pattern
Related todos: #24