Skip to content

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 aura support to RingDrawable and implement a new GlassButtonDrawable for translucent glossy button styling

Rishabh Bajpaif847d1af763d
diff --git a/app/src/main/java/com/gotcha/ui/CallChatWindow.kt b/app/src/main/java/com/gotcha/ui/CallChatWindow.kt
index 989fba1..e78359b 100644
--- a/app/src/main/java/com/gotcha/ui/CallChatWindow.kt
+++ b/app/src/main/java/com/gotcha/ui/CallChatWindow.kt
@@ -5,7 +5,6 @@ import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
import android.content.Context
import android.graphics.Color
-import android.graphics.Outline
import android.graphics.PixelFormat
import android.graphics.drawable.GradientDrawable
import android.os.Build
@@ -15,9 +14,9 @@ import android.view.Gravity
import android.view.MotionEvent
import android.view.View
import android.view.ViewConfiguration
-import android.view.ViewOutlineProvider
import android.view.WindowManager
import android.view.animation.AccelerateDecelerateInterpolator
+import android.view.animation.OvershootInterpolator
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.TextView
@@ -32,7 +31,7 @@ import kotlin.math.abs
* ring drawn as a separate [WindowManager] overlay) to fire — taps alone
* are ignored.
*/
-@Suppress("TooManyFunctions")
+@Suppress("TooManyFunctions", "LargeClass")
class CallChatWindow(context: Context) {
private val appContext = context.applicationContext
@@ -60,6 +59,18 @@ class CallChatWindow(context: Context) {
private var actionRingOverlayView: View? = null
private var actionRingDrawable: RingDrawable? = null
private var actionRingAnimator: ValueAnimator? = null
+ private var actionBtnBg: GradientDrawable? = null
+ private var currentRingColor: Int = 0
+
+ // Glass backgrounds + state-driven animations
+ private var glassAction: GlassButtonDrawable? = null
+ private var glassEnd: GlassButtonDrawable? = null
+ private var breatheAnimator: ValueAnimator? = null
+ private var swapAnimator: ValueAnimator? = null
+ private var currentActionEmoji: String = ""
+ private var currentActionTint: Int = TINT_MIC
+ private var currentBreatheTag: String = ""
+ private var entranceAnimating: Boolean = false
private var currentState: CallState = CallState.IDLE
@@ -98,6 +109,9 @@ class CallChatWindow(context: Context) {
fun hide() {
mainHandler.post {
mainHandler.removeCallbacks(endLongPressRunnable)
+ stopBreathe()
+ swapAnimator?.cancel()
+ swapAnimator = null
removeRingOverlay()
removeActionRingOverlay()
rootView?.let {
@@ -130,30 +144,156 @@ class CallChatWindow(context: Context) {
// ---- Rendering ----
+ /** (emoji, glass tint) for the action button in a given call state. */
+ private fun actionAppearance(s: CallState): Pair<String, Int>? = when (s) {
+ CallState.READY, CallState.WAITING_USER -> "\uD83C\uDFA4" to TINT_MIC
+ CallState.LISTENING -> "\u23F9" to TINT_STOP
+ CallState.THINKING, CallState.SPEAKING -> "\uD83D\uDED1" to TINT_INTERRUPT
+ else -> null
+ }
+
@Suppress("SetTextI18n")
private fun renderButtons() {
val s = currentState
- when (s) {
- CallState.READY, CallState.WAITING_USER -> {
- actionBtn?.visibility = View.VISIBLE
- (actionBtn as? TextView)?.text = "\uD83C\uDFA4"
- actionBtn?.alpha = 1f
+ val appearance = actionAppearance(s)
+ val btn = actionBtn as? TextView
+ if (appearance == null) {
+ // Fade + shrink out, then hide.
+ swapAnimator?.cancel()
+ stopBreathe()
+ btn?.let { v ->
+ if (v.visibility == View.VISIBLE) {
+ v.animate().alpha(0f).scaleX(0.6f).scaleY(0.6f)
+ .setDuration(160L)
+ .setInterpolator(AccelerateDecelerateInterpolator())
+ .withEndAction { v.visibility = View.GONE }
+ .start()
+ }
}
- CallState.LISTENING -> {
- actionBtn?.visibility = View.VISIBLE
- (actionBtn as? TextView)?.text = "\u23F9"
- actionBtn?.alpha = 1f
+ } else {
+ val (emoji, tint) = appearance
+ val firstShow = btn?.visibility != View.VISIBLE
+ btn?.visibility = View.VISIBLE
+ if (firstShow) {
+ currentActionEmoji = emoji
+ currentActionTint = tint
+ btn?.text = emoji
+ glassAction?.tintColor = tint
+ animateEntrance(btn)
+ } else if (emoji != currentActionEmoji) {
+ animateSwap(btn, emoji, tint)
}
- CallState.THINKING, CallState.SPEAKING -> {
- actionBtn?.visibility = View.VISIBLE
- (actionBtn as? TextView)?.text = "\uD83D\uDED1"
- actionBtn?.alpha = 1f
+ startBreathe(s)
+ }
+ // Smoothly fade the end button's active/dim state instead of snapping.
+ val target = if (s != CallState.IDLE && s != CallState.ENDING) 1f else 0.28f
+ endWrapper?.let { w ->
+ w.animate().alpha(target).setDuration(220L)
+ .setInterpolator(AccelerateDecelerateInterpolator()).start()
+ }
+ }
+
+ /** Pop-in entrance: overshoot scale + fade from a small transparent state. */
+ private fun animateEntrance(btn: TextView?) {
+ val v = btn ?: return
+ entranceAnimating = true
+ v.alpha = 0f
+ v.scaleX = 0.4f
+ v.scaleY = 0.4f
+ v.animate().alpha(1f).scaleX(1f).scaleY(1f)
+ .setDuration(360L)
+ .setInterpolator(OvershootInterpolator(2.4f))
+ .withEndAction { entranceAnimating = false }
+ .start()
+ }
+
+ /**
+ * Animated emoji swap: shrink the current glyph away, switch text and glass
+ * tint at the low point, then overshoot back \u2014 with the tint crossfading
+ * across the whole motion so state changes read as one fluid gesture.
+ */
+ private fun animateSwap(btn: TextView?, emoji: String, tint: Int) {
+ val v = btn ?: return
+ swapAnimator?.cancel()
+ val fromTint = currentActionTint
+ currentActionEmoji = emoji
+ currentActionTint = tint
+ var switched = false
+ swapAnimator = ValueAnimator.ofFloat(0f, 1f).apply {
+ duration = 380L
+ interpolator = AccelerateDecelerateInterpolator()
+ addUpdateListener { anim ->
+ val p = anim.animatedValue as Float
+ // Scale dips to 0.55 at the midpoint, overshoots to ~1.08, settles.
+ val scale = when {
+ p < 0.5f -> 1f - 0.45f * (p / 0.5f)
+ else -> {
+ val t = (p - 0.5f) / 0.5f
+ 0.55f + 0.53f * t * t * (3f - 2f * t) - 0.08f * t
+ }
+ }
+ v.scaleX = scale
+ v.scaleY = scale
+ // Rotate a touch through the swap for life.
+ v.rotation = (1f - kotlin.math.abs(0.5f - p) * 2f) * 12f
+ glassAction?.tintColor = ColorUtils.blendARGB(fromTint, tint, p)
+ if (!switched && p >= 0.5f) {
+ switched = true
+ v.text = emoji
+ }
}
- else -> {
- actionBtn?.visibility = View.GONE
+ addListener(object : AnimatorListenerAdapter() {
+ override fun onAnimationEnd(animation: Animator) {
+ v.scaleX = 1f
+ v.scaleY = 1f
+ v.rotation = 0f
+ glassAction?.tintColor = tint
+ }
+ })
+ start()
+ }
+ }
+
+ /**
+ * Breathing glow that conveys agent state: a slow, calm pulse while waiting
+ * for the user (READY / WAITING_USER), and a faster, stronger pulse while
+ * the agent is actively listening / thinking / speaking.
+ */
+ private fun startBreathe(s: CallState) {
+ val active = s == CallState.LISTENING || s == CallState.THINKING || s == CallState.SPEAKING
+ val period = if (active) 1100L else 2600L
+ val peak = if (active) 1f else 0.5f
+ // Restart only if the cadence changed, so a steady state keeps its phase.
+ val tag = "$period|$peak"
+ if (breatheAnimator?.isRunning == true && currentBreatheTag == tag) return
+ currentBreatheTag = tag
+ breatheAnimator?.cancel()
+ val glass = glassAction ?: return
+ breatheAnimator = ValueAnimator.ofFloat(0f, 1f).apply {
+ duration = period
+ repeatMode = ValueAnimator.REVERSE
+ repeatCount = ValueAnimator.INFINITE
+ interpolator = AccelerateDecelerateInterpolator()
+ addUpdateListener { anim ->
+ val p = anim.animatedValue as Float
+ val g = 0.12f + (peak - 0.12f) * p
+ glass.glow = g
+ // Gentle scale swell synced to the glow, skipped mid-swap/entrance.
+ if (swapAnimator?.isRunning != true && !entranceAnimating) {
+ val sc = 1f + 0.05f * p * (if (active) 1f else 0.6f)
+ actionBtn?.scaleX = sc
+ actionBtn?.scaleY = sc
+ }
}
+ start()
}
- endWrapper?.alpha = if (s != CallState.IDLE && s != CallState.ENDING) 0.9f else 0.25f
+ }
+
+ private fun stopBreathe() {
+ breatheAnimator?.cancel()
+ breatheAnimator = null
+ currentBreatheTag = ""
+ glassAction?.glow = 0f
}
// ---- Container ----
@@ -192,43 +332,38 @@ class CallChatWindow(context: Context) {
private fun glassButton(emoji: String, size: Int, isEnd: Boolean): View {
val density = appContext.resources.displayMetrics.density
- val bg = GradientDrawable().apply {
+ val glass = GlassButtonDrawable(if (isEnd) TINT_END else TINT_MIC).apply {
+ fillAlpha = if (isEnd) 120 else 105
+ }
+ if (isEnd) glassEnd = glass else glassAction = glass
+
+ // Tool-execution tint overlay (transparent until setActionRingColor drives
+ // it). Kept as a separate oval GradientDrawable so existing setColor /
+ // setAlpha behavior is unchanged; layered above the glass base. Inset so
+ // it aligns with the (inset) translucent sphere, not the square bounds.
+ val inset = (size * 0.14f).toInt()
+ val toolTint = GradientDrawable().apply {
shape = GradientDrawable.OVAL
- if (isEnd) {
- colors = intArrayOf(
- Color.parseColor("#66FF6B6B"),
- Color.parseColor("#33CC3333")
- )
- setStroke(dp(1.5f), Color.parseColor("#AAFF6B6B"))
- } else {
- colors = intArrayOf(
- Color.parseColor("#44FFFFFF"),
- Color.parseColor("#22C0C0C0")
- )
- setStroke(dp(1.5f), Color.parseColor("#66FFFFFF"))
- }
- gradientType = GradientDrawable.LINEAR_GRADIENT
- orientation = GradientDrawable.Orientation.TL_BR
+ setColor(Color.TRANSPARENT)
+ }
+ val background = android.graphics.drawable.LayerDrawable(
+ arrayOf<android.graphics.drawable.Drawable>(glass, toolTint)
+ ).apply {
+ setLayerInset(1, inset, inset, inset, inset)
}
return TextView(appContext).apply {
text = emoji
- textSize = 18f
+ textSize = 19f
gravity = Gravity.CENTER
setIncludeFontPadding(false)
translationY = -1.5f * density
setTextColor(Color.WHITE)
- setShadowLayer(4f, 0f, 2f, Color.parseColor("#80000000"))
- this.background = bg
- setElevation(dp(3f).toFloat())
- outlineProvider = object : ViewOutlineProvider() {
- override fun getOutline(view: View, outline: Outline) {
- outline.setOval(0, 0, view.width, view.height)
- }
- }
- clipToOutline = true
+ // Soft circular glow behind the glyph (not clipped → no square edge).
+ setShadowLayer(6f * density, 0f, 1f * density, Color.parseColor("#66000000"))
+ this.background = background
layoutParams = LinearLayout.LayoutParams(size, size)
- }
+ }.also { if (!isEnd) actionBtnBg = toolTint }
}
// ---- Ring as a separate overlay ----
@@ -303,13 +438,14 @@ class CallChatWindow(context: Context) {
}
}
- /** Show or hide a thin static ring around the action (mic) button. */
+ /** Show or hide the action ring with aura glow. */
fun setActionRingColor(color: Int?) {
mainHandler.post {
if (color == null) {
removeActionRingOverlay()
return@post
}
+ currentRingColor = color
val density = appContext.resources.displayMetrics.density
val paddingPx = (8 * density).toInt()
val btnPx = (BTN_SIZE_DP * density).toInt()
@@ -318,7 +454,8 @@ class CallChatWindow(context: Context) {
if (actionRingOverlayView != null) {
actionRingDrawable?.strokeColor = color
- startActionRingAnimation(color)
+ actionRingDrawable?.auraColor = color
+ startActionRingWave(color)
return@post
}
@@ -328,6 +465,9 @@ class CallChatWindow(context: Context) {
strokeWidth = 2.5f * density
strokeColor = ColorUtils.setAlphaComponent(color, 0)
fillColor = android.graphics.Color.TRANSPARENT
+ auraColor = color
+ auraRadius = btnPx * 1.4f
+ auraIntensity = 0f
}
actionRingDrawable = drawable
@@ -354,55 +494,102 @@ class CallChatWindow(context: Context) {
try {
windowManager.addView(view, params)
actionRingOverlayView = view
- startActionRingAnimation(color)
+ startActionRingWave(color)
} catch (_: Exception) {
actionRingOverlayView = null
}
}
}
- /** Wave ripple → gentle breathing pulse. */
- private fun startActionRingAnimation(color: Int) {
+ /**
+ * Wave intro: aura explodes outward like a shockwave, ring appears at
+ * peak and settles, button background lights up.
+ */
+ private fun startActionRingWave(color: Int) {
actionRingAnimator?.cancel()
val drawable = actionRingDrawable ?: return
val density = appContext.resources.displayMetrics.density
val btnPx = (BTN_SIZE_DP * density).toInt()
val baseRadius = btnPx * 0.65f
val baseStroke = 2.5f * density
+ val bg = actionBtnBg
+
+ // Reset button background to ring color (fully transparent → fade in)
+ bg?.setColor(color)
+ bg?.setAlpha(0)
val wave = ValueAnimator.ofFloat(0f, 1f).apply {
- duration = 600L
+ duration = 800L
interpolator = AccelerateDecelerateInterpolator()
addUpdateListener { anim ->
val p = anim.animatedValue as Float
- val radiusScale: Float = when {
- p < 0.45f -> {
- val t = p / 0.45f
+ // Aura: expand from zero, overshoot, settle
+ val auraScale: Float = when {
+ p < 0.35f -> {
+ val t = p / 0.35f
+ 0f + 1.6f * t * t * (3f - 2f * t)
+ }
+ p < 0.60f -> {
+ val t = (p - 0.35f) / 0.25f
+ 1.6f - (1.6f - 1.2f) * t * t
+ }
+ else -> {
+ val t = (p - 0.60f) / 0.4f
+ 1.2f + (1.05f - 1.2f) * t
+ }
+ }
+ drawable.auraRadius = btnPx * 1.4f * auraScale
+
+ // Aura intensity: fade in, peak at mid-wave, settle
+ val auraIntensity: Float = when {
+ p < 0.20f -> p / 0.20f * 0.25f
+ p < 0.40f -> 0.25f + (0.55f - 0.25f) * ((p - 0.20f) / 0.20f)
+ p < 0.65f -> 0.55f - (0.55f - 0.30f) * ((p - 0.40f) / 0.25f)
+ else -> 0.30f * (1f - (p - 0.65f) / 0.35f * 0.5f)
+ }
+ drawable.auraIntensity = auraIntensity
+
+ // Ring: appears after aura starts, ripples
+ val ringScale: Float = when {
+ p < 0.15f -> 0f
+ p < 0.50f -> {
+ val t = (p - 0.15f) / 0.35f
0.2f + (1.35f - 0.2f) * t * t * (3f - 2f * t)
}
p < 0.75f -> {
- val t = (p - 0.45f) / 0.3f
- 1.35f - (1.35f - 0.85f) * t * t
+ val t = (p - 0.50f) / 0.25f
+ 1.35f - (1.35f - 0.88f) * t * t
}
else -> {
val t = (p - 0.75f) / 0.25f
- 0.85f + (1f - 0.85f) * t * t * (3f - 2f * t)
+ 0.88f + (1f - 0.88f) * t * t * (3f - 2f * t)
}
}
- drawable.ringRadius = baseRadius * radiusScale
+ drawable.ringRadius = if (ringScale > 0f) baseRadius * ringScale else 0f
+ // Stroke: flash at peak ring expansion
val strokeScale: Float = when {
- p < 0.25f -> 1f + (2.8f - 1f) * (p / 0.25f)
- p < 0.45f -> 2.8f - (2.8f - 1f) * ((p - 0.25f) / 0.2f)
+ p < 0.30f -> 0f
+ p < 0.42f -> ((p - 0.30f) / 0.12f) * 2.5f + 1f
+ p < 0.55f -> 3.5f - (3.5f - 1f) * ((p - 0.42f) / 0.13f)
else -> 1f
}
- drawable.strokeWidth = baseStroke * strokeScale
+ drawable.strokeWidth = if (strokeScale > 0f) baseStroke * strokeScale else 0f
- val alpha = if (p < 0.12f) p / 0.12f else 1f
+ // Ring alpha: fade in after aura
+ val ringAlpha: Float = when {
+ p < 0.20f -> 0f
+ p < 0.35f -> (p - 0.20f) / 0.15f
+ else -> 1f
+ }
drawable.strokeColor = ColorUtils.setAlphaComponent(
- color, (alpha * 255).toInt()
+ color, (ringAlpha * 255).toInt()
)
+
+ // Button background: fade in alongside aura
+ val bgAlpha = (auraIntensity * 50).toInt().coerceIn(0, 50)
+ bg?.setAlpha(bgAlpha)
}
addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
@@ -414,23 +601,42 @@ class CallChatWindow(context: Context) {
actionRingAnimator = wave
}
- /** Looping gentle pulse on alpha + radius. */
+ /**
+ * Aura breathe: ring alpha and aura radius pulse in shifted phases,
+ * button background follows the aura.
+ */
private fun startActionRingBreathe(color: Int) {
val drawable = actionRingDrawable ?: return
val baseRadius = drawable.ringRadius
+ val bg = actionBtnBg
+
+ drawable.auraRadius = baseRadius * 1.6f
- val breathe = ValueAnimator.ofFloat(0.4f, 1f).apply {
- duration = 2000L
+ val breathe = ValueAnimator.ofFloat(0f, 1f).apply {
+ duration = 3000L
repeatMode = ValueAnimator.REVERSE
repeatCount = ValueAnimator.INFINITE
interpolator = AccelerateDecelerateInterpolator()
addUpdateListener { anim ->
val p = anim.animatedValue as Float
+
+ // Ring alpha: 60% → 100% → 60%
+ val ringP = 0.6f + 0.4f * p
drawable.strokeColor = ColorUtils.setAlphaComponent(
- color, (p * 255).toInt()
+ color, (ringP * 255).toInt()
)
- // Subtle radius pulse for "alive" feel
- drawable.ringRadius = baseRadius * (0.97f + 0.03f * p)
+
+ // Aura intensity: 15% → 35% → 15% (shifted peak for organic feel)
+ val auraP = 0.12f + 0.25f * p
+ drawable.auraIntensity = auraP
+
+ // Aura radius: subtle pulse
+ val auraR = 1.55f + 0.15f * p
+ drawable.auraRadius = baseRadius * auraR
+
+ // Button background: 10 → 30 alpha, follows aura
+ val bgAlpha = (10 + 20 * p).toInt().coerceIn(0, 50)
+ bg?.setAlpha(bgAlpha)
}
start()
}
@@ -440,6 +646,7 @@ class CallChatWindow(context: Context) {
private fun removeActionRingOverlay() {
actionRingAnimator?.cancel()
actionRingAnimator = null
+ actionBtnBg?.setAlpha(0)
actionRingOverlayView?.let {
try { windowManager.removeView(it) } catch (_: Exception) { }
actionRingOverlayView = null
@@ -571,5 +778,11 @@ class CallChatWindow(context: Context) {
private companion object {
const val BTN_SIZE_DP = 44
const val END_LONG_PRESS_MS = 2000L
+
+ // Glass tints per action state and the end button.
+ val TINT_MIC = Color.parseColor("#2FB6C4") // calm teal — ready / mic
+ val TINT_STOP = Color.parseColor("#E8A13A") // amber — listening / stop
+ val TINT_INTERRUPT = Color.parseColor("#E5544B") // coral — interrupt
+ val TINT_END = Color.parseColor("#E23B3B") // red — end call
}
}
diff --git a/app/src/main/java/com/gotcha/ui/GlassButtonDrawable.kt b/app/src/main/java/com/gotcha/ui/GlassButtonDrawable.kt
new file mode 100644
index 0000000..25643e1
--- /dev/null
+++ b/app/src/main/java/com/gotcha/ui/GlassButtonDrawable.kt
@@ -0,0 +1,164 @@
+package com.gotcha.ui
+
+import android.graphics.Canvas
+import android.graphics.Color
+import android.graphics.ColorFilter
+import android.graphics.LinearGradient
+import android.graphics.Paint
+import android.graphics.PixelFormat
+import android.graphics.RadialGradient
+import android.graphics.Rect
+import android.graphics.Shader
+import android.graphics.drawable.Drawable
+import androidx.core.graphics.ColorUtils
+
+/**
+ * A translucent, glossy "liquid glass" circular button background.
+ *
+ * Everything is drawn as circular radial/linear gradients that fade to
+ * transparent well before the (square) bounds, so the button never shows a
+ * square edge and never fully occludes what's behind it:
+ * - a soft circular halo / glow just outside the sphere (doubles as the drop
+ * shadow and the breathing aura — [glow] intensifies it),
+ * - a translucent tinted sphere ([fillAlpha] controls see-through-ness),
+ * - a specular gloss near the top and a rim light.
+ *
+ * The visible sphere is inset from the bounds so the halo has room to fade out
+ * as a circle within the same square view — no layout/size change required.
+ */
+class GlassButtonDrawable(tint: Int) : Drawable() {
+
+ private val haloPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
+ private val basePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
+ private val specPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
+ private val rimPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE }
+
+ private var baseShaderValid = false
+ private var specShaderValid = false
+ private var rimShaderValid = false
+
+ private var sphereR = 0f
+ private var haloOuter = 0f
+
+ /** Base sphere opacity (0..255). Lower = more transparent / less blocking. */
+ var fillAlpha: Int = 125
+ set(value) {
+ field = value.coerceIn(0, 255)
+ invalidateSelf()
+ }
+
+ var tintColor: Int = tint
+ set(value) {
+ field = value
+ baseShaderValid = false
+ rimShaderValid = false
+ invalidateSelf()
+ }
+
+ /** 0..1 extra glow — brightens the halo, gloss and rim (breathing). */
+ var glow: Float = 0f
+ set(value) {
+ field = value.coerceIn(0f, 1f)
+ invalidateSelf()
+ }
+
+ override fun onBoundsChange(bounds: Rect) {
+ val rBox = minOf(bounds.width(), bounds.height()) / 2f
+ sphereR = rBox * 0.72f
+ haloOuter = rBox * 0.99f
+ baseShaderValid = false
+ specShaderValid = false
+ rimShaderValid = false
+ }
+
+ private fun lighten(c: Int, f: Float) = ColorUtils.blendARGB(c, Color.WHITE, f)
+ private fun darken(c: Int, f: Float) = ColorUtils.blendARGB(c, Color.BLACK, f)
+
+ override fun draw(canvas: Canvas) {
+ if (bounds.isEmpty || sphereR <= 0f) return
+ val cx = bounds.exactCenterX()
+ val cy = bounds.exactCenterY()
+
+ // Circular halo / glow — the soft drop shadow at rest, the breathing
+ // aura when [glow] rises. Peaks just outside the sphere and fades to
+ // transparent before the bounds, so it reads as a circle, not a square.
+ val peakA = (HALO_BASE_ALPHA + glow * HALO_GLOW_ALPHA).toInt().coerceIn(0, 255)
+ haloPaint.shader = RadialGradient(
+ cx, cy, haloOuter,
+ intArrayOf(
+ ColorUtils.setAlphaComponent(tintColor, peakA / 4),
+ ColorUtils.setAlphaComponent(tintColor, peakA),
+ Color.TRANSPARENT
+ ),
+ floatArrayOf((sphereR * 0.62f) / haloOuter, sphereR / haloOuter, 1f),
+ Shader.TileMode.CLAMP
+ )
+ canvas.drawCircle(cx, cy, haloOuter, haloPaint)
+
+ // Translucent tinted sphere, highlight biased toward the upper-left.
+ if (!baseShaderValid) {
+ basePaint.shader = RadialGradient(
+ cx - sphereR * 0.30f, cy - sphereR * 0.36f, sphereR * 1.35f,
+ intArrayOf(lighten(tintColor, 0.40f), tintColor, darken(tintColor, 0.32f)),
+ floatArrayOf(0f, 0.55f, 1f),
+ Shader.TileMode.CLAMP
+ )
+ baseShaderValid = true
+ }
+ basePaint.alpha = fillAlpha
+ canvas.drawCircle(cx, cy, sphereR, basePaint)
+
+ // Soft specular gloss concentrated near the top.
+ if (!specShaderValid) {
+ specPaint.shader = RadialGradient(
+ cx, cy - sphereR * 0.44f, sphereR * 0.78f,
+ intArrayOf(Color.WHITE, Color.TRANSPARENT),
+ floatArrayOf(0f, 1f),
+ Shader.TileMode.CLAMP
+ )
+ specShaderValid = true
+ }
+ specPaint.alpha = (28f + glow * 70f).toInt().coerceIn(0, 160)
+ canvas.drawCircle(cx, cy, sphereR, specPaint)
+
+ // Rim light — bright at the top, fading to a darker tint at the bottom.
+ if (!rimShaderValid) {
+ rimPaint.shader = LinearGradient(
+ cx, cy - sphereR, cx, cy + sphereR,
+ intArrayOf(
+ ColorUtils.setAlphaComponent(Color.WHITE, 150),
+ ColorUtils.setAlphaComponent(Color.WHITE, 30),
+ ColorUtils.setAlphaComponent(darken(tintColor, 0.25f), 90)
+ ),
+ floatArrayOf(0f, 0.5f, 1f),
+ Shader.TileMode.CLAMP
+ )
+ rimPaint.strokeWidth = sphereR * 0.07f
+ rimShaderValid = true
+ }
+ rimPaint.alpha = (150 + glow * 90f).toInt().coerceIn(0, 255)
+ canvas.drawCircle(cx, cy, sphereR - rimPaint.strokeWidth * 0.3f, rimPaint)
+ }
+
+ override fun setAlpha(alpha: Int) {
+ haloPaint.alpha = alpha
+ basePaint.alpha = alpha
+ specPaint.alpha = alpha
+ rimPaint.alpha = alpha
+ }
+
+ override fun setColorFilter(colorFilter: ColorFilter?) {
+ haloPaint.colorFilter = colorFilter
+ basePaint.colorFilter = colorFilter
+ specPaint.colorFilter = colorFilter
+ rimPaint.colorFilter = colorFilter
+ }
+
+ @Suppress("Deprecated")
+ override fun getOpacity(): Int = PixelFormat.TRANSLUCENT
+
+ private companion object {
+ const val HALO_BASE_ALPHA = 22f
+ const val HALO_GLOW_ALPHA = 80f
+ }
+}
diff --git a/app/src/main/java/com/gotcha/ui/RingDrawable.kt b/app/src/main/java/com/gotcha/ui/RingDrawable.kt
index 30ce9e2..4cdcd95 100644
--- a/app/src/main/java/com/gotcha/ui/RingDrawable.kt
+++ b/app/src/main/java/com/gotcha/ui/RingDrawable.kt
@@ -5,34 +5,33 @@ import android.graphics.Color
import android.graphics.ColorFilter
import android.graphics.Paint
import android.graphics.PixelFormat
+import android.graphics.RadialGradient
+import android.graphics.Shader
import android.graphics.drawable.Drawable
+import androidx.core.graphics.ColorUtils
/**
* 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.
+ * radius from the center of its bounds, with an optional soft glow aura.
*
- * 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.
+ * The aura is a radial gradient that peaks at [ringRadius] and fades outward
+ * to [auraRadius], creating a soft halo effect around the ring.
*/
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 }
+ private val auraPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
+
+ private var auraShaderValid = false
- /** How far the ring extends from the center, in pixels. */
var ringRadius: Float = 0f
set(value) {
field = value
+ auraShaderValid = false
invalidateSelf()
}
- /** Outline thickness in pixels. Independent of [ringRadius]. */
var strokeWidth: Float = 0f
set(value) {
field = value
@@ -40,28 +39,74 @@ class RingDrawable : Drawable() {
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()
}
+ /** Outer radius of the soft glow aura. 0 disables the aura. */
+ var auraRadius: Float = 0f
+ set(value) {
+ field = value
+ auraShaderValid = false
+ invalidateSelf()
+ }
+
+ /** Color used for the glow aura (alpha is scaled by [auraIntensity]). */
+ var auraColor: Int = Color.TRANSPARENT
+ set(value) {
+ field = value
+ auraShaderValid = false
+ invalidateSelf()
+ }
+
+ /** Glow intensity 0..1, scales the aura color's alpha. */
+ var auraIntensity: Float = 0f
+ set(value) {
+ field = value.coerceIn(0f, 1f)
+ auraShaderValid = false
+ invalidateSelf()
+ }
+
override fun draw(canvas: Canvas) {
- if (ringRadius <= 0f || bounds.isEmpty) return
+ if (bounds.isEmpty) return
val cx = bounds.exactCenterX()
val cy = bounds.exactCenterY()
+
+ if (auraIntensity > 0f && auraRadius > 0f && auraColor != Color.TRANSPARENT) {
+ if (!auraShaderValid) {
+ val baseAlpha = Color.alpha(auraColor)
+ val peakAlpha = (baseAlpha * auraIntensity).toInt().coerceIn(0, 255)
+ val peakColor = ColorUtils.setAlphaComponent(auraColor, peakAlpha)
+ val innerFade = ColorUtils.setAlphaComponent(auraColor, (peakAlpha * 0.3f).toInt())
+ val glowColors = intArrayOf(innerFade, peakColor, Color.TRANSPARENT)
+ val glowPositions = floatArrayOf(
+ (ringRadius / auraRadius) * 0.7f,
+ ringRadius / auraRadius,
+ 1f
+ )
+ auraPaint.shader = RadialGradient(
+ cx, cy, auraRadius,
+ glowColors, glowPositions,
+ Shader.TileMode.CLAMP
+ )
+ auraShaderValid = true
+ }
+ canvas.drawCircle(cx, cy, auraRadius, auraPaint)
+ }
+
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
@@ -77,6 +122,7 @@ class RingDrawable : Drawable() {
override fun setColorFilter(colorFilter: ColorFilter?) {
fillPaint.colorFilter = colorFilter
strokePaint.colorFilter = colorFilter
+ auraPaint.colorFilter = colorFilter
}
@Suppress("Deprecated")