List of usage examples for android.os Looper myLooper
public static @Nullable Looper myLooper()
From source file:io.samsungsami.example.SAMInBLEws.SAMISession.java
private SAMISession() { if (Looper.myLooper() != Looper.getMainLooper()) { Log.e(TAG, "Constructor is not called in UI thread "); }/*from w ww . java 2 s. c o m*/ mHandler = new Handler(); }
From source file:com.just.agentweb.AgentWebUtils.java
static final void clearWebView(WebView m) { if (m == null) { return;//from w ww .ja va2 s. c om } if (Looper.myLooper() != Looper.getMainLooper()) { return; } m.loadUrl("about:blank"); m.stopLoading(); if (m.getHandler() != null) { m.getHandler().removeCallbacksAndMessages(null); } m.removeAllViews(); ViewGroup mViewGroup = null; if ((mViewGroup = ((ViewGroup) m.getParent())) != null) { mViewGroup.removeView(m); } m.setWebChromeClient(null); m.setWebViewClient(null); m.setTag(null); m.clearHistory(); m.destroy(); m = null; }
From source file:nl.sebastiaanschool.contact.app.gui.GrabBag.java
static void assertNotOnMainThread() { if (Looper.myLooper() == Looper.getMainLooper()) { throw new IllegalStateException("on main thread"); }/*from w ww . ja v a 2 s. co m*/ }
From source file:com.android.deskclock.Utils.java
public static void enforceMainLooper() { if (Looper.getMainLooper() != Looper.myLooper()) { throw new IllegalAccessError("May only call from main thread."); }//from www .ja v a2 s .c o m }
From source file:ua.at.tsvetkov.data_processor.ProcessingCentre.java
/** * @param request/*from ww w . j av a 2s.c o m*/ * @param clazz * @param callback */ public ProcessingCentre(Request request, Class<T> clazz, Callback<T> callback) { if (request == null || clazz == null) { throw new InvalidParameterException(INVALID_PARAMETER); } this.request = request; this.clazz = clazz; this.callback = callback; if (Looper.myLooper() != null) handler = new Handler(); else handler = null; thread = Thread.currentThread(); }
From source file:com.loopj.android.http.sample.AsyncBackgroundThreadSample.java
@Override public ResponseHandlerInterface getResponseHandler() { FutureTask<ResponseHandlerInterface> future = new FutureTask<>(new Callable<ResponseHandlerInterface>() { @Override/* ww w. j a v a2 s. c o m*/ public ResponseHandlerInterface call() throws Exception { Log.d(LOG_TAG, "Creating AsyncHttpResponseHandler on background thread"); return new AsyncHttpResponseHandler(Looper.getMainLooper()) { @Override public void onStart() { clearOutputs(); } @Override public void onSuccess(int statusCode, Header[] headers, byte[] response) { Log.d(LOG_TAG, String.format("onSuccess executing on main thread : %B", Looper.myLooper() == Looper.getMainLooper())); debugHeaders(LOG_TAG, headers); debugStatusCode(LOG_TAG, statusCode); debugResponse(LOG_TAG, new String(response)); } @Override public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) { Log.d(LOG_TAG, String.format("onFailure executing on main thread : %B", Looper.myLooper() == Looper.getMainLooper())); debugHeaders(LOG_TAG, headers); debugStatusCode(LOG_TAG, statusCode); debugThrowable(LOG_TAG, e); if (errorResponse != null) { debugResponse(LOG_TAG, new String(errorResponse)); } } @Override public void onRetry(int retryNo) { Toast.makeText(AsyncBackgroundThreadSample.this, String.format("Request is retried, retry no. %d", retryNo), Toast.LENGTH_SHORT) .show(); } }; } }); executor.execute(future); ResponseHandlerInterface responseHandler = null; try { responseHandler = future.get(); Log.d(LOG_TAG, "Background thread for AsyncHttpResponseHandler has finished"); } catch (Exception e) { e.printStackTrace(); } return responseHandler; }
From source file:com.android.deskclock.Utils.java
public static void enforceNotMainLooper() { if (Looper.getMainLooper() == Looper.myLooper()) { throw new IllegalAccessError("May not call from main thread."); }//from w w w. j a v a 2s.c o m }
From source file:com.veniosg.dir.mvvm.model.storage.operation.DeleteOperation.java
private void runOnUi(Runnable runnable) { if (Looper.myLooper() != context.getMainLooper()) { mainThreadHandler.post(runnable); } else {//from ww w.ja v a 2 s . c o m runnable.run(); } }
From source file:ota.otaupdates.utils.Utils.java
public static Boolean isMainThread() { return Looper.myLooper() == Looper.getMainLooper(); }
From source file:ru.dublgis.androidhelpers.mobility.CellListener.java
public synchronized boolean start() { Log.d(TAG, "start"); try {/*w w w .j a va 2s. com*/ if (mManager == null) { mManager = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE); } Runnable listenRunnable = new Runnable() { @Override public void run() { if (mManager != null) { try { Looper.prepare(); mListenerLooper = Looper.myLooper(); mListener = new CellListenerImpl(); mManager.listen(mListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); Looper.loop(); mManager.listen(mListener, PhoneStateListener.LISTEN_NONE); } catch (Throwable ex) { Log.e(TAG, "Failed to start TelephonyManager listener", ex); } } } }; mListenerThread = new Thread(listenRunnable, "Listen TelephonyManager"); mListenerThread.start(); return true; } catch (Throwable e) { Log.e(TAG, "Exception while starting cell listener: ", e); return false; } }