Skip to content

Commit

Permalink
#168 PR comment : add programmatically code in JjPlusButton
Browse files Browse the repository at this point in the history
  • Loading branch information
Jokwanhee committed Feb 21, 2024
1 parent eefc97d commit 3ee1dc9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.android.jj_design.utils.button.Following
import com.android.jj_design.utils.button.Minus
import com.android.jj_design.utils.button.Position
import com.android.jj_design.utils.button.Requested
import com.jjbaksa.jjbaksa.R
import com.jjbaksa.jjbaksa.databinding.ActivityDesignComponentSampleBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -28,6 +29,7 @@ class DesignComponentSampleActivity : AppCompatActivity() {
initJjChipButton()
initJjTrendButton()
initJjMapButton()
initJjPlusButton()
}

private fun initJjButton() {
Expand Down Expand Up @@ -88,4 +90,17 @@ class DesignComponentSampleActivity : AppCompatActivity() {
}
}
}

private fun initJjPlusButton() {
CoroutineScope(Dispatchers.Main).launch {
while (isActive) {
binding.jjPlusButton.iconDrawable = com.android.jj_design.R.drawable.icon_add
delay(2000)
binding.jjPlusButton.iconDrawable = com.android.jj_design.R.drawable.icon_minus
delay(2000)
binding.jjPlusButton.iconDrawable = com.android.jj_design.R.drawable.icon_pencil
delay(2000)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
android:layout_marginTop="10dp"/>

<com.android.jj_design.button.JjPlusButton
android:id="@+id/jj_plus_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toBitmap
import com.android.jj_design.R
Expand All @@ -19,6 +20,16 @@ class JjPlusButton @JvmOverloads constructor(
private val plusButtonPaint = Paint()
private var plusBitmap: Bitmap?

var iconDrawable: Int? = null
set(@DrawableRes value) {
plusBitmap = value?.let {
ContextCompat.getDrawable(context, it)
?.toBitmap(PLUS_IMAGE_SIZE.px, PLUS_IMAGE_SIZE.px)
}
invalidate()
field = value
}

init {
plusButtonPaint.apply {
color = context.getColor(R.color.color_50EEEEEE)
Expand Down

0 comments on commit 3ee1dc9

Please sign in to comment.