FlowTooBigDialog.java
3.31 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.wd.common.dialog;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.KeyEvent;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.wd.fastcoding.base.R;
/**
* created by wxl and 2022/8/2
*/
public class FlowTooBigDialog extends Dialog {
private final OnCloseClickListener mOnCloseClickListener;
private boolean isflowtoobig = true;
private Runnable runnable;
private Context context;
public boolean isIsflowtoobig() {
return isflowtoobig;
}
public void setIsflowtoobig(boolean isflowtoobig) {
this.isflowtoobig = isflowtoobig;
}
public FlowTooBigDialog(@NonNull Context context, OnCloseClickListener onCloseClickListener) {
super(context, R.style.AlertDialogStyle);
this.context = context;
mOnCloseClickListener = onCloseClickListener;
}
int secnum = -100;
TextView titlt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_flowbig_layout);
titlt = findViewById(R.id.titlt);
runnable = new Runnable() {
@Override
public void run() {
if (secnum != -100) {
if (secnum < 0) {
secnum = -100;
dismiss();
mOnCloseClickListener.back();
return;
}
// Log.e("!!!!", "secnum " + secnum);
titlt.setText(secnum-- + "");
handler.postDelayed(this, 1100);
}
}
};
setCancelable(false);
}
private Handler handler = new Handler(Looper.getMainLooper());
@Override
public void show() {
if(getContext() != null){
if(getContext() instanceof Activity){
Activity activity = (Activity) getContext();
if(!activity.isDestroyed() && !activity.isFinishing()){
super.show();
if (secnum == -100) {
secnum = 10;
handler.post(runnable);
}
}
}else{
super.show();
if (secnum == -100) {
secnum = 10;
handler.post(runnable);
}
}
}
}
@Override
public void dismiss() {
try{
if(context != null && isShowing()){
if(context instanceof Activity){
Activity activity = (Activity) context;
if(!activity.isDestroyed() && !activity.isFinishing()){
super.dismiss();
}
}else{
super.dismiss();
}
}
}catch (Exception e){
}
secnum = -100;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyDown(keyCode, event);
}
public interface OnCloseClickListener {
void back();
}
}