Я пытался, но не смог.
Основная активность с кнопкой, при нажатии на кнопку подсказка откроется всплывающая функция showDiag () . и поп состоит из двух кнопок btnHnt и btnResult . При нажатии на каждую из кнопок Награда Ad должна отображаться каждый раз при нажатии. После завершения показа награжденного объявления открывается другая всплывающая функция resultShowDiag () .
Спасибо
Основная активность:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val hint = findViewById<Button>(R.id.hints)
hint.setOnClickListener{
showDiag()
}
}
//PopUp Dialog congracts for level complite
private fun showDiag() {
val dialogView = View.inflate(this, R.layout.pop, null)
val dialog = Dialog(this, R.style.MyAlertDialogStyle)
dialog.getWindow()!!.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
val btnHnt = dialogView.findViewById<Button>(R.id.btnHnt)
val btnResult = dialogView.findViewById<Button>(R.id.btnResult)
dialog.setContentView(dialogView)
val imageView = dialog.findViewById(R.id.closeDialogImg) as ImageView
imageView.setOnClickListener { revealShow(dialogView, false, dialog) }
btnHnt.setOnClickListener {
dialog.cancel()
resultShowDiag()
}
btnResult.setOnClickListener {
dialog.cancel()
resultShowDiag() }
dialog.setOnShowListener(DialogInterface.OnShowListener {revealShow(dialogView, true, null)})
dialog.setOnKeyListener(DialogInterface.OnKeyListener { dialogInterface, i, keyEvent ->
if (i == KeyEvent.KEYCODE_BACK) {
revealShow(dialogView, false, dialog)
return@OnKeyListener true
}
false
})
dialog.getWindow()!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog.show()
}
private fun resultShowDiag() {
val dialogViewResult = View.inflate(this, R.layout.hint_result_pop, null)
val dialogResult = Dialog(this, R.style.MyAlertDialogStyle)
dialogResult.getWindow()!!.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
val btnClose = dialogViewResult.findViewById<Button>(R.id.btnClose)
val hintResult = dialogViewResult.findViewById<ImageView>(R.id.hint_result)
hintResult.setBackgroundResource(R.drawable.hint1)
dialogResult.setContentView(dialogViewResult)
val imageView = dialogResult.findViewById(R.id.closeDialogImg) as ImageView
imageView.setOnClickListener { revealShow(dialogViewResult, false, dialogResult) }
btnClose.setOnClickListener { revealShow(dialogViewResult, false, dialogResult) }//close after result
dialogResult.setOnKeyListener(DialogInterface.OnKeyListener { dialogInterface, i, keyEvent ->
if (i == KeyEvent.KEYCODE_BACK) {
dialogResult.cancel()
return@OnKeyListener true
}
false
})
dialogResult.getWindow()!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialogResult.show()
}
private fun revealShow(dialogView: View, b: Boolean, dialog: Dialog?) {
val view = dialogView.findViewById<View>(R.id.dialog)
val w = view.width
val h = view.height
val endRadius = Math.hypot(w.toDouble(), h.toDouble()).toInt()
val cx = (hints.getX() + hints.getWidth() / 2).toInt()
val cy = hints.getY().toInt() + hints.getHeight()
if (b) {
val revealAnimator =
ViewAnimationUtils.createCircularReveal(view, cx, cy, 0f, endRadius.toFloat())
view.visibility = View.VISIBLE
revealAnimator.duration = 700
revealAnimator.start()
} else {
val anim =
ViewAnimationUtils.createCircularReveal(view, cx, cy, endRadius.toFloat(), 0f)
anim.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
super.onAnimationEnd(animation)
dialog!!.dismiss()
view.visibility = View.INVISIBLE
}
})
anim.duration = 600
anim.start()
}
}
}