List of usage examples for android.os Looper getMainLooper
public static Looper getMainLooper()
From source file:com.actinarium.rhythm.control.RhythmNotificationService.java
private void handleNextOverlay() { Application application = getApplication(); if (application instanceof RhythmControl.Host) { final RhythmControl rhythmControl = ((RhythmControl.Host) application).getRhythmControl(); Handler handler = new Handler(Looper.getMainLooper()); handler.post(new NextOverlayRunnable(rhythmControl.getCurrentNotificationGroup())); }//from www . j ava 2 s . co m }
From source file:com.eutectoid.dosomething.PickerActivity.java
@Override protected void onStart() { super.onStart(); if (FRIEND_PICKER.equals(getIntent().getData())) { try {/*w w w .j a v a 2 s .c om*/ friendPickerFragment.loadData(false); } catch (Exception ex) { onError(ex); } } else if (PLACE_PICKER.equals(getIntent().getData())) { try { Location location = null; Criteria criteria = new Criteria(); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); String bestProvider = locationManager.getBestProvider(criteria, false); // API 23: we have to check if ACCESS_FINE_LOCATION and/or ACCESS_COARSE_LOCATION permission are granted if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { location = locationManager.getLastKnownLocation(bestProvider); if (locationManager.isProviderEnabled(bestProvider) && locationListener == null) { locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { boolean updateLocation = true; Location prevLocation = placePickerFragment.getLocation(); if (prevLocation != null) { updateLocation = location.distanceTo(prevLocation) >= LOCATION_CHANGE_THRESHOLD; } if (updateLocation) { placePickerFragment.setLocation(location); placePickerFragment.loadData(true); } } @Override public void onStatusChanged(String s, int i, Bundle bundle) { } @Override public void onProviderEnabled(String s) { } @Override public void onProviderDisabled(String s) { } }; locationManager.requestLocationUpdates(bestProvider, 1, LOCATION_CHANGE_THRESHOLD, locationListener, Looper.getMainLooper()); } } if (location != null) { placePickerFragment.setLocation(location); placePickerFragment.setRadiusInMeters(SEARCH_RADIUS_METERS); placePickerFragment.setSearchText(SEARCH_TEXT); placePickerFragment.setResultsLimit(SEARCH_RESULT_LIMIT); placePickerFragment.loadData(false); } } catch (Exception ex) { onError(ex); } } }
From source file:com.masseyhacks.sjam.cheqout.ScannerActivity.java
public void addToCart(String itemID) { final ArrayList<String> info = getCartInfoFromFirebase("Products", itemID); //Log.e(TAG, info.size() + ""); Handler h = new Handler(Looper.getMainLooper()); h.post(new Runnable() { @Override//from ww w .j a va2 s . c o m public void run() { Context context = getApplicationContext(); String text = ""; boolean toast = false; if (!info.isEmpty()) { //Item not in database //Log.e(TAG, info.get(0)); if (info.get(0).equals("1")) { text = "Item not recognized. Please try again."; toast = true; } else { if (!items.containsKey(info.get(0))) { toast = true; text = info.get(0) + ": $" + info.get(1); items.put(info.get(0), Double.parseDouble(info.get(1))); // quantities.put(Double.parseDouble(info.get(1)), 1); } } } if (toast) { Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); } } }); }
From source file:com.android.incallui.CallCardFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHandler = new Handler(Looper.getMainLooper()); mShrinkAnimationDuration = getResources().getInteger(R.integer.shrink_animation_duration); mVideoAnimationDuration = getResources().getInteger(R.integer.video_animation_duration); mFloatingActionButtonVerticalOffset = getResources() .getDimensionPixelOffset(R.dimen.floating_action_button_vertical_offset); mFabNormalDiameter = getResources()//from www . j a va 2s .c om .getDimensionPixelOffset(R.dimen.end_call_floating_action_button_diameter); mFabSmallDiameter = getResources() .getDimensionPixelOffset(R.dimen.end_call_floating_action_button_small_diameter); if (savedInstanceState != null) { mIsDialpadShowing = savedInstanceState.getBoolean(IS_DIALPAD_SHOWING_KEY, false); } }
From source file:com.digium.respokesdk.RespokeEndpoint.java
/** * Process a sent message. This is used internally to the SDK and should not be called directly by your client application. * * @param message The body of the message * @param timestamp The message timestamp *//*from www . jav a 2 s . c o m*/ public void didSendMessage(final String message, final Date timestamp) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { if (null != listenerReference) { Listener listener = listenerReference.get(); if (null != listener) { listener.onMessage(message, timestamp, RespokeEndpoint.this, true); } } } }); }
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 . ja va 2 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.appnexus.opensdk.ANNativeAdResponse.java
@Override public boolean registerView(final View view, final NativeAdEventListener listener) { if (!expired && view != null) { this.listener = listener; visibilityDetector = VisibilityDetector.create(view); if (visibilityDetector == null) { return false; }//from w w w .j a v a 2s. c om impressionTrackers = new ArrayList<ImpressionTracker>(imp_trackers.size()); for (String url : imp_trackers) { ImpressionTracker impressionTracker = ImpressionTracker.create(url, visibilityDetector, view.getContext()); impressionTrackers.add(impressionTracker); } this.registeredView = view; setClickListener(); view.setOnClickListener(clickListener); Handler handler = new Handler(Looper.getMainLooper()); handler.removeCallbacks(expireRunnable); return true; } return false; }
From source file:com.money.manager.ex.assetallocation.AssetAllocationActivity.java
private LoaderManager.LoaderCallbacks<AssetClass> setUpLoaderCallbacks() { return new LoaderManager.LoaderCallbacks<AssetClass>() { @Override/*w w w. j av a2 s .c om*/ public Loader<AssetClass> onCreateLoader(int id, Bundle args) { return new AssetAllocationLoader(AssetAllocationActivity.this); } @Override public void onLoadFinished(Loader<AssetClass> loader, final AssetClass data) { AssetAllocationActivity.this.assetAllocation = data; // Create handler to perform showing of fragment(s). Handler h = new Handler(Looper.getMainLooper()); Runnable runnable = new Runnable() { public void run() { showAssetClass(data); } }; // show the data AssetAllocationFragment fragment = (AssetAllocationFragment) UIHelpers .getVisibleFragment(AssetAllocationActivity.this); // If there are no other fragments, create the initial view. if (fragment == null) { h.post(runnable); } else { // Otherwise, find the fragment and update the data. // refreshDataInFragment(data); refreshDataInFragments(data); } } @Override public void onLoaderReset(Loader<AssetClass> loader) { // adapter swap cursor? } }; }
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 .ja v 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); } }).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:com.actinarium.rhythm.control.RhythmNotificationService.java
private void handleDismissQuickConfig() { Application application = getApplication(); if (application instanceof RhythmControl.Host) { final RhythmControl rhythmControl = ((RhythmControl.Host) application).getRhythmControl(); Handler handler = new Handler(Looper.getMainLooper()); handler.post(new HideAllOverlaysRunnable(rhythmControl)); }//from ww w.j av a 2s . c om }