android get view hierarchy for all windows in activity -


i making skd automation. needs different normal app development.

requirement: viewhierarchy of current activity. problem: correct when spinner not open. not details of spinner when open.

i use following code hierarchy. questions is: spinner hosted in different window why not getting it? way it?

    //this how start recursion view hierarchy     view view = getwindow().getdecorview().getrootview();     if (view instanceof viewgroup) {         viewgroup group = (viewgroup) view;         dumpviewhierarchywithproperties( group, 0);     }  //functions hierarchy private  void dumpviewhierarchywithproperties(viewgroup group,int level) {     if (!dumpviewwithproperties(group, level)) {         return;     }      final int count = group.getchildcount();     (int = 0; < count; i++) {         final view view = group.getchildat(i);         if (view instanceof viewgroup) {             dumpviewhierarchywithproperties((viewgroup) view, level + 1);         } else {             dumpviewwithproperties(view, level + 1);         }     } }  private  boolean dumpviewwithproperties(view view,int level) {      //add view hierarchy.     return true; } 

i have managed opened spinner popup view hierarchy using part of code in addition other reflection magic, here full code, take in mind reflection affect performance of sdk , applications use it.

//function available windows of application using reflection private void logrootviews() {     try {         class wmgclass = class.forname("android.view.windowmanagerglobal");         object wmginstnace = wmgclass.getmethod("getinstance").invoke(null, (object[])null);          method getviewrootnames = wmgclass.getmethod("getviewrootnames");         method getrootview = wmgclass.getmethod("getrootview", string.class);         string[] rootviewnames = (string[])getviewrootnames.invoke(wmginstnace, (object[])null);          for(string viewname : rootviewnames) {             view rootview = (view)getrootview.invoke(wmginstnace, viewname);             log.i(tag, "found root view: " + viewname + ": " + rootview);             getviewhierarchy(rootview);         }     } catch (exception e) {         e.printstacktrace();     } }  //functions hierarchy private void getviewhierarchy(view view) {     //this how start recursion view hierarchy     if (view instanceof viewgroup) {         viewgroup group = (viewgroup) view;         dumpviewhierarchywithproperties(group, 0);     } else {         dumpviewwithproperties(view, 0);     } }  private void dumpviewhierarchywithproperties(viewgroup group, int level) {     if (!dumpviewwithproperties(group, level)) {         return;     }      final int count = group.getchildcount();     (int = 0; < count; i++) {         final view view = group.getchildat(i);         if (view instanceof viewgroup) {             dumpviewhierarchywithproperties((viewgroup) view, level + 1);         } else {             dumpviewwithproperties(view, level + 1);         }     } }  private boolean dumpviewwithproperties(view view, int level) {     //add view hierarchy.     if (view instanceof textview) {         log.d(tag, "textview hierarchy dumped: " + view.tostring() + " text: " + ((textview) view).gettext().tostring() + " ,in level: " + level);     } else {         log.d(tag, "view hierarchy dumped: " + view.tostring() + " ,in level: " + level);     }     return true; } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -