Context-detection API for Android developed as a university project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RecordingActivity.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package uk.co.md87.android.sensorlogger.activities;
  6. import android.content.Intent;
  7. import android.os.Bundle;
  8. import android.os.Handler;
  9. import android.os.RemoteException;
  10. import android.util.Log;
  11. import android.widget.TextView;
  12. import com.flurry.android.FlurryAgent;
  13. import java.util.TimerTask;
  14. import uk.co.md87.android.sensorlogger.R;
  15. /**
  16. *
  17. * @author chris
  18. */
  19. public class RecordingActivity extends BoundActivity {
  20. private final Handler handler = new Handler();
  21. int state = 3;
  22. int phase = 3;
  23. private final TimerTask task = new TimerTask() {
  24. @Override
  25. public void run() {
  26. checkSamples();
  27. }
  28. };
  29. /** {@inheritDoc} */
  30. @Override
  31. public void onCreate(final Bundle icicle) {
  32. super.onCreate(icicle);
  33. setContentView(R.layout.recording);
  34. handler.removeCallbacks(task);
  35. handler.postDelayed(task, 500);
  36. }
  37. @Override
  38. protected void onDestroy() {
  39. super.onDestroy();
  40. handler.removeCallbacks(task);
  41. }
  42. public void checkSamples() {
  43. try {
  44. phase = (phase + 1) % 4;
  45. String text = "?";
  46. switch (phase) {
  47. case 0: text = ". "; break;
  48. case 1: text = " . "; break;
  49. case 2: text = " ."; break;
  50. case 3: text = " . "; break;
  51. }
  52. ((TextView) findViewById(R.id.recordingcount)).setText(text);
  53. final int serviceState = service.getState();
  54. if (serviceState > state) {
  55. state = serviceState;
  56. if (state == 4) {
  57. setTitle("Sensor Logger > Analysing");
  58. ((TextView) findViewById(R.id.recordingheader)).setTag(R.string.analysingheader);
  59. }
  60. }
  61. if (serviceState > 4) {
  62. FlurryAgent.onEvent("countdown_to_results");
  63. startActivity(new Intent(this, ResultsActivity.class));
  64. finish();
  65. } else {
  66. handler.postDelayed(task, 500);
  67. }
  68. } catch (RemoteException ex) {
  69. Log.e(getClass().getName(), "Error getting countdown", ex);
  70. }
  71. }
  72. /** {@inheritDoc} */
  73. @Override
  74. protected void onStart() {
  75. super.onStart();
  76. FlurryAgent.onStartSession(this, "TFBJJPQUQX3S1Q6IUHA6");
  77. }
  78. /** {@inheritDoc} */
  79. @Override
  80. protected void onStop() {
  81. super.onStop();
  82. FlurryAgent.onEndSession(this);
  83. }
  84. }