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.

ResultsActivity.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.app.AlertDialog;
  7. import android.app.ProgressDialog;
  8. import android.content.DialogInterface;
  9. import android.content.Intent;
  10. import android.os.Bundle;
  11. import android.os.Handler;
  12. import android.os.RemoteException;
  13. import android.util.Log;
  14. import android.view.View;
  15. import android.view.View.OnClickListener;
  16. import android.widget.ArrayAdapter;
  17. import android.widget.AutoCompleteTextView;
  18. import android.widget.Button;
  19. import android.widget.TextView;
  20. import com.flurry.android.FlurryAgent;
  21. import java.util.TimerTask;
  22. import uk.co.md87.android.sensorlogger.R;
  23. /**
  24. *
  25. * @author chris
  26. */
  27. public class ResultsActivity extends BoundActivity {
  28. private final Handler handler = new Handler();
  29. private AutoCompleteTextView input;
  30. private ProgressDialog dialog;
  31. private final TimerTask task = new TimerTask() {
  32. @Override
  33. public void run() {
  34. checkStage();
  35. }
  36. };
  37. private final OnClickListener yesListener = new OnClickListener() {
  38. public void onClick(View arg0) {
  39. FlurryAgent.onEvent("results_yes_click");
  40. findViewById(R.id.resultsno).setEnabled(false);
  41. findViewById(R.id.resultsyes).setEnabled(false);
  42. dialog = ProgressDialog.show(ResultsActivity.this, "Please wait",
  43. "Submitting...", true);
  44. try {
  45. service.submit();
  46. } catch (RemoteException ex) {
  47. Log.e(getClass().getName(), "Unable to submit correction", ex);
  48. }
  49. }
  50. };
  51. private final DialogInterface.OnClickListener correctionListener
  52. = new DialogInterface.OnClickListener() {
  53. public void onClick(DialogInterface arg0, int arg1) {
  54. FlurryAgent.onEvent("results_correction_submitted");
  55. dialog = ProgressDialog.show(ResultsActivity.this, "Please wait",
  56. "Submitting...", true);
  57. try {
  58. service.submitWithCorrection(input.getText().toString());
  59. } catch (RemoteException ex) {
  60. Log.e(getClass().getName(), "Unable to submit correction", ex);
  61. }
  62. }
  63. };
  64. private final OnClickListener noListener = new OnClickListener() {
  65. public void onClick(View arg0) {
  66. FlurryAgent.onEvent("results_no_click");
  67. findViewById(R.id.resultsno).setEnabled(false);
  68. findViewById(R.id.resultsyes).setEnabled(false);
  69. input = new AutoCompleteTextView(ResultsActivity.this);
  70. input.setAdapter(new ArrayAdapter<String>(ResultsActivity.this,
  71. android.R.layout.simple_dropdown_item_1line, new String[] {
  72. "Walking", "Walking (up stairs)", "Walking (down stairs)",
  73. "On a bus", "In a car", "Standing", "Sitting", "Dancing"
  74. }));
  75. input.setSingleLine();
  76. input.setThreshold(0);
  77. AlertDialog.Builder adb = new AlertDialog.Builder(ResultsActivity.this);
  78. adb.setView(input).setCancelable(false);
  79. adb.setTitle(R.string.correct_title);
  80. adb.setMessage(R.string.correct_activity);
  81. adb.setPositiveButton(R.string.correct_button, correctionListener);
  82. adb.create().show();
  83. }
  84. };
  85. @Override
  86. protected void serviceBound() {
  87. super.serviceBound();
  88. try {
  89. String name = "activity_" + service.getClassification().substring(11)
  90. .replace("/", "_").toLowerCase();
  91. int res = getResources().getIdentifier(name, "string", "uk.co.md87.android.sensorlogger");
  92. ((TextView) findViewById(R.id.resultsresult)).setText(res);
  93. } catch (RemoteException ex) {
  94. Log.e(getClass().getName(), "Unable to get classification", ex);
  95. }
  96. handler.postDelayed(task, 500);
  97. }
  98. /** {@inheritDoc} */
  99. @Override
  100. public void onCreate(final Bundle icicle) {
  101. super.onCreate(icicle);
  102. setContentView(R.layout.results);
  103. ((Button) findViewById(R.id.resultsyes)).setOnClickListener(yesListener);
  104. ((Button) findViewById(R.id.resultsno)).setOnClickListener(noListener);
  105. }
  106. @Override
  107. protected void onDestroy() {
  108. super.onDestroy();
  109. }
  110. void checkStage() {
  111. try {
  112. if (service.getState() == 7) {
  113. FlurryAgent.onEvent("results_to_thanks");
  114. service.setState(8);
  115. startActivity(new Intent(this, ThanksActivity.class));
  116. finish();
  117. } else {
  118. handler.postDelayed(task, 500);
  119. }
  120. } catch (RemoteException ex) {
  121. Log.e(getClass().getName(), "Unable to get state", ex);
  122. }
  123. }
  124. /** {@inheritDoc} */
  125. @Override
  126. protected void onStart() {
  127. super.onStart();
  128. FlurryAgent.onStartSession(this, "TFBJJPQUQX3S1Q6IUHA6");
  129. }
  130. /** {@inheritDoc} */
  131. @Override
  132. protected void onStop() {
  133. super.onStop();
  134. FlurryAgent.onEndSession(this);
  135. }
  136. }