Skip to content

Commit

Permalink
Got the GUI working, and overwrote Log with an inner class in SAFServ…
Browse files Browse the repository at this point in the history
…ice. This lets a broadcast constantly ping the GUI
  • Loading branch information
Tadashi-Hikari committed Mar 5, 2021
1 parent 8533bec commit c139968
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<TextView>(R.id.textView)
// For some reason this won't work when set in the XML
textView.setHorizontallyScrolling(true)
}

override fun onResume() {
Expand All @@ -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")
}
}
Expand All @@ -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
Expand Down
99 changes: 0 additions & 99 deletions CoreModule/src/main/res/layout/activity_core_central.xml

This file was deleted.

103 changes: 103 additions & 0 deletions CoreModule/src/main/res/layout/core_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.wear.widget.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/box_insert_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:padding="@dimen/box_inset_layout_padding"
tools:context=".CoreSimpleActivity"
tools:deviceIds="wear">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<Space
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="8"
android:background="#000000"
android:visibility="visible" />

<androidx.constraintlayout.widget.Barrier
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:foregroundTint="#000000"
android:visibility="visible"
app:barrierDirection="top" />

<ScrollView
android:id="@+id/scrollView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:isScrollContainer="true"
android:scrollbars="horizontal|vertical">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ellipsize="end"
android:hyphenationFrequency="none"
android:isScrollContainer="true"
android:lineSpacingExtra="4sp"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbars="horizontal|vertical"
android:singleLine="false"
android:text="Demo text \nTesting"
android:textColor="@color/black"
android:visibility="visible"
tools:visibility="visible" />
</ScrollView>

<androidx.constraintlayout.widget.Barrier
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="visible"
app:barrierDirection="top" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal">

<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />

<Button
android:id="@+id/record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="startCoreService"
android:text="Start Assistant" />

<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="reset"
android:text="Stop and Reset" />

<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>

</LinearLayout>

</androidx.wear.widget.BoxInsetLayout>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.termuxmodule

import android.content.Intent
import android.util.Log
import com.example.componentframework.SAFInstallService

class TermuxModuleInstallService: SAFInstallService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@
**/

import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import org.kaldi.KaldiRecognizer;
import org.kaldi.Model;
import org.kaldi.RecognitionListener;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package com.example.vosksttmodule
import android.content.Intent
import android.os.Binder
import android.os.IBinder
import android.util.Log
import com.example.componentframework.SAFService
import org.json.JSONObject
import org.kaldi.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.vosksttmodule

import android.content.Intent
import android.util.Log
import com.example.componentframework.SAFInstallService
import org.json.JSONObject
import java.lang.Exception
Expand Down

0 comments on commit c139968

Please sign in to comment.