TracingSyncActivity.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package de.tudarmstadt.informatik.hostage.sync.tracing;
  2. import de.tudarmstadt.informatik.hostage.R;
  3. import de.tudarmstadt.informatik.hostage.sync.android.SyncUtils;
  4. import android.app.Activity;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.os.Handler;
  8. import android.widget.TextView;
  9. /**
  10. * Starts a synchronization service and shows the progress of the synchronization.
  11. * @author Lars Pandikow
  12. */
  13. public class TracingSyncActivity extends Activity implements TracingSyncResultReciever.Receiver{
  14. TextView mInfoText;
  15. @Override
  16. public void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_nfc);
  19. mInfoText = (TextView) findViewById(R.id.nfc_text_view);
  20. mInfoText.setText("Synchronizing...");
  21. TracingSyncResultReciever mReceiver = new TracingSyncResultReciever(new Handler());
  22. mReceiver.setReceiver(this);
  23. Intent intent = new Intent(this, TracingSyncService.class);
  24. intent.setAction(TracingSyncService.ACTION_START_SYNC);
  25. intent.putExtra(TracingSyncService.EXTRA_RECEIVER, mReceiver);
  26. startService(intent);
  27. }
  28. @Override
  29. public void onReceiveResult(int resultCode, Bundle resultData) {
  30. switch (resultCode) {
  31. case TracingSyncService.SYNC_COMPLETE:
  32. mInfoText.setText("Records were synchronized successfully!");
  33. setResult(SyncUtils.SYNC_SUCCESSFUL, null);
  34. break;
  35. case TracingSyncService.RECORD_UPLOADED:
  36. mInfoText.setText("Uploading Records... (" + resultData.getInt(TracingSyncService.UPLOAD_PROGRESS) + "/"+ resultData.getInt(TracingSyncService.UPLOAD_SIZE) + ")");
  37. break;
  38. case TracingSyncService.RECORD_DOWNLOAD:
  39. mInfoText.setText("Downloading Records...");
  40. break;
  41. case TracingSyncService.SYNC_DOWNLOAD_ERROR:
  42. mInfoText.setText("There was an error while trying to download records to TraCiNG");
  43. break;
  44. case TracingSyncService.SYNC_UPLOAD_ERROR:
  45. mInfoText.setText("There was an error while trying to upload records to TraCiNG");
  46. break;
  47. case TracingSyncService.SYNC_ERROR:
  48. mInfoText.setText("There was an error while trying to synchronize with TraCiNG.");
  49. break;
  50. }
  51. }
  52. }