commit c06968c582bf28cdbc01adde30691ca4c301beab Author: Captain Arepa Date: Fri May 17 08:51:52 2024 -0400 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..b268ef3 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..0897082 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0ad17cb --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..b277167 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,51 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace 'com.example.cameraxtestappjava' + compileSdk 34 + + defaultConfig { + applicationId "com.example.cameraxtestappjava" + minSdk 23 + targetSdk 34 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildFeatures { + viewBinding true + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation libs.appcompat + implementation libs.material + implementation libs.activity + implementation libs.constraintlayout + + implementation libs.camera.core + implementation libs.camera.camera2 + implementation libs.camera.lifecycle + implementation libs.camera.view + implementation libs.camera.extensions + + testImplementation libs.junit + androidTestImplementation libs.ext.junit + androidTestImplementation libs.espresso.core +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/cameraxtestappjava/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/cameraxtestappjava/ExampleInstrumentedTest.java new file mode 100644 index 0000000..ddb2091 --- /dev/null +++ b/app/src/androidTest/java/com/example/cameraxtestappjava/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.cameraxtestappjava; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.cameraxtestappjava", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..b62109d --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/cameraxtestappjava/MainActivity.java b/app/src/main/java/com/example/cameraxtestappjava/MainActivity.java new file mode 100644 index 0000000..7cb2610 --- /dev/null +++ b/app/src/main/java/com/example/cameraxtestappjava/MainActivity.java @@ -0,0 +1,133 @@ +package com.example.cameraxtestappjava; + +import android.content.ContentValues; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.provider.MediaStore; +import android.util.Log; +import android.widget.Toast; + +import androidx.activity.EdgeToEdge; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.camera.core.CameraSelector; +import androidx.camera.core.ImageCapture; +import androidx.camera.core.ImageCaptureException; +import androidx.camera.core.Preview; +import androidx.camera.lifecycle.ProcessCameraProvider; +import androidx.core.content.ContextCompat; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import com.example.cameraxtestappjava.databinding.ActivityMainBinding; +import com.google.common.util.concurrent.ListenableFuture; + +import java.util.concurrent.ExecutionException; + +public class MainActivity extends AppCompatActivity { + + ProcessCameraProvider cameraProvider; + ImageCapture imageCapture; + ImageCapture.OutputFileOptions outputFileOptions; + ListenableFuture cameraProviderFuture; + ContentValues contentValues; + String fileName; + Uri tempFileUri; + + ActivityMainBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + + binding = ActivityMainBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + + setListeners(); + setUpCamera(); + + + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + } + + private void setListeners() { + binding.btnTakePicture.setOnClickListener(v -> capturePhoto()); + } + + private void capturePhoto() { + if (imageCapture == null) return; + + fileName = System.currentTimeMillis() + ""; + + outputFileOptions = getOutputFileOptions(fileName); + + imageCapture.takePicture(outputFileOptions, ContextCompat.getMainExecutor(this), new ImageCapture.OnImageSavedCallback() { + @Override + public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) { + tempFileUri = outputFileResults.getSavedUri(); + Toast.makeText(MainActivity.this, "Image saved! " + tempFileUri, Toast.LENGTH_LONG).show(); + } + + @Override + public void onError(@NonNull ImageCaptureException exception) { + Toast.makeText(MainActivity.this, "Image Not Saved " + exception.getMessage(), Toast.LENGTH_LONG).show(); + } + }); + + } + + @NonNull + private ImageCapture.OutputFileOptions getOutputFileOptions(String name) { + contentValues = new ContentValues(); + contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, name); + contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg"); + + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { + contentValues.put(MediaStore.Images.Media.RELATIVE_PATH, "Pictures/CameraXTestApp"); + } + + return new ImageCapture.OutputFileOptions.Builder( + getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues + ).build(); + } + + private void setUpCamera() { + cameraProviderFuture = ProcessCameraProvider.getInstance(this); + cameraProviderFuture.addListener(() -> { + try { + cameraProvider = cameraProviderFuture.get(); + startSegPassCamera(cameraProvider); + } catch (ExecutionException | InterruptedException e) { + throw new RuntimeException(e); + } + + }, ContextCompat.getMainExecutor(this)); // por parametro + } + + private void startSegPassCamera(ProcessCameraProvider cameraProvider) { + Log.d("TAGTAG", "UEEEP"); + CameraSelector cameraSelector = CameraSelector.DEFAULT_FRONT_CAMERA; + + Preview preview = new Preview.Builder().build(); + preview.setSurfaceProvider(binding.pvViewfinder.getSurfaceProvider()); + + imageCapture = new ImageCapture.Builder().build(); + + try { + cameraProvider.unbindAll(); + + cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageCapture); + + } catch (Exception e) { + e.printStackTrace(); + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/cameraxtestappjava/camera/SegPassCamera.java b/app/src/main/java/com/example/cameraxtestappjava/camera/SegPassCamera.java new file mode 100644 index 0000000..7a6f7c1 --- /dev/null +++ b/app/src/main/java/com/example/cameraxtestappjava/camera/SegPassCamera.java @@ -0,0 +1,84 @@ +package com.example.cameraxtestappjava.camera; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.widget.FrameLayout; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatButton; +import androidx.camera.view.PreviewView; + +import com.example.cameraxtestappjava.R; + +import java.util.concurrent.Executor; + +public class SegPassCamera extends FrameLayout { + + private final View rootView; + private PreviewView cameraViewFinder; + private AppCompatButton takePictureBtn; + + private Executor mExecutor; + private Context mContext; + + public SegPassCamera(@NonNull Context context) { + super(context); + rootView = inflate(context, R.layout.segpass_camera, this); + initComponents(); + } + + public SegPassCamera(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + // Aqui van los estilos y todo eso si se requiere + rootView = inflate(context, R.layout.segpass_camera, this); + initComponents(); + } + + public SegPassCamera(@NonNull Context context, Executor executor) { + super(context); + rootView = inflate(context, R.layout.segpass_camera, this); + initEnvironment(context, executor); + initComponents(); + } + + private void initEnvironment(@NonNull Context context, Executor executor) { + mExecutor = executor; + mContext = context; + } + + public SegPassCamera(@NonNull Context context, @Nullable AttributeSet attrs, Executor executor) { + super(context, attrs); + // Aqui van los estilos y todo eso si se requiere + rootView = inflate(context, R.layout.segpass_camera, this); + initEnvironment(context, executor); + initComponents(); + } + + private void initComponents() { + findIds(); + initializeCamera(); + initializeListeners(); + } + + private void findIds() { + cameraViewFinder = findViewById(R.id.pvViewfinder); + takePictureBtn = findViewById(R.id.btnTakePicture); + } + + private void initializeCamera() { + } + + private void initializeListeners() { + + } + + private void setUpCamera() { + + } + + private void startSegPassCamera() { + + } +} diff --git a/app/src/main/java/com/example/cameraxtestappjava/camera/SegPassCameraDelegate.java b/app/src/main/java/com/example/cameraxtestappjava/camera/SegPassCameraDelegate.java new file mode 100644 index 0000000..ca89753 --- /dev/null +++ b/app/src/main/java/com/example/cameraxtestappjava/camera/SegPassCameraDelegate.java @@ -0,0 +1,9 @@ +package com.example.cameraxtestappjava.camera; + +interface SegPassCameraDelegate { + + void onPictureTakenSuccess(); + void onPictureTakenFailError(); + + +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..8350491 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/picture_preview.xml b/app/src/main/res/layout/picture_preview.xml new file mode 100644 index 0000000..77d9ef6 --- /dev/null +++ b/app/src/main/res/layout/picture_preview.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/segpass_camera.xml b/app/src/main/res/layout/segpass_camera.xml new file mode 100644 index 0000000..80c0922 --- /dev/null +++ b/app/src/main/res/layout/segpass_camera.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml new file mode 100644 index 0000000..49ccf1f --- /dev/null +++ b/app/src/main/res/values-night/themes.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..c8524cd --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,5 @@ + + + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..ded705a --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + CameraXTestAppJava + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..9dce478 --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,9 @@ + + + + +