Example #1
0
  @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);
  }
Example #2
0
  /**
   * 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);
  }
  /** function to pull list of all categories form web server */
  public void pullList() {
    // Tag used to cancel the request
    String tag_string_req = "req_" + url;

    final GsonRequest<T> gsonRequest =
        new GsonRequest<T>(
            url,
            t,
            null,
            new Response.Listener<T>() {

              @Override
              public void onResponse(T model) {

                if (model != null) {
                  webRequestCallbackInterface.webRequestSuccess(true, model);
                  Log.d("tag_string_req", "NOT NULL");
                  Log.d("tag_string_req", model.toString());

                } else {
                  Log.d("pullCategoriesResp", "NULL RESPONSE");
                  webRequestCallbackInterface.webRequestSuccess(false, model);
                }
              }
            },
            new Response.ErrorListener() {

              @Override
              public void onErrorResponse(VolleyError error) {
                webRequestCallbackInterface.webRequestError(error.getMessage());
              }
            }) {

          @Override
          protected Map<String, String> getParams() {
            // Post params
            Map<String, String> params = new HashMap<>();
            params.put("action", "pull " + t.getName());
            params.put("id", url);
            return params;
          }
        };

    gsonRequest.setRetryPolicy(
        new DefaultRetryPolicy(
            AppParams.DEFAULT_TIMEOUT_MS,
            AppParams.DEFAULT_MAX_RETRIES,
            AppParams.DEFAULT_BACKOFF_MULT));
    // Adding request to  queue
    mVolleySingleton.addToRequestQueue(gsonRequest);
  }
  /**
   * Bind an instance of the <code>Chat</code> class to our view. This method is called by <code>
   * FirebaseListAdapter</code> when there is a data change, and we are given an instance of a View
   * that corresponds to the layout that we passed to the constructor, as well as a single <code>
   * Chat</code> instance that represents the current data to bind.
   *
   * @param view A view instance corresponding to the layout we passed to the constructor.
   * @param chat An instance representing the current state of a chat message
   */
  @Override
  protected void populateView(View view, Chat chat) {
    // Map a Chat object to an entry in our listview
    String author = chat.getAuthor();
    TextView authorText = (TextView) view.findViewById(R.id.author);
    authorText.setText(author + ": ");
    instanceOfVolley = VolleySingleton.newInstance(context);

    final NetworkImageView imageView = (NetworkImageView) view.findViewById(R.id.networkImageView);
    final ImageLoader imageLoader = instanceOfVolley.getImageLoader();
    final TextView titleTextView = (TextView) view.findViewById(R.id.title);
    final TextView descriptionTextView = (TextView) view.findViewById(R.id.description);

    // If the message was sent by this user, color it differently
    if (author.equals(username)) {
      authorText.setTextColor(Color.RED);
    } else {
      authorText.setTextColor(Color.BLUE);
    }
    ((TextView) view.findViewById(R.id.message)).setText(chat.getMessage());

    String message = chat.getMessage();
    int start = message.indexOf("((");
    if (start != -1) {
      String query = message.substring(start + 2, message.indexOf("))"));

      // the volley listener
      listener =
          new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
              try {
                JSONArray items = response.getJSONArray("items");
                JSONObject json = items.getJSONObject(0);
                JSONObject id = json.getJSONObject("id");
                JSONObject snippet = json.getJSONObject("snippet");
                JSONObject thumbnails = snippet.getJSONObject("thumbnails");
                JSONObject high = thumbnails.getJSONObject("high");
                String url = high.getString("url");
                String description = snippet.getString("description");
                String title = snippet.getString("title");
                titleTextView.setText(title);
                descriptionTextView.setText(description);
                imageView.setImageUrl(url, imageLoader);
                videoID = id.getString("videoId");
                imageView.setVisibility(View.VISIBLE);
                titleTextView.setVisibility(View.VISIBLE);
                descriptionTextView.setVisibility(View.VISIBLE);
                imageView.setTag(videoID);
                imageView.setOnClickListener(
                    new View.OnClickListener() {

                      @Override
                      public void onClick(View view) {
                        String tag = view.getTag().toString();
                        Intent intent = new Intent(activity, PlayActivity.class);
                        intent.putExtra("id", tag);
                        activity.startActivity(intent);
                      }
                    });
              } catch (JSONException ex) {
                ex.printStackTrace();
              }
            }
          };

      // the volley error listener
      errorListener =
          new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
              error.printStackTrace();
            }
          };

      try {
        url = Config.URL + URLEncoder.encode(query, "utf-8");
      } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
      }

      JsonObjectRequest req = new JsonObjectRequest(url, null, listener, errorListener);
      instanceOfVolley.addToRequestQueue(req);

    } else {
      imageView.setVisibility(View.GONE);
      titleTextView.setVisibility(View.GONE);
      descriptionTextView.setVisibility(View.GONE);
    }
  }
Example #7
0
 private void grab() {
   final MyProgressDialog pd = MyProgressDialog.show(CommonUtilities.context, "", "");
   String URL;
   System.out.println(System.currentTimeMillis());
   URL =
       "https://script.google.com/macros/s/AKfycbxM-vcwreQme8aX8_sWdKcc-KXFPzZ9XQzRm6u_-oIYjNXUhxI/exec";
   RequestQueue queue = VolleySingleton.getsInstance().getmRequestQueue();
   StringRequest stringRequest =
       new StringRequest(
           Request.Method.GET,
           URL,
           new Response.Listener<String>() {
             @Override
             public void onResponse(String response) {
               JSONArray objects = null;
               try {
                 objects = new JSONArray(response);
                 for (int i = 0; i < CommonUtilities.keys.size(); i++)
                   banqiMap.put(i, new ArrayList<String>());
                 for (int i = 0; i < objects.length(); i++) {
                   HashMap<String, String> map = new HashMap<String, String>();
                   JSONObject session = objects.getJSONObject(i);
                   for (int x = 0; x < CommonUtilities.keys.size(); x++) {
                     String key = CommonUtilities.keys.get(x);
                     String result;
                     if (session.has(key)) {
                       result = session.getString(key);
                       if (result == "1") banqiMap.get(x).add(session.getString("姓名"));
                     }
                   }
                 }
               } catch (JSONException e) {
                 e.printStackTrace();
               }
               for (int i = 0; i < CommonUtilities.keys.size(); i++) {
                 myMergeAdapter.addView(buildLabel(CommonUtilities.keys.get(i), 0, 22));
                 myMergeAdapter.addView(buildLabel("C 组", 10, 12));
                 Iterator<String> iterator = banqiMap.get(i).iterator();
                 List<String> tmplist = new ArrayList<String>();
                 while (iterator.hasNext()) {
                   String s = iterator.next();
                   if (CommonUtilities.ClassMap.get("C").contains(s)) tmplist.add(s);
                 }
                 ListAdapter adapter =
                     new ArrayAdapter<String>(
                         context, android.R.layout.simple_list_item_activated_1, tmplist);
                 myMergeAdapter.addAdapter(adapter);
                 myMergeAdapter.addView(buildLabel("B 组", 10, 12));
                 iterator = banqiMap.get(i).iterator();
                 tmplist = new ArrayList<String>();
                 while (iterator.hasNext()) {
                   String s = iterator.next();
                   if (CommonUtilities.ClassMap.get("B").contains(s)) tmplist.add(s);
                 }
                 adapter =
                     new ArrayAdapter<String>(
                         context, android.R.layout.simple_list_item_activated_1, tmplist);
                 myMergeAdapter.addAdapter(adapter);
                 myMergeAdapter.addView(buildLabel("A 组", 10, 12));
                 iterator = banqiMap.get(i).iterator();
                 tmplist = new ArrayList<String>();
                 while (iterator.hasNext()) {
                   String s = iterator.next();
                   if (CommonUtilities.ClassMap.get("A").contains(s)) tmplist.add(s);
                 }
                 adapter =
                     new ArrayAdapter<String>(
                         context, android.R.layout.simple_list_item_activated_1, tmplist);
                 myMergeAdapter.addAdapter(adapter);
               }
               if (pd.isShowing()) pd.dismiss();
               listview.setAdapter(myMergeAdapter);
             }
           },
           new Response.ErrorListener() {
             @Override
             public void onErrorResponse(VolleyError error) {
               pd.dismiss();
             }
           });
   queue.add(stringRequest);
 }
  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);
  }
Example #9
0
 public ExploreHttpFacadeImpl(Context context) {
   requestQueue = VolleySingleton.getInstance(context).getRequestQueue();
   location = InternalExploreSettings.getInstance(context).getLocation();
 }