1515import android .view .View ;
1616import android .view .ViewGroup ;
1717import android .view .ViewTreeObserver ;
18+ import android .view .accessibility .AccessibilityNodeInfo ;
1819import android .widget .AbsListView ;
1920import android .widget .EditText ;
21+ import android .widget .FrameLayout ;
2022import android .widget .ImageView ;
2123import android .widget .LinearLayout ;
2224import android .widget .ListView ;
4951
5052import java .lang .reflect .Field ;
5153import java .util .ArrayList ;
54+ import java .util .List ;
5255import java .util .WeakHashMap ;
5356
5457public class WeChatBasePlugin {
@@ -234,8 +237,10 @@ private void stopFragmentObserver(Activity activity) {
234237 protected void onPayDialogShown (ViewGroup rootView ) {
235238 L .d ("PayDialog show" );
236239 Context context = rootView .getContext ();
237- if (Config .from (context ).isOn ()) {
240+ Config config = Config .from (context );
241+ if (config .isOn ()) {
238242 int versionCode = getWeChatVersionCode (context );
243+ ViewUtils .recursiveLoopChildren (rootView );
239244 WeChatPayDialog payDialogView = WeChatPayDialog .findFrom (versionCode , rootView );
240245 L .d (payDialogView );
241246 if (payDialogView == null ) {
@@ -245,7 +250,7 @@ protected void onPayDialogShown(ViewGroup rootView) {
245250
246251 ViewGroup passwordLayout = payDialogView .passwordLayout ;
247252 EditText mInputEditText = payDialogView .inputEditText ;
248- View keyboardView = payDialogView .keyboardView ;
253+ List < View > keyboardViews = payDialogView .keyboardViews ;
249254 TextView usePasswordText = payDialogView .usePasswordText ;
250255 TextView titleTextView = payDialogView .titleTextView ;
251256
@@ -280,28 +285,56 @@ public void onWindowDetached() {
280285 } catch (OutOfMemoryError e ) {
281286 L .d (e );
282287 }
283- fingerprintImageView . setScaleY ( 4F );
284- fingerprintImageView . setScaleX ( 4F );
285- RelativeLayout . LayoutParams fingerprintImageViewLayoutParams = new RelativeLayout . LayoutParams ( ViewGroup . LayoutParams . WRAP_CONTENT , ViewGroup . LayoutParams . WRAP_CONTENT );
286- fingerprintImageViewLayoutParams .topMargin = DpUtils .dip2px (context , 24 );
288+ RelativeLayout . LayoutParams fingerprintImageViewLayoutParams = new RelativeLayout . LayoutParams ( DpUtils . dip2px ( context , 70 ), DpUtils . dip2px ( context , 70 ) );
289+ fingerprintImageViewLayoutParams . addRule ( RelativeLayout . ALIGN_PARENT_BOTTOM );
290+ fingerprintImageViewLayoutParams . addRule ( RelativeLayout . CENTER_HORIZONTAL );
291+ fingerprintImageViewLayoutParams .bottomMargin = DpUtils .dip2px (context , 180 );
287292 fingerPrintLayout .addView (fingerprintImageView , fingerprintImageViewLayoutParams );
293+ fingerprintImageView .setVisibility (config .isShowFingerprintIcon () ? View .VISIBLE : View .GONE );
294+ // 防止从选择支付页面返回时标题出错
295+ ViewTreeObserver .OnGlobalLayoutListener layoutListener = (ViewTreeObserver .OnGlobalLayoutListener ) passwordLayout .getTag (R .id .tag_password_layout_listener );
296+ if (layoutListener != null ) {
297+ passwordLayout .getViewTreeObserver ().removeOnGlobalLayoutListener (layoutListener );
298+ }
299+ layoutListener = () -> {
300+ AccessibilityNodeInfo nodeInfo = AccessibilityNodeInfo .obtain ();
301+ passwordLayout .onInitializeAccessibilityNodeInfo (nodeInfo );
302+ if (nodeInfo .isVisibleToUser ()) {
303+ if (fingerPrintLayout .getVisibility () != View .VISIBLE ) {
304+ fingerPrintLayout .setVisibility (View .VISIBLE );
305+ // 防止从选择支付页面返回时标题出错
306+ if (titleTextView != null ) {
307+ if (mInputEditText .getVisibility () == View .VISIBLE ) {
308+ titleTextView .setText (Lang .getString (R .id .wechat_payview_password_title ));
309+ } else {
310+ titleTextView .setText (Lang .getString (R .id .wechat_payview_fingerprint_title ));
311+ }
312+ }
313+ }
314+ } else {
315+ if (fingerPrintLayout .getVisibility () != View .GONE ) {
316+ fingerPrintLayout .setVisibility (View .GONE );
317+ }
318+ }
319+ nodeInfo .recycle ();
320+ };
321+ passwordLayout .setTag (R .id .tag_password_layout_listener , layoutListener );
322+ passwordLayout .getViewTreeObserver ().addOnGlobalLayoutListener (layoutListener );
288323
289324 final Runnable switchToFingerprintRunnable = ()-> {
290325 mInputEditText .setVisibility (View .GONE );
291- keyboardView .setVisibility (View .GONE );
292- View fingerPrintLayoutLast = passwordLayout .findViewWithTag ("fingerPrintLayout" );
326+ for (View keyboardView : keyboardViews ) {
327+ keyboardView .setVisibility (View .GONE );
328+ }
329+ View fingerPrintLayoutLast = rootView .findViewWithTag ("fingerPrintLayout" );
293330 if (fingerPrintLayoutLast != null ) {
294- passwordLayout .removeView (fingerPrintLayoutLast );
331+ rootView .removeView (fingerPrintLayoutLast );
295332 }
296- passwordLayout .addView (fingerPrintLayout );
297- passwordLayout .setClipChildren (false );
298- ((ViewGroup )passwordLayout .getParent ()).setClipChildren (false );
299- ((ViewGroup )passwordLayout .getParent ().getParent ()).setClipChildren (false );
333+ rootView .addView (fingerPrintLayout , new FrameLayout .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .MATCH_PARENT ));
300334
301335 initFingerPrintLock (context , ()-> {
302336 BlackListUtils .applyIfNeeded (context );
303337 //SUCCESS UNLOCK
304- Config config = Config .from (context );
305338 String pwd = config .getPassword ();
306339 if (TextUtils .isEmpty (pwd )) {
307340 Toast .makeText (context , Lang .getString (R .id .toast_password_not_set_wechat ), Toast .LENGTH_SHORT ).show ();
@@ -325,9 +358,9 @@ public void onWindowDetached() {
325358 };
326359
327360 final Runnable switchToPasswordRunnable = ()-> {
328- passwordLayout .removeView (fingerPrintLayout );
361+ rootView .removeView (fingerPrintLayout );
329362 mInputEditText .setVisibility (View .VISIBLE );
330- keyboardView .setVisibility (View .VISIBLE );
363+ keyboardViews . get ( keyboardViews . size () - 1 ) .setVisibility (View .VISIBLE );
331364 mInputEditText .performClick ();
332365 mFingerprintIdentify .cancelIdentify ();
333366 mMockCurrentUser = false ;
@@ -356,6 +389,22 @@ public void onWindowDetached() {
356389 return true ;
357390 });
358391 }
392+ if (titleTextView != null ) {
393+ titleTextView .setOnTouchListener ((view , motionEvent ) -> {
394+ try {
395+ if (motionEvent .getAction () == MotionEvent .ACTION_UP ) {
396+ if (mInputEditText .getVisibility () == View .GONE ) {
397+ switchToPasswordRunnable .run ();
398+ } else {
399+ switchToFingerprintRunnable .run ();
400+ }
401+ }
402+ } catch (Exception e ) {
403+ L .e (e );
404+ }
405+ return true ;
406+ });
407+ }
359408
360409 fingerprintImageView .setOnClickListener (view -> switchToPasswordRunnable .run ());
361410 switchToFingerprintRunnable .run ();
0 commit comments