Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b208a1853a | ||
|
|
12697ab05a | ||
|
|
c2ad9c6847 | ||
|
|
a111765677 | ||
|
|
4c0c4416fc |
No files matched your search
@@ -25,7 +25,6 @@ android {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
namespace 'com.example.greenwatch'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -36,10 +35,4 @@ dependencies {
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||
|
||||
def camerax_version = "1.2.3"
|
||||
implementation "androidx.camera:camera-camera2:${camerax_version}"
|
||||
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
|
||||
implementation "androidx.camera:camera-view:${camerax_version}"
|
||||
|
||||
}
|
||||
@@ -1,14 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<uses-feature android:name="android.hardware.camera"/>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.greenwatch">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@@ -17,6 +9,9 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.GreenWatch">
|
||||
<activity
|
||||
android:name=".Beschleunigungssensor"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
@@ -26,9 +21,6 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".KameraAktivitaet" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -1,4 +1,188 @@
|
||||
package com.example.greenwatch;
|
||||
|
||||
public class Beschleunigungssensor {
|
||||
}
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
public class Beschleunigungssensor extends AppCompatActivity implements SensorEventListener{
|
||||
|
||||
private SensorManager bsmanager;
|
||||
private ArrayList<Float> Gesamt_be;
|
||||
private int sensorType = Sensor.TYPE_GYROSCOPE, zaehler_runde =0, listen_groesse = 500, kalibrieren, Offset_shared = 0, shared_merk, mittelwertsumme_shared;
|
||||
private Sensor sens, sensor_l;
|
||||
private float x_value = 0, y_value, z_value, Vorbesetzung = 0, gesamt_runde =0;
|
||||
private double Schwellwert = 0.15, mittelwertsumme = 0.0, Offset = 0.1;
|
||||
String Daten, Warnung, Zeitstempel, Array_shared;
|
||||
private final static String KEY_kalibirieren = "KEY_KALIBRIEREN_"+Beschleunigungssensor.class.getSimpleName();
|
||||
private final static String KEY_Gesamt_be = "KEY_GESAMT_BE_"+Beschleunigungssensor.class.getSimpleName();
|
||||
private final static String KEY_Offset = "KEY_OFFSET_"+Beschleunigungssensor.class.getSimpleName();
|
||||
private final static String KEY_Mittelwertsumme = "KEY_MITTELWERTSUMME_"+Beschleunigungssensor.class.getSimpleName();
|
||||
TextView Daten_Bsensor, Warnung_Bsensor, test;
|
||||
private boolean toggle = true, ts_setzen = true, start_messen;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_beschleunigungssensor);
|
||||
|
||||
Daten_Bsensor = (TextView) findViewById(R.id.DatenBsensor);
|
||||
Warnung_Bsensor = (TextView) findViewById(R.id.WarnungBsensor);
|
||||
test = (TextView) findViewById(R.id.test);
|
||||
|
||||
bsmanager = (SensorManager) getSystemService(SENSOR_SERVICE);
|
||||
if (bsmanager.getSensorList(Sensor.TYPE_GYROSCOPE).size() == 0) {
|
||||
sens = null;
|
||||
Daten = "kein B Sensor voranden";
|
||||
} else {
|
||||
sens = bsmanager.getSensorList(sensorType).get(0);
|
||||
}
|
||||
Gesamt_be = new ArrayList<Float>();
|
||||
for (int i = 0; i < listen_groesse ; i++){
|
||||
Gesamt_be.add(Vorbesetzung);
|
||||
}
|
||||
kalibrieren = 0;
|
||||
start_messen = false;
|
||||
}
|
||||
|
||||
public static String getTimestamp(){
|
||||
Long tslong = System.currentTimeMillis();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
Date date = new Date(tslong);
|
||||
String result = sdf.format(date);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("x=").append(event.values[0])//.append(event.timestamp)
|
||||
.append("\ny=").append(event.values[1])
|
||||
.append("\nz=").append(event.values[2]);
|
||||
Daten = sb.toString();
|
||||
Daten_Bsensor.setText(Daten);
|
||||
gesamt_runde = event.values[0] + event.values[1] + event.values[2];
|
||||
Gesamt_be.remove(zaehler_runde);
|
||||
Gesamt_be.add(zaehler_runde, gesamt_runde);
|
||||
mittelwertsumme = 0.0;
|
||||
|
||||
//Mittelwert des Arrays berechnen
|
||||
for (int i = 0; i < listen_groesse; i++){
|
||||
if (Gesamt_be.get(i) < 0){
|
||||
mittelwertsumme += (Gesamt_be.get(i) * (-1));
|
||||
}else {
|
||||
mittelwertsumme += Gesamt_be.get(i);
|
||||
}
|
||||
}
|
||||
mittelwertsumme = mittelwertsumme/listen_groesse;
|
||||
if (kalibrieren < listen_groesse){
|
||||
Offset = mittelwertsumme;
|
||||
kalibrieren++;
|
||||
}else {
|
||||
start_messen = true;
|
||||
}
|
||||
StringBuilder testsb = new StringBuilder();
|
||||
testsb.append(mittelwertsumme);
|
||||
String tests = testsb.toString();
|
||||
test.setText(tests);
|
||||
|
||||
if((mittelwertsumme > (Schwellwert+Offset) ) & (ts_setzen == true) &(start_messen == true)){
|
||||
Zeitstempel = getTimestamp();
|
||||
StringBuilder ts = new StringBuilder();
|
||||
ts.append(Zeitstempel)
|
||||
.append(", Gruppe3")
|
||||
.append(", An")
|
||||
.append(", Bewegung, ")
|
||||
.append(mittelwertsumme);
|
||||
Warnung = ts.toString();
|
||||
Warnung_Bsensor.setText(Warnung);
|
||||
ts_setzen = false;
|
||||
}else if((mittelwertsumme > (Schwellwert+Offset)) & (ts_setzen == false)){
|
||||
} else if ((mittelwertsumme < (Schwellwert+Offset)) & (ts_setzen == false)) {
|
||||
Warnung_Bsensor.setText("");
|
||||
ts_setzen = true;
|
||||
}
|
||||
|
||||
if (zaehler_runde < (listen_groesse -1)){
|
||||
zaehler_runde++;
|
||||
}else {
|
||||
zaehler_runde = 0;
|
||||
}
|
||||
}
|
||||
//mittelwertsumme ist kein int in diesem programm
|
||||
//shared prefenrences: bei Kippen speichern -> nochmal neu klalibrieren? -> eig ja, weil neuer Standort
|
||||
//Vorbelegung nicht nochmal neu vornehmen -> aus onCreate Funktion raus -> hilfsvariablen auch in shared preferences speichern
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (sens != null) {
|
||||
if (bsmanager.registerListener(this, sens, SensorManager.SENSOR_DELAY_GAME)) {
|
||||
Daten = "Wir haben uns beim Sensor angemeldet";
|
||||
} else {
|
||||
Daten = "Das anmelden hat nicht geklappt";
|
||||
}
|
||||
}
|
||||
//SharedPreferences p = getPreferences(Context.MODE_PRIVATE);
|
||||
//mittelwertsumme_shared = p.getInt(KEY_Mittelwertsumme, 0);
|
||||
//kalibrieren = p.getInt(KEY_kalibirieren, 0);
|
||||
//Offset_shared = p.getInt(KEY_Offset, 0 );
|
||||
//Array_shared = p.getString(KEY_Gesamt_be, "");
|
||||
|
||||
//mittelwertsumme = (double) mittelwertsumme_shared;
|
||||
//mittelwertsumme /= 1000000.0;
|
||||
|
||||
//Offset = (double) Offset_shared;
|
||||
//Offset /= 1000000.0;
|
||||
|
||||
//String zw[] = Array_shared.split(";", listen_groesse);
|
||||
|
||||
//if(shared_merk == 2){
|
||||
//for (int i=0; i<listen_groesse; i++){
|
||||
//float wert = Float.valueOf(zw[i]);
|
||||
//Gesamt_be.add(i, wert);
|
||||
//}}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPause () {
|
||||
super.onPause();
|
||||
if (sens != null) {
|
||||
bsmanager.unregisterListener(this, sens);
|
||||
}
|
||||
//shared_merk = 2;
|
||||
// Offset_shared = (int) (Offset * 1000000.0);
|
||||
//mittelwertsumme_shared = (int) (mittelwertsumme * 1000000.0);
|
||||
|
||||
//StringBuilder ar = new StringBuilder();
|
||||
//for (int z=0; z < listen_groesse; z++){
|
||||
//ar.append(Gesamt_be.get(z)).append(";");
|
||||
//}
|
||||
//Array_shared = ar.toString();
|
||||
|
||||
//SharedPreferences p = getPreferences(Context.MODE_PRIVATE);
|
||||
//SharedPreferences.Editor editor = p.edit();
|
||||
//editor.putInt(KEY_Mittelwertsumme, mittelwertsumme_shared);
|
||||
//editor.putInt(KEY_kalibirieren, kalibrieren);
|
||||
//editor.putInt(KEY_Offset, Offset_shared);
|
||||
//editor.putString(KEY_Gesamt_be, Array_shared);
|
||||
//editor.commit();
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package com.example.greenwatch;
|
||||
|
||||
import android.graphics.ImageFormat;
|
||||
import android.media.Image;
|
||||
import android.os.Bundle;
|
||||
import android.util.Size;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.camera.core.CameraSelector;
|
||||
import androidx.camera.core.ImageAnalysis;
|
||||
import androidx.camera.core.Preview;
|
||||
import androidx.camera.lifecycle.ProcessCameraProvider;
|
||||
import androidx.camera.view.PreviewView;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class KameraAktivitaet extends AppCompatActivity {
|
||||
private PreviewView previewView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_demo_kamera2_nebenaktivitaet);
|
||||
previewView = findViewById(R.id.previewView);
|
||||
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(this);
|
||||
cameraProviderFuture.addListener(() -> {
|
||||
try {
|
||||
bindImageAnalysis(cameraProviderFuture.get());
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, ContextCompat.getMainExecutor(this));
|
||||
}
|
||||
|
||||
private void bindImageAnalysis(ProcessCameraProvider cameraProvider) {
|
||||
ImageAnalysis.Builder builder = new ImageAnalysis.Builder();
|
||||
builder.setTargetResolution(new Size(640, 480));
|
||||
builder.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST);
|
||||
ImageAnalysis imageAnalysis = builder.build();
|
||||
imageAnalysis.setAnalyzer(
|
||||
ContextCompat.getMainExecutor(this),
|
||||
imageProxy -> {
|
||||
int imageFormat = imageProxy.getFormat();
|
||||
if (imageFormat == ImageFormat.YUV_420_888) {
|
||||
Image image = imageProxy.getImage();
|
||||
}
|
||||
imageProxy.close();
|
||||
});
|
||||
|
||||
Preview preview = new Preview.Builder().build();
|
||||
CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build();
|
||||
preview.setSurfaceProvider(previewView.getSurfaceProvider());
|
||||
cameraProvider.bindToLifecycle(this, cameraSelector, imageAnalysis, preview);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,41 @@
|
||||
package com.example.greenwatch;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private static final int RECHTEANFORDERUNG_KAMERA = 10;
|
||||
|
||||
private Button Beschleunigungssensor;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
Button kameraStarten = findViewById(R.id.button_camera);
|
||||
kameraStarten.setOnClickListener(v -> {
|
||||
if (istZugriffAufKameraErlaubt()) {
|
||||
starteKameraAktivitaet();
|
||||
} else {
|
||||
zugriffAufKameraAnfordern();
|
||||
|
||||
final Button Beschleunigungssensor = (Button) findViewById(R.id.beschleunigungssensor);
|
||||
Beschleunigungssensor.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(MainActivity.this, Beschleunigungssensor.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean istZugriffAufKameraErlaubt() {
|
||||
return ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
private void zugriffAufKameraAnfordern() {
|
||||
ActivityCompat.requestPermissions(this,new String[]{android.Manifest.permission.CAMERA}, RECHTEANFORDERUNG_KAMERA);
|
||||
}
|
||||
|
||||
private void starteKameraAktivitaet() {
|
||||
startActivity(new Intent(this, KameraAktivitaet.class));
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
}
|
||||
+12
-21
@@ -4,38 +4,29 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".KameraAktivitaet">
|
||||
tools:context=".Beschleunigungssensor">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/erklaerung">
|
||||
<androidx.camera.view.PreviewView
|
||||
android:id="@+id/previewView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
</FrameLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/alarm"
|
||||
android:id="@+id/DatenBsensor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/luminanz"
|
||||
android:id="@+id/WarnungBsensor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:textSize="100sp"
|
||||
android:textColor="#9999ff"/>
|
||||
</LinearLayout>
|
||||
android:layout_height="wrap_content"
|
||||
android:text="" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/test"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="" />
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -6,17 +6,42 @@
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_camera"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Kamera starten"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.129"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.931" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView"
|
||||
tools:layout_editor_absoluteX="171dp"
|
||||
tools:layout_editor_absoluteY="186dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/beschleunigungssensor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Beschleunigungssensor" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/aufnahme"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Aufnahme Start" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/wiedergabe"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Wiedergabe" />
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id 'com.android.application' version '8.0.0' apply false
|
||||
id 'com.android.library' version '8.0.0' apply false
|
||||
id 'com.android.application' version '7.1.3' apply false
|
||||
id 'com.android.library' version '7.1.3' apply false
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
|
||||
+1
-3
@@ -18,6 +18,4 @@ android.useAndroidX=true
|
||||
# Enables namespacing of each library's R class so that its R class includes only the
|
||||
# resources declared in the library itself and none from the library's dependencies,
|
||||
# thereby reducing the size of the R class for that library
|
||||
android.nonTransitiveRClass=true
|
||||
android.defaults.buildfeatures.buildconfig=true
|
||||
android.nonFinalResIds=false
|
||||
android.nonTransitiveRClass=true
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#Thu May 11 14:50:16 CEST 2023
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
Reference in new issue
Block a user