Menu

Building StareBrain, Part 17: Drag-to-Reposition and Persisting Overlay Position
πŸ“°

Building StareBrain, Part 17: Drag-to-Reposition and Persisting Overlay Position

DEV Community: mobileΒ·StareBrainΒ·9 days ago
#b4ZqAdlI
#devtomobile#devto#dev#event#overlay
Reading 0:00
15s threshold

Building StareBrain, Part 17: Drag-to-Reposition and Persisting Overlay Position

Part 16 introduced the overlay window β€” the floating UI layer that shows task progress and surfaces confirmation prompts. One problem we hit immediately in testing: the overlay covers UI the user needs to interact with.

The fix is drag-to-reposition. The user holds and drags the overlay anywhere on screen. When they reopen StareBrain, it's where they left it.

Here's how we built it.

Touch Handling

The overlay uses a View.OnTouchListener to track drag gestures. We calculate delta from the initial touch position and update WindowManager.LayoutParams on every ACTION_MOVE .

class OverlayView ( context : Context ) : FrameLayout ( context ) {

private var initialX = 0 private var initialY = 0 private var initialTouchX = 0f private var initialTouchY = 0f

var onPositionChanged : (( Int , Int ) -> Unit )? = null

init { setOnTouchListener { _ , event -> val params = layoutParams as WindowManager . LayoutParams when ( event .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.