1
1
package com .yoti .mobile .android .sdk .sampleapp ;
2
2
3
+ import android .content .Intent ;
3
4
import android .support .v7 .app .AppCompatActivity ;
4
5
import android .os .Bundle ;
5
6
import android .view .View ;
@@ -14,67 +15,85 @@ public class MainActivity extends AppCompatActivity {
14
15
15
16
private static final String TAG = MainActivity .class .getSimpleName ();
16
17
18
+ private YotiSDKButton mYotiSDKButton ;
19
+ private ProgressBar mProgress ;
20
+ private TextView mMessage ;
21
+
17
22
@ Override
18
23
protected void onCreate (Bundle savedInstanceState ) {
19
24
super .onCreate (savedInstanceState );
20
25
21
26
setContentView (R .layout .activity_main );
22
27
23
- final YotiSDKButton yotiSDKButton = (YotiSDKButton ) findViewById (R .id .button );
24
- final ProgressBar progress = (ProgressBar ) findViewById (R .id .progress );
25
- final TextView message = (TextView )findViewById (R .id .text );
28
+ mYotiSDKButton = (YotiSDKButton ) findViewById (R .id .button );
29
+ mProgress = (ProgressBar ) findViewById (R .id .progress );
30
+ mMessage = (TextView )findViewById (R .id .text );
26
31
27
- yotiSDKButton .setOnYotiButtonClickListener (new YotiSDKButton .OnYotiButtonClickListener () {
32
+ mYotiSDKButton .setOnYotiButtonClickListener (new YotiSDKButton .OnYotiButtonClickListener () {
28
33
@ Override
29
34
public void onStartScenario () {
30
- yotiSDKButton .setVisibility (View .GONE );
31
- progress .setVisibility (View .VISIBLE );
32
- message .setText (null );
35
+ mYotiSDKButton .setVisibility (View .GONE );
36
+ mProgress .setVisibility (View .VISIBLE );
37
+ mMessage .setText (null );
33
38
}
34
39
35
40
@ Override
36
41
public void onStartScenarioError (YotiSDKException cause ) {
37
- yotiSDKButton .setVisibility (View .VISIBLE );
38
- progress .setVisibility (View .GONE );
39
- message .setText (R .string .loc_error_unknow );
42
+ mYotiSDKButton .setVisibility (View .VISIBLE );
43
+ mProgress .setVisibility (View .GONE );
44
+ mMessage .setText (R .string .loc_error_unknow );
40
45
}
41
46
});
42
47
43
- yotiSDKButton .setOnYotiAppNotInstalledListener (new YotiSDKButton .OnYotiAppNotInstalledListener () {
48
+ mYotiSDKButton .setOnYotiAppNotInstalledListener (new YotiSDKButton .OnYotiAppNotInstalledListener () {
44
49
@ Override
45
50
public void onYotiAppNotInstalledError (YotiSDKNoYotiAppException cause ) {
46
51
//The Yoti app is not installed, let's deal with it
47
- yotiSDKButton .setVisibility (View .VISIBLE );
48
- progress .setVisibility (View .GONE );
49
- message .setText (R .string .loc_no_yoti_app_error );
52
+ mYotiSDKButton .setVisibility (View .VISIBLE );
53
+ mProgress .setVisibility (View .GONE );
54
+ mMessage .setText (R .string .loc_no_yoti_app_error );
50
55
}
51
56
});
52
57
53
- yotiSDKButton .setOnYotiCalledListener (new YotiSDKButton .OnYotiCalledListener () {
58
+ mYotiSDKButton .setOnYotiCalledListener (new YotiSDKButton .OnYotiCalledListener () {
54
59
@ Override
55
60
public void onYotiCalled () {
56
61
// Restore the original state
57
- yotiSDKButton .setVisibility (View .VISIBLE );
58
- progress .setVisibility (View .GONE );
62
+ mYotiSDKButton .setVisibility (View .VISIBLE );
63
+ mProgress .setVisibility (View .GONE );
59
64
}
60
65
});
66
+ }
67
+
68
+ @ Override
69
+ protected void onNewIntent (Intent intent ) {
70
+ super .onNewIntent (intent );
71
+ setIntent (intent );
72
+ processExtraData (intent );
73
+ }
61
74
62
- if (getIntent ().hasExtra (ShareAttributesResultBroadcastReceiver .EXTRA_CANCELLED_BY_USER )) {
63
- yotiSDKButton .setVisibility (View .VISIBLE );
64
- progress .setVisibility (View .GONE );
65
- message .setText (R .string .loc_error_not_completed_on_yoti );
75
+ private void processExtraData (Intent intent ) {
76
+ if (intent .hasExtra (ShareAttributesResultBroadcastReceiver .EXTRA_CANCELLED_BY_USER )) {
77
+ mYotiSDKButton .setVisibility (View .VISIBLE );
78
+ mProgress .setVisibility (View .GONE );
79
+ mMessage .setText (R .string .loc_error_not_completed_on_yoti );
66
80
}
67
81
68
- if (getIntent () .hasExtra (ShareAttributesResultBroadcastReceiver .EXTRA_IS_FAILED )) {
69
- yotiSDKButton .setVisibility (View .VISIBLE );
70
- progress .setVisibility (View .GONE );
71
- message .setText (R .string .loc_error_unknow );
82
+ if (intent .hasExtra (ShareAttributesResultBroadcastReceiver .EXTRA_IS_FAILED )) {
83
+ mYotiSDKButton .setVisibility (View .VISIBLE );
84
+ mProgress .setVisibility (View .GONE );
85
+ mMessage .setText (R .string .loc_error_unknow );
72
86
}
73
87
74
- if (getIntent ().hasExtra (ShareAttributesResultBroadcastReceiver .EXTRA_RESPONSE )) {
75
- String phone = getIntent ().getStringExtra (ShareAttributesResultBroadcastReceiver .EXTRA_RESPONSE );
76
- message .setText (String .format (getString (R .string .loc_phone_number ), phone ));
88
+ if (intent .hasExtra (ShareAttributesResultBroadcastReceiver .EXTRA_RESPONSE )) {
89
+ String response = getIntent ().getStringExtra (ShareAttributesResultBroadcastReceiver .EXTRA_RESPONSE );
90
+ if (response != null ) {
91
+ mMessage .setText (R .string .loc_success_status );
92
+ }
77
93
}
78
- }
79
94
95
+ if (intent .hasExtra (ShareAttributesResultBroadcastReceiver .EXTRA_LOADING )) {
96
+ mMessage .setText (R .string .loc_loading_status );
97
+ }
98
+ }
80
99
}
0 commit comments