Skip to content

Commit ec51f2f

Browse files
Merge pull request #8 from OutSystems/fix/android15-edge-to-edge
Fix ::: Android 15 Edge-to-Edge
2 parents 4ae8a07 + 4bb5b3d commit ec51f2f

File tree

6 files changed

+90
-3
lines changed

6 files changed

+90
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased]
7+
## [1.1.2]
8+
### Fixes
9+
- Android 15 - Fix cropping of Card IO screens due to Edge-to-Edge
810

911
## [1.1.1]
1012
### Fixes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.os.mobile.cardio",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Plugin Read Card ID and to Scan Documents",
55
"cordova": {
66
"id": "com.os.mobile.cardio",

plugin.xml

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

33
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
44
id="com.os.mobile.cardio"
5-
version="1.1.1">
5+
version="1.1.2">
66
<name>Card.io Cordova Plugin</name>
77
<description>Plugin Read Card ID and to Scan Documents</description>
88
<author>OutSystems</author>
@@ -28,6 +28,7 @@
2828
</feature>
2929
</config-file>
3030
<source-file src="src/android/CardIoPlugin.java" target-dir="src/com/os/mobile/cardioplugin" />
31+
<source-file src="src/android/CardIoActivityLifecycleCallbacks.java" target-dir="src/com/os/mobile/cardioplugin" />
3132
<framework src="src/android/cardio.gradle" custom="true" type="gradleReference" />
3233
</platform> <!-- /Android -->
3334

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.os.mobile.cardioplugin;
2+
3+
import android.app.Activity;
4+
import android.app.Application;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
9+
import androidx.annotation.NonNull;
10+
import androidx.annotation.Nullable;
11+
import androidx.core.graphics.Insets;
12+
import androidx.core.view.ViewCompat;
13+
import androidx.core.view.WindowInsetsCompat;
14+
15+
import io.card.payment.CardIOActivity;
16+
import io.card.payment.DataEntryActivity;
17+
18+
/**
19+
* Listener for Card IO Activities lifecycle.
20+
* The main goal being to fix the insets on Android 15 (since edge-to-edge is enforced with targetSdk=35).
21+
* Checks when an activity is in foreground (onResume), and applying the proper insets to the root layout.
22+
* This way, there is no need to provide a custom implementation/fork of Card IO.
23+
*/
24+
public class CardIoActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {
25+
@Override
26+
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {}
27+
28+
@Override
29+
public void onActivityStarted(@NonNull Activity activity) {}
30+
31+
32+
@Override
33+
public void onActivityResumed(@NonNull Activity activity) {
34+
if (!(activity instanceof CardIOActivity || activity instanceof DataEntryActivity)) {
35+
return;
36+
}
37+
View activityLayoutRootView =
38+
((ViewGroup) activity.getWindow().getDecorView().getRootView()).getChildAt(0);
39+
if (activityLayoutRootView != null) {
40+
ViewCompat.setOnApplyWindowInsetsListener(
41+
activityLayoutRootView,
42+
(v, insets) -> {
43+
Insets systemBarInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars());
44+
v.setPadding(
45+
systemBarInsets.left,
46+
systemBarInsets.top,
47+
systemBarInsets.right,
48+
systemBarInsets.bottom
49+
);
50+
return insets;
51+
}
52+
);
53+
}
54+
}
55+
56+
@Override
57+
public void onActivityPaused(@NonNull Activity activity) {}
58+
59+
@Override
60+
public void onActivityStopped(@NonNull Activity activity) {}
61+
62+
@Override
63+
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {}
64+
65+
@Override
66+
public void onActivityDestroyed(@NonNull Activity activity) {}
67+
}

src/android/CardIoPlugin.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class CardIoPlugin extends CordovaPlugin {
3333

3434
private CallbackContext callbackContext;
3535

36+
private CardIoActivityLifecycleCallbacks mCurrentActivityCallback = null;
37+
3638
@Override
3739
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
3840
this.callbackContext = callbackContext;
@@ -83,6 +85,7 @@ private boolean scanCardLogic(JSONArray args) {
8385
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, requirePostalCode); // default: false
8486
// scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, true);
8587
// scanIntent.putExtra(CardIOActivity.EXTRA_KEEP_APPLICATION_THEME, true);
88+
observeActivityLifecycle();
8689
this.cordova.startActivityForResult(this, scanIntent, CARDIO_PLUGIN_SCAN_CARD_REQUEST_CODE);
8790
return true;
8891
} catch (JSONException e) {
@@ -95,6 +98,18 @@ private boolean scanCardLogic(JSONArray args) {
9598
}
9699
}
97100

101+
private void observeActivityLifecycle() {
102+
if (mCurrentActivityCallback != null) {
103+
this.cordova.getActivity().getApplication().unregisterActivityLifecycleCallbacks(
104+
mCurrentActivityCallback
105+
);
106+
}
107+
mCurrentActivityCallback = new CardIoActivityLifecycleCallbacks();
108+
this.cordova.getActivity().getApplication().registerActivityLifecycleCallbacks(
109+
mCurrentActivityCallback
110+
);
111+
}
112+
98113
@Override
99114
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
100115
super.onActivityResult(requestCode, resultCode, intent);

src/android/cardio.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
repositories {
2+
google()
23
mavenCentral()
34
}
45

56
dependencies {
67
implementation 'io.card:android-sdk:5.1.2'
8+
implementation 'androidx.appcompat:appcompat:1.6.1'
79
}

0 commit comments

Comments
 (0)