From 2295bd4f8f4a1d565e69ab5931ae2f0108d24407 Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Sat, 1 Sep 2018 02:34:08 +0200
Subject: Added drawing tool and color selection seekbar
---
app/src/main/AndroidManifest.xml | 2 +-
app/src/main/java/me/texx/Texx/CameraActivity.kt | 2 +-
.../main/java/me/texx/Texx/MediaPreviewActivity.kt | 34 -----------
.../main/java/me/texx/Texx/PhotoEditorActivity.kt | 69 ++++++++++++++++++++++
.../main/res/drawable/ic_mode_edit_black_24dp.xml | 9 +++
app/src/main/res/layout/activity_photo_editor.xml | 58 ++++++++++++++++++
6 files changed, 138 insertions(+), 36 deletions(-)
delete mode 100644 app/src/main/java/me/texx/Texx/MediaPreviewActivity.kt
create mode 100644 app/src/main/java/me/texx/Texx/PhotoEditorActivity.kt
create mode 100644 app/src/main/res/drawable/ic_mode_edit_black_24dp.xml
create mode 100644 app/src/main/res/layout/activity_photo_editor.xml
(limited to 'app/src')
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f92d495..927f6b1 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -44,7 +44,7 @@
android:value="me.texx.Texx.MainActivity" />
-
+
\ No newline at end of file
diff --git a/app/src/main/java/me/texx/Texx/CameraActivity.kt b/app/src/main/java/me/texx/Texx/CameraActivity.kt
index 2cb67c2..ed50f25 100644
--- a/app/src/main/java/me/texx/Texx/CameraActivity.kt
+++ b/app/src/main/java/me/texx/Texx/CameraActivity.kt
@@ -65,7 +65,7 @@ class CameraActivity : AppCompatActivity() {
override fun onPictureTaken(jpeg: ByteArray?) {
val file: File? = createFile()
writeFile(BitmapFactory.decodeByteArray(jpeg, 0, jpeg!!.size), file)
- startActivity(intentFor("filepath" to file.toString()))
+ startActivity(intentFor("filepath" to file.toString()))
}
})
diff --git a/app/src/main/java/me/texx/Texx/MediaPreviewActivity.kt b/app/src/main/java/me/texx/Texx/MediaPreviewActivity.kt
deleted file mode 100644
index b0ebaa7..0000000
--- a/app/src/main/java/me/texx/Texx/MediaPreviewActivity.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-package me.texx.Texx
-
-import android.net.Uri
-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
-
-/**
- * Activity which will be shown after you've taken a picture
- * Previews the taken picture and posts it if you want
- */
-class MediaPreviewActivity : AppCompatActivity() {
- /**
- * Set initial configuration
- */
- override fun onCreate(savedInstanceState: Bundle?) {
- matchDressCode()
- super.onCreate(savedInstanceState)
- dressCodeName = getThemeName(this)
- requestWindowFeature(Window.FEATURE_NO_TITLE)
- window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN)
- setContentView(R.layout.activity_media_preview)
-
- val filepath = intent.getStringExtra("filepath")
- val imageView = findViewById(R.id.imagePreview)
- imageView.setImageURI(Uri.parse(filepath))
- }
-}
diff --git a/app/src/main/java/me/texx/Texx/PhotoEditorActivity.kt b/app/src/main/java/me/texx/Texx/PhotoEditorActivity.kt
new file mode 100644
index 0000000..dd537a7
--- /dev/null
+++ b/app/src/main/java/me/texx/Texx/PhotoEditorActivity.kt
@@ -0,0 +1,69 @@
+package me.texx.Texx
+
+import android.net.Uri
+import android.os.Bundle
+import android.support.v7.app.AppCompatActivity
+import android.view.View
+import android.view.Window
+import android.view.WindowManager
+import daio.io.dresscode.dressCodeName
+import daio.io.dresscode.matchDressCode
+import ja.burhanrashid52.photoeditor.PhotoEditor
+import ja.burhanrashid52.photoeditor.PhotoEditorView
+import kotlinx.android.synthetic.main.activity_photo_editor.*
+import me.texx.Texx.util.ThemeUtil.getThemeName
+
+/**
+ * Activity which will be shown after you've taken a picture
+ * Previews the taken picture and posts it if you want
+ */
+class PhotoEditorActivity : AppCompatActivity() {
+ /**
+ * Set initial configuration
+ */
+ override fun onCreate(savedInstanceState: Bundle?) {
+ matchDressCode()
+ super.onCreate(savedInstanceState)
+ dressCodeName = getThemeName(this)
+ requestWindowFeature(Window.FEATURE_NO_TITLE)
+ window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
+ WindowManager.LayoutParams.FLAG_FULLSCREEN)
+ setContentView(R.layout.activity_photo_editor)
+
+ initPhotoEditor()
+ }
+
+ private fun initPhotoEditor() {
+ val filepath = intent.getStringExtra("filepath")
+ val imageEditorView = findViewById(R.id.imageEditor)
+ imageEditorView.source.setImageURI(Uri.parse(filepath))
+
+ val photoEditor = PhotoEditor.Builder(this, imageEditorView)
+ .setPinchTextScalable(true)
+ .build()
+
+ setButtonListeners(photoEditor)
+ }
+
+ private fun setButtonListeners(photoEditor: PhotoEditor) {
+ var currentlyDrawing = false
+
+ photoDrawButton.setOnClickListener {
+ currentlyDrawing = !currentlyDrawing
+ photoEditor.setBrushDrawingMode(currentlyDrawing)
+
+ if (currentlyDrawing) drawColorSeekbar.visibility = View.VISIBLE
+ else {
+ drawColorSeekbar.visibility = View.GONE
+ photoDrawButton.setBackgroundColor(View.INVISIBLE)
+ }
+ }
+
+ drawColorSeekbar.setOnColorChangeListener { _, _, color ->
+ if (currentlyDrawing) {
+ photoEditor.brushColor = color
+ photoDrawButton.setBackgroundColor(color)
+ }
+ }
+ }
+}
diff --git a/app/src/main/res/drawable/ic_mode_edit_black_24dp.xml b/app/src/main/res/drawable/ic_mode_edit_black_24dp.xml
new file mode 100644
index 0000000..b49930d
--- /dev/null
+++ b/app/src/main/res/drawable/ic_mode_edit_black_24dp.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/app/src/main/res/layout/activity_photo_editor.xml b/app/src/main/res/layout/activity_photo_editor.xml
new file mode 100644
index 0000000..dd0abba
--- /dev/null
+++ b/app/src/main/res/layout/activity_photo_editor.xml
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
--
cgit v1.2.3