Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
188 additions
and
24 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 |
---|---|---|
@@ -1,2 +1,10 @@ | ||
code/android/Android_GeigerCounter_basico/bin/ | ||
code/android/Android_GeigerCounter_basico/gen/ | ||
## generic files to ignore | ||
*~ | ||
*.lock | ||
*.DS_Store | ||
*.swp | ||
*.out | ||
*.class | ||
|
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
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
101 changes: 101 additions & 0 deletions
101
code/android/Android_GeigerCounter_basico/src/com/dofideas/geiger2/DataRecorder.java
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,101 @@ | ||
package com.dofideas.geiger2; | ||
|
||
import java.io.DataOutputStream; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import android.text.format.DateUtils; | ||
import android.content.Context; | ||
import java.text.SimpleDateFormat; | ||
|
||
import android.os.Environment; | ||
import android.text.format.DateFormat; | ||
import android.util.Log; | ||
|
||
public class DataRecorder { | ||
|
||
private Context contextRef; | ||
private DataOutputStream fos; | ||
DataRecorder(Context andContext){ | ||
this.contextRef=andContext; | ||
} | ||
boolean checkForCard(){ | ||
//checking for media CArd | ||
boolean mExternalStorageAvailable = false; | ||
boolean mExternalStorageWriteable = false; | ||
|
||
String state = Environment.getExternalStorageState(); | ||
if (Environment.MEDIA_MOUNTED.equals(state)) { | ||
// We can read and write the media | ||
mExternalStorageAvailable = mExternalStorageWriteable = true; | ||
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { | ||
// We can only read the media | ||
mExternalStorageAvailable = true; | ||
mExternalStorageWriteable = false; | ||
} else { | ||
// Something else is wrong. It may be one of many other states, but all we need | ||
// to know is we can neither read nor write | ||
mExternalStorageAvailable = mExternalStorageWriteable = false; | ||
} | ||
Log.d("qq","mExternalStorageWriteable: "+mExternalStorageWriteable); | ||
return mExternalStorageWriteable; | ||
|
||
} | ||
|
||
boolean open(){ | ||
if(checkForCard()){ | ||
if(openFile()){ | ||
Log.d("qq","open: "); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
boolean openFile(){ | ||
File folder1= contextRef.getExternalFilesDir(null); | ||
try { | ||
Log.d("qq","open file " + folder1.getCanonicalPath()); | ||
} catch (IOException e1) { | ||
// TODO Auto-generated catch block | ||
e1.printStackTrace(); | ||
} | ||
|
||
Calendar cal = Calendar.getInstance(); | ||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm"); | ||
String dateStr = sdf.format(cal.getTime()); | ||
|
||
File file = new File(folder1, dateStr+".txt"); | ||
|
||
try { | ||
fos = new DataOutputStream( new FileOutputStream(file) ); | ||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
boolean closeFile(){ | ||
Log.d("qq","closing file"); | ||
try { | ||
fos.close(); | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
boolean addData (int cpm, int seq) { | ||
try { | ||
fos.writeUTF(seq + " " + cpm + "\n" ); | ||
} catch (IOException e) { | ||
Log.d("qq","error in addDAta: "); | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
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