From c139968212b33235f71b1f1b20e2c435a02da906 Mon Sep 17 00:00:00 2001 From: Christopher Carroll Date: Thu, 4 Mar 2021 20:44:56 -0500 Subject: [PATCH] Got the GUI working, and overwrote Log with an inner class in SAFService. This lets a broadcast constantly ping the GUI --- .../example/componentframework/SAFService.kt | 42 ++++++- .../CoreModuleInstallService.kt | 2 - .../CoreSimpleActivity.kt | 13 ++- .../main/res/layout/activity_core_central.xml | 99 ----------------- .../src/main/res/layout/core_activity.xml | 103 ++++++++++++++++++ .../TermuxModuleInstallService.kt | 1 - .../vosksttmodule/CustomSpeechRecognizer.java | 6 - .../com/example/vosksttmodule/KaldiService.kt | 1 - .../vosksttmodule/VoskModuleInstallService.kt | 1 - 9 files changed, 152 insertions(+), 116 deletions(-) delete mode 100644 CoreModule/src/main/res/layout/activity_core_central.xml create mode 100644 CoreModule/src/main/res/layout/core_activity.xml diff --git a/ComponentFramework/src/main/java/com/example/componentframework/SAFService.kt b/ComponentFramework/src/main/java/com/example/componentframework/SAFService.kt index c6a9463..0464c26 100644 --- a/ComponentFramework/src/main/java/com/example/componentframework/SAFService.kt +++ b/ComponentFramework/src/main/java/com/example/componentframework/SAFService.kt @@ -10,6 +10,45 @@ import java.io.InputStreamReader import java.lang.Exception abstract class SAFService: Service(){ + + // This is just to override + inner class LogOverride{ + + fun broadcastStatus(name: String, message:String) { + var notifyIntent = Intent() + notifyIntent.putExtra(MESSAGE, "${name}: ${message}") + notifyIntent.setAction(GUI_BROADCAST) + sendBroadcast(notifyIntent) + } + + fun i(name: String, message: String){ + android.util.Log.i(name,message) + broadcastStatus(name,message) + } + + fun d(name: String, message: String){ + android.util.Log.d(name,message) + broadcastStatus(name,message) + } + + fun e(name: String, message: String){ + android.util.Log.e(name,message) + broadcastStatus(name,message) + } + + fun v(name: String, message: String){ + android.util.Log.v(name,message) + broadcastStatus(name,message) + } + + fun w(name: String, message: String){ + android.util.Log.w(name,message) + broadcastStatus(name,message) + } + } + + var Log = LogOverride() + // Standard extras val MESSAGE="assistant.framework.protocol.MESSAGE" val STDERR="assistant.framework.protocol.STDERR" @@ -59,7 +98,6 @@ abstract class SAFService: Service(){ val GUI_BROADCAST = "assistant.framework.broadcast.GUI_UPDATE" override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int{ - Log.d(this.javaClass.name,"----------------------------------INCOMING INTENT: ${intent.extras.toString()}") // I don't know why I can't copy or send out the incoming intent. I suppose its the broadcast propogation thing var notifyIntent = Intent() notifyIntent.putExtra(MESSAGE,"${this.packageName};${this.javaClass.name}") @@ -169,7 +207,7 @@ abstract class SAFService: Service(){ } fun parseConfigFile(filename: String): JSONObject{ - Log.v(this.applicationInfo.className,"Parsing config file") + Log.v(this.javaClass.name,"Parsing config file") return JSONObject() } diff --git a/CoreModule/src/main/java/com/example/sapphireassistantframework/CoreModuleInstallService.kt b/CoreModule/src/main/java/com/example/sapphireassistantframework/CoreModuleInstallService.kt index 7205679..5faea19 100644 --- a/CoreModule/src/main/java/com/example/sapphireassistantframework/CoreModuleInstallService.kt +++ b/CoreModule/src/main/java/com/example/sapphireassistantframework/CoreModuleInstallService.kt @@ -1,9 +1,7 @@ package com.example.sapphireassistantframework import android.content.Intent -import android.util.Log import com.example.componentframework.SAFInstallService -import com.example.componentframework.SAFService class CoreModuleInstallService: SAFInstallService(){ val VERSION = "0.0.1" diff --git a/CoreModule/src/main/java/com/example/sapphireassistantframework/CoreSimpleActivity.kt b/CoreModule/src/main/java/com/example/sapphireassistantframework/CoreSimpleActivity.kt index 33d7b32..4ba4d19 100644 --- a/CoreModule/src/main/java/com/example/sapphireassistantframework/CoreSimpleActivity.kt +++ b/CoreModule/src/main/java/com/example/sapphireassistantframework/CoreSimpleActivity.kt @@ -8,7 +8,7 @@ import android.content.IntentFilter import android.content.pm.PackageManager import android.util.Log import android.view.View -import android.widget.EditText +import android.widget.ScrollView import android.widget.TextView import androidx.core.content.ContextCompat import java.io.File @@ -20,10 +20,14 @@ class CoreSimpleActivity: Activity() // This needs to be loaded from a config table private var tables = listOf("registration.tbl","defaultmodules.tbl","background.tbl","routetable.tbl","alias.tbl") val GUI_BROADCAST = "assistant.framework.broadcast.GUI_UPDATE" + val MESSAGE="assistant.framework.protocol.MESSAGE" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_core_central) + setContentView(R.layout.core_activity) + var textView = findViewById(R.id.textView) + // For some reason this won't work when set in the XML + textView.setHorizontallyScrolling(true) } override fun onResume() { @@ -32,7 +36,8 @@ class CoreSimpleActivity: Activity() // Maybe an optimization issue var coreBroadcastReceiver = object : BroadcastReceiver(){ override fun onReceive(context: Context?, intent: Intent?) { - updateUI(intent.toString()) + var test = intent?.getStringExtra(MESSAGE) + updateUI(test!!) Log.i(this.javaClass.name,"SAF Broadcast receieved") } } @@ -45,7 +50,7 @@ class CoreSimpleActivity: Activity() fun updateUI(string: String){ var textView: TextView = findViewById(R.id.textView) - textView.append(string) + textView.append("\n${string}") } // This will likely need to be more dynamic. This is just checking for permissions diff --git a/CoreModule/src/main/res/layout/activity_core_central.xml b/CoreModule/src/main/res/layout/activity_core_central.xml deleted file mode 100644 index 96740de..0000000 --- a/CoreModule/src/main/res/layout/activity_core_central.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - -