Skip to content

Commit

Permalink
Add OnBalloonInitializedListener for listening initialized balloon co…
Browse files Browse the repository at this point in the history
…ntent
  • Loading branch information
skydoves committed Jul 28, 2020
1 parent c902c42 commit 5678d82
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions balloon/src/main/java/com/skydoves/balloon/Balloon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class Balloon(
private var destroyed: Boolean = false
var onBalloonClickListener: OnBalloonClickListener? = null
var onBalloonDismissListener: OnBalloonDismissListener? = null
var onBalloonInitializedListener: OnBalloonInitializedListener? = null
var onBalloonOutsideTouchListener: OnBalloonOutsideTouchListener? = null
private var supportRtlLayoutFactor: Int = LTR.unaryMinus(builder.isRtlSupport)
private val balloonPersistence = BalloonPersistence.getInstance(context)
Expand Down Expand Up @@ -151,6 +152,7 @@ class Balloon(
}
binding.root.post {
binding.balloonArrow.visible(builder.arrowVisible)
onBalloonInitializedListener?.onBalloonInitialized(getContentView())
when (builder.arrowOrientation) {
ArrowOrientation.BOTTOM, ArrowOrientation.TOP -> {
x = getArrowConstraintPositionX(anchor)
Expand Down Expand Up @@ -266,6 +268,7 @@ class Balloon(
private fun initializeBalloonListeners() {
this.onBalloonClickListener = builder.onBalloonClickListener
this.onBalloonDismissListener = builder.onBalloonDismissListener
this.onBalloonInitializedListener = builder.onBalloonInitializedListener
this.onBalloonOutsideTouchListener = builder.onBalloonOutsideTouchListener
this.binding.root.setOnClickListener {
this.onBalloonClickListener?.onBalloonClick(it)
Expand Down Expand Up @@ -867,6 +870,9 @@ class Balloon(
@JvmField
var onBalloonDismissListener: OnBalloonDismissListener? = null

@JvmField
var onBalloonInitializedListener: OnBalloonInitializedListener? = null

@JvmField
var onBalloonOutsideTouchListener: OnBalloonOutsideTouchListener? = null

Expand Down Expand Up @@ -1216,6 +1222,11 @@ class Balloon(
this.onBalloonDismissListener = value
}

/** sets a [OnBalloonInitializedListener] to the popup. */
fun setOnBalloonInitializedListener(value: OnBalloonInitializedListener): Builder = apply {
this.onBalloonInitializedListener = value
}

/** sets a [OnBalloonOutsideTouchListener] to the popup. */
fun setOnBalloonOutsideTouchListener(value: OnBalloonOutsideTouchListener): Builder = apply {
this.onBalloonOutsideTouchListener = value
Expand All @@ -1239,6 +1250,15 @@ class Balloon(
}
}

/** sets a [OnBalloonInitializedListener] to the popup using lambda. */
fun setOnBalloonInitializedListener(unit: (View) -> Unit): Builder = apply {
this.onBalloonInitializedListener = object : OnBalloonInitializedListener {
override fun onBalloonInitialized(contentView: View) {
unit(contentView)
}
}
}

/** sets a [OnBalloonOutsideTouchListener] to the popup using lambda. */
fun setOnBalloonOutsideTouchListener(unit: (View, MotionEvent) -> Unit): Builder = apply {
this.onBalloonOutsideTouchListener = object : OnBalloonOutsideTouchListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2019 skydoves
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.skydoves.balloon

import android.view.View

/** Interface definition for a callback to be invoked when a balloon view is initialized. */
interface OnBalloonInitializedListener {

/** invoked when the [Balloon] is initialized. */
fun onBalloonInitialized(contentView: View)
}

0 comments on commit 5678d82

Please sign in to comment.