aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/src/main
diff options
context:
space:
mode:
authorMarvin Borner2018-08-31 22:44:44 +0200
committerMarvin Borner2018-08-31 22:44:44 +0200
commit770081bb0090e8867b1b6e153f8cf65cb700be86 (patch)
tree8d13eddd3c1498f090ac086d86359a725d273328 /app/src/main
parent0387275f1111975a3643d4c44c36d105f476fe6e (diff)
Finished saving and displaying of image
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/me/texx/Texx/CameraActivity.kt35
-rw-r--r--app/src/main/java/me/texx/Texx/MediaPreviewActivity.kt6
-rw-r--r--app/src/main/res/drawable/ic_send_black_24dp.xml9
-rw-r--r--app/src/main/res/layout/activity_media_preview.xml12
-rw-r--r--app/src/main/res/values/colors.xml2
5 files changed, 54 insertions, 10 deletions
diff --git a/app/src/main/java/me/texx/Texx/CameraActivity.kt b/app/src/main/java/me/texx/Texx/CameraActivity.kt
index 0023dcc..1cc4800 100644
--- a/app/src/main/java/me/texx/Texx/CameraActivity.kt
+++ b/app/src/main/java/me/texx/Texx/CameraActivity.kt
@@ -20,7 +20,11 @@ import daio.io.dresscode.matchDressCode
import kotlinx.android.synthetic.main.activity_camera.*
import me.texx.Texx.util.ThemeUtil.getThemeName
import org.jetbrains.anko.intentFor
+import org.jetbrains.anko.longToast
import java.io.File
+import java.io.FileNotFoundException
+import java.io.FileOutputStream
+import java.io.IOException
import java.text.SimpleDateFormat
import java.util.*
@@ -54,8 +58,9 @@ class CameraActivity : AppCompatActivity() {
private fun setListeners() {
camera.addCameraListener(object : CameraListener() {
override fun onPictureTaken(jpeg: ByteArray?) {
- val file: File? = saveImage(BitmapFactory.decodeByteArray(jpeg, 0, jpeg!!.size))
- startActivity(intentFor<MediaPreviewActivity>("file" to file))
+ val file: File? = createFile()
+ writeFile(BitmapFactory.decodeByteArray(jpeg, 0, jpeg!!.size), file)
+ startActivity(intentFor<MediaPreviewActivity>("filepath" to file.toString()))
}
})
@@ -80,18 +85,36 @@ class CameraActivity : AppCompatActivity() {
/**
* Saves [bitmap] in local storage and returns the absolute path [String] of the file
*/
- private fun saveImage(bitmap: Bitmap): File? {
+ private fun writeFile(bitmap: Bitmap, file: File?) {
+ if (file == null) {
+ longToast("Error creating file - please check the storage permission.)")
+ return
+ }
+ try {
+ val out = FileOutputStream(file)
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)
+ out.close()
+ } catch (e: FileNotFoundException) {
+ longToast("File not found - please try again.\n(${e.message})")
+ } catch (e: IOException) {
+ longToast("Error accessing file - please try again.\n(${e.message})")
+ }
+ }
+
+ /**
+ * Creates empty file to write the file on
+ */
+ private fun createFile(): File? {
val mediaStorageDir = File(Environment.getExternalStorageDirectory().toString()
- + "/Android/data/"
+ + "/Android/media/"
+ applicationContext.packageName
- + "/Files")
+ + "/Images")
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
return null
}
}
-
val mediaFile: File
mediaFile = File(mediaStorageDir.path + File.separator + generateFilename())
return mediaFile
diff --git a/app/src/main/java/me/texx/Texx/MediaPreviewActivity.kt b/app/src/main/java/me/texx/Texx/MediaPreviewActivity.kt
index 6a83362..3e6f25b 100644
--- a/app/src/main/java/me/texx/Texx/MediaPreviewActivity.kt
+++ b/app/src/main/java/me/texx/Texx/MediaPreviewActivity.kt
@@ -1,5 +1,6 @@
package me.texx.Texx
+import android.net.Uri
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Window
@@ -8,7 +9,6 @@ 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() {
@@ -21,8 +21,8 @@ class MediaPreviewActivity : AppCompatActivity() {
WindowManager.LayoutParams.FLAG_FULLSCREEN)
setContentView(R.layout.activity_media_preview)
- val file = intent.getStringExtra("file")
+ val filepath = intent.getStringExtra("filepath")
val imageView = findViewById<ImageView>(R.id.imagePreview)
- longToast(file)
+ imageView.setImageURI(Uri.parse(filepath))
}
}
diff --git a/app/src/main/res/drawable/ic_send_black_24dp.xml b/app/src/main/res/drawable/ic_send_black_24dp.xml
new file mode 100644
index 0000000..00c668c
--- /dev/null
+++ b/app/src/main/res/drawable/ic_send_black_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportHeight="24.0"
+ android:viewportWidth="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z" />
+</vector>
diff --git a/app/src/main/res/layout/activity_media_preview.xml b/app/src/main/res/layout/activity_media_preview.xml
index 4996725..86c6406 100644
--- a/app/src/main/res/layout/activity_media_preview.xml
+++ b/app/src/main/res/layout/activity_media_preview.xml
@@ -12,4 +12,16 @@
android:layout_height="match_parent"
android:contentDescription="Kwel image"
app:srcCompat="@drawable/ic_camera_black_24dp" />
+
+ <android.support.design.widget.FloatingActionButton
+ android:id="@+id/floatingActionButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="24dp"
+ android:layout_marginEnd="24dp"
+ android:clickable="true"
+ app:fabSize="normal"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:srcCompat="@drawable/ic_send_black_24dp" />
</android.support.constraint.ConstraintLayout> \ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 3ab3e9c..4d44345 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -2,5 +2,5 @@
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
- <color name="colorAccent">#FF4081</color>
+ <color name="colorAccent">#ff4081</color>
</resources>