NoBindPhoneDialog.java 1.71 KB
Newer Older
1
package com.ydl.ydlcommon.view;
konghaorui committed
2 3 4 5

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
YKai committed
6
import androidx.annotation.NonNull;
konghaorui committed
7 8 9 10 11
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

12
import com.ydl.ydlcommon.R;
konghaorui committed
13 14 15 16 17 18 19 20 21 22 23

/**
 * Created by jiucheng on 2018/7/13.
 * 功能:
 */

public class NoBindPhoneDialog extends Dialog {
    private Context context; //上下文对象
    private OnBindPhoneListener listener;

    public NoBindPhoneDialog(@NonNull Context context, OnBindPhoneListener listener) {
konghaorui committed
24
        super(context, R.style.platform_normaldialog_style);
konghaorui committed
25 26 27
        this.context = context;
        this.listener = listener;

28
        View view = LayoutInflater.from(context).inflate(R.layout.platform_dialog_no_bind_phone, null);
konghaorui committed
29 30 31 32 33 34 35 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
        RoundCornerButton bind = view.findViewById(R.id.btn_bind);
        bind.setOnClickListener(v -> {
            if (this.listener != null) {
                this.listener.bindPhone();
            }
            dismiss();
        });
        setContentView(view);
    }

    @Override
    public void show() {
        if (null == context){
            return;
        }
        if (context instanceof Activity){
            if (((Activity)context).isFinishing()){
                return;
            }
        }
        super.show();
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = ViewGroup.LayoutParams.MATCH_PARENT;
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;

        getWindow().getDecorView().setPadding(0, 0, 0, 0);

        getWindow().setAttributes(params);
    }

    public interface OnBindPhoneListener {
        void bindPhone();
    }
}