8 Commits
v1 ... v1.1

Author SHA1 Message Date
dd77dcfdf4 Add recycler data 2020-05-05 11:07:17 +02:00
0a417dbca2 Merge pull request 'Add Recyclerview' (#1) from recyclerview into master 2020-04-28 00:12:11 +02:00
48c4cfc121 Add recyclerview click listener 2020-04-27 20:19:00 +02:00
cdf9b5b155 Add recyclerview 2020-04-26 20:38:34 +02:00
9abc83001e Merge branch 'master' of https://git.schoffit.net/structix/janasRoboter 2020-04-26 19:26:02 +02:00
6307a68408 Update gitignore 2020-04-26 19:25:52 +02:00
282af39b48 Add comments 2020-04-18 20:00:07 +02:00
0f2e78b005 Add singen button 2020-04-18 19:42:09 +02:00
9 changed files with 201 additions and 10 deletions

1
.gitignore vendored
View File

@@ -13,3 +13,4 @@
.externalNativeBuild
.cxx
.idea
/app/release

View File

@@ -27,4 +27,5 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
}

View File

@@ -1,6 +1,10 @@
package com.janasroboter;
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.StrictMode;
import android.view.View;
@@ -10,46 +14,101 @@ import android.widget.Toast;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import static com.janasroboter.REST.URL;
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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.build());
// Netzwerk aktivieren
StrictMode.setThreadPolicy(new StrictMode
.ThreadPolicy
.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.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) {
// Fehlernachricht in String schreiben
String toast = "Obacht! Etwas ist schief gelaufen.";
try {
// Aufruf an den Mikrocontroller senden
REST.getString(URL + "/toggle");
// Erfolgsnachricht anpassen
toast = "Muster geändert.";
} catch (IOException e) {
e.printStackTrace();
}
// Nachricht auf dem Bildschirm ausgeben
Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
}
public void btnLos(View view) {
// Textfeld im Code verfügbar machen
EditText state = view.getRootView().findViewById(R.id.state);
// Zahl aus dem Textfeld auslesen
String nummer = state.getText().toString();
// Fehlernachricht in String schreiben
String toast = "Obacht! Etwas ist schief gelaufen.";
try {
// Aufruf mit Zahl an den Mikrocontroller senden
REST.getString(URL + "/togglearg?state=" + nummer);
// Erfolgsnachricht anpassen
toast = "Muster auf " + nummer + " gesetzt.";
} catch (IOException e) {
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();
}

View 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();
}
}

View File

@@ -17,6 +17,9 @@ public class REST {
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
* @param url the url string

View File

@@ -64,4 +64,36 @@
android:text="Nächstes Muster:"
app:layout_constraintStart_toStartOf="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>

View 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>

View File

@@ -7,7 +7,7 @@ buildscript {
}
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
// in the individual module build.gradle files

View File

@@ -1,6 +1,6 @@
#Wed Apr 15 23:02:08 CEST 2020
#Sun Apr 26 20:33:59 CEST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
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