List of usage examples for android.os Looper getMainLooper
public static Looper getMainLooper()
From source file:de.dsi8.dsi8acl.connection.impl.SocketConnection.java
/** * Default Constructor./*from w w w .j a v a 2s .c o m*/ * @param dependencyContainer The {@link Socket} * @param listener Will be informed, when something happen here. */ public SocketConnection(ISocket socket) { this.socket = socket; jsonMapper.configure(Feature.AUTO_CLOSE_TARGET, false); jsonMapper.configure(SerializationFeature.CLOSE_CLOSEABLE, false); jsonMapper.configure(SerializationFeature.FLUSH_AFTER_WRITE_VALUE, true); messageListenerThread = new MessageListenerThread(this, new Handler(Looper.getMainLooper())); }
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. j av a 2 s . co m*/ mHandler = new Handler(); }
From source file:com.just.agentweb.AgentWebUtils.java
static final void clearWebView(WebView m) { if (m == null) { return;/* w ww.ja va 2 s .com*/ } 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:com.loopj.android.http.sample.AsyncBackgroundThreadSample.java
@Override public ResponseHandlerInterface getResponseHandler() { FutureTask<ResponseHandlerInterface> future = new FutureTask<>(new Callable<ResponseHandlerInterface>() { @Override/*from w w w .ja v a2s.co 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.f2prateek.dfg.core.GenerateMultipleFramesService.java
public void notifyFinished() { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override//from w w w .ja v a 2 s .c o m public void run() { bus.post(new Events.MultipleImagesProcessed(device, processedImageUris)); } }); if (processedImageUris.size() == 0) { return; } String text = resources.getString(R.string.multiple_screenshots_saved, processedImageUris.size(), device.name()); Intent viewImagesIntent = new Intent(Intent.ACTION_VIEW); viewImagesIntent.setData(processedImageUris.get(0)); viewImagesIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notificationBuilder.setContentTitle(resources.getString(R.string.screenshot_saved_title)) .setContentText(text).setContentIntent(PendingIntent.getActivity(this, 0, viewImagesIntent, 0)) .setProgress(0, 0, false); notificationManager.notify(DFG_NOTIFICATION_ID, notificationBuilder.build()); }
From source file:com.example.igorklimov.tictactoe.wifi.GcmIntentService.java
protected void showToast(final String message) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override//from w w w . jav a2s .c om public void run() { Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show(); } }); }
From source file:com.connectsdk.discovery.provider.CastDiscoveryProvider.java
@Override public void start() { stop();/*from w ww . jav a 2s .c om*/ addCallbackTimer = new Timer(); addCallbackTimer.schedule(new TimerTask() { @Override public void run() { sendSearch(); } }, 100, RESCAN_INTERVAL); removeCallbackTimer = new Timer(); removeCallbackTimer.schedule(new TimerTask() { @Override public void run() { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { mMediaRouter.removeCallback(mMediaRouterCallback); } }); } }, 9100, RESCAN_INTERVAL); }
From source file:com.auth0.api.authentication.AuthenticationAPIClient.java
/** * Creates a new API client instance providing Auth0 account info. * * @param auth0 account information/*from w w w.j av a2 s . co m*/ */ public AuthenticationAPIClient(Auth0 auth0) { this(auth0, new Handler(Looper.getMainLooper())); }
From source file:com.digi.android.wva.WvaApplication.java
public Handler getHandler() { // This method seems to not work when running unit tests. if (isTesting()) return new Handler(Looper.getMainLooper()); return mHandler; }
From source file:com.mirasense.scanditsdk.plugin.SubViewPickerController.java
@Override public void show(final JSONObject settings, final Bundle options, final Bundle overlayOptions, boolean legacyMode) { mPendingClose.set(false);// w w w. j a va 2s. com mLegacyMode = legacyMode; mContinuousMode = PhonegapParamParser.shouldRunInContinuousMode(options); mOrientationHandler = new SubViewPickerOrientationHandler(Looper.getMainLooper(), mPlugin, null); mCloseWhenDidScanCallbackFinishes = false; mOrientationHandler.start(true); final Activity pluginActivity = mPlugin.cordova.getActivity(); DisplayMetrics display = pluginActivity.getApplicationContext().getResources().getDisplayMetrics(); int width = (int) (display.widthPixels * 160.f / display.densityDpi); int height = (int) (display.heightPixels * 160.f / display.densityDpi); mScreenDimensions = new Point(Math.min(width, height), Math.max(width, height)); // initialization must be performed on main thread. this.runOnUiThread(new Runnable() { @Override public void run() { ScanSettings scanSettings; if (settings == null) { scanSettings = LegacySettingsParamParser.getSettings(options); } else { try { scanSettings = ScanSettings.createWithJson(settings); } catch (JSONParseException e) { Log.e("ScanditSDK", "Exception while creating settings"); e.printStackTrace(); sendRuntimeError("Exception while creating settings: " + e.getMessage() + ". Falling back to default scan settings."); scanSettings = ScanSettings.create(); } } BarcodePickerWithSearchBar picker = new BarcodePickerWithSearchBar(pluginActivity, scanSettings); picker.setOnScanListener(SubViewPickerController.this); mPickerStateMachine = new PickerStateMachine(picker, SubViewPickerController.this); mOrientationHandler.setScreenDimensions(mScreenDimensions); mOrientationHandler.setPicker(mPickerStateMachine.getPicker()); // Set all the UI options. PhonegapParamParser.updatePicker(picker, options, SubViewPickerController.this); internalUpdateUI(overlayOptions, options); // Create the layout to add the picker to and add it on top of the web view. mLayout = new RelativeLayout(pluginActivity); ViewGroup viewGroup = getPickerParent(); if (viewGroup == null) return; // couldn't determine view group, nothing to be done. viewGroup.addView(mLayout); RelativeLayout.LayoutParams rLayoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); mLayout.addView(mPickerStateMachine.getPicker(), rLayoutParams); PhonegapParamParser.updateLayout(pluginActivity, mPickerStateMachine.getPicker(), options, mScreenDimensions); if (mPendingClose.compareAndSet(true, false)) { // picker was closed(canceled) in the meantime. close it now. SubViewPickerController.this.close(); } if (!mLegacyMode) return; // In legacy mode, start scanning when show is called. int state = PhonegapParamParser.shouldStartInPausedState(options) ? PickerStateMachine.PAUSED : PickerStateMachine.ACTIVE; mPickerStateMachine.setState(state); } }); }