From 2d977407a15697738d9b6d8827001e0ff635d239 Mon Sep 17 00:00:00 2001 From: skydoves Date: Mon, 17 Feb 2020 02:55:11 +0900 Subject: [PATCH 1/4] Make wrap_content layout_balloon --- .../main/java/com/skydoves/balloon/Balloon.kt | 22 +++++++++---------- .../src/main/res/layout/layout_balloon.xml | 20 ++++++----------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/balloon/src/main/java/com/skydoves/balloon/Balloon.kt b/balloon/src/main/java/com/skydoves/balloon/Balloon.kt index 9b04ff08..a81b297c 100644 --- a/balloon/src/main/java/com/skydoves/balloon/Balloon.kt +++ b/balloon/src/main/java/com/skydoves/balloon/Balloon.kt @@ -47,7 +47,6 @@ import androidx.lifecycle.OnLifecycleEvent import com.skydoves.balloon.annotations.Dp import com.skydoves.balloon.annotations.Sp import kotlinx.android.synthetic.main.layout_balloon.view.balloon_arrow -import kotlinx.android.synthetic.main.layout_balloon.view.balloon_background import kotlinx.android.synthetic.main.layout_balloon.view.balloon_content import kotlinx.android.synthetic.main.layout_balloon.view.balloon_detail import kotlinx.android.synthetic.main.layout_balloon.view.balloon_icon @@ -81,10 +80,9 @@ class Balloon( init { val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater this.bodyView = inflater.inflate(R.layout.layout_balloon, null) - val width = getMeasureWidth() - val params = RelativeLayout.LayoutParams(width, builder.height) - this.bodyView.layoutParams = params - this.bodyWindow = PopupWindow(bodyView, width, builder.height) + this.bodyView.layoutParams = RelativeLayout.LayoutParams(getMeasureWidth(), builder.height) + this.bodyWindow = PopupWindow(bodyView, RelativeLayout.LayoutParams.WRAP_CONTENT, + RelativeLayout.LayoutParams.WRAP_CONTENT) createByBuilder() } @@ -125,11 +123,13 @@ class Balloon( rotation = 90f } } - when (builder.arrowOrientation) { - ArrowOrientation.BOTTOM, ArrowOrientation.TOP -> - x = bodyWindow.width * builder.arrowPosition - (builder.arrowSize / 2) - ArrowOrientation.LEFT, ArrowOrientation.RIGHT -> - y = bodyWindow.height * builder.arrowPosition - (builder.arrowSize / 2) + bodyView.post { + when (builder.arrowOrientation) { + ArrowOrientation.BOTTOM, ArrowOrientation.TOP -> + x = bodyView.width * builder.arrowPosition - (builder.arrowSize / 2) + ArrowOrientation.LEFT, ArrowOrientation.RIGHT -> + y = bodyView.height * builder.arrowPosition - (builder.arrowSize / 2) + } } layoutParams = params alpha = builder.alpha @@ -139,7 +139,7 @@ class Balloon( } private fun initializeBackground() { - with(bodyView.balloon_background) { + with(bodyView.balloon_detail) { alpha = builder.alpha if (builder.backgroundDrawable == null) { background = GradientDrawable().apply { diff --git a/balloon/src/main/res/layout/layout_balloon.xml b/balloon/src/main/res/layout/layout_balloon.xml index 9af3364c..530dda4c 100644 --- a/balloon/src/main/res/layout/layout_balloon.xml +++ b/balloon/src/main/res/layout/layout_balloon.xml @@ -2,15 +2,15 @@ - - + android:orientation="horizontal" + tools:background="@android:color/darker_gray"> Date: Fri, 20 Mar 2020 01:29:31 +0900 Subject: [PATCH 2/4] Wrap balloon xml layout content --- .../factory/ProfileBalloonFactory.kt | 2 - .../balloondemo/factory/TagBalloonFactory.kt | 2 - .../main/res/layout/layout_custom_profile.xml | 2 +- app/src/main/res/layout/layout_custom_tag.xml | 5 +- .../main/java/com/skydoves/balloon/Balloon.kt | 48 ++++++++++++++----- .../src/main/res/layout/layout_balloon.xml | 2 +- 6 files changed, 41 insertions(+), 20 deletions(-) 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 45d53389..077a2273 100644 --- a/app/src/main/java/com/skydoves/balloondemo/factory/ProfileBalloonFactory.kt +++ b/app/src/main/java/com/skydoves/balloondemo/factory/ProfileBalloonFactory.kt @@ -32,8 +32,6 @@ class ProfileBalloonFactory : Balloon.Factory() { setArrowSize(10) setArrowOrientation(ArrowOrientation.TOP) setArrowPosition(0.5f) - setWidthRatio(0.55f) - setHeight(250) setCornerRadius(4f) setBackgroundColorResource(R.color.white) setBalloonAnimation(BalloonAnimation.CIRCULAR) 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 35f7b1b4..cc475c38 100644 --- a/app/src/main/java/com/skydoves/balloondemo/factory/TagBalloonFactory.kt +++ b/app/src/main/java/com/skydoves/balloondemo/factory/TagBalloonFactory.kt @@ -31,8 +31,6 @@ class TagBalloonFactory : Balloon.Factory() { setArrowSize(10) setArrowOrientation(ArrowOrientation.BOTTOM) setArrowPosition(0.5f) - setWidth(90) - setHeight(60) setCornerRadius(4f) setBalloonAnimationStyle(R.style.ElasticAndFadeOut) setBackgroundColorResource(R.color.white_93) diff --git a/app/src/main/res/layout/layout_custom_profile.xml b/app/src/main/res/layout/layout_custom_profile.xml index b46be9cc..8b367d98 100644 --- a/app/src/main/res/layout/layout_custom_profile.xml +++ b/app/src/main/res/layout/layout_custom_profile.xml @@ -1,7 +1,7 @@ diff --git a/app/src/main/res/layout/layout_custom_tag.xml b/app/src/main/res/layout/layout_custom_tag.xml index 1879ef5f..456f225b 100644 --- a/app/src/main/res/layout/layout_custom_tag.xml +++ b/app/src/main/res/layout/layout_custom_tag.xml @@ -3,14 +3,14 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + android:gravity="center" android:orientation="horizontal" android:padding="4dp"> - @@ -18,7 +18,6 @@ - Date: Fri, 20 Mar 2020 20:34:31 +0900 Subject: [PATCH 3/4] Implement set balloon inner padding functionalities --- .../skydoves/balloondemo/CustomActivity.kt | 6 +- .../factory/ProfileBalloonFactory.kt | 1 - app/src/main/res/layout/activity_custom.xml | 2 + .../main/res/layout/layout_custom_list.xml | 3 + .../main/java/com/skydoves/balloon/Balloon.kt | 63 ++++++++++++++----- .../java/com/skydoves/balloon/Definition.kt | 3 + dependencies.gradle | 6 +- 7 files changed, 60 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/skydoves/balloondemo/CustomActivity.kt b/app/src/main/java/com/skydoves/balloondemo/CustomActivity.kt index 37b0ef22..960bbcc8 100644 --- a/app/src/main/java/com/skydoves/balloondemo/CustomActivity.kt +++ b/app/src/main/java/com/skydoves/balloondemo/CustomActivity.kt @@ -21,7 +21,6 @@ import android.view.View import android.widget.Button import android.widget.Toast import androidx.appcompat.app.AppCompatActivity -import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.skydoves.balloon.balloon import com.skydoves.balloondemo.factory.CustomListBalloonFactory @@ -58,13 +57,12 @@ class CustomActivity : AppCompatActivity(), tabLayout.addTab(tabLayout.newTab().setText("Contents")) recyclerView.adapter = adapter - recyclerView.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) - this.adapter.addItems(ItemUtils.getSamples(this)) + adapter.addItems(ItemUtils.getSamples(this)) + // gets customListBalloon's recyclerView. val listRecycler: RecyclerView = customListBalloon.getContentView().findViewById(R.id.list_recyclerView) listRecycler.adapter = customAdapter - listRecycler.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) this.customAdapter.addCustomItem(ItemUtils.getCustomSamples(this)) toolbar_list.setOnClickListener { 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 decca1a2..0115f083 100644 --- a/app/src/main/java/com/skydoves/balloondemo/factory/ProfileBalloonFactory.kt +++ b/app/src/main/java/com/skydoves/balloondemo/factory/ProfileBalloonFactory.kt @@ -33,7 +33,6 @@ class ProfileBalloonFactory : Balloon.Factory() { setArrowSize(10) setArrowOrientation(ArrowOrientation.TOP) setArrowPosition(0.5f) - setWidthRatio(0.55f) setHeight(250) isRtlSupport(BalloonUtils.isRtlLayout()) setCornerRadius(4f) diff --git a/app/src/main/res/layout/activity_custom.xml b/app/src/main/res/layout/activity_custom.xml index 882ba127..3f691119 100644 --- a/app/src/main/res/layout/activity_custom.xml +++ b/app/src/main/res/layout/activity_custom.xml @@ -166,6 +166,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="8dp" + android:orientation="vertical" + app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" tools:listitem="@layout/item_sample" /> diff --git a/app/src/main/res/layout/layout_custom_list.xml b/app/src/main/res/layout/layout_custom_list.xml index c5cfd396..c414ea50 100644 --- a/app/src/main/res/layout/layout_custom_list.xml +++ b/app/src/main/res/layout/layout_custom_list.xml @@ -1,5 +1,6 @@ diff --git a/balloon/src/main/java/com/skydoves/balloon/Balloon.kt b/balloon/src/main/java/com/skydoves/balloon/Balloon.kt index 282c3710..3f2b430f 100644 --- a/balloon/src/main/java/com/skydoves/balloon/Balloon.kt +++ b/balloon/src/main/java/com/skydoves/balloon/Balloon.kt @@ -86,12 +86,12 @@ class Balloon( this.bodyWindow = PopupWindow(bodyView, RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT) - if (builder.widthRatio != 0f || builder.width != -1) { + if (builder.widthRatio != NO_Float_VALUE || builder.width != NO_INT_VALUE) { this.bodyWindow.width = getMeasureWidth() this.bodyView.balloon_detail.layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT } - if (builder.height != -1) { + if (builder.height != NO_INT_VALUE) { this.bodyWindow.height = getMeasureHeight() this.bodyView.balloon_detail.layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT } @@ -154,7 +154,12 @@ class Balloon( private fun initializeBackground() { with(bodyView.balloon_detail) { alpha = builder.alpha - setPadding(builder.padding, builder.padding, builder.padding, builder.padding) + if (builder.padding != NO_INT_VALUE) { + setPadding(builder.padding, builder.padding, builder.padding, builder.padding) + } else { + setPadding(builder.paddingLeft, builder.paddingTop, + builder.paddingRight, builder.paddingBottom) + } if (builder.backgroundDrawable == null) { background = GradientDrawable().apply { setColor(builder.backgroundColor) @@ -493,7 +498,7 @@ class Balloon( val dismissWindow: () -> Unit = { this.bodyWindow.dismiss() } if (this.builder.balloonAnimation == BalloonAnimation.CIRCULAR) { - this.bodyWindow.contentView.circularUnRevealed() { + this.bodyWindow.contentView.circularUnRevealed { dismissWindow() } } else { @@ -537,21 +542,22 @@ class Balloon( } } - /** gets measured width size of the balloon. */ + /** gets measured width size of the balloon popup. */ fun getMeasureWidth(): Int { - if (builder.widthRatio != 0f) { + if (builder.widthRatio != NO_Float_VALUE) { return (context.displaySize().x * builder.widthRatio - builder.space).toInt() - } else if (builder.width != -1) { - return builder.width - builder.space + } else if (builder.width != NO_INT_VALUE) { + return builder.width } - return this.bodyView.measuredWidth - builder.space + return this.bodyView.measuredWidth } + /** gets measured height size of the balloon popup. */ fun getMeasureHeight(): Int { - if (builder.height != -1) { - return builder.height - builder.space + if (builder.height != NO_INT_VALUE) { + return builder.height } - return this.bodyView.measuredHeight - builder.space + return this.bodyView.measuredHeight } /** gets a content view of the balloon popup window. */ @@ -569,13 +575,21 @@ class Balloon( @BalloonDsl class Builder(private val context: Context) { @JvmField @Dp - var width: Int = -1 + var width: Int = NO_INT_VALUE @JvmField @FloatRange(from = 0.0, to = 1.0) - var widthRatio: Float = 0f + var widthRatio: Float = NO_Float_VALUE + @JvmField @Dp + var height: Int = NO_INT_VALUE + @JvmField @Dp + var padding: Int = NO_INT_VALUE + @JvmField @Dp + var paddingLeft: Int = 0 + @JvmField @Dp + var paddingTop: Int = 0 @JvmField @Dp - var height: Int = -1 + var paddingRight: Int = 0 @JvmField @Dp - var padding: Int = 0 + var paddingBottom: Int = 0 @JvmField @Dp var space: Int = 0 @JvmField @@ -658,8 +672,25 @@ class Balloon( /** sets the height size. */ fun setHeight(@Dp value: Int): Builder = apply { this.height = context.dp2Px(value) } + /** sets the padding on all directions. */ fun setPadding(@Dp value: Int): Builder = apply { this.padding = context.dp2Px(value) } + /** sets the left padding on all directions. */ + fun setPaddingLeft(@Dp value: Int): Builder = apply { this.paddingLeft = context.dp2Px(value) } + + /** sets the top padding on all directions. */ + fun setPaddingTop(@Dp value: Int): Builder = apply { this.paddingTop = context.dp2Px(value) } + + /** sets the right padding on all directions. */ + fun setPaddingRight(@Dp value: Int): Builder = apply { + this.paddingRight = context.dp2Px(value) + } + + /** sets the bottom padding on all directions. */ + fun setPaddingBottom(@Dp value: Int): Builder = apply { + this.paddingBottom = context.dp2Px(value) + } + /** sets the side space between popup and display. */ fun setSpace(@Dp value: Int): Builder = apply { this.space = context.dp2Px(value) } diff --git a/balloon/src/main/java/com/skydoves/balloon/Definition.kt b/balloon/src/main/java/com/skydoves/balloon/Definition.kt index 7878decc..9ed26167 100644 --- a/balloon/src/main/java/com/skydoves/balloon/Definition.kt +++ b/balloon/src/main/java/com/skydoves/balloon/Definition.kt @@ -19,6 +19,9 @@ package com.skydoves.balloon /** definition of the non-value of Int type. */ const val NO_INT_VALUE: Int = -1 +/** definition of the non-value of Float type. */ +const val NO_Float_VALUE: Float = 0f + /** definition of the non-value of Long type. */ const val NO_LONG_VALUE: Long = -1L diff --git a/dependencies.gradle b/dependencies.gradle index ea42b557..c6a6d848 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -5,12 +5,12 @@ ext.versions = [ versionName : '1.1.1', gradleBuildTool : '3.5.3', - spotlessGradle : '3.26.1', + spotlessGradle : '3.27.2', dokkaGradle : '0.9.17', bintrayRelease : '0.9.2', - kotlin : '1.3.61', - androidxAppcompat : '1.2.0-alpha02', + kotlin : '1.3.70', + androidxAppcompat : '1.2.0-alpha03', // for demo googleMaterial : '1.2.0-alpha05' From 04647893b56a14e3ad90b685c19bd0d32397bf58 Mon Sep 17 00:00:00 2001 From: skydoves Date: Fri, 20 Mar 2020 20:55:02 +0900 Subject: [PATCH 4/4] Refacotr demo layout xml --- app/src/main/res/layout/activity_custom.xml | 2 +- app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/layout/item_custom.xml | 2 +- app/src/main/res/layout/layout_custom_list.xml | 5 +++-- app/src/main/res/layout/layout_custom_profile.xml | 2 ++ 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/res/layout/activity_custom.xml b/app/src/main/res/layout/activity_custom.xml index 3f691119..2dfa8062 100644 --- a/app/src/main/res/layout/activity_custom.xml +++ b/app/src/main/res/layout/activity_custom.xml @@ -93,7 +93,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" - android:text="334" + android:text="1024" android:textColor="@color/white_93" android:textSize="16sp" android:textStyle="bold" /> diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 52ea715d..f78addef 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -85,7 +85,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" - android:text="334" + android:text="1024" android:textColor="@color/white_93" android:textSize="16sp" android:textStyle="bold" /> diff --git a/app/src/main/res/layout/item_custom.xml b/app/src/main/res/layout/item_custom.xml index b3bba09c..2567f9e1 100644 --- a/app/src/main/res/layout/item_custom.xml +++ b/app/src/main/res/layout/item_custom.xml @@ -2,7 +2,7 @@ @@ -33,6 +34,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="5dp" + android:gravity="center" android:text="Love coffee, music, magic tricks and writing poems." android:textColor="@color/background800" android:textSize="14sp"