Skip to content

Commit

Permalink
Show debug outputs
Browse files Browse the repository at this point in the history
Show tinymix outputs dor device 1 and 2 in main activity
  • Loading branch information
rustammendel committed Jul 15, 2024
1 parent d86a954 commit 9a84b5f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 54 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ dependencies {
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.androidx.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
Expand Down
26 changes: 4 additions & 22 deletions app/src/main/java/com/rlabs/dakc/DakcTileService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,18 @@ import java.io.InputStreamReader
class DakcTileService : TileService() {


// Called when the user adds your tile.
override fun onTileAdded() {
super.onTileAdded()
}

// Called when your app can update your tile.
override fun onStartListening() {
super.onStartListening()
}

// Called when your app can no longer update your tile.
override fun onStopListening() {
super.onStopListening()
}

// Called when the user taps on your tile in an active or inactive state.
override fun onClick() {
super.onClick()
Log.d("QS", "Tile tapped")
runAsRoot(arrayOf("tinymix -D 2 3 120"))
}

// Called when the user removes your tile.
override fun onTileRemoved() {
super.onTileRemoved()
}
}

fun runAsRoot(commands: Array<String>) {
fun runAsRoot(commands: Array<String>): Pair<StringBuilder, StringBuilder> {
val output = StringBuilder()
val errorOutput = StringBuilder()

try {
for (command in commands) {
Expand All @@ -47,8 +30,6 @@ fun runAsRoot(commands: Array<String>) {
// Read the output
val reader = BufferedReader(InputStreamReader(process.inputStream))
val errorReader = BufferedReader(InputStreamReader(process.errorStream))
val output = StringBuilder()
val errorOutput = StringBuilder()

var line: String?
while (reader.readLine().also { line = it } != null) {
Expand All @@ -74,4 +55,5 @@ fun runAsRoot(commands: Array<String>) {
e.printStackTrace()
}

return Pair(output, errorOutput)
}
52 changes: 20 additions & 32 deletions app/src/main/java/com/rlabs/dakc/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,47 +1,35 @@
package com.rlabs.dakc

import android.os.Bundle
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.rlabs.dakc.ui.theme.DAKCTheme

class MainActivity : ComponentActivity() {
lateinit var dev1: TextView
lateinit var dev2: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
DAKCTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
Greeting(
name = "DAkC",
modifier = Modifier.padding(innerPadding)
)
}
}
}
setContentView(R.layout.activity_main)
dev1 = findViewById(R.id.dev1)
dev1.text = TinymixOut(device = "1")

dev2 = findViewById(R.id.dev2)
dev2.text = TinymixOut(device = "2")
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}
fun TinymixOut(device: String): String {
val outPair = runAsRoot(arrayOf("tinymix -D $device"))

val out = outPair.first.toString()
val errout = outPair.second.toString()

val firstLine = if (errout.isNotEmpty()) errout.split("\n")[0] else out.split("\n")[0]

// Log.d("tinymix", firstLine)

return "tinymix -D $device out: ${firstLine}!"

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
DAKCTheme {
Greeting("Android")
}
}
29 changes: 29 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dev1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="48dp"
android:layout_marginStart="32dp" />

<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dev2"
app:layout_constraintTop_toBottomOf="@+id/dev1"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="32dp" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 9a84b5f

Please sign in to comment.