-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed up the battery drain bug and cleaned up some code
- Loading branch information
unknown
authored and
unknown
committed
May 17, 2010
1 parent
ff7fd14
commit 921879c
Showing
2 changed files
with
164 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* $Id$ | ||
*/ | ||
|
||
package com.tokudu.demo; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
import android.os.Environment; | ||
|
||
public class ConnectionLog | ||
{ | ||
private String mPath; | ||
private Writer mWriter; | ||
|
||
private static final SimpleDateFormat TIMESTAMP_FMT = | ||
new SimpleDateFormat("[HH:mm:ss] "); | ||
|
||
public ConnectionLog() | ||
throws IOException | ||
{ | ||
File sdcard = Environment.getExternalStorageDirectory(); | ||
File logDir = new File(sdcard, "tokudu/log/"); | ||
if (!logDir.exists()) { | ||
logDir.mkdirs(); | ||
// do not allow media scan | ||
new File(logDir, ".nomedia").createNewFile(); | ||
} | ||
|
||
open(logDir.getAbsolutePath() + "/push.log"); | ||
} | ||
|
||
public ConnectionLog(String basePath) | ||
throws IOException | ||
{ | ||
open(basePath); | ||
} | ||
|
||
protected void open(String basePath) | ||
throws IOException | ||
{ | ||
File f = new File(basePath + "-" + getTodayString()); | ||
mPath = f.getAbsolutePath(); | ||
mWriter = new BufferedWriter(new FileWriter(mPath), 2048); | ||
|
||
println("Opened log."); | ||
} | ||
|
||
private static String getTodayString() | ||
{ | ||
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd-hhmmss"); | ||
return df.format(new Date()); | ||
} | ||
|
||
public String getPath() | ||
{ | ||
return mPath; | ||
} | ||
|
||
public void println(String message) | ||
throws IOException | ||
{ | ||
mWriter.write(TIMESTAMP_FMT.format(new Date())); | ||
mWriter.write(message); | ||
mWriter.write('\n'); | ||
mWriter.flush(); | ||
} | ||
|
||
public void close() | ||
throws IOException | ||
{ | ||
mWriter.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters