Skip to content

Commit 72e7781

Browse files
committed
Upgrade reEnteredPayDialogSolution for Taobao and Alipay
1 parent 650bd61 commit 72e7781

File tree

2 files changed

+21
-68
lines changed

2 files changed

+21
-68
lines changed

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

+10-34
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
import android.app.AlertDialog;
88
import android.content.Context;
99
import android.graphics.Color;
10-
import android.os.Build;
11-
import android.os.Bundle;
10+
import android.os.*;
1211
import android.text.TextUtils;
1312
import android.util.TypedValue;
1413
import android.view.Gravity;
1514
import android.view.View;
1615
import android.view.ViewGroup;
16+
import android.view.ViewTreeObserver;
1717
import android.widget.EditText;
1818
import android.widget.FrameLayout;
1919
import android.widget.ImageView;
@@ -357,10 +357,6 @@ private void setupPaymentItemOnClickListener(ViewGroup rootView) {
357357
ViewUtils.getChildViewsByRegex(rootView, ".*选中,.+", paymentMethodsViewList);
358358
long paymentMethodsViewListSize = paymentMethodsViewList.size();
359359
for (int i = 0; i < paymentMethodsViewListSize; i++) {
360-
if (i == paymentMethodsViewListSize - 1) {
361-
// 最后一个
362-
continue;
363-
}
364360
View paymentMethodView = paymentMethodsViewList.get(i);
365361
L.d("paymentMethodView", ViewUtils.getViewInfo(paymentMethodView));
366362
// 只取第一次, 防止多次调用造成出错
@@ -413,34 +409,14 @@ private void reEnteredPayDialogSolution(Activity activity) {
413409
activityViewObserver, 300, (observer, view) -> {
414410
ActivityViewObserverHolder.stop(observer);
415411
L.d("找到密码框", view);
416-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
417-
view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
418-
private boolean lastFocusState = true; //初始化默认给true
419-
@Override
420-
public void onFocusChange(View v, boolean hasFocus) {
421-
L.d("密码框", "onFocusChange", view, hasFocus);
422-
try {
423-
// 如果失去焦点并且获得新焦点, 通常是切换支付方式, 尝试重新触发识别
424-
if (!lastFocusState && hasFocus) {
425-
// 如果支付方式点了第一项, 页面会刷新, 需要重建OnclickListener
426-
Task.onMain(666, () -> {
427-
setupPaymentItemOnClickListener(rootView);
428-
});
429-
AlertDialog dialog = mFingerPrintAlertDialog;
430-
if (dialog == null) {
431-
return;
432-
}
433-
if (!dialog.isShowing()) {
434-
dialog.show();
435-
}
436-
}
437-
} finally {
438-
lastFocusState = hasFocus;
439-
}
440-
}
441-
442-
});
443-
}
412+
Object debounceToken = new Object();
413+
Handler debounceHandler = view.getHandler();
414+
view.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
415+
debounceHandler.removeCallbacksAndMessages(debounceToken);
416+
debounceHandler.postAtTime(() -> {
417+
setupPaymentItemOnClickListener(rootView);
418+
}, debounceToken, SystemClock.uptimeMillis() + 666);
419+
});
444420
},
445421
10000);
446422
}

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

+11-34
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import android.graphics.Color;
99
import android.os.Build;
1010
import android.os.Bundle;
11+
import android.os.*;
1112
import android.text.TextUtils;
1213
import android.util.TypedValue;
1314
import android.view.Gravity;
1415
import android.view.View;
1516
import android.view.ViewGroup;
17+
import android.view.ViewTreeObserver;
1618
import android.widget.EditText;
1719
import android.widget.LinearLayout;
1820
import android.widget.TextView;
@@ -328,10 +330,6 @@ private void setupPaymentItemOnClickListener(ViewGroup rootView) {
328330
ViewUtils.getChildViewsByRegex(rootView, ".*选中,.+", paymentMethodsViewList);
329331
long paymentMethodsViewListSize = paymentMethodsViewList.size();
330332
for (int i = 0; i < paymentMethodsViewListSize; i++) {
331-
if (i == paymentMethodsViewListSize - 1) {
332-
// 最后一个
333-
continue;
334-
}
335333
View paymentMethodView = paymentMethodsViewList.get(i);
336334
L.d("paymentMethodView", ViewUtils.getViewInfo(paymentMethodView));
337335
// 只取第一次, 防止多次调用造成出错
@@ -380,39 +378,18 @@ private void reEnteredPayDialogSolution(Activity activity) {
380378
outViewList.add(shortPwdView);
381379
}
382380
});
383-
ActivityViewObserverHolder.start(ActivityViewObserverHolder.Key.TaobaoPasswordView,
381+
ActivityViewObserverHolder.start(ActivityViewObserverHolder.Key.AlipayPasswordView,
384382
activityViewObserver, 300, (observer, view) -> {
385383
ActivityViewObserverHolder.stop(observer);
386384
L.d("找到密码框", view);
387-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
388-
view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
389-
private boolean lastFocusState = true; //初始化默认给true
390-
@Override
391-
public void onFocusChange(View v, boolean hasFocus) {
392-
L.d("密码框", "onFocusChange", view, hasFocus);
393-
try {
394-
// 如果失去焦点并且获得新焦点, 通常是切换支付方式, 尝试重新触发识别
395-
if (!lastFocusState && hasFocus) {
396-
// 如果支付方式点了第一项, 页面会刷新, 需要重建OnclickListener
397-
Task.onMain(666, () -> {
398-
setupPaymentItemOnClickListener(rootView);
399-
});
400-
AlertDialog dialog = mFingerPrintAlertDialog;
401-
if (dialog == null) {
402-
return;
403-
}
404-
if (!dialog.isShowing()) {
405-
dialog.show();
406-
}
407-
}
408-
} finally {
409-
lastFocusState = hasFocus;
410-
}
411-
412-
}
413-
414-
});
415-
}
385+
Object debounceToken = new Object();
386+
Handler debounceHandler = view.getHandler();
387+
view.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
388+
debounceHandler.removeCallbacksAndMessages(debounceToken);
389+
debounceHandler.postAtTime(() -> {
390+
setupPaymentItemOnClickListener(rootView);
391+
}, debounceToken, SystemClock.uptimeMillis() + 666);
392+
});
416393
},
417394
10000);
418395
}

0 commit comments

Comments
 (0)