Advertisement
Guest User

forme

a guest
Mar 16th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. package com.example.app0811.mytodo;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.content.SharedPreferences;
  6. import android.os.Bundle;
  7. import android.widget.EditText;
  8. import android.widget.Toast;
  9.  
  10. public class MainActivity extends Activity
  11. {
  12. SharedPreferences myPref;
  13. SharedPreferences.Editor editor;
  14.  
  15. private EditText userName;
  16. private EditText passWord;
  17.  
  18. @Override
  19. protected void onCreate(Bundle savedInstanceState)
  20. {
  21. super.onCreate(savedInstanceState);
  22. setContentView(R.layout.activity_main);
  23. setPoints();
  24. }
  25.  
  26. private void setPoints()
  27. {
  28. myPref = getApplicationContext().getSharedPreferences(Register.myPrefs,MODE_PRIVATE);
  29. editor =myPref.edit();
  30.  
  31. userName = (EditText)findViewById(R.id.inUser);
  32. passWord = (EditText)findViewById(R.id.inPass);
  33. }
  34.  
  35. private void chkUser()
  36. {
  37. String userInput = userName.getText().toString();
  38. String passInput = passWord.getText().toString();
  39.  
  40. if(userInput.trim().equals("") || passInput.trim().equals(""))
  41. {
  42. Toast.makeText(this,"Error, please fill all the fields",Toast.LENGTH_SHORT).show();
  43. }
  44. else if(!myPref.contains(userInput) || !passInput.equals(myPref.getString(userInput,passInput)))
  45. {
  46. Toast.makeText(this,"Error, wrong username or password!",Toast.LENGTH_SHORT).show();
  47. }
  48. else
  49. {
  50. Intent logMe = new Intent(this,Logged.class);
  51. this.startActivity(logMe);
  52. }
  53. }
  54.  
  55. }
  56. =========================================================================================================================
  57. =============================register
  58.  
  59. package com.example.app0811.mytodo;
  60.  
  61. import android.app.Activity;
  62. import android.content.Intent;
  63. import android.content.SharedPreferences;
  64. import android.os.Bundle;
  65. import android.view.View;
  66. import android.widget.EditText;
  67. import android.widget.Toast;
  68.  
  69. /**
  70. * Created by app0811 on 16/03/2016.
  71. */
  72. public class Register extends Activity
  73. {
  74. public final static String myPrefs = "myPref";//shared prefrences xml file name
  75.  
  76. SharedPreferences myPref;
  77. SharedPreferences.Editor editor;
  78.  
  79. private EditText userInput;
  80. private EditText passInput;
  81. private EditText rePassInput;
  82.  
  83. @Override
  84. protected void onCreate(Bundle savedInstanceState)
  85. {
  86. super.onCreate(savedInstanceState);
  87. setContentView(R.layout.activity_register);
  88. setPoints();
  89. }
  90.  
  91. private void setPoints()
  92. {
  93. myPref = getApplicationContext().getSharedPreferences(myPrefs,MODE_PRIVATE);
  94. editor =myPref.edit();
  95.  
  96. userInput = (EditText)findViewById(R.id.setUser);
  97. passInput = (EditText)findViewById(R.id.setPass);
  98. rePassInput = (EditText)findViewById(R.id.confPass);
  99. }
  100.  
  101. private void chkReg()
  102. {
  103. String userName = userInput.getText().toString();
  104. String passWord = passInput.getText().toString();
  105. String checkPass = rePassInput.getText().toString();
  106.  
  107. if(userName.trim().length()<=0 || passWord.trim().length()<=0 || checkPass.trim().length()<=0)
  108. {
  109. Toast.makeText(this, "Error, please fill all the fields", Toast.LENGTH_SHORT).show();
  110. }
  111. else if(!checkPass.equals(passWord))
  112. {
  113. Toast.makeText(this, "Error, Password do not match!", Toast.LENGTH_SHORT).show();
  114. }
  115. else if(userName.equals(myPref.contains(userName)))
  116. {
  117. Toast.makeText(this, "Error, this user allready exists", Toast.LENGTH_SHORT).show();
  118. }
  119. else
  120. {
  121. editor.putString(userName, passWord);
  122. editor.commit();
  123.  
  124. Intent mainInt = new Intent(this,MainActivity.class);
  125. this.startActivity(mainInt);
  126. finish();
  127. }
  128. }
  129.  
  130. public void btnReg(View v)
  131. {
  132. chkReg();
  133. }
  134.  
  135. public void btnCncle(View v)
  136. {
  137. Intent cnclInten = new Intent (this,MainActivity.class);
  138. this.startActivity(cnclInten);
  139. finish();
  140. }
  141. }
  142. ==============================================================================================
  143. ====================================logged
  144.  
  145. package com.example.app0811.mytodo;
  146.  
  147. import android.app.Activity;
  148. import android.os.Bundle;
  149.  
  150. /**
  151. * Created by app0811 on 16/03/2016.
  152. */
  153. public class Logged extends Activity
  154. {
  155. @Override
  156. protected void onCreate(Bundle savedInstanceState)
  157. {
  158. super.onCreate(savedInstanceState);
  159. setContentView(R.layout.activity_logged);
  160. }
  161.  
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement