Camera timer

This commit is contained in:
Hardcore Sushi 2020-08-09 15:27:31 +02:00
parent cac264043f
commit 9c2da04a11
3 changed files with 80 additions and 1 deletions

View File

@ -1,8 +1,12 @@
package sushi.hardcore.droidfs
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.InputType
import android.view.View
import android.view.WindowManager
import android.widget.EditText
import android.widget.Toast
import com.otaliastudios.cameraview.CameraListener
import com.otaliastudios.cameraview.PictureResult
@ -13,6 +17,7 @@ import sushi.hardcore.droidfs.util.GocryptfsVolume
import sushi.hardcore.droidfs.util.MiscUtils
import sushi.hardcore.droidfs.util.PathUtils
import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder
import sushi.hardcore.droidfs.widgets.ThemeColor
import java.io.ByteArrayInputStream
import java.io.FileOutputStream
import java.io.InputStream
@ -28,6 +33,15 @@ class CameraActivity : AppCompatActivity() {
private val random = Random()
}
private var currentFlashModeIndex = 0
private var timerDuration = 0
set(value) {
field = value
if (value > 0){
image_timer.setColorFilter(Color.GREEN)
} else {
image_timer.clearColorFilter()
}
}
private lateinit var gocryptfsVolume: GocryptfsVolume
private lateinit var outputDirectory: String
private lateinit var fileName: String
@ -61,7 +75,21 @@ class CameraActivity : AppCompatActivity() {
do {
fileName = baseName+(random.nextInt(fileNameRandomMax-fileNameRandomMin)+fileNameRandomMin)+".jpg"
} while (gocryptfsVolume.pathExists(fileName))
camera.takePicture()
if (timerDuration > 0){
text_timer.visibility = View.VISIBLE
Thread{
for (i in timerDuration downTo 1){
runOnUiThread { text_timer.text = i.toString() }
Thread.sleep(1000)
}
runOnUiThread {
camera.takePicture()
text_timer.visibility = View.GONE
}
}.start()
} else {
camera.takePicture()
}
}
fun onClickFlash(view: View) {
@ -86,4 +114,25 @@ class CameraActivity : AppCompatActivity() {
}.start()
}
}
fun onClickTimer(view: View) {
val dialogEditTextView = layoutInflater.inflate(R.layout.dialog_edit_text, null)
val dialogEditText = dialogEditTextView.findViewById<EditText>(R.id.dialog_edit_text)
dialogEditText.inputType = InputType.TYPE_CLASS_NUMBER
val dialog = ColoredAlertDialogBuilder(this)
.setView(dialogEditTextView)
.setTitle("Enter the timer duration (in s)")
.setPositiveButton(R.string.ok) { _, _ ->
timerDuration = dialogEditText.text.toString().toInt()
}
.setNegativeButton(R.string.cancel, null)
.create()
dialogEditText.setOnEditorActionListener { _, _, _ ->
timerDuration = dialogEditText.text.toString().toInt()
dialog.dismiss()
true
}
dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
dialog.show()
}
}

View File

@ -0,0 +1,6 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
<path android:fillColor="@android:color/white" android:pathData="M12.5,7H11v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z"/>
</vector>

View File

@ -14,6 +14,30 @@
app:cameraPictureFormat="jpeg"
app:cameraAudio="off"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp">
<ImageView
android:id="@+id/image_timer"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/icon_timer"
android:layout_centerInParent="true"
android:onClick="onClickTimer"/>
</RelativeLayout>
<TextView
android:id="@+id/text_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="100sp"
android:layout_centerInParent="true"
android:visibility="gone"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"