com.androidnetworking.common.Priority Java Examples

The following examples show how to use com.androidnetworking.common.Priority. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseActivity.java    From EasyVPN-Free with GNU General Public License v3.0 4 votes vote down vote up
protected void getIpInfo(final List<Server> serverList) {
    JSONArray jsonArray = new JSONArray();

    for (Server server : serverList) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("query", server.getIp());
            jsonObject.put("lang", Locale.getDefault().getLanguage());

            jsonArray.put(jsonObject);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    AndroidNetworking.post(getString(R.string.url_check_ip_batch))
            .addJSONArrayBody(jsonArray)
            .setTag("getIpInfo")
            .setPriority(Priority.MEDIUM)
            .build()
            .getAsJSONArray(new JSONArrayRequestListener() {
                @Override
                public void onResponse(JSONArray response) {
                    if (dbHelper.setIpInfo(response, serverList))
                        ipInfoResult();
                }
                @Override
                public void onError(ANError error) {

                }
            });
}
 
Example #2
Source File: MainActivity.java    From API-Calling-Flow with Apache License 2.0 3 votes vote down vote up
private void requestTestApi() {
    //TODO Step 1: Get reference to root layout of Activity or Fragment.
    RelativeLayout parentLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
    /*
     * TODO Step 2: Initialize ApiCallingFlow
     * 1st parameter - context
     * 2nd parameter - parentLayout from step 1
     * 3rd parameter - isTransparent (if you want background color to be transparent then 'true' else for default white background 'false')
     */
    final ApiCallingFlow apiCallingFlow = new ApiCallingFlow(this, parentLayout, false) {
        @Override
        public void callCurrentApiHere() {
            //TODO Step 3: Pass function to call current API
            requestTestApi();
        }
    };
    //TODO Step 4: Get current Network state ( apiCallingFlow.getNetworkState() ) and request API accordingly.
    if (apiCallingFlow.getNetworkState()) {
        AndroidNetworking.get("https://jsonplaceholder.typicode.com/posts/1")
                .setPriority(Priority.HIGH)
                .setTag("requestTestApi")
                .build()
                .getAsJSONObject(new JSONObjectRequestListener() {
                    @Override
                    public void onResponse(JSONObject response) {
                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                ((TextView) findViewById(R.id.tvDummyView)).setText(getString(R.string.valid_text));
                                //TODO Step 5: Call ( apiCallingFlow.onSuccessResponse(); ) after API is successful
                                apiCallingFlow.onSuccessResponse();
                            }
                        }, 5000);
                    }

                    @Override
                    public void onError(ANError anError) {
                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                //TODO Step 6: Call ( apiCallingFlow.onErrorResponse(); ) after API is failed
                                apiCallingFlow.onErrorResponse();
                            }
                        }, 5000);
                    }
                });
    }
}