Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4f34f32ac |
No files matched your search
@@ -25,7 +25,6 @@ android {
|
|||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
namespace 'com.example.greenwatch'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -36,10 +35,4 @@ dependencies {
|
|||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
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,15 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.example.greenwatch">
|
||||||
|
|
||||||
<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-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<uses-feature android:name="android.hardware.camera"/>
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
@@ -26,9 +20,6 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name=".KameraAktivitaet" />
|
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -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,56 @@
|
|||||||
package com.example.greenwatch;
|
package com.example.greenwatch;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.app.ActivityCompat;
|
|
||||||
import androidx.core.content.ContextCompat;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import java.net.SocketException;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
private static final int RECHTEANFORDERUNG_KAMERA = 10;
|
WifiCommunication communication; //Member WifiCommunication
|
||||||
|
TextView tvReceivedData; //Test Textview um empfangene Daten anzuzeigen -> Gegen finale Textview in der Anzeige austauschen
|
||||||
|
//ToDo: Falls finale Textview zum Anzeigen der Nachricht anders heißt, muss das in der Klasse WifiCommunication.java angepasst werden!
|
||||||
|
// Wo anpassen: Receive Thread, Zeile 58
|
||||||
|
private EditText etSendMessage; //Test Edittext um eine Nachricht zu senden -> gegen Nachricht von den Sensoren austauschen
|
||||||
|
private Button btnSend; //Test Sendebutton
|
||||||
|
|
||||||
|
private String sendmsg = "default";
|
||||||
|
|
||||||
|
@SuppressLint("MissingInflatedId")
|
||||||
@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);
|
||||||
Button kameraStarten = findViewById(R.id.button_camera);
|
|
||||||
kameraStarten.setOnClickListener(v -> {
|
xmlToJava(); //Funktionsaufruf, wo die Testbuttons etc angelegt sind
|
||||||
if (istZugriffAufKameraErlaubt()) {
|
|
||||||
starteKameraAktivitaet();
|
|
||||||
} else {
|
|
||||||
zugriffAufKameraAnfordern();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean istZugriffAufKameraErlaubt() {
|
public void xmlToJava(){
|
||||||
return ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
|
tvReceivedData = findViewById(R.id.tvRecTxt); //Test Textview
|
||||||
|
etSendMessage = findViewById(R.id.sendMessage); //Test Nachricht
|
||||||
|
btnSend = findViewById(R.id.btnSend); //Test Sendebefehl
|
||||||
}
|
}
|
||||||
|
|
||||||
private void zugriffAufKameraAnfordern() {
|
public void onClickSend(View view) throws SocketException{ //ToDo: Sendebefehl mit boolscher Variable lösen --> wo setzen?
|
||||||
ActivityCompat.requestPermissions(this,new String[]{android.Manifest.permission.CAMERA}, RECHTEANFORDERUNG_KAMERA);
|
sendmsg = etSendMessage.getText().toString(); //ToDo: hier String von Sensoren übergeben
|
||||||
|
communication.setMessage(sendmsg, true); //übergibt zu sendenden String und setzt die entscheidende Boolsche Variable fürs Senden
|
||||||
}
|
}
|
||||||
|
|
||||||
private void starteKameraAktivitaet() {
|
@Override
|
||||||
startActivity(new Intent(this, KameraAktivitaet.class));
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
//Erstellen des Members
|
||||||
|
communication = new WifiCommunication(MainActivity.this, MainActivity.this, 1234);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
//schließt socket
|
||||||
|
communication.stopCommunication();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
package com.example.greenwatch;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.DatagramPacket;
|
||||||
|
import java.net.DatagramSocket;
|
||||||
|
import java.net.Inet4Address;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
|
||||||
|
public class WifiCommunication {
|
||||||
|
private final MainActivity mainActivity;
|
||||||
|
private final InetAddress address;
|
||||||
|
private final int port;
|
||||||
|
private final Context context;
|
||||||
|
private boolean newMsg;
|
||||||
|
private String rxString;
|
||||||
|
private String sendMsg;
|
||||||
|
//private String sendMsg = "default";
|
||||||
|
private final DatagramSocket socket;
|
||||||
|
volatile private boolean running;
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
public WifiCommunication(MainActivity mainActivity, Context context, int port) {
|
||||||
|
this.mainActivity = mainActivity;
|
||||||
|
this.port = port;
|
||||||
|
this.context = context;
|
||||||
|
try {
|
||||||
|
socket = new DatagramSocket(this.port);
|
||||||
|
socket.setBroadcast(true);
|
||||||
|
address = InetAddress.getByName("255.255.255.255");
|
||||||
|
running = true;
|
||||||
|
new ReceiveThread().start();
|
||||||
|
new SendThread().start();
|
||||||
|
} catch (SocketException | UnknownHostException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
mainActivity.runOnUiThread(() -> Toast.makeText(context,"Communication running", Toast.LENGTH_SHORT).show());
|
||||||
|
}
|
||||||
|
private class ReceiveThread extends Thread {
|
||||||
|
private String rxString = "";
|
||||||
|
private String previousRxString = "";
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
do {
|
||||||
|
|
||||||
|
byte[] rxBuffer = new byte[1024];
|
||||||
|
DatagramPacket packet = new DatagramPacket(rxBuffer, rxBuffer.length);
|
||||||
|
socket.receive(packet);
|
||||||
|
rxString = new String(packet.getData(), 0, packet.getLength());
|
||||||
|
|
||||||
|
if(!previousRxString.equals(rxString))
|
||||||
|
mainActivity.runOnUiThread(() -> mainActivity.tvReceivedData.setText(rxString));
|
||||||
|
|
||||||
|
previousRxString = rxString;
|
||||||
|
|
||||||
|
} while (running);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String showMessage(){
|
||||||
|
return rxString;
|
||||||
|
}
|
||||||
|
public void setMessage(String message, boolean newMsg){
|
||||||
|
this.sendMsg=message;
|
||||||
|
this.newMsg = newMsg;
|
||||||
|
}
|
||||||
|
private class SendThread extends Thread {
|
||||||
|
private int tmpCnt = 0;
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
do {
|
||||||
|
|
||||||
|
if(newMsg == true)
|
||||||
|
{
|
||||||
|
newMsg = false;
|
||||||
|
|
||||||
|
String txString = getLocalIpAddress() + " sends. #" + tmpCnt++ + sendMsg;
|
||||||
|
byte[] txBuffer = txString.getBytes();
|
||||||
|
|
||||||
|
DatagramPacket txPacket = new DatagramPacket(txBuffer, txBuffer.length, address, port);
|
||||||
|
|
||||||
|
for(int i = 0; i < 20; i++) {
|
||||||
|
socket.send(txPacket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (running);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static String getLocalIpAddress() {
|
||||||
|
try {
|
||||||
|
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
|
||||||
|
NetworkInterface networkInterface = (NetworkInterface) ((Enumeration<?>) en).nextElement();
|
||||||
|
for (Enumeration<InetAddress> addresses = networkInterface.getInetAddresses(); addresses.hasMoreElements();) {
|
||||||
|
InetAddress inetAddress = addresses.nextElement();
|
||||||
|
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
|
||||||
|
return inetAddress.getHostAddress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SocketException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public void stopCommunication() {
|
||||||
|
running = false;
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
<?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=".KameraAktivitaet">
|
|
||||||
|
|
||||||
<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:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/luminanz"
|
|
||||||
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>
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
@@ -6,17 +6,31 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<Button
|
<TextView
|
||||||
android:id="@+id/button_camera"
|
android:id="@+id/tvRecTxt"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Kamera starten"
|
android:text="Received Message"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintTop_toBottomOf="@id/sendMessage"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintStart_toStartOf="parent"/>
|
||||||
app:layout_constraintHorizontal_bias="0.129"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
app:layout_constraintVertical_bias="0.931" />
|
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/sendMessage"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:ems="10"
|
||||||
|
android:inputType="textPersonName"
|
||||||
|
android:text="Send Message"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnSend"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Send"
|
||||||
|
android:onClick="onClickSend"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/sendMessage"/>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</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.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
plugins {
|
plugins {
|
||||||
id 'com.android.application' version '8.0.0' apply false
|
id 'com.android.application' version '7.1.3' apply false
|
||||||
id 'com.android.library' version '8.0.0' apply false
|
id 'com.android.library' version '7.1.3' apply false
|
||||||
}
|
}
|
||||||
|
|
||||||
task clean(type: Delete) {
|
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
|
# 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,
|
# resources declared in the library itself and none from the library's dependencies,
|
||||||
# thereby reducing the size of the R class for that library
|
# thereby reducing the size of the R class for that library
|
||||||
android.nonTransitiveRClass=true
|
android.nonTransitiveRClass=true
|
||||||
android.defaults.buildfeatures.buildconfig=true
|
|
||||||
android.nonFinalResIds=false
|
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#Thu May 11 14:50:16 CEST 2023
|
#Thu May 11 14:50:16 CEST 2023
|
||||||
distributionBase=GRADLE_USER_HOME
|
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
|
distributionPath=wrapper/dists
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
Reference in new issue
Block a user