Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.user_pc.imhungry;
- import android.app.AlertDialog;
- import android.content.Intent;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.os.Bundle;
- import android.support.design.widget.FloatingActionButton;
- import android.support.design.widget.Snackbar;
- import android.support.v7.app.AppCompatActivity;
- import android.support.v7.widget.Toolbar;
- import android.view.View;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- import java.text.ParseException;
- import java.util.prefs.Preferences;
- public class MainActivity extends AppCompatActivity {
- Button sendBtn;
- EditText usernameFld, passwordFld;
- // Defining the database:
- SQLiteDatabase mydatabase;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- // Setting up the database:
- mydatabase = openOrCreateDatabase("your database name", MODE_PRIVATE, null);
- FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
- fab.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
- .setAction("Action", null).show();
- }
- });
- // sendBtn = (Button)findViewById(R.id.sendBtn);
- usernameFld = (EditText)findViewById(R.id.usernameFld);
- passwordFld = (EditText)findViewById(R.id.passwordFld);
- }
- public void sendBtnOnClick(View v)
- {
- mydatabase.execSQL("CREATE TABLE IF NOT EXISTS users(username VARCHAR,password VARCHAR);");
- mydatabase.execSQL("INSERT INTO TutorialsPoint VALUES('markigor','igormark');");
- Cursor resultSet = mydatabase.rawQuery("Select * from TutorialsPoint",null);
- resultSet.moveToFirst();
- String username = resultSet.getString(1);
- String password = resultSet.getString(2);
- AlertDialog alert = new AlertDialog.Builder(this).create();
- if(usernameFld.getText().toString().equals(username) && passwordFld.getText().toString().equals(password))
- {
- alert.setTitle("WELCOME"); alert.setMessage("Welcome dear user !!!");
- }
- else
- {
- alert.setTitle("ERROR"); alert.setMessage("You are not one of ours !!!");
- }
- alert.show();
- mydatabase.close();
- }
- public void signUpBtnOnClick(View v)
- {
- startActivity(new Intent(getApplicationContext(), SignUp.class)); // Transfers the user to sign up screen.
- }
- public void forgotPassBtnOnClick(View v)
- {
- /*String emailReset = usernameFld.getText().toString();
- try{
- ParseUser.requestPasswordResetInBackground(emailReset, new RequestPasswordResetCallback() {
- public void done(ParseException e) {
- if (e == null) {
- usernameFld.setText("An Email has been send to your email account! Follow the procedure");
- } else {
- Toast.makeText(getApplicationContext(), "Some Error! Try later" + e, Toast.LENGTH_LONG);
- }
- }
- });
- }
- catch(Exception e){
- Toast.makeText(getApplicationContext(),"Error"+e,Toast.LENGTH_LONG).show();
- }*/
- }
- public void clearBtnOnClick(View v)
- {
- usernameFld.setText("");
- passwordFld.setText("");
- }
- public void exitBtnOnClick(View v)
- {
- finish();
- System.exit(0);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement