@Override public void onBackPressed() { if (!dontToastMeTwice) { if (running) w.make( "Cannot exit via BACK while recording data; use HOME instead.", Waffle.LENGTH_LONG, Waffle.IMAGE_WARN); else w.make("Press back again to exit.", Waffle.LENGTH_SHORT); new NoToastTwiceTask().execute(); } else if (exitAppViaBack && !running) { setupDone = false; super.onBackPressed(); } }
private void manageUploadQueue() { if (!uq.emptyQueue()) { Intent i = new Intent().setClass(mContext, QueueLayout.class); i.putExtra(QueueLayout.PARENT_NAME, uq.getParentName()); startActivityForResult(i, QUEUE_UPLOAD_REQUESTED); } else { w.make("There are no data to upload!", Waffle.LENGTH_LONG, Waffle.IMAGE_X); } }
/** Handles application behavior on back press. */ @Override public void onBackPressed() { // Allows there user to leave via back only when not recording. if (running) { w.make( "Cannot exit via BACK while recording data; use HOME instead.", Waffle.LENGTH_LONG, Waffle.IMAGE_WARN); } else { super.onBackPressed(); } }
@Override public void onClick(View v) { if (v == okay) { if (usernameInput.getText().length() != 0 && passwordInput.getText().length() != 0) { boolean success = rapi.login(usernameInput.getText().toString(), passwordInput.getText().toString()); if (success) { w.make("Login Successful!", Waffle.LENGTH_SHORT, Waffle.IMAGE_CHECK); final SharedPreferences mPrefs = new ObscuredSharedPreferences( Main.mContext, Main.mContext.getSharedPreferences("USER_INFO", Context.MODE_PRIVATE)); mPrefs.edit().putString("username", usernameInput.getText().toString()).commit(); mPrefs.edit().putString("password", passwordInput.getText().toString()).commit(); setResult(LoginActivity.RESULT_OK); LoginActivity.this.finish(); } else { w.make( "Login failed. Check internet connectivity and your username/password.", Waffle.LENGTH_LONG, Waffle.IMAGE_X); } } else w.make("Please enter a username and password.", Waffle.LENGTH_SHORT, Waffle.IMAGE_X); } else if (v == cancel) { setResult(LoginActivity.RESULT_CANCELED); LoginActivity.this.finish(); } }
/** Tries to login then launches the upload queue uploading activity. */ private void manageUploadQueue() { // Attempt to login with saved credentials, otherwise try default // credentials new AttemptLoginTask().execute(); // If the queue isn't empty, launch the activity. Otherwise tell the // user the queue is empty. if (!uq.emptyQueue()) { Intent i = new Intent().setClass(mContext, QueueLayout.class); i.putExtra(QueueLayout.PARENT_NAME, uq.getParentName()); startActivityForResult(i, QUEUE_UPLOAD_REQUESTED); } else { w.make("No Data to Upload.", Waffle.LENGTH_LONG, Waffle.IMAGE_WARN); } }
@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"); } }
/** Catches the returns from other activities back to DataWalk.java. */ protected void onActivityResult(int requestCode, int resultCode, Intent data) { // If the user hits yes, launch a web page to view their data on iSENSE, // else do nothing. if (requestCode == DIALOG_VIEW_DATA) { if (resultCode == RESULT_OK) { projectURL += dataSetID + "?embed=true"; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(projectURL)); startActivity(i); } // If a new project has been selected, check to see if it is // actually valid. } else if (requestCode == PROJECT_REQUESTED) { if (api.hasConnectivity()) { if (resultCode == RESULT_OK) { setProjectIdtoUsersChoice(); if (api.hasConnectivity()) { new GetProjectTask().execute(); } } else if (resultCode == RESULT_CANCELED) { // This is called when they hit cancel. // In this situation, we want the UI to display the last project number the user entered. projectID = DEFAULT_PROJECT; // Set the project ID in preferences back to its default value SharedPreferences prefs = getSharedPreferences(Setup.PREFS_ID, Context.MODE_PRIVATE); SharedPreferences.Editor mEdit = prefs.edit(); mEdit.putString(Setup.PROJECT_ID, DEFAULT_PROJECT); mEdit.commit(); } } else { // There is no Internet so menu is disabled, thus the user will never reach this point. } // If the user hit yes, bring them to GPS settings. } else if (requestCode == DIALOG_NO_GPS) { if (resultCode == RESULT_OK) { startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } // The user left the app while it was running, so press the main // button to stop recording. } else if (requestCode == DIALOG_FORCE_STOP) { if (resultCode == RESULT_OK) { startStop.performLongClick(); } // If the user uploaded data, offer to show the data on iSENSE } else if (requestCode == QUEUE_UPLOAD_REQUESTED) { uq.buildQueueFromFile(); if (resultCode == RESULT_OK) { if (data != null) { dataSetID = data.getIntExtra(QueueLayout.LAST_UPLOADED_DATA_SET_ID, -1); if (dataSetID != -1) { Intent i = new Intent(DataWalk.this, ViewData.class); startActivityForResult(i, DIALOG_VIEW_DATA); } } } // Return of EnterNameActivity } else if (requestCode == NAME_REQUESTED) { // the user entered a valid name so update the main UI if (resultCode == RESULT_OK) { nameTxtBox.setText("Name: " + firstName + " " + lastInitial); } else { // Calls the enter name activity if a name has not yet been // entered. if (firstName.equals("") || lastInitial.equals("")) { startActivityForResult(new Intent(mContext, EnterNameActivity.class), NAME_REQUESTED); w.make( "You must enter your name before starting to record data.", Waffle.LENGTH_SHORT, Waffle.IMAGE_X); } } // Resets iSENSE and recording variables to their defaults. } else if (requestCode == RESET_REQUESTED) { if (resultCode == RESULT_OK) { // Set variables to default mInterval = DEFAULT_INTERVAL; loginName = DEFAULT_USERNAME; loginPass = DEFAULT_PASSWORD; firstName = ""; lastInitial = ""; projectID = DEFAULT_PROJECT; // Set the project ID in preferences back to its default value SharedPreferences prefs = getSharedPreferences(Setup.PREFS_ID, Context.MODE_PRIVATE); SharedPreferences.Editor mEdit = prefs.edit(); mEdit.putString(Setup.PROJECT_ID, DEFAULT_PROJECT); mEdit.commit(); // Set the default username and password in preferences back to // their default value final SharedPreferences mPrefs = new ObscuredSharedPreferences( DataWalk.mContext, DataWalk.mContext.getSharedPreferences(USER_PREFS_KEY, Context.MODE_PRIVATE)); SharedPreferences.Editor mEditor = mPrefs.edit(); mEditor.putString(DataWalk.USERNAME_KEY, loginName); mEditor.putString(DataWalk.PASSWORD_KEY, loginPass); mEditor.commit(); // Tell the user his settings are back to default w.make("Settings have been reset to default.", Waffle.LENGTH_SHORT); // Launch the EnterNameActivity startActivityForResult(new Intent(mContext, EnterNameActivity.class), NAME_REQUESTED); } // Catches return from LoginIsense.java } else if (requestCode == LOGIN_ISENSE_REQUESTED) { if (resultCode == RESULT_OK) { // Get the new login information from preferences final SharedPreferences mPrefs = new ObscuredSharedPreferences( DataWalk.mContext, DataWalk.mContext.getSharedPreferences(USER_PREFS_KEY, Context.MODE_PRIVATE)); loginName = mPrefs.getString(DataWalk.USERNAME_KEY, DEFAULT_USERNAME); loginPass = mPrefs.getString(DataWalk.PASSWORD_KEY, DEFAULT_USERNAME); // Set the UI to the new login name loggedInAs.setText(getResources().getString(R.string.logged_in_as) + " " + loginName); } else { // A lo // Set the UI to say you aren't logged in // TODO What if you are still logged in as default? // loggedInAs.setText(getResources().getString(R.string.logged_in_as + ""+ loginName)); loggedInAs.setText(getResources().getString(R.string.logged_in_as) + " " + loginName); } } } // End of onActivityResult