1010import android .os .Build ;
1111import android .os .SystemClock ;
1212import android .support .annotation .Nullable ;
13+ import android .support .v7 .widget .AppCompatImageView ;
14+ import android .support .v7 .widget .ButtonBarLayout ;
15+ import android .support .v7 .widget .ListViewCompat ;
16+ import android .support .v7 .widget .SwitchCompat ;
1317import android .text .TextUtils ;
1418import android .view .MotionEvent ;
1519import android .view .View ;
1620import android .view .ViewGroup ;
1721import android .view .ViewParent ;
22+ import android .widget .CheckBox ;
23+ import android .widget .CheckedTextView ;
24+ import android .widget .EditText ;
25+ import android .widget .FrameLayout ;
26+ import android .widget .GridLayout ;
27+ import android .widget .GridView ;
28+ import android .widget .ImageView ;
29+ import android .widget .LinearLayout ;
30+ import android .widget .ListView ;
31+ import android .widget .ProgressBar ;
32+ import android .widget .QuickContactBadge ;
33+ import android .widget .RadioButton ;
34+ import android .widget .RatingBar ;
35+ import android .widget .RelativeLayout ;
36+ import android .widget .SeekBar ;
37+ import android .widget .Space ;
38+ import android .widget .Spinner ;
39+ import android .widget .Switch ;
40+ import android .widget .TableLayout ;
41+ import android .widget .TableRow ;
1842import android .widget .TextView ;
1943
2044import com .yyxx .wechatfp .util .log .L ;
@@ -160,10 +184,78 @@ public static View findViewByText(View rootView, String... names) {
160184 return null ;
161185 }
162186
187+ private static Class sRecycleViewClz ;
188+
189+ private static String getViewBaseDesc (View view ) {
190+ if (sRecycleViewClz == null ) {
191+ try {
192+ sRecycleViewClz = Class .forName ("android.support.v7.widget.RecyclerView" );
193+ } catch (ClassNotFoundException e ) {
194+ }
195+ }
196+
197+ if (view instanceof FrameLayout ) {
198+ return FrameLayout .class .getName ();
199+ } else if (view instanceof RatingBar ) {
200+ return RatingBar .class .getName ();
201+ } else if (view instanceof SeekBar ) {
202+ return SeekBar .class .getName ();
203+ } else if (view instanceof TableLayout ) {
204+ return TableLayout .class .getName ();
205+ } else if (view instanceof ButtonBarLayout ) {
206+ return ButtonBarLayout .class .getName ();
207+ } else if (view instanceof TableRow ) {
208+ return TableRow .class .getName ();
209+ } else if (view instanceof LinearLayout ) {
210+ return LinearLayout .class .getName ();
211+ } else if (view instanceof RelativeLayout ) {
212+ return RelativeLayout .class .getName ();
213+ } else if (view instanceof GridLayout ) {
214+ return GridLayout .class .getName ();
215+ } else if (view instanceof CheckBox ) {
216+ return CheckBox .class .getName ();
217+ } else if (view instanceof RadioButton ) {
218+ return RadioButton .class .getName ();
219+ } else if (view instanceof CheckedTextView ) {
220+ return CheckedTextView .class .getName ();
221+ } else if (view instanceof Spinner ) {
222+ return Spinner .class .getName ();
223+ } else if (view instanceof ProgressBar ) {
224+ return ProgressBar .class .getName ();
225+ } else if (view instanceof QuickContactBadge ) {
226+ return QuickContactBadge .class .getName ();
227+ } else if (view instanceof SwitchCompat ) {
228+ return SwitchCompat .class .getName ();
229+ } else if (view instanceof Switch ) {
230+ return Switch .class .getName ();
231+ } else if (view instanceof Space ) {
232+ return Space .class .getName ();
233+ } else if (view instanceof TextView ) {
234+ return TextView .class .getName ();
235+ } else if (view instanceof AppCompatImageView ) {
236+ return AppCompatImageView .class .getName ();
237+ } else if (view instanceof ImageView ) {
238+ return ImageView .class .getName ();
239+ } else if (view instanceof ListViewCompat ) {
240+ return ListViewCompat .class .getName ();
241+ } else if (view instanceof ListView ) {
242+ return ListView .class .getName ();
243+ } else if (view instanceof GridView ) {
244+ return ListView .class .getName ();
245+ } else if (sRecycleViewClz != null && view .getClass ().isAssignableFrom (sRecycleViewClz )) {
246+ return sRecycleViewClz .getName ();
247+ }
248+ return view .getClass ().getName ();
249+ }
250+
163251 public static String getViewInfo (View view ) {
164252 StringBuffer stringBuffer = new StringBuffer ();
165253 stringBuffer .append (String .valueOf (view ));
166- if (view instanceof TextView ) {
254+ stringBuffer .append (" type:" ).append (getViewBaseDesc (view ));
255+ stringBuffer .append (" clz:" ).append (view .getClass ().getName ());
256+ if (view instanceof EditText ) {
257+ stringBuffer .append (" text:" ).append (((EditText ) view ).getText ()).append (" hint:" ).append (((EditText ) view ).getHint ());
258+ } else if (view instanceof TextView ) {
167259 stringBuffer .append (" text:" ).append (((TextView ) view ).getText ());
168260 }
169261 int []location = new int []{0 ,0 };
@@ -173,9 +265,18 @@ public static String getViewInfo(View view) {
173265 if (!TextUtils .isEmpty (desc )) {
174266 stringBuffer .append (" desc:" ).append (desc );
175267 }
268+ stringBuffer .append (" tag:" ).append (view .getTag ());
176269 return stringBuffer .toString ();
177270 }
178271
272+ public static void recursiveLoopChildren (View view ) {
273+ if (view instanceof ViewGroup ) {
274+ recursiveLoopChildren ((ViewGroup ) view );
275+ } else {
276+ L .d ("Empty view" );
277+ }
278+ }
279+
179280 public static void recursiveLoopChildren (ViewGroup parent ) {
180281 for (int i = parent .getChildCount () - 1 ; i >= 0 ; i --) {
181282 final View child = parent .getChildAt (i );
@@ -186,7 +287,7 @@ public static void recursiveLoopChildren(ViewGroup parent) {
186287 } else {
187288 if (child != null ) {
188289 try {
189- L .d ("view" , getViewInfo (child ), child . getTag () );
290+ L .d ("view" , getViewInfo (child ));
190291 } catch (Exception e ) {
191292
192293 }
@@ -202,7 +303,13 @@ public static void getChildViews(ViewGroup parent, String text, List<View> outLi
202303 if (child == null ) {
203304 continue ;
204305 }
205- if (child instanceof TextView ) {
306+ if (child instanceof EditText ) {
307+ if (text .equals (String .valueOf (((TextView ) child ).getText ()))) {
308+ outList .add (child );
309+ } else if (text .equals (String .valueOf (((EditText ) child ).getHint ()))) {
310+ outList .add (child );
311+ }
312+ } else if (child instanceof TextView ) {
206313 if (text .equals (String .valueOf (((TextView ) child ).getText ()))) {
207314 outList .add (child );
208315 }
0 commit comments