- package volleyjson.androidhive.info.myapplication;
-
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.Intent;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
-
- import com.android.volley.AuthFailureError;
- import com.android.volley.Request;
- import com.android.volley.Response;
- import com.android.volley.VolleyError;
- import com.android.volley.VolleyLog;
- import com.android.volley.toolbox.JsonObjectRequest;
- import volleyjson.androidhive.info.myapplication.app.AppController;
-
- import org.json.JSONObject;
-
- import java.util.HashMap;
- import java.util.Map;
-
- @SuppressWarnings("ALL")
- public class login extends Activity implements View.OnClickListener{
- private final String TAG = login.class.getSimpleName();
- private static final String LOGIN_URL = "http://www.nishkarsh.co.in/api/login";
- private static final String KEY_EMAIL = "email";
- private ProgressDialog pDialog;
- private TextView t1;
- private TextView t2;
- private TextView t3;
- private EditText ed1;
- private Button b1;
- private String email;
-
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.login_dialogue);
- t1 = (TextView) findViewById(R.id.textView1);
- t2 = (TextView) findViewById(R.id.textView2);
- t3 = (TextView) findViewById(R.id.textView3);
- ed1 = (EditText) findViewById(R.id.RegEmail);
- b1 = (Button) findViewById(R.id.btnLogin);
- b1.setOnClickListener(this);
- ProgressDialog pDialog = new ProgressDialog(this);
- pDialog.setMessage("Loading...");
- pDialog.setCancelable(false);
- }
- private void showProgressDialog() {
- if (!pDialog.isShowing())
- pDialog.show();
- }
-
- private void hideProgressDialog() {
- if (pDialog.isShowing())
- pDialog.hide();
- }
- private void makeJsonObjReq() {
- showProgressDialog();
- JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
- LOGIN_URL , null,
- new Response.Listener<JSONObject>() {
-
- @Override
- public void onResponse(JSONObject response) {
- Log.d(TAG, response.toString());
- openProfile();
- pDialog.hide();
- }
- }, new Response.ErrorListener() {
-
- @Override
- public void onErrorResponse(VolleyError error) {
- VolleyLog.d(TAG, "Error: " + error.getMessage());
- hideProgressDialog();
- }
- }) {
-
- /**
- * Passing some request headers
- * */
- @Override
- public Map<String, String> getHeaders() throws AuthFailureError {
- HashMap<String, String> headers = new HashMap<>();
- headers.put("Content-Type", "application/json");
- return headers;
- }
- @Override
- protected Map<String, String> getParams() {
- Map<String, String> params = new HashMap<>();
- params.put(KEY_EMAIL, email);
-
- return params;
- }
-
- };
-
- // Adding request to request queue
- String tag_json_obj = "jsonObjReq ";
- AppController.getInstance().addToRequestQueue(jsonObjReq,
- tag_json_obj);
-
- // Cancelling request
- // ApplicationController.getInstance().getRequestQueue().cancelAll(tag_json_obj);
- }
- private void openProfile(){
- Intent intent = new Intent(login.this, MainActivity.class);
- intent.putExtra(KEY_EMAIL,email);
- startActivity(intent);
- }
-
- @Override
- public void onClick(View v) {
-
- makeJsonObjReq();
- }
- }
package volleyjson.androidhive.info.myapplication;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonObjectRequest;
import volleyjson.androidhive.info.myapplication.app.AppController;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
@SuppressWarnings("ALL")
public class login extends Activity implements View.OnClickListener{
private final String TAG = login.class.getSimpleName();
private static final String LOGIN_URL = "http://www.nishkarsh.co.in/api/login";
private static final String KEY_EMAIL = "email";
private ProgressDialog pDialog;
private TextView t1;
private TextView t2;
private TextView t3;
private EditText ed1;
private Button b1;
private String email;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_dialogue);
t1 = (TextView) findViewById(R.id.textView1);
t2 = (TextView) findViewById(R.id.textView2);
t3 = (TextView) findViewById(R.id.textView3);
ed1 = (EditText) findViewById(R.id.RegEmail);
b1 = (Button) findViewById(R.id.btnLogin);
b1.setOnClickListener(this);
ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.setCancelable(false);
}
private void showProgressDialog() {
if (!pDialog.isShowing())
pDialog.show();
}
private void hideProgressDialog() {
if (pDialog.isShowing())
pDialog.hide();
}
private void makeJsonObjReq() {
showProgressDialog();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
LOGIN_URL , null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
openProfile();
pDialog.hide();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
hideProgressDialog();
}
}) {
/**
* Passing some request headers
* */
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
return headers;
}
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put(KEY_EMAIL, email);
return params;
}
};
// Adding request to request queue
String tag_json_obj = "jsonObjReq ";
AppController.getInstance().addToRequestQueue(jsonObjReq,
tag_json_obj);
// Cancelling request
// ApplicationController.getInstance().getRequestQueue().cancelAll(tag_json_obj);
}
private void openProfile(){
Intent intent = new Intent(login.this, MainActivity.class);
intent.putExtra(KEY_EMAIL,email);
startActivity(intent);
}
@Override
public void onClick(View v) {
makeJsonObjReq();
}
}
4 Answer(s)