1515import android .media .MediaPlayer ;
1616import android .provider .Settings ;
1717import java .util .List ;
18+ import java .util .Timer ;
19+ import java .util .TimerTask ;
20+
1821import android .app .Activity ;
1922
2023import androidx .appcompat .app .AppCompatActivity ;
@@ -36,16 +39,29 @@ public class UnlockScreenActivity extends AppCompatActivity implements UnlockScr
3639 private TextView tvName ;
3740 private TextView tvInfo ;
3841 private ImageView ivAvatar ;
42+ private Integer timeout = 0 ;
3943 private String uuid = "" ;
4044 static boolean active = false ;
4145 private static Vibrator v = (Vibrator ) IncomingCallModule .reactContext .getSystemService (Context .VIBRATOR_SERVICE );
4246 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 );
4448 private static Activity fa ;
49+ private Timer timer ;
50+
4551
4652 @ Override
4753 public void onStart () {
4854 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+ }
4965 active = true ;
5066 }
5167
@@ -86,6 +102,10 @@ protected void onCreate(Bundle savedInstanceState) {
86102 Picasso .get ().load (avatar ).transform (new CircleTransform ()).into (ivAvatar );
87103 }
88104 }
105+ if (bundle .containsKey ("timeout" )) {
106+ this .timeout = bundle .getInt ("timeout" );
107+ }
108+ else this .timeout = 0 ;
89109 }
90110
91111 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() {
130150 // Dont back
131151 }
132152
133- public static void dismissIncoming () {
153+ public void dismissIncoming () {
134154 v .cancel ();
135155 player .stop ();
136156 player .prepareAsync ();
137- fa . finish ();
157+ dismissDialing ();
138158 }
139159
140160 private void acceptDialing () {
141161 WritableMap params = Arguments .createMap ();
142162 params .putBoolean ("accept" , true );
143163 params .putString ("uuid" , uuid );
164+ if (timer != null ){
165+ timer .cancel ();
166+ }
144167 if (!IncomingCallModule .reactContext .hasCurrentActivity ()) {
145168 params .putBoolean ("isHeadless" , true );
146169 }
@@ -165,6 +188,9 @@ private void dismissDialing() {
165188 WritableMap params = Arguments .createMap ();
166189 params .putBoolean ("accept" , false );
167190 params .putString ("uuid" , uuid );
191+ if (timer != null ) {
192+ timer .cancel ();
193+ }
168194 if (!IncomingCallModule .reactContext .hasCurrentActivity ()) {
169195 params .putBoolean ("isHeadless" , true );
170196 }
0 commit comments