hc
2023-08-30 862c27fc9920c83318c784bfdadf43a65df1ec8f
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
package com.rockchip.smart.rockhome.view;
 
import android.app.Activity;
import android.app.Dialog;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;
 
import com.rockchip.smart.rockhome.R;
 
/**
 * 自定义透明的dialog
 */
public class LoadingView extends Dialog {
    private Activity mActivity;
    private TextView mTvContent;
    private String mContent;
 
    public LoadingView(Activity activity) {
        this(activity, null);
    }
 
    public LoadingView(Activity activity, String content) {
        super(activity, R.style.LoadingView);
        setContentView(R.layout.loading_view);
 
        setCancelable(false);
 
        this.mActivity = activity;
        this.mContent=content;
        initView();
    }
 
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode){
            case KeyEvent.KEYCODE_BACK:
                if(LoadingView.this.isShowing())
                    LoadingView.this.dismiss();
                break;
        }
        return true;
    }
 
    private void initView(){
        mTvContent = ((TextView) findViewById(R.id.tvcontent));
        if (mContent != null && !mContent.isEmpty()) {
            mTvContent.setVisibility(View.VISIBLE);
            mTvContent.setText(mContent);
        } else {
            mTvContent.setVisibility(View.GONE);
        }
    }
 
    @Override
    public void show() {
        show(mContent);
    }
 
    public void show(String content) {
        if (content != null && !content.isEmpty())
            mContent = content;
 
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (mContent != null && !mContent.isEmpty()) {
                    mTvContent.setVisibility(View.VISIBLE);
                    mTvContent.setText(mContent == null ? "" : mContent);
                } else {
                    mTvContent.setVisibility(View.GONE);
                }
                LoadingView.super.show();
            }
        });
    }
 
    @Override
    public void dismiss() {
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                LoadingView.super.dismiss();
            }
        });
    }
}