Changeset 1871


Ignore:
Timestamp:
02/03/15 12:37:19 (9 years ago)
Author:
funger
Message:
  • improve documentation
  • fix a bug
Location:
trunk/autoquest-androidmonitor/src/main/java/de/ugoe/cs/autoquest/androidmonitor
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-androidmonitor/src/main/java/de/ugoe/cs/autoquest/androidmonitor/AndroidMonitor.java

    r1842 r1871  
    6262        return monitor; 
    6363    } 
    64     
    6564 
    6665    /** 
     
    7069     */ 
    7170    public void startMonitor(Activity activity) { 
    72         //create logFile only once 
    73         if(AndroidMonitor.logFile == null){ 
     71        // create logFile only once. 
     72        if (AndroidMonitor.logFile == null) { 
    7473            AndroidMonitor.logFile = new AndroidMonitorLogFile(activity); 
    7574            Log.i("logfile", "file created"); 
    7675        } 
    77         activityName = activity.getClass().getSimpleName();   
     76        activityName = activity.getClass().getSimpleName(); 
    7877        addLogListenerToView(getRootView(activity)); 
    79          
    80  
    81         // TODO 
    82         // listen to changes and update own listener 
    83  
    84         // write backPresss as event to xml file 
    85         // activity.onBackPressed(); 
    86  
    87         // handle onStop() method of the activity 
    88         // add a function that end up tracking if onStop() is given otherwise 
    89         // create onStop() 
    90         // http://developer.android.com/training/basics/activity-lifecycle/stopping.html 
    91     } 
    92     public void startMonitor(View view){ 
     78 
     79        /* 
     80         * TODO listen to changes and update own listener. - Listen to known elements is implemented 
     81         * and trigger startMonitot(View). 
     82         */ 
     83        /* 
     84         * TODO write backPresss as event to xml file activity.onBackPressed(); 
     85         */ 
     86        /* 
     87         * TODO handle onStop() method of the activity add a function that end up tracking if 
     88         * onStop() is given otherwise. Maybe: create onStop() 
     89         * http://developer.android.com/training/basics/activity-lifecycle/stopping.html 
     90         */ 
     91    } 
     92 
     93    public void startMonitor(View view) { 
    9394        addLogListenerToView(findFirstView(view)); 
    9495    } 
    95      
     96 
    9697    /** 
    9798     * Get the root view of an activity. 
     
    149150        if (!AndroidMonitorLogFile.isComponentLogged(view.hashCode())) { 
    150151            AndroidMonitor.logFile.addComponent(view, parentHash, activityName); 
     152 
     153            Log.i("object type", ""); 
    151154 
    152155            // save original listener to add it later on to the groupLisatener 
     
    215218     * @return the listener of the view or null if no listener exists 
    216219     */ 
     220    // source: http://stackoverflow.com/questions/11186960/getonclicklistener-in-android-views 
    217221    private View.OnClickListener getOnClickListener(View view) { 
    218         // http://stackoverflow.com/questions/11186960/getonclicklistener-in-android-views 
    219222        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 
    220223            return getOnClickListenerV14(view); 
     
    226229 
    227230    // Used for APIs lower than ICS (API 14) 
     231    // source: http://stackoverflow.com/questions/11186960/getonclicklistener-in-android-views 
    228232    private View.OnClickListener getOnClickListenerV(View view) { 
    229233        View.OnClickListener retrievedListener = null; 
     
    250254    // Used for new ListenerInfo class structure used beginning with API 14 
    251255    // (ICS) 
     256    // source: http://stackoverflow.com/questions/11186960/getonclicklistener-in-android-views 
    252257    private View.OnClickListener getOnClickListenerV14(View view) { 
    253258        View.OnClickListener retrievedListener = null; 
     
    283288    } 
    284289 
    285      
    286      
    287290    /** 
    288291     *  
     
    290293     * Return the AndroidMonitorLogFile that is used in the AndroidMonitor. 
    291294     * </p> 
    292      * 
    293      * @return AndroidMonitorLogFile  
    294      *          that is used in the AndroidMonitor. 
    295      */ 
    296     public AndroidMonitorLogFile getLogFile(){ 
    297         return logFile;         
     295     *  
     296     * @return AndroidMonitorLogFile that is used in the AndroidMonitor. 
     297     */ 
     298    public AndroidMonitorLogFile getLogFile() { 
     299        return logFile; 
    298300    } 
    299301} 
  • trunk/autoquest-androidmonitor/src/main/java/de/ugoe/cs/autoquest/androidmonitor/AndroidMonitorLogFile.java

    r1842 r1871  
    9090     */ 
    9191    public AndroidMonitorLogFile(Activity activity) { 
    92  
    93         AndroidMonitorLogFile.currentLoggedComponents = new ArrayList<Integer>(); 
    94  
    95         AndroidMonitorLogFile.appName = getAppLable(activity); 
    96  
    9792        createFile(activity); 
    9893    } 
     
    111106 
    112107    /** 
    113      * Get application name as defined in Package Name 
     108     * Get application name as defined in Package Name and write it to appName. 
    114109     *  
    115110     * @param pContext 
     
    121116        // http://stackoverflow.com/questions/11229219/android-get-application-name-not-package-name 
    122117        // (last call 2014-09-04) 
     118        String appLabel; 
    123119        PackageManager lPackageManager = pContext.getPackageManager(); 
    124120        ApplicationInfo lApplicationInfo = null; 
     
    127123                lPackageManager.getApplicationInfo(pContext.getApplicationInfo().packageName, 0); 
    128124        } 
    129         catch (final NameNotFoundException e) {} 
    130         return (String) (lApplicationInfo != null ? lPackageManager 
     125        catch (final NameNotFoundException e) { 
     126             
     127        } 
     128        appLabel = (String) (lApplicationInfo != null ? lPackageManager 
    131129            .getApplicationLabel(lApplicationInfo) : "Unknown"); 
     130        return appLabel; 
    132131    } 
    133132 
     
    269268            serializer.startTag("", "component"); 
    270269            /* 
    271              * (non-Javadoc) TODO find a way in that the hash code is unique over time and target 
     270             * (non-Javadoc)  
     271             * TODO find a way in that the hash code is unique over time and target 
    272272             *  
    273273             * view.getId() seems to be unique over time and targets but there is a problem. In some 
    274274             * cases there is no ID (value: -1). 
    275275             *  
    276              * view.getId() is not unique in every case. E.g. in the application timerdroid the id 
    277              * of the list elements changes when calling home button. 
     276             * view.getId() returns different values in case of some identical components.  
     277             * E.g. in the application timerdroid the id of the list elements  
     278             * changes when calling home button. 
    278279             */ 
    279280            serializer.attribute("", "hash", "" + view.hashCode()); 
    280281            currentLoggedComponents.add(view.hashCode()); 
    281282 
     283            /* 
     284             * (non-Javadoc) 
     285             * http://developer.android.com/reference/android/view/View.html#getId() 
     286             * Returns this view's identifier. 
     287             */ 
    282288            serializer.startTag("", "param"); 
    283289            serializer.attribute("", "name", "id"); 
     
    296302                serializer.startTag("", "param"); 
    297303                serializer.attribute("", "name", "title"); 
    298                 
    299                  
    300304                serializer.attribute("", "value", "image:" ); 
    301305                serializer.endTag("", "param"); 
     
    316320            serializer.attribute("", "name", "parent"); 
    317321            /* 
    318              * (non-Javadoc) Problem in using view.getParent().hashCode(): 
     322             * (non-Javadoc)  
     323             * Problem in using view.getParent().hashCode(): 
    319324             * http://developer.android.com/reference/android/view/View.html#getParent() tells: 
    320325             * "... parent is a ViewParent and not necessarily a View." ViewParent does not have a 
     
    487492     */ 
    488493    private void createFile(Activity activity) { 
    489  
     494         
     495        AndroidMonitorLogFile.appName = getAppLable(activity); 
    490496        AndroidMonitorLogFile.name = 
    491497            "androidLogFile_" + AndroidMonitorLogFile.appName + System.currentTimeMillis() + ".log"; 
     
    494500                new File(activity.getFilesDir(), AndroidMonitorLogFile.name); 
    495501            if (AndroidMonitorLogFile.file.exists() && !AndroidMonitorLogFile.file.isDirectory()) { 
    496                 createFile(activity, 0); 
     502                createFile(activity, 0);                 
    497503            } 
    498504            else { 
     505                AndroidMonitorLogFile.currentLoggedComponents = new ArrayList<Integer>(); 
    499506                writeHeaderToFile(activity); 
     507                 
    500508            } 
    501509        } 
     
    521529            "androidLogFile_" + count + "_" + AndroidMonitorLogFile.appName + 
    522530                System.currentTimeMillis() + ".log"; 
     531         
    523532        try { 
    524533            AndroidMonitorLogFile.file = 
Note: See TracChangeset for help on using the changeset viewer.