Skip to content

Commit

Permalink
+ 5.2.0 Alipay Taobao support switch payment method
Browse files Browse the repository at this point in the history
UnionPay support english environment
  • Loading branch information
eritpchy committed May 26, 2024
1 parent 721135d commit ad05993
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 62 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 14
targetSdkVersion 33
versionCode 32
versionName "5.1.0"
versionName "5.2.0"
buildConfigField "String", "APP_PRODUCT_NAME", "\"FingerprintPay\""
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.surcumference.fingerprint.util.drawable.XDrawable;
import com.surcumference.fingerprint.util.log.L;
import com.surcumference.fingerprint.view.AlipayPayView;
import com.surcumference.fingerprint.view.DialogUtils;
import com.surcumference.fingerprint.view.SettingsView;
import com.wei.android.lib.fingerprintidentify.bean.FingerprintIdentifyFailInfo;

Expand Down Expand Up @@ -317,11 +318,7 @@ public boolean showFingerPrintDialog(final Activity activity) {
onCompleteRunnable.run();
});
}).withOnCancelButtonClickListener(target -> {
AlertDialog dialog = target.getDialog();
if (dialog != null) {
dialog.dismiss();
}
activity.onBackPressed();
DialogUtils.dismiss(target.getDialog());
}).withOnDismissListener(v -> {
XBiometricIdentify fingerprintIdentify = mFingerprintIdentify;
if (fingerprintIdentify != null) {
Expand All @@ -337,19 +334,59 @@ public boolean showFingerPrintDialog(final Activity activity) {
return true;
}

private void setupPaymentItemOnClickListener(ViewGroup rootView) {
List<View> paymentMethodsViewList = new ArrayList<>();
ViewUtils.getChildViewsByRegex(rootView, ".*选中,.+", paymentMethodsViewList);
long paymentMethodsViewListSize = paymentMethodsViewList.size();
for (int i = 0; i < paymentMethodsViewListSize; i++) {
if (i == paymentMethodsViewListSize - 1) {
// 最后一个
continue;
}
View paymentMethodView = paymentMethodsViewList.get(i);
L.d("paymentMethodView", ViewUtils.getViewInfo(paymentMethodView));
// 只取第一次, 防止多次调用造成出错
View.OnClickListener originPaymentMethodListener = (View.OnClickListener) paymentMethodView.getTag(R.id.alipay_payment_method_item_click_listener);
if (originPaymentMethodListener == null) {
paymentMethodView.setTag(R.id.alipay_payment_method_item_click_listener, ViewUtils.getOnClickListener(paymentMethodView));
}
paymentMethodView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
AlertDialog dialog = mFingerPrintAlertDialog;
if (dialog == null) {
return;
}
if (!dialog.isShowing()) {
dialog.show();
}
} finally {
View.OnClickListener originPaymentMethodListener = (View.OnClickListener) v.getTag(R.id.alipay_payment_method_item_click_listener);
if (originPaymentMethodListener != null && originPaymentMethodListener != this) {
originPaymentMethodListener.onClick(v);
}
}
}
});
}
}

private void reEnteredPayDialogSolution(Activity activity) {
int versionCode = getVersionCode(activity);
if (versionCode < 1261 /** 10.5.96.8000 */) {
return;
}
ViewGroup rootView = (ViewGroup)activity.getWindow().getDecorView();
setupPaymentItemOnClickListener(rootView);
// 在10s内寻找密码框
ActivityViewObserver activityViewObserver = new ActivityViewObserver(activity);
activityViewObserver.setActivityViewFinder(outViewList -> {
EditText view = findPasswordEditText(activity);
if (view != null) {
outViewList.add(view);
}
View shortPwdView = ViewUtils.findViewByText(activity.getWindow().getDecorView(), "密码共6位,已输入0位");
View shortPwdView = ViewUtils.findViewByText(rootView, "密码共6位,已输入0位");
if (ViewUtils.isShown(shortPwdView)) {
outViewList.add(shortPwdView);
}
Expand All @@ -367,6 +404,10 @@ public void onFocusChange(View v, boolean hasFocus) {
try {
// 如果失去焦点并且获得新焦点, 通常是切换支付方式, 尝试重新触发识别
if (!lastFocusState && hasFocus) {
// 如果支付方式点了第一项, 页面会刷新, 需要重建OnclickListener
Task.onMain(666, () -> {
setupPaymentItemOnClickListener(rootView);
});
AlertDialog dialog = mFingerPrintAlertDialog;
if (dialog == null) {
return;
Expand All @@ -378,7 +419,6 @@ public void onFocusChange(View v, boolean hasFocus) {
} finally {
lastFocusState = hasFocus;
}

}

});
Expand Down Expand Up @@ -687,13 +727,7 @@ private View findConfirmPasswordBtn(Activity activity) {
}
ViewGroup rootView = (ViewGroup) activity.getWindow().getDecorView();
List<View> outList = new ArrayList<>();
ViewUtils.getChildViews(rootView, "付款", outList);
if (outList.isEmpty()) {
ViewUtils.getChildViews(rootView, "Pay", outList);
}
if (outList.isEmpty()) {
ViewUtils.getChildViews(rootView, "确定", outList);
}
ViewUtils.getChildViewsByRegex(rootView, "确定|確定|OK|确认|付款|確認|Pay", outList);
int versionCode = getVersionCode(activity);
for (View view : outList) {
if (view.getId() != -1) {
Expand All @@ -702,20 +736,21 @@ private View findConfirmPasswordBtn(Activity activity) {
if (!view.isShown()) {
continue;
}
if (versionCode >= 1261 /** 10.5.96.8000 */) {
return view;
// 跳过键盘上的OK
if (view.getParent().toString().contains(":id/key_enter")) {
continue;
}
return (View) view.getParent();
if (versionCode < 1261 /** 10.5.96.8000 */) {
return (View) view.getParent();
}
return view;
}
return null;
}

private void hidePreviousPayDialog() {
AlertDialog dialog = mFingerPrintAlertDialog;
L.d("hidePreviousPayDialog", mFingerPrintAlertDialog);
if (dialog != null) {
dialog.dismiss();
}
DialogUtils.dismiss(mFingerPrintAlertDialog);
mFingerPrintAlertDialog = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.surcumference.fingerprint.util.drawable.XDrawable;
import com.surcumference.fingerprint.util.log.L;
import com.surcumference.fingerprint.view.AlipayPayView;
import com.surcumference.fingerprint.view.DialogUtils;
import com.surcumference.fingerprint.view.SettingsView;
import com.wei.android.lib.fingerprintidentify.bean.FingerprintIdentifyFailInfo;

Expand Down Expand Up @@ -287,11 +288,7 @@ public void showFingerPrintDialog(final Activity activity) {
onCompleteRunnable.run();
});
}).withOnCancelButtonClickListener(target -> {
AlertDialog dialog = target.getDialog();
if (dialog != null) {
dialog.dismiss();
}
activity.onBackPressed();
DialogUtils.dismiss(target.getDialog());
}).withOnDismissListener(v -> {
XBiometricIdentify fingerprintIdentify = mFingerprintIdentify;
if (fingerprintIdentify != null) {
Expand All @@ -306,19 +303,59 @@ public void showFingerPrintDialog(final Activity activity) {
}
}

private void setupPaymentItemOnClickListener(ViewGroup rootView) {
List<View> paymentMethodsViewList = new ArrayList<>();
ViewUtils.getChildViewsByRegex(rootView, ".*选中,.+", paymentMethodsViewList);
long paymentMethodsViewListSize = paymentMethodsViewList.size();
for (int i = 0; i < paymentMethodsViewListSize; i++) {
if (i == paymentMethodsViewListSize - 1) {
// 最后一个
continue;
}
View paymentMethodView = paymentMethodsViewList.get(i);
L.d("paymentMethodView", ViewUtils.getViewInfo(paymentMethodView));
// 只取第一次, 防止多次调用造成出错
View.OnClickListener originPaymentMethodListener = (View.OnClickListener) paymentMethodView.getTag(R.id.alipay_payment_method_item_click_listener);
if (originPaymentMethodListener == null) {
paymentMethodView.setTag(R.id.alipay_payment_method_item_click_listener, ViewUtils.getOnClickListener(paymentMethodView));
}
paymentMethodView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
AlertDialog dialog = mFingerPrintAlertDialog;
if (dialog == null) {
return;
}
if (!dialog.isShowing()) {
dialog.show();
}
} finally {
View.OnClickListener originPaymentMethodListener = (View.OnClickListener) v.getTag(R.id.alipay_payment_method_item_click_listener);
if (originPaymentMethodListener != null && originPaymentMethodListener != this) {
originPaymentMethodListener.onClick(v);
}
}
}
});
}
}

private void reEnteredPayDialogSolution(Activity activity) {
int versionCode = getVersionCode(activity);
if (versionCode < 643 /** 10.36.10 */) {
return;
}
ViewGroup rootView = (ViewGroup)activity.getWindow().getDecorView();
setupPaymentItemOnClickListener(rootView);
// 在10s内寻找密码框
ActivityViewObserver activityViewObserver = new ActivityViewObserver(activity);
activityViewObserver.setActivityViewFinder(outViewList -> {
EditText view = findPasswordEditText(activity);
if (view != null) {
outViewList.add(view);
}
View shortPwdView = ViewUtils.findViewByText(activity.getWindow().getDecorView(), "密码共6位,已输入0位");
View shortPwdView = ViewUtils.findViewByText(rootView, "密码共6位,已输入0位");
if (ViewUtils.isShown(shortPwdView)) {
outViewList.add(shortPwdView);
}
Expand All @@ -336,6 +373,10 @@ public void onFocusChange(View v, boolean hasFocus) {
try {
// 如果失去焦点并且获得新焦点, 通常是切换支付方式, 尝试重新触发识别
if (!lastFocusState && hasFocus) {
// 如果支付方式点了第一项, 页面会刷新, 需要重建OnclickListener
Task.onMain(666, () -> {
setupPaymentItemOnClickListener(rootView);
});
AlertDialog dialog = mFingerPrintAlertDialog;
if (dialog == null) {
return;
Expand Down Expand Up @@ -582,26 +623,25 @@ private View findConfirmPasswordBtn(Activity activity) {
}
return okView;
}
ViewGroup viewGroup = (ViewGroup)activity.getWindow().getDecorView();
ViewGroup rootView = (ViewGroup)activity.getWindow().getDecorView();
List<View> outList = new ArrayList<>();
ViewUtils.getChildViews(viewGroup, "确认", outList);
if (outList.isEmpty()) {
ViewUtils.getChildViews(viewGroup, "付款", outList);
}
if (outList.isEmpty()) {
ViewUtils.getChildViews(viewGroup, "確認", outList);
}
if (outList.isEmpty()) {
ViewUtils.getChildViews(viewGroup, "Pay", outList);
}
ViewUtils.getChildViewsByRegex(rootView, "确定|確定|OK|确认|付款|確認|Pay", outList);
int versionCode = getVersionCode(activity);
for (View view : outList) {
if (view.getId() != -1) {
continue;
}
if (!view.isShown()) {
continue;
}
return (View) view.getParent();
// 跳过键盘上的OK
if (view.getParent().toString().contains(":id/key_enter")) {
continue;
}
if (versionCode < 643 /** 10.36.10 */) {
return (View) view.getParent();
}
return view;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.surcumference.fingerprint.util.XBiometricIdentify;
import com.surcumference.fingerprint.util.log.L;
import com.surcumference.fingerprint.view.AlipayPayView;
import com.surcumference.fingerprint.view.DialogUtils;
import com.surcumference.fingerprint.view.SettingsView;
import com.wei.android.lib.fingerprintidentify.bean.FingerprintIdentifyFailInfo;

Expand Down Expand Up @@ -123,7 +124,7 @@ public synchronized void showFingerPrintDialog(@Nullable Activity activity, View
ViewTreeObserver.OnGlobalLayoutListener paymentMethodListener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
View selectPaymentMethodView = ViewUtils.findViewByText(rootView, "选择付款方式");
View selectPaymentMethodView = ViewUtils.findViewByText(rootView, "选择付款方式", "Select payment method");
L.d("selectPaymentMethodView", ViewUtils.getViewInfo(selectPaymentMethodView));
if (selectPaymentMethodView == null) {
showFingerPrintDialog(activity, targetView);
Expand Down Expand Up @@ -153,19 +154,16 @@ public void onGlobalLayout() {
View payRootLayout = ViewUtils.findViewByName(rootView, PACKAGE_NAME_UNIONPAY, "fl_container");
L.d("payRootLayout", payRootLayout);
if (payRootLayout == null) {
View payTitleTextView = ViewUtils.findViewByText(rootView, "请输入支付密码");
View payTitleTextView = ViewUtils.findViewByText(rootView, "请输入支付密码", "Input payment password");
payRootLayout = (View)payTitleTextView.getParent().getParent().getParent();
dialogMode = true;
}
L.d("payRootLayout", payRootLayout);
boolean finalDialogMode = dialogMode;
AlipayPayView payView = new AlipayPayView(context)
.withOnCancelButtonClickListener(target -> {
AlertDialog dialog = target.getDialog();
if (dialog != null) {
dialog.dismiss();
}
if (finalDialogMode) {
DialogUtils.dismiss(target.getDialog());
if (finalDialogMode) {
Task.onBackground(100, () -> {
Task.onMain(500, () -> {
//窗口消失了
Expand Down Expand Up @@ -247,14 +245,14 @@ public void onGlobalLayout() {
}
}

private void retryWatchPayViewIfPossible(Activity activity, View rootView, int countDown, int delayMsec) {
View payTitleTextView = ViewUtils.findViewByText(rootView, "请输入支付密码");
private void retryWatchPayViewIfPossible(Activity activity, View rootView, int countDown, int delayMS) {
View payTitleTextView = ViewUtils.findViewByText(rootView, "请输入支付密码", "Input payment password");
if (payTitleTextView == null
|| !(ViewUtils.isViewVisibleInScreen(payTitleTextView) && ViewUtils.isShownInScreen(payTitleTextView))) {
watchPayView(activity);
}
if (countDown > 0) {
Task.onMain(delayMsec, () -> retryWatchPayViewIfPossible(activity, rootView, countDown - 1, delayMsec));
Task.onMain(delayMS, () -> retryWatchPayViewIfPossible(activity, rootView, countDown - 1, delayMS));
}
}

Expand Down Expand Up @@ -380,7 +378,7 @@ public void setMockCurrentUser(boolean mock) {

private void watchPayView(Activity activity) {
ActivityViewObserver activityViewObserver = new ActivityViewObserver(activity);
activityViewObserver.setViewIdentifyText("请输入支付密码");
activityViewObserver.setViewIdentifyText("请输入支付密码", "Input payment password");
activityViewObserver.setWatchActivityViewOnly(true);
ActivityViewObserverHolder.start(ActivityViewObserverHolder.Key.UnionPayPasswordView, activityViewObserver,
100, new ActivityViewObserver.IActivityViewListener() {
Expand Down Expand Up @@ -558,15 +556,8 @@ protected void doSettingsMenuInject(final Activity activity) {
}

private void hidePreviousPayDialog() {
AlertDialog dialog = mFingerPrintAlertDialog;
L.d("hidePreviousPayDialog", mFingerPrintAlertDialog);
if (dialog != null) {
try {
dialog.dismiss();
} catch (IllegalArgumentException e) {
//for java.lang.IllegalArgumentException: View=DecorView@4eafdfb[UPActivityPayPasswordSet] not attached to window manager
}
}
DialogUtils.dismiss(mFingerPrintAlertDialog);
mFingerPrintAlertDialog = null;
}
}
Loading

0 comments on commit ad05993

Please sign in to comment.