Index: trunk/autoquest-androidmonitor/src/main/java/de/ugoe/cs/autoquest/androidmonitor/AndroidMonitor.java
===================================================================
--- trunk/autoquest-androidmonitor/src/main/java/de/ugoe/cs/autoquest/androidmonitor/AndroidMonitor.java	(revision 1833)
+++ trunk/autoquest-androidmonitor/src/main/java/de/ugoe/cs/autoquest/androidmonitor/AndroidMonitor.java	(revision 1842)
@@ -19,8 +19,4 @@
 import de.ugoe.cs.autoquest.androidmonitor.AndroidMonitorCompositeOnClickListener;
 import android.app.Activity;
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
 import android.os.Build;
 import android.text.Editable;
@@ -48,5 +44,5 @@
      * </p>
      */
-    String activityName;
+    private String activityName;
 
     /**
@@ -55,5 +51,5 @@
      * </p>
      */
-    private AndroidMonitorLogFile logFile;
+    private static AndroidMonitorLogFile logFile = null;
 
     /**
@@ -66,4 +62,5 @@
         return monitor;
     }
+   
 
     /**
@@ -73,15 +70,15 @@
      */
     public void startMonitor(Activity activity) {
-        activityName = activity.getClass().getSimpleName();
-
-        logFile = new AndroidMonitorLogFile(getAppLable(activity), activity.getFilesDir());
-
+        //create logFile only once
+        if(AndroidMonitor.logFile == null){
+            AndroidMonitor.logFile = new AndroidMonitorLogFile(activity);
+            Log.i("logfile", "file created");
+        }
+        activityName = activity.getClass().getSimpleName();  
         addLogListenerToView(getRootView(activity));
+        
 
         // TODO
         // listen to changes and update own listener
-        // find out if it is possible to directly call addLogListenerToView
-        // again
-        // activity.onContentChanged();
 
         // write backPresss as event to xml file
@@ -93,12 +90,15 @@
         // http://developer.android.com/training/basics/activity-lifecycle/stopping.html
     }
-
-    /**
-     * get the root view of an activity
+    public void startMonitor(View view){
+        addLogListenerToView(findFirstView(view));
+    }
+    
+    /**
+     * Get the root view of an activity.
      * 
      * @param activity
      * @return
      */
-    public View getRootView(Activity activity) {
+    private View getRootView(Activity activity) {
         // get root view of the activity as start point
         View view = activity.getWindow().getDecorView().getRootView();
@@ -111,5 +111,5 @@
 
     /**
-     * returns first view element of the tree
+     * Returns first view element of the tree.
      * 
      * @param view
@@ -127,10 +127,10 @@
     /**
      * Replace the listener of each view with a composite listener which collects several listeners
-     * for one view.
+     * for one view. Add a TextWatcher to all TexView views.
      * 
      * @param view
      *            to be monitored
      */
-    public void addLogListenerToView(View view) {
+    private void addLogListenerToView(View view) {
         addLogListenerToView(view, 0);
     }
@@ -147,11 +147,54 @@
     private void addLogListenerToView(View view, int parentHash) {
 
-        if (!logFile.isComponentLogged(view.hashCode())) {
-            logFile.addComponent(view, parentHash, activityName);
+        if (!AndroidMonitorLogFile.isComponentLogged(view.hashCode())) {
+            AndroidMonitor.logFile.addComponent(view, parentHash, activityName);
+
+            // save original listener to add it later on to the groupLisatener
+            View.OnClickListener onClickListener = getOnClickListener(view);
+
+            if (onClickListener != null) {
+                // create new compositeOnClickListener to handle multiple listeners
+                // for one view
+                AndroidMonitorCompositeOnClickListener groupListener =
+                    new AndroidMonitorCompositeOnClickListener();
+                // replace the original onClickListener with the
+                // compositeOnClickListener
+                view.setOnClickListener(groupListener);
+                // add the tracking part as a several listener
+                groupListener.addOnClickListener(new View.OnClickListener() {
+                    public void onClick(View v) {
+
+                        AndroidMonitor.logFile.addEvent(v, "onClick");
+                        // check if something changed in the activity
+                        startMonitor(v);
+                    }
+                });
+
+                groupListener.addOnClickListener(onClickListener);
+            }
+            // if view is a TextView add a addTextChangedListener to this view
+            if (view instanceof TextView) {
+                final int hashOfView = view.hashCode();
+                TextView textView = (TextView) view;
+                textView.addTextChangedListener(new TextWatcher() {
+                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+                        // do nothing
+                    }
+
+                    public void onTextChanged(CharSequence s, int start, int before, int count) {
+                        // do nothing
+                    }
+
+                    public void afterTextChanged(Editable s) {
+                        AndroidMonitor.logFile.addEvent(hashOfView, "text", s.toString());
+                    }
+
+                });
+            }
         }
 
         // hash code of the actual view element. Problem in using
         // view.getParent().hashCode() is described in
-        // de.ugoe.cs.autoquest.androidmonitor#addComponent()
+        // de.ugoe.cs.autoquest.androidmonitor.AndroidMonitorLogFile#addComponent()
         parentHash = view.hashCode();
         // traverse all views of the activity
@@ -164,44 +207,4 @@
         }
 
-        // save original listener to add it later on to the groupLisatener
-        View.OnClickListener onClickListener = getOnClickListener(view);
-
-        if (onClickListener != null) {
-            // create new compositeOnClickListener to handle multiple listeners
-            // for one view
-            AndroidMonitorCompositeOnClickListener groupListener =
-                new AndroidMonitorCompositeOnClickListener();
-            // replace the original onClickListener with the
-            // compositeOnClickListener
-            view.setOnClickListener(groupListener);
-            // add the tracking part as a several listener
-            groupListener.addOnClickListener(new View.OnClickListener() {
-                public void onClick(View v) {
-
-                    logFile.addEvent(v, "onClick");
-                }
-            });
-
-            groupListener.addOnClickListener(onClickListener);
-        }
-        // if view is a TextView add a addTextChangedListener to this view
-        if (view instanceof TextView) {
-            final int hashOfView = view.hashCode();
-            TextView textView = (TextView) view;
-            textView.addTextChangedListener(new TextWatcher() {
-                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-                    // do nothing
-                }
-
-                public void onTextChanged(CharSequence s, int start, int before, int count) {
-                    // do nothing
-                }
-
-                public void afterTextChanged(Editable s) {
-                    logFile.addEvent(hashOfView, "text", s.toString());
-                }
-
-            });
-        }
     }
 
@@ -212,5 +215,5 @@
      * @return the listener of the view or null if no listener exists
      */
-    public View.OnClickListener getOnClickListener(View view) {
+    private View.OnClickListener getOnClickListener(View view) {
         // http://stackoverflow.com/questions/11186960/getonclicklistener-in-android-views
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
@@ -280,23 +283,17 @@
     }
 
-    /**
-     * get application name as defined in Package Name
-     * 
-     * @param pContext
-     *            package context; could also be an activity
-     * @return app name
-     */
-    public String getAppLable(Context pContext) {
-        // source (2014-09-04):
-        // http://stackoverflow.com/questions/11229219/android-get-application-name-not-package-name
-        PackageManager lPackageManager = pContext.getPackageManager();
-        ApplicationInfo lApplicationInfo = null;
-        try {
-            lApplicationInfo =
-                lPackageManager.getApplicationInfo(pContext.getApplicationInfo().packageName, 0);
-        }
-        catch (final NameNotFoundException e) {}
-        return (String) (lApplicationInfo != null ? lPackageManager
-            .getApplicationLabel(lApplicationInfo) : "Unknown");
+    
+    
+    /**
+     * 
+     * <p>
+     * Return the AndroidMonitorLogFile that is used in the AndroidMonitor.
+     * </p>
+     *
+     * @return AndroidMonitorLogFile 
+     *          that is used in the AndroidMonitor.
+     */
+    public AndroidMonitorLogFile getLogFile(){
+        return logFile;        
     }
 }
Index: trunk/autoquest-androidmonitor/src/main/java/de/ugoe/cs/autoquest/androidmonitor/AndroidMonitorLogFile.java
===================================================================
--- trunk/autoquest-androidmonitor/src/main/java/de/ugoe/cs/autoquest/androidmonitor/AndroidMonitorLogFile.java	(revision 1833)
+++ trunk/autoquest-androidmonitor/src/main/java/de/ugoe/cs/autoquest/androidmonitor/AndroidMonitorLogFile.java	(revision 1842)
@@ -25,12 +25,22 @@
 import org.xmlpull.v1.XmlSerializer;
 
+import android.app.Activity;
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
 import android.util.Log;
 import android.util.Xml;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
 
 /**
  * <p>
- * TODO comment
+ * Writes informations about the device, the application, the components of the activity and the
+ * events in a log file. File is stored in the space of the application. Path is normally internal
+ * storage: data/data/<package name of the application using the AndroidMonitor>/files/ e.g.
+ * data/data/de.ugoe.cs.autoquest.androidmonitor.testApp/files/
  * </p>
  * 
@@ -45,13 +55,20 @@
      * </p>
      */
-    private String name;
-    
-    /**
-     * <p>
-     * File representation to store monitored information. 
-     * </p>
-     */
-    private File file;
-    
+    private static String name;
+
+    /**
+     * <p>
+     * Name of the Application which is monitored.
+     * </p>
+     */
+    private static String appName;
+
+    /**
+     * <p>
+     * File representation to store monitored information.
+     * </p>
+     */
+    private static File file;
+
     /**
      * <p>
@@ -59,5 +76,5 @@
      * </p>
      */
-    private List<Integer> currentLoggedComponents;
+    private static List<Integer> currentLoggedComponents;
 
     /**
@@ -66,59 +83,17 @@
      * Constructor. Creates a new AndroidmonitorLogFile.
      * </p>
-     *
+     * 
      * @param appName
-     *          Name of the calling application.
+     *            Name of the calling application.
      * @param dir
-     *          Folder to store the log file.
-     */
-    public AndroidMonitorLogFile(String appName, File dir) {
-        
-        currentLoggedComponents = new ArrayList<Integer>();
-        
-        this.name = "androidLogFile_" + appName + System.currentTimeMillis() + ".log";
-
-        try {
-                // prove if file exists
-                this.file = new File(dir, this.name);
-                /*
-                 * if file does not exists write device and app information to a new
-                 * file. Otherwise use existing file and add activity information to
-                 * file.
-                 */
-                // TODO prove if file exists and add activity information
-                if (true) { // !this.file.exists()
-                        /*
-                         * create log file. Using method openFileOutput() does not work
-                         * for this project due to the reason that this method would try
-                         * to create the file in the directory of the non-existing
-                         * directory de.ugoe.cs.androidmonitor. This directory does not
-                         * exist due to the reason that this project is a library and
-                         * the file has to be stored in the directory of the running
-                         * application. Furthermore it would not be possible to write in
-                         * another app directory as the own one.
-                         */
-
-                        String string = "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><sessions>";
-                        
-                        try {
-                                FileOutputStream outputStream = new FileOutputStream(
-                                                this.file);
-                                outputStream.write(string.getBytes());
-                                outputStream.close();
-                        } catch (Exception e) {
-                                Log.e("this.file", "outputstream: " + e.getMessage());
-                        }
-                        
-                        setDeviceInformation();
-                        setAppInformation();
-
-                } 
-                /*else {
-                        // TODO add activity information
-                }*/
-        } catch (Exception e) {
-                e.printStackTrace();
-                Log.e("file", "file: " + e.getMessage());
-        }
+     *            Folder to store the log file.
+     */
+    public AndroidMonitorLogFile(Activity activity) {
+
+        AndroidMonitorLogFile.currentLoggedComponents = new ArrayList<Integer>();
+
+        AndroidMonitorLogFile.appName = getAppLable(activity);
+
+        createFile(activity);
     }
 
@@ -128,9 +103,45 @@
      * Get file name which is in use.
      * </p>
-     *
+     * 
      * @return filename
      */
-    public String getFileName() {
-            return this.name;
+    public static String getFileName() {
+        return AndroidMonitorLogFile.name;
+    }
+
+    /**
+     * Get application name as defined in Package Name
+     * 
+     * @param pContext
+     *            package context; could also be an activity
+     * @return app name
+     */
+    private String getAppLable(Context pContext) {
+        // source:
+        // http://stackoverflow.com/questions/11229219/android-get-application-name-not-package-name
+        // (last call 2014-09-04)
+        PackageManager lPackageManager = pContext.getPackageManager();
+        ApplicationInfo lApplicationInfo = null;
+        try {
+            lApplicationInfo =
+                lPackageManager.getApplicationInfo(pContext.getApplicationInfo().packageName, 0);
+        }
+        catch (final NameNotFoundException e) {}
+        return (String) (lApplicationInfo != null ? lPackageManager
+            .getApplicationLabel(lApplicationInfo) : "Unknown");
+    }
+
+    /**
+     * 
+     * <p>
+     * Get package Name.
+     * </p>
+     * 
+     * @param pContext
+     *            package context; could also be an activity
+     * @return package name
+     */
+    private String getAppPackageName(Context pContext) {
+        return pContext.getPackageName();
     }
 
@@ -140,10 +151,44 @@
      * Writes information about the application to the log file.
      * </p>
-     *
-     */
-    private void setAppInformation() {
-            // TODO create app information in the same manner as coded in
-            // getDeviceInformation
-            
+     * 
+     * @param activity
+     * 
+     */
+    private void setAppInformation(Activity activity) {
+
+        XmlSerializer serializer = Xml.newSerializer();
+        StringWriter writer = new StringWriter();
+        try {
+            serializer.setOutput(writer);
+
+            serializer.startTag("", "application");
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "value", getAppPackageName(activity));
+            serializer.attribute("", "name", "package");
+            serializer.endTag("", "param");
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "value", getAppLable(activity));
+            serializer.attribute("", "name", "name");
+            serializer.endTag("", "param");
+
+            serializer.endTag("", "application");
+            serializer.endDocument();
+
+            writeToFile(writer.toString());
+        }
+        catch (IllegalArgumentException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
+        catch (IllegalStateException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
+        catch (IOException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
     }
 
@@ -155,53 +200,51 @@
      */
     private void setDeviceInformation() {
-           
-            XmlSerializer serializer = Xml.newSerializer();
-            StringWriter writer = new StringWriter();
-            try {
-                    serializer.setOutput(writer);
-                    serializer.startTag("", "device");
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "value", ""
-                                    + android.os.Build.VERSION.SDK_INT);
-                    serializer.attribute("", "name", "sdk_version");
-                    serializer.endTag("", "param");
-
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "value", android.os.Build.DEVICE);
-                    serializer.attribute("", "name", "device");
-                    serializer.endTag("", "param");
-
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "value", android.os.Build.MANUFACTURER);
-                    serializer.attribute("", "name", "manufacturer");
-                    serializer.endTag("", "param");
-
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "value", android.os.Build.MODEL);
-                    serializer.attribute("", "name", "model");
-                    serializer.endTag("", "param");
-
-                    // TODO get resolution ...
-
-                    serializer.endTag("", "device");
-                    serializer.endDocument();
-                    
-                    writeToFile(writer.toString());
-
-            } catch (IllegalArgumentException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
-                Log.e("file", "outputstream: " + e.getMessage());
-            } catch (IllegalStateException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                    Log.e("file", "outputstream: " + e.getMessage());
-            } catch (IOException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                    Log.e("file", "outputstream: " + e.getMessage());
-            }
-
-            
+
+        XmlSerializer serializer = Xml.newSerializer();
+        StringWriter writer = new StringWriter();
+        try {
+            serializer.setOutput(writer);
+            serializer.startTag("", "device");
+            serializer.startTag("", "param");
+            serializer.attribute("", "value", "" + android.os.Build.VERSION.SDK_INT);
+            serializer.attribute("", "name", "sdk_version");
+            serializer.endTag("", "param");
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "value", android.os.Build.DEVICE);
+            serializer.attribute("", "name", "device");
+            serializer.endTag("", "param");
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "value", android.os.Build.MANUFACTURER);
+            serializer.attribute("", "name", "manufacturer");
+            serializer.endTag("", "param");
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "value", android.os.Build.MODEL);
+            serializer.attribute("", "name", "model");
+            serializer.endTag("", "param");
+
+            // TODO get resolution ...
+
+            serializer.endTag("", "device");
+            serializer.endDocument();
+
+            writeToFile(writer.toString());
+
+        }
+        catch (IllegalArgumentException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
+        catch (IllegalStateException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
+        catch (IOException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
+
     }
 
@@ -219,79 +262,97 @@
      */
     public void addComponent(View view, int parentHash, String activityName) {
-            XmlSerializer serializer = Xml.newSerializer();
-            StringWriter writer = new StringWriter();
-            
-            try {
-                    serializer.setOutput(writer);
-                    serializer.startTag("", "component");
-                    // TODO find a way in that the hash code is unique over time and
-                    // target
-                    /*
-                     * (non-Javadoc) view.getId() seems to be unique over time and
-                     * targets but there is a problem. In some cases there is no ID
-                     * (value: -1).
-                     */
-                    serializer.attribute("", "hash", "" + view.hashCode());
-                    
-
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "name", "id");
-                    serializer.attribute("", "value", "" + view.getId());
-                    serializer.endTag("", "param");
-
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "name", "path");
-                    serializer.attribute("", "value", activityName + "/"
-                                    + getViewPath(view) + view.getClass().getSimpleName());
-                    serializer.endTag("", "param");
-
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "name", "class");
-                    serializer.attribute("", "value", view.getClass().getName());
-                    serializer.endTag("", "param");
-
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "name", "parent");
-                    // Problem in using view.getParent().hashCode():
-                    // http://developer.android.com/reference/android/view/View.html#getParent()
-                    // tells: "... parent is a ViewParent and not necessarily a View."
-                    // ViewParent does not have a method hashCode(). Solution is done
-                    // add parentHash as parameter to method addComponent() and
-                    // Androidmonitor-> addLogListenerToView.
-                    serializer.attribute("", "value", "" + parentHash);
-                    serializer.endTag("", "param");
-
-                    // TODO add title e.g. android:text="Button"
-
-                    serializer.startTag("", "ancestors");
-                    
-                    Class<? extends Object> classobject = view.getClass();
-                    
-                    while((classobject != null)){
-                            serializer.startTag("", "ancestor");
-                            serializer.attribute("", "name", classobject.getName());
-                            serializer.endTag("", "ancestor");
-                            classobject = classobject.getSuperclass();
-                    }
-                    serializer.endTag("", "ancestors");
-
-                    serializer.endTag("", "component");
-                    serializer.endDocument();
-
-                    writeToFile(writer.toString());
-
-            } catch (IllegalArgumentException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                    Log.e("file", "outputstream: " + e.getMessage());
-            } catch (IllegalStateException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                    Log.e("file", "outputstream: " + e.getMessage());
-            } catch (IOException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                    Log.e("file", "outputstream: " + e.getMessage());
+        XmlSerializer serializer = Xml.newSerializer();
+        StringWriter writer = new StringWriter();
+
+        try {
+            serializer.setOutput(writer);
+            serializer.startTag("", "component");
+            /*
+             * (non-Javadoc) TODO find a way in that the hash code is unique over time and target
+             * 
+             * view.getId() seems to be unique over time and targets but there is a problem. In some
+             * cases there is no ID (value: -1).
+             * 
+             * view.getId() is not unique in every case. E.g. in the application timerdroid the id
+             * of the list elements changes when calling home button.
+             */
+            serializer.attribute("", "hash", "" + view.hashCode());
+            currentLoggedComponents.add(view.hashCode());
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "name", "id");
+            serializer.attribute("", "value", "" + view.getId());
+            serializer.endTag("", "param");
+
+            if (view instanceof TextView) {
+                serializer.startTag("", "param");
+                serializer.attribute("", "name", "title");
+                TextView textView = (TextView) view;
+                serializer.attribute("", "value", "" + textView.getText());
+                serializer.endTag("", "param");
             }
+            //TODO in case of an image add file name
+            if (view instanceof ImageView) {
+                serializer.startTag("", "param");
+                serializer.attribute("", "name", "title");
+               
+                
+                serializer.attribute("", "value", "image:" );
+                serializer.endTag("", "param");
+            }
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "name", "path");
+            serializer.attribute("", "value", activityName + "/" + getViewPath(view) +
+                view.getClass().getSimpleName());
+            serializer.endTag("", "param");
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "name", "class");
+            serializer.attribute("", "value", view.getClass().getName());
+            serializer.endTag("", "param");
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "name", "parent");
+            /*
+             * (non-Javadoc) Problem in using view.getParent().hashCode():
+             * http://developer.android.com/reference/android/view/View.html#getParent() tells:
+             * "... parent is a ViewParent and not necessarily a View." ViewParent does not have a
+             * method hashCode(). Solution is done add parentHash as parameter to method
+             * addComponent() and Androidmonitor-> addLogListenerToView.
+             */
+            serializer.attribute("", "value", "" + parentHash);
+            serializer.endTag("", "param");
+
+            serializer.startTag("", "ancestors");
+
+            Class<? extends Object> classobject = view.getClass();
+
+            while ((classobject != null)) {
+                serializer.startTag("", "ancestor");
+                serializer.attribute("", "name", classobject.getName());
+                serializer.endTag("", "ancestor");
+                classobject = classobject.getSuperclass();
+            }
+            serializer.endTag("", "ancestors");
+
+            serializer.endTag("", "component");
+            serializer.endDocument();
+
+            writeToFile(writer.toString());
+
+        }
+        catch (IllegalArgumentException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
+        catch (IllegalStateException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
+        catch (IOException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
 
     }
@@ -303,54 +364,54 @@
      * 
      * @param hash
-     *                      hash value of the calling view of the listener
+     *            hash value of the calling view of the listener
      * @param type
-     *                      the type of listener e.g. textView ...
+     *            the type of listener e.g. textView ...
      * @param message
-     *                      message typed in
-     */
-    public void addEvent(int hash, String type, String message){
-            XmlSerializer serializer = Xml.newSerializer();
-            StringWriter writer = new StringWriter();
-
-            try {
-                    serializer.setOutput(writer);
-
-                    serializer.startTag("", "event");
-                    serializer.attribute("", "id", type);
-
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "value", "" + hash);
-                    serializer.attribute("", "name", "source");
-                    serializer.endTag("", "param");
-                    
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "value", message);
-                    serializer.attribute("", "name", "message");
-                    serializer.endTag("", "param");
-
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "value", "" + System.currentTimeMillis());
-                    serializer.attribute("", "name", "timestamp");
-                    serializer.endTag("", "param");
-
-                    serializer.endTag("", "event");
-                    serializer.endDocument();
-
-                    writeToFile(writer.toString());
-            } catch (IllegalArgumentException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                    Log.e("file", "outputstream: " + e.getMessage());
-            } catch (IllegalStateException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                    Log.e("file", "outputstream: " + e.getMessage());
-            } catch (IOException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                    Log.e("file", "outputstream: " + e.getMessage());
-            }
-    }
-    
+     *            message typed in
+     */
+    public void addEvent(int hash, String type, String message) {
+        XmlSerializer serializer = Xml.newSerializer();
+        StringWriter writer = new StringWriter();
+
+        try {
+            serializer.setOutput(writer);
+
+            serializer.startTag("", "event");
+            serializer.attribute("", "id", type);
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "value", "" + hash);
+            serializer.attribute("", "name", "source");
+            serializer.endTag("", "param");
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "value", message);
+            serializer.attribute("", "name", "message");
+            serializer.endTag("", "param");
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "value", "" + System.currentTimeMillis());
+            serializer.attribute("", "name", "timestamp");
+            serializer.endTag("", "param");
+
+            serializer.endTag("", "event");
+            serializer.endDocument();
+
+            writeToFile(writer.toString());
+        }
+        catch (IllegalArgumentException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
+        catch (IllegalStateException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
+        catch (IOException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
+    }
+
     /**
      * <p>
@@ -365,59 +426,134 @@
     public void addEvent(View view, String type) {
 
-            String x = "" + view.getX();
-            String y = "" + view.getY();
-
-            XmlSerializer serializer = Xml.newSerializer();
-            StringWriter writer = new StringWriter();
-
-            try {
-                    serializer.setOutput(writer);
-
-                    serializer.startTag("", "event");
-                    serializer.attribute("", "id", type);
-
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "value", x);
-                    serializer.attribute("", "name", "X");
-                    serializer.endTag("", "param");
-
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "value", y);
-                    serializer.attribute("", "name", "Y");
-                    serializer.endTag("", "param");
-
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "value", "" + view.hashCode());
-                    serializer.attribute("", "name", "source");
-                    serializer.endTag("", "param");
-
-                    serializer.startTag("", "param");
-                    serializer.attribute("", "value", "" + System.currentTimeMillis());
-                    serializer.attribute("", "name", "timestamp");
-                    serializer.endTag("", "param");
-
-                    serializer.endTag("", "event");
-                    serializer.endDocument();
-
-                    writeToFile(writer.toString());
-            } catch (IllegalArgumentException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                    Log.e("file", "outputstream: " + e.getMessage());
-            } catch (IllegalStateException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                    Log.e("file", "outputstream: " + e.getMessage());
-            } catch (IOException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                    Log.e("file", "outputstream: " + e.getMessage());
+        String x = "" + view.getX();
+        String y = "" + view.getY();
+
+        XmlSerializer serializer = Xml.newSerializer();
+        StringWriter writer = new StringWriter();
+
+        try {
+            serializer.setOutput(writer);
+
+            serializer.startTag("", "event");
+            serializer.attribute("", "id", type);
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "value", x);
+            serializer.attribute("", "name", "X");
+            serializer.endTag("", "param");
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "value", y);
+            serializer.attribute("", "name", "Y");
+            serializer.endTag("", "param");
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "value", "" + view.hashCode());
+            serializer.attribute("", "name", "source");
+            serializer.endTag("", "param");
+
+            serializer.startTag("", "param");
+            serializer.attribute("", "value", "" + System.currentTimeMillis());
+            serializer.attribute("", "name", "timestamp");
+            serializer.endTag("", "param");
+
+            serializer.endTag("", "event");
+            serializer.endDocument();
+
+            writeToFile(writer.toString());
+        }
+        catch (IllegalArgumentException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
+        catch (IllegalStateException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
+        catch (IOException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
+    }
+
+    /**
+     * 
+     * <p>
+     * Creates a new file to store information.
+     * </p>
+     * 
+     * @param activity
+     *            Calling application.
+     */
+    private void createFile(Activity activity) {
+
+        AndroidMonitorLogFile.name =
+            "androidLogFile_" + AndroidMonitorLogFile.appName + System.currentTimeMillis() + ".log";
+        try {
+            AndroidMonitorLogFile.file =
+                new File(activity.getFilesDir(), AndroidMonitorLogFile.name);
+            if (AndroidMonitorLogFile.file.exists() && !AndroidMonitorLogFile.file.isDirectory()) {
+                createFile(activity, 0);
             }
-    }
-
-    /**
-     * <p>
-     * Writes given information to the file. e.g. previous produced XML
-     * statements.
+            else {
+                writeHeaderToFile(activity);
+            }
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            Log.e("AndroidMonitorLogFile.file", "file: " + e.getMessage());
+        }
+    }
+
+    /**
+     * 
+     * <p>
+     * Creates a new file to store information. Counts up if file exists.
+     * </p>
+     * 
+     * @param activity
+     *            Calling application.
+     * @param count
+     *            File number.
+     */
+    private void createFile(Activity activity, int count) {
+        AndroidMonitorLogFile.name =
+            "androidLogFile_" + count + "_" + AndroidMonitorLogFile.appName +
+                System.currentTimeMillis() + ".log";
+        try {
+            AndroidMonitorLogFile.file =
+                new File(activity.getFilesDir(), AndroidMonitorLogFile.name);
+            if (AndroidMonitorLogFile.file.exists() && !AndroidMonitorLogFile.file.isDirectory()) {
+                count++;
+                createFile(activity, count);
+            }
+            else {
+                writeHeaderToFile(activity);
+            }
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            Log.e("AndroidMonitorLogFile.file", "file: " + e.getMessage());
+        }
+    }
+
+    /**
+     * 
+     * <p>
+     * Writes XML head, device and application information to file.
+     * </p>
+     * 
+     * @param activity
+     *            Calling application.
+     */
+    private void writeHeaderToFile(Activity activity) {
+        writeToFile("<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><sessions>");
+        setDeviceInformation();
+        setAppInformation(activity);
+    }
+
+    /**
+     * <p>
+     * Writes given information to the file. e.g. previous produced XML statements.
      * </p>
      * 
@@ -427,16 +563,18 @@
     private void writeToFile(String data) {
 
-            FileOutputStream outputStream;
-            try {
-                    outputStream = new FileOutputStream(file, true);
-                    outputStream.write(data.getBytes());
-                    outputStream.close();
-            } catch (FileNotFoundException e) {
-                    e.printStackTrace();
-                    Log.e("file", "outputstream: " + e.getMessage());
-            } catch (IOException e) {
-                    e.printStackTrace();
-                    Log.e("file", "outputstream: " + e.getMessage());
-            }
+        FileOutputStream outputStream;
+        try {
+            outputStream = new FileOutputStream(AndroidMonitorLogFile.file, true);
+            outputStream.write(data.getBytes());
+            outputStream.close();
+        }
+        catch (FileNotFoundException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
+        catch (IOException e) {
+            e.printStackTrace();
+            Log.e("file", "outputstream: " + e.getMessage());
+        }
 
     }
@@ -451,5 +589,5 @@
      */
     private String getViewPath(View view) {
-            return getViewPath(view, null);
+        return getViewPath(view, null);
     }
 
@@ -464,16 +602,18 @@
      */
     private String getViewPath(View view, String path) {
-            if (path == null) {
-                    path = "";
-            } else {
-                    path = view.getClass().getSimpleName() + "/" + path;
-            }
-            if (view.getParent() != null && (view.getParent() instanceof ViewGroup)) {
-                    return getViewPath((View) view.getParent(), path);
-            } else {
-                    return path;
-            }
-    }
-    
+        if (path == null) {
+            path = "";
+        }
+        else {
+            path = view.getClass().getSimpleName() + "/" + path;
+        }
+        if (view.getParent() != null && (view.getParent() instanceof ViewGroup)) {
+            return getViewPath((View) view.getParent(), path);
+        }
+        else {
+            return path;
+        }
+    }
+
     /**
      * 
@@ -481,13 +621,12 @@
      * Check whether a component is still written to log file.
      * </p>
-     *
+     * 
      * @param hashCode
-     *          hash code of the view
+     *            hash code of the view
      * @return
      */
-    public Boolean isComponentLogged(Integer hashCode){
-        return currentLoggedComponents.contains(hashCode);
-    }
-    
-    
+    public static Boolean isComponentLogged(Integer hashCode) {
+        return AndroidMonitorLogFile.currentLoggedComponents.contains(hashCode);
+    }
+
 }
