Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.bruna.appvalid1;
- import android.content.Context;
- import android.content.Intent;
- import android.database.SQLException;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.inputmethod.InputMethodManager;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- public class Login extends AppCompatActivity {
- DBAdapter dbAdapter;
- Button login, novousuario;
- Intent intent;
- EditText usuario1, senha1;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- usuario1 = (EditText) findViewById(R.id.usuario1);
- senha1 = (EditText) findViewById(R.id.senha1);
- novousuario = (Button) findViewById(R.id.button_novousuario) ;
- login = (Button) findViewById(R.id.button_login);
- dbAdapter = new DBAdapter(this);
- dbAdapter.openDataBase();
- novousuario.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View arg0) {
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(usuario1.getWindowToken(),0);
- imm.hideSoftInputFromWindow(senha1.getWindowToken(),0);
- try {
- String username = usuario1.getText().toString();
- String password = senha1.getText().toString();
- long i = dbAdapter.register(username, password);
- if (i != -1)
- Toast.makeText(Login.this, "You have successfully registered", Toast.LENGTH_LONG).show();
- }catch(SQLException e){
- Toast.makeText(Login.this, "some problem occurred", Toast.LENGTH_LONG).show();}}});
- login.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View arg0) {
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(usuario1.getWindowToken(),0);
- imm.hideSoftInputFromWindow(senha1.getWindowToken(),0);
- String username = usuario1.getText().toString();
- String password = senha1.getText().toString();
- if(username.length()>0&&password.length()>0){
- try {
- if (dbAdapter.Login(username, password)) {
- Toast.makeText(Login.this, "Successfully Logged In", Toast.LENGTH_LONG).show();
- intent = new Intent(Login.this,MenuInventario.class);
- startActivity(intent);
- } else {
- Toast.makeText(Login.this, "Invalid username or password", Toast.LENGTH_LONG).show();
- }}
- catch(Exception e){
- Toast.makeText(Login.this, e.toString(), Toast.LENGTH_LONG).show();
- }}
- else{
- Toast.makeText(Login.this, "Username or Password is empty", Toast.LENGTH_LONG).show();}}}); }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement