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 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (c) 2009-2010 Chris Smith
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package uk.co.md87.android.sensorlogger.activities;
  23. import android.content.Intent;
  24. import android.os.Bundle;
  25. import android.os.Handler;
  26. import android.os.RemoteException;
  27. import android.util.Log;
  28. import android.widget.TextView;
  29. import com.flurry.android.FlurryAgent;
  30. import java.util.TimerTask;
  31. import uk.co.md87.android.sensorlogger.R;
  32. /**
  33. *
  34. * @author chris
  35. */
  36. public class RecordingActivity extends BoundActivity {
  37. private final Handler handler = new Handler();
  38. int state = 3;
  39. int phase = 3;
  40. private final TimerTask task = new TimerTask() {
  41. @Override
  42. public void run() {
  43. checkSamples();
  44. }
  45. };
  46. /** {@inheritDoc} */
  47. @Override
  48. public void onCreate(final Bundle icicle) {
  49. super.onCreate(icicle);
  50. setContentView(R.layout.recording);
  51. handler.removeCallbacks(task);
  52. handler.postDelayed(task, 500);
  53. }
  54. @Override
  55. protected void onDestroy() {
  56. super.onDestroy();
  57. handler.removeCallbacks(task);
  58. }
  59. public void checkSamples() {
  60. try {
  61. phase = (phase + 1) % 4;
  62. String text = "?";
  63. switch (phase) {
  64. case 0: text = ". "; break;
  65. case 1: text = " . "; break;
  66. case 2: text = " ."; break;
  67. case 3: text = " . "; break;
  68. }
  69. ((TextView) findViewById(R.id.recordingcount)).setText(text);
  70. final int serviceState = service.getState();
  71. if (serviceState > state) {
  72. state = serviceState;
  73. if (state == 4) {
  74. setTitle("Sensor Logger > Analysing");
  75. ((TextView) findViewById(R.id.recordingheader)).setTag(R.string.analysingheader);
  76. }
  77. }
  78. if (serviceState > 4) {
  79. FlurryAgent.onEvent("countdown_to_results");
  80. startActivity(new Intent(this, ResultsActivity.class));
  81. finish();
  82. } else {
  83. handler.postDelayed(task, 500);
  84. }
  85. } catch (RemoteException ex) {
  86. Log.e(getClass().getName(), "Error getting countdown", ex);
  87. }
  88. }
  89. /** {@inheritDoc} */
  90. @Override
  91. protected void onStart() {
  92. super.onStart();
  93. FlurryAgent.onStartSession(this, "TFBJJPQUQX3S1Q6IUHA6");
  94. }
  95. /** {@inheritDoc} */
  96. @Override
  97. protected void onStop() {
  98. super.onStop();
  99. FlurryAgent.onEndSession(this);
  100. }
  101. }