Search in sources :

Example 21 with Response

use of com.android.volley.Response in project easy by MehdiBenmesa.

the class AbsenceService method getSeanceByTeacher.

public void getSeanceByTeacher(final IAbsence callBack) throws JSONException {
    CustomRequest jsonReq = new CustomRequest(Request.Method.GET, GET_TIME_TABLE_TEACHER + "/" + App.getInstance().getUser().getString("_id"), null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            callBack.onDataReceived(response);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
        }
    });
    App.getInstance().addToRequestQueue(jsonReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) CustomRequest(dz.easy.androidclient.Util.CustomRequest)

Example 22 with Response

use of com.android.volley.Response in project easy by MehdiBenmesa.

the class TimeLineActivity method setDataListItemsStudent.

public void setDataListItemsStudent(final Itimeline callback) {
    try {
        CustomRequest jsonReq = new CustomRequest(Request.Method.GET, GET_TIME_TABLE_STUDENT + "/" + user.getString("section") + "/" + user.getString("groupe"), null, new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                callback.onDataRecieved(response);
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
        App.getInstance().addToRequestQueue(jsonReq);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) CustomRequest(dz.easy.androidclient.Util.CustomRequest)

Example 23 with Response

use of com.android.volley.Response in project easy by MehdiBenmesa.

the class StartActivity method handleSignInResult.

// [END onActivityResult]
//1D:80:89:02:65:1A:38:03:60:08:D1:38:24:EA:CA:C0:F9:59:48:AC
// [START handleSignInResult]
private void handleSignInResult(GoogleSignInResult result) {
    Log.d(TAG, "handleSignInResult:" + result.isSuccess());
    if (result.isSuccess()) {
        // Signed in successfully, show authenticated UI.
        GoogleSignInAccount acct = result.getSignInAccount();
        updateUI(true);
        App.getInstance().setAccessToken(acct.getIdToken());
        App.getInstance().setEmail(acct.getEmail());
        if (acct.getEmail().substring(acct.getEmail().length() - 6, acct.getEmail().length()).equals("esi.dz")) {
            CustomRequest jsonReq = new CustomRequest(Request.Method.POST, APP_LOGIN, null, new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    try {
                        JSONObject user = response.getJSONObject("user");
                        Log.i(TAG, "Signed in as: " + user.getString("name"));
                        //JSONArray resp = responseBody.to;
                        if (user.getString("mail").equals(App.getInstance().getEmail())) {
                            startUserActivity(user);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {

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

                @Override
                protected Map<String, String> getParams() {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("email", App.getInstance().getEmail());
                    params.put("idToken", App.getInstance().getAccessToken());
                    return params;
                }
            };
            App.getInstance().addToRequestQueue(jsonReq);
        } else {
            String msg = "c'est pas un compte ESI ";
            Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
        }
    } else {
        // Signed out, show unauthenticated UI.
        updateUI(false);
    }
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) JSONException(org.json.JSONException) CustomRequest(dz.easy.androidclient.Util.CustomRequest)

Example 24 with Response

use of com.android.volley.Response in project saga-android by AnandChowdhary.

the class Updater method checkForUpdates.

public static void checkForUpdates(final Context context, boolean visibility) {
    final int versionCode = getVersionCode(context);
    final ProgressDialog progressDialog = new ProgressDialog(context);
    String updateUrl = "https://www.dropbox.com/s/bka9o3p43oki217/saga.json?raw=1";
    if (visibility) {
        progressDialog.setTitle(context.getString(R.string.update));
        progressDialog.setMessage(context.getString(R.string.update_checking));
        progressDialog.setCancelable(true);
        progressDialog.show();
    }
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, updateUrl, null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            try {
                int updateVersionCode = response.getInt("versionCode");
                if (updateVersionCode > versionCode && versionCode != 0) {
                    if (progressDialog.isShowing()) {
                        progressDialog.cancel();
                    }
                    final String apkUrl = response.getString("apkUrl");
                    String changelog = response.getString("changelog");
                    AlertDialog dialog = new AlertDialog.Builder(context).setTitle(context.getString(R.string.new_update)).setMessage(changelog).setPositiveButton(context.getString(R.string.update_now), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            File myFile = new File(Utils.getStoragePath(context), "update.apk");
                            if (myFile.exists())
                                myFile.delete();
                            Uri uri = Uri.parse(apkUrl);
                            DownloadManager dMgr = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
                            DownloadManager.Request dr = new DownloadManager.Request(uri);
                            String filename = "update.apk";
                            dr.setTitle(context.getString(R.string.app_name) + " " + context.getString(R.string.update));
                            dr.setDestinationUri(Uri.fromFile(new File(Utils.getStoragePath(context) + "/" + filename)));
                            //                                        dr.setDestinationInExternalPublicDir("/Saga/", filename);
                            dMgr.enqueue(dr);
                        }
                    }).setNegativeButton(context.getString(R.string.cancel), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    }).setCancelable(false).create();
                    dialog.show();
                } else {
                    if (progressDialog.isShowing()) {
                        progressDialog.cancel();
                        Toast.makeText(context, context.getString(R.string.no_update), Toast.LENGTH_SHORT).show();
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            if (progressDialog.isShowing()) {
                progressDialog.cancel();
                Toast.makeText(context, context.getString(R.string.error_connect), Toast.LENGTH_SHORT).show();
            }
        }
    });
    request.setShouldCache(false);
    VolleySingleton.getInstance(context).getRequestQueue().add(request);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) VolleyError(com.android.volley.VolleyError) DialogInterface(android.content.DialogInterface) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) Request(com.android.volley.Request) JSONException(org.json.JSONException) ProgressDialog(android.app.ProgressDialog) Uri(android.net.Uri) DownloadManager(android.app.DownloadManager) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) File(java.io.File)

Example 25 with Response

use of com.android.volley.Response in project saga-android by AnandChowdhary.

the class MusicDownloader method getSongInfo.

private static void getSongInfo(final Context context, final String filename, final String songName, final String artistName) {
    String url = "http://162.243.144.151/everything.php?q=";
    url += artistName == null ? filename.replace(" ", "%20") : songName.replace(" ", "%20");
    StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            if (artistName != null) {
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    jsonObject.put("track", songName);
                    jsonObject.put("artist", artistName);
                    Utils.saveSongInfo(context, filename, jsonObject.toString());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else {
                Utils.saveSongInfo(context, filename, response);
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d("Music download", "Error: " + error.toString());
            if (artistName != null) {
                JSONObject jsonObject = new JSONObject();
                try {
                    jsonObject.put("track", songName);
                    jsonObject.put("artist", artistName);
                    Utils.saveSongInfo(context, filename, jsonObject.toString());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    request.setShouldCache(false);
    VolleySingleton.getInstance(context).getRequestQueue().add(request);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) StringRequest(com.android.volley.toolbox.StringRequest) JSONException(org.json.JSONException)

Aggregations

Response (com.android.volley.Response)110 VolleyError (com.android.volley.VolleyError)108 JSONObject (org.json.JSONObject)80 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)60 RequestQueue (com.android.volley.RequestQueue)58 HashMap (java.util.HashMap)57 JSONException (org.json.JSONException)57 User (model.User)49 JSONArray (org.json.JSONArray)29 CustomRequestArray (dz.easy.androidclient.Util.CustomRequestArray)18 Context (android.content.Context)17 Toast (android.widget.Toast)17 StringRequest (com.android.volley.toolbox.StringRequest)14 TextView (android.widget.TextView)9 CustomRequest (dz.easy.androidclient.Util.CustomRequest)9 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 Intent (android.content.Intent)6 GridLayoutManager (android.support.v7.widget.GridLayoutManager)6 JsonArrayRequest (com.android.volley.toolbox.JsonArrayRequest)6 MaterialViewPagerHeaderDecorator (com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator)5