Java Code Examples for com.loopj.android.http.AsyncHttpClient#get()

The following examples show how to use com.loopj.android.http.AsyncHttpClient#get() . 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: ListFragment.java    From ListItemFold with MIT License 6 votes vote down vote up
private void loadData() {
    AsyncHttpClient client = new AsyncHttpClient();

    client.get(getActivity(), "https://moment.douban.com/api/stream/date/2015-06-09", new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);
            if (response != null) {
                final JSONArray posts = response.optJSONArray("posts");
                int length = posts.length();
                List<SimpleData> resultDatas = new ArrayList<SimpleData>(length);
                for (int i = 0; i < length; i++) {
                    JSONObject obj = posts.optJSONObject(i);
                    SimpleData data = new SimpleData();
                    data.content = obj.optString("abstract");
                    data.title = obj.optString("title");
                    data.url = obj.optString("url");
                    JSONArray thumbs = obj.optJSONArray("thumbs");
                    if (thumbs.length() > 0) {
                        JSONObject thumb = thumbs.optJSONObject(0);
                        thumb = thumb.optJSONObject("large");
                        if (thumb != null) {
                            data.picUrl = thumb.optString("url");
                            resultDatas.add(data);
                        }
                    }
                }
                mAdapter.addAll(resultDatas);
            }
        }
    });
}
 
Example 2
Source File: RecyclerFragment.java    From ListItemFold with MIT License 6 votes vote down vote up
private void loadData() {
    AsyncHttpClient client = new AsyncHttpClient();

    client.get(getActivity(), "https://moment.douban.com/api/stream/date/2015-06-09", new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);
            if (response != null) {
                final JSONArray posts = response.optJSONArray("posts");
                int length = posts.length();
                List<SimpleData> resultDatas = new ArrayList<SimpleData>(length);
                for (int i = 0; i < length; i++) {
                    JSONObject obj = posts.optJSONObject(i);
                    SimpleData data = new SimpleData();
                    data.content = obj.optString("abstract");
                    data.title = obj.optString("title");
                    data.url = obj.optString("url");
                    JSONArray thumbs = obj.optJSONArray("thumbs");
                    if (thumbs.length() > 0) {
                        JSONObject thumb = thumbs.optJSONObject(0);
                        thumb = thumb.optJSONObject("large");
                        if (thumb != null) {
                            data.picUrl = thumb.optString("url");
                            resultDatas.add(data);
                        }
                    }
                }
                mAdapter.addAll(resultDatas);
            }
        }
    });
}
 
Example 3
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Perform a HTTP GET request with cookie which generate by own context
 *
 * @param context
 * @param url
 * @param responseHandler
 */
public static void getWithCookie(Context context, String url, AsyncHttpResponseHandler responseHandler) {
    AsyncHttpClient client = new AsyncHttpClient();
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    //  myCookieStore.clear();
    client.setCookieStore(myCookieStore);
    client.get(getAbsoluteUrl(url), responseHandler);

}
 
Example 4
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Perform a HTTP GET request with cookies which are defined in hashmap
 *
 * @param context
 * @param url
 * @param hashMap
 * @param responseHandler
 */
public static void getUseCookie(Context context, String url, HashMap hashMap, AsyncHttpResponseHandler responseHandler) {
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    if (BasicUtils.judgeNotNull(hashMap)) {
        Iterator iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            Cookie cookie = new BasicClientCookie(key.toString(), value.toString());
            myCookieStore.addCookie(cookie);
        }
    }
    AsyncHttpClient client = new AsyncHttpClient();
    client.setCookieStore(myCookieStore);
    client.get(getAbsoluteUrl(url), responseHandler);
}
 
Example 5
Source File: FlowAsyncClient.java    From flow-android with MIT License 6 votes vote down vote up
public static void get(HashMap<String, String> headers, String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
    final AsyncHttpClient specialClient = new AsyncHttpClient();

    for (String key : headers.keySet()) {
        specialClient.addHeader(key, headers.get(key));
    }
    specialClient.get(getAbsoluteUrl(url), params, responseHandler);
}
 
Example 6
Source File: ImageLoadActivity.java    From android-opensource-library-56 with Apache License 2.0 6 votes vote down vote up
private void startLoad() {
    AsyncHttpClient client = new AsyncHttpClient();

    client.get(
            "http://farm3.staticflickr.com/2004/2249945112_caa85476ef_o.jpg",
            new BinaryHttpResponseHandler() {
                @Override
                public void onSuccess(byte[] binaryData) {
                    Log.d(TAG, "onSuccess");
                    Bitmap bitmap = BitmapFactory.decodeByteArray(
                            binaryData, 0, binaryData.length);
                    ImageView imageView = ((ImageView) findViewById(R.id.image));
                    imageView.setImageBitmap(bitmap);
                    imageView.setVisibility(View.VISIBLE);
                    findViewById(R.id.progress).setVisibility(View.GONE);
                }

                @Override
                public void onFailure(Throwable error, String content) {
                    error.printStackTrace();
                    Log.d(TAG, "onFailure");
                }
            });

    RequestParams param = new RequestParams();
    param.put("hpge", "fuga");

}
 
Example 7
Source File: ApiConnector.java    From AnimeTaste with MIT License 4 votes vote down vote up
private void get(String request, JsonHttpResponseHandler handler) {
	AsyncHttpClient client = new AsyncHttpClient();
       client.setTimeout(10000);
	client.get(request, null, handler);
}
 
Example 8
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 3 votes vote down vote up
/**
 * Perform a HTTP GET request with cookie which generate by own context
 *
 * @param context
 * @param url
 * @param responseHandler
 */
public static void getWithCookie(Context context, String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
    AsyncHttpClient client = new AsyncHttpClient();
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    client.setCookieStore(myCookieStore);
    client.get(getAbsoluteUrl(url), params, responseHandler);
}