use of com.android.volley.RequestQueue in project EC2018App by Manan-YMCA.
the class RegisterActivity method registerUser.
private void registerUser(final UserDetails userDetails) {
String url = getResources().getString(R.string.register_user_api);
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
MDToast.makeText(RegisterActivity.this, "Registered!", MDToast.LENGTH_SHORT, MDToast.TYPE_SUCCESS).show();
mProgress.dismiss();
SharedPreferences.Editor editor = getSharedPreferences(getResources().getString(R.string.sharedPrefName), MODE_PRIVATE).edit();
editor.putString("Phone", userDetails.getmPhone());
editor.apply();
AccessToken token = AccessToken.getCurrentAccessToken();
if (token != null) {
startSession();
} else {
FragmentManager fm = getFragmentManager();
FragmentFbLogin fbLogin = new FragmentFbLogin();
fbLogin.show(fm, "fbLoginFragment");
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mProgress.dismiss();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> map = new HashMap<String, String>();
map.put("name", userDetails.getmName());
map.put("email", userDetails.getEmail());
map.put("phone", userDetails.getmPhone());
map.put("college", userDetails.getmCollege());
map.put("fb", userDetails.getmFbId());
return map;
}
};
queue.add(request);
}
use of com.android.volley.RequestQueue in project EC2018App by Manan-YMCA.
the class Tickets method reload.
private void reload(final String[] phone) {
String url = getResources().getString(R.string.get_events_qr_code);
url += phone;
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
mProgress.dismiss();
try {
JSONObject obj1 = new JSONObject(response);
JSONArray ticketDetails = obj1.getJSONArray("data");
for (int i = 0; i < ticketDetails.length(); i++) {
JSONObject obj2 = ticketDetails.getJSONObject(i);
QRTicketModel TicketModel = new QRTicketModel();
TicketModel.setPaymentStatus(obj2.getInt("paymentstatus"));
TicketModel.setArrivalStatus(obj2.getInt("arrived"));
TicketModel.setQRcode(obj2.getString("qrcode"));
TicketModel.setEventID(obj2.getString("eventid"));
TicketModel.setTimeStamp(obj2.getLong("timestamp"));
userTickets.add(TicketModel);
}
mIncomingHandler.sendEmptyMessage(0);
}// Try and catch are included to handle any errors due to JSON
catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mProgress.dismiss();
}
});
queue.add(request);
}
use of com.android.volley.RequestQueue in project aplicativo by InCasa.
the class ReleActivity method getRele4.
public void getRele4(String URLRELE4) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLRELE4, null, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
String temp = "";
try {
Switch rele4 = (Switch) findViewById(R.id.switch4);
temp = response.getString("valor");
if (temp.equals("0")) {
rele4.setChecked(false);
estado4 = false;
} else {
rele4.setChecked(true);
estado4 = true;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
// Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
Context context = getApplicationContext();
CharSequence text = "Erro na requisição";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.RequestQueue in project aplicativo by InCasa.
the class ReleActivity method getRele3.
public void getRele3(String URLRELE3) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLRELE3, null, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
String temp = "";
try {
Switch rele3 = (Switch) findViewById(R.id.switch3);
temp = response.getString("valor");
if (temp.equals("0")) {
rele3.setChecked(false);
estado3 = false;
} else {
rele3.setChecked(true);
estado3 = true;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
// Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
Context context = getApplicationContext();
CharSequence text = "Erro na requisição";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.RequestQueue in project aplicativo by InCasa.
the class ReleActivity method getRele1.
public void getRele1(String URLRELE1) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLRELE1, null, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
String temp = "";
try {
Switch rele1 = (Switch) findViewById(R.id.switch1);
temp = response.getString("valor");
if (temp.equals("0")) {
rele1.setChecked(false);
estado1 = false;
} else {
rele1.setChecked(true);
estado1 = true;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
// Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
Context context = getApplicationContext();
CharSequence text = "Erro na requisição";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
// Adiciona a requisição á fila de requisições
fila.add(req);
}
Aggregations