From 577d76c2a2c48fe0d228917db4aeb6eeaa70b17a Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Fri, 21 Nov 2025 20:50:27 +0530 Subject: [PATCH] refactor(ui): Simplify assistant overlay layout and remove unused buttons --- .../conduit/ConduitVoiceInteractionSession.kt | 108 ++++++++++++++---- .../src/main/res/layout/assistant_overlay.xml | 95 ++------------- 2 files changed, 92 insertions(+), 111 deletions(-) diff --git a/android/app/src/main/kotlin/app/cogwheel/conduit/ConduitVoiceInteractionSession.kt b/android/app/src/main/kotlin/app/cogwheel/conduit/ConduitVoiceInteractionSession.kt index 1e24238..ffd7c9c 100644 --- a/android/app/src/main/kotlin/app/cogwheel/conduit/ConduitVoiceInteractionSession.kt +++ b/android/app/src/main/kotlin/app/cogwheel/conduit/ConduitVoiceInteractionSession.kt @@ -6,50 +6,39 @@ import android.service.voice.VoiceInteractionSession import android.os.Bundle import android.app.assist.AssistStructure import android.app.assist.AssistContent +import android.graphics.Bitmap class ConduitVoiceInteractionSession(context: Context) : VoiceInteractionSession(context) { private var capturedContext: String? = null + private var capturedScreenshot: Bitmap? = null override fun onCreateContentView(): android.view.View { val view = layoutInflater.inflate(app.cogwheel.conduit.R.layout.assistant_overlay, null) - // Share screen button - val shareScreenButton = view.findViewById(app.cogwheel.conduit.R.id.btn_share_screen) - shareScreenButton?.setOnClickListener { - // TODO: Implement share screen functionality - launchAppWithContext() - } - - // Summarize page button + // Summarize page button - sends screen context val summarizeButton = view.findViewById(app.cogwheel.conduit.R.id.btn_summarize) summarizeButton?.setOnClickListener { - launchAppWithContext() + launchAppWithContext(includeScreenshot = false) } - // Ask about page button + // Ask about page button - sends screenshot val askAboutButton = view.findViewById(app.cogwheel.conduit.R.id.btn_ask_about) askAboutButton?.setOnClickListener { - launchAppWithContext() + launchAppWithScreenshot() } // Input area (opens text input) val inputArea = view.findViewById(app.cogwheel.conduit.R.id.input_area) inputArea?.setOnClickListener { - launchAppWithContext() + launchApp() } // Voice button val voiceButton = view.findViewById(app.cogwheel.conduit.R.id.btn_voice) voiceButton?.setOnClickListener { // TODO: Implement voice input functionality - launchAppWithContext() - } - - // Sparkle button (AI actions) - val sparkleButton = view.findViewById(app.cogwheel.conduit.R.id.btn_sparkle) - sparkleButton?.setOnClickListener { - launchAppWithContext() + launchAppWithContext(includeScreenshot = false) } return view @@ -61,9 +50,10 @@ class ConduitVoiceInteractionSession(context: Context) : VoiceInteractionSession content: AssistContent? ) { super.onHandleAssist(data, structure, content) - + android.util.Log.d("ConduitVoiceSession", "onHandleAssist called") + // Capture screen context val screenContext = StringBuilder() structure?.let { val nodes = it.windowNodeCount @@ -72,26 +62,60 @@ class ConduitVoiceInteractionSession(context: Context) : VoiceInteractionSession traverseNode(windowNode.rootViewNode, screenContext) } } - capturedContext = screenContext.toString() - // Ideally, we could update the UI here to say "Context Ready" + + // Capture screenshot from assist data + data?.let { + try { + capturedScreenshot = it.getParcelable("screenshot") + if (capturedScreenshot == null) { + // Try alternative key + capturedScreenshot = it.getParcelable("android.intent.extra.ASSIST_SCREENSHOT") + } + android.util.Log.d("ConduitVoiceSession", "Screenshot captured: ${capturedScreenshot != null}") + } catch (e: Exception) { + android.util.Log.e("ConduitVoiceSession", "Failed to get screenshot from bundle", e) + } + } } - private fun launchAppWithContext() { + override fun onHandleScreenshot(screenshot: Bitmap?) { + super.onHandleScreenshot(screenshot) + capturedScreenshot = screenshot + android.util.Log.d("ConduitVoiceSession", "Screenshot received via onHandleScreenshot: ${screenshot != null}") + } + + private fun launchApp() { + try { + android.util.Log.d("ConduitVoiceSession", "Attempting to launch app") + val intent = Intent(context, MainActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + + context.startActivity(intent) + android.util.Log.d("ConduitVoiceSession", "App launch requested") + finish() // Close the overlay + } catch (e: Exception) { + android.util.Log.e("ConduitVoiceSession", "Failed to launch app", e) + } + } + + private fun launchAppWithContext(includeScreenshot: Boolean) { try { android.util.Log.d("ConduitVoiceSession", "Attempting to launch app with context") val intent = Intent(context, MainActivity::class.java) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - + if (capturedContext != null) { intent.putExtra("screen_context", capturedContext) android.util.Log.d("ConduitVoiceSession", "Context attached: ${capturedContext?.take(50)}...") } else { android.util.Log.d("ConduitVoiceSession", "No context captured") } - + context.startActivity(intent) android.util.Log.d("ConduitVoiceSession", "App launch requested") finish() // Close the overlay @@ -100,6 +124,40 @@ class ConduitVoiceInteractionSession(context: Context) : VoiceInteractionSession } } + private fun launchAppWithScreenshot() { + try { + android.util.Log.d("ConduitVoiceSession", "Attempting to launch app with screenshot") + val intent = Intent(context, MainActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + + // Save screenshot to cache and pass URI + capturedScreenshot?.let { bitmap -> + try { + val file = java.io.File(context.cacheDir, "assistant_screenshot_${System.currentTimeMillis()}.png") + val outputStream = java.io.FileOutputStream(file) + bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream) + outputStream.flush() + outputStream.close() + + intent.putExtra("screenshot_path", file.absolutePath) + android.util.Log.d("ConduitVoiceSession", "Screenshot saved to: ${file.absolutePath}") + } catch (e: Exception) { + android.util.Log.e("ConduitVoiceSession", "Failed to save screenshot", e) + } + } ?: run { + android.util.Log.d("ConduitVoiceSession", "No screenshot captured") + } + + context.startActivity(intent) + android.util.Log.d("ConduitVoiceSession", "App launch requested with screenshot") + finish() // Close the overlay + } catch (e: Exception) { + android.util.Log.e("ConduitVoiceSession", "Failed to launch app with screenshot", e) + } + } + private fun traverseNode(node: AssistStructure.ViewNode?, builder: StringBuilder) { if (node == null) return diff --git a/android/app/src/main/res/layout/assistant_overlay.xml b/android/app/src/main/res/layout/assistant_overlay.xml index 2988499..26b252a 100644 --- a/android/app/src/main/res/layout/assistant_overlay.xml +++ b/android/app/src/main/res/layout/assistant_overlay.xml @@ -20,36 +20,6 @@ android:layout_gravity="start" android:layout_marginBottom="16dp"> - - - - - - - - - - - - - + - - - - - + android:focusable="true"/> - - - - - - + android:src="@drawable/ic_voice"/>