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: add RingDrawable for smooth growing-ring animations and update overlay UI components to use it
Rishabh Bajpaia6b5d1af0a44
diff --git a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.ktindex df19ed5..565bc27 100644--- a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt+++ b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt@@ -1,5 +1,6 @@package com.gotcha.ui+import android.animation.ValueAnimatorimport android.annotation.SuppressLintimport android.content.Contextimport android.graphics.Color@@ -17,11 +18,13 @@ import android.view.Viewimport android.view.ViewConfigurationimport android.view.ViewOutlineProviderimport android.view.WindowManager+import android.view.animation.AccelerateDecelerateInterpolatorimport android.widget.Buttonimport android.widget.ImageViewimport android.widget.LinearLayoutimport android.widget.ScrollViewimport android.widget.TextView+import androidx.core.graphics.ColorUtilsimport com.gotcha.Rimport kotlin.math.absimport kotlin.math.hypot@@ -61,6 +64,8 @@ class AssistiveBallOverlay(context: Context) {private var ballView: View? = nullprivate var ringView: View? = null+ private var ringDrawable: RingDrawable? = null+ private var ringAnimator: ValueAnimator? = nullprivate var menuView: View? = nullprivate var cardView: View? = nullprivate var dismissTargetView: View? = null@@ -160,54 +165,77 @@ class AssistiveBallOverlay(context: Context) {// ---- Long-press ring ----- /** Show an expanding ring around the ball during the 3s hold to start a call. */+ /** Show a growing 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 density = appContext.resources.displayMetrics.density+ // View is 3.5x the ball so the ring can grow to ~1.6x the ball radius+ // without hitting the view's bounds. The screen edge may still clip+ // when the ball is near the edge — that's intended.+ val viewSize = (BALL_SIZE_DP * 3.5f * density).toInt()+ val ballPx = dp(BALL_SIZE_DP)+ val drawable = RingDrawable()+ val view = View(appContext).apply { background = drawable }val params = WindowManager.LayoutParams(- ringSize,- ringSize,+ viewSize,+ viewSize,overlayType(),WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or- WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,+ WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE or+ WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,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+ x = ballParams.x + ballPx / 2 - viewSize / 2+ y = ballParams.y + ballPx / 2 - viewSize / 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()+ windowManager.addView(view, params)+ ringView = view+ ringDrawable = drawable++ val minRadius = ballPx * 0.50f+ val maxRadius = ballPx * 1.60f+ val strokePx = 2.5f * density+ val fillBase = Color.WHITE+ val strokeBase = Color.WHITE++ ringAnimator = ValueAnimator.ofFloat(0f, 1f).apply {+ duration = LONG_PRESS_START_MS+ interpolator = AccelerateDecelerateInterpolator()+ addUpdateListener { anim ->+ val p = anim.animatedValue as Float+ drawable.ringRadius = minRadius + (maxRadius - minRadius) * p+ // Stroke fades from full to ~40% opacity as it expands+ drawable.strokeColor = ColorUtils.setAlphaComponent(+ strokeBase,+ ((1f - p * 0.6f) * 255).toInt()+ )+ drawable.strokeWidth = strokePx+ // Fill tints the area between ball and ring, fades out+ drawable.fillColor = ColorUtils.setAlphaComponent(+ fillBase,+ ((0.18f * (1f - p)) * 255).toInt()+ )+ }+ start()+ }} catch (_: Exception) {ringView = null+ ringDrawable = null}}private fun hideLongPressRing() {- ringView?.let { safeRemove(it) }- ringView = null+ removeLongPressRing()}private fun removeLongPressRing() {+ ringAnimator?.cancel()+ ringAnimator = nullringView?.let { safeRemove(it) }ringView = null+ ringDrawable = null}@Suppress("CyclomaticComplexMethod")diff --git a/app/src/main/java/com/gotcha/ui/CallChatWindow.kt b/app/src/main/java/com/gotcha/ui/CallChatWindow.ktindex c61944c..59e490a 100644--- a/app/src/main/java/com/gotcha/ui/CallChatWindow.kt+++ b/app/src/main/java/com/gotcha/ui/CallChatWindow.kt@@ -1,5 +1,6 @@package com.gotcha.ui+import android.animation.ValueAnimatorimport android.content.Contextimport android.graphics.Colorimport android.graphics.Outline@@ -14,9 +15,11 @@ import android.view.Viewimport android.view.ViewConfigurationimport android.view.ViewOutlineProviderimport android.view.WindowManager+import android.view.animation.AccelerateDecelerateInterpolatorimport android.widget.FrameLayoutimport android.widget.LinearLayoutimport android.widget.TextView+import androidx.core.graphics.ColorUtilsimport com.gotcha.service.CallStateimport kotlin.math.abs@@ -45,6 +48,8 @@ class CallChatWindow(context: Context) {private var endBtn: View? = nullprivate var endWrapper: View? = nullprivate var ringView: View? = null+ private var ringDrawable: RingDrawable? = null+ private var ringAnimator: ValueAnimator? = nullprivate var currentState: CallState = CallState.IDLE@@ -59,7 +64,7 @@ class CallChatWindow(context: Context) {private var longPressFired = falseprivate val endLongPressRunnable = Runnable {longPressFired = true- hideEndButtonRing()+ cancelEndRing()onEndCall()}@@ -83,6 +88,7 @@ class CallChatWindow(context: Context) {fun hide() {mainHandler.post {mainHandler.removeCallbacks(endLongPressRunnable)+ cancelEndRing()rootView?.let {try { windowManager.removeView(it) } catch (_: Exception) { }}@@ -92,6 +98,7 @@ class CallChatWindow(context: Context) {endBtn = nullendWrapper = nullringView = null+ ringDrawable = null}}@@ -147,37 +154,48 @@ class CallChatWindow(context: Context) {private fun buildContainer(): View {val density = appContext.resources.displayMetrics.densityval btnSize = (BTN_SIZE_DP * density).toInt()+ val ringViewSize = (BTN_SIZE_DP * 3.5f * density).toInt()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()+ // Custom ring drawable — its radius is animated, not the view's scale+ val drawable = RingDrawable()+ ringDrawable = drawableval 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+ background = drawable+ layoutParams = FrameLayout.LayoutParams(ringViewSize, ringViewSize, Gravity.CENTER)}ringView = ring++ // Wrapper is exactly the end-button size so it lines up with the mic+ // button in the row. The ring view (3.5x) is centered inside and+ // allowed to draw beyond via clipChildren=false + software layer+ // (hardware acceleration can ignore clipChildren=false on some+ // devices, so we force software rendering to guarantee the ring+ // draws beyond the wrapper's bounds).val wrapper = FrameLayout(appContext).apply {- layoutParams = LinearLayout.LayoutParams(- LinearLayout.LayoutParams.WRAP_CONTENT,- LinearLayout.LayoutParams.WRAP_CONTENT- )+ layoutParams = LinearLayout.LayoutParams(btnSize, btnSize)+ clipChildren = false+ clipToPadding = false+ setLayerType(View.LAYER_TYPE_SOFTWARE, null)}+ // End button fills the wrapper so its center matches the ring's center+ endBtn!!.layoutParams = FrameLayout.LayoutParams(+ FrameLayout.LayoutParams.MATCH_PARENT,+ FrameLayout.LayoutParams.MATCH_PARENT+ )+ // Ring first (drawn underneath), then the buttonwrapper.addView(ring)wrapper.addView(endBtn!!)endWrapper = wrapper- ringView = ringval row = LinearLayout(appContext).apply {orientation = LinearLayout.HORIZONTALgravity = Gravity.CENTER_VERTICALsetPadding((8 * density).toInt(), 0, (8 * density).toInt(), 0)+ clipChildren = false+ clipToPadding = falsesetOnTouchListener(containerTouchListener())}actionBtn?.let { row.addView(it) }@@ -225,25 +243,47 @@ 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 startEndRingAnimation() {+ val drawable = ringDrawable ?: return+ val density = appContext.resources.displayMetrics.density+ val btnPx = dp(BTN_SIZE_DP.toFloat())+ val minRadius = btnPx * 0.50f+ val maxRadius = btnPx * 1.60f+ val strokePx = 2.5f * density+ val fillBase = Color.parseColor("#FF6B6B")+ val strokeBase = Color.parseColor("#FF6B6B")++ ringAnimator?.cancel()+ ringAnimator = ValueAnimator.ofFloat(0f, 1f).apply {+ duration = END_LONG_PRESS_MS+ interpolator = AccelerateDecelerateInterpolator()+ addUpdateListener { anim ->+ val p = anim.animatedValue as Float+ drawable.ringRadius = minRadius + (maxRadius - minRadius) * p+ drawable.strokeWidth = strokePx+ // Stroke fades from full to ~40% as it expands+ drawable.strokeColor = ColorUtils.setAlphaComponent(+ strokeBase,+ ((1f - p * 0.6f) * 255).toInt()+ )+ // Fill tints the area between the button and the growing ring+ drawable.fillColor = ColorUtils.setAlphaComponent(+ fillBase,+ ((0.22f * (1f - p)) * 255).toInt()+ )+ }+ start()}}- private fun hideEndButtonRing() {- ringView?.let { ring ->- ring.animate().cancel()- ring.visibility = View.GONE+ private fun cancelEndRing() {+ ringAnimator?.cancel()+ ringAnimator = null+ // Reset drawable so a fresh hold starts from a clean state+ ringDrawable?.let {+ it.ringRadius = 0f+ it.fillColor = Color.TRANSPARENT+ it.strokeColor = Color.TRANSPARENT}}@@ -281,7 +321,7 @@ class CallChatWindow(context: Context) {if (isTouchOnEndWrapper(event.x, event.y) && endWrapper?.alpha != 0.25f) {mainHandler.postDelayed(endLongPressRunnable, END_LONG_PRESS_MS)- showEndButtonRing()+ startEndRingAnimation()}true}@@ -291,7 +331,7 @@ class CallChatWindow(context: Context) {if (!dragging && !longPressFired && (abs(dx) > touchSlop || abs(dy) > touchSlop)) {dragging = truemainHandler.removeCallbacks(endLongPressRunnable)- hideEndButtonRing()+ cancelEndRing()}if (dragging) {rootParams?.let { p ->@@ -306,7 +346,7 @@ class CallChatWindow(context: Context) {}MotionEvent.ACTION_UP -> {mainHandler.removeCallbacks(endLongPressRunnable)- hideEndButtonRing()+ cancelEndRing()if (!dragging && !longPressFired) {handleActionUp(event.x, event.y)}@@ -315,7 +355,7 @@ class CallChatWindow(context: Context) {}MotionEvent.ACTION_CANCEL -> {mainHandler.removeCallbacks(endLongPressRunnable)- hideEndButtonRing()+ cancelEndRing()true}else -> falsediff --git a/app/src/main/java/com/gotcha/ui/RingDrawable.kt b/app/src/main/java/com/gotcha/ui/RingDrawable.ktnew file mode 100644index 0000000..30ce9e2--- /dev/null+++ b/app/src/main/java/com/gotcha/ui/RingDrawable.kt@@ -0,0 +1,84 @@+package com.gotcha.ui++import android.graphics.Canvas+import android.graphics.Color+import android.graphics.ColorFilter+import android.graphics.Paint+import android.graphics.PixelFormat+import android.graphics.drawable.Drawable++/**+ * A drawable that renders a ring (filled disk + outline) at a configurable+ * radius from the center of its bounds. Used for the long-press growing-ring+ * effect on the assistive ball and the call end button.+ *+ * Unlike scaling a [android.graphics.drawable.GradientDrawable], the stroke+ * width and fill here are independent of the [ringRadius] — animating the+ * radius changes the ring's size without distorting its stroke.+ *+ * Properties are settable from a [android.animation.ValueAnimator] for smooth+ * interpolation: grow [ringRadius] from a small value to a max while+ * simultaneously fading the fill.+ */+class RingDrawable : Drawable() {++ private val fillPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }+ private val strokePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE }++ /** How far the ring extends from the center, in pixels. */+ var ringRadius: Float = 0f+ set(value) {+ field = value+ invalidateSelf()+ }++ /** Outline thickness in pixels. Independent of [ringRadius]. */+ var strokeWidth: Float = 0f+ set(value) {+ field = value+ strokePaint.strokeWidth = value+ invalidateSelf()+ }++ /** Color painted inside the ring (between the center and [ringRadius]). */+ var fillColor: Int = Color.TRANSPARENT+ set(value) {+ field = value+ invalidateSelf()+ }++ /** Outline color drawn at [ringRadius]. */+ var strokeColor: Int = Color.TRANSPARENT+ set(value) {+ field = value+ invalidateSelf()+ }++ override fun draw(canvas: Canvas) {+ if (ringRadius <= 0f || bounds.isEmpty) return+ val cx = bounds.exactCenterX()+ val cy = bounds.exactCenterY()+ if (fillColor != Color.TRANSPARENT) {+ fillPaint.color = fillColor+ canvas.drawCircle(cx, cy, ringRadius, fillPaint)+ }+ if (strokeColor != Color.TRANSPARENT && strokeWidth > 0f) {+ strokePaint.color = strokeColor+ strokePaint.strokeWidth = strokeWidth+ canvas.drawCircle(cx, cy, ringRadius, strokePaint)+ }+ }++ override fun setAlpha(alpha: Int) {+ fillPaint.alpha = alpha+ strokePaint.alpha = alpha+ }++ override fun setColorFilter(colorFilter: ColorFilter?) {+ fillPaint.colorFilter = colorFilter+ strokePaint.colorFilter = colorFilter+ }++ @Suppress("Deprecated")+ override fun getOpacity(): Int = PixelFormat.TRANSLUCENT+}