Changeset 5 for trunk/TagTracker/src
- Timestamp:
- 05/04/12 17:14:40 (13 years ago)
- Location:
- trunk/TagTracker/src/nl/deadpixel/tagtracker/beta
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/TagTracker/src/nl/deadpixel/tagtracker/beta/FileHandler.java
r3 r5 43 43 } 44 44 } 45 public void writeUID(String uid, String time , String note)45 public void writeUID(String uid, String time) 46 46 { 47 47 try { … … 52 52 " <tag uid=\"" + uid + "\">\r\n" + 53 53 " <time>" + time + "</time>\r\n" + 54 " <note>" + note + "</note>\r\n" +55 54 " </tag>\r\n"; 56 Log.i("TagTracker", "Writing tag " + uid);57 55 writer.append(tag); 58 Log.i("TagTracker", "Wrote tag " + uid);59 56 writer.flush(); 60 57 writer.close(); … … 65 62 } 66 63 64 public void writeNote(String note) 65 { 66 try { 67 File root = new File(Environment.getExternalStorageDirectory(), "TagTracker"); 68 File xmlfile = new File(root, "tags.log"); 69 FileWriter writer = new FileWriter(xmlfile,true); 70 String tag = 71 " <note>\r\n" + 72 " " + note + 73 " <note>\r\n"; 74 writer.append(tag); 75 writer.flush(); 76 writer.close(); 77 } catch (IOException e) { 78 Log.e("TagTracker", "" + e.getMessage()); 79 } 80 81 } 67 82 public void writeStart(String starttime) 68 83 { … … 76 91 "<tags>\r\n" + 77 92 " <start time=\""+starttime+"\" />\r\n"; 78 Log.i("TagTracker", "Writing start...");93 //Log.i("TagTracker", "Writing start..."); 79 94 writer.write(start); 80 Log.i("TagTracker", "Wrote start...");95 //Log.i("TagTracker", "Wrote start..."); 81 96 writer.flush(); 82 97 writer.close(); … … 97 112 "<end time=\""+endtime+"\" />\r\n" + 98 113 "</tags>"; 99 Log.i("TagTracker", "Writing end...");114 //Log.i("TagTracker", "Writing end..."); 100 115 writer.append(end); 101 Log.i("TagTracker", "Wrote end...");116 //Log.i("TagTracker", "Wrote end..."); 102 117 writer.flush(); 103 118 writer.close(); -
trunk/TagTracker/src/nl/deadpixel/tagtracker/beta/TagTrackerActivity.java
r4 r5 2 2 3 3 4 import java.io.File; 4 5 import java.io.IOException; 5 6 import java.text.DateFormat; … … 8 9 9 10 import android.app.Activity; 11 import android.app.AlertDialog; 10 12 import android.app.PendingIntent; 11 13 import android.content.Context; 14 import android.content.DialogInterface; 12 15 import android.content.Intent; 13 16 import android.content.IntentFilter; 14 17 import android.content.IntentFilter.MalformedMimeTypeException; 18 import android.content.SharedPreferences; 15 19 import android.media.AudioManager; 16 20 import android.media.MediaPlayer; … … 20 24 import android.nfc.tech.NfcA; 21 25 import android.os.Bundle; 26 import android.os.Environment; 22 27 import android.os.Handler; 23 28 import android.os.PowerManager; … … 26 31 import android.view.Menu; 27 32 import android.view.MenuInflater; 33 import android.view.MenuItem; 28 34 import android.view.View; 29 35 import android.widget.Button; 36 import android.widget.EditText; 30 37 import android.widget.RelativeLayout; 31 import android.widget.TextView;32 38 import android.widget.ToggleButton; 33 39 … … 42 48 private RelativeLayout mScreen; 43 49 44 @Override 50 @SuppressWarnings("unchecked") 51 @Override 45 52 public void onCreate(Bundle savedState) { 46 53 super.onCreate(savedState); … … 51 58 button.setOnClickListener(new View.OnClickListener() { 52 59 public void onClick(View v) { 53 60 zenden(); 54 61 } 55 62 }); 63 SharedPreferences p = getPreferences(MODE_PRIVATE); 64 writeAllow = p.getBoolean("writeAllow", false); 65 cardID = (ArrayList<String>) ObjectSerializer.deserialize(p.getString("cardID", ObjectSerializer.serialize(new ArrayList<String>()))); 66 ToggleButton tg = (ToggleButton) findViewById(R.id.status); 67 tg.setChecked(writeAllow); 56 68 mScreen = (RelativeLayout) findViewById(R.id.Screen); 57 69 mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,""); … … 116 128 if(!cardID.contains(uid)) 117 129 { 118 Log.i("Foreground dispatch", "Discovered tag with ID: " + uid);130 //Log.i("Foreground dispatch", "Discovered tag with ID: " + uid); 119 131 //mText.append("\r\n["+time+"] Discovered tag " + ++mCount + " with ID: " + uid); 120 fh.writeUID(uid, time , "");132 fh.writeUID(uid, time); 121 133 cardID.add(uid); 122 134 setBackground(0xFF00FF00, 200); … … 170 182 mScreen.setBackgroundColor(android.R.color.white); 171 183 } 172 }, time); 173 174 184 }, time); 175 185 } 176 186 @Override 177 187 public void onPause() { 178 188 super.onPause(); 189 SharedPreferences preferences = getPreferences(MODE_PRIVATE); 190 SharedPreferences.Editor editor = preferences.edit(); 191 editor.putBoolean("writeAllow", writeAllow); // value to store 192 editor.putString("cardID", ObjectSerializer.serialize(cardID)); 193 editor.commit(); 179 194 if (mAdapter != null) mAdapter.disableForegroundDispatch(this); 180 195 } 196 181 197 @Override 182 198 public boolean onCreateOptionsMenu(Menu menu) { … … 185 201 return true; 186 202 } 203 @Override 204 public boolean onOptionsItemSelected(MenuItem item) { 205 // Handle item selection 206 switch (item.getItemId()) { 207 case R.id.add_uid: 208 addUID(); 209 return true; 210 case R.id.add_note: 211 addNote(); 212 return true; 213 case R.id.stopsend: 214 stopSend(); 215 return true; 216 default: 217 return super.onOptionsItemSelected(item); 218 } 219 } 220 221 public void addUID() 222 { 223 if(writeAllow) 224 { 225 AlertDialog.Builder alert = new AlertDialog.Builder(this); 226 alert.setTitle("UID Toevoegen"); 227 228 // Set an EditText view to get user input 229 final EditText input = new EditText(this); 230 alert.setView(input); 231 232 alert.setPositiveButton("Toevoegen", new DialogInterface.OnClickListener() { 233 public void onClick(DialogInterface dialog, int whichButton) { 234 String value = input.getText().toString(); 235 fh.writeUID(value, DateFormat.getDateTimeInstance().format(new Date())); 236 return; 237 } 238 }); 239 240 alert.setNegativeButton("Annuleren", new DialogInterface.OnClickListener() { 241 242 public void onClick(DialogInterface dialog, int which) { 243 // TODO Auto-generated method stub 244 return; 245 } 246 }); 247 alert.show(); 248 } 249 else 250 { 251 AlertDialog.Builder alert = new AlertDialog.Builder(this, 4); 252 alert.setTitle("Oeps!"); 253 alert.setMessage("Druk op start om een UID toe te voegen"); 254 alert.setNeutralButton("Ok", new DialogInterface.OnClickListener() { 255 256 public void onClick(DialogInterface dialog, int which) { 257 // TODO Auto-generated method stub 258 return; 259 } 260 }); 261 alert.show(); 262 } 263 } 264 265 public void addNote() 266 { 267 if(writeAllow) 268 { 269 AlertDialog.Builder alert = new AlertDialog.Builder(this); 270 alert.setTitle("Notitie Toevoegen"); 271 272 // Set an EditText view to get user input 273 final EditText input = new EditText(this); 274 alert.setView(input); 275 276 alert.setPositiveButton("Toevoegen", new DialogInterface.OnClickListener() { 277 public void onClick(DialogInterface dialog, int whichButton) { 278 String value = input.getText().toString(); 279 fh.writeNote(value); 280 return; 281 } 282 }); 283 284 alert.setNegativeButton("Annuleren", new DialogInterface.OnClickListener() { 285 286 public void onClick(DialogInterface dialog, int which) { 287 // TODO Auto-generated method stub 288 return; 289 } 290 }); 291 alert.show(); 292 } 293 else 294 { 295 AlertDialog.Builder alert = new AlertDialog.Builder(this, 4); 296 alert.setTitle("Oeps!"); 297 alert.setMessage("Druk op start om een Notitie toe te voegen"); 298 alert.setNeutralButton("Ok", new DialogInterface.OnClickListener() { 299 300 public void onClick(DialogInterface dialog, int which) { 301 // TODO Auto-generated method stub 302 return; 303 } 304 }); 305 alert.show(); 306 } 307 } 308 public void stopSend() 309 { 310 writeAllow = false; 311 ToggleButton tg = (ToggleButton) findViewById(R.id.status); 312 tg.setChecked(writeAllow); 313 AlertDialog.Builder alert = new AlertDialog.Builder(this); 314 alert.setTitle("Email Zenden"); 315 316 // Set an EditText view to get user input 317 final EditText input = new EditText(this); 318 input.setHint("Email"); 319 input.setInputType(32); 320 alert.setView(input); 321 322 alert.setPositiveButton("Verder", new DialogInterface.OnClickListener() { 323 public void onClick(DialogInterface dialog, int whichButton) { 324 String value = input.getText().toString(); 325 Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 326 emailIntent.setType("text/xml"); 327 emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] 328 {value}); 329 emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, 330 "Tag Track from " + DateFormat.getDateTimeInstance().format(new Date())); 331 emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 332 "XML Attached"); 333 File root = new File(Environment.getExternalStorageDirectory(), "TagTracker"); 334 File xmlfile = new File(root, "tags.log"); 335 emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ xmlfile)); 336 startActivity(Intent.createChooser(emailIntent, "Stuur Email")); 337 return; 338 } 339 }); 340 alert.show(); 341 } 342 public void zenden() 343 { 344 if(!writeAllow) 345 { 346 AlertDialog.Builder alert = new AlertDialog.Builder(this); 347 alert.setTitle("Email Zenden"); 348 349 // Set an EditText view to get user input 350 final EditText input = new EditText(this); 351 input.setHint("Email"); 352 input.setInputType(32); 353 alert.setView(input); 354 355 alert.setPositiveButton("Verder", new DialogInterface.OnClickListener() { 356 public void onClick(DialogInterface dialog, int whichButton) { 357 String value = input.getText().toString(); 358 Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 359 emailIntent.setType("text/xml"); 360 emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] 361 {value}); 362 emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, 363 "Tag Track from " + DateFormat.getDateTimeInstance().format(new Date())); 364 emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 365 "XML Attached"); 366 File root = new File(Environment.getExternalStorageDirectory(), "TagTracker"); 367 File xmlfile = new File(root, "tags.log"); 368 emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ xmlfile)); 369 startActivity(Intent.createChooser(emailIntent, "Stuur Email")); 370 return; 371 } 372 }); 373 alert.show(); 374 } 375 else 376 { 377 AlertDialog.Builder alert = new AlertDialog.Builder(this, 4); 378 alert.setTitle("Oeps!"); 379 alert.setMessage("Druk op stop om te verzenden"); 380 alert.setNeutralButton("Ok", new DialogInterface.OnClickListener() { 381 382 public void onClick(DialogInterface dialog, int which) { 383 // TODO Auto-generated method stub 384 return; 385 } 386 }); 387 alert.show(); 388 } 389 } 187 390 }
Note: See TracChangeset
for help on using the changeset viewer.