Advertisement
Guest User

Untitled

a guest
Nov 27th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. package com.example.alannah.overwatch;
  2.  
  3. import android.content.Intent;
  4. import android.database.Cursor;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.Toast;
  12.  
  13. import static android.database.DatabaseUtils.dumpCursorToString;
  14.  
  15. public class MainActivity extends AppCompatActivity {
  16.  
  17. Button buttonL, buttonR;
  18. EditText userUsername;
  19. EditText password;
  20. MyDBManager db;
  21.  
  22.  
  23. @Override
  24. protected void onCreate(Bundle savedInstanceState) {
  25. super.onCreate(savedInstanceState);
  26. setContentView(R.layout.activity_main);
  27.  
  28. buttonR = (Button) findViewById(R.id.buttonR);
  29. buttonL = (Button) findViewById(R.id.buttonL);
  30. userUsername = (EditText) findViewById(R.id.username);
  31. password = (EditText) findViewById(R.id.password);
  32.  
  33. db = new MyDBManager(this).open();
  34.  
  35. buttonR.setOnClickListener(new View.OnClickListener() {
  36. @Override
  37. public void onClick(View v) {
  38. String userName = userUsername.getText().toString();
  39. String passWord = password.getText().toString();
  40. Cursor user = db.getPreviousUsers(userName);
  41. String name = user.getString(user.getColumnIndexOrThrow(MyDBManager.KEY_USERNAME));
  42. String pass = user.getString(user.getColumnIndexOrThrow(MyDBManager.KEY_PASSWORD));
  43. if (name.equals(userName))
  44. {
  45. Toast.makeText(getApplicationContext(), "Somebody else has this username",Toast.LENGTH_SHORT).show();
  46. }
  47. else
  48. {
  49. db.insertUser(name, pass);
  50. Toast.makeText(getApplicationContext(), "Your account has been created",Toast.LENGTH_SHORT).show();
  51. }
  52. }
  53. });
  54.  
  55. buttonL.setOnClickListener(new View.OnClickListener() {
  56. @Override
  57. public void onClick(View v) {
  58. String userName = userUsername.getText().toString();
  59. Toast.makeText(getApplicationContext(), "Your account has been created",Toast.LENGTH_SHORT).show();
  60. String passWord = password.getText().toString();
  61. Log.d("HELLO", userName);
  62. Toast.makeText(getApplicationContext(),userName,Toast.LENGTH_SHORT).show();
  63. Cursor user = db.getPreviousUsers(userName);
  64. if(user == null){
  65. Toast.makeText(getApplicationContext()," null",Toast.LENGTH_SHORT).show();
  66.  
  67. }//end if
  68.  
  69. else{
  70. Toast.makeText(getApplicationContext(),"Not null",Toast.LENGTH_SHORT).show();
  71.  
  72. }
  73. /*String name = user.getString(user.getColumnIndexOrThrow(MyDBManager.KEY_USERNAME));
  74. String pass = user.getString(user.getColumnIndexOrThrow(MyDBManager.KEY_PASSWORD));
  75. if ((name.equals(userName)) && (pass.equals(passWord)) )
  76. {
  77. Intent loginIntent = new Intent(getApplicationContext(), Menu.class);
  78. startActivity(loginIntent);
  79. }
  80. else
  81. {
  82. Toast.makeText(getApplicationContext(), "Wrong Credentials",Toast.LENGTH_SHORT).show();
  83. }
  84. */
  85. }
  86. });
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement