Advertisement
Guest User

Untitled

a guest
Mar 27th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. package com.example.user_pc.imhungry;
  2.  
  3. import android.app.AlertDialog;
  4. import android.content.Intent;
  5. import android.database.Cursor;
  6. import android.database.sqlite.SQLiteDatabase;
  7. import android.os.Bundle;
  8. import android.support.design.widget.FloatingActionButton;
  9. import android.support.design.widget.Snackbar;
  10. import android.support.v7.app.AppCompatActivity;
  11. import android.support.v7.widget.Toolbar;
  12. import android.view.View;
  13. import android.view.Menu;
  14. import android.view.MenuItem;
  15. import android.widget.Button;
  16. import android.widget.EditText;
  17. import android.widget.Toast;
  18.  
  19. import java.text.ParseException;
  20. import java.util.prefs.Preferences;
  21.  
  22. public class MainActivity extends AppCompatActivity {
  23. Button sendBtn;
  24. EditText usernameFld, passwordFld;
  25. // Defining the database:
  26. SQLiteDatabase mydatabase;
  27.  
  28. @Override
  29. protected void onCreate(Bundle savedInstanceState) {
  30. super.onCreate(savedInstanceState);
  31.  
  32. setContentView(R.layout.activity_main);
  33. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  34. setSupportActionBar(toolbar);
  35.  
  36. // Setting up the database:
  37. mydatabase = openOrCreateDatabase("your database name", MODE_PRIVATE, null);
  38.  
  39.  
  40. FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  41. fab.setOnClickListener(new View.OnClickListener() {
  42. @Override
  43. public void onClick(View view) {
  44. Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
  45. .setAction("Action", null).show();
  46. }
  47. });
  48. // sendBtn = (Button)findViewById(R.id.sendBtn);
  49. usernameFld = (EditText)findViewById(R.id.usernameFld);
  50. passwordFld = (EditText)findViewById(R.id.passwordFld);
  51.  
  52. }
  53. public void sendBtnOnClick(View v)
  54. {
  55. mydatabase.execSQL("CREATE TABLE IF NOT EXISTS users(username VARCHAR,password VARCHAR);");
  56. mydatabase.execSQL("INSERT INTO TutorialsPoint VALUES('markigor','igormark');");
  57. Cursor resultSet = mydatabase.rawQuery("Select * from TutorialsPoint",null);
  58. resultSet.moveToFirst();
  59. String username = resultSet.getString(1);
  60. String password = resultSet.getString(2);
  61.  
  62. AlertDialog alert = new AlertDialog.Builder(this).create();
  63. if(usernameFld.getText().toString().equals(username) && passwordFld.getText().toString().equals(password))
  64. {
  65. alert.setTitle("WELCOME"); alert.setMessage("Welcome dear user !!!");
  66. }
  67. else
  68. {
  69. alert.setTitle("ERROR"); alert.setMessage("You are not one of ours !!!");
  70. }
  71. alert.show();
  72. mydatabase.close();
  73. }
  74. public void signUpBtnOnClick(View v)
  75. {
  76. startActivity(new Intent(getApplicationContext(), SignUp.class)); // Transfers the user to sign up screen.
  77. }
  78. public void forgotPassBtnOnClick(View v)
  79. {
  80. /*String emailReset = usernameFld.getText().toString();
  81. try{
  82. ParseUser.requestPasswordResetInBackground(emailReset, new RequestPasswordResetCallback() {
  83. public void done(ParseException e) {
  84. if (e == null) {
  85. usernameFld.setText("An Email has been send to your email account! Follow the procedure");
  86. } else {
  87. Toast.makeText(getApplicationContext(), "Some Error! Try later" + e, Toast.LENGTH_LONG);
  88. }
  89.  
  90. }
  91. });
  92. }
  93. catch(Exception e){
  94. Toast.makeText(getApplicationContext(),"Error"+e,Toast.LENGTH_LONG).show();
  95. }*/
  96. }
  97. public void clearBtnOnClick(View v)
  98. {
  99. usernameFld.setText("");
  100. passwordFld.setText("");
  101. }
  102. public void exitBtnOnClick(View v)
  103. {
  104. finish();
  105. System.exit(0);
  106. }
  107. @Override
  108. public boolean onCreateOptionsMenu(Menu menu) {
  109. // Inflate the menu; this adds items to the action bar if it is present.
  110. getMenuInflater().inflate(R.menu.menu_main, menu);
  111. return true;
  112. }
  113.  
  114. @Override
  115. public boolean onOptionsItemSelected(MenuItem item) {
  116. // Handle action bar item clicks here. The action bar will
  117. // automatically handle clicks on the Home/Up button, so long
  118. // as you specify a parent activity in AndroidManifest.xml.
  119. int id = item.getItemId();
  120.  
  121. //noinspection SimplifiableIfStatement
  122. if (id == R.id.action_settings) {
  123. return true;
  124. }
  125.  
  126. return super.onOptionsItemSelected(item);
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement