package com.example.reader.types;

public class BasicTimer {

}

@@ -32,33 +32,1811 @@
 s;%0A%0A
-public class BasicTimer %7B%0A
+import java.io.BufferedWriter;%0Aimport java.io.File;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.OutputStreamWriter;%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.concurrent.TimeUnit;%0A%0Aimport android.os.Environment;%0A%0Apublic class BasicTimer %7B%0A%0A%09long start, end, elapsedTime;%0A%09boolean isStarted;%0A%09%0A%09%0A%09String root, filename;%0A%09File timerDir, file;%0A%09public BasicTimer(String filename)%7B%0A%09%09%0A%09%09isStarted = false;%0A%09%09%0A%09%09//long start = System.nanoTime(); %0A%09%09// method()%0A%09%09//long end = System.nanoTime(); %0A%09%09//long elapsedTime = end - start;%0A%09%09//TimeUnit.SECONDS.convert(elapsedTime, TimeUnit.NANOSECONDS);%0A%09%09%0A%09%09root = Environment.getExternalStorageDirectory().toString();%0A%09%09timerDir = new File(root + %22/ilearn_timer%22);%0A%09%09timerDir.mkdirs();%0A%09%0A%09%09this.filename = filename;%0A%09%7D%0A%09%0A%09public void start()%7B%0A%09%09if(isStarted)%7B%0A%09%09%09stop();%0A%09%09%7D%0A%09%09%0A%09%09isStarted = true;%0A%09%09start = System.nanoTime();%0A%09%7D%0A%09%0A%09public void stop()%7B%0A%09%09end = System.nanoTime();%0A%09%09isStarted = false;%0A%09%09%0A%09%09elapsedTime = end - start;%0A%09%09%0A%09%09ArrayList%3CLong%3E out = new ArrayList%3CLong%3E(Arrays.asList(start, end, elapsedTime));%0A%09%09saveFile(out, true);%0A%09%7D%0A%09%0A%09public void saveFile(ArrayList%3CLong%3E out, boolean isAppending)%7B%0A%09%09file = new File(timerDir, filename);%0A%09%09%0A%09%09if(!isAppending)%0A%09%09%09if(file.exists())%0A%09%09%09%09file.delete();%0A%09%09%0A%09%09BufferedWriter writer =  null;%0A%09%09try %7B%0A%09%09%09writer= new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, isAppending), %22UTF-8%22));%0A%09%09%09for(int i=0; i%3Cout.size(); i++)%7B%0A%09%09%09%09Long value = out.get(i);%0A%0A%09%09%09%09if(value%253==0)%0A%09%09%09%09%09writer.write(TimeUnit.SECONDS.convert(value, TimeUnit.NANOSECONDS)+%22%5Cn%22);%0A%09%09%09%09else%0A%09%09%09%09%09writer.write(value+%22%5Cn%22);%0A%09%09%09%7D%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D finally %7B%0A%09%09%09try %7B%0A%09%09%09%09writer.close();%0A%09%09%09%7D catch (IOException e2) %7B%7D%0A%09%09%7D%0A%09%7D
 %0A%7D%0A

update timer