-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaitActivity.java
More file actions
165 lines (141 loc) · 6.83 KB
/
WaitActivity.java
File metadata and controls
165 lines (141 loc) · 6.83 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package com.example.yuta.ringflashwithoutuisample;
import android.content.Intent;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.MenuItem;
import android.widget.Toast;
import com.thrivecom.ringcaptcha.ringflashsdk.RingFlashSDK;
import com.thrivecom.ringcaptcha.ringflashsdk.handler.RingFlashVerificationHandler;
import com.thrivecom.ringcaptcha.ringflashsdk.http.RingFlashAPIController;
import com.thrivecom.ringcaptcha.ringflashsdk.http.RingFlashAPIHandler;
import com.thrivecom.ringcaptcha.ringflashsdk.interceptor.RingFlashInterceptionHandler;
import com.thrivecom.ringcaptcha.ringflashsdk.model.RingFlashCredentials;
import com.thrivecom.ringcaptcha.ringflashsdk.model.RingFlashResponse;
public class WaitActivity extends AppCompatActivity {
private RingFlashSDK _flashCallSDK = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wait);
// Get the Intent that started this activity and extract the string
Intent intent = getIntent();
String number_text = intent.getStringExtra(MainActivity.RINGCAPTCHA_PHONE_NUMBER);
// Verify
verifyWithoutUi(MainActivity.RINGCAPTCHA_APP_KEY, MainActivity.RINGCAPTCHA_SECRET_KEY, number_text);
}
@Override
public void onBackPressed() {
// Clear intercepting
if (_flashCallSDK != null) {
_flashCallSDK.stopCellularBroadcastIntercepting();
}
super.onBackPressed();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
// Clear intercepting
if (_flashCallSDK != null) {
_flashCallSDK.stopCellularBroadcastIntercepting();
}
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
private void verifyWithoutUi(final String app_key, final String secret_key, final String number) {
final RingFlashCredentials credentials = new RingFlashCredentials();
credentials.setSecretKey(secret_key);
credentials.setAppKey(app_key);
credentials.setPhoneNumber(number);
RingFlashAPIHandler ringFlashAPIHandler = new RingFlashAPIHandler() {
@Override
public void onSuccess(RingFlashResponse response) {
Log.i(MainActivity.TAG, response.toString());
boolean callRequested = response.checkStatus();
if (callRequested) {
RingFlashInterceptionHandler interceptionHandler = new RingFlashInterceptionHandler() {
@Override
public void onCallEnded(String callerNumber) {
RingFlashAPIHandler ringFlashAPIHandler1 = new RingFlashAPIHandler() {
@Override
public void onSuccess(RingFlashResponse response) {
Log.i(MainActivity.TAG, response.toString());
String message = "";
boolean is_verified = response.checkStatus();
if (is_verified) {
message = "VERIFIED!";
} else {
message = response.getMessage() == null ? "ERROR_DEFAULT_MESSAGE" : response.getMessage();
Log.i(MainActivity.TAG, message);
}
Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
_flashCallSDK.stopCellularBroadcastIntercepting();
finish();
}
@Override
public void onError(Exception exception) {
Log.i(MainActivity.TAG, exception.getMessage());
_flashCallSDK.stopCellularBroadcastIntercepting();
//TODO
}
};
RingFlashAPIController ringFlashAPIController = new RingFlashAPIController(getApplicationContext());
ringFlashAPIController.requestVerification(credentials, callerNumber, ringFlashAPIHandler1);
}
};
_flashCallSDK = RingFlashSDK.builder()
.setContext(getApplicationContext())
.setSecretKey(secret_key)
.setAppKey(app_key)
.setHandler(getEmptyHandler())
.setPhoneNumber(number)
.build();
_flashCallSDK.startCellularBroadcastIntercepting(interceptionHandler);
} else {
String error = response.getMessage() == null ? "ERROR_DEFAULT_MESSAGE" : response.getMessage();
Log.i(MainActivity.TAG, error);
Toast toast = Toast.makeText(getApplicationContext(), error, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
finish();
}
}
@Override
public void onError(Exception exception) {
//TODO
}
};
RingFlashAPIController ringFlashAPIController = new RingFlashAPIController(getApplicationContext());
ringFlashAPIController.requestVoiceCall(credentials, ringFlashAPIHandler);
}
private static RingFlashVerificationHandler getEmptyHandler() {
return new RingFlashVerificationHandler() {
@Override
public void onVerified() {
}
@Override
public void onVerificationFailed(RingFlashResponse response) {
}
@Override
public void onError(Exception e) {
}
@Override
public void onFlashCallRequested(RingFlashResponse response) {
}
@Override
public void onFlashCallRequestedFailed(RingFlashResponse response) {
}
@Override
public void onVerificationInitiated() {
}
};
}
}