1
1
package com .yoti .mobile .android .sdk .sampleapp ;
2
2
3
+ import android .annotation .SuppressLint ;
3
4
import android .content .Intent ;
5
+ import android .net .Uri ;
4
6
import android .os .Bundle ;
5
7
import android .text .Editable ;
6
8
import android .text .TextUtils ;
7
9
import android .text .TextWatcher ;
8
10
import android .view .View ;
9
- import android .view . View . OnFocusChangeListener ;
11
+ import android .widget . RadioGroup ;
10
12
import android .widget .TextView ;
13
+ import android .widget .ViewFlipper ;
11
14
12
15
import androidx .annotation .StringRes ;
13
16
import androidx .appcompat .app .AppCompatActivity ;
14
17
15
18
import com .yoti .mobile .android .sdk .YotiSDK ;
16
19
import com .yoti .mobile .android .sdk .YotiSDKButton ;
17
20
import com .yoti .mobile .android .sdk .exceptions .YotiSDKException ;
18
- import com .yoti .mobile .android .sdk .exceptions .YotiSDKNoYotiAppException ;
19
21
import com .yoti .mobile .android .sdk .exceptions .YotiSDKNotValidScenarioException ;
20
22
import com .yoti .mobile .android .sdk .model .Scenario ;
21
23
import com .yoti .mobile .android .sdk .sampleapp3 .R ;
22
24
25
+ import static com .yoti .mobile .android .sdk .sampleapp .ShareAttributesResultBroadcastReceiver .EXTRA_FULL_URL ;
26
+
23
27
public class MainActivity extends AppCompatActivity {
24
28
25
29
private static final String TAG = MainActivity .class .getSimpleName ();
26
30
31
+ private static final int YOTI_SDK_BUTTON = 0 ;
32
+ private static final int EASY_ID_SDK_BUTTON = 1 ;
33
+ private static final int PARTNERSHIP_SDK_BUTTON = 2 ;
34
+
27
35
private YotiSDKButton mYotiSDKButton ;
28
36
private View mStatusContainer ;
29
37
private TextView mStatusHeader ;
@@ -32,62 +40,108 @@ public class MainActivity extends AppCompatActivity {
32
40
private TextView mSdkEntry ;
33
41
private TextView mButtonTextEntry ;
34
42
private TextView mUseCaseEntry ;
43
+ private ViewFlipper mSdkButtonViewFlipper ;
35
44
45
+ @ SuppressLint ("NonConstantResourceId" )
36
46
@ Override
37
47
protected void onCreate (Bundle savedInstanceState ) {
38
48
super .onCreate (savedInstanceState );
39
49
40
50
setContentView (R .layout .activity_main );
41
51
YotiSDK .enableSDKLogging (true );
42
52
43
- mYotiSDKButton = findViewById (R .id .button );
44
53
mStatusContainer = findViewById (R .id .resultContainer );
45
54
mStatusHeader = findViewById (R .id .resultHeader );
46
55
mStatusMessage = findViewById (R .id .resultStatus );
47
56
mScenarioEntry = findViewById (R .id .scenarioIdText );
48
57
mSdkEntry = findViewById (R .id .sdkIdText );
49
58
mButtonTextEntry = findViewById (R .id .buttonLabelText );
50
59
mUseCaseEntry = findViewById (R .id .useCaseIdText );
51
- createScenario ();
52
60
53
61
mSdkEntry .addTextChangedListener (scenarioUpdateListener );
54
62
mScenarioEntry .addTextChangedListener (scenarioUpdateListener );
55
63
mUseCaseEntry .addTextChangedListener (scenarioUpdateListener );
56
64
mButtonTextEntry .addTextChangedListener (buttonTextListener );
57
65
58
- mYotiSDKButton .setOnYotiButtonClickListener (new YotiSDKButton .OnYotiButtonClickListener () {
66
+ mSdkButtonViewFlipper = findViewById (R .id .sdkButtonViewFlipper );
67
+ handleSDKButtonThemeSelection (PARTNERSHIP_SDK_BUTTON );
68
+
69
+ RadioGroup buttonSelectionRadioGroup = findViewById (R .id .buttonSelectionRadioGroup );
70
+ buttonSelectionRadioGroup .setOnCheckedChangeListener ((group , checkedId ) -> {
71
+ switch (checkedId ) {
72
+ case R .id .yotiRadioButton :
73
+ handleSDKButtonThemeSelection (YOTI_SDK_BUTTON );
74
+ break ;
75
+ case R .id .easyIdRadioButton :
76
+ handleSDKButtonThemeSelection (EASY_ID_SDK_BUTTON );
77
+ break ;
78
+ default :
79
+ handleSDKButtonThemeSelection (PARTNERSHIP_SDK_BUTTON );
80
+ break ;
81
+ }
82
+ });
83
+ }
84
+
85
+ private void handleSDKButtonThemeSelection (int selection ) {
86
+ switch (selection ) {
87
+ case YOTI_SDK_BUTTON :
88
+ YotiSDKButton yotiSdkButton = findViewById (R .id .yotiSDKButton );
89
+ mSdkButtonViewFlipper .setDisplayedChild (YOTI_SDK_BUTTON );
90
+ initSDKButton (yotiSdkButton );
91
+ break ;
92
+ case EASY_ID_SDK_BUTTON :
93
+ YotiSDKButton easyIdSdkButton = findViewById (R .id .easyIdSDKButton );
94
+ mSdkButtonViewFlipper .setDisplayedChild (EASY_ID_SDK_BUTTON );
95
+ initSDKButton (easyIdSdkButton );
96
+ break ;
97
+ case PARTNERSHIP_SDK_BUTTON :
98
+ YotiSDKButton partnershipSDKButton = findViewById (R .id .partnershipSDKButton );
99
+ mSdkButtonViewFlipper .setDisplayedChild (PARTNERSHIP_SDK_BUTTON );
100
+ initSDKButton (partnershipSDKButton );
101
+ break ;
102
+ }
103
+ }
104
+
105
+ private void initSDKButton (YotiSDKButton yotiSDKButton ) {
106
+ mYotiSDKButton = yotiSDKButton ;
107
+ createScenario ();
108
+
109
+ yotiSDKButton .setOnYotiButtonClickListener (new YotiSDKButton .OnYotiButtonClickListener () {
59
110
@ Override
60
111
public void onStartScenario () {
61
- mYotiSDKButton .setVisibility (View .GONE );
112
+ yotiSDKButton .setVisibility (View .GONE );
62
113
showStatus (true , R .string .result_status_startScenario );
63
114
}
64
115
65
116
@ Override
66
117
public void onStartScenarioError (YotiSDKException cause ) {
67
- mYotiSDKButton .setVisibility (View .VISIBLE );
118
+ yotiSDKButton .setVisibility (View .VISIBLE );
68
119
showStatus (false , R .string .result_status_startScenarioError );
69
120
}
70
121
});
71
122
72
- mYotiSDKButton .setOnYotiAppNotInstalledListener (new YotiSDKButton .OnYotiAppNotInstalledListener () {
73
- @ Override
74
- public void onYotiAppNotInstalledError (YotiSDKNoYotiAppException cause ) {
75
- //The Yoti app is not installed, let's deal with it
76
- mYotiSDKButton .setVisibility (View .VISIBLE );
77
- showStatus (false , R .string .result_status_appNotInstalled );
78
- }
123
+ yotiSDKButton .setOnAppNotInstalledListener ((cause , appURL ) -> {
124
+ yotiSDKButton .setVisibility (View .VISIBLE );
125
+ showStatus (false , R .string .result_status_appNotInstalled );
126
+ launchAppUrl (appURL );
79
127
});
80
128
81
- mYotiSDKButton .setOnYotiCalledListener (new YotiSDKButton .OnYotiCalledListener () {
82
- @ Override
83
- public void onYotiCalled () {
84
- // Restore the original state
85
- mYotiSDKButton .setVisibility (View .VISIBLE );
86
- showStatus (true , R .string .result_status_openYoti );
87
- }
129
+ yotiSDKButton .setOnYotiCalledListener (() -> {
130
+ // Restore the original state
131
+ yotiSDKButton .setVisibility (View .VISIBLE );
132
+ showStatus (true , R .string .result_status_openYoti );
88
133
});
89
134
}
90
135
136
+ // required app is not installed, launch app url to download the app
137
+ private void launchAppUrl (String redirectURL ) {
138
+ Uri webpage = Uri .parse (redirectURL );
139
+ Intent intent = new Intent (Intent .ACTION_VIEW , webpage );
140
+ if (intent .resolveActivity (getPackageManager ()) != null ) {
141
+ startActivity (intent );
142
+ }
143
+ }
144
+
91
145
@ Override
92
146
protected void onNewIntent (Intent intent ) {
93
147
super .onNewIntent (intent );
@@ -114,7 +168,7 @@ private void processExtraData(Intent intent) {
114
168
}
115
169
116
170
if (intent .hasExtra (ShareAttributesResultBroadcastReceiver .EXTRA_LOADING )) {
117
- showStatus (true , R .string .result_status_loading );
171
+ showStatus (true , R .string .result_status_loading , " \n \n FULL_URL - " + intent . getStringExtra ( EXTRA_FULL_URL ) );
118
172
}
119
173
}
120
174
@@ -152,16 +206,22 @@ private void createScenario() {
152
206
private void showStatus (boolean success , @ StringRes int message ) {
153
207
mStatusContainer .setVisibility (View .VISIBLE );
154
208
if (success ) {
155
- mStatusContainer .setBackgroundColor (getResources ().getColor (R .color .YotiGreen ));
209
+ mStatusContainer .setBackgroundColor (getResources ().getColor (R .color .yoti_green ));
156
210
mStatusHeader .setText (R .string .result_header_success );
157
211
}else {
158
- mStatusContainer .setBackgroundColor (getResources ().getColor (R .color .YotiRed ));
212
+ mStatusContainer .setBackgroundColor (getResources ().getColor (R .color .yoti_red ));
159
213
mStatusHeader .setText (R .string .result_header_error );
160
214
}
161
215
162
216
mStatusMessage .setText (message );
163
217
}
164
218
219
+ private void showStatus (boolean success , @ StringRes int messageResId , String messageText ) {
220
+ showStatus (success , messageResId );
221
+
222
+ mStatusMessage .setText (String .format ("%s %s" , getString (messageResId ), messageText ));
223
+ }
224
+
165
225
private void hideStatus () {
166
226
mStatusContainer .setVisibility (View .INVISIBLE );
167
227
}
@@ -196,7 +256,7 @@ public void onTextChanged(final CharSequence s, final int start, final int befor
196
256
197
257
@ Override
198
258
public void afterTextChanged (final Editable s ) {
199
- mYotiSDKButton . setText ( s . toString ());
259
+
200
260
}
201
261
};
202
262
}
0 commit comments