Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.
feat: implement long-press requirement with expanding ring animation for call termination and overlay dismissal
Rishabh Bajpai0152505f22f5
diff --git a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.ktindex 85039da..df19ed5 100644--- a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt+++ b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt@@ -60,6 +60,7 @@ class AssistiveBallOverlay(context: Context) {var isCallActive: () -> Boolean = { false }private var ballView: View? = null+ private var ringView: View? = nullprivate var menuView: View? = nullprivate var cardView: View? = nullprivate var dismissTargetView: View? = null@@ -85,6 +86,7 @@ class AssistiveBallOverlay(context: Context) {fun dismiss() {mainHandler.post {+ removeLongPressRing()removeMenu()removeCard()removeDismissTarget()@@ -109,6 +111,7 @@ class AssistiveBallOverlay(context: Context) {*/fun hideChromeForCapture() {mainHandler.post {+ removeLongPressRing()removeMenu()removeCard()ballView?.visibility = View.GONE@@ -155,6 +158,58 @@ class AssistiveBallOverlay(context: Context) {}}+ // ---- Long-press ring ----++ /** Show an expanding ring around the ball during the 3s hold to start a call. */+ private fun showLongPressRing() {+ removeLongPressRing()+ val ringSize = dp(BALL_SIZE_DP * 2)+ val ring = View(appContext).apply {+ background = GradientDrawable().apply {+ shape = GradientDrawable.OVAL+ setStroke(dp(2), Color.parseColor("#66FFFFFF"))+ setColor(Color.TRANSPARENT)+ }+ }+ val params = WindowManager.LayoutParams(+ ringSize,+ ringSize,+ overlayType(),+ WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or+ WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,+ PixelFormat.TRANSLUCENT+ ).apply {+ gravity = Gravity.TOP or Gravity.START+ x = ballParams.x + dp(BALL_SIZE_DP / 2) - ringSize / 2+ y = ballParams.y + dp(BALL_SIZE_DP / 2) - ringSize / 2+ }+ try {+ windowManager.addView(ring, params)+ ringView = ring+ ring.scaleX = 0.2f+ ring.scaleY = 0.2f+ ring.alpha = 1f+ ring.animate()+ .scaleX(1.8f)+ .scaleY(1.8f)+ .alpha(0f)+ .setDuration(LONG_PRESS_START_MS)+ .start()+ } catch (_: Exception) {+ ringView = null+ }+ }++ private fun hideLongPressRing() {+ ringView?.let { safeRemove(it) }+ ringView = null+ }++ private fun removeLongPressRing() {+ ringView?.let { safeRemove(it) }+ ringView = null+ }+@Suppress("CyclomaticComplexMethod")private fun ballTouchListener(): View.OnTouchListener {var startX = 0@@ -181,6 +236,7 @@ class AssistiveBallOverlay(context: Context) {longPressRunnable,if (isCallActive()) LONG_PRESS_END_MS else LONG_PRESS_START_MS)+ if (!isCallActive()) showLongPressRing()true}MotionEvent.ACTION_MOVE -> {@@ -189,6 +245,7 @@ class AssistiveBallOverlay(context: Context) {if (!dragging && !longPressFired && (abs(dx) > touchSlop || abs(dy) > touchSlop)) {dragging = truemainHandler.removeCallbacks(longPressRunnable)+ hideLongPressRing()removeMenu()showDismissTarget()}@@ -204,6 +261,7 @@ class AssistiveBallOverlay(context: Context) {}MotionEvent.ACTION_UP -> {mainHandler.removeCallbacks(longPressRunnable)+ hideLongPressRing()val droppedOnTarget = dragging && isOverDismissTarget()removeDismissTarget()when {@@ -217,6 +275,7 @@ class AssistiveBallOverlay(context: Context) {}MotionEvent.ACTION_CANCEL -> {mainHandler.removeCallbacks(longPressRunnable)+ hideLongPressRing()removeDismissTarget()if (dragging) clampBallIntoBounds()truediff --git a/app/src/main/java/com/gotcha/ui/CallChatWindow.kt b/app/src/main/java/com/gotcha/ui/CallChatWindow.ktindex 6057946..c61944c 100644--- a/app/src/main/java/com/gotcha/ui/CallChatWindow.kt+++ b/app/src/main/java/com/gotcha/ui/CallChatWindow.kt@@ -14,6 +14,7 @@ import android.view.Viewimport android.view.ViewConfigurationimport android.view.ViewOutlineProviderimport android.view.WindowManager+import android.widget.FrameLayoutimport android.widget.LinearLayoutimport android.widget.TextViewimport com.gotcha.service.CallState@@ -21,15 +22,9 @@ import kotlin.math.abs/*** Two floating draggable glass buttons drawn over other apps during a voice- * call. The left button changes emoji and behavior based on call state:- *- * READY / WAITING_USER → 🎤 (onStartMic)- * LISTENING → ⏹ (onStopMic)- * THINKING / SPEAKING → 🛑 (onInterrupt)- * IDLE / STARTING / ENDING → hidden- *- * The right button is always the red end-call button (📞).- * The whole group is draggable so the user can move it out of the way.+ * call. The left button changes emoji and behavior based on call state.+ * The right end-call button requires a 3-second hold (shown via an expanding+ * ring) to fire — taps alone are ignored.*/class CallChatWindow(context: Context) {@@ -48,14 +43,26 @@ class CallChatWindow(context: Context) {private var rootParams: WindowManager.LayoutParams? = nullprivate var actionBtn: View? = nullprivate var endBtn: View? = null+ private var endWrapper: View? = null+ private var ringView: View? = nullprivate var currentState: CallState = CallState.IDLE++ // Drag stateprivate var dragging = falseprivate var startX = 0private var startY = 0private var touchDownRawX = 0fprivate var touchDownRawY = 0f+ // End-button long-press+ private var longPressFired = false+ private val endLongPressRunnable = Runnable {+ longPressFired = true+ hideEndButtonRing()+ onEndCall()+ }+fun show() {mainHandler.post {if (rootView != null) return@post@@ -75,6 +82,7 @@ class CallChatWindow(context: Context) {fun hide() {mainHandler.post {+ mainHandler.removeCallbacks(endLongPressRunnable)rootView?.let {try { windowManager.removeView(it) } catch (_: Exception) { }}@@ -82,6 +90,8 @@ class CallChatWindow(context: Context) {rootParams = nullactionBtn = nullendBtn = null+ endWrapper = null+ ringView = null}}@@ -129,11 +139,10 @@ class CallChatWindow(context: Context) {actionBtn?.visibility = View.GONE}}- endBtn?.alpha = if (s != CallState.IDLE && s != CallState.ENDING) 0.9f else 0.25f- endBtn?.setOnClickListener { onEndCall() }+ endWrapper?.alpha = if (s != CallState.IDLE && s != CallState.ENDING) 0.9f else 0.25f}- // ---- Container with drag handling ----+ // ---- Container with drag + end-button long-press handling ----private fun buildContainer(): View {val density = appContext.resources.displayMetrics.density@@ -142,6 +151,29 @@ class CallChatWindow(context: Context) {actionBtn = glassButton("\uD83C\uDFA4", btnSize, isEnd = false)endBtn = glassButton("\uD83D\uDCDE", btnSize, isEnd = true)+ // Wrap end button in FrameLayout so a ring can sit behind it+ val ringSize = (BTN_SIZE_DP * 1.6f * density).toInt()+ val ring = View(appContext).apply {+ background = GradientDrawable().apply {+ shape = GradientDrawable.OVAL+ setStroke(dp(2f), Color.parseColor("#AAFF6B6B"))+ setColor(Color.TRANSPARENT)+ }+ layoutParams = FrameLayout.LayoutParams(ringSize, ringSize, Gravity.CENTER)+ visibility = View.GONE+ }+ ringView = ring+ val wrapper = FrameLayout(appContext).apply {+ layoutParams = LinearLayout.LayoutParams(+ LinearLayout.LayoutParams.WRAP_CONTENT,+ LinearLayout.LayoutParams.WRAP_CONTENT+ )+ }+ wrapper.addView(ring)+ wrapper.addView(endBtn!!)+ endWrapper = wrapper+ ringView = ring+val row = LinearLayout(appContext).apply {orientation = LinearLayout.HORIZONTALgravity = Gravity.CENTER_VERTICAL@@ -150,7 +182,7 @@ class CallChatWindow(context: Context) {}actionBtn?.let { row.addView(it) }(actionBtn?.layoutParams as? LinearLayout.LayoutParams)?.setMargins(0, 0, (6 * density).toInt(), 0)- endBtn?.let { row.addView(it) }+ row.addView(wrapper)return row}@@ -193,22 +225,73 @@ class CallChatWindow(context: Context) {}}+ private fun showEndButtonRing() {+ ringView?.let { ring ->+ ring.visibility = View.VISIBLE+ ring.scaleX = 0.2f+ ring.scaleY = 0.2f+ ring.alpha = 1f+ ring.animate()+ .scaleX(1.8f)+ .scaleY(1.8f)+ .alpha(0f)+ .setDuration(END_LONG_PRESS_MS)+ .start()+ }+ }++ private fun hideEndButtonRing() {+ ringView?.let { ring ->+ ring.animate().cancel()+ ring.visibility = View.GONE+ }+ }++ private fun isTouchOnEndWrapper(x: Float, y: Float): Boolean {+ val w = endWrapper ?: return false+ return x >= w.left && x <= w.right && y >= w.top && y <= w.bottom+ }++ private fun handleActionUp(x: Float, y: Float) {+ val root = rootView as? LinearLayout ?: return+ val count = root.childCount+ for (i in 0 until count) {+ val child = root.getChildAt(i)+ if (x >= child.left && x <= child.right &&+ y >= child.top && y <= child.bottom+ ) {+ if (child == actionBtn) {+ actionBtn?.callOnClick()+ }+ break+ }+ }+ }++ @Suppress("CyclomaticComplexMethod")private fun containerTouchListener() = View.OnTouchListener { _, event ->when (event.action) {MotionEvent.ACTION_DOWN -> {- val p = rootParams ?: return@OnTouchListener false- startX = p.x- startY = p.y+ startX = rootParams?.x ?: 0+ startY = rootParams?.y ?: 0touchDownRawX = event.rawXtouchDownRawY = event.rawYdragging = false+ longPressFired = false++ if (isTouchOnEndWrapper(event.x, event.y) && endWrapper?.alpha != 0.25f) {+ mainHandler.postDelayed(endLongPressRunnable, END_LONG_PRESS_MS)+ showEndButtonRing()+ }true}MotionEvent.ACTION_MOVE -> {val dx = (event.rawX - touchDownRawX).toInt()val dy = (event.rawY - touchDownRawY).toInt()- if (!dragging && (abs(dx) > touchSlop || abs(dy) > touchSlop)) {+ if (!dragging && !longPressFired && (abs(dx) > touchSlop || abs(dy) > touchSlop)) {dragging = true+ mainHandler.removeCallbacks(endLongPressRunnable)+ hideEndButtonRing()}if (dragging) {rootParams?.let { p ->@@ -222,27 +305,19 @@ class CallChatWindow(context: Context) {true}MotionEvent.ACTION_UP -> {- if (!dragging) {- val x = event.x- val y = event.y- val root = rootView as? LinearLayout ?: return@OnTouchListener true- val count = root.childCount- for (i in 0 until count) {- val child = root.getChildAt(i)- if (x >= child.left && x <= child.right &&- y >= child.top && y <= child.bottom- ) {- when (child) {- actionBtn -> actionBtn?.callOnClick()- endBtn -> onEndCall()- }- break- }- }+ mainHandler.removeCallbacks(endLongPressRunnable)+ hideEndButtonRing()+ if (!dragging && !longPressFired) {+ handleActionUp(event.x, event.y)}+ longPressFired = false+ true+ }+ MotionEvent.ACTION_CANCEL -> {+ mainHandler.removeCallbacks(endLongPressRunnable)+ hideEndButtonRing()true}- MotionEvent.ACTION_CANCEL -> trueelse -> false}}@@ -275,5 +350,6 @@ class CallChatWindow(context: Context) {private companion object {const val BTN_SIZE_DP = 44+ const val END_LONG_PRESS_MS = 3000L}}