converted views into fragments
This commit is contained in:
parent
500c40a125
commit
b881af0bcf
|
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
android:theme="@style/Theme.Dermy"
|
android:theme="@style/Theme.Dermy"
|
||||||
tools:targetApi="31" >
|
tools:targetApi="31" >
|
||||||
|
|
||||||
<activity android:name=".CameraActivity"
|
<activity android:name=".MainActivity"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
package xyz.r0r5chach.dermy;
|
||||||
|
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import xyz.r0r5chach.dermy.fragments.CameraFragment;
|
||||||
|
|
||||||
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
public static final int REQUEST_CAMERA_PERMISSION = 200;
|
||||||
|
|
||||||
|
public MainActivity() {
|
||||||
|
super(R.layout.activity_main);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
if (savedInstanceState == null) {
|
||||||
|
startCamera();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startCamera() {
|
||||||
|
getSupportFragmentManager().beginTransaction()
|
||||||
|
.setReorderingAllowed(true)
|
||||||
|
.add(R.id.fragment_container, CameraFragment.class, null)
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { //FIXME: deprecated listener fir request permissions
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
if (requestCode == REQUEST_CAMERA_PERMISSION) {
|
||||||
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
startCamera();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "Camera permission is required", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
package xyz.r0r5chach.dermy;
|
|
||||||
|
|
||||||
public class MapActivity {
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
package xyz.r0r5chach.dermy;
|
|
||||||
|
|
||||||
public class NearbyActivity {
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
package xyz.r0r5chach.dermy;
|
package xyz.r0r5chach.dermy.fragments;
|
||||||
|
|
||||||
|
import static xyz.r0r5chach.dermy.MainActivity.REQUEST_CAMERA_PERMISSION;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import androidx.camera.core.CameraSelector;
|
import androidx.camera.core.CameraSelector;
|
||||||
import androidx.camera.core.ImageCapture;
|
import androidx.camera.core.ImageCapture;
|
||||||
import androidx.camera.core.ImageCaptureException;
|
import androidx.camera.core.ImageCaptureException;
|
||||||
|
|
@ -15,38 +20,41 @@ import androidx.camera.lifecycle.ProcessCameraProvider;
|
||||||
import androidx.camera.view.PreviewView;
|
import androidx.camera.view.PreviewView;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class CameraActivity extends AppCompatActivity {
|
import xyz.r0r5chach.dermy.R;
|
||||||
private static final int REQUEST_CAMERA_PERMISSION = 200;
|
|
||||||
|
public class CameraFragment extends Fragment {
|
||||||
private PreviewView previewView;
|
private PreviewView previewView;
|
||||||
private ImageCapture imageCapture;
|
private ImageCapture imageCapture;
|
||||||
private ExecutorService cameraExecutor;
|
private ExecutorService cameraExecutor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
View view = inflater.inflate(R.layout.fragment_camera, container, false);
|
||||||
setContentView(R.layout.activity_main);
|
previewView = view.findViewById(R.id.camera_preview);
|
||||||
|
|
||||||
previewView = findViewById(R.id.previewView);
|
if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
|
||||||
Button captureButton = findViewById(R.id.captureButton);
|
|
||||||
|
|
||||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
|
|
||||||
startCamera();
|
startCamera();
|
||||||
} else {
|
} else {
|
||||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA_PERMISSION);
|
ActivityCompat.requestPermissions(requireActivity(), new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA_PERMISSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
captureButton.setOnClickListener(v -> takePhoto());
|
previewView.setOnClickListener(v -> takePhoto());
|
||||||
|
|
||||||
cameraExecutor = Executors.newSingleThreadExecutor();
|
cameraExecutor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startCamera() {
|
private void startCamera() {
|
||||||
ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(this);
|
ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(requireContext());
|
||||||
|
|
||||||
cameraProviderFuture.addListener(() -> {
|
cameraProviderFuture.addListener(() -> {
|
||||||
try {
|
try {
|
||||||
|
|
@ -55,7 +63,7 @@ public class CameraActivity extends AppCompatActivity {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(); //TODO: Replace with better logging
|
e.printStackTrace(); //TODO: Replace with better logging
|
||||||
}
|
}
|
||||||
}, ContextCompat.getMainExecutor(this));
|
}, ContextCompat.getMainExecutor(requireContext()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindPreview(@NonNull ProcessCameraProvider cameraProvider) {
|
private void bindPreview(@NonNull ProcessCameraProvider cameraProvider) {
|
||||||
|
|
@ -71,9 +79,9 @@ public class CameraActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void takePhoto() {
|
private void takePhoto() {
|
||||||
File photoFile = new File(getExternalFilesDir(null), System.currentTimeMillis() + ".jpg");
|
File photoFile = new File(requireContext().getExternalFilesDir(null), System.currentTimeMillis() + ".jpg");
|
||||||
ImageCapture.OutputFileOptions outputFileOptions = new ImageCapture.OutputFileOptions.Builder(photoFile).build();
|
ImageCapture.OutputFileOptions outputFileOptions = new ImageCapture.OutputFileOptions.Builder(photoFile).build();
|
||||||
imageCapture.takePicture(outputFileOptions, ContextCompat.getMainExecutor(this), new ImageCapture.OnImageSavedCallback() {
|
imageCapture.takePicture(outputFileOptions, ContextCompat.getMainExecutor(requireContext()), new ImageCapture.OnImageSavedCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
|
public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
|
||||||
//TODO: Add image path to bundle to pass onto next activity
|
//TODO: Add image path to bundle to pass onto next activity
|
||||||
|
|
@ -83,26 +91,14 @@ public class CameraActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onError(@NonNull ImageCaptureException exception) {
|
public void onError(@NonNull ImageCaptureException exception) {
|
||||||
exception.printStackTrace(); //TODO: Replace with better logging
|
exception.printStackTrace(); //TODO: Replace with better logging
|
||||||
Toast.makeText(CameraActivity.this, "Error saving photo: " + exception.getMessage(), Toast.LENGTH_SHORT).show();
|
Toast.makeText(requireContext(), "Error saving photo: " + exception.getMessage(), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
cameraExecutor.shutdown();
|
cameraExecutor.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
||||||
if (requestCode == REQUEST_CAMERA_PERMISSION) {
|
|
||||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
||||||
startCamera();
|
|
||||||
} else {
|
|
||||||
Toast.makeText(this, "Camera permission is required", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
package xyz.r0r5chach.dermy.fragments;
|
||||||
|
|
||||||
|
public class MapFragment {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
package xyz.r0r5chach.dermy.fragments;
|
||||||
|
|
||||||
|
public class NearbyFragment {
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package xyz.r0r5chach.dermy;
|
package xyz.r0r5chach.dermy.fragments;
|
||||||
|
|
||||||
public class PreferencesActivity {
|
public class PreferencesFragment {
|
||||||
//TODO: Disclaimers
|
//TODO: Disclaimers
|
||||||
//TODO: Useful Links
|
//TODO: Useful Links
|
||||||
//TODO: Export File
|
//TODO: Export File
|
||||||
|
|
@ -1,18 +1,12 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
<androidx.camera.view.PreviewView
|
|
||||||
android:id="@+id/previewView"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<Button
|
<androidx.fragment.app.FragmentContainerView
|
||||||
android:id="@+id/captureButton"
|
android:id="@+id/fragment_container"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center_horizontal|bottom"
|
android:name="xyz.r0r5chach.dermy.fragments.CameraFragment" />
|
||||||
android:text="@string/image_capture_button_text" />
|
|
||||||
</androidx.camera.view.PreviewView>
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<androidx.camera.view.PreviewView
|
||||||
|
android:id="@+id/camera_preview"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" >
|
||||||
|
</androidx.camera.view.PreviewView>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Loading…
Reference in New Issue