Advertisement
Guest User

Untitled

a guest
Dec 26th, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. public class Change_Password extends Activity {
  2.  
  3.  
  4. public SharedPreferences prefs;
  5. private String prefName = "MyPref";
  6. private static final String TEXT_VALUE_KEY = "nothing";
  7. String passtemp="";
  8.  
  9.  
  10.  
  11.  
  12.  
  13. @Override
  14. protected void onCreate(Bundle savedInstanceState) {
  15.  
  16. super.onCreate(savedInstanceState);
  17. setContentView(R.layout.change_password);
  18.  
  19.  
  20. Button btnCancel=(Button)findViewById(R.id.btnCancel);
  21. btnCancel.setOnClickListener(new OnClickListener() {
  22.  
  23. public void onClick(View arg0) {
  24.  
  25. finish();
  26. }
  27. });
  28.  
  29. final EditText txtNewPassword=(EditText)findViewById(R.id.txtNewPassword);
  30. final EditText txtCurrentPassword=(EditText)findViewById(R.id.txtCurrentPassword);
  31. final EditText txtConfirmPassword=(EditText)findViewById(R.id.txtConfirmNewPassword);
  32. Button btnSave=(Button)findViewById(R.id.btnSave);
  33. btnSave.setOnClickListener(new OnClickListener() {
  34.  
  35. public void onClick(View arg0) {
  36. prefs = getSharedPreferences(prefName, MODE_PRIVATE);
  37. passtemp = prefs.getString(TEXT_VALUE_KEY, "nothing");
  38. if(txtConfirmPassword.getText().toString().equalsIgnoreCase("") |
  39. txtCurrentPassword.getText().toString().equalsIgnoreCase("") |
  40. txtCurrentPassword.getText().toString().equalsIgnoreCase(""))
  41. {
  42. Toast.makeText(getBaseContext(),"Please Complete the Information", Toast.LENGTH_SHORT).show();
  43. }
  44. else
  45. if(!txtNewPassword.getText().toString().equalsIgnoreCase(txtConfirmPassword.getText().toString()))
  46. {
  47. Toast.makeText(getBaseContext(),
  48. "These Passwords Don't Match !", Toast.LENGTH_SHORT).show();
  49. }
  50. else
  51. if(!passtemp.equalsIgnoreCase(txtCurrentPassword.getText().toString()))
  52. {
  53. Toast.makeText(getBaseContext(),
  54. "Current Password is Incorrect!", Toast.LENGTH_SHORT).show();
  55. }
  56. else
  57. {
  58. ///------- //---save the values in the EditText view to preferences---
  59. prefs = getPreferences(MODE_PRIVATE);
  60. SharedPreferences.Editor editor = prefs.edit();
  61. editor.putString(TEXT_VALUE_KEY, txtNewPassword.getText().toString());
  62. //---saves the values---
  63. editor.commit();
  64. ///--------
  65. //Password=txtNewPassword.getText().toString();
  66. Toast.makeText(getBaseContext(),
  67. Password, Toast.LENGTH_SHORT).show();
  68. }
  69.  
  70. }
  71. });
  72.  
  73. }
  74.  
  75. @Override
  76. public void onAttachedToWindow() {
  77. this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
  78. super.onAttachedToWindow();
  79.  
  80.  
  81. }
  82.  
  83. @Override
  84. public boolean onKeyDown(int keyCode, KeyEvent event) {
  85. if(keyCode == KeyEvent.KEYCODE_HOME)
  86.  
  87. BackToMainIntent();
  88.  
  89. else if(keyCode==KeyEvent.KEYCODE_BACK)
  90. {
  91. BackToMainIntent();
  92. }
  93. return false;
  94. }
  95.  
  96.  
  97.  
  98. public void BackToMainIntent()
  99. {
  100. Intent intent = new Intent(this, Main.class);
  101. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  102. startActivity(intent);
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement