15
15
import android .media .MediaPlayer ;
16
16
import android .provider .Settings ;
17
17
import java .util .List ;
18
+ import java .util .Timer ;
19
+ import java .util .TimerTask ;
20
+
18
21
import android .app .Activity ;
19
22
20
23
import androidx .appcompat .app .AppCompatActivity ;
@@ -36,16 +39,29 @@ public class UnlockScreenActivity extends AppCompatActivity implements UnlockScr
36
39
private TextView tvName ;
37
40
private TextView tvInfo ;
38
41
private ImageView ivAvatar ;
42
+ private Integer timeout = 0 ;
39
43
private String uuid = "" ;
40
44
static boolean active = false ;
41
45
private static Vibrator v = (Vibrator ) IncomingCallModule .reactContext .getSystemService (Context .VIBRATOR_SERVICE );
42
46
private long [] pattern = {0 , 1000 , 800 };
43
- private static MediaPlayer player = MediaPlayer .create (IncomingCallModule .reactContext . getApplicationContext () , Settings .System .DEFAULT_RINGTONE_URI );
47
+ private static MediaPlayer player = MediaPlayer .create (IncomingCallModule .reactContext , Settings .System .DEFAULT_RINGTONE_URI );
44
48
private static Activity fa ;
49
+ private Timer timer ;
50
+
45
51
46
52
@ Override
47
53
public void onStart () {
48
54
super .onStart ();
55
+ if (this .timeout > 0 ) {
56
+ this .timer = new Timer ();
57
+ this .timer .schedule (new TimerTask () {
58
+ @ Override
59
+ public void run () {
60
+ // this code will be executed after timeout seconds
61
+ dismissIncoming ();
62
+ }
63
+ }, timeout );
64
+ }
49
65
active = true ;
50
66
}
51
67
@@ -86,6 +102,10 @@ protected void onCreate(Bundle savedInstanceState) {
86
102
Picasso .get ().load (avatar ).transform (new CircleTransform ()).into (ivAvatar );
87
103
}
88
104
}
105
+ if (bundle .containsKey ("timeout" )) {
106
+ this .timeout = bundle .getInt ("timeout" );
107
+ }
108
+ else this .timeout = 0 ;
89
109
}
90
110
91
111
getWindow ().addFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN | WindowManager .LayoutParams .FLAG_TURN_SCREEN_ON | WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON
@@ -130,17 +150,20 @@ public void onBackPressed() {
130
150
// Dont back
131
151
}
132
152
133
- public static void dismissIncoming () {
153
+ public void dismissIncoming () {
134
154
v .cancel ();
135
155
player .stop ();
136
156
player .prepareAsync ();
137
- fa . finish ();
157
+ dismissDialing ();
138
158
}
139
159
140
160
private void acceptDialing () {
141
161
WritableMap params = Arguments .createMap ();
142
162
params .putBoolean ("accept" , true );
143
163
params .putString ("uuid" , uuid );
164
+ if (timer != null ){
165
+ timer .cancel ();
166
+ }
144
167
if (!IncomingCallModule .reactContext .hasCurrentActivity ()) {
145
168
params .putBoolean ("isHeadless" , true );
146
169
}
@@ -165,6 +188,9 @@ private void dismissDialing() {
165
188
WritableMap params = Arguments .createMap ();
166
189
params .putBoolean ("accept" , false );
167
190
params .putString ("uuid" , uuid );
191
+ if (timer != null ) {
192
+ timer .cancel ();
193
+ }
168
194
if (!IncomingCallModule .reactContext .hasCurrentActivity ()) {
169
195
params .putBoolean ("isHeadless" , true );
170
196
}
0 commit comments