1616
1717import com .yyxx .wechatfp .util .log .L ;
1818
19+ import java .util .ArrayList ;
20+ import java .util .List ;
1921import java .util .Random ;
2022import java .util .concurrent .atomic .AtomicInteger ;
2123
@@ -67,7 +69,7 @@ public static void performActionClick(View view) {
6769 height = 0 ;
6870 }
6971 long downTime = SystemClock .uptimeMillis ();
70- long eventTime = SystemClock .uptimeMillis () + 100 ;
72+ long eventTime = SystemClock .uptimeMillis () + 200 ;
7173
7274 float x = width > 0 ? new Random (downTime ).nextInt (width ) : 0 ;
7375 float y = height > 0 ? new Random (eventTime ).nextInt (height ) : 0 ;
@@ -114,9 +116,19 @@ public static View findViewByName(Activity activity, String packageName, String.
114116 if (id == 0 ) {
115117 continue ;
116118 }
117- View view = activity .findViewById (id );
118- if (view != null ) {
119- return view ;
119+ View rootView = activity .getWindow ().getDecorView ();
120+ List <View > viewList = new ArrayList <>();
121+ getChildViews ((ViewGroup ) rootView , id , viewList );
122+ int outViewListSize = viewList .size ();
123+ if (outViewListSize == 1 ) {
124+ return viewList .get (0 );
125+ } else if (outViewListSize > 1 ) {
126+ for (View view : viewList ) {
127+ if (view .isShown ()) {
128+ return view ;
129+ }
130+ }
131+ return viewList .get (0 );
120132 }
121133 }
122134 return null ;
@@ -142,4 +154,20 @@ public static void recursiveLoopChildren(ViewGroup parent) {
142154 }
143155 }
144156 }
157+
158+ public static void getChildViews (ViewGroup parent , int id ,List <View > outList ) {
159+ for (int i = parent .getChildCount () - 1 ; i >= 0 ; i --) {
160+ final View child = parent .getChildAt (i );
161+ if (child == null ) {
162+ continue ;
163+ }
164+ if (id == child .getId ()) {
165+ outList .add (child );
166+ }
167+ if (child instanceof ViewGroup ) {
168+ getChildViews ((ViewGroup ) child , id , outList );
169+ } else {
170+ }
171+ }
172+ }
145173}
0 commit comments