aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/src/main
diff options
context:
space:
mode:
authorMarvin Borner2018-08-31 16:16:06 +0200
committerMarvin Borner2018-08-31 16:16:06 +0200
commit0387275f1111975a3643d4c44c36d105f476fe6e (patch)
treebb26572727010989dd50de30e673c3d12ceb0327 /app/src/main
parentdf994e4fe077dc643658dbd4c65845b0e086fc8a (diff)
Began saving of file
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/AndroidManifest.xml2
-rw-r--r--app/src/main/java/me/texx/Texx/CameraActivity.kt47
-rw-r--r--app/src/main/java/me/texx/Texx/MediaPreviewActivity.kt8
3 files changed, 51 insertions, 6 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 1e82523..f92d495 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -4,6 +4,8 @@
package="me.texx.Texx">
<!-- To auto-complete the email text field in the login form with the user's emails -->
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
diff --git a/app/src/main/java/me/texx/Texx/CameraActivity.kt b/app/src/main/java/me/texx/Texx/CameraActivity.kt
index 9186f28..0023dcc 100644
--- a/app/src/main/java/me/texx/Texx/CameraActivity.kt
+++ b/app/src/main/java/me/texx/Texx/CameraActivity.kt
@@ -1,11 +1,13 @@
package me.texx.Texx
+import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color.RED
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.graphics.drawable.Drawable
import android.os.Bundle
+import android.os.Environment
import android.support.v7.app.AppCompatActivity
import android.view.Window
import android.view.WindowManager
@@ -16,9 +18,12 @@ import com.otaliastudios.cameraview.SessionType
import daio.io.dresscode.dressCodeName
import daio.io.dresscode.matchDressCode
import kotlinx.android.synthetic.main.activity_camera.*
-import kotlinx.android.synthetic.main.activity_media_preview.*
import me.texx.Texx.util.ThemeUtil.getThemeName
-import org.jetbrains.anko.startActivity
+import org.jetbrains.anko.intentFor
+import java.io.File
+import java.text.SimpleDateFormat
+import java.util.*
+
class CameraActivity : AppCompatActivity() {
@@ -35,15 +40,22 @@ class CameraActivity : AppCompatActivity() {
}
private fun initCameraLayout() {
+ setGestures()
+ setListeners()
+ }
+
+ private fun setGestures() {
camera.mapGesture(Gesture.PINCH, GestureAction.ZOOM)
camera.mapGesture(Gesture.TAP, GestureAction.FOCUS_WITH_MARKER)
camera.mapGesture(Gesture.LONG_TAP, GestureAction.CAPTURE)
camera.mapGesture(Gesture.SCROLL_HORIZONTAL, GestureAction.EXPOSURE_CORRECTION)
+ }
+ private fun setListeners() {
camera.addCameraListener(object : CameraListener() {
- override fun onPictureTaken(jpeg: ByteArray) {
- imagePreview.setImageBitmap(BitmapFactory.decodeByteArray(jpeg, 0, jpeg.size))
- startActivity<MediaPreviewActivity>()
+ override fun onPictureTaken(jpeg: ByteArray?) {
+ val file: File? = saveImage(BitmapFactory.decodeByteArray(jpeg, 0, jpeg!!.size))
+ startActivity(intentFor<MediaPreviewActivity>("file" to file))
}
})
@@ -65,6 +77,31 @@ class CameraActivity : AppCompatActivity() {
}
}
+ /**
+ * Saves [bitmap] in local storage and returns the absolute path [String] of the file
+ */
+ private fun saveImage(bitmap: Bitmap): File? {
+ val mediaStorageDir = File(Environment.getExternalStorageDirectory().toString()
+ + "/Android/data/"
+ + applicationContext.packageName
+ + "/Files")
+
+ if (!mediaStorageDir.exists()) {
+ if (!mediaStorageDir.mkdirs()) {
+ return null
+ }
+ }
+
+ val mediaFile: File
+ mediaFile = File(mediaStorageDir.path + File.separator + generateFilename())
+ return mediaFile
+ }
+
+ private fun generateFilename(): String {
+ val timestamp = SimpleDateFormat("ddMMyyyy_HHmm").format(Date())
+ return "Texx_$timestamp.jpg"
+ }
+
override fun onResume() {
super.onResume()
camera.start()
diff --git a/app/src/main/java/me/texx/Texx/MediaPreviewActivity.kt b/app/src/main/java/me/texx/Texx/MediaPreviewActivity.kt
index cdc5c71..6a83362 100644
--- a/app/src/main/java/me/texx/Texx/MediaPreviewActivity.kt
+++ b/app/src/main/java/me/texx/Texx/MediaPreviewActivity.kt
@@ -4,9 +4,11 @@ import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Window
import android.view.WindowManager
+import android.widget.ImageView
import daio.io.dresscode.dressCodeName
import daio.io.dresscode.matchDressCode
import me.texx.Texx.util.ThemeUtil.getThemeName
+import org.jetbrains.anko.longToast
class MediaPreviewActivity : AppCompatActivity() {
@@ -17,6 +19,10 @@ class MediaPreviewActivity : AppCompatActivity() {
requestWindowFeature(Window.FEATURE_NO_TITLE)
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN)
- setContentView(R.layout.activity_camera)
+ setContentView(R.layout.activity_media_preview)
+
+ val file = intent.getStringExtra("file")
+ val imageView = findViewById<ImageView>(R.id.imagePreview)
+ longToast(file)
}
}