Unverified Commit ad9e42ed authored by Filipe Brito's avatar Filipe Brito Committed by GitHub

Merge pull request #2084 from kareemhamdy100/develop

[IMPROVEMENT] Hide the drawing toolbar while drawing
parents 6642f154 67364d3e
...@@ -204,4 +204,4 @@ task compileSdk(type: Exec) { ...@@ -204,4 +204,4 @@ task compileSdk(type: Exec) {
preBuild.dependsOn compileSdk preBuild.dependsOn compileSdk
if (isPlay) { if (isPlay) {
apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.gms.google-services'
} }
\ No newline at end of file
...@@ -44,7 +44,15 @@ class DrawingActivity : DaggerAppCompatActivity(), DrawView { ...@@ -44,7 +44,15 @@ class DrawingActivity : DaggerAppCompatActivity(), DrawView {
.show() .show()
} }
private fun setupListeners() { private fun setupListeners() {
custom_draw_view.setOnTouchListener { view, event ->
custom_draw_view.onTouch(
event,
draw_tools,
::toggleCompleteDrawTools)
}
image_close_drawing.setOnClickListener { finish() } image_close_drawing.setOnClickListener { finish() }
image_send_drawing.setOnClickListener { image_send_drawing.setOnClickListener {
...@@ -117,6 +125,15 @@ class DrawingActivity : DaggerAppCompatActivity(), DrawView { ...@@ -117,6 +125,15 @@ class DrawingActivity : DaggerAppCompatActivity(), DrawView {
} }
} }
fun toggleCompleteDrawTools(view: View, showView: Boolean = true) {
if (view.translationY == (112).toPx && showView) {
toggleDrawTools(draw_tools, false)
} else {
view.animate().translationY((112).toPx)
}
}
private fun colorSelector() { private fun colorSelector() {
image_color_black.setOnClickListener { image_color_black.setOnClickListener {
custom_draw_view.setColor( custom_draw_view.setColor(
...@@ -232,6 +249,7 @@ class DrawingActivity : DaggerAppCompatActivity(), DrawView { ...@@ -232,6 +249,7 @@ class DrawingActivity : DaggerAppCompatActivity(), DrawView {
}) })
} }
private val Int.toPx: Float private val Int.toPx: Float
get() = (this * Resources.getSystem().displayMetrics.density) get() = (this * Resources.getSystem().displayMetrics.density)
} }
\ No newline at end of file
...@@ -79,7 +79,7 @@ class CustomDrawView(context: Context, attrs: AttributeSet) : View(context, attr ...@@ -79,7 +79,7 @@ class CustomDrawView(context: Context, attrs: AttributeSet) : View(context, attr
} }
fun setAlpha(newAlpha: Int) { fun setAlpha(newAlpha: Int) {
val alpha = (newAlpha*255)/100 val alpha = (newAlpha * 255) / 100
mPaintOptions.alpha = alpha mPaintOptions.alpha = alpha
setColor(mPaintOptions.color) setColor(mPaintOptions.color)
} }
...@@ -157,22 +157,26 @@ class CustomDrawView(context: Context, attrs: AttributeSet) : View(context, attr ...@@ -157,22 +157,26 @@ class CustomDrawView(context: Context, attrs: AttributeSet) : View(context, attr
mPaintOptions = PaintOptions(mPaintOptions.color, mPaintOptions.strokeWidth, mPaintOptions.alpha) mPaintOptions = PaintOptions(mPaintOptions.color, mPaintOptions.strokeWidth, mPaintOptions.alpha)
} }
override fun onTouchEvent(event: MotionEvent): Boolean { fun onTouch(event: MotionEvent, drawTools: View, toggleDrawTools: (View, Boolean) -> Unit): Boolean {
val x = event.x val x = event.x
val y = event.y val y = event.y
when (event.action) { when (event.action) {
MotionEvent.ACTION_DOWN -> { MotionEvent.ACTION_DOWN -> {
toggleDrawTools(drawTools, false)
mStartX = x mStartX = x
mStartY = y mStartY = y
actionDown(x, y) actionDown(x, y)
mUndonePaths.clear() mUndonePaths.clear()
} }
MotionEvent.ACTION_MOVE -> actionMove(x, y) MotionEvent.ACTION_MOVE -> actionMove(x, y)
MotionEvent.ACTION_UP -> actionUp() MotionEvent.ACTION_UP -> {
toggleDrawTools(drawTools, true)
actionUp()
}
} }
invalidate() invalidate()
return true return true
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment