Skip to content

Commit

Permalink
Make setBackgroundColorResource, setTextColorResource functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Aug 29, 2019
1 parent 7f806dc commit 5402522
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.skydoves.balloondemo.factory

import android.content.Context
import androidx.core.content.ContextCompat
import androidx.lifecycle.LifecycleOwner
import com.skydoves.balloon.ArrowOrientation
import com.skydoves.balloon.Balloon
Expand All @@ -36,7 +35,7 @@ class CustomListBalloonFactory : Balloon.Factory() {
.setHeight(200)
.setTextSize(12f)
.setCornerRadius(4f)
.setBackgroundColor(ContextCompat.getColor(context, R.color.background800))
.setBackgroundColorResource(R.color.background800)
.setBalloonAnimation(BalloonAnimation.FADE)
.setDismissWhenShowAgain(true)
.setLifecycleOwner(lifecycle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.skydoves.balloondemo.factory

import android.content.Context
import androidx.core.content.ContextCompat
import androidx.lifecycle.LifecycleOwner
import com.skydoves.balloon.ArrowOrientation
import com.skydoves.balloon.Balloon
Expand All @@ -36,7 +35,7 @@ class ProfileBalloonFactory : Balloon.Factory() {
setWidthRatio(0.55f)
setHeight(250)
setCornerRadius(4f)
setBackgroundColor(ContextCompat.getColor(context, R.color.background900))
setBackgroundColorResource(R.color.background900)
setBalloonAnimation(BalloonAnimation.CIRCULAR)
setDismissWhenShowAgain(true)
setLifecycleOwner(lifecycle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.skydoves.balloondemo.factory

import android.content.Context
import androidx.core.content.ContextCompat
import androidx.lifecycle.LifecycleOwner
import com.skydoves.balloon.ArrowOrientation
import com.skydoves.balloon.Balloon
Expand All @@ -36,7 +35,7 @@ class TagBalloonFactory : Balloon.Factory() {
setWidth(90)
setHeight(60)
setCornerRadius(4f)
setBackgroundColor(ContextCompat.getColor(context, R.color.white))
setBackgroundColorResource(R.color.white)
setBalloonAnimation(BalloonAnimation.ELASTIC)
setDismissWhenShowAgain(true)
setLifecycleOwner(lifecycle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,30 @@ import com.skydoves.balloon.ArrowOrientation
import com.skydoves.balloon.Balloon
import com.skydoves.balloon.BalloonAnimation
import com.skydoves.balloon.createBalloon
import com.skydoves.balloon.textForm
import com.skydoves.balloondemo.R

class ViewHolderBalloonFactory : Balloon.Factory() {

override fun create(context: Context, lifecycle: LifecycleOwner): Balloon {
val textForm = textForm(context) {
setText("This is your new content!!!")
setTextSize(15f)
setTextColor(ContextCompat.getColor(context, R.color.white_87))
}

return createBalloon(context) {
setText("This is your new content.")
setArrowSize(10)
setWidthRatio(0.75f)
setHeight(63)
setTextSize(15f)
setCornerRadius(8f)
setTextForm(textForm)
setArrowOrientation(ArrowOrientation.TOP)
setTextColor(ContextCompat.getColor(context, R.color.white_87))
setTextColorResource(R.color.white_87)
setIconDrawable(ContextCompat.getDrawable(context, R.drawable.ic_edit))
setBackgroundColor(ContextCompat.getColor(context, R.color.yellow))
setBackgroundColorResource(R.color.yellow)
setOnBalloonDismissListener { Toast.makeText(context, "dismissed", Toast.LENGTH_SHORT).show() }
setDismissWhenClicked(true)
setDismissWhenShowAgain(true)
Expand Down
7 changes: 7 additions & 0 deletions balloon/src/main/java/com/skydoves/balloon/Balloon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import android.widget.RelativeLayout
import androidx.annotation.FloatRange
import androidx.annotation.LayoutRes
import androidx.annotation.MainThread
import androidx.core.content.ContextCompat
import androidx.core.widget.ImageViewCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
Expand Down Expand Up @@ -459,6 +460,9 @@ class Balloon(
/** sets the background color of the arrow and popup. */
fun setBackgroundColor(value: Int): Builder = apply { this.backgroundColor = value }

/** sets the background color of the arrow and popup by the resource color. */
fun setBackgroundColorResource(value: Int): Builder = apply { this.backgroundColor = ContextCompat.getColor(context, value) }

/** sets the background drawable of the popup. */
fun setBackgroundDrawable(value: Drawable?) = apply { this.backgroundDrawable = value }

Expand All @@ -471,6 +475,9 @@ class Balloon(
/** sets the color of the main text content. */
fun setTextColor(value: Int): Builder = apply { this.textColor = value }

/** sets the color of the main text content by the resource color. */
fun setTextColorResource(value: Int): Builder = apply { this.textColor = ContextCompat.getColor(context, value) }

/** sets the size of the main text content. */
fun setTextSize(value: Float): Builder = apply { this.textSize = value }

Expand Down

0 comments on commit 5402522

Please sign in to comment.