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

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