@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash_screen); final TextView mTextView = (TextView) findViewById(R.id.splashscreen_text); // Get a RequestQueue RequestQueue queue = VolleySingleton.getInstance(this.getApplicationContext()).getRequestQueue(); // Formulate the JSON request and handle the response. JsonObjectRequest jsObjRequest = new JsonObjectRequest( Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.i("Response", response.toString()); String stringFromJson = parseJSON(response); mTextView.setText(stringFromJson); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { mTextView.setText(error.toString()); } }); // Add a JsonObjectRequest to your RequestQueue. VolleySingleton.getInstance(this).addToRequestQueue(jsObjRequest); new Handler() .postDelayed( new Runnable() { /* * Showing splash screen with a timer. This will be useful when you * want to show case your app logo / company */ @Override public void run() { // This method will be executed once the timer is over // move to Main Intent i = new Intent(SplashScreen.this, Home.class); startActivity(i); // close this activity finish(); } }, SPLASH_TIME_OUT); }
/** * Helper function for performing a Generic HTTP Get JSON request * * @param context * @param REQUEST_TAG */ public static void genericGet( Context context, String url, final RequestCallback callback, String REQUEST_TAG) { JsonObjectRequest jsObjRequest = new JsonObjectRequest( Request.Method.GET, url, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { // Successful response so send data via the observable callback.onCompleted(response, null); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // Error occurred, should send error here so error handling can be implemented callback.onCompleted(null, null); } }); jsObjRequest.setTag(REQUEST_TAG); // Set a tag for this request VolleySingleton.getInstance(context) .addToRequestQueue(jsObjRequest); // Add the request to the Volley Queue }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.around_me, container, false); if (location.latitude != 0 && location.longitude != 0) myLocation = new LatLng(location.latitude, location.longitude); else myLocation = new LatLng(40.7431735, -73.9799391); url = url + "location=" + myLocation.latitude + "," + myLocation.longitude + "&radius=" + radius + "&key=" + key; final RequestQueue requestQueue = VolleySingleton.getInstance().getRequestQueue(); final JsonObjectRequest jsObjRequest = new JsonObjectRequest( Request.Method.GET, url, (String) null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { AroundMeParser parse = new AroundMeParser(); JSONArray cleanPlaces = parse.cleanPlaces(parse.parseResponse(response)); try { cleanPlaces = sortTop25(cleanPlaces); display(cleanPlaces); } catch (JSONException e) { e.printStackTrace(); Toast.makeText( getActivity(), "ERROR while Sorting or Display", Toast.LENGTH_SHORT) .show(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub // Toast.makeText(getActivity(), "ERROR: " + error.getMessage(), // Toast.LENGTH_SHORT).show(); Log.i("", "ERROR: + error.getMessage()"); } }); requestQueue.add(jsObjRequest); return view; }
private void eliminar(final Vehiculo vehiculo, final User sesion) { RequestQueue mRequestQueue; mRequestQueue = VolleySingleton.getInstance().getmRequestQueue(); StringRequest request = new StringRequest( Request.Method.POST, "http://52.23.181.133/index.php/eliminarVehiculo", new Response.Listener<String>() { @Override public void onResponse(String response) { try { JSONObject json = new JSONObject(response); if (json.getBoolean("exito")) { Toast.makeText( getApplicationContext(), "Vehículo eliminado correctamente", Toast.LENGTH_LONG) .show(); Intent intent = new Intent(DetalleVehiculoActivity.this, VehiculoActivity.class); intent.putExtra("sesion", sesion); intent.putExtra("vehiculo", vehiculo); startActivity(intent); } else { Toast.makeText( getApplicationContext(), json.getString("error"), Toast.LENGTH_LONG) .show(); } } catch (JSONException e) { Toast.makeText( getApplicationContext(), "Se ha producido un error al establecer comunicación con los servidores de Gerprin. Inténtelo de nuevo más tarde", Toast.LENGTH_LONG) .show(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText( getApplicationContext(), "Se ha producido un error al establecer comunicación con los servidores de Gerprin. Inténtelo de nuevo más tarde", Toast.LENGTH_LONG) .show(); } }) { @Override protected Map<String, String> getParams() { Map<String, String> params = new HashMap<String, String>(); params.put("vehiculo_id", String.valueOf(vehiculo.getId())); return params; } }; mRequestQueue.add(request); }
public void registrar( final User sesion, final Vehiculo vehiculo, final String email, final String nombre, final String apellido, final String contraseña, final boolean dueño) { final User conductor = (User) getIntent().getExtras().getSerializable("conductor"); RequestQueue mRequestQueue; mRequestQueue = VolleySingleton.getInstance().getmRequestQueue(); StringRequest request = new StringRequest( Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) { try { JSONObject json = new JSONObject(response); if (json.getBoolean("exito")) { Toast.makeText( getApplicationContext(), "Usuario editado correctamente", Toast.LENGTH_LONG) .show(); conductor.setEmail(email); conductor.setNombre(nombre); conductor.setApellido(apellido); conductor.setDueño(dueño); Intent intent = new Intent(EditarUserActivity.this, DetalleUserActivity.class); intent.putExtra("sesion", sesion); intent.putExtra("vehiculo", vehiculo); intent.putExtra("conductor", conductor); visibilityLoadOff(); startActivity(intent); } else { visibilityLoadOff(); Toast.makeText( getApplicationContext(), json.getString("error"), Toast.LENGTH_LONG) .show(); } } catch (JSONException e) { visibilityLoadOff(); Toast.makeText( getApplicationContext(), "Se ha producido un error al establecer comunicación con los servidores de Gerprin. Inténtelo de nuevo más tarde", Toast.LENGTH_LONG) .show(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { visibilityLoadOff(); Toast.makeText( getApplicationContext(), "Se ha producido un error al establecer comunicación con los servidores de Gerprin. Inténtelo de nuevo más tarde", Toast.LENGTH_LONG) .show(); } }) { @Override protected Map<String, String> getParams() { Map<String, String> params = new HashMap<>(); params.put("user_id", String.valueOf(conductor.getId())); params.put("nombre", nombre); params.put("apellido", apellido); params.put("email", email); if (!contraseña.matches("")) { params.put("password", contraseña); } params.put("vehiculo_id", String.valueOf(vehiculo.getId())); if (dueño) { params.put("dueno", "1"); } else { params.put("dueno", "0"); } return params; } }; mRequestQueue.add(request); }
public ExploreHttpFacadeImpl(Context context) { requestQueue = VolleySingleton.getInstance(context).getRequestQueue(); location = InternalExploreSettings.getInstance(context).getLocation(); }