Back to project page GroupSmart-Android.
The source code is released under:
Copyright (C) <2014> <Derek Argueta - Hunter Kehoe> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), ...
If you think the Android project GroupSmart-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.dargueta.groupsmart; /*from w w w . j ava 2s . c o m*/ import android.app.Activity; import android.app.ProgressDialog; import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnKeyListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.google.analytics.tracking.android.EasyTracker; /** * * @author Hunter Kehoe * * Provides the activity where the user can change his or her password. * */ public class ChangePassword extends Activity { ProgressDialog pDialog; EditText etCurrentPassword, etNewPassword, etNewPasswordCheck; Button btnChangePassword; String newPassword = ""; String updatePasswordURL = ""; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.change_password); etCurrentPassword = (EditText) findViewById(R.id.etCurrentPassword); etNewPassword = (EditText) findViewById(R.id.etNewPassword); etNewPasswordCheck = (EditText) findViewById(R.id.etNewPasswordCheck); btnChangePassword = (Button) findViewById(R.id.btnChangePassword); etNewPasswordCheck.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) { btnChangePassword.performClick(); return true; } return false; } }); btnChangePassword.setOnClickListener(new OnClickListener() { public void onClick(View v) { String currentPassword = etCurrentPassword.getText().toString(); newPassword = etNewPassword.getText().toString(); String newPasswordCheck = etNewPasswordCheck.getText().toString(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); String correctPassword = prefs.getString(Constants.PASSWORD_KEY, Constants.EMPTY_STRING); if(!correctPassword.equals("")) { if (!currentPassword.equals(correctPassword)) { Toast.makeText(getApplicationContext(), "Incorrect current password", Toast.LENGTH_SHORT).show(); return; } else { if (newPassword.length() == 0) { Toast.makeText(getApplicationContext(), R.string.enterPassword, Toast.LENGTH_SHORT).show(); return; } if (!newPassword.equals(newPasswordCheck)) { Toast.makeText(getApplicationContext(), R.string.passwordMismatch, Toast.LENGTH_SHORT).show(); return; } else { String email = prefs.getString(Constants.EMAIL_KEY, Constants.EMPTY_STRING); if (email.equals("")) { Toast.makeText(getApplicationContext(), R.string.somethingWrong, Toast.LENGTH_SHORT).show(); finish(); } updatePasswordURL = Constants.BASE_URL + "mode=uup&e=" + email + "&p=" + correctPassword + "&np=" + newPassword; new UpdatePassword().execute(); } } } } }); } /** * * @author Hunter Kehoe * * Asynchronously send the new password to the remote database. * */ private class UpdatePassword extends AsyncTask<Void, Void, Void> { boolean successful = false; protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(ChangePassword.this); pDialog.setMessage(getString(R.string.pleaseWait)); pDialog.setCancelable(false); pDialog.show(); } protected Void doInBackground(Void... arg0) { ServiceHandler sh = new ServiceHandler(); String jsonStr = sh.makeServiceCall(updatePasswordURL, ServiceHandler.GET); if (jsonStr.contains("Successfully")) { successful = true; } return null; } protected void onPostExecute(Void result) { super.onPostExecute(result); if(pDialog.isShowing()) { pDialog.dismiss(); } if (successful) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = prefs.edit(); editor.putString(Constants.PASSWORD_KEY, newPassword); editor.apply(); Toast.makeText(getApplicationContext(), R.string.goodUpdate, Toast.LENGTH_SHORT).show(); finish(); } else { Toast.makeText(getApplicationContext(), R.string.somethingWrong, Toast.LENGTH_SHORT).show(); finish(); } } } // Google Analytics public void onStart() { super.onStart(); EasyTracker.getInstance(this).activityStart(this); } public void onStop() { super.onStop(); EasyTracker.getInstance(this).activityStop(this); } }