package jp.co.hyakujushibank.view

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.Window
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import jp.co.hyakujushibank.securestarter.R @Suppress("DEPRECATION")
/**
*
* Created by liuhaolong on 2017/07/05.
*/
class ConfirmDialog : Dialog { private var supContext: Context? = null
private var dialogMsg: String? = ""
private var cacelButtonText: String? = ""
private var confirmButtonText: String? = ""
private var imageRes: Int = 0
private var backFlag: Boolean = true constructor(supContext: Context, dialogMsg: String, cacelButtonText: String, confirmButtonText: String) : super(supContext) {
this.supContext = supContext
this.dialogMsg = dialogMsg
this.cacelButtonText = cacelButtonText
this.confirmButtonText = confirmButtonText
this.backFlag = backFlag
} constructor(supContext: Context, dialogMsg: String, cacelButtonText: String, confirmButtonText: String, backFlag: Boolean) : super(supContext) {
this.supContext = supContext
this.dialogMsg = dialogMsg
this.cacelButtonText = cacelButtonText
this.confirmButtonText = confirmButtonText
this.backFlag = backFlag
} constructor(supContext: Context, dialogMsg: String, cacelButtonText: String, confirmButtonText: String, imageRes: Int) : super(supContext) {
this.supContext = supContext
this.dialogMsg = dialogMsg
this.cacelButtonText = cacelButtonText
this.confirmButtonText = confirmButtonText
this.imageRes = imageRes } constructor(supContext: Context, dialogMsg: String, cacelButtonText: String, confirmButtonText: String, backFlag: Boolean, imageRes: Int) : super(supContext) {
this.supContext = supContext
this.dialogMsg = dialogMsg
this.cacelButtonText = cacelButtonText
this.confirmButtonText = confirmButtonText
this.backFlag = backFlag
this.imageRes = imageRes
} //クリックリスナーインターフェース
var clickListenerInterface: ClickListenerInterface? = null interface ClickListenerInterface {
//確認
fun doConfirm() fun doCancel()
} override fun onBackPressed() {
if (backFlag) {
dismiss()
}
return
} override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE)
//初期化
init() } fun setClicklistener(clickListenerInterface: ClickListenerInterface) {
this.clickListenerInterface = clickListenerInterface
} fun init() {
//充填画面
val inflater = LayoutInflater.from(supContext)
val view = inflater.inflate(R.layout.confirm_alert_dialog, null)
setContentView(view)
//メッセージ
val tvMsg = view.findViewById(R.id.confirm_msg_text) as TextView
//確認
val tvConfirm = view.findViewById(R.id.click_btn) as Button
//メッセージ
val tvCancel = view.findViewById(R.id.cancel_btn) as Button
//画像
val dialogImage = view.findViewById(R.id.dialog_image) as ImageView
if (imageRes == 0) {
dialogImage.setImageDrawable(supContext!!.resources.getDrawable(R.mipmap.info))
} else {
dialogImage.setImageDrawable(supContext!!.resources.getDrawable(imageRes))
}
tvMsg.text = dialogMsg
tvConfirm.text = confirmButtonText
tvCancel.text = cacelButtonText tvConfirm.setOnClickListener(clickListener())
tvCancel.setOnClickListener(clickListener()) setCancelable(false)
setCanceledOnTouchOutside(false) val dialogWindow = window
val lp = dialogWindow.attributes
val d = context.resources.displayMetrics
lp.width = (d.widthPixels * 0.95).toInt()
dialogWindow.attributes = lp
} inner class clickListener : View.OnClickListener {
override fun onClick(v: View) {
val id = v.id
when (id) {
//ボタン
R.id.click_btn -> clickListenerInterface!!.doConfirm()
//ボタン
R.id.cancel_btn -> clickListenerInterface!!.doCancel()
}
}
}
}
怎么用:
val confirm = ConfirmDialog(this@MypageFragmentView, "ログアウトしてもよろしいでしょうか?", "いいえ", "はい")
confirm.setClicklistener(object : ConfirmDialog.ClickListenerInterface {
override fun doConfirm() { logoutApi(this@MypageFragmentView) confirm.dismiss()
} //いいえ
override fun doCancel() {
confirm.dismiss()
}
})
confirm.show()

val confirmDialog = ConfirmDialog(this@MyThemeWebView, msg, "いいえ", "はい", false)

confirmDialog.setOnKeyListener { dialog, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_BACK && event!!.repeatCount == 0) {
handler.cancel()
}
false
} confirmDialog.setClicklistener(object : ConfirmDialog.ClickListenerInterface {
override fun doConfirm() {
handler.proceed()
confirmDialog.dismiss()
} //いいえ
override fun doCancel() {
handler.cancel()
confirmDialog.dismiss()
}
}) confirmDialog.show()


最新文章

  1. Scala中None, Nil, Nothing的区别
  2. DataTable的过滤需要的数据
  3. Markdown语言.md文件
  4. LuManager 2.0.97 设置shopex 手机版waptouch,绑定二级目录
  5. C#:向控件添加信息类
  6. cmd命令行中的errorlevel和延迟赋值
  7. 前端优化分析 之 javascript引用位置优化
  8. bzoj 1090 [SCOI2003]字符串折叠(区间DP)
  9. .NET编程和SQL Server ——Sql Server 与CLR集成 (学习笔记整理-1)
  10. C++STL vector简单使用练习1
  11. IPQ4028开启I2C功能
  12. vim之添加多行和删除多行
  13. HTML5效果:Canvas 实现圆形进度条并显示数字百分比
  14. 【2017下集美大学软工1412班_助教博客】团队作业7——第二次项目冲刺(Beta阶段)成绩公示
  15. Convolutional Neural Networks: Step by Step
  16. Web 应用架构基础课(转载)
  17. 监测多个textFiled.text的长度同时不小于0
  18. 瞥了一眼js
  19. HDU1576 A/B
  20. 《DSP using MATLAB》示例Example 8.17

热门文章

  1. jmeter分布式测试配置
  2. 微信程序开发系列教程(二)使用JavaScript给微信用户发送消息
  3. UVA10917 A walk trough the Forest (最短路,dp)
  4. 树形dp——Tree2cycle
  5. LVM逻辑分区的优缺点与步骤
  6. Open Cascade:AIS_InteractiveContext如何调用函数选择AIS对象
  7. 用navcat编写定时任务调用存储过程
  8. Mac终端(Terminal)自定义颜色,字体,背景
  9. springboot-i18n国际化
  10. 函数的参数是函数,函数中Ajax返回的回调函数中的函数运行