List of usage examples for android.os Looper myLooper
public static @Nullable Looper myLooper()
From source file:com.just.agentweb.AgentWebUtils.java
public static boolean isUIThread() { return Looper.myLooper() == Looper.getMainLooper(); }
From source file:com.networking.ApiTestActivity.java
public void doNotCacheResponse(View view) { AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY).addPathParameter("pageNumber", "0") .addQueryParameter("limit", "3").setTag(this).setPriority(Priority.LOW).doNotCacheResponse().build() .setAnalyticsListener(new AnalyticsListener() { @Override//from w w w . ja va 2 s. co m public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) { Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis); Log.d(TAG, " bytesSent : " + bytesSent); Log.d(TAG, " bytesReceived : " + bytesReceived); Log.d(TAG, " isFromCache : " + isFromCache); } }).getAsJSONArray(new JSONArrayRequestListener() { @Override public void onResponse(JSONArray response) { Log.d(TAG, "onResponse array : " + response.toString()); Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper())); } @Override public void onError(ANError error) { if (error.getErrorCode() != 0) { // received ANError from server // error.getErrorCode() - the ANError code from server // error.getErrorBody() - the ANError body from server // error.getErrorDetail() - just a ANError detail Log.d(TAG, "onError errorCode : " + error.getErrorCode()); Log.d(TAG, "onError errorBody : " + error.getErrorBody()); Log.d(TAG, "onError errorDetail : " + error.getErrorDetail()); } else { // error.getErrorDetail() : connectionError, parseError, requestCancelledError Log.d(TAG, "onError errorDetail : " + error.getErrorDetail()); } } }); }
From source file:com.networking.OkHttpResponseTestActivity.java
public void getResponseOnlyIfCached(View view) { AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY).addPathParameter("pageNumber", "0") .addQueryParameter("limit", "3").setTag(this).setPriority(Priority.LOW).getResponseOnlyIfCached() .build().setAnalyticsListener(new AnalyticsListener() { @Override//from w ww .j a v a2 s . c o m public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) { Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis); Log.d(TAG, " bytesSent : " + bytesSent); Log.d(TAG, " bytesReceived : " + bytesReceived); Log.d(TAG, " isFromCache : " + isFromCache); } }).getAsOkHttpResponseAndJSONArray(new OkHttpResponseAndJSONArrayRequestListener() { @Override public void onResponse(Response okHttpResponse, JSONArray response) { Log.d(TAG, "onResponse object : " + response.toString()); Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper())); if (okHttpResponse.isSuccessful()) { Log.d(TAG, "onResponse success headers : " + okHttpResponse.headers().toString()); } else { Log.d(TAG, "onResponse not success headers : " + okHttpResponse.headers().toString()); } } @Override public void onError(ANError anError) { Utils.logError(TAG, anError); } }); }
From source file:com.android.yijiang.kzx.http.AsyncHttpClient.java
/** * Cancels any pending (or potentially active) requests associated with the passed Context. * <p> </p> <b>Note:</b> This will only affect requests which were created with a non-null * android Context. This method is intended to be used in the onDestroy method of your android * activities to destroy all requests which are no longer required. * * @param context the android Context instance associated to the request. * @param mayInterruptIfRunning specifies if active requests should be cancelled along with * pending requests. *//*from w ww. ja v a 2s. c o m*/ public void cancelRequests(final Context context, final boolean mayInterruptIfRunning) { if (context == null) { Log.e(LOG_TAG, "Passed null Context to cancelRequests"); return; } Runnable r = new Runnable() { @Override public void run() { List<RequestHandle> requestList = requestMap.get(context); if (requestList != null) { for (RequestHandle requestHandle : requestList) { requestHandle.cancel(mayInterruptIfRunning); } requestMap.remove(context); } } }; if (Looper.myLooper() == Looper.getMainLooper()) { new Thread(r).start(); } else { r.run(); } }
From source file:com.networking.ApiTestActivity.java
public void getResponseOnlyIfCached(View view) { AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY).addPathParameter("pageNumber", "0") .addQueryParameter("limit", "3").setTag(this).setPriority(Priority.LOW).getResponseOnlyIfCached() .build().setAnalyticsListener(new AnalyticsListener() { @Override//from w ww.java 2s. c o m public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) { Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis); Log.d(TAG, " bytesSent : " + bytesSent); Log.d(TAG, " bytesReceived : " + bytesReceived); Log.d(TAG, " isFromCache : " + isFromCache); } }).getAsJSONArray(new JSONArrayRequestListener() { @Override public void onResponse(JSONArray response) { Log.d(TAG, "onResponse array : " + response.toString()); Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper())); } @Override public void onError(ANError error) { if (error.getErrorCode() != 0) { // received ANError from server // error.getErrorCode() - the ANError code from server // error.getErrorBody() - the ANError body from server // error.getErrorDetail() - just a ANError detail Log.d(TAG, "onError errorCode : " + error.getErrorCode()); Log.d(TAG, "onError errorBody : " + error.getErrorBody()); Log.d(TAG, "onError errorDetail : " + error.getErrorDetail()); } else { // error.getErrorDetail() : connectionError, parseError, requestCancelledError Log.d(TAG, "onError errorDetail : " + error.getErrorDetail()); } } }); }
From source file:com.networking.OkHttpResponseTestActivity.java
public void getResponseOnlyFromNetwork(View view) { AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY).addPathParameter("pageNumber", "0") .addQueryParameter("limit", "3").setTag(this).setPriority(Priority.LOW).getResponseOnlyFromNetwork() .build().setAnalyticsListener(new AnalyticsListener() { @Override/*from w w w. j ava 2 s . co m*/ public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) { Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis); Log.d(TAG, " bytesSent : " + bytesSent); Log.d(TAG, " bytesReceived : " + bytesReceived); Log.d(TAG, " isFromCache : " + isFromCache); } }).getAsOkHttpResponseAndJSONArray(new OkHttpResponseAndJSONArrayRequestListener() { @Override public void onResponse(Response okHttpResponse, JSONArray response) { Log.d(TAG, "onResponse object : " + response.toString()); Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper())); if (okHttpResponse.isSuccessful()) { Log.d(TAG, "onResponse success headers : " + okHttpResponse.headers().toString()); } else { Log.d(TAG, "onResponse not success headers : " + okHttpResponse.headers().toString()); } } @Override public void onError(ANError anError) { Utils.logError(TAG, anError); } }); }
From source file:com.yunmall.ymsdk.net.http.AsyncHttpClient.java
/** * Cancels any pending (or potentially active) requests associated with the passed Context. * <p> </p> <b>Note:</b> This will only affect requests which were created with a non-null * android Context. This method is intended to be used in the onDestroy method of your android * activities to destroy all requests which are no longer required. * * @param context the android Context instance associated to the request. * @param mayInterruptIfRunning specifies if active requests should be cancelled along with * pending requests. *//*from ww w .j a v a 2s . c o m*/ public void cancelRequests(final Context context, final boolean mayInterruptIfRunning) { if (context == null) { YmLog.e(LOG_TAG, "Passed null Context to cancelRequests"); return; } Runnable r = new Runnable() { @Override public void run() { List<RequestHandle> requestList = requestMap.get(context); if (requestList != null) { for (RequestHandle requestHandle : requestList) { requestHandle.cancel(mayInterruptIfRunning); } requestMap.remove(context); } } }; if (Looper.myLooper() == Looper.getMainLooper()) { new Thread(r).start(); } else { r.run(); } }
From source file:com.networking.ApiTestActivity.java
public void getResponseOnlyFromNetwork(View view) { AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY).addPathParameter("pageNumber", "0") .addQueryParameter("limit", "3").setTag(this).setPriority(Priority.LOW).getResponseOnlyFromNetwork() .build().setAnalyticsListener(new AnalyticsListener() { @Override/* www . ja va2 s . co m*/ public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) { Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis); Log.d(TAG, " bytesSent : " + bytesSent); Log.d(TAG, " bytesReceived : " + bytesReceived); Log.d(TAG, " isFromCache : " + isFromCache); } }).getAsJSONArray(new JSONArrayRequestListener() { @Override public void onResponse(JSONArray response) { Log.d(TAG, "onResponse array : " + response.toString()); Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper())); } @Override public void onError(ANError error) { if (error.getErrorCode() != 0) { // received ANError from server // error.getErrorCode() - the ANError code from server // error.getErrorBody() - the ANError body from server // error.getErrorDetail() - just a ANError detail Log.d(TAG, "onError errorCode : " + error.getErrorCode()); Log.d(TAG, "onError errorBody : " + error.getErrorBody()); Log.d(TAG, "onError errorDetail : " + error.getErrorDetail()); } else { // error.getErrorDetail() : connectionError, parseError, requestCancelledError Log.d(TAG, "onError errorDetail : " + error.getErrorDetail()); } } }); }
From source file:com.networking.OkHttpResponseTestActivity.java
public void setMaxAgeCacheControl(View view) { AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY).addPathParameter("pageNumber", "0") .addQueryParameter("limit", "3").setTag(this).setPriority(Priority.LOW) .setMaxAgeCacheControl(0, TimeUnit.SECONDS).build().setAnalyticsListener(new AnalyticsListener() { @Override/*from ww w . j a v a 2 s . co m*/ public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) { Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis); Log.d(TAG, " bytesSent : " + bytesSent); Log.d(TAG, " bytesReceived : " + bytesReceived); Log.d(TAG, " isFromCache : " + isFromCache); } }).getAsOkHttpResponseAndJSONArray(new OkHttpResponseAndJSONArrayRequestListener() { @Override public void onResponse(Response okHttpResponse, JSONArray response) { Log.d(TAG, "onResponse object : " + response.toString()); Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper())); if (okHttpResponse.isSuccessful()) { Log.d(TAG, "onResponse success headers : " + okHttpResponse.headers().toString()); } else { Log.d(TAG, "onResponse not success headers : " + okHttpResponse.headers().toString()); } } @Override public void onError(ANError anError) { Utils.logError(TAG, anError); } }); }
From source file:derson.com.httpsender.AsyncHttpClient.AsyncHttpClient.java
/** * Cancels any pending (or potentially active) requests associated with the passed Context. * <p> </p> <b>Note:</b> This will only affect requests which were created with a non-null * android Context. This method is intended to be used in the onDestroy method of your android * activities to destroy all requests which are no longer required. * * @param context the android Context instance associated to the request. * @param mayInterruptIfRunning specifies if active requests should be cancelled along with * pending requests. */// w w w . j ava 2 s . c om public void cancelRequests(final Context context, final boolean mayInterruptIfRunning) { if (context == null) { HPLog.e(LOG_TAG, "Passed null Context to cancelRequests"); return; } Runnable r = new Runnable() { @Override public void run() { List<RequestHandle> requestList = requestMap.get(context); if (requestList != null) { for (RequestHandle requestHandle : requestList) { requestHandle.cancel(mayInterruptIfRunning); } requestMap.remove(context); } } }; if (Looper.myLooper() == Looper.getMainLooper()) { new Thread(r).start(); } else { r.run(); } }