Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.xyz.dbapp;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.Intent;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- import org.json.JSONException;
- import org.json.JSONObject;
- /**
- * Created by selvakumar on 6/23/2015.
- */
- public class loginactivity extends Activity
- {
- private ProgressDialog pDialog;
- JSONParser jsonParser = new JSONParser();
- private static final String url_login = "http://192.168.43.105/xamarin/loginprocess.php";
- String username;
- String password;
- EditText e1;
- EditText e2;
- public void onCreate(Bundle b)
- {
- super.onCreate(b);
- setContentView(R.layout.loginlayout);
- e1=(EditText)findViewById(R.id.tusername);
- e2=(EditText)findViewById(R.id.tpassword);
- Button btnlogin = (Button) findViewById(R.id.btnlogin);
- btnlogin.setOnClickListener(new View.OnClickListener()
- {
- public void onClick(View view)
- {
- username=e1.getText().toString();
- password=e2.getText().toString();
- new getlogindetails().execute(username,password);
- }
- });
- }
- class getlogindetails extends AsyncTask<String, String, String>
- {
- protected void onPreExecute()
- {
- super.onPreExecute();
- pDialog = new ProgressDialog(loginactivity.this);
- pDialog.setMessage("Logging in. Please wait...");
- pDialog.setIndeterminate(false);
- pDialog.setCancelable(true);
- pDialog.show();
- }
- protected String doInBackground(String... params)
- {
- int success;
- try
- {
- JSONObject json = jsonParser.makeHttpRequest(url_login, username,password);
- Log.d("Login", json.toString());
- success = json.getInt("result");
- if (success == 1)
- {
- Intent myintent=new Intent(getApplicationContext(),menuactivity.class);
- startActivity(myintent);
- }
- else
- {
- loginactivity.this.runOnUiThread(new Runnable()
- {
- public void run()
- {
- Toast.makeText(getApplicationContext(),"Not Found",Toast.LENGTH_LONG).show();
- }
- });
- }
- }
- catch (JSONException e)
- {
- e.printStackTrace();
- }
- return null;
- }
- protected void onPostExecute(String file_url)
- {
- pDialog.dismiss();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement