List of usage examples for android.os Handler post
public final boolean post(Runnable r)
From source file:com.blackstar.math4brain.util.IabHelper.java
void consumeAsyncInternal(final List<Purchase> purchases, final OnConsumeFinishedListener singleListener, final OnConsumeMultiFinishedListener multiListener) { final Handler handler = new Handler(); flagStartAsync("consume"); (new Thread(new Runnable() { @Override/*from www.j av a2s . com*/ public void run() { final List<IabResult> results = new ArrayList<IabResult>(); for (Purchase purchase : purchases) { try { consume(purchase); results.add(new IabResult(BILLING_RESPONSE_RESULT_OK, "Successful consume of sku " + purchase.getSku())); } catch (IabException ex) { results.add(ex.getResult()); } } flagEndAsync(); if (singleListener != null) { handler.post(new Runnable() { @Override public void run() { singleListener.onConsumeFinished(purchases.get(0), results.get(0)); } }); } if (multiListener != null) { handler.post(new Runnable() { @Override public void run() { multiListener.onConsumeMultiFinished(purchases, results); } }); } } })).start(); }
From source file:com.annahid.libs.artenus.internal.unified.IabHelper.java
void consumeAsyncInternal(final List<IabPurchase> purchases, final OnConsumeFinishedListener singleListener, final OnConsumeMultiFinishedListener multiListener) { final Handler handler = new Handler(); flagStartAsync("consume"); (new Thread(new Runnable() { public void run() { final List<IabResult> results = new ArrayList<>(); for (IabPurchase purchase : purchases) { try { consume(purchase);/*from ww w . j a v a2s .co m*/ results.add(new IabResult(BILLING_RESPONSE_RESULT_OK, "Successful consume of sku " + purchase.getSku())); } catch (IabException ex) { results.add(ex.getResult()); } } flagEndAsync(); if (!mDisposed && singleListener != null) { handler.post(new Runnable() { public void run() { singleListener.onConsumeFinished(purchases.get(0), results.get(0)); } }); } if (!mDisposed && multiListener != null) { handler.post(new Runnable() { public void run() { multiListener.onConsumeMultiFinished(purchases, results); } }); } } })).start(); }
From source file:com.achep.acdisplay.iab.utils.IabHelper.java
void consumeAsyncInternal(final List<Purchase> purchases, final OnConsumeFinishedListener singleListener, final OnConsumeMultiFinishedListener multiListener) { final Handler handler = new Handler(); flagStartAsync("consume"); (new Thread(new Runnable() { public void run() { final List<IabResult> results = new ArrayList<>(); for (Purchase purchase : purchases) { try { consume(purchase);//from ww w .ja va2 s.co m results.add(new IabResult(BILLING_RESPONSE_RESULT_OK, "Successful consume of sku " + purchase.getSku())); } catch (IabException ex) { results.add(ex.getResult()); } } flagEndAsync(); if (!mDisposed && singleListener != null) { handler.post(new Runnable() { public void run() { singleListener.onConsumeFinished(purchases.get(0), results.get(0)); } }); } if (!mDisposed && multiListener != null) { handler.post(new Runnable() { public void run() { multiListener.onConsumeMultiFinished(purchases, results); } }); } } })).start(); }
From source file:acceptable_risk.nik.uniobuda.hu.andrawid.util.IabHelper.java
void consumeAsyncInternal(final List<Purchase> purchases, final OnConsumeFinishedListener singleListener, final OnConsumeMultiFinishedListener multiListener) { final Handler handler = new Handler(); flagStartAsync("consume"); (new Thread(new Runnable() { public void run() { final List<IabResult> results = new ArrayList<IabResult>(); for (Purchase purchase : purchases) { try { consume(purchase);/*w w w . j a va2s . c o m*/ results.add(new IabResult(BILLING_RESPONSE_RESULT_OK, "Successful consume of sku " + purchase.getSku())); } catch (IabException ex) { results.add(ex.getResult()); } } flagEndAsync(); if (!mDisposed && singleListener != null) { handler.post(new Runnable() { public void run() { singleListener.onConsumeFinished(purchases.get(0), results.get(0)); } }); } if (!mDisposed && multiListener != null) { handler.post(new Runnable() { public void run() { multiListener.onConsumeMultiFinished(purchases, results); } }); } } })).start(); }
From source file:org.xbmc.kore.ui.hosts.AddHostFragmentZeroconf.java
/** * Starts the service discovery, setting up the UI accordingly *///ww w . j av a 2s . c o m public void startSearching() { if (!isNetworkConnected()) { noNetworkConnection(); return; } LogUtils.LOGD(TAG, "Starting service discovery..."); searchCancelled = false; final Handler handler = new Handler(); final Thread searchThread = new Thread(new Runnable() { @Override public void run() { WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); WifiManager.MulticastLock multicastLock = null; try { // Get wifi ip address int wifiIpAddress = wifiManager.getConnectionInfo().getIpAddress(); InetAddress wifiInetAddress = NetUtils.intToInetAddress(wifiIpAddress); // Acquire multicast lock multicastLock = wifiManager.createMulticastLock("kore2.multicastlock"); multicastLock.setReferenceCounted(false); multicastLock.acquire(); JmDNS jmDns = (wifiInetAddress != null) ? JmDNS.create(wifiInetAddress) : JmDNS.create(); // Get the json rpc service list final ServiceInfo[] serviceInfos = jmDns.list(MDNS_XBMC_SERVICENAME, DISCOVERY_TIMEOUT); synchronized (lock) { // If the user didn't cancel the search, and we are sill in the activity if (!searchCancelled && isAdded()) { handler.post(new Runnable() { @Override public void run() { if ((serviceInfos == null) || (serviceInfos.length == 0)) { noHostFound(); } else { foundHosts(serviceInfos); } } }); } } } catch (IOException e) { LogUtils.LOGD(TAG, "Got an IO Exception", e); } finally { if (multicastLock != null) multicastLock.release(); } } }); titleTextView.setText(R.string.searching); messageTextView.setText(Html.fromHtml(getString(R.string.wizard_search_message))); messageTextView.setMovementMethod(LinkMovementMethod.getInstance()); progressBar.setVisibility(View.VISIBLE); hostListGridView.setVisibility(View.GONE); // Setup buttons nextButton.setVisibility(View.INVISIBLE); previousButton.setVisibility(View.VISIBLE); previousButton.setText(android.R.string.cancel); previousButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { synchronized (lock) { searchCancelled = true; noHostFound(); } } }); searchThread.start(); }
From source file:github.popeen.dsub.fragments.NowPlayingFragment.java
private void scheduleHideControls() { if (hideControlsFuture != null) { hideControlsFuture.cancel(false); }//from w ww .j a v a 2 s. c o m final Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { handler.post(new Runnable() { @Override public void run() { //TODO, make a setting to turn this on & off // setControlsVisible(false); } }); } }; hideControlsFuture = executorService.schedule(runnable, 3000L, TimeUnit.MILLISECONDS); }
From source file:com.facebook.samples.musicdashboard.MusicGalleryFragment.java
void requestUserData() { Bundle params = new Bundle(); params.putString("fields", "name,picture"); final Handler handler = new Handler(); // Facebook - Graph API call to get personalizatoin info MusicDashboardApplication.mAsyncRunner.request("me", params, new BaseRequestListener() { @Override/*from w ww . j av a 2s .com*/ public void onComplete(String response, Object state) { JSONObject jsonObject; try { Log.i(TAG, "User info response: " + response); jsonObject = new JSONObject(response); final String userName = jsonObject.getString(JSON_NAME); String pictureUrl = null; // An upcoming change in how picture data is returned means // we have to check two ways for picture URL info. try { pictureUrl = jsonObject.getJSONObject(JSON_PICTURE).getJSONObject(JSON_DATA) .getString(JSON_URL); } catch (JSONException e) { // ignored } if (pictureUrl == null) { pictureUrl = jsonObject.getString(JSON_PICTURE); } final Drawable drawable = fetchImageFromUrl(getActivity(), pictureUrl, "profilepic.jpg"); handler.post(new Runnable() { @Override public void run() { // Set the personalization UI info on the main thread userNameTextView.setText(userName); profileImageView.setImageDrawable(drawable); } }); } catch (JSONException e) { Log.i(TAG, "Could not get user info"); } } }); }
From source file:org.mobicents.restcomm.android.client.sdk.RCConnection.java
private void onConnectedToRoom(final SignalingParameters params) { Handler mainHandler = new Handler(RCClient.getContext().getMainLooper()); Runnable myRunnable = new Runnable() { @Override//from w w w . j a v a 2 s .co m public void run() { onConnectedToRoomInternal(params); } }; mainHandler.post(myRunnable); // Phone state Intents to capture dialing or answering event if (signalingParameters.initiator) sendQoSConnectionIntent("dialing"); else sendQoSConnectionIntent("answering"); }
From source file:acceptable_risk.nik.uniobuda.hu.andrawid.util.IabHelper.java
/** * Asynchronous wrapper for inventory query. This will perform an inventory * query as described in {@link #queryInventory}, but will do so asynchronously * and call back the specified listener upon completion. This method is safe to * call from a UI thread./*from w w w. ja va2 s . co m*/ * * @param querySkuDetails as in {@link #queryInventory} * @param moreSkus as in {@link #queryInventory} * @param listener The listener to notify when the refresh operation completes. */ public void queryInventoryAsync(final boolean querySkuDetails, final List<String> moreSkus, final QueryInventoryFinishedListener listener) { final Handler handler = new Handler(); checkNotDisposed(); checkSetupDone("queryInventory"); flagStartAsync("refresh inventory"); (new Thread(new Runnable() { public void run() { IabResult result = new IabResult(BILLING_RESPONSE_RESULT_OK, "Inventory refresh successful."); Inventory inv = null; try { inv = queryInventory(querySkuDetails, moreSkus); } catch (IabException ex) { result = ex.getResult(); } flagEndAsync(); final IabResult result_f = result; final Inventory inv_f = inv; if (!mDisposed && listener != null) { handler.post(new Runnable() { public void run() { listener.onQueryInventoryFinished(result_f, inv_f); } }); } } })).start(); }
From source file:com.cdd.allpay.util.IabHelper.java
void consumeAsyncInternal(final List<Purchase> purchases, final OnConsumeFinishedListener singleListener, final OnConsumeMultiFinishedListener multiListener) { final Handler handler = new Handler(); flagStartAsync("consume"); (new Thread(new Runnable() { public void run() { final List<IabResult> results = new ArrayList<IabResult>(); for (Purchase purchase : purchases) { try { consume(purchase);/*from w w w . j ava 2 s . c o m*/ results.add(new IabResult(BILLING_RESPONSE_RESULT_OK, "Successful consume of sku " + purchase.getSku())); } catch (IabException ex) { results.add(ex.getResult()); } } flagEndAsync(); if (!mDisposed && singleListener != null) { handler.post(new Runnable() { public void run() { singleListener.onConsumeFinished(purchases.get(0), results.get(0)); } }); } if (!mDisposed && multiListener != null) { handler.post(new Runnable() { public void run() { multiListener.onConsumeMultiFinished(purchases, results); } }); } } })).start(); }