@Override protected void onPostExecute(Void voids) { dia.setMessage("Done"); if (dia != null && dia.isShowing()) dia.dismiss(); len = 0; len2 = 0; if (uploadSuccessful) { w.make("Data upload successful.", Waffle.LENGTH_SHORT, Waffle.IMAGE_CHECK); startActivity(new Intent(CarRampPhysicsV2.this, ViewData.class)); } else { w.make("Data saved.", Waffle.LENGTH_LONG, Waffle.IMAGE_CHECK); } OrientationManager.enableRotation(CarRampPhysicsV2.this); }
@Override public void onActivityResult(int reqCode, int resultCode, Intent data) { super.onActivityResult(reqCode, resultCode, data); dontPromptMeTwice = false; if (reqCode == EXPERIMENT_REQUESTED) { if (resultCode == RESULT_OK) { SharedPreferences prefs = getSharedPreferences("PROJID", 0); experimentNumber = prefs.getString("project_id", null); if (experimentNumber == null) { if (useDev) { experimentNumber = DEFAULT_PROJ_DEV; } else { experimentNumber = DEFAULT_PROJ_PROD; } } dfm = new DataFieldManager(Integer.parseInt(experimentNumber), api, mContext, f); dfm.getOrder(); } } else if (reqCode == QUEUE_UPLOAD_REQUESTED) { uq.buildQueueFromFile(); } else if (reqCode == UPLOAD_OK_REQUESTED) { if (resultCode == RESULT_OK) { if (len == 0 || len2 == 0) { w.make("There are no data to upload!", Waffle.LENGTH_LONG, Waffle.IMAGE_X); OrientationManager.enableRotation(CarRampPhysicsV2.this); } else new UploadTask().execute(); } else { w.make("Data set discarded", Waffle.LENGTH_LONG, Waffle.IMAGE_WARN); OrientationManager.enableRotation(CarRampPhysicsV2.this); } } else if (reqCode == LOGIN_STATUS_REQUESTED) { if (resultCode == RESULT_OK) { if (loggedInAs == null) loggedInAs = (TextView) findViewById(R.id.loginStatus); loggedInAs.setText( getResources().getString(R.string.logged_in_as) + " " + data.getStringExtra("username") + ", Name: " + firstName + " " + lastInitial); dfm = new DataFieldManager(Integer.parseInt(experimentNumber), api, mContext, f); dfm.getOrder(); } } else if (reqCode == RECORDING_LENGTH_REQUESTED) { if (resultCode == RESULT_OK) { length = Integer.parseInt(data.getStringExtra("input")); countdown = length; SharedPreferences prefs = getSharedPreferences("RECORD_LENGTH", 0); SharedPreferences.Editor editor = prefs.edit(); editor.putInt("length", length); // Below is a math fail // if (length <= 25) { // INTERVAL = 50; // } else { // INTERVAL = 2 * length; // } editor.putInt("Interval", INTERVAL); editor.commit(); } } else if (reqCode == resultGotName) { if (resultCode == RESULT_OK) { final SharedPreferences mPrefs = new ObscuredSharedPreferences( CarRampPhysicsV2.mContext, CarRampPhysicsV2.mContext.getSharedPreferences("USER_INFO", Context.MODE_PRIVATE)); if (!inApp) inApp = true; loggedInAs.setText( getResources().getString(R.string.logged_in_as) + " " + mPrefs.getString("username", "") + ", Name: " + firstName + " " + lastInitial); } else { if (!inApp) finish(); } } else if (reqCode == RESET_REQUESTED) { if (resultCode == RESULT_OK) { SharedPreferences prefs = getSharedPreferences("RECORD_LENGTH", 0); countdown = length = prefs.getInt("length", 10); final SharedPreferences mPrefs = new ObscuredSharedPreferences( CarRampPhysicsV2.mContext, CarRampPhysicsV2.mContext.getSharedPreferences("USER_INFO", Context.MODE_PRIVATE)); SharedPreferences.Editor mOSPEdit = mPrefs.edit(); mOSPEdit.putString("username", DEFAULT_USER).commit(); mOSPEdit.putString("password", DEFAULT_USER).commit(); new OnCreateLoginTask().execute(); loggedInAs.setText( getResources().getString(R.string.logged_in_as) + " " + mPrefs.getString("username", "") + ", Name: " + firstName + " " + lastInitial); SharedPreferences eprefs = getSharedPreferences("PROJID", 0); SharedPreferences.Editor editor = eprefs.edit(); if (useDev) { experimentNumber = DEFAULT_PROJ_DEV; } else { experimentNumber = DEFAULT_PROJ_PROD; } editor.putString("project_id", experimentNumber); editor.commit(); INTERVAL = 50; SharedPreferences rprefs = getSharedPreferences("RECORD_SETTINGS", 0); SharedPreferences.Editor mEdit = rprefs.edit(); mEdit.putBoolean("X", false); mEdit.putBoolean("Y", true); mEdit.putBoolean("Z", false); mEdit.putBoolean("Magnitude", false); mEdit.commit(); x = z = mag = false; y = true; values.setText("Y: " + accel[1]); Log.d("fantastag", "resetti"); } } else if (reqCode == SAVE_MODE_REQUESTED) { if (resultCode == RESULT_OK) { saveMode = true; CarRampPhysicsV2.experimentNumber = "-1"; dfm = new DataFieldManager(Integer.parseInt(experimentNumber), api, mContext, f); dfm.getOrder(); } else { if (!api.hasConnectivity()) { startActivityForResult(new Intent(mContext, SaveModeDialog.class), SAVE_MODE_REQUESTED); } else { saveMode = false; } } } }
@Override public void onResume() { super.onResume(); inPausedState = false; SharedPreferences prefs = getSharedPreferences(RecordSettings.RECORD_SETTINGS, 0); x = prefs.getBoolean("X", false); y = prefs.getBoolean("Y", true); z = prefs.getBoolean("Z", false); mag = prefs.getBoolean("Magnitude", false); String dataLabel = ""; if (x) { dataLabel += "X: "; } if (y) { if (x) { dataLabel += " , Y: "; } else dataLabel += "Y: "; } if (z) { if (x || y) { dataLabel += " , Z: "; } else dataLabel += "Z: "; } if (mag) { if (x || y || z) { dataLabel += " , Magnitude: "; } else dataLabel += "Magnitude: "; } values.setText(dataLabel); if (usedHomeButton && running) { setupDone = false; timeHasElapsed = false; useMenu = true; countdown = length; running = false; startStop.setText("Hold to Start"); startStop.setEnabled(true); startStop.setBackgroundResource(R.drawable.button_rsense); timeTimer.cancel(); choiceViaMenu = false; startStop.setEnabled(true); dataSet = new JSONArray(); OrientationManager.enableRotation(CarRampPhysicsV2.this); w.make("Data recording halted.", Waffle.LENGTH_SHORT, Waffle.IMAGE_X); } if (uq != null) uq.buildQueueFromFile(); if (api.hasConnectivity() && saveMode) { SharedPreferences prefs2 = getSharedPreferences("PROJID", 0); experimentNumber = prefs2.getString("project_id", null); if (experimentNumber == null) { if (useDev) { experimentNumber = DEFAULT_PROJ_DEV; } else { experimentNumber = DEFAULT_PROJ_PROD; } } dfm = new DataFieldManager(Integer.parseInt(experimentNumber), api, mContext, f); dfm.getOrder(); saveMode = false; System.out.println("Switching off save mode"); } }