List of usage examples for android.os Looper myLooper
public static @Nullable Looper myLooper()
From source file:com.networking.ApiTestActivity.java
public void checkForHeaderGet(View view) { ANRequest.GetRequestBuilder getRequestBuilder = new ANRequest.GetRequestBuilder( ApiEndPoint.BASE_URL + ApiEndPoint.CHECK_FOR_HEADER); getRequestBuilder.addHeaders("token", "1234").setTag(this).setPriority(Priority.LOW).build() .setAnalyticsListener(new AnalyticsListener() { @Override/*from ww w . j ava2 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); } }).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.rxsampleapp.RxApiTestActivity.java
public void checkForHeaderGet(View view) { RxANRequest.GetRequestBuilder getRequestBuilder = new RxANRequest.GetRequestBuilder( ApiEndPoint.BASE_URL + ApiEndPoint.CHECK_FOR_HEADER); getRequestBuilder.addHeaders("token", "1234").build().setAnalyticsListener(new AnalyticsListener() { @Override//w ww . j av a 2s . 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); } }).getJSONObjectObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<JSONObject>() { @Override public void onCompleted() { Log.d(TAG, "onComplete Detail : checkForHeaderGet completed"); } @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(JSONObject response) { Log.d(TAG, "onResponse object : " + response.toString()); Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper())); } }); }
From source file:android.databinding.ViewDataBinding.java
/** * @hide//from www . ja v a 2s . c o m */ protected ViewDataBinding(DataBindingComponent bindingComponent, View root, int localFieldCount) { mBindingComponent = bindingComponent; mLocalFieldObservers = new WeakListener[localFieldCount]; this.mRoot = root; if (Looper.myLooper() == null) { throw new IllegalStateException("DataBinding must be created in view's UI Thread"); } if (USE_CHOREOGRAPHER) { mChoreographer = Choreographer.getInstance(); mFrameCallback = new Choreographer.FrameCallback() { @Override public void doFrame(long frameTimeNanos) { mRebindRunnable.run(); } }; } else { mFrameCallback = null; mUIThreadHandler = new Handler(Looper.myLooper()); } }
From source file:org.jitsi.service.osgi.OSGiActivity.java
protected void start(BundleContext bundleContext) throws Exception { // Starts children OSGI fragments. for (OSGiUiPart osGiFragment : osgiFrgaments) { osGiFragment.start(bundleContext); }/*from w w w . j av a 2 s . c o m*/ // If OSGi has just started and we're on UI thread check for crash event // We must be on UIThread to show the dialog and it makes no sense // to show it from the background, so it will be eventually displayed // from onResume() if (Looper.getMainLooper() == Looper.myLooper()) { checkForSendLogsDialog(); } }
From source file:com.waz.zclient.pages.main.MainPhoneFragment.java
@Override public void onShowOnboardingHint(final OnBoardingHintType hintType, int delayMilSec) { if (hintType == OnBoardingHintType.NONE) { return;/*w w w . ja v a 2s.c om*/ } new Handler(Looper.myLooper()).postDelayed(new Runnable() { @Override public void run() { if (getContainer() == null || !isResumed()) { return; } // Additional check if hint types match. Some animations go through conversation list and might trigger pull down hint Page currentPage = getControllerFactory().getNavigationController().getCurrentPage(); IConversation currentConversation = getStoreFactory().getConversationStore() .getCurrentConversation(); boolean currentConversationHasDraft = TextUtils.isEmpty(getStoreFactory().getDraftStore() .getDraft(getStoreFactory().getConversationStore().getCurrentConversation())); OnBoardingHintType currentHintType = getControllerFactory().getOnboardingController() .getCurrentOnBoardingHint(currentPage, currentConversation, currentConversationHasDraft); if (hintType != currentHintType) { return; } getChildFragmentManager().popBackStackImmediate(OnBoardingHintFragment.TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); getChildFragmentManager().beginTransaction() .setCustomAnimations(R.anim.fade_in, R.anim.slide_out_to_top, R.anim.slide_in_from_bottom, R.anim.fade_out) .add(R.id.fl_fragment_main_onboarding, OnBoardingHintFragment.newInstance(hintType), OnBoardingHintFragment.TAG) .addToBackStack(OnBoardingHintFragment.TAG).commit(); } }, delayMilSec); }
From source file:com.peptrack.gps.locationupdatesforegroundservice.LocationUpdatesService.java
/** * Makes a request for location updates. Note that in this sample we merely log the * {@link SecurityException}.//from ww w. j ava2 s .c o m */ public void requestLocationUpdates() { Log.i(TAG, "Requesting location updates"); Utils.setRequestingLocationUpdates(this, true); startService(new Intent(getApplicationContext(), LocationUpdatesService.class)); try { mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper()); } catch (SecurityException unlikely) { Utils.setRequestingLocationUpdates(this, false); Log.e(TAG, "Lost location permission. Could not request updates. " + unlikely); } }
From source file:com.feedhenry.sdk.tests.api.FHSDKTest.java
private void runAsyncRequest(final FHAct pRequest, final FHActCallback pCallback) throws Exception { // The AsyncHttpClient uses Looper & Handlers to implement async http calls. // It requires the calling thread to have a looper attached to it. // When requests are made from the main UI thread, it will work find as the // main UI thread contains a main Looper. // However, if the app creates another Thread which will be used to invoke // the call, it should use the sync mode or attach the looper to the thread // as demoed below. // The main thread that runs the tests doesn't work with Handlers either. Thread testThread = new Thread() { @Override//from w w w. j a v a 2 s. c o m public void run() { try { Looper.prepare(); pRequest.executeAsync(new FHActCallback() { @Override public void success(FHResponse pResponse) { System.out.println("Got response " + pResponse.getRawResponse()); pCallback.success(pResponse); Looper.myLooper().quit(); } @Override public void fail(FHResponse pResponse) { System.out.println("Got error response : " + pResponse.getRawResponse()); pCallback.fail(pResponse); Looper.myLooper().quit(); } }); Looper.loop(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; testThread.start(); testThread.join(); }
From source file:org.moire.ultrasonic.service.DownloadServiceImpl.java
@SuppressLint("NewApi") @Override/*from w w w.j ava 2s . c om*/ public void onCreate() { super.onCreate(); new Thread(new Runnable() { @Override public void run() { Thread.currentThread().setName("DownloadServiceImpl"); Looper.prepare(); if (mediaPlayer != null) { mediaPlayer.release(); } mediaPlayer = new MediaPlayer(); mediaPlayer.setWakeMode(DownloadServiceImpl.this, PowerManager.PARTIAL_WAKE_LOCK); mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mediaPlayer, int what, int more) { handleError(new Exception(String.format("MediaPlayer error: %d (%d)", what, more))); return false; } }); try { Intent i = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mediaPlayer.getAudioSessionId()); i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName()); sendBroadcast(i); } catch (Throwable e) { // Froyo or lower } mediaPlayerLooper = Looper.myLooper(); mediaPlayerHandler = new Handler(mediaPlayerLooper); Looper.loop(); } }).start(); audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); setUpRemoteControlClient(); if (equalizerAvailable) { equalizerController = new EqualizerController(this, mediaPlayer); if (!equalizerController.isAvailable()) { equalizerController = null; } else { equalizerController.loadSettings(); } } if (visualizerAvailable) { visualizerController = new VisualizerController(mediaPlayer); if (!visualizerController.isAvailable()) { visualizerController = null; } } PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); wakeLock.setReferenceCounted(false); instance = this; lifecycleSupport.onCreate(); }
From source file:com.dspot.declex.actions.NotificationActionHolder.java
/** * Add a large icon to the notification content view. * * In the platform template, this image will be shown on the left of the notification view * in place of the {@link #smallIcon(Icon) small icon} (which will be placed in a small * badge atop the large icon)./*from w ww. j a v a 2s . com*/ */ public NotificationActionHolder largeIcon(@FormattedExpression String icon) { if (icon == null || icon.isEmpty()) return this; if (Looper.myLooper() == Looper.getMainLooper()) { //Call should not be in main thread pendingLargeIconLoad = icon; return this; } try { Bitmap bitmap = Picasso.with(context).load(icon).get(); builder.setLargeIcon(bitmap); } catch (IOException ignored) { } return this; }