diff --git a/EasyCameraAndGallery/build.gradle b/EasyCameraAndGallery/build.gradle index 1cb06a7..cb6026c 100644 --- a/EasyCameraAndGallery/build.gradle +++ b/EasyCameraAndGallery/build.gradle @@ -5,11 +5,11 @@ plugins { } android { - compileSdk 32 + compileSdk 34 defaultConfig { minSdk 21 - targetSdk 32 + targetSdk 34 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" @@ -31,26 +31,26 @@ android { buildFeatures { viewBinding true } + namespace 'dev.ahrsoft.easycameraandgallery' } dependencies { - implementation 'androidx.core:core-ktx:1.8.0' - implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'com.google.android.material:material:1.6.1' + implementation 'androidx.core:core-ktx:1.13.1' + implementation 'androidx.appcompat:appcompat:1.7.0' + implementation 'com.google.android.material:material:1.12.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - def camerax_version = "1.1.0" + def camerax_version = "1.3.4" implementation "androidx.camera:camera-core:${camerax_version}" implementation "androidx.camera:camera-camera2:${camerax_version}" implementation "androidx.camera:camera-lifecycle:${camerax_version}" - // implementation "androidx.camera:camera-video:${camerax_version}" new version implementation "androidx.camera:camera-view:${camerax_version}" implementation "androidx.camera:camera-extensions:${camerax_version}" - implementation 'com.github.bumptech.glide:glide:4.13.2' + implementation 'com.github.bumptech.glide:glide:4.16.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2' - implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1") + implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4") } \ No newline at end of file diff --git a/EasyCameraAndGallery/src/main/AndroidManifest.xml b/EasyCameraAndGallery/src/main/AndroidManifest.xml index f101c19..901fc21 100644 --- a/EasyCameraAndGallery/src/main/AndroidManifest.xml +++ b/EasyCameraAndGallery/src/main/AndroidManifest.xml @@ -1,11 +1,15 @@ + xmlns:tools="http://schemas.android.com/tools"> + - + android:maxSdkVersion="28" /> + + + diff --git a/EasyCameraAndGallery/src/main/java/dev/ahrsoft/easycameraandgallery/Constant.kt b/EasyCameraAndGallery/src/main/java/dev/ahrsoft/easycameraandgallery/Constant.kt index 7d6b773..50b424c 100644 --- a/EasyCameraAndGallery/src/main/java/dev/ahrsoft/easycameraandgallery/Constant.kt +++ b/EasyCameraAndGallery/src/main/java/dev/ahrsoft/easycameraandgallery/Constant.kt @@ -1,6 +1,8 @@ package dev.ahrsoft.easycameraandgallery import android.Manifest +import android.os.Build +import androidx.annotation.RequiresApi object Constant { const val TAG = "CameraAndGallery" @@ -13,5 +15,12 @@ object Constant { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE ) + + @RequiresApi(Build.VERSION_CODES.TIRAMISU) + val REQUIRED_PERMISSIONS_TIRAMISU = arrayOf( + Manifest.permission.CAMERA, + Manifest.permission.READ_MEDIA_IMAGES + ) + const val REQUEST_CODE_PERMISSIONS = 10 } \ No newline at end of file diff --git a/EasyCameraAndGallery/src/main/java/dev/ahrsoft/easycameraandgallery/camera/CameraActivity.kt b/EasyCameraAndGallery/src/main/java/dev/ahrsoft/easycameraandgallery/camera/CameraActivity.kt index ed2ebce..d11cc0e 100644 --- a/EasyCameraAndGallery/src/main/java/dev/ahrsoft/easycameraandgallery/camera/CameraActivity.kt +++ b/EasyCameraAndGallery/src/main/java/dev/ahrsoft/easycameraandgallery/camera/CameraActivity.kt @@ -4,25 +4,25 @@ import android.annotation.SuppressLint import android.app.Activity import android.app.AlertDialog import android.content.ContentValues -import android.content.DialogInterface import android.content.Intent import android.content.pm.PackageManager import android.media.MediaScannerConnection import android.net.Uri import android.os.Build +import android.os.Build.VERSION import android.os.Bundle import android.os.Environment import android.provider.MediaStore import android.provider.Settings -import android.util.Log import android.view.Surface.ROTATION_0 -import android.view.View import android.webkit.MimeTypeMap -import android.widget.Toast import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity -import androidx.camera.core.* +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.app.ActivityCompat import androidx.core.content.ContextCompat @@ -30,12 +30,11 @@ import androidx.core.net.toFile import androidx.core.view.isVisible import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager -import com.bumptech.glide.util.Util import dev.ahrsoft.easycameraandgallery.Constant.FILENAME import dev.ahrsoft.easycameraandgallery.Constant.PHOTO_EXTENSION import dev.ahrsoft.easycameraandgallery.Constant.REQUEST_CODE_PERMISSIONS import dev.ahrsoft.easycameraandgallery.Constant.REQUIRED_PERMISSIONS -import dev.ahrsoft.easycameraandgallery.Constant.TAG +import dev.ahrsoft.easycameraandgallery.Constant.REQUIRED_PERMISSIONS_TIRAMISU import dev.ahrsoft.easycameraandgallery.EasyCamera.IMAGE_RESULTS import dev.ahrsoft.easycameraandgallery.Flash import dev.ahrsoft.easycameraandgallery.OptionsCamera @@ -47,7 +46,7 @@ import dev.ahrsoft.easycameraandgallery.gallery.GalleryAdapter import dev.ahrsoft.easycameraandgallery.gallery.ImageModel import java.io.File import java.text.SimpleDateFormat -import java.util.* +import java.util.Locale class CameraActivity : AppCompatActivity(), GalleryAdapter.OnItemClickListener { @@ -74,18 +73,17 @@ class CameraActivity : AppCompatActivity(), GalleryAdapter.OnItemClickListener { binding = ActivityCameraBinding.inflate(layoutInflater) setContentView(binding.root) supportActionBar?.hide() - optionsCamera = (intent.getSerializableExtra("options") as? OptionsCamera)!! + optionsCamera = if (VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + intent.getSerializableExtra("options", OptionsCamera::class.java) as OptionsCamera + }else{ + intent.getSerializableExtra("options") as OptionsCamera + } viewModel = ViewModelProvider(this)[CameraViewModel::class.java] initCameraUI() initObserver() openCallback() } - override fun onRestart() { - super.onRestart() - initCameraUI() - } - private fun initCameraUI() { if (allPermissionsGranted()){ binding.cameraVfState.displayedChild = CameraFlipperState.SHOW_CAMERA.state @@ -93,7 +91,7 @@ class CameraActivity : AppCompatActivity(), GalleryAdapter.OnItemClickListener { startCamera() viewModel.getAllPhoto(this) }else{ - ActivityCompat.requestPermissions(this, REQUIRED_PERMISSIONS, REQUEST_CODE_PERMISSIONS) + ActivityCompat.requestPermissions(this, if (VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) REQUIRED_PERMISSIONS_TIRAMISU else REQUIRED_PERMISSIONS, REQUEST_CODE_PERMISSIONS) } } @@ -244,7 +242,7 @@ class CameraActivity : AppCompatActivity(), GalleryAdapter.OnItemClickListener { outputDirectory = getOutputDirectory() var photoFile: File? = null val outputOptions: ImageCapture.OutputFileOptions = - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + if (VERSION.SDK_INT >= Build.VERSION_CODES.Q) { val contentValues = ContentValues().apply { put( MediaStore.MediaColumns.DISPLAY_NAME, SimpleDateFormat( @@ -276,7 +274,7 @@ class CameraActivity : AppCompatActivity(), GalleryAdapter.OnItemClickListener { ContextCompat.getMainExecutor(this), object : ImageCapture.OnImageSavedCallback { override fun onImageSaved(outputFileResults: ImageCapture.OutputFileResults) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q){ + if (VERSION.SDK_INT < Build.VERSION_CODES.Q){ outputFileResults.savedUri?.let { mediaScanner(it) } viewModel.addImage(outputFileResults.savedUri, photoFile) }else{ @@ -298,8 +296,16 @@ class CameraActivity : AppCompatActivity(), GalleryAdapter.OnItemClickListener { ) { _, _ -> } } - private fun allPermissionsGranted() = REQUIRED_PERMISSIONS.all { - ContextCompat.checkSelfPermission(baseContext, it) == PackageManager.PERMISSION_GRANTED + private fun allPermissionsGranted() : Boolean { + return if (VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + REQUIRED_PERMISSIONS_TIRAMISU.all { + ContextCompat.checkSelfPermission(baseContext, it) == PackageManager.PERMISSION_GRANTED + } + }else { + REQUIRED_PERMISSIONS.all { + ContextCompat.checkSelfPermission(baseContext, it) == PackageManager.PERMISSION_GRANTED + } + } } override fun onRequestPermissionsResult( diff --git a/EasyCameraAndGallery/src/main/java/dev/ahrsoft/easycameraandgallery/gallery/GalleryAdapter.kt b/EasyCameraAndGallery/src/main/java/dev/ahrsoft/easycameraandgallery/gallery/GalleryAdapter.kt index 94ade18..995e2e8 100644 --- a/EasyCameraAndGallery/src/main/java/dev/ahrsoft/easycameraandgallery/gallery/GalleryAdapter.kt +++ b/EasyCameraAndGallery/src/main/java/dev/ahrsoft/easycameraandgallery/gallery/GalleryAdapter.kt @@ -12,6 +12,7 @@ class GalleryAdapter(private val context : Context) : RecyclerView.Adapter? = null fun getGallery(imageList: List){ this.imageList = imageList + notifyDataSetChanged() } class GalleryHolder(private val binding: ImagePickerListCameraBinding) : RecyclerView.ViewHolder(binding.root){ diff --git a/app/build.gradle b/app/build.gradle index 64837fd..76b6583 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,12 +4,12 @@ plugins { } android { - compileSdk 32 + compileSdk 34 defaultConfig { applicationId "dev.ahrsoft.cameralibrary" minSdk 21 - targetSdk 32 + targetSdk 34 versionCode 1 versionName "0.5" @@ -32,17 +32,18 @@ android { buildFeatures { viewBinding true } + namespace 'dev.ahrsoft.cameralibrary' } dependencies { - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.appcompat:appcompat:1.3.0' - implementation 'com.google.android.material:material:1.4.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.core:core-ktx:1.13.1' + implementation 'androidx.appcompat:appcompat:1.7.0' + implementation 'com.google.android.material:material:1.12.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation project(path: ':EasyCameraAndGallery') testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7cf0980..5f31197 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools">