mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-18 12:30:38 +01:00
implement contact Choose Photo function
This commit is contained in:
parent
d7ac1c8d72
commit
0e918349d5
@ -55,7 +55,7 @@ class ContactActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private var wasActivityInitialized = false
|
private var wasActivityInitialized = false
|
||||||
private var currentContactPhotoPath = ""
|
private var currentContactPhotoPath = ""
|
||||||
private var takePhotoPath = ""
|
private var getPhotoPath = ""
|
||||||
private var contact: Contact? = null
|
private var contact: Contact? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@ -157,8 +157,11 @@ class ContactActivity : SimpleActivity() {
|
|||||||
super.onActivityResult(requestCode, resultCode, resultData)
|
super.onActivityResult(requestCode, resultCode, resultData)
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
if (requestCode == INTENT_TAKE_PHOTO) {
|
if (requestCode == INTENT_TAKE_PHOTO) {
|
||||||
currentContactPhotoPath = takePhotoPath
|
updateContactPhoto(getPhotoPath)
|
||||||
updateContactPhoto(currentContactPhotoPath)
|
} else if (requestCode == INTENT_CHOOSE_PHOTO) {
|
||||||
|
val selectedUri = resultData?.data ?: return
|
||||||
|
val pathToUse = getRealPathFromURI(selectedUri) ?: selectedUri.toString()
|
||||||
|
updateContactPhoto(pathToUse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -439,13 +442,8 @@ class ContactActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun startTakePhotoIntent() {
|
private fun startTakePhotoIntent() {
|
||||||
val imagesFolder = File(filesDir, "images")
|
val file = getCachePhotoFile()
|
||||||
if (!imagesFolder.exists()) {
|
getPhotoPath = file.absolutePath
|
||||||
imagesFolder.mkdirs()
|
|
||||||
}
|
|
||||||
|
|
||||||
val file = File(imagesFolder, "Photo_${System.currentTimeMillis()}.jpg")
|
|
||||||
takePhotoPath = file.absolutePath
|
|
||||||
val uri = FileProvider.getUriForFile(this, "${BuildConfig.APPLICATION_ID}.provider", file)
|
val uri = FileProvider.getUriForFile(this, "${BuildConfig.APPLICATION_ID}.provider", file)
|
||||||
Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
|
Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
|
||||||
putExtra(MediaStore.EXTRA_OUTPUT, uri)
|
putExtra(MediaStore.EXTRA_OUTPUT, uri)
|
||||||
@ -458,7 +456,27 @@ class ContactActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun startChoosePhotoIntent() {
|
private fun startChoosePhotoIntent() {
|
||||||
|
val file = getCachePhotoFile()
|
||||||
|
val uri = FileProvider.getUriForFile(this, "${BuildConfig.APPLICATION_ID}.provider", file)
|
||||||
|
Intent(Intent.ACTION_PICK).apply {
|
||||||
|
type = "image/*"
|
||||||
|
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
putExtra(MediaStore.EXTRA_OUTPUT, uri)
|
||||||
|
if (resolveActivity(packageManager) != null) {
|
||||||
|
startActivityForResult(this, INTENT_CHOOSE_PHOTO)
|
||||||
|
} else {
|
||||||
|
toast(R.string.no_app_found)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getCachePhotoFile(): File {
|
||||||
|
val imagesFolder = File(cacheDir, "my_cache")
|
||||||
|
if (!imagesFolder.exists()) {
|
||||||
|
imagesFolder.mkdirs()
|
||||||
|
}
|
||||||
|
|
||||||
|
return File(imagesFolder, "Photo_${System.currentTimeMillis()}.jpg")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getEmailTextId(type: Int) = when (type) {
|
private fun getEmailTextId(type: Int) = when (type) {
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
<paths>
|
<paths>
|
||||||
<external-path name="external_files" path="."/>
|
<external-path name="external_files" path="."/>
|
||||||
<root-path name="external_files" path="/storage/" />
|
<root-path name="external_files" path="/storage/" />
|
||||||
<files-path name="external_files" path="images/" />
|
<cache-path name="cache_files" path="my_cache/" />
|
||||||
</paths>
|
</paths>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user