ActivityGuideDialog.kt 1.74 KB
Newer Older
1 2 3 4 5 6 7 8 9
package com.yidianling.home.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Window
import com.ydl.ydl_image.module.GlideApp
import com.ydl.ydlcommon.utils.DisplayUtils
import com.yidianling.home.R
konghaorui committed
10
import kotlinx.android.synthetic.xlzx.home_dialog_guide_activity.*
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
import java.util.*

/**
 * 首页活动引导弹窗
 */
class ActivityGuideDialog : Dialog{

    private var imgUrl :String?= null
    private var title:String? = null
    private var marginTop: Int? = null
    private var marginLeft: Int? = null

    constructor(context: Context,imgUrl: String?,title: String?,marginTop : Int,marginLeft:Int):super(context,R.style.activityDialog){
        this.imgUrl = imgUrl
        this.title = title
        this.marginTop = marginTop
        this.marginLeft = marginLeft
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        window.setBackgroundDrawableResource(android.R.color.transparent)

konghaorui committed
35
        setContentView(R.layout.home_dialog_guide_activity)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

        initView()
    }

    private fun initView(){

        if (marginTop==null){
            marginTop = DisplayUtils.dp2px(context,135)
        }
        if (marginLeft==null){
            marginLeft = DisplayUtils.dp2px(context,35)
        }

        c_body.setPadding(marginLeft!!,marginTop!!,0,0)

        c_body.setOnClickListener {
            dismiss()
        }

        tv_content.text = this.title

        GlideApp.with(context).load(imgUrl).into(img_activity)

        //3秒自动消失
        Timer().schedule(object : TimerTask() {
            override fun run() {
                dismiss()
            }
        },3000)
    }

}