NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.example.asusrog.papajohns;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

public class LoginActivity extends AppCompatActivity {

EditText emailEditText;
EditText passwordEditText;
Button loginBT;


private static final String TAG_NAME = "name";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

emailEditText = (EditText) findViewById(R.id.usernameET);
passwordEditText = (EditText) findViewById(R.id.passwordET);
loginBT = (Button) findViewById(R.id.button);

SQLiteDatabase db;
db=openOrCreateDatabase("papaJ", Context.MODE_PRIVATE, null);
Cursor c =db.rawQuery("SELECT name FROM users LIMIT(1);",null);

if(c.moveToFirst()){
Intent i = new Intent(LoginActivity.this,MainActivity.class);
startActivity(i);
finish();
Toast.makeText(getApplicationContext(), "Welcome "+c.getString(0), Toast.LENGTH_LONG).show();
}else
loginBT.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = emailEditText.getText().toString();
String pass = passwordEditText.getText().toString();

new PostAsync().execute(email, pass);

}
});
}

@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_login, 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);
}
class PostAsync extends AsyncTask<String, String, JSONObject> {
JSONParser jsonParser = new JSONParser();

private ProgressDialog pDialog;

private static final String LOGIN_URL = "http://tootbh.com/a_papa/getUser.php";

// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";

private static final String TAG_USERS = "user";
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static final String TAG_MOBILE = "mobile";
private static final String TAG_EMAIL = "email";
SQLiteDatabase db;

JSONArray user = null;
int id;
String name,mobile,email;


@Override
protected void onPreExecute() {
pDialog = new ProgressDialog(LoginActivity.this);
pDialog.setMessage("Attempting login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}

@Override
protected JSONObject doInBackground(String... args) {

try {

HashMap<String, String> params = new HashMap<>();
params.put("email", args[0]);
params.put("pass", args[1]);

Log.d("request", "starting");

JSONObject json = jsonParser.makeHttpRequest(
LOGIN_URL, "POST", params);

if (json != null) {
Log.d("JSON result", json.toString());
/////////////////////////////////////////////////////////////////////////////////////////////////////////


int success = 0;
String message = "";

//Toast.makeText(getApplicationContext(), json.toString(), Toast.LENGTH_LONG).show();

try {
success = json.getInt(TAG_SUCCESS);
message = json.getString(TAG_MESSAGE);
} catch (JSONException e) {
e.printStackTrace();
}


if (success == 1) {
Log.d("Success!", message);
// Creating database and table

try {

user = json.getJSONArray(TAG_USERS);
JSONObject c = user.getJSONObject(0);
id = c.getInt("id");
name = c.getString("name");
mobile = c.getString("mobile");
email = c.getString("email");
//Toast.makeText(LoginActivity.this,v1,Toast.LENGTH_LONG).show();


/*
Toast.makeText(LoginActivity.this,user.getString('id'),Toast.LENGTH_LONG).show();
JSONObject c = user.getJSONObject(0);
// Storing each json item in variable
int id = c.getInt(TAG_ID);
String name = c.getString(TAG_NAME);
String mobile = c.getString(TAG_MOBILE);
String email = c.getString(TAG_EMAIL);
*/
// Toast.makeText(LoginActivity.this, String.valueOf(id) + "," + name + "," + mobile + "," + email, Toast.LENGTH_LONG).show();


}
catch (JSONException e){
e.printStackTrace();
}

db=openOrCreateDatabase("papaJ", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS users(" +
" id INT(11) NOT NULL," +
" name VARCHAR(250) NOT NULL," +
" mobile VARCHAR(8) NOT NULL," +
" email VARCHAR(250) NOT NULL);");
//db.execSQL("INSERT INTO users VALUES(1,'Abbas Salman','33213188','[email protected]');");
db.execSQL("INSERT INTO users VALUES("+id+",'"+name+"','"+mobile+"','"+email+"');");

Intent i = new Intent(LoginActivity.this,MainActivity.class);
startActivity(i);
finish();
Toast.makeText(getApplicationContext(), "Welcome", Toast.LENGTH_LONG).show();
}else{
Log.d("Failure", message);
Toast.makeText(getApplicationContext(),"Failure",Toast.LENGTH_LONG).show();
}




///////////////////////////////////////////////////////////////////////////////////////////////////////

return json;
}

} catch (Exception e) {
e.printStackTrace();
}

return null;
}

protected void onPostExecute(JSONObject json) {
if (pDialog != null && pDialog.isShowing()) {
pDialog.dismiss();
}

}

}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.