Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. package com.example.bruna.appvalid1;
  2.  
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.database.SQLException;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.view.inputmethod.InputMethodManager;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.Toast;
  13.  
  14. public class Login extends AppCompatActivity {
  15.  
  16. DBAdapter dbAdapter;
  17. Button login, novousuario;
  18. Intent intent;
  19. EditText usuario1, senha1;
  20.  
  21. @Override
  22. public void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.activity_login);
  25.  
  26. usuario1 = (EditText) findViewById(R.id.usuario1);
  27. senha1 = (EditText) findViewById(R.id.senha1);
  28. novousuario = (Button) findViewById(R.id.button_novousuario) ;
  29. login = (Button) findViewById(R.id.button_login);
  30.  
  31. dbAdapter = new DBAdapter(this);
  32. dbAdapter.openDataBase();
  33.  
  34.  
  35. novousuario.setOnClickListener(new View.OnClickListener() {
  36. @Override
  37. public void onClick(View arg0) {
  38. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
  39. imm.hideSoftInputFromWindow(usuario1.getWindowToken(),0);
  40. imm.hideSoftInputFromWindow(senha1.getWindowToken(),0);
  41. try {
  42. String username = usuario1.getText().toString();
  43. String password = senha1.getText().toString();
  44. long i = dbAdapter.register(username, password);
  45. if (i != -1)
  46. Toast.makeText(Login.this, "You have successfully registered", Toast.LENGTH_LONG).show();
  47. }catch(SQLException e){
  48. Toast.makeText(Login.this, "some problem occurred", Toast.LENGTH_LONG).show();}}});
  49.  
  50.  
  51. login.setOnClickListener(new View.OnClickListener() {
  52. @Override
  53. public void onClick(View arg0) {
  54. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
  55. imm.hideSoftInputFromWindow(usuario1.getWindowToken(),0);
  56. imm.hideSoftInputFromWindow(senha1.getWindowToken(),0);
  57. String username = usuario1.getText().toString();
  58. String password = senha1.getText().toString();
  59. if(username.length()>0&&password.length()>0){
  60. try {
  61. if (dbAdapter.Login(username, password)) {
  62. Toast.makeText(Login.this, "Successfully Logged In", Toast.LENGTH_LONG).show();
  63. intent = new Intent(Login.this,MenuInventario.class);
  64. startActivity(intent);
  65. } else {
  66. Toast.makeText(Login.this, "Invalid username or password", Toast.LENGTH_LONG).show();
  67. }}
  68.  
  69. catch(Exception e){
  70. Toast.makeText(Login.this, e.toString(), Toast.LENGTH_LONG).show();
  71. }}
  72. else{
  73. Toast.makeText(Login.this, "Username or Password is empty", Toast.LENGTH_LONG).show();}}}); }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement