Skip to content

Commit ad05993

Browse files
committed
+ 5.2.0 Alipay Taobao support switch payment method
UnionPay support english environment
1 parent 721135d commit ad05993

File tree

9 files changed

+229
-62
lines changed

9 files changed

+229
-62
lines changed

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion 14
99
targetSdkVersion 33
1010
versionCode 32
11-
versionName "5.1.0"
11+
versionName "5.2.0"
1212
buildConfigField "String", "APP_PRODUCT_NAME", "\"FingerprintPay\""
1313
}
1414

app/src/main/java/com/surcumference/fingerprint/plugin/impl/alipay/AlipayBasePlugin.java

+56-21
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.surcumference.fingerprint.util.drawable.XDrawable;
4848
import com.surcumference.fingerprint.util.log.L;
4949
import com.surcumference.fingerprint.view.AlipayPayView;
50+
import com.surcumference.fingerprint.view.DialogUtils;
5051
import com.surcumference.fingerprint.view.SettingsView;
5152
import com.wei.android.lib.fingerprintidentify.bean.FingerprintIdentifyFailInfo;
5253

@@ -317,11 +318,7 @@ public boolean showFingerPrintDialog(final Activity activity) {
317318
onCompleteRunnable.run();
318319
});
319320
}).withOnCancelButtonClickListener(target -> {
320-
AlertDialog dialog = target.getDialog();
321-
if (dialog != null) {
322-
dialog.dismiss();
323-
}
324-
activity.onBackPressed();
321+
DialogUtils.dismiss(target.getDialog());
325322
}).withOnDismissListener(v -> {
326323
XBiometricIdentify fingerprintIdentify = mFingerprintIdentify;
327324
if (fingerprintIdentify != null) {
@@ -337,19 +334,59 @@ public boolean showFingerPrintDialog(final Activity activity) {
337334
return true;
338335
}
339336

337+
private void setupPaymentItemOnClickListener(ViewGroup rootView) {
338+
List<View> paymentMethodsViewList = new ArrayList<>();
339+
ViewUtils.getChildViewsByRegex(rootView, ".*选中,.+", paymentMethodsViewList);
340+
long paymentMethodsViewListSize = paymentMethodsViewList.size();
341+
for (int i = 0; i < paymentMethodsViewListSize; i++) {
342+
if (i == paymentMethodsViewListSize - 1) {
343+
// 最后一个
344+
continue;
345+
}
346+
View paymentMethodView = paymentMethodsViewList.get(i);
347+
L.d("paymentMethodView", ViewUtils.getViewInfo(paymentMethodView));
348+
// 只取第一次, 防止多次调用造成出错
349+
View.OnClickListener originPaymentMethodListener = (View.OnClickListener) paymentMethodView.getTag(R.id.alipay_payment_method_item_click_listener);
350+
if (originPaymentMethodListener == null) {
351+
paymentMethodView.setTag(R.id.alipay_payment_method_item_click_listener, ViewUtils.getOnClickListener(paymentMethodView));
352+
}
353+
paymentMethodView.setOnClickListener(new View.OnClickListener() {
354+
@Override
355+
public void onClick(View v) {
356+
try {
357+
AlertDialog dialog = mFingerPrintAlertDialog;
358+
if (dialog == null) {
359+
return;
360+
}
361+
if (!dialog.isShowing()) {
362+
dialog.show();
363+
}
364+
} finally {
365+
View.OnClickListener originPaymentMethodListener = (View.OnClickListener) v.getTag(R.id.alipay_payment_method_item_click_listener);
366+
if (originPaymentMethodListener != null && originPaymentMethodListener != this) {
367+
originPaymentMethodListener.onClick(v);
368+
}
369+
}
370+
}
371+
});
372+
}
373+
}
374+
340375
private void reEnteredPayDialogSolution(Activity activity) {
341376
int versionCode = getVersionCode(activity);
342377
if (versionCode < 1261 /** 10.5.96.8000 */) {
343378
return;
344379
}
380+
ViewGroup rootView = (ViewGroup)activity.getWindow().getDecorView();
381+
setupPaymentItemOnClickListener(rootView);
345382
// 在10s内寻找密码框
346383
ActivityViewObserver activityViewObserver = new ActivityViewObserver(activity);
347384
activityViewObserver.setActivityViewFinder(outViewList -> {
348385
EditText view = findPasswordEditText(activity);
349386
if (view != null) {
350387
outViewList.add(view);
351388
}
352-
View shortPwdView = ViewUtils.findViewByText(activity.getWindow().getDecorView(), "密码共6位,已输入0位");
389+
View shortPwdView = ViewUtils.findViewByText(rootView, "密码共6位,已输入0位");
353390
if (ViewUtils.isShown(shortPwdView)) {
354391
outViewList.add(shortPwdView);
355392
}
@@ -367,6 +404,10 @@ public void onFocusChange(View v, boolean hasFocus) {
367404
try {
368405
// 如果失去焦点并且获得新焦点, 通常是切换支付方式, 尝试重新触发识别
369406
if (!lastFocusState && hasFocus) {
407+
// 如果支付方式点了第一项, 页面会刷新, 需要重建OnclickListener
408+
Task.onMain(666, () -> {
409+
setupPaymentItemOnClickListener(rootView);
410+
});
370411
AlertDialog dialog = mFingerPrintAlertDialog;
371412
if (dialog == null) {
372413
return;
@@ -378,7 +419,6 @@ public void onFocusChange(View v, boolean hasFocus) {
378419
} finally {
379420
lastFocusState = hasFocus;
380421
}
381-
382422
}
383423

384424
});
@@ -687,13 +727,7 @@ private View findConfirmPasswordBtn(Activity activity) {
687727
}
688728
ViewGroup rootView = (ViewGroup) activity.getWindow().getDecorView();
689729
List<View> outList = new ArrayList<>();
690-
ViewUtils.getChildViews(rootView, "付款", outList);
691-
if (outList.isEmpty()) {
692-
ViewUtils.getChildViews(rootView, "Pay", outList);
693-
}
694-
if (outList.isEmpty()) {
695-
ViewUtils.getChildViews(rootView, "确定", outList);
696-
}
730+
ViewUtils.getChildViewsByRegex(rootView, "确定|確定|OK|确认|付款|確認|Pay", outList);
697731
int versionCode = getVersionCode(activity);
698732
for (View view : outList) {
699733
if (view.getId() != -1) {
@@ -702,20 +736,21 @@ private View findConfirmPasswordBtn(Activity activity) {
702736
if (!view.isShown()) {
703737
continue;
704738
}
705-
if (versionCode >= 1261 /** 10.5.96.8000 */) {
706-
return view;
739+
// 跳过键盘上的OK
740+
if (view.getParent().toString().contains(":id/key_enter")) {
741+
continue;
707742
}
708-
return (View) view.getParent();
743+
if (versionCode < 1261 /** 10.5.96.8000 */) {
744+
return (View) view.getParent();
745+
}
746+
return view;
709747
}
710748
return null;
711749
}
712750

713751
private void hidePreviousPayDialog() {
714-
AlertDialog dialog = mFingerPrintAlertDialog;
715752
L.d("hidePreviousPayDialog", mFingerPrintAlertDialog);
716-
if (dialog != null) {
717-
dialog.dismiss();
718-
}
753+
DialogUtils.dismiss(mFingerPrintAlertDialog);
719754
mFingerPrintAlertDialog = null;
720755
}
721756
}

app/src/main/java/com/surcumference/fingerprint/plugin/impl/taobao/TaobaoBasePlugin.java

+58-18
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.surcumference.fingerprint.util.drawable.XDrawable;
4242
import com.surcumference.fingerprint.util.log.L;
4343
import com.surcumference.fingerprint.view.AlipayPayView;
44+
import com.surcumference.fingerprint.view.DialogUtils;
4445
import com.surcumference.fingerprint.view.SettingsView;
4546
import com.wei.android.lib.fingerprintidentify.bean.FingerprintIdentifyFailInfo;
4647

@@ -287,11 +288,7 @@ public void showFingerPrintDialog(final Activity activity) {
287288
onCompleteRunnable.run();
288289
});
289290
}).withOnCancelButtonClickListener(target -> {
290-
AlertDialog dialog = target.getDialog();
291-
if (dialog != null) {
292-
dialog.dismiss();
293-
}
294-
activity.onBackPressed();
291+
DialogUtils.dismiss(target.getDialog());
295292
}).withOnDismissListener(v -> {
296293
XBiometricIdentify fingerprintIdentify = mFingerprintIdentify;
297294
if (fingerprintIdentify != null) {
@@ -306,19 +303,59 @@ public void showFingerPrintDialog(final Activity activity) {
306303
}
307304
}
308305

306+
private void setupPaymentItemOnClickListener(ViewGroup rootView) {
307+
List<View> paymentMethodsViewList = new ArrayList<>();
308+
ViewUtils.getChildViewsByRegex(rootView, ".*选中,.+", paymentMethodsViewList);
309+
long paymentMethodsViewListSize = paymentMethodsViewList.size();
310+
for (int i = 0; i < paymentMethodsViewListSize; i++) {
311+
if (i == paymentMethodsViewListSize - 1) {
312+
// 最后一个
313+
continue;
314+
}
315+
View paymentMethodView = paymentMethodsViewList.get(i);
316+
L.d("paymentMethodView", ViewUtils.getViewInfo(paymentMethodView));
317+
// 只取第一次, 防止多次调用造成出错
318+
View.OnClickListener originPaymentMethodListener = (View.OnClickListener) paymentMethodView.getTag(R.id.alipay_payment_method_item_click_listener);
319+
if (originPaymentMethodListener == null) {
320+
paymentMethodView.setTag(R.id.alipay_payment_method_item_click_listener, ViewUtils.getOnClickListener(paymentMethodView));
321+
}
322+
paymentMethodView.setOnClickListener(new View.OnClickListener() {
323+
@Override
324+
public void onClick(View v) {
325+
try {
326+
AlertDialog dialog = mFingerPrintAlertDialog;
327+
if (dialog == null) {
328+
return;
329+
}
330+
if (!dialog.isShowing()) {
331+
dialog.show();
332+
}
333+
} finally {
334+
View.OnClickListener originPaymentMethodListener = (View.OnClickListener) v.getTag(R.id.alipay_payment_method_item_click_listener);
335+
if (originPaymentMethodListener != null && originPaymentMethodListener != this) {
336+
originPaymentMethodListener.onClick(v);
337+
}
338+
}
339+
}
340+
});
341+
}
342+
}
343+
309344
private void reEnteredPayDialogSolution(Activity activity) {
310345
int versionCode = getVersionCode(activity);
311346
if (versionCode < 643 /** 10.36.10 */) {
312347
return;
313348
}
349+
ViewGroup rootView = (ViewGroup)activity.getWindow().getDecorView();
350+
setupPaymentItemOnClickListener(rootView);
314351
// 在10s内寻找密码框
315352
ActivityViewObserver activityViewObserver = new ActivityViewObserver(activity);
316353
activityViewObserver.setActivityViewFinder(outViewList -> {
317354
EditText view = findPasswordEditText(activity);
318355
if (view != null) {
319356
outViewList.add(view);
320357
}
321-
View shortPwdView = ViewUtils.findViewByText(activity.getWindow().getDecorView(), "密码共6位,已输入0位");
358+
View shortPwdView = ViewUtils.findViewByText(rootView, "密码共6位,已输入0位");
322359
if (ViewUtils.isShown(shortPwdView)) {
323360
outViewList.add(shortPwdView);
324361
}
@@ -336,6 +373,10 @@ public void onFocusChange(View v, boolean hasFocus) {
336373
try {
337374
// 如果失去焦点并且获得新焦点, 通常是切换支付方式, 尝试重新触发识别
338375
if (!lastFocusState && hasFocus) {
376+
// 如果支付方式点了第一项, 页面会刷新, 需要重建OnclickListener
377+
Task.onMain(666, () -> {
378+
setupPaymentItemOnClickListener(rootView);
379+
});
339380
AlertDialog dialog = mFingerPrintAlertDialog;
340381
if (dialog == null) {
341382
return;
@@ -582,26 +623,25 @@ private View findConfirmPasswordBtn(Activity activity) {
582623
}
583624
return okView;
584625
}
585-
ViewGroup viewGroup = (ViewGroup)activity.getWindow().getDecorView();
626+
ViewGroup rootView = (ViewGroup)activity.getWindow().getDecorView();
586627
List<View> outList = new ArrayList<>();
587-
ViewUtils.getChildViews(viewGroup, "确认", outList);
588-
if (outList.isEmpty()) {
589-
ViewUtils.getChildViews(viewGroup, "付款", outList);
590-
}
591-
if (outList.isEmpty()) {
592-
ViewUtils.getChildViews(viewGroup, "確認", outList);
593-
}
594-
if (outList.isEmpty()) {
595-
ViewUtils.getChildViews(viewGroup, "Pay", outList);
596-
}
628+
ViewUtils.getChildViewsByRegex(rootView, "确定|確定|OK|确认|付款|確認|Pay", outList);
629+
int versionCode = getVersionCode(activity);
597630
for (View view : outList) {
598631
if (view.getId() != -1) {
599632
continue;
600633
}
601634
if (!view.isShown()) {
602635
continue;
603636
}
604-
return (View) view.getParent();
637+
// 跳过键盘上的OK
638+
if (view.getParent().toString().contains(":id/key_enter")) {
639+
continue;
640+
}
641+
if (versionCode < 643 /** 10.36.10 */) {
642+
return (View) view.getParent();
643+
}
644+
return view;
605645
}
606646
return null;
607647
}

app/src/main/java/com/surcumference/fingerprint/plugin/impl/unionpay/UnionPayBasePlugin.java

+10-19
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.surcumference.fingerprint.util.XBiometricIdentify;
4747
import com.surcumference.fingerprint.util.log.L;
4848
import com.surcumference.fingerprint.view.AlipayPayView;
49+
import com.surcumference.fingerprint.view.DialogUtils;
4950
import com.surcumference.fingerprint.view.SettingsView;
5051
import com.wei.android.lib.fingerprintidentify.bean.FingerprintIdentifyFailInfo;
5152

@@ -123,7 +124,7 @@ public synchronized void showFingerPrintDialog(@Nullable Activity activity, View
123124
ViewTreeObserver.OnGlobalLayoutListener paymentMethodListener = new ViewTreeObserver.OnGlobalLayoutListener() {
124125
@Override
125126
public void onGlobalLayout() {
126-
View selectPaymentMethodView = ViewUtils.findViewByText(rootView, "选择付款方式");
127+
View selectPaymentMethodView = ViewUtils.findViewByText(rootView, "选择付款方式", "Select payment method");
127128
L.d("selectPaymentMethodView", ViewUtils.getViewInfo(selectPaymentMethodView));
128129
if (selectPaymentMethodView == null) {
129130
showFingerPrintDialog(activity, targetView);
@@ -153,19 +154,16 @@ public void onGlobalLayout() {
153154
View payRootLayout = ViewUtils.findViewByName(rootView, PACKAGE_NAME_UNIONPAY, "fl_container");
154155
L.d("payRootLayout", payRootLayout);
155156
if (payRootLayout == null) {
156-
View payTitleTextView = ViewUtils.findViewByText(rootView, "请输入支付密码");
157+
View payTitleTextView = ViewUtils.findViewByText(rootView, "请输入支付密码", "Input payment password");
157158
payRootLayout = (View)payTitleTextView.getParent().getParent().getParent();
158159
dialogMode = true;
159160
}
160161
L.d("payRootLayout", payRootLayout);
161162
boolean finalDialogMode = dialogMode;
162163
AlipayPayView payView = new AlipayPayView(context)
163164
.withOnCancelButtonClickListener(target -> {
164-
AlertDialog dialog = target.getDialog();
165-
if (dialog != null) {
166-
dialog.dismiss();
167-
}
168-
if (finalDialogMode) {
165+
DialogUtils.dismiss(target.getDialog());
166+
if (finalDialogMode) {
169167
Task.onBackground(100, () -> {
170168
Task.onMain(500, () -> {
171169
//窗口消失了
@@ -247,14 +245,14 @@ public void onGlobalLayout() {
247245
}
248246
}
249247

250-
private void retryWatchPayViewIfPossible(Activity activity, View rootView, int countDown, int delayMsec) {
251-
View payTitleTextView = ViewUtils.findViewByText(rootView, "请输入支付密码");
248+
private void retryWatchPayViewIfPossible(Activity activity, View rootView, int countDown, int delayMS) {
249+
View payTitleTextView = ViewUtils.findViewByText(rootView, "请输入支付密码", "Input payment password");
252250
if (payTitleTextView == null
253251
|| !(ViewUtils.isViewVisibleInScreen(payTitleTextView) && ViewUtils.isShownInScreen(payTitleTextView))) {
254252
watchPayView(activity);
255253
}
256254
if (countDown > 0) {
257-
Task.onMain(delayMsec, () -> retryWatchPayViewIfPossible(activity, rootView, countDown - 1, delayMsec));
255+
Task.onMain(delayMS, () -> retryWatchPayViewIfPossible(activity, rootView, countDown - 1, delayMS));
258256
}
259257
}
260258

@@ -380,7 +378,7 @@ public void setMockCurrentUser(boolean mock) {
380378

381379
private void watchPayView(Activity activity) {
382380
ActivityViewObserver activityViewObserver = new ActivityViewObserver(activity);
383-
activityViewObserver.setViewIdentifyText("请输入支付密码");
381+
activityViewObserver.setViewIdentifyText("请输入支付密码", "Input payment password");
384382
activityViewObserver.setWatchActivityViewOnly(true);
385383
ActivityViewObserverHolder.start(ActivityViewObserverHolder.Key.UnionPayPasswordView, activityViewObserver,
386384
100, new ActivityViewObserver.IActivityViewListener() {
@@ -558,15 +556,8 @@ protected void doSettingsMenuInject(final Activity activity) {
558556
}
559557

560558
private void hidePreviousPayDialog() {
561-
AlertDialog dialog = mFingerPrintAlertDialog;
562559
L.d("hidePreviousPayDialog", mFingerPrintAlertDialog);
563-
if (dialog != null) {
564-
try {
565-
dialog.dismiss();
566-
} catch (IllegalArgumentException e) {
567-
//for java.lang.IllegalArgumentException: View=DecorView@4eafdfb[UPActivityPayPasswordSet] not attached to window manager
568-
}
569-
}
560+
DialogUtils.dismiss(mFingerPrintAlertDialog);
570561
mFingerPrintAlertDialog = null;
571562
}
572563
}

0 commit comments

Comments
 (0)