package com.android.launcher3.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.android.launcher3.R;

import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.annotation.StyleRes;

public class TipsDialog extends Dialog {
    private TextView tvTips;

    private TextView tvKnow;

    public TipsDialog(@NonNull Context context) {
        this(context, R.style.Dialog);
    }

    public TipsDialog(@NonNull Context context, @StyleRes int theme) {
        super(context, theme);

        setCanceledOnTouchOutside(true);
        setCancelable(true);
        setContentView(R.layout.dialog_app_tips);
        tvTips = findViewById(R.id.tv_tips);
        tvKnow = findViewById(R.id.tv_know);

        tvKnow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

    }

    @Override
    public void show() {
        super.show();
        Window win = getWindow();
        WindowManager.LayoutParams lp = win.getAttributes();

        lp.gravity = Gravity.CENTER;

        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;

        final float scale = getContext().getResources().getDisplayMetrics().density;
        lp.width = (int) (280 * scale + 0.5f);

        win.setAttributes(lp);

    }

    public void setTip(@StringRes int tips) {
        tvTips.setText(tips);
    }

    public void setTip(String tips) {
        tvTips.setText(tips);
    }
}
