From 54f8d30ef2e689bf8d923e85ada7b8aa110ebd52 Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Sun, 2 Sep 2018 17:04:51 +0200
Subject: Added location tracking in camera and fixed permissions
---
app/src/main/AndroidManifest.xml | 3 +-
app/src/main/java/me/texx/Texx/CameraActivity.kt | 65 ++++++++++++++++++++----
2 files changed, 56 insertions(+), 12 deletions(-)
(limited to 'app/src/main')
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f2882db..87001df 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -11,7 +11,8 @@
-
+
+
("filepath" to file.toString()))
+ if (ContextCompat.checkSelfPermission(this@CameraActivity, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ val file: File? = createFile()
+ SaveFileTask(file).execute(jpeg)
+ startActivity(intentFor("filepath" to file.toString()))
+ } else {
+ triggerPermissionError("Storage")
+ }
}
})
camera_button.setOnClickListener {
- if (takingPicture)
+ if (camera.sessionType == SessionType.PICTURE)
camera.capturePicture()
else
camera.startCapturingVideo()
}
camera_button.setOnLongClickListener {
- if (takingPicture) {
+ if (camera.sessionType == SessionType.PICTURE) {
camera.sessionType = SessionType.VIDEO
val videoButtonDrawable: Drawable = this.resources.getDrawable(R.drawable.focus_marker_outline)
videoButtonDrawable.colorFilter = PorterDuffColorFilter(RED, PorterDuff.Mode.SRC_IN)
@@ -110,7 +123,7 @@ class CameraActivity : AppCompatActivity() {
}
/**
- * Creates empty [File] to write the file on
+ * Creates empty [File] to write the file on if permission is granted
*/
private fun createFile(): File? {
val mediaStorageDir = File(Environment.getExternalStorageDirectory().toString()
@@ -136,6 +149,35 @@ class CameraActivity : AppCompatActivity() {
return "Texx_$timestamp.jpg"
}
+ /**
+ * Initializes location service
+ */
+ private fun initLocation() {
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
+ locationCLient = LocationServices.getFusedLocationProviderClient(this)
+ locationCLient.lastLocation
+ .addOnSuccessListener { location: Location? ->
+ location?.let {
+ camera.location = location
+ }
+ }
+ }
+ }
+
+ /**
+ * Triggers permission error if permission wasn't granted
+ */
+ private fun triggerPermissionError(permission: String) {
+ alert("You have to give this app the $permission permission to work properly.",
+ "Error") {
+ isCancelable = false
+ positiveButton("Okay") {
+ finishAffinity()
+ startActivity()
+ }
+ }.show()
+ }
+
/**
* Start components on activity resume (called at start)
*/
@@ -160,3 +202,4 @@ class CameraActivity : AppCompatActivity() {
camera.destroy() // doesn't really destroys your camera lol
}
}
+
--
cgit v1.2.3