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..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" /> @@ -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/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 @@ diff --git a/app/src/main/res/layout/layout_custom_profile.xml b/app/src/main/res/layout/layout_custom_profile.xml index f14f0a61..49c82556 100644 --- a/app/src/main/res/layout/layout_custom_profile.xml +++ b/app/src/main/res/layout/layout_custom_profile.xml @@ -2,8 +2,9 @@ @@ -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" diff --git a/app/src/main/res/layout/layout_custom_tag.xml b/app/src/main/res/layout/layout_custom_tag.xml index 582dd3cf..456f225b 100644 --- a/app/src/main/res/layout/layout_custom_tag.xml +++ b/app/src/main/res/layout/layout_custom_tag.xml @@ -3,13 +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"> @@ -17,7 +18,6 @@ { - x = - supportRtlLayoutFactor * (bodyWindow.width * 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) } - ArrowOrientation.LEFT, ArrowOrientation.RIGHT -> - y = bodyWindow.height * builder.arrowPosition - (builder.arrowSize / 2) } layoutParams = params alpha = builder.alpha @@ -143,8 +152,14 @@ class Balloon( } private fun initializeBackground() { - with(bodyView.balloon_background) { + with(bodyView.balloon_detail) { alpha = builder.alpha + 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) @@ -226,6 +241,7 @@ class Balloon( bodyView.balloon_detail.removeAllViews() val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater inflater.inflate(builder.layout, bodyView.balloon_detail) + bodyView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED) } private fun applyBalloonAnimation() { @@ -282,7 +298,7 @@ class Balloon( fun show(anchor: View) { show(anchor) { bodyWindow.showAsDropDown(anchor, -(anchor.measuredWidth / 2), - -builder.height - (anchor.measuredHeight / 2)) + -getMeasureHeight() - (anchor.measuredHeight / 2)) } } @@ -340,7 +356,7 @@ class Balloon( show(anchor) { bodyWindow.showAsDropDown(anchor, supportRtlLayoutFactor * ((anchor.measuredWidth / 2) - (getMeasureWidth() / 2)), - -builder.height - anchor.measuredHeight) + -getMeasureHeight() - anchor.measuredHeight) } } @@ -358,7 +374,7 @@ class Balloon( show(anchor) { bodyWindow.showAsDropDown(anchor, supportRtlLayoutFactor * ((anchor.measuredWidth / 2) - (getMeasureWidth() / 2) + xOff), - -builder.height - anchor.measuredHeight + yOff) + -getMeasureHeight() - anchor.measuredHeight + yOff) } } @@ -411,7 +427,7 @@ class Balloon( fun showAlignRight(anchor: View) { show(anchor) { bodyWindow.showAsDropDown(anchor, anchor.measuredWidth, - -(builder.height / 2) - (anchor.measuredHeight / 2)) + -(getMeasureHeight() / 2) - (anchor.measuredHeight / 2)) } } @@ -428,7 +444,7 @@ class Balloon( fun showAlignRight(anchor: View, xOff: Int, yOff: Int) { show(anchor) { bodyWindow.showAsDropDown(anchor, anchor.measuredWidth + xOff, - -(builder.height / 2) - (anchor.measuredHeight / 2) + yOff) + -(getMeasureHeight() / 2) - (anchor.measuredHeight / 2) + yOff) } } @@ -445,7 +461,7 @@ class Balloon( fun showAlignLeft(anchor: View) { show(anchor) { bodyWindow.showAsDropDown(anchor, -(getMeasureWidth()), - -(builder.height / 2) - (anchor.measuredHeight / 2)) + -(getMeasureHeight() / 2) - (anchor.measuredHeight / 2)) } } @@ -462,7 +478,7 @@ class Balloon( fun showAlignLeft(anchor: View, xOff: Int, yOff: Int) { show(anchor) { bodyWindow.showAsDropDown(anchor, -(getMeasureWidth()) + xOff, - -(builder.height / 2) - (anchor.measuredHeight / 2) + yOff) + -(getMeasureHeight() / 2) - (anchor.measuredHeight / 2) + yOff) } } @@ -482,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 { @@ -526,12 +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 != NO_INT_VALUE) { + return builder.width + } + return this.bodyView.measuredWidth + } + + /** gets measured height size of the balloon popup. */ + fun getMeasureHeight(): Int { + if (builder.height != NO_INT_VALUE) { + return builder.height } - return builder.width - builder.space + return this.bodyView.measuredHeight } /** gets a content view of the balloon popup window. */ @@ -549,11 +575,21 @@ class Balloon( @BalloonDsl class Builder(private val context: Context) { @JvmField @Dp - var width: Int = context.displaySize().x + 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 = context.dp2Px(60) + 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 paddingRight: Int = 0 + @JvmField @Dp + var paddingBottom: Int = 0 @JvmField @Dp var space: Int = 0 @JvmField @@ -636,6 +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/balloon/src/main/res/layout/layout_balloon.xml b/balloon/src/main/res/layout/layout_balloon.xml index 9af3364c..3f5a0a54 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"> -