Skip to content

Commit 7b3ec0d

Browse files
author
bootpay
committed
androidx support
1 parent 4d41754 commit 7b3ec0d

File tree

6 files changed

+494
-50
lines changed

6 files changed

+494
-50
lines changed

bootpay/src/main/java/kr/co/bootpay/BootpayBuilder.java

Lines changed: 108 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class BootpayBuilder {
5757
private CancelListener cancel;
5858
private ConfirmListener confirm;
5959
private BootpayDialog dialog;
60+
private BootpayDialogX dialogX;
6061
// private BootpayBioDialog bioDialog;
6162
private ApiPresenter presenter;
6263
// boolean isBioIntent = false;
@@ -425,7 +426,7 @@ private void validCheck() {
425426
if(ux == null || ux == UX.NONE) { request.setUX(UX.PG_DIALOG); }
426427
ux = request.getUX();
427428
if(ux == UX.PG_DIALOG) {
428-
if (fm == null || fm.isDestroyed()) { error("fragment 값은 null 이 될 수 없습니다."); }
429+
if ((fm == null || fm.isDestroyed()) && (fmx == null || fmx.isDestroyed())) { error("fragment 값은 null 이 될 수 없습니다."); }
429430

430431
} else if(ux == UX.APP2APP_CARD_SIMPLE
431432
|| ux == UX.APP2APP_NFC
@@ -530,38 +531,43 @@ private void requestBioActivity() {
530531

531532

532533
private void requestDialog() {
533-
dialog = new BootpayDialog().setRequest(request)
534-
.setOnResponseListener(listener != null ? listener : new EventListener() {
535-
@Override
536-
public void onClose(String data) {
537-
if(close != null ) close.onClose(data);
538-
}
539-
540-
@Override
541-
public void onReady(String data) {
542-
if(ready != null ) ready.onReady(data);
543-
}
544-
545-
@Override
546-
public void onError(String data) {
547-
if(error != null ) error.onError(data);
548-
}
549-
550-
@Override
551-
public void onCancel(String data) {
552-
if(cancel != null ) cancel.onCancel(data);
553-
}
554-
555-
@Override
556-
public void onConfirm(String data) {
557-
if(confirm != null ) confirm.onConfirm(data);
558-
}
534+
if(this.fm != null) { requestDialogCall(); }
535+
else if(this.fmx != null) { requestDialogXCall(); }
536+
}
559537

560-
@Override
561-
public void onDone(String data) {
562-
if(done != null ) done.onDone(data);
563-
}
564-
});
538+
private void requestDialogCall() {
539+
dialog = new BootpayDialog().setRequest(request)
540+
.setOnResponseListener(listener != null ? listener : new EventListener() {
541+
@Override
542+
public void onClose(String data) {
543+
if(close != null ) close.onClose(data);
544+
}
545+
546+
@Override
547+
public void onReady(String data) {
548+
if(ready != null ) ready.onReady(data);
549+
}
550+
551+
@Override
552+
public void onError(String data) {
553+
if(error != null ) error.onError(data);
554+
}
555+
556+
@Override
557+
public void onCancel(String data) {
558+
if(cancel != null ) cancel.onCancel(data);
559+
}
560+
561+
@Override
562+
public void onConfirm(String data) {
563+
if(confirm != null ) confirm.onConfirm(data);
564+
}
565+
566+
@Override
567+
public void onDone(String data) {
568+
if(done != null ) done.onDone(data);
569+
}
570+
});
565571

566572
dialog.onCancel(new DialogInterface() {
567573
@Override
@@ -583,8 +589,68 @@ public void dismiss() {
583589
}
584590
});
585591

586-
if (dialog != null) dialog.show(fm, "bootpay");
587-
// System.currentTimeMillis()
592+
if (dialog != null) {
593+
dialog.show(fm, "bootpay");
594+
}
595+
}
596+
597+
private void requestDialogXCall() {
598+
dialogX = new BootpayDialogX().setRequest(request)
599+
.setOnResponseListener(listener != null ? listener : new EventListener() {
600+
@Override
601+
public void onClose(String data) {
602+
if(close != null ) close.onClose(data);
603+
}
604+
605+
@Override
606+
public void onReady(String data) {
607+
if(ready != null ) ready.onReady(data);
608+
}
609+
610+
@Override
611+
public void onError(String data) {
612+
if(error != null ) error.onError(data);
613+
}
614+
615+
@Override
616+
public void onCancel(String data) {
617+
if(cancel != null ) cancel.onCancel(data);
618+
}
619+
620+
@Override
621+
public void onConfirm(String data) {
622+
if(confirm != null ) confirm.onConfirm(data);
623+
}
624+
625+
@Override
626+
public void onDone(String data) {
627+
if(done != null ) done.onDone(data);
628+
}
629+
});
630+
631+
dialogX.onCancel(new DialogInterface() {
632+
@Override
633+
public void cancel() {
634+
if (dialogX != null && dialogX.bootpay != null)
635+
dialogX.bootpay.destroy();
636+
dialogX = null;
637+
UserInfo.getInstance(context).finish();
638+
Bootpay.finish();
639+
}
640+
641+
@Override
642+
public void dismiss() {
643+
if (dialogX != null && dialogX.bootpay != null)
644+
dialogX.bootpay.destroy();
645+
dialogX = null;
646+
UserInfo.getInstance(context).finish();
647+
Bootpay.finish();
648+
}
649+
});
650+
651+
if (dialogX != null) {
652+
dialogX.show(fmx, "bootpay");
653+
}
588654
}
589655

590656
private void requestApi() {
@@ -602,6 +668,9 @@ public void transactionConfirm(String data) {
602668
if (dialog != null)
603669
dialog.transactionConfirm(data);
604670

671+
if(dialogX != null)
672+
dialogX.transactionConfirm(data);
673+
605674
if(CurrentBioRequest.getInstance().activity != null)
606675
CurrentBioRequest.getInstance().activity.transactionConfirm(data);
607676

@@ -617,11 +686,16 @@ public void transactionConfirm(String data) {
617686
public void removePaymentWindow() {
618687
if (dialog != null)
619688
dialog.removePaymentWindow();
689+
690+
if (dialogX != null)
691+
dialogX.removePaymentWindow();
620692
}
621693

622694
public void dismiss() {
623695
if(dialog != null) dialog.dismiss();
624696

697+
if(dialogX != null) dialogX.dismiss();
698+
625699
if(CurrentBioRequest.getInstance().activity != null)
626700
CurrentBioRequest.getInstance().activity.activityFinish();
627701

@@ -642,6 +716,4 @@ private boolean isEmpty(String value) {
642716
private void error(String message) {
643717
throw new RuntimeException(message);
644718
}
645-
646-
647719
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package kr.co.bootpay;
2+
3+
import android.app.Dialog;
4+
import android.content.DialogInterface;
5+
import android.os.Bundle;
6+
import android.view.KeyEvent;
7+
import android.view.LayoutInflater;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
11+
import androidx.fragment.app.DialogFragment;
12+
13+
import kr.co.bootpay.listener.EventListener;
14+
import kr.co.bootpay.model.Request;
15+
16+
public class BootpayDialogX extends DialogFragment {
17+
18+
private Request request;
19+
protected BootpayWebView bootpay;
20+
private EventListener listener;
21+
22+
// @Override
23+
// public Dialog onCreateDialog(Bundle savedInstanceState) {
24+
// return new Dialog(getActivity(), getTheme()){
25+
// @Override
26+
// public void onBackPressed() {
27+
// //do your stuff
28+
// }
29+
// };
30+
// }
31+
32+
@Override
33+
public void onCreate(Bundle savedInstanceState) {
34+
super.onCreate(savedInstanceState);
35+
setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Holo_Light);
36+
}
37+
38+
@Override
39+
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
40+
bootpay = new BootpayWebView(inflater.getContext());
41+
42+
43+
44+
afterViewInit();
45+
// bootpay.getSettings().setUserAgentString(userAgent + "/뭥미");
46+
return bootpay;
47+
}
48+
49+
@Override
50+
public void onDestroyView() {
51+
super.onDestroyView();
52+
}
53+
54+
private void afterViewInit() {
55+
if (bootpay != null) {
56+
Dialog dialog = getDialog();
57+
dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
58+
@Override
59+
public boolean onKey(DialogInterface dialogInterface, int keyCode, KeyEvent keyEvent) {
60+
if(keyCode == KeyEvent.KEYCODE_BACK) {
61+
if(listener != null)
62+
listener.onClose("android backbutton clicked");
63+
}
64+
return false;
65+
}
66+
});
67+
bootpay.setRequest(request)
68+
.setDialog(dialog)
69+
.setOnResponseListener(listener);
70+
}
71+
72+
73+
74+
// setOnKeyListener(new DialogInterface.OnKeyListener() {
75+
// @Override
76+
// public boolean onKey(android.content.DialogInterface dialog, int keyCode, android.view.KeyEvent event) {
77+
//
78+
// if ((keyCode == android.view.KeyEvent.KEYCODE_BACK)) {
79+
//
80+
// }
81+
// }
82+
// }
83+
}
84+
85+
public BootpayDialogX setOnResponseListener(EventListener listener) {
86+
this.listener = listener;
87+
return this;
88+
}
89+
90+
public BootpayDialogX setRequest(Request request) {
91+
this.request = request;
92+
return this;
93+
}
94+
95+
protected void transactionConfirm(String data) {
96+
if (bootpay != null)
97+
bootpay.transactionConfirm(data);
98+
}
99+
100+
protected void removePaymentWindow() {
101+
if (bootpay != null)
102+
bootpay.removePaymentWindow();
103+
}
104+
}

sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
</activity>
2525

2626
<activity android:name=".NativeActivity" android:screenOrientation="portrait"/>
27+
<activity android:name=".NativeXActivity" android:screenOrientation="portrait"/>
2728
<activity android:name=".WebAppActivity" android:screenOrientation="portrait"/>
2829
<activity android:name=".LocalHtmlActivity" android:screenOrientation="portrait"/>
2930
<activity android:name=".App2AppActivity" android:screenOrientation="portrait"/>

sample/src/main/java/bootpay/co/kr/samplepayment/MainActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ public void goNativeActivity(View v) {
239239
startActivity(intent);
240240
}
241241

242+
public void goNativeXActivity(View v) {
243+
Intent intent = new Intent(this, NativeXActivity.class);
244+
startActivity(intent);
245+
}
246+
242247
public void goBioActivity(View v) {
243248
Intent intent = new Intent(this, BioActivity.class);
244249
startActivity(intent);

0 commit comments

Comments
 (0)