Skip to content

Commit 595b6f5

Browse files
committed
#Allowing applying the theme to SDK button
#YM-23299
1 parent 02517a5 commit 595b6f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1077
-161
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,18 @@ android:id="@+id/my_id"
7575
android:layout_height="wrap_content"
7676
android:layout_width="wrap_content"
7777
android:text="My Yoti Button"
78-
yoti:useCaseId="YOUR_USE_CASE_ID"/>
78+
yoti:useCaseId="YOUR_USE_CASE_ID"
79+
yoti:buttonTheme="<Theme_Yoti | Theme_EasyId | Theme_Partnership>"/>
7980
```
81+
82+
In case ```yoti:buttonTheme``` is not provided, then ```Theme_Partnership``` is considered as a default theme.
83+
84+
When the theme is applied as ```Theme_Yoti``` or ```Theme_Partnership```
85+
* User can share attribute either through Yoti or EasyId app
86+
87+
When the theme is applied as ```Theme_EasyId```
88+
* User can share attribute only through EasyId app
89+
8090
[See this code in one of our sample apps](./sample-app/src/main/res/layout/activity_main.xml)
8191

8292
Alternatively, you can set the button's useCaseId with:
@@ -218,6 +228,7 @@ If the Yoti app is not installed in the user's phone by default the SDK will sen
218228
open a website that invites the user to download the Yoti app.
219229
Alternatively, an error listener can be set up so you can deal with this situation by yourself.
220230

231+
Attention: This listener is now deprecated.
221232
```java
222233
yotiSDKButton.setOnYotiAppNotInstalledListener(new YotiSDKButton.OnYotiAppNotInstalledListener() {
223234
@Override
@@ -226,6 +237,16 @@ Alternatively, an error listener can be set up so you can deal with this situati
226237
}
227238
});
228239
```
240+
Please use the below listener to determine whether the Yoti/EasyId app is not installed:
241+
```java
242+
mYotiSDKButton.setOnAppNotInstalledListener(new OnAppNotInstalledListener() {
243+
@Override
244+
public void onAppNotInstalled(final YotiSDKAppNotInstalledException cause, final String appURL) {
245+
// appURL is the app's play store URL, launch the browser intent to allow user to download the app and proceed
246+
}
247+
});
248+
```
249+
[See this code in one of our sample apps](./sample-app/src/main/java/com/yoti/mobile/android/sdk/sampleapp/MainActivity.java)
229250

230251
## Running the Example
231252

gradle.properties

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
#org.gradle.daemon=true
2222

2323

24-
minSdkVersionVersion=15
24+
minSdkVersionVersion=21
2525
targetSdkVersion=28
2626
compileSdkVersion=28
2727

28-
yotiCommonUIVersion=0.0.5
28+
uiWidgetsVersion=1.9.0
2929
supportLibraryVersion=1.0.2
3030

3131
libJunitVersion=4.12
@@ -35,10 +35,23 @@ currentAppName=Mobile Button SDK
3535

3636
#Environment
3737
yotiAppPackage=com.yoti.mobile.android.live
38+
easyIdAppPackage=com.postofficeid.mobile.android.live
3839
yotiAppMinVersion=1622
3940
yotiBackendUrl=https://api.yoti.com
4041
yotiBackendPort=443
4142

43+
#app url
44+
yotiAppUrl=https://play.google.com/store/apps/details?id=com.yoti.mobile.android.live
45+
easyIdAppUrl=https://play.google.com/store/apps/details?id=com.postofficeid.mobile.android.live
46+
partnershipAppUrl=https://code.yoti.com/
47+
48+
#deeplink host url
49+
appHostUrl=code.yoti.com
50+
51+
#app scheme
52+
yotiAppScheme=yoti://
53+
easyIDScheme=easyid://
54+
4255
# Publication
4356
pomId=yoti-button-sdk
4457
pomGroup=com.yoti.mobile.android.sdk

sample-app-2/build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ android {
2121
}
2222
}
2323

24+
compileOptions {
25+
sourceCompatibility JavaVersion.VERSION_1_8
26+
targetCompatibility JavaVersion.VERSION_1_8
27+
}
2428
}
2529

2630
dependencies {
2731
implementation fileTree(dir: 'libs', include: ['*.jar'])
2832
implementation parent.ext.libAndroidSupport
29-
testImplementation 'junit:junit:4.12'
30-
implementation("com.yoti.mobile.android.sdk:yoti-button-sdk:1.1.0")
33+
//implementation("com.yoti.mobile.android.sdk:yoti-button-sdk:1.1.0")
34+
implementation project(path: ':yoti-sdk')
3135
implementation 'com.google.code.gson:gson:2.8.5'
3236
}

sample-app-2/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
<activity
1717
android:name="com.yoti.mobile.android.sampleapp2.MainActivity"
18-
android:launchMode="singleInstance">
18+
android:launchMode="singleInstance"
19+
android:theme="@style/SampleAppFullScreenTheme">
1920
<intent-filter>
2021
<action android:name="android.intent.action.MAIN" />
2122

sample-app-2/src/main/res/layout/activity_main.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
android:layout_centerVertical="true"
1616
android:layout_centerInParent="true"
1717
android:gravity="center"
18-
android:text=" Use Yoti"
1918
yoti:useCaseId="yoti_btn_1" />
2019

2120
<TextView
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<resources>
2+
3+
<style name="SampleAppFullScreenTheme" parent="AppTheme">
4+
<item name="android:background">@android:color/black</item>
5+
</style>
6+
7+
</resources>
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
<resources>
22

33
<!-- Base application theme. -->
4-
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
4+
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
55
<!-- Customize your theme here. -->
66
<item name="colorPrimary">@color/colorPrimary</item>
77
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
88
<item name="colorAccent">@color/colorAccent</item>
99
</style>
1010

11+
<style name="SampleAppFullScreenTheme" parent="AppTheme">
12+
<item name="android:background">@android:color/white</item>
13+
</style>
14+
1115
</resources>

sample-app-3/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ android {
1111
versionName "1.0"
1212
}
1313

14+
compileOptions {
15+
sourceCompatibility JavaVersion.VERSION_1_8
16+
targetCompatibility JavaVersion.VERSION_1_8
17+
}
18+
1419
signingConfigs {
1520
debug {
1621
storeFile file('debug.keystore')

sample-app-3/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
android:supportsRtl="true"
1313
android:theme="@style/AppTheme">
1414
<activity android:name="com.yoti.mobile.android.sdk.sampleapp.MainActivity"
15+
android:theme="@style/SampleAppTheme"
1516
android:launchMode="singleInstance">
1617
<intent-filter>
1718
<action android:name="android.intent.action.MAIN" />

sample-app-3/src/main/java/com/yoti/mobile/android/sdk/sampleapp/MainActivity.java

Lines changed: 85 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
package com.yoti.mobile.android.sdk.sampleapp;
22

3+
import android.annotation.SuppressLint;
34
import android.content.Intent;
5+
import android.net.Uri;
46
import android.os.Bundle;
57
import android.text.Editable;
68
import android.text.TextUtils;
79
import android.text.TextWatcher;
810
import android.view.View;
9-
import android.view.View.OnFocusChangeListener;
11+
import android.widget.RadioGroup;
1012
import android.widget.TextView;
13+
import android.widget.ViewFlipper;
1114

1215
import androidx.annotation.StringRes;
1316
import androidx.appcompat.app.AppCompatActivity;
1417

1518
import com.yoti.mobile.android.sdk.YotiSDK;
1619
import com.yoti.mobile.android.sdk.YotiSDKButton;
1720
import com.yoti.mobile.android.sdk.exceptions.YotiSDKException;
18-
import com.yoti.mobile.android.sdk.exceptions.YotiSDKNoYotiAppException;
1921
import com.yoti.mobile.android.sdk.exceptions.YotiSDKNotValidScenarioException;
2022
import com.yoti.mobile.android.sdk.model.Scenario;
2123
import com.yoti.mobile.android.sdk.sampleapp3.R;
2224

25+
import static com.yoti.mobile.android.sdk.sampleapp.ShareAttributesResultBroadcastReceiver.EXTRA_FULL_URL;
26+
2327
public class MainActivity extends AppCompatActivity {
2428

2529
private static final String TAG = MainActivity.class.getSimpleName();
2630

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+
2735
private YotiSDKButton mYotiSDKButton;
2836
private View mStatusContainer;
2937
private TextView mStatusHeader;
@@ -32,62 +40,108 @@ public class MainActivity extends AppCompatActivity {
3240
private TextView mSdkEntry;
3341
private TextView mButtonTextEntry;
3442
private TextView mUseCaseEntry;
43+
private ViewFlipper mSdkButtonViewFlipper;
3544

45+
@SuppressLint("NonConstantResourceId")
3646
@Override
3747
protected void onCreate(Bundle savedInstanceState) {
3848
super.onCreate(savedInstanceState);
3949

4050
setContentView(R.layout.activity_main);
4151
YotiSDK.enableSDKLogging(true);
4252

43-
mYotiSDKButton = findViewById(R.id.button);
4453
mStatusContainer = findViewById(R.id.resultContainer);
4554
mStatusHeader = findViewById(R.id.resultHeader);
4655
mStatusMessage = findViewById(R.id.resultStatus);
4756
mScenarioEntry = findViewById(R.id.scenarioIdText);
4857
mSdkEntry = findViewById(R.id.sdkIdText);
4958
mButtonTextEntry = findViewById(R.id.buttonLabelText);
5059
mUseCaseEntry = findViewById(R.id.useCaseIdText);
51-
createScenario();
5260

5361
mSdkEntry.addTextChangedListener(scenarioUpdateListener);
5462
mScenarioEntry.addTextChangedListener(scenarioUpdateListener);
5563
mUseCaseEntry.addTextChangedListener(scenarioUpdateListener);
5664
mButtonTextEntry.addTextChangedListener(buttonTextListener);
5765

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() {
59110
@Override
60111
public void onStartScenario() {
61-
mYotiSDKButton.setVisibility(View.GONE);
112+
yotiSDKButton.setVisibility(View.GONE);
62113
showStatus(true, R.string.result_status_startScenario);
63114
}
64115

65116
@Override
66117
public void onStartScenarioError(YotiSDKException cause) {
67-
mYotiSDKButton.setVisibility(View.VISIBLE);
118+
yotiSDKButton.setVisibility(View.VISIBLE);
68119
showStatus(false, R.string.result_status_startScenarioError);
69120
}
70121
});
71122

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);
79127
});
80128

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);
88133
});
89134
}
90135

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+
91145
@Override
92146
protected void onNewIntent(Intent intent) {
93147
super.onNewIntent(intent);
@@ -114,7 +168,7 @@ private void processExtraData(Intent intent) {
114168
}
115169

116170
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));
118172
}
119173
}
120174

@@ -152,16 +206,22 @@ private void createScenario() {
152206
private void showStatus(boolean success, @StringRes int message) {
153207
mStatusContainer.setVisibility(View.VISIBLE);
154208
if (success) {
155-
mStatusContainer.setBackgroundColor(getResources().getColor(R.color.YotiGreen));
209+
mStatusContainer.setBackgroundColor(getResources().getColor(R.color.yoti_green));
156210
mStatusHeader.setText(R.string.result_header_success);
157211
}else {
158-
mStatusContainer.setBackgroundColor(getResources().getColor(R.color.YotiRed));
212+
mStatusContainer.setBackgroundColor(getResources().getColor(R.color.yoti_red));
159213
mStatusHeader.setText(R.string.result_header_error);
160214
}
161215

162216
mStatusMessage.setText(message);
163217
}
164218

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+
165225
private void hideStatus() {
166226
mStatusContainer.setVisibility(View.INVISIBLE);
167227
}
@@ -196,7 +256,7 @@ public void onTextChanged(final CharSequence s, final int start, final int befor
196256

197257
@Override
198258
public void afterTextChanged(final Editable s) {
199-
mYotiSDKButton.setText(s.toString());
259+
200260
}
201261
};
202262
}

0 commit comments

Comments
 (0)