package com.gh.ndownload.suspendwindow.view

import android.content.Context
import android.util.AttributeSet
import android.util.TypedValue
import android.view.Gravity
import android.widget.FrameLayout
import android.widget.ImageView
import com.gh.gamecenter.R

class NDownloadSuspendCloseLayout @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyle: Int = 0
) : FrameLayout(context, attrs, defStyle) {

    init {
        setBackgroundResource(R.drawable.shape_download_suspend_close)
    }

    val close = ImageView(context).also {
        val padding = TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP,
            20F,
            context.resources.displayMetrics
        ).toInt()
        it.setPadding(padding, padding, padding, padding)
        it.setBackgroundResource(R.drawable.shape_download_suspend_close_icon)
        it.setImageResource(R.drawable.ic_download_suspend_close)
        val size = TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP,
            60F,
            context.resources.displayMetrics
        ).toInt()
        val layoutParams = LayoutParams(size, size).apply {
            bottomMargin = TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP,
                72F,
                context.resources.displayMetrics
            ).toInt()
            gravity = Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL
        }
        addView(it, layoutParams)
    }
}