Skip to content

Commit

Permalink
Update sample app to include text/initials drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorhugods committed Feb 25, 2020
1 parent c16080e commit b85bb34
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 54 deletions.
75 changes: 53 additions & 22 deletions app/src/main/java/xyz/schwaab/avvy/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.appcompat.app.AppCompatActivity
import com.flask.colorpicker.ColorPickerView
import com.flask.colorpicker.builder.ColorPickerDialogBuilder
import kotlinx.android.synthetic.main.activity_main.*
import xyz.schwaab.avvylib.AvatarView

class MainActivity : AppCompatActivity() {

Expand All @@ -14,42 +15,61 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)

buttonToggleHighlight.setOnClickListener {
avatarView.isHighlighted = !avatarView.isHighlighted
updateAvatars {
isHighlighted = !isHighlighted
}
}
buttonToggleProgress.setOnClickListener {
avatarView.isAnimating = !avatarView.isAnimating
updateAvatars {
isAnimating = !isAnimating
}
}
avatarView.setOnClickListener {
Toast.makeText(this@MainActivity, "It works!", Toast.LENGTH_SHORT).show()
updateAvatars {
setOnClickListener {
Toast.makeText(this@MainActivity, R.string.it_works, Toast.LENGTH_SHORT).show()
}
}

viewHighlightColor.setOnClickListener {
requestColorPick(avatarView.highlightBorderColor){
requestColorPick(avatarView.highlightBorderColor) {
viewHighlightColor.setBackgroundColor(it)
avatarView.highlightBorderColor = it
updateAvatars {
highlightBorderColor = it
}
}
}
viewHighlightColorEnd.setOnClickListener {
requestColorPick(avatarView.highlightBorderColorEnd){
requestColorPick(avatarView.highlightBorderColorEnd) {
viewHighlightColorEnd.setBackgroundColor(it)
avatarView.highlightBorderColorEnd = it
updateAvatars {
highlightBorderColorEnd = it
}
}
}
viewColor.setOnClickListener {
requestColorPick(avatarView.borderColor){
requestColorPick(avatarView.borderColor) {
viewColor.setBackgroundColor(it)
avatarView.borderColor = it
updateAvatars {
borderColor = it
}
}
}
viewColorEnd.setOnClickListener {
requestColorPick(avatarView.borderColorEnd){
requestColorPick(avatarView.borderColorEnd) {
viewColorEnd.setBackgroundColor(it)
avatarView.borderColorEnd = it
updateAvatars {
borderColorEnd = it
}
}
}
}

fun requestColorPick(initialColor: Int, onPick: ((Int) -> Unit)){
private fun updateAvatars(apply: AvatarView.() -> Unit) {
avatarView.apply()
avatarView2.apply()
}

private fun requestColorPick(initialColor: Int, onPick: ((Int) -> Unit)) {
ColorPickerDialogBuilder
.with(this@MainActivity)
.setTitle(R.string.choose_color)
Expand All @@ -59,11 +79,10 @@ class MainActivity : AppCompatActivity() {
.setPositiveButton(R.string.confirm) { _, color, _ ->
onPick(color)
}
.setNegativeButton(R.string.cancel){_,_ -> }
.setNegativeButton(R.string.cancel) { _, _ -> }
.build()
.show()
}

override fun onResume() {
super.onResume()
seekbarHighlightBorderThickness.apply {
Expand All @@ -73,7 +92,9 @@ class MainActivity : AppCompatActivity() {
build()
}
onProgressChangedListener = onUserChange { progress, _ ->
avatarView.highlightedBorderThickness = progress
updateAvatars {
highlightedBorderThickness = progress
}
}
}
seekbarBorderThickness.apply {
Expand All @@ -83,7 +104,9 @@ class MainActivity : AppCompatActivity() {
build()
}
onProgressChangedListener = onUserChange { progress, _ ->
avatarView.borderThickness = progress
updateAvatars {
borderThickness = progress
}
}
}
seekbarDistanceToBorder.apply {
Expand All @@ -93,18 +116,26 @@ class MainActivity : AppCompatActivity() {
build()
}
onProgressChangedListener = onUserChange { progress, _ ->
avatarView.distanceToBorder = progress
updateAvatars {
distanceToBorder = progress
}
}
}

seekbarArcLenght.onProgressChangedListener = onUserChange { _, progress ->
avatarView.individualArcDegreeLenght = progress
seekbarArcLength.onProgressChangedListener = onUserChange { _, progress ->
updateAvatars {
individualArcDegreeLength = progress
}
}
seekbarArchesArea.onProgressChangedListener = onUserChange { _, progress ->
avatarView.totalArchesDegreeArea = progress
updateAvatars {
totalArchesDegreeArea = progress
}
}
seekbarArchesCount.onProgressChangedListener = onUserChange { progress, _ ->
avatarView.numberOfArches = progress
updateAvatars {
numberOfArches = progress
}
}
}
}
Loading

0 comments on commit b85bb34

Please sign in to comment.