List of usage examples for android.os Handler post
public final boolean post(Runnable r)
From source file:org.onepf.oms.appstore.skubitUtils.SkubitIabHelper.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 ww w.ja v a 2s. c om*/ * * @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, @NotNull final QueryInventoryFinishedListener listener) { final Handler handler = new Handler(); checkSetupDone("queryInventory"); flagStartAsync("refresh inventory"); (new Thread(new Runnable() { public void run() { IabResult result = new IabResult(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; handler.post(new Runnable() { public void run() { listener.onQueryInventoryFinished(result_f, inv_f); } }); } })).start(); }
From source file:com.syncedsynapse.kore2.ui.hosts.AddHostFragmentZeroconf.java
/** * Starts the service discovery, setting up the UI accordingly */// www. j a va 2s . c om public void startSearching() { 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:com.abid_mujtaba.fetchheaders.fragments.AccountFragment.java
public void remove_emails_marked_for_deletion(Handler handler) // Called by parent activity to force the fragment to refresh its contents. This will cause emails set for deletions to be deleted. { if (mEmails != null) // If an error occurs while connecting to an account mEmails == null in which case there cannot be any emails to delete so we skip the entire functionality {//from w w w . ja v a 2 s .c o m // We iterate over the emails weeding out the emails marked for deletion ArrayList<Email> emails = new ArrayList<Email>(); ArrayList<Integer> keys = new ArrayList<Integer>(); // We store the keys that we have to delete from the HashMap. We can't do it while we are traversing the key set itself for (int ii = 0; ii < mEmails.size(); ii++) // We iterate over the keys in the SparseArray. This way we know that we are iterating over existing objects and have access to their unique keys { Integer key = mEmails.keyAt(ii); Email email = mEmails.get(key); if (email.isToBeDeleted()) { emails.add(email); keys.add(key); } } mAccount.delete(emails); for (Integer key : keys) { mEmails.remove(key); } // Remove the Email objects corresponding to the deleted emails from the HashMap handler.post(new Runnable() { // Since emails have been deleted we completely refresh the fragment view @Override public void run() { refreshFragmentView(); } }); } }
From source file:com.welmo.andengine.utility.inappbilling.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 ww w .jav a2 s . c o 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 IAPurchasing 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:mc.inappbilling.v3.InAppBillingHelper.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<InAppBillingResult> results = new ArrayList<InAppBillingResult>(); for (Purchase purchase : purchases) { try { consume(purchase);/*from www. j a v a 2 s .c o m*/ results.add(new InAppBillingResult(BILLING_RESPONSE_RESULT_OK, "Successful consume of sku " + purchase.getSku())); } catch (InAppBillingException ex) { results.add(ex.getResult()); } } flagEndAsync(); if (singleListener != null) { handler.post(new Runnable() { public void run() { singleListener.onConsumeFinished(purchases.get(0), results.get(0)); } }); } if (multiListener != null) { handler.post(new Runnable() { public void run() { multiListener.onConsumeMultiFinished(purchases, results); } }); } } })).start(); }
From source file:co.hmsk.android.webdbpress76.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 av a 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 (singleListener != null) { handler.post(new Runnable() { public void run() { singleListener.onConsumeFinished(purchases.get(0), results.get(0)); } }); } if (multiListener != null) { handler.post(new Runnable() { public void run() { multiListener.onConsumeMultiFinished(purchases, results); } }); } } })).start(); }
From source file:me.ccrama.redditslide.util.IabHelper.java
private 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 w w w. j a v a2 s. c om 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.onepf.oms.appstore.skubitUtils.SkubitIabHelper.java
void consumeAsyncInternal(@NotNull final List<Purchase> purchases, @Nullable final OnConsumeFinishedListener singleListener, @Nullable 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);/*ww w . j av a2s . c om*/ results.add(new IabResult(RESULT_OK, "Successful consume of sku " + purchase.getSku())); } catch (IabException ex) { results.add(ex.getResult()); } } flagEndAsync(); if (singleListener != null) { handler.post(new Runnable() { public void run() { singleListener.onConsumeFinished(purchases.get(0), results.get(0)); } }); } if (multiListener != null) { handler.post(new Runnable() { public void run() { multiListener.onConsumeMultiFinished(purchases, results); } }); } } })).start(); }
From source file:br.com.cpb.esperanca.iab.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/* ww w . j a v a 2 s .c o m*/ 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:me.ccrama.redditslide.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 ww w . ja v a 2 s. c o m * * @param querySkuDetails as in {@link #queryInventory} * @param listener The listener to notify when the refresh operation completes. */ private void queryInventoryAsync(final boolean querySkuDetails, 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, null); } 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(); }