Compare commits
2 Commits
AppVersion
...
crop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2078d91dd | ||
|
|
b9a669e5e5 |
3
.idea/misc.xml
generated
Normal file
3
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,3 @@
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -96,5 +96,6 @@ dependencies {
|
||||
// Barcode scanner
|
||||
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
|
||||
|
||||
|
||||
// cropping
|
||||
implementation 'com.github.yalantis:ucrop:2.2.6'
|
||||
}
|
||||
7
app/proguard-rules.pro
vendored
7
app/proguard-rules.pro
vendored
@@ -18,4 +18,9 @@
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
# ucrop
|
||||
-dontwarn com.yalantis.ucrop**
|
||||
-keep class com.yalantis.ucrop** { *; }
|
||||
-keep interface com.yalantis.ucrop** { *; }
|
||||
@@ -42,6 +42,11 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.yalantis.ucrop.UCropActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -2,13 +2,13 @@ package com.example.hposregistration.ui.fragments.registration
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.app.Activity.RESULT_OK
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -16,12 +16,14 @@ import android.widget.ImageView
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import com.bumptech.glide.Glide
|
||||
import com.example.hposregistration.data.user.UserData
|
||||
import com.example.hposregistration.ui.viewmodels.RegistrationViewModel
|
||||
import com.yalantis.ucrop.UCrop
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hposregistration.databinding.FragmentCaptureUserImageBinding
|
||||
import java.io.File
|
||||
@@ -82,7 +84,7 @@ class CaptureUserImageFragment : Fragment() {
|
||||
|
||||
private fun setupCameraLauncher() {
|
||||
cameraLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK && result.data != null) {
|
||||
if (result.resultCode == RESULT_OK && result.data != null) {
|
||||
val thumbnail: Bitmap = result.data!!.extras!!.get("data") as Bitmap
|
||||
val uri: Uri = saveImageToInternalStorage(thumbnail)
|
||||
uri.let {
|
||||
@@ -122,9 +124,42 @@ class CaptureUserImageFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun submitImage(uri: Uri) {
|
||||
userData.userImage = uri.toString()
|
||||
viewModel.insert(userData)
|
||||
navigate()
|
||||
|
||||
val cropLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK && result.data != null) {
|
||||
val resultUri: Uri? = UCrop.getOutput(result.data!!)
|
||||
binding.userImage.loadImageFromUri(Uri.parse(resultUri.toString()))
|
||||
} else if (result.resultCode == UCrop.RESULT_ERROR) {
|
||||
val cropError: Throwable? = UCrop.getError(result.data!!)
|
||||
}
|
||||
}
|
||||
|
||||
// val cropIntent: Intent = // Create your crop intent here
|
||||
// cropLauncher.launch(cropIntent)
|
||||
|
||||
|
||||
// userData.userImage = uri.toString()
|
||||
// viewModel.insert(userData)
|
||||
// navigate()
|
||||
var sourceUri = uri
|
||||
var destinationUri = uri
|
||||
val maxWidth = 160
|
||||
val maxHeight = 90
|
||||
|
||||
// val context = getContext().getA
|
||||
UCrop.of(sourceUri, destinationUri)
|
||||
.withAspectRatio(9F, 16F)
|
||||
.withMaxResultSize(maxWidth, maxHeight)
|
||||
.start(requireActivity())
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
|
||||
val resultUri: Uri? = data?.let { UCrop.getOutput(it) }
|
||||
binding.userImage.loadImageFromUri(Uri.parse(resultUri.toString()))
|
||||
} else if (resultCode == UCrop.RESULT_ERROR) {
|
||||
val cropError: Throwable? = data?.let { UCrop.getError(it) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun navigate() {
|
||||
@@ -177,14 +212,14 @@ class CaptureUserImageFragment : Fragment() {
|
||||
requestPermissionLauncher.launch(permissions)
|
||||
}
|
||||
|
||||
private fun ImageView.loadImageFromUri(uri: Uri) {
|
||||
Glide.with(this)
|
||||
.load(uri)
|
||||
.into(this)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
|
||||
private fun ImageView.loadImageFromUri(uri: Uri) {
|
||||
Glide.with(this)
|
||||
.load(uri)
|
||||
.into(this)
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ dependencyResolutionManagement {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven {url "https://jitpack.io"}
|
||||
}
|
||||
}
|
||||
rootProject.name = "HPOS Registration"
|
||||
|
||||
Reference in New Issue
Block a user