Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
dd77dcfdf4 | |||
0a417dbca2 | |||
48c4cfc121 | |||
cdf9b5b155 | |||
9abc83001e | |||
6307a68408 | |||
282af39b48 | |||
0f2e78b005 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,3 +13,4 @@
|
|||||||
.externalNativeBuild
|
.externalNativeBuild
|
||||||
.cxx
|
.cxx
|
||||||
.idea
|
.idea
|
||||||
|
/app/release
|
||||||
|
@@ -27,4 +27,5 @@ dependencies {
|
|||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
|
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
|
||||||
|
implementation 'androidx.recyclerview:recyclerview:1.1.0'
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,10 @@
|
|||||||
package com.janasroboter;
|
package com.janasroboter;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -10,46 +14,101 @@ import android.widget.Toast;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.janasroboter.REST.URL;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private final String URL = "http://192.168.4.1";
|
private RecyclerView recyclerView;
|
||||||
|
private RecyclerView.Adapter modeAdapter;
|
||||||
|
private LinearLayoutManager layoutManager;
|
||||||
|
private List<String> data;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
|
// Netzwerk aktivieren
|
||||||
|
StrictMode.setThreadPolicy(new StrictMode
|
||||||
|
.ThreadPolicy
|
||||||
|
.Builder()
|
||||||
.detectDiskReads()
|
.detectDiskReads()
|
||||||
.detectDiskWrites()
|
.detectDiskWrites()
|
||||||
.detectNetwork()
|
.detectNetwork()
|
||||||
.penaltyLog()
|
.penaltyLog()
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
|
recyclerView = findViewById(R.id.recyclerv);
|
||||||
|
|
||||||
|
recyclerView.setHasFixedSize(true);
|
||||||
|
layoutManager = new LinearLayoutManager(getBaseContext());
|
||||||
|
recyclerView.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
|
data = new ArrayList<>();
|
||||||
|
setRecyclerData(data);
|
||||||
|
|
||||||
|
modeAdapter = new ModeListAdapter(data);
|
||||||
|
recyclerView.setAdapter(modeAdapter);
|
||||||
|
|
||||||
|
recyclerView.addItemDecoration(new DividerItemDecoration(getBaseContext(), DividerItemDecoration.VERTICAL));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setRecyclerData(List<String> data) {
|
||||||
|
data.add("Beide Augen");
|
||||||
|
data.add("SOS");
|
||||||
|
data.add("Abwechselnd blinken");
|
||||||
|
data.add("Ein Auge einmal, Ein Auge zweimal");
|
||||||
|
data.add("Augen blinken immer langsamer");
|
||||||
|
data.add("Augen blinken immer schneller");
|
||||||
|
data.add("Augen blinken zufällig");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void btnToggle(View view) {
|
public void btnToggle(View view) {
|
||||||
|
// Fehlernachricht in String schreiben
|
||||||
String toast = "Obacht! Etwas ist schief gelaufen.";
|
String toast = "Obacht! Etwas ist schief gelaufen.";
|
||||||
try {
|
try {
|
||||||
|
// Aufruf an den Mikrocontroller senden
|
||||||
REST.getString(URL + "/toggle");
|
REST.getString(URL + "/toggle");
|
||||||
|
// Erfolgsnachricht anpassen
|
||||||
toast = "Muster geändert.";
|
toast = "Muster geändert.";
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
// Nachricht auf dem Bildschirm ausgeben
|
||||||
Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void btnLos(View view) {
|
public void btnLos(View view) {
|
||||||
|
// Textfeld im Code verfügbar machen
|
||||||
EditText state = view.getRootView().findViewById(R.id.state);
|
EditText state = view.getRootView().findViewById(R.id.state);
|
||||||
|
// Zahl aus dem Textfeld auslesen
|
||||||
String nummer = state.getText().toString();
|
String nummer = state.getText().toString();
|
||||||
|
// Fehlernachricht in String schreiben
|
||||||
String toast = "Obacht! Etwas ist schief gelaufen.";
|
String toast = "Obacht! Etwas ist schief gelaufen.";
|
||||||
try {
|
try {
|
||||||
|
// Aufruf mit Zahl an den Mikrocontroller senden
|
||||||
REST.getString(URL + "/togglearg?state=" + nummer);
|
REST.getString(URL + "/togglearg?state=" + nummer);
|
||||||
|
// Erfolgsnachricht anpassen
|
||||||
toast = "Muster auf " + nummer + " gesetzt.";
|
toast = "Muster auf " + nummer + " gesetzt.";
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
// Nachricht auf dem Bildschirm ausgeben
|
||||||
|
Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void btnSingen(View view) {
|
||||||
|
String toast = "Obacht! Etwas ist schief gelaufen.";
|
||||||
|
try {
|
||||||
|
REST.getString(URL + "/singen");
|
||||||
|
toast = "Singen aktiviert";
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
77
app/src/main/java/com/janasroboter/ModeListAdapter.java
Normal file
77
app/src/main/java/com/janasroboter/ModeListAdapter.java
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
package com.janasroboter;
|
||||||
|
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ModeListAdapter extends RecyclerView.Adapter<ModeListAdapter.LineHolder> {
|
||||||
|
|
||||||
|
private List<String> data;
|
||||||
|
|
||||||
|
static class LineHolder extends RecyclerView.ViewHolder {
|
||||||
|
public TextView mode;
|
||||||
|
|
||||||
|
|
||||||
|
public LineHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
mode = itemView.findViewById(R.id.tv_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModeListAdapter(List<String> data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModeListAdapter.LineHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
// Create a new view
|
||||||
|
View view = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.recycler_item, parent, false);
|
||||||
|
|
||||||
|
return new LineHolder(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull LineHolder holder, final int position) {
|
||||||
|
// Set the mode text
|
||||||
|
String text = data.get(position);
|
||||||
|
System.out.println("Username: " + text);
|
||||||
|
holder.mode.setText(text);
|
||||||
|
|
||||||
|
// Set the click actions
|
||||||
|
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Thread t = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String msg = "";
|
||||||
|
try {
|
||||||
|
// Aufruf mit Zahl an den Mikrocontroller senden
|
||||||
|
REST.getString(REST.URL + "/togglearg?state=" + (position + 1));
|
||||||
|
// Erfolgsnachricht anpassen
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
t.start();
|
||||||
|
Toast.makeText(v.getContext(), "Setze auf Muster: " + (position + 1), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return data.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -17,6 +17,9 @@ public class REST {
|
|||||||
private static final MediaType MEDIA_TYPE_MP4 = MediaType.parse("video/mp4");
|
private static final MediaType MEDIA_TYPE_MP4 = MediaType.parse("video/mp4");
|
||||||
|
|
||||||
|
|
||||||
|
public static final String URL = "http://192.168.4.1";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a GET request to a url
|
* Make a GET request to a url
|
||||||
* @param url the url string
|
* @param url the url string
|
||||||
|
@@ -64,4 +64,36 @@
|
|||||||
android:text="Nächstes Muster:"
|
android:text="Nächstes Muster:"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="41dp"
|
||||||
|
android:text="Singen:"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/textViewMuster" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnSingen"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="90dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:onClick="btnSingen"
|
||||||
|
android:text="Singen"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/textView"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/state" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/recyclerv"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/btnSingen"
|
||||||
|
app:layout_constraintVertical_bias="1.0" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
18
app/src/main/res/layout/recycler_item.xml
Normal file
18
app/src/main/res/layout/recycler_item.xml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?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"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_mode"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:text="TextView"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@@ -7,7 +7,7 @@ buildscript {
|
|||||||
|
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.5.1'
|
classpath 'com.android.tools.build:gradle:3.6.3'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
#Wed Apr 15 23:02:08 CEST 2020
|
#Sun Apr 26 20:33:59 CEST 2020
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
|
||||||
|
Reference in New Issue
Block a user