lzw
2024-02-27 9efba3e1d69fb7540707f8f7293714c3a319766e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.fwupgrade.saymanss.view;
 
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;
 
import com.fwupgrade.saymanss.R;
 
import java.io.File;
 
 
/**
 * 带标题通用性dialog
 */
 
public class GeneralDialog extends Dialog implements View.OnClickListener {
 
    /** ok 按钮点击 */
    public static final int BUTTON_CLICK_OK = 200;
    public static final int BUTTON_CLICK_CANCEL = 201;
 
    private Context mContext;
    /** titleId */
    private String mTitle;
    /** file */
    private File mFile;
    /** 消息传递 */
    private Handler mHandler;
    /** dialog 标题 */
    private TextView mDialogTitle;
    /** dialog 内容 */
    private TextView mDialogContent;
    /** dialog 按键 */
    private BaseButtonDialog mBtnOkOrCancel;
 
    public GeneralDialog(@NonNull Context context) {
        super(context);
    }
 
    public GeneralDialog(Context context, int themeResId, Handler handler, String title, File file) {
        super(context, themeResId);
        this.mContext = context;
        this.mHandler = handler;
        this.mTitle = title;
        this.mFile = file;
    }
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_universal_layout);
 
        initView();
        initListener();
    }
 
    /**
     * 初始化view
     */
    private void initView() {
        mDialogTitle = (TextView) findViewById(R.id.dialog_universal_title);
        mDialogContent = (TextView) findViewById(R.id.dialog_universal_content);
        mDialogTitle.setText(mTitle);
        mBtnOkOrCancel = (BaseButtonDialog) findViewById(R.id.dialog_universal_button);
 
        if (mFile != null) {
            mDialogContent.setVisibility(View.VISIBLE);
            mDialogContent.setText(mFile.getName());
        }
    }
 
    /**
     *设置监听
     */
    private void initListener() {
        mBtnOkOrCancel.setBtnOnClickListener(this);
    }
 
    @Override
    public void onClick(View view) {
        if (view.getId() == mBtnOkOrCancel.getBaseDialogCancelbtn()) {
 
            //取消操作
            this.dismiss();
 
        } else if (view.getId() == mBtnOkOrCancel.getBaseDialogOKbtn()) {
 
            //确认
            this.dismiss();
 
            Message msg = Message.obtain();
            msg.what = BUTTON_CLICK_OK;
            msg.obj = mFile;
            mHandler.sendMessage(msg);
        }
    }
}