Example usage for android.os Looper myLooper

List of usage examples for android.os Looper myLooper

Introduction

In this page you can find the example usage for android.os Looper myLooper.

Prototype

public static @Nullable Looper myLooper() 

Source Link

Document

Return the Looper object associated with the current thread.

Usage

From source file:com.networking.ApiTestActivity.java

public void disableGzipForCustomRequest(View view) {
    AndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER)
            .addBodyParameter("firstname", "Amit").addBodyParameter("lastname", "Shekhar").setTag(this)
            .setOkHttpClient(new OkHttpClient()).setPriority(Priority.LOW).build()
            .setAnalyticsListener(new AnalyticsListener() {
                @Override//from w w  w  .j  a v a2  s.  c om
                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);
                }
            }).getAsJSONObject(new JSONObjectRequestListener() {
                @Override
                public void onResponse(JSONObject response) {
                    Log.d(TAG, "onResponse object : " + 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.actionbarsherlock.internal.nineoldandroids.animation.ValueAnimator.java

/**
 * Start the animation playing. This version of start() takes a boolean flag that indicates
 * whether the animation should play in reverse. The flag is usually false, but may be set
 * to true if called from the reverse() method.
 *
 * <p>The animation started by calling this method will be run on the thread that called
 * this method. This thread should have a Looper on it (a runtime exception will be thrown if
 * this is not the case). Also, if the animation will animate
 * properties of objects in the view hierarchy, then the calling thread should be the UI
 * thread for that view hierarchy.</p>
 *
 * @param playBackwards Whether the ValueAnimator should start playing in reverse.
 *//*w ww. j  a  v a 2  s.  c  om*/
private void start(boolean playBackwards) {
    if (Looper.myLooper() == null) {
        throw new AndroidRuntimeException("Animators may only be run on Looper threads");
    }
    mPlayingBackwards = playBackwards;
    mCurrentIteration = 0;
    mPlayingState = STOPPED;
    mStarted = true;
    mStartedDelay = false;
    sPendingAnimations.get().add(this);
    if (mStartDelay == 0) {
        // This sets the initial value of the animation, prior to actually starting it running
        setCurrentPlayTime(getCurrentPlayTime());
        mPlayingState = STOPPED;
        mRunning = true;

        if (mListeners != null) {
            ArrayList<AnimatorListener> tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone();
            int numListeners = tmpListeners.size();
            for (int i = 0; i < numListeners; ++i) {
                tmpListeners.get(i).onAnimationStart(this);
            }
        }
    }
    AnimationHandler animationHandler = sAnimationHandler.get();
    if (animationHandler == null) {
        animationHandler = new AnimationHandler();
        sAnimationHandler.set(animationHandler);
    }
    animationHandler.sendEmptyMessage(ANIMATION_START);
}

From source file:com.networking.ApiTestActivity.java

public void checkCacheForCustomClient(View view) {
    String url = "http://www.colorado.edu/conflict/peace/download/peace_problem.ZIP";
    AndroidNetworking.download(url, Utils.getRootDirPath(getApplicationContext()), "file1.zip")
            .setPriority(Priority.HIGH).setTag(this).setOkHttpClient(new OkHttpClient()).build()
            .setAnalyticsListener(new AnalyticsListener() {
                @Override/* w  w  w. jav a  2 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);
                }
            }).setDownloadProgressListener(new DownloadProgressListener() {
                @Override
                public void onProgress(long bytesDownloaded, long totalBytes) {
                    Log.d(TAG, "bytesDownloaded : " + bytesDownloaded + " totalBytes : " + totalBytes);
                    Log.d(TAG, "setDownloadProgressListener isMainThread : "
                            + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
                }
            }).startDownload(new DownloadListener() {
                @Override
                public void onDownloadComplete() {
                    Log.d(TAG, "File download Completed");
                    Log.d(TAG, "onDownloadComplete 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 an 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.android.mail.ui.AnimatedAdapter.java

@Override
public void notifyDataSetChanged() {
    // This may be a temporary catch for a problem, or we may leave it here.
    // b/9527863//w ww  . ja v  a  2s  . com
    if (Looper.getMainLooper() != Looper.myLooper()) {
        LogUtils.wtf(LOG_TAG, "notifyDataSetChanged() called off the main thread");
    }

    updateSpecialViews();
    super.notifyDataSetChanged();
}

From source file:com.networking.OkHttpResponseTestActivity.java

public void checkOkHttpResponse(View view) {

    AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY).addPathParameter("pageNumber", "0")
            .addQueryParameter("limit", "3").setTag(this).setPriority(Priority.LOW).build()
            .setAnalyticsListener(new AnalyticsListener() {
                @Override//from   w ww  . j av 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);
                }
            }).getAsOkHttpResponse(new OkHttpResponseListener() {
                @Override
                public void onResponse(Response response) {
                    if (response != null) {
                        if (response.isSuccessful()) {
                            Log.d(TAG, "response is successful");
                            try {
                                Log.d(TAG, "response : " + response.body().source().readUtf8());
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        } else {
                            Log.d(TAG, "response is not successful");
                        }
                    } else {
                        Log.d(TAG, "response is null");
                    }
                }

                @Override
                public void onError(ANError anError) {
                    Utils.logError(TAG, anError);
                }
            });

    AndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER)
            .addBodyParameter("firstname", "Suman").addBodyParameter("lastname", "Shekhar").setTag(this)
            .setPriority(Priority.LOW).build().setAnalyticsListener(new AnalyticsListener() {
                @Override
                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);
                }
            }).getAsOkHttpResponse(new OkHttpResponseListener() {
                @Override
                public void onResponse(Response response) {
                    if (response != null) {
                        if (response.isSuccessful()) {
                            Log.d(TAG, "response is successful");
                            try {
                                Log.d(TAG, "response : " + response.body().source().readUtf8());
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        } else {
                            Log.d(TAG, "response is not successful");
                        }
                    } else {
                        Log.d(TAG, "response is null");
                    }
                }

                @Override
                public void onError(ANError anError) {
                    Utils.logError(TAG, anError);
                }
            });

    AndroidNetworking.upload(ApiEndPoint.BASE_URL + ApiEndPoint.UPLOAD_IMAGE).setPriority(Priority.MEDIUM)
            .addMultipartFile("image",
                    new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "test.png"))
            .setTag(this).build().setAnalyticsListener(new AnalyticsListener() {
                @Override
                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);
                }
            }).setUploadProgressListener(new UploadProgressListener() {
                @Override
                public void onProgress(long bytesUploaded, long totalBytes) {
                    Log.d(TAG, "bytesUploaded : " + bytesUploaded + " totalBytes : " + totalBytes);
                    Log.d(TAG, "setUploadProgressListener isMainThread : "
                            + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
                }
            }).getAsOkHttpResponse(new OkHttpResponseListener() {
                @Override
                public void onResponse(Response response) {
                    if (response != null) {
                        if (response.isSuccessful()) {
                            Log.d(TAG, "response is successful");
                            try {
                                Log.d(TAG, "response : " + response.body().source().readUtf8());
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        } else {
                            Log.d(TAG, "response is not successful");
                        }
                    } else {
                        Log.d(TAG, "response is null");
                    }
                }

                @Override
                public void onError(ANError anError) {
                    Utils.logError(TAG, anError);
                }
            });
}

From source file:io.requery.android.database.sqlite.SQLiteConnection.java

private void applyBlockGuardPolicy(PreparedStatement statement) {
    if (!mConfiguration.isInMemoryDb() && SQLiteDebug.DEBUG_SQL_LOG) {
        // don't have access to the policy, so just log
        if (Looper.myLooper() == Looper.getMainLooper()) {
            if (statement.mReadOnly) {
                Log.w(TAG, "Reading from disk on main thread");
            } else {
                Log.w(TAG, "Writing to disk on main thread");
            }/*  w w  w  . j a v a 2  s.  c om*/
        }
    }
}

From source file:com.networking.OkHttpResponseTestActivity.java

public void checkSynchronousCall(View view) {
    new Thread(new Runnable() {
        @Override/*ww  w.  jav  a2  s. c om*/
        public void run() {

            String url = "http://www.colorado.edu/conflict/peace/download/peace_problem.ZIP";
            ANRequest requestOne = AndroidNetworking
                    .download(url, Utils.getRootDirPath(getApplicationContext()), "file1.zip")
                    .setPriority(Priority.HIGH).setTag(this).build()
                    .setAnalyticsListener(new AnalyticsListener() {
                        @Override
                        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);
                        }
                    }).setDownloadProgressListener(new DownloadProgressListener() {
                        @Override
                        public void onProgress(long bytesDownloaded, long totalBytes) {
                            Log.d(TAG, "bytesDownloaded : " + bytesDownloaded + " totalBytes : " + totalBytes);
                            Log.d(TAG, "setDownloadProgressListener isMainThread : "
                                    + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));

                        }
                    });
            ANResponse<String> responseOne = requestOne.executeForDownload();

            if (responseOne.isSuccess()) {
                Log.d(TAG, "checkSynchronousCall : download success");
                Log.d(TAG, "checkSynchronousCall : download result " + responseOne.getResult());
                Response response = responseOne.getOkHttpResponse();
                Log.d(TAG, "checkSynchronousCall : headers : " + response.headers().toString());
            } else {
                Log.d(TAG, "checkSynchronousCall : download failed");
                Utils.logError(TAG, responseOne.getError());
            }

            ANRequest requestTwo = AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY)
                    .addPathParameter("pageNumber", "0").addQueryParameter("limit", "3").setTag(this)
                    .setPriority(Priority.LOW).build().setAnalyticsListener(new AnalyticsListener() {
                        @Override
                        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);
                        }
                    });
            ANResponse<List<User>> responseTwo = requestTwo.executeForParsed(new TypeToken<List<User>>() {
            });

            if (responseTwo.isSuccess()) {
                Log.d(TAG, "checkSynchronousCall : response success");
                List<User> users = responseTwo.getResult();
                Log.d(TAG, "userList size : " + users.size());
                for (User user : users) {
                    Log.d(TAG, "id : " + user.id);
                    Log.d(TAG, "firstname : " + user.firstname);
                    Log.d(TAG, "lastname : " + user.lastname);
                }
                Response response = responseTwo.getOkHttpResponse();
                Log.d(TAG, "checkSynchronousCall : headers : " + response.headers().toString());
            } else {
                Log.d(TAG, "checkSynchronousCall : response failed");
                Utils.logError(TAG, responseTwo.getError());
            }

            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put("firstname", "Rohit");
                jsonObject.put("lastname", "Kumar");
            } catch (JSONException e) {
                e.printStackTrace();
            }

            ANRequest requestThree = AndroidNetworking
                    .post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER).addJSONObjectBody(jsonObject)
                    .setTag(this).setPriority(Priority.LOW).build()
                    .setAnalyticsListener(new AnalyticsListener() {
                        @Override
                        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);
                        }
                    });
            ANResponse<JSONObject> responseThree = requestThree.executeForJSONObject();

            if (responseThree.isSuccess()) {
                Log.d(TAG, "checkSynchronousCall : jsonObjectANResponse success");
                JSONObject jsonObjectFinal = responseThree.getResult();
                Log.d(TAG, "checkSynchronousCall : jsonObjectANResponse result " + jsonObjectFinal.toString());
                Response response = responseThree.getOkHttpResponse();
                Log.d(TAG, "checkSynchronousCall : headers : " + response.headers().toString());
            } else {
                Log.d(TAG, "checkSynchronousCall : jsonObjectANResponse failed");
                Utils.logError(TAG, responseThree.getError());
            }

            ANRequest requestFour = AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY)
                    .addPathParameter("pageNumber", "0").addQueryParameter("limit", "3").setTag(this)
                    .setPriority(Priority.LOW).build().setAnalyticsListener(new AnalyticsListener() {
                        @Override
                        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);
                        }
                    });
            ANResponse<Response> responseFour = requestFour.executeForOkHttpResponse();

            if (responseFour.isSuccess()) {
                Log.d(TAG, "checkSynchronousCall : okHttpResponse success");
                Response okHttpResponse = responseFour.getResult();
                if (okHttpResponse != null) {
                    if (okHttpResponse.isSuccessful()) {
                        Log.d(TAG, "response is successful");
                        try {
                            Log.d(TAG, "response : " + okHttpResponse.body().source().readUtf8());
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    } else {
                        Log.d(TAG, "response is not successful");
                    }
                } else {
                    Log.d(TAG, "response is null");
                }
            } else {
                Log.d(TAG, "checkSynchronousCall : okHttpResponse failed");
                Utils.logError(TAG, responseFour.getError());
            }
        }
    }).start();
}

From source file:com.taobao.weex.bridge.WXBridgeManager.java

private boolean checkMainThread() {
    return Looper.myLooper() == Looper.getMainLooper();
}

From source file:dev.ukanth.ufirewall.Api.java

/**
 * Runs a script as root (multiple commands separated by "\n")
* @param ctx mandatory context/*from  ww  w . j  a  v  a 2 s . c om*/
 * @param script the script to be executed
 * @param res the script output response (stdout + stderr)
 * @return the script exit code
 * @throws IOException on any error executing the script, or writing it to disk
 */
public static int runScriptAsRoot(Context ctx, List<String> script, StringBuilder res) throws IOException {
    int returnCode = -1;

    if ((Looper.myLooper() != null) && (Looper.myLooper() == Looper.getMainLooper())) {
        Log.e(TAG, "runScriptAsRoot should not be called from the main thread\nCall Trace:\n");
        for (StackTraceElement e : new Throwable().getStackTrace()) {
            Log.e(TAG, e.toString());
        }
    }

    try {
        returnCode = new RunCommand().execute(script, res, ctx).get();
    } catch (RejectedExecutionException r) {
        Log.e(TAG, "runScript failed: " + r.getLocalizedMessage());
    } catch (InterruptedException e) {
        Log.e(TAG, "Caught InterruptedException");
    } catch (ExecutionException e) {
        Log.e(TAG, "runScript failed: " + e.getLocalizedMessage());
    } catch (Exception e) {
        Log.e(TAG, "runScript failed: " + e.getLocalizedMessage());
    }

    return returnCode;
}

From source file:com.tct.mail.ui.AnimatedAdapter.java

@Override
public void notifyDataSetChanged() {
    // This may be a temporary catch for a problem, or we may leave it here.
    // b/9527863//  ww w .  ja v a  2s .  c o  m
    if (Looper.getMainLooper() != Looper.myLooper()) {
        LogUtils.wtf(LOG_TAG, "notifyDataSetChanged() called off the main thread");
    }

    //TS: tao.gan 2015-10-13 EMAIL FEATURE-559893 ADD_S
    if (getCount() - mCount < 0) {
        //If the count is decreased, we show the action bar,in case of some UI problem
        LogUtils.i(LogUtils.TAG, "The count is decreases, show the action bar");
        mListView.animateShowBar();
    }
    mCount = getCount();
    //TS: tao.gan 2015-10-13 EMAIL FEATURE-559893 ADD_E
    updateSpecialViews();
    super.notifyDataSetChanged();
}