refactor(ui): Simplify assistant overlay layout and remove unused buttons
This commit is contained in:
@@ -6,50 +6,39 @@ import android.service.voice.VoiceInteractionSession
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.app.assist.AssistStructure
|
import android.app.assist.AssistStructure
|
||||||
import android.app.assist.AssistContent
|
import android.app.assist.AssistContent
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
|
||||||
class ConduitVoiceInteractionSession(context: Context) : VoiceInteractionSession(context) {
|
class ConduitVoiceInteractionSession(context: Context) : VoiceInteractionSession(context) {
|
||||||
|
|
||||||
private var capturedContext: String? = null
|
private var capturedContext: String? = null
|
||||||
|
private var capturedScreenshot: Bitmap? = null
|
||||||
|
|
||||||
override fun onCreateContentView(): android.view.View {
|
override fun onCreateContentView(): android.view.View {
|
||||||
val view = layoutInflater.inflate(app.cogwheel.conduit.R.layout.assistant_overlay, null)
|
val view = layoutInflater.inflate(app.cogwheel.conduit.R.layout.assistant_overlay, null)
|
||||||
|
|
||||||
// Share screen button
|
// Summarize page button - sends screen context
|
||||||
val shareScreenButton = view.findViewById<android.view.View>(app.cogwheel.conduit.R.id.btn_share_screen)
|
|
||||||
shareScreenButton?.setOnClickListener {
|
|
||||||
// TODO: Implement share screen functionality
|
|
||||||
launchAppWithContext()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Summarize page button
|
|
||||||
val summarizeButton = view.findViewById<android.view.View>(app.cogwheel.conduit.R.id.btn_summarize)
|
val summarizeButton = view.findViewById<android.view.View>(app.cogwheel.conduit.R.id.btn_summarize)
|
||||||
summarizeButton?.setOnClickListener {
|
summarizeButton?.setOnClickListener {
|
||||||
launchAppWithContext()
|
launchAppWithContext(includeScreenshot = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask about page button
|
// Ask about page button - sends screenshot
|
||||||
val askAboutButton = view.findViewById<android.view.View>(app.cogwheel.conduit.R.id.btn_ask_about)
|
val askAboutButton = view.findViewById<android.view.View>(app.cogwheel.conduit.R.id.btn_ask_about)
|
||||||
askAboutButton?.setOnClickListener {
|
askAboutButton?.setOnClickListener {
|
||||||
launchAppWithContext()
|
launchAppWithScreenshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input area (opens text input)
|
// Input area (opens text input)
|
||||||
val inputArea = view.findViewById<android.view.View>(app.cogwheel.conduit.R.id.input_area)
|
val inputArea = view.findViewById<android.view.View>(app.cogwheel.conduit.R.id.input_area)
|
||||||
inputArea?.setOnClickListener {
|
inputArea?.setOnClickListener {
|
||||||
launchAppWithContext()
|
launchApp()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Voice button
|
// Voice button
|
||||||
val voiceButton = view.findViewById<android.view.View>(app.cogwheel.conduit.R.id.btn_voice)
|
val voiceButton = view.findViewById<android.view.View>(app.cogwheel.conduit.R.id.btn_voice)
|
||||||
voiceButton?.setOnClickListener {
|
voiceButton?.setOnClickListener {
|
||||||
// TODO: Implement voice input functionality
|
// TODO: Implement voice input functionality
|
||||||
launchAppWithContext()
|
launchAppWithContext(includeScreenshot = false)
|
||||||
}
|
|
||||||
|
|
||||||
// Sparkle button (AI actions)
|
|
||||||
val sparkleButton = view.findViewById<android.view.View>(app.cogwheel.conduit.R.id.btn_sparkle)
|
|
||||||
sparkleButton?.setOnClickListener {
|
|
||||||
launchAppWithContext()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return view
|
return view
|
||||||
@@ -64,6 +53,7 @@ class ConduitVoiceInteractionSession(context: Context) : VoiceInteractionSession
|
|||||||
|
|
||||||
android.util.Log.d("ConduitVoiceSession", "onHandleAssist called")
|
android.util.Log.d("ConduitVoiceSession", "onHandleAssist called")
|
||||||
|
|
||||||
|
// Capture screen context
|
||||||
val screenContext = StringBuilder()
|
val screenContext = StringBuilder()
|
||||||
structure?.let {
|
structure?.let {
|
||||||
val nodes = it.windowNodeCount
|
val nodes = it.windowNodeCount
|
||||||
@@ -72,12 +62,46 @@ class ConduitVoiceInteractionSession(context: Context) : VoiceInteractionSession
|
|||||||
traverseNode(windowNode.rootViewNode, screenContext)
|
traverseNode(windowNode.rootViewNode, screenContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
capturedContext = screenContext.toString()
|
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 {
|
try {
|
||||||
android.util.Log.d("ConduitVoiceSession", "Attempting to launch app with context")
|
android.util.Log.d("ConduitVoiceSession", "Attempting to launch app with context")
|
||||||
val intent = Intent(context, MainActivity::class.java)
|
val intent = Intent(context, MainActivity::class.java)
|
||||||
@@ -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) {
|
private fun traverseNode(node: AssistStructure.ViewNode?, builder: StringBuilder) {
|
||||||
if (node == null) return
|
if (node == null) return
|
||||||
|
|
||||||
|
|||||||
@@ -20,36 +20,6 @@
|
|||||||
android:layout_gravity="start"
|
android:layout_gravity="start"
|
||||||
android:layout_marginBottom="16dp">
|
android:layout_marginBottom="16dp">
|
||||||
|
|
||||||
<!-- Share screen with Live button -->
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/btn_share_screen"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:background="@drawable/dark_rounded_button_bg"
|
|
||||||
android:paddingStart="16dp"
|
|
||||||
android:paddingEnd="20dp"
|
|
||||||
android:paddingTop="14dp"
|
|
||||||
android:paddingBottom="14dp"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:layout_marginBottom="12dp"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="24dp"
|
|
||||||
android:layout_height="24dp"
|
|
||||||
android:src="@drawable/ic_share"
|
|
||||||
android:layout_marginEnd="12dp"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Share screen with Live"
|
|
||||||
android:textColor="@android:color/white"
|
|
||||||
android:textSize="16sp"/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<!-- Summarize page button -->
|
<!-- Summarize page button -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/btn_summarize"
|
android:id="@+id/btn_summarize"
|
||||||
@@ -119,73 +89,26 @@
|
|||||||
android:paddingStart="20dp"
|
android:paddingStart="20dp"
|
||||||
android:paddingEnd="8dp">
|
android:paddingEnd="8dp">
|
||||||
|
|
||||||
<!-- Plus button -->
|
<!-- Ask Conduit text -->
|
||||||
<ImageView
|
<TextView
|
||||||
android:id="@+id/btn_add"
|
|
||||||
android:layout_width="28dp"
|
|
||||||
android:layout_height="28dp"
|
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:src="@drawable/ic_add"
|
|
||||||
android:alpha="0.7"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"/>
|
|
||||||
|
|
||||||
<!-- Ask Conduit text with security icon -->
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/input_area"
|
android:id="@+id/input_area"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_toEndOf="@id/btn_add"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_toStartOf="@id/btn_voice"
|
android:layout_toStartOf="@id/btn_voice"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:layout_marginStart="12dp"
|
android:text="Ask Conduit"
|
||||||
android:orientation="horizontal"
|
android:textColor="@android:color/white"
|
||||||
android:gravity="center_vertical"
|
android:textSize="16sp"
|
||||||
|
android:alpha="0.6"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true">
|
android:focusable="true"/>
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="16dp"
|
|
||||||
android:layout_height="16dp"
|
|
||||||
android:src="@android:drawable/ic_secure"
|
|
||||||
android:alpha="0.5"
|
|
||||||
android:layout_marginEnd="6dp"
|
|
||||||
android:tint="@android:color/white"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Ask Conduit"
|
|
||||||
android:textColor="@android:color/white"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:alpha="0.6"/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<!-- Voice button -->
|
<!-- Voice button -->
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/btn_voice"
|
android:id="@+id/btn_voice"
|
||||||
android:layout_width="40dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="40dp"
|
android:layout_height="40dp"
|
||||||
android:layout_toStartOf="@id/btn_sparkle"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:layout_marginEnd="8dp"
|
|
||||||
android:background="@drawable/voice_button_bg"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="20dp"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:src="@drawable/ic_voice"/>
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
<!-- Sparkle button -->
|
|
||||||
<FrameLayout
|
|
||||||
android:id="@+id/btn_sparkle"
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:background="@drawable/voice_button_bg"
|
android:background="@drawable/voice_button_bg"
|
||||||
@@ -196,7 +119,7 @@
|
|||||||
android:layout_width="20dp"
|
android:layout_width="20dp"
|
||||||
android:layout_height="20dp"
|
android:layout_height="20dp"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:src="@drawable/ic_sparkle"/>
|
android:src="@drawable/ic_voice"/>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user