@@ -29,6 +29,9 @@ | |||
<activity | |||
android:name=".AccelerometerActivity" | |||
android:exported="false" /> | |||
<activity | |||
android:name=".VideoPreviewActivity" | |||
android:exported="false" /> | |||
<activity | |||
android:name=".MainActivity" | |||
android:exported="true"> |
@@ -27,6 +27,7 @@ public class MainActivity extends AppCompatActivity { | |||
private Button audiodetectionAndAccelerometerButton; | |||
private Button videodetectionAndAccelerometerButton; | |||
private Button connectionButton; | |||
private Button prewview_kamera; | |||
private MainActivityViewModel mMainActivityViewModel; | |||
@Override | |||
@@ -40,6 +41,7 @@ public class MainActivity extends AppCompatActivity { | |||
audiodetectionAndAccelerometerButton = (Button) findViewById(R.id.audiodetectionAndAccelerometerButton); | |||
videodetectionAndAccelerometerButton = (Button) findViewById(R.id.videodetectionAndAccelerometerButton); | |||
connectionButton = (Button) findViewById(R.id.connectionButton); | |||
prewview_kamera = (Button) findViewById(R.id.preview_kamera); | |||
RecyclerView deviceListRecyclerView = findViewById(R.id.deviceListRecyclerView); | |||
deviceListRecyclerView.setLayoutManager(new LinearLayoutManager(this)); | |||
@@ -84,6 +86,17 @@ public class MainActivity extends AppCompatActivity { | |||
} | |||
}); | |||
prewview_kamera.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (mMainActivityViewModel.isCameraAccessAllowed(MainActivity.this)) { | |||
openVideoPrewvoewActivity(); | |||
} | |||
else { | |||
mMainActivityViewModel.accessRequestCamera(MainActivity.this); | |||
} | |||
} | |||
}); | |||
audiodetectionButton.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
@@ -131,6 +144,10 @@ public class MainActivity extends AppCompatActivity { | |||
} | |||
}); | |||
} | |||
public void openVideoPrewvoewActivity() { | |||
Intent intent = new Intent(this, VideoPreviewActivity.class); | |||
startActivity(intent); | |||
} | |||
public void openAudiodetectionActivity(){ | |||
Intent intent = new Intent(this, AudiodetectionActivity.class); | |||
startActivity(intent); |
@@ -0,0 +1,61 @@ | |||
package com.example.greenwatch; | |||
import android.os.Bundle; | |||
import android.util.Size; | |||
import android.widget.Button; | |||
import androidx.appcompat.app.AppCompatActivity; | |||
import androidx.camera.core.CameraSelector; | |||
import androidx.camera.core.ImageAnalysis; | |||
import androidx.camera.core.ImageProxy; | |||
import androidx.camera.core.Preview; | |||
import androidx.camera.lifecycle.ProcessCameraProvider; | |||
import androidx.camera.view.PreviewView; | |||
import androidx.core.content.ContextCompat; | |||
import androidx.lifecycle.LifecycleOwner; | |||
import com.google.common.util.concurrent.ListenableFuture; | |||
import java.util.concurrent.ExecutionException; | |||
public class VideoPreviewActivity extends AppCompatActivity { | |||
private Button backToMainActivity; | |||
private PreviewView previewView; | |||
@Override | |||
protected void onCreate(Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_preview_kamera); | |||
backToMainActivity = (Button) findViewById(R.id.videodetectorBackToMainActivity); | |||
previewView = findViewById(R.id.previewView); | |||
backToMainActivity.setOnClickListener(v -> finish()); | |||
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::close); | |||
Preview preview = new Preview.Builder().build(); | |||
CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build(); | |||
preview.setSurfaceProvider(previewView.getSurfaceProvider()); | |||
cameraProvider.bindToLifecycle((LifecycleOwner) this, cameraSelector, imageAnalysis, preview); | |||
} | |||
} |
@@ -8,6 +8,12 @@ | |||
android:padding="10dp" | |||
tools:context=".MainActivity"> | |||
<Button | |||
android:id="@+id/preview_kamera" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="PrewView Kamera" /> | |||
<androidx.recyclerview.widget.RecyclerView | |||
android:id="@+id/alarmHistoryListRecyclerView" | |||
android:layout_width="match_parent" | |||
@@ -22,6 +28,7 @@ | |||
android:layout_height="match_parent" | |||
android:layout_weight="3" | |||
tools:listitem="@layout/device_item"> | |||
</androidx.recyclerview.widget.RecyclerView> | |||
<LinearLayout |
@@ -0,0 +1,31 @@ | |||
<?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=""> | |||
<Button | |||
android:id="@+id/videodetectorBackToMainActivity" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:text="Back to MainActivity"> | |||
</Button> | |||
<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"/> | |||
</androidx.constraintlayout.widget.ConstraintLayout> |