From a519da8f8e00786b247f959c40992e50f84e06b2 Mon Sep 17 00:00:00 2001 From: NIsha Raut <53817683+nisharaut2@users.noreply.github.com> Date: Thu, 24 Oct 2019 13:28:54 +0530 Subject: [PATCH] Registration Page User Registration Page Android --- Registration Page | 145 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 Registration Page diff --git a/Registration Page b/Registration Page new file mode 100644 index 0000000..fda260d --- /dev/null +++ b/Registration Page @@ -0,0 +1,145 @@ +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +public class Login extends ActionBarActivity { + +public static android.content.SharedPreferences SharedPreferences = null; + +private static final String PREFER_NAME = null; + +Button buttonLogin; + +EditText txtUsername, txtPassword; + +// User Session Manager Class +UserSession session; + +@Override +public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.login); + + Button switchButton = (Button)findViewById(R.id.buttonReg); + switchButton.setOnClickListener (new View.OnClickListener() { + + @Override + public void onClick(View v) { + Intent intent=new Intent(Login.this, Reg.class); + startActivity(intent); + + } + }); + + + // User Session Manager + session = new UserSession(getApplicationContext()); + + // get Email, Password input text + txtUsername = (EditText) findViewById(R.id.txtUsername); + txtPassword = (EditText) findViewById(R.id.txtPassword); + + Toast.makeText(getApplicationContext(), + "User Login Status: " + session.isUserLoggedIn(), + Toast.LENGTH_LONG).show(); + + + // User Login button + buttonLogin = (Button) findViewById(R.id.buttonLogin); + + SharedPreferences = getSharedPreferences(PREFER_NAME, Context.MODE_PRIVATE); + + + // Login button click event + buttonLogin.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View arg0) { + + // Get username, password from EditText + String username = txtUsername.getText().toString(); + String password = txtPassword.getText().toString(); + + // Validate if username, password is filled + if(username.trim().length() > 0 && password.trim().length() > 0){ + + if (SharedPreferences.contains("name")) + { + String uName = (SharedPreferences).getString("name", ""); + + } + + if (SharedPreferences.contains("email")) + { + String uEmail = (SharedPreferences).getString("email", ""); + + } + + Object uName = null; + Object uEmail = null; + if(username.equals(uName) && password.equals(uEmail)){ + + session.createUserLoginSession(uName, + uEmail); + + // Starting MainActivity + Intent i = new Intent(getApplicationContext(),MainActivity.class); + i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + + // Add new Flag to start new Activity + i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(i); + + finish(); + + }else{ + + // username / password doesn't match& + Toast.makeText(getApplicationContext(), + "Username/Password is incorrect", + Toast.LENGTH_LONG).show(); + + } + }else{ + + // user didn't entered username or password + Toast.makeText(getApplicationContext(), + "Please enter username and password", + Toast.LENGTH_LONG).show(); + + } + + } + }); +} + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = new MenuInflater(this); + inflater.inflate(R.menu.main, menu); + return true; + } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + switch (id) { + case R.id.MENU_1: + Intent intent1 = new Intent(this, Login.class); + this.startActivity(intent1); + break; + case R.id.MENU_2: + Intent intent2 = new Intent(this, MainActivity.class); + this.startActivity(intent2); + break; + default: + return super.onOptionsItemSelected(item); + } + + return true; + }