List of usage examples for android.os Looper myLooper
public static @Nullable Looper myLooper()
From source file:android.support.animation.DynamicAnimation.java
/** * Starts an animation. If the animation has already been started, no op. Note that calling * {@link #start()} will not immediately set the property value to start value of the animation. * The property values will be changed at each animation pulse, which happens before the draw * pass. As a result, the changes will be reflected in the next frame, the same as if the values * were set immediately. This method should only be called on main thread. * * @throws AndroidRuntimeException if this method is not called on the main thread *//*from ww w .j a v a 2s . com*/ public void start() { if (Looper.myLooper() != Looper.getMainLooper()) { throw new AndroidRuntimeException("Animations may only be started on the main thread"); } if (!mRunning) { startAnimationInternal(); } }
From source file:com.abiansoftware.lib.reader.AbianReaderData.java
public synchronized void addItem(AbianReaderItem newItem) { //Log.e(getClass().getName(), "Enter addItem"); if (Looper.myLooper() != Looper.getMainLooper()) { //Log.e(getClass().getName(), "not on main thread, adding to the new item vector"); m_newItemVector.add(newItem);//from w w w . j a v a 2 s . c o m } else { //Log.e(getClass().getName(), "on main thread, adding to the item vector"); m_itemVector.add(newItem); } //Log.e(getClass().getName(), "Leave addItem"); }
From source file:com.frostwire.android.gui.transfers.TransferManager.java
private void registerPreferencesChangeListener() { if (Looper.myLooper() == Looper.getMainLooper()) { Engine.instance().getThreadPool().execute(() -> ConfigurationManager.instance() .registerOnPreferenceChange(onSharedPreferenceChangeListener)); } else {//from ww w. ja v a 2s.c o m ConfigurationManager.instance().registerOnPreferenceChange(onSharedPreferenceChangeListener); } }
From source file:com.boko.vimusic.cache.ImageCache.java
private void waitUntilUnpaused() { synchronized (mPauseLock) { if (Looper.myLooper() != Looper.getMainLooper()) { while (mPauseDiskAccess) { try { mPauseLock.wait();// w w w .j a va 2s . co m } catch (InterruptedException e) { // ignored, we'll start waiting again } } } } }
From source file:com.networking.ApiTestActivity.java
public void downloadImage(final View view) { String url = "http://i.imgur.com/AtbX9iX.png"; AndroidNetworking.download(url, Utils.getRootDirPath(getApplicationContext()), "image1.png") .setPriority(Priority.MEDIUM).setTag(this).build().setAnalyticsListener(new AnalyticsListener() { @Override/*from w w w . j a va 2 s . com*/ 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); } }).startDownload(new DownloadListener() { @Override public void onDownloadComplete() { Log.d(TAG, "Image 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 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.abiansoftware.lib.reader.AbianReaderData.java
public synchronized void syncItems() { if (Looper.myLooper() == Looper.getMainLooper()) { if (m_newItemVector.size() > 0) { //Log.e(getClass().getName(), "Enter syncItems on main thread"); //Log.e(getClass().getName(), "on main thread adding vectors"); for (int i = 0; i < m_newItemVector.size(); i++) { m_itemVector.add(m_newItemVector.get(i)); }/* w ww .ja va2 s . com*/ m_newItemVector.clear(); //Log.e(getClass().getName(), "Exit syncItems"); } } else { Log.e(getClass().getName(), "syncItems not on main thread"); } }
From source file:android.support.animation.DynamicAnimation.java
/** * Cancels the on-going animation. If the animation hasn't started, no op. Note that this method * should only be called on main thread. * * @throws AndroidRuntimeException if this method is not called on the main thread *///from ww w.j a va 2 s . c om public void cancel() { if (Looper.myLooper() != Looper.getMainLooper()) { throw new AndroidRuntimeException("Animations may only be canceled on the main thread"); } if (mRunning) { endAnimationInternal(true); } }
From source file:com.frostwire.android.gui.transfers.TransferManager.java
private void unregisterPreferencesChangeListener() { if (Looper.myLooper() == Looper.getMainLooper()) { Engine.instance().getThreadPool().execute(() -> ConfigurationManager.instance() .unregisterOnPreferenceChange(onSharedPreferenceChangeListener)); } else {/* w w w .j av a2 s .c o m*/ ConfigurationManager.instance().unregisterOnPreferenceChange(onSharedPreferenceChangeListener); } }
From source file:com.example.android.wearable.runtimepermissions.MainWearActivity.java
private void logToUi(final String message) { boolean mainUiThread = (Looper.myLooper() == Looper.getMainLooper()); if (mainUiThread) { if (!message.isEmpty()) { Log.d(TAG, message);//from w ww . j a v a2 s .co m mOutputTextView.setText(message); } } else { runOnUiThread(new Runnable() { @Override public void run() { if (!message.isEmpty()) { Log.d(TAG, message); mOutputTextView.setText(message); } } }); } }
From source file:com.rxsampleapp.RxApiTestActivity.java
public void downloadImage(final View view) { String url = "http://i.imgur.com/AtbX9iX.png"; RxAndroidNetworking.download(url, Utils.getRootDirPath(getApplicationContext()), "image1.png").build() .setAnalyticsListener(new AnalyticsListener() { @Override/* w ww. jav a 2 s. com*/ 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); } }).getDownloadObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<String>() { @Override public void onCompleted() { Log.d(TAG, "File download Completed"); Log.d(TAG, "onDownloadComplete isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper())); } @Override public void onError(Throwable e) { if (e instanceof ANError) { ANError anError = (ANError) e; if (anError.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 : " + anError.getErrorCode()); Log.d(TAG, "onError errorBody : " + anError.getErrorBody()); Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail()); } else { // error.getErrorDetail() : connectionError, parseError, requestCancelledError Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail()); } } else { Log.d(TAG, "onError errorMessage : " + e.getMessage()); } } @Override public void onNext(String s) { Log.d(TAG, "onNext : " + s); } }); }