Skip to content

Commit 95b966a

Browse files
authored
Merge pull request #17 from getyoti/sample-3
Create sample app with id entry
2 parents 20a317f + 03e86f9 commit 95b966a

23 files changed

+521
-1
lines changed

.github/workflows/pr.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,11 @@ jobs:
4545
with:
4646
name: sample-2
4747
path: "sample-app-2/build/outputs/apk/"
48+
49+
- name: Build sample-3
50+
run: ./gradlew sample-app-3:assembleDebug --no-daemon
51+
- name: Upload sample-3
52+
uses: actions/upload-artifact@v1
53+
with:
54+
name: sample-3
55+
path: "sample-app-3/build/outputs/apk/"

sample-app-3/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

sample-app-3/build.gradle

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion parent.ext.androidCompileSdkVersion
5+
6+
defaultConfig {
7+
applicationId "com.yoti.mobile.android.button.sdk.sampleapp3"
8+
minSdkVersion parent.ext.androidMinSdkVersion
9+
targetSdkVersion parent.ext.androidTargetSdkVersion
10+
versionCode 1
11+
versionName "1.0"
12+
}
13+
14+
signingConfigs {
15+
debug {
16+
storeFile file('debug.keystore')
17+
keyAlias 'androiddebugkey'
18+
keyPassword 'android'
19+
storePassword 'android'
20+
}
21+
release {
22+
storeFile file('debug.keystore')
23+
keyAlias 'androiddebugkey'
24+
keyPassword 'android'
25+
storePassword 'android'
26+
}
27+
}
28+
29+
buildTypes {
30+
debug {
31+
signingConfig signingConfigs.debug
32+
debuggable true
33+
versionNameSuffix "-SNAPSHOT"
34+
}
35+
36+
release {
37+
minifyEnabled false
38+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
39+
signingConfig signingConfigs.release
40+
}
41+
}
42+
}
43+
44+
45+
dependencies {
46+
implementation parent.ext.libAndroidSupport
47+
testImplementation 'junit:junit:4.12'
48+
49+
implementation project(path: ':yoti-sdk')
50+
51+
52+
// Use this version if you want to point at the dependency published on mavenCentral
53+
//implementation("com.yoti.mobile.android.sdk:yoti-button-sdk:1.1.0")
54+
}

sample-app-3/debug.keystore

1.23 KB
Binary file not shown.

sample-app-3/proguard-rules.pro

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/adrienviolet/Documents/opt/android-sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.yoti.mobile.android.sdk.sampleapp3">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/AppTheme">
14+
<activity android:name="com.yoti.mobile.android.sdk.sampleapp.MainActivity"
15+
android:launchMode="singleInstance">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
23+
<receiver android:name="com.yoti.mobile.android.sdk.sampleapp.ShareAttributesResultBroadcastReceiver" android:exported="false">
24+
<intent-filter>
25+
<action android:name="com.test.app.YOTI_CALLBACK" />
26+
<action android:name="com.test.app.BACKEND_CALLBACK" />
27+
</intent-filter>
28+
</receiver>
29+
</application>
30+
31+
</manifest>
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
package com.yoti.mobile.android.sdk.sampleapp;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.text.Editable;
6+
import android.text.TextUtils;
7+
import android.text.TextWatcher;
8+
import android.view.View;
9+
import android.view.View.OnFocusChangeListener;
10+
import android.widget.TextView;
11+
12+
import androidx.annotation.StringRes;
13+
import androidx.appcompat.app.AppCompatActivity;
14+
15+
import com.yoti.mobile.android.sdk.YotiSDK;
16+
import com.yoti.mobile.android.sdk.YotiSDKButton;
17+
import com.yoti.mobile.android.sdk.exceptions.YotiSDKException;
18+
import com.yoti.mobile.android.sdk.exceptions.YotiSDKNoYotiAppException;
19+
import com.yoti.mobile.android.sdk.exceptions.YotiSDKNotValidScenarioException;
20+
import com.yoti.mobile.android.sdk.model.Scenario;
21+
import com.yoti.mobile.android.sdk.sampleapp3.R;
22+
23+
public class MainActivity extends AppCompatActivity {
24+
25+
private static final String TAG = MainActivity.class.getSimpleName();
26+
27+
private YotiSDKButton mYotiSDKButton;
28+
private View mStatusContainer;
29+
private TextView mStatusHeader;
30+
private TextView mStatusMessage;
31+
private TextView mScenarioEntry;
32+
private TextView mSdkEntry;
33+
private TextView mButtonTextEntry;
34+
private TextView mUseCaseEntry;
35+
36+
@Override
37+
protected void onCreate(Bundle savedInstanceState) {
38+
super.onCreate(savedInstanceState);
39+
40+
setContentView(R.layout.activity_main);
41+
YotiSDK.enableSDKLogging(true);
42+
43+
mYotiSDKButton = findViewById(R.id.button);
44+
mStatusContainer = findViewById(R.id.resultContainer);
45+
mStatusHeader = findViewById(R.id.resultHeader);
46+
mStatusMessage = findViewById(R.id.resultStatus);
47+
mScenarioEntry = findViewById(R.id.scenarioIdText);
48+
mSdkEntry = findViewById(R.id.sdkIdText);
49+
mButtonTextEntry = findViewById(R.id.buttonLabelText);
50+
mUseCaseEntry = findViewById(R.id.useCaseIdText);
51+
createScenario();
52+
53+
mSdkEntry.setOnFocusChangeListener(scenarioChangeListener);
54+
mScenarioEntry.setOnFocusChangeListener(scenarioChangeListener);
55+
mUseCaseEntry.setOnFocusChangeListener(scenarioChangeListener);
56+
mButtonTextEntry.addTextChangedListener(buttonTextListener);
57+
58+
mYotiSDKButton.setOnYotiButtonClickListener(new YotiSDKButton.OnYotiButtonClickListener() {
59+
@Override
60+
public void onStartScenario() {
61+
mYotiSDKButton.setVisibility(View.GONE);
62+
showStatus(true, R.string.result_status_startScenario);
63+
}
64+
65+
@Override
66+
public void onStartScenarioError(YotiSDKException cause) {
67+
mYotiSDKButton.setVisibility(View.VISIBLE);
68+
showStatus(false, R.string.result_status_startScenarioError);
69+
}
70+
});
71+
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+
}
79+
});
80+
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+
}
88+
});
89+
}
90+
91+
@Override
92+
protected void onNewIntent(Intent intent) {
93+
super.onNewIntent(intent);
94+
setIntent(intent);
95+
processExtraData(intent);
96+
}
97+
98+
private void processExtraData(Intent intent) {
99+
if (intent.hasExtra(ShareAttributesResultBroadcastReceiver.EXTRA_CANCELLED_BY_USER)) {
100+
mYotiSDKButton.setVisibility(View.VISIBLE);
101+
showStatus(false, R.string.result_status_cancel);
102+
}
103+
104+
if (intent.hasExtra(ShareAttributesResultBroadcastReceiver.EXTRA_IS_FAILED)) {
105+
mYotiSDKButton.setVisibility(View.VISIBLE);
106+
showStatus(false, R.string.result_status_fail);
107+
}
108+
109+
if (intent.hasExtra(ShareAttributesResultBroadcastReceiver.EXTRA_RESPONSE)) {
110+
String response = getIntent().getStringExtra(ShareAttributesResultBroadcastReceiver.EXTRA_RESPONSE);
111+
if (response != null) {
112+
showStatus(true, R.string.result_status_success);
113+
}
114+
}
115+
116+
if (intent.hasExtra(ShareAttributesResultBroadcastReceiver.EXTRA_LOADING)) {
117+
showStatus(true, R.string.result_status_loading);
118+
}
119+
}
120+
121+
private OnFocusChangeListener scenarioChangeListener = new OnFocusChangeListener() {
122+
123+
@Override
124+
public void onFocusChange(final View v, final boolean hasFocus) {
125+
if (!hasFocus) {
126+
createScenario();
127+
}
128+
}
129+
};
130+
131+
private void createScenario() {
132+
hideStatus();
133+
mYotiSDKButton.setVisibility(View.INVISIBLE);
134+
135+
String sdkId = mSdkEntry.getText().toString();
136+
String scenarioId = mScenarioEntry.getText().toString();
137+
String useCaseId = mUseCaseEntry.getText().toString();
138+
139+
if (TextUtils.isEmpty(sdkId) || TextUtils.isEmpty(scenarioId) || TextUtils.isEmpty(useCaseId)) {
140+
return;
141+
}
142+
143+
Scenario scenario = null;
144+
145+
try {
146+
scenario = new Scenario.Builder()
147+
.setUseCaseId(useCaseId)
148+
.setClientSDKId(sdkId)
149+
.setScenarioId(scenarioId)
150+
.setCallbackAction("com.test.app.YOTI_CALLBACK")
151+
.setBackendCallbackAction("com.test.app.BACKEND_CALLBACK")
152+
.create();
153+
} catch (YotiSDKNotValidScenarioException e) {
154+
e.printStackTrace();
155+
}
156+
157+
YotiSDK.addScenario(scenario);
158+
mYotiSDKButton.setUseCaseId(useCaseId);
159+
mYotiSDKButton.setVisibility(View.VISIBLE);
160+
}
161+
162+
private void showStatus(boolean success, @StringRes int message) {
163+
mStatusContainer.setVisibility(View.VISIBLE);
164+
if (success) {
165+
mStatusContainer.setBackgroundColor(getResources().getColor(R.color.YotiGreen));
166+
mStatusHeader.setText(R.string.result_header_success);
167+
}else {
168+
mStatusContainer.setBackgroundColor(getResources().getColor(R.color.YotiRed));
169+
mStatusHeader.setText(R.string.result_header_error);
170+
}
171+
172+
mStatusMessage.setText(message);
173+
}
174+
175+
private void hideStatus() {
176+
mStatusContainer.setVisibility(View.INVISIBLE);
177+
}
178+
179+
private TextWatcher buttonTextListener = new TextWatcher() {
180+
181+
@Override
182+
public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
183+
}
184+
185+
@Override
186+
public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
187+
}
188+
189+
@Override
190+
public void afterTextChanged(final Editable s) {
191+
mYotiSDKButton.setText(s.toString());
192+
}
193+
};
194+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.yoti.mobile.android.sdk.sampleapp;
2+
3+
4+
import android.content.Intent;
5+
6+
import com.yoti.mobile.android.sdk.AbstractShareAttributesBroadcastReceiver;
7+
8+
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
9+
10+
/**
11+
* Example of a broadcast receiver implementing the {@link AbstractShareAttributesBroadcastReceiver}
12+
* In this example the call to the third party backend will be made by the Yoti Mobile SDK.
13+
*/
14+
public class ShareAttributesResultBroadcastReceiver extends AbstractShareAttributesBroadcastReceiver {
15+
16+
public static final String EXTRA_USE_CASE_ID = "com.yoti.mobile.android.sdk.EXTRA_USE_CASE_ID";
17+
public static final String EXTRA_CANCELLED_BY_USER = "com.yoti.mobile.android.sdk.EXTRA_CANCELLED_BY_USER";
18+
public static final String EXTRA_IS_FAILED = "com.yoti.mobile.android.sdk.EXTRA_IS_FAILED";
19+
public static final String EXTRA_RESPONSE = "com.yoti.mobile.android.sdk.EXTRA_RESPONSE";
20+
public static final String EXTRA_LOADING = "com.yoti.mobile.android.sdk.EXTRA_LOADING";
21+
22+
@Override
23+
public boolean onCallbackReceived(String useCaseId, String callbackRoot, String token, String fullUrl) {
24+
Intent intent = new Intent(mContext, MainActivity.class);
25+
intent.putExtra(EXTRA_LOADING, true);
26+
intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
27+
mContext.startActivity(intent);
28+
return false;
29+
}
30+
31+
@Override
32+
public void onShareFailed(String useCaseId) {
33+
Intent intent = new Intent(mContext, MainActivity.class);
34+
intent.putExtra(EXTRA_USE_CASE_ID, useCaseId);
35+
intent.putExtra(EXTRA_CANCELLED_BY_USER, true);
36+
intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
37+
mContext.startActivity(intent);
38+
}
39+
40+
@Override
41+
public void onCallbackSuccess(String useCaseId, byte[] response) {
42+
if (response != null) {
43+
Intent intent = new Intent(mContext, MainActivity.class);
44+
intent.putExtra(EXTRA_RESPONSE, new String(response));
45+
intent.putExtra(EXTRA_USE_CASE_ID, useCaseId);
46+
intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
47+
mContext.startActivity(intent);
48+
}
49+
}
50+
51+
@Override
52+
public void onCallbackError(String useCaseId, int httpErrorCode, Throwable error, byte[] response) {
53+
Intent intent = new Intent(mContext, MainActivity.class);
54+
intent.putExtra(EXTRA_IS_FAILED, true);
55+
intent.putExtra(EXTRA_USE_CASE_ID, useCaseId);
56+
intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
57+
mContext.startActivity(intent);
58+
}
59+
}

0 commit comments

Comments
 (0)