public void checkuser() { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); String email = Plus.AccountApi.getAccountName(mGoogleApiClient); String personName = currentPerson.getDisplayName(); try { long timeInMillis = System.currentTimeMillis(); final String PhoneModel = android.os.Build.MODEL; JSONObject userData = new JSONObject(); userData.put("phoneModel", PhoneModel); userData.put("username", personName); userData.put("email", email); Log.d(TAG, userData.toString()); String response = CommonFunctions.sendRequestToServer(userData.toString(), "login"); if (response.contains("SUCCESS") || response.contains("ALREADY")) { Log.d("testing", response); String userid = response.subSequence(13, 17).toString(); // Log.d("testing", userid); saveSharedString("USERID", userid); // initialsetup(); // SensingController.unregisterAlarm(getApplicationContext()); } } catch (Exception e) { Log.e(TAG, e.toString()); } }
public boolean requestlogout() { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); String email = Plus.AccountApi.getAccountName(mGoogleApiClient); String response = null; try { JSONObject userData = new JSONObject(); userData.put("email", email); Log.d(TAG, userData.toString()); response = CommonFunctions.sendRequestToServer(userData.toString(), "logout"); if (response.contains("DONE")) { return true; } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; }
@Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.btn_launch_app: launchApp(); break; case R.id.btn_sign_in: // Force File Upload if (internetConnectionCheck()) { Log.i(TAG, "sign in clicked to upload files"); signInWithGplus(); txtDatasent.setText("Signed In!"); String FILE_UPL = "fileupload"; Editor editor = sharedPref.edit(); editor.putBoolean(FILE_UPL, true); editor.commit(); try { timeBuf.close(); } catch (IOException ie) { ie.printStackTrace(); } CommonFunctions.CompressandSend(); SensingController.unregisterAlarm(context.getApplicationContext()); Log.i("File Upload Option:", "Zip Folder created!"); final Runnable runnable = new Runnable() { public void run() { // TODO Auto-generated method stub { try { Thread.sleep(10000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.d(TAG, "Going to start File upload service"); String FILE_UPL = "fileupload"; Editor editor = sharedPref.edit(); editor.putBoolean(FILE_UPL, true); editor.commit(); CommonFunctions.CompressandSend(); startFileUpload(); } } }; new Thread(runnable).start(); txtDatasent.setText("Uploading Data"); txtDatasent.setAnimation(getBlinkAnimation()); boolean valUpload = sharedPref.getBoolean("FILE_UPL", false); // txtDatasent.setText("Data Uploaded!"); String text = txtDatasent.getText().toString(); if (!valUpload && text.startsWith("Data Sent:")) { if (requestlogout()) { signOutFromGplus(); Toast.makeText(getApplicationContext(), "Logged out!", Toast.LENGTH_LONG).show(); } // launchRingDialog(); } } else { Toast.makeText(getApplicationContext(), "Network Not available...", Toast.LENGTH_LONG) .show(); } break; case R.id.btn_sign_out: // Signout button clicked exitApp(); launchRingDialog(); break; /*case R.id.btn_check_updates: // Checking for updates try{ Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse("https://play.google.com/store/apps/details?id=sense.routinenew")); startActivity(viewIntent); } catch(Exception e) { Toast.makeText(getApplicationContext(),"Unable to Connect Try Again...", Toast.LENGTH_LONG).show(); e.printStackTrace(); } break; */ case R.id.btn_note_on_time: long timeInMillis = System.currentTimeMillis(); String newMsg = "Entry Time:" + CommonUtils.unixTimestampToString(timeInMillis); Toast.makeText(getApplicationContext(), "Entry time to be recorded!", Toast.LENGTH_LONG) .show(); saveDataInFile(newMsg); break; case R.id.btn_note_off_time: long etimeInMillis = System.currentTimeMillis(); String enewMsg = "Exit Time:" + CommonUtils.unixTimestampToString(etimeInMillis); Toast.makeText(getApplicationContext(), "Exit time to be recorded!", Toast.LENGTH_LONG) .show(); saveDataInFile(enewMsg); break; case R.id.btn_entry_station: Intent entryIntent = new Intent(this, StationsList.class); entryIntent.putExtra("Travel Type", false); startActivity(entryIntent); break; case R.id.btn_exit_station: Intent exitIntent = new Intent(this, StationsList.class); exitIntent.putExtra("Travel Type", true); startActivity(exitIntent); break; } }