Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
0xMartin committed Jan 20, 2023
1 parent 883c15a commit 640444e
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 38 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,7 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

// circle image view
implementation 'com.mikhaellopez:circularimageview:4.3.1'

}
19 changes: 19 additions & 0 deletions app/src/main/java/cz/utb/photostudio/CameraFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.core.graphics.scale
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
Expand Down Expand Up @@ -58,6 +59,7 @@ class CameraFragment : Fragment(), TensorFlowObjDetector.DetectorListener {

// UID naposledy vyfoceneho obrazku (v dane session)
var last_img_uid: Int? = null
var last_img_path: String? = null


override fun onCreateView(
Expand Down Expand Up @@ -185,6 +187,13 @@ class CameraFragment : Fragment(), TensorFlowObjDetector.DetectorListener {
// pokud ne tak provede clear overlayer vrstvy s vysledakama detekce
this.binding.overlay.clear()
}

// obnoveni nahledu naposledy vyfoceneho obrazku
if(this.last_img_path != null) {
binding.imageviewLast.setImageBitmap(ImageIO.loadImage(requireContext(),
this.last_img_path!!)?.scale(128, 128))
binding.imageviewLast.invalidate()
}
}

override fun onPause() {
Expand Down Expand Up @@ -258,6 +267,7 @@ class CameraFragment : Fragment(), TensorFlowObjDetector.DetectorListener {
// oprazek ulozi na uloziste zarizeni
val rotation: Int = this.activity?.windowManager?.defaultDisplay?.rotation ?: Surface.ROTATION_0
val path: String = ImageIO.saveImage(requireContext(), image, rotation)

// cas
val now = LocalDateTime.now()
var current = now.year.toString() + "-"
Expand All @@ -266,6 +276,14 @@ class CameraFragment : Fragment(), TensorFlowObjDetector.DetectorListener {
current += "%02d".format(now.hour) + ":"
current += "%02d".format(now.minute) + ":"
current += "%02d".format(now.second)

// obnoveni nahledu naposledy vyfoceneho obrazku
this.last_img_path = path
Handler(Looper.getMainLooper()).post(java.lang.Runnable {
binding.imageviewLast.setImageBitmap(ImageIO.loadImage(requireContext(), path)?.scale(128, 128))
binding.imageviewLast.invalidate()
})

// ulozeni informaci do lokalni databaze
val db: AppDatabase = AppDatabase.getDatabase(requireContext())
last_img_uid = db.imageFileDao().getMaxUid() + 1
Expand All @@ -275,6 +293,7 @@ class CameraFragment : Fragment(), TensorFlowObjDetector.DetectorListener {
path
)
db.imageFileDao().insert(img)

} catch (e: java.lang.Exception) {
e.printStackTrace()
Handler(Looper.getMainLooper()).post(java.lang.Runnable {
Expand Down
26 changes: 22 additions & 4 deletions app/src/main/java/cz/utb/photostudio/filter/Brightness.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Brightness(name: String, brightness: Float = 0.0f) : Filter(name) {
init {
this.brightness = brightness
this.fragment = FilterFragment()
this.fragment?.refresh(this.brightness)
this.fragment!!.brightnessChanged = { c ->
this.brightness = c
this.changed?.invoke()
Expand All @@ -38,6 +39,7 @@ class Brightness(name: String, brightness: Float = 0.0f) : Filter(name) {

override fun reset() {
this.brightness = 1.0f
this.fragment?.refresh(this.brightness)
}

private fun adjustBrightness(matrix: ColorMatrix, brightness: Float) {
Expand All @@ -54,16 +56,25 @@ class Brightness(name: String, brightness: Float = 0.0f) : Filter(name) {
/**
* Fragment pro ovladani filtru
*/
class FilterFragment : Fragment() {
class FilterFragment() : Fragment() {

var brightnessChanged: ((c: Float)->Unit)? = null

private var seekBar: CustomSeekBar? = null

private var brightness: Float = 1.0f
init {
this.brightness = brightness
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?,
): View? {
val view: View = inflater.inflate(R.layout.filter_brightness, container, false)
val seekBar: CustomSeekBar = view.findViewById(R.id.seekBar)
seekBar.fromCenter = true
seekBar.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
this.seekBar = view.findViewById(R.id.seekBar)
this.seekBar?.fromCenter = true
this.seekBar?.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {}
override fun onStartTrackingTouch(p0: SeekBar?) {}
override fun onStopTrackingTouch(p0: SeekBar?) {
Expand All @@ -72,8 +83,15 @@ class Brightness(name: String, brightness: Float = 0.0f) : Filter(name) {
}
}
})
refresh(this.brightness)
return view
}

fun refresh(brightness: Float) {
this.brightness = brightness
this.seekBar?.progress = ((brightness + 60.0f) / 120.0f * 100.0f).toInt()
}

}

}
28 changes: 23 additions & 5 deletions app/src/main/java/cz/utb/photostudio/filter/Contrast.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class Contrast(name: String, contrast: Float = 1.0f) : Filter(name) {

init {
this.contrast = contrast
this.fragment = FilterFragment()
this.fragment = FilterFragment(this.contrast)
this.fragment?.refresh(this.contrast)
this.fragment!!.contrastChanged = { c ->
this.contrast = c
this.changed?.invoke()
Expand All @@ -39,6 +40,7 @@ class Contrast(name: String, contrast: Float = 1.0f) : Filter(name) {

override fun reset() {
this.contrast = 1.0f
this.fragment?.refresh(this.contrast)
}

private fun adjustContrast(matrix: ColorMatrix, contrast: Float) {
Expand All @@ -56,16 +58,25 @@ class Contrast(name: String, contrast: Float = 1.0f) : Filter(name) {
/**
* Fragment pro ovladani filtru
*/
class FilterFragment : Fragment() {
class FilterFragment(contrast: Float) : Fragment() {

var contrastChanged: ((c: Float)->Unit)? = null

private var seekBar: CustomSeekBar? = null

private var contrast: Float = 1.0f
init {
this.contrast = contrast
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?,
): View? {
val view: View = inflater.inflate(R.layout.filter_contrast, container, false)
val seekBar: CustomSeekBar = view.findViewById(R.id.seekBar)
seekBar.fromCenter = true
seekBar.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
this.seekBar = view.findViewById(R.id.seekBar)
this.seekBar?.fromCenter = true
this.seekBar?.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {}
override fun onStartTrackingTouch(p0: SeekBar?) {}
override fun onStopTrackingTouch(p0: SeekBar?) {
Expand All @@ -74,8 +85,15 @@ class Contrast(name: String, contrast: Float = 1.0f) : Filter(name) {
}
}
})
refresh(this.contrast)
return view
}

fun refresh(contrast: Float) {
this.contrast = contrast
this.seekBar?.progress = (contrast / 2.0f * 100.0f).toInt()
}

}

}
2 changes: 0 additions & 2 deletions app/src/main/java/cz/utb/photostudio/filter/Filter.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cz.utb.photostudio.filter

import android.graphics.Bitmap
import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import androidx.fragment.app.Fragment

abstract class Filter(name: String) {
Expand Down
58 changes: 45 additions & 13 deletions app/src/main/java/cz/utb/photostudio/filter/RGB.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cz.utb.photostudio.filter

import android.annotation.SuppressLint
import android.graphics.*
import android.os.Bundle
import android.view.LayoutInflater
Expand All @@ -19,7 +18,10 @@ class RGB(name: String, red: Float = 1.0f, green: Float = 1.0f, blue: Float = 1.
private var fragment: FilterFragment? = null

init {
this.fragment = FilterFragment()
this.red = red
this.green = green
this.blue = blue
this.fragment = FilterFragment(red, green, blue)
this.fragment!!.redChanged = { c ->
this.red = c
this.changed?.invoke()
Expand Down Expand Up @@ -58,6 +60,7 @@ class RGB(name: String, red: Float = 1.0f, green: Float = 1.0f, blue: Float = 1.
this.red = 1.0f
this.green = 1.0f
this.blue = 1.0f
this.fragment?.refresh(red, green, blue)
}

private fun adjustRGB(matrix: ColorMatrix, red: Float, green: Float, blue: Float) {
Expand All @@ -69,20 +72,34 @@ class RGB(name: String, red: Float = 1.0f, green: Float = 1.0f, blue: Float = 1.
/**
* Fragment pro ovladani filtru
*/
class FilterFragment : Fragment() {
class FilterFragment(red: Float, green: Float, blue: Float) : Fragment() {

var redChanged: ((c: Float)->Unit)? = null
var greenChanged: ((c: Float)->Unit)? = null
var blueChanged: ((c: Float)->Unit)? = null
@SuppressLint("CutPasteId")

private var seekBarRed: CustomSeekBar? = null
private var seekBarGreen: CustomSeekBar? = null
private var seekBarBlue: CustomSeekBar? = null

private var red: Float = 1.0f
private var green: Float = 1.0f
private var blue: Float = 1.0f
init {
this.red = red
this.green = green
this.blue = blue
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?,
): View? {
val view: View = inflater.inflate(R.layout.filter_rgb, container, false)
// red
val seekBar: CustomSeekBar = view.findViewById(R.id.seekBarRed)
seekBar.fromCenter = true
seekBar.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
this.seekBarRed = view.findViewById(R.id.seekBarRed)
this.seekBarRed?.fromCenter = true
this.seekBarRed?.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {}
override fun onStartTrackingTouch(p0: SeekBar?) {}
override fun onStopTrackingTouch(p0: SeekBar?) {
Expand All @@ -92,9 +109,9 @@ class RGB(name: String, red: Float = 1.0f, green: Float = 1.0f, blue: Float = 1.
}
})
// green
val seekBar2: CustomSeekBar = view.findViewById(R.id.seekBarGreen)
seekBar2.fromCenter = true
seekBar2.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
this.seekBarGreen = view.findViewById(R.id.seekBarGreen)
this.seekBarGreen?.fromCenter = true
this.seekBarGreen?.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {}
override fun onStartTrackingTouch(p0: SeekBar?) {}
override fun onStopTrackingTouch(p0: SeekBar?) {
Expand All @@ -104,9 +121,9 @@ class RGB(name: String, red: Float = 1.0f, green: Float = 1.0f, blue: Float = 1.
}
})
// blue
val seekBar3: CustomSeekBar = view.findViewById(R.id.seekBarBlue)
seekBar3.fromCenter = true
seekBar3.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
this.seekBarBlue = view.findViewById(R.id.seekBarBlue)
this.seekBarBlue?.fromCenter = true
this.seekBarBlue?.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {}
override fun onStartTrackingTouch(p0: SeekBar?) {}
override fun onStopTrackingTouch(p0: SeekBar?) {
Expand All @@ -115,8 +132,23 @@ class RGB(name: String, red: Float = 1.0f, green: Float = 1.0f, blue: Float = 1.
}
}
})
this.refresh(red, green, blue)
return view
}

fun refresh(red: Float, green: Float, blue: Float) {
this.red = red
this.green = green
this.blue = blue

this.seekBarRed?.progress = (red / 2.0f * 100.0f).toInt()
this.seekBarGreen?.progress = (green / 2.0f * 100.0f).toInt()
this.seekBarBlue?.progress = (blue / 2.0f * 100.0f).toInt()
this.seekBarRed?.invalidate()
this.seekBarGreen?.invalidate()
this.seekBarBlue?.invalidate()
}

}

}
32 changes: 27 additions & 5 deletions app/src/main/java/cz/utb/photostudio/filter/Saturation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Saturation(name: String, saturation: Float = 1.0f) : Filter(name) {

init {
this.saturation = saturation
this.fragment = FilterFragment()
this.fragment = FilterFragment(this.saturation)
this.fragment?.refresh(this.saturation)
this.fragment!!.saturationChanged = { c ->
this.saturation = c
this.changed?.invoke()
Expand All @@ -38,6 +39,7 @@ class Saturation(name: String, saturation: Float = 1.0f) : Filter(name) {

override fun reset() {
this.saturation = 1.0f
this.fragment?.refresh(this.saturation)
}

private fun adjustSaturation(matrix: ColorMatrix, saturation: Float) {
Expand All @@ -49,16 +51,25 @@ class Saturation(name: String, saturation: Float = 1.0f) : Filter(name) {
/**
* Fragment pro ovladani filtru
*/
class FilterFragment : Fragment() {
class FilterFragment(saturation: Float) : Fragment() {

var saturationChanged: ((c: Float)->Unit)? = null

private var seekBar: CustomSeekBar? = null

private var saturation: Float = 1.0f
init {
this.saturation = saturation
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?,
): View? {
val view: View = inflater.inflate(R.layout.filter_saturation, container, false)
val seekBar: CustomSeekBar = view.findViewById(R.id.seekBar)
seekBar.fromCenter = true
seekBar.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
this.seekBar = view.findViewById(R.id.seekBar)
this.seekBar?.fromCenter = true
this.seekBar?.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {}
override fun onStartTrackingTouch(p0: SeekBar?) {}
override fun onStopTrackingTouch(p0: SeekBar?) {
Expand All @@ -73,8 +84,19 @@ class Saturation(name: String, saturation: Float = 1.0f) : Filter(name) {
}
}
})
refresh(this.saturation)
return view
}

fun refresh(saturation: Float) {
this.saturation = saturation
if(saturation <= 1) {
this.seekBar?.progress = (saturation * 50.0f).toInt()
} else {
this.seekBar?.progress = ((saturation - 1.0f) / 3.0f * 50.0f + 50.0f).toInt()
}
}

}

}
Loading

0 comments on commit 640444e

Please sign in to comment.