From 5402522da3c28bf95df9caa7ffc3ff85013f0dc5 Mon Sep 17 00:00:00 2001 From: skydoves Date: Thu, 29 Aug 2019 20:20:10 +0900 Subject: [PATCH] Make setBackgroundColorResource, setTextColorResource functionality --- .../balloondemo/factory/CustomListBalloonFactory.kt | 3 +-- .../balloondemo/factory/ProfileBalloonFactory.kt | 3 +-- .../balloondemo/factory/TagBalloonFactory.kt | 3 +-- .../balloondemo/factory/ViewHolderBalloonFactory.kt | 12 ++++++++++-- .../src/main/java/com/skydoves/balloon/Balloon.kt | 7 +++++++ 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/skydoves/balloondemo/factory/CustomListBalloonFactory.kt b/app/src/main/java/com/skydoves/balloondemo/factory/CustomListBalloonFactory.kt index e62f09ac..5ee8f4dd 100644 --- a/app/src/main/java/com/skydoves/balloondemo/factory/CustomListBalloonFactory.kt +++ b/app/src/main/java/com/skydoves/balloondemo/factory/CustomListBalloonFactory.kt @@ -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 @@ -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) diff --git a/app/src/main/java/com/skydoves/balloondemo/factory/ProfileBalloonFactory.kt b/app/src/main/java/com/skydoves/balloondemo/factory/ProfileBalloonFactory.kt index 0f50dda4..5efcedfc 100644 --- a/app/src/main/java/com/skydoves/balloondemo/factory/ProfileBalloonFactory.kt +++ b/app/src/main/java/com/skydoves/balloondemo/factory/ProfileBalloonFactory.kt @@ -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 @@ -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) diff --git a/app/src/main/java/com/skydoves/balloondemo/factory/TagBalloonFactory.kt b/app/src/main/java/com/skydoves/balloondemo/factory/TagBalloonFactory.kt index 7a236e2d..ec0a17d2 100644 --- a/app/src/main/java/com/skydoves/balloondemo/factory/TagBalloonFactory.kt +++ b/app/src/main/java/com/skydoves/balloondemo/factory/TagBalloonFactory.kt @@ -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 @@ -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) diff --git a/app/src/main/java/com/skydoves/balloondemo/factory/ViewHolderBalloonFactory.kt b/app/src/main/java/com/skydoves/balloondemo/factory/ViewHolderBalloonFactory.kt index cfb6212d..3aa8262c 100644 --- a/app/src/main/java/com/skydoves/balloondemo/factory/ViewHolderBalloonFactory.kt +++ b/app/src/main/java/com/skydoves/balloondemo/factory/ViewHolderBalloonFactory.kt @@ -24,11 +24,18 @@ 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) @@ -36,10 +43,11 @@ class ViewHolderBalloonFactory : Balloon.Factory() { 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) diff --git a/balloon/src/main/java/com/skydoves/balloon/Balloon.kt b/balloon/src/main/java/com/skydoves/balloon/Balloon.kt index 51d5417e..4ff3cd50 100644 --- a/balloon/src/main/java/com/skydoves/balloon/Balloon.kt +++ b/balloon/src/main/java/com/skydoves/balloon/Balloon.kt @@ -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 @@ -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 } @@ -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 }