Broadcast for Android

This commit is contained in:
rusefi 2020-08-15 21:49:39 -04:00
parent ccc3012705
commit 3e207b5549
6 changed files with 79 additions and 48 deletions

View File

@ -47,6 +47,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

View File

@ -3,7 +3,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rusefi.app">
<application android:label="@string/app_name">
<application android:label="@string/app_name"
android:theme="@style/AppTheme">
<!--
The USB_DEVICE_ATTACHED intent is always sent to an activity.

View File

@ -35,6 +35,8 @@ import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;
import com.google.android.material.snackbar.BaseTransientBottomBar;
import com.google.android.material.snackbar.Snackbar;
import com.rusefi.Callable;
import com.rusefi.app.serial.AndroidSerial;
import com.rusefi.auth.AutoTokenUtil;
@ -211,8 +213,11 @@ public class rusEFI extends Activity {
soundBroadcast.start();
} else if (view.getId() == R.id.buttonBroadcast) {
AndroidSerial serial = AndroidSerial.getAndroidSerial(mStatusView, mResultView, usbManager);
if (serial == null)
if (serial == null) {
Snackbar mySnackbar = Snackbar.make(view, "No ECU detected", BaseTransientBottomBar.LENGTH_LONG);
mySnackbar.show();
return;
}
LinkManager linkManager = new LinkManager();
linkManager.setConnector(new StreamConnector(linkManager, new Callable<IoStream>() {
@ -232,6 +237,10 @@ public class rusEFI extends Activity {
mResultView.append("On connection failed\n");
}
});
Snackbar mySnackbar = Snackbar.make(view, "Broadcasting with " + AutoTokenUtil.getAuthToken(), BaseTransientBottomBar.LENGTH_LONG);
mySnackbar.show();
}
}

View File

@ -1,54 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/myCoordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
android:layout_height="match_parent">
<TextView
android:id="@+id/text_status"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceMedium"/>
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sendMessage"
android:text="DFU" />
<EditText
android:id="@+id/authToken"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="Auth Token" />
<Button
android:id="@+id/buttonSound"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sendMessage"
android:text="Sound" />
<Button
android:id="@+id/buttonBroadcast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sendMessage"
android:text="Broadcast" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_result"
android:id="@+id/text_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</ScrollView>
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceMedium" />
</LinearLayout>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sendMessage"
android:text="DFU" />
<EditText
android:id="@+id/authToken"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="Auth Token" />
<Button
android:id="@+id/buttonSound"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sendMessage"
android:text="Sound" />
<Button
android:id="@+id/buttonBroadcast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sendMessage"
android:text="Broadcast" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_result"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -0,0 +1,8 @@
<!--
https://stackoverflow.com/questions/47090526/caused-by-java-lang-unsupportedoperationexception-failed-to-resolve-attribute/47090603
https://stackoverflow.com/questions/27780713/do-i-need-to-use-a-theme-appcompat-theme-or-descendant-for-v21-styles-too
-->
<resources>
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>

View File

@ -0,0 +1,4 @@
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat"></style>
<style name="AppTheme" parent="AppBaseTheme"></style>
</resources>