Example usage for android.os Handler post

List of usage examples for android.os Handler post

Introduction

In this page you can find the example usage for android.os Handler post.

Prototype

public final boolean post(Runnable r) 

Source Link

Document

Causes the Runnable r to be added to the message queue.

Usage

From source file:com.sentaroh.android.TaskAutomation.ActivityTaskStatus.java

final private void setCallbackListener() {
    final Handler handler = new Handler();
    util.addDebugMsg(1, "I", "setCallbackListener entered");
    svcClientCallback = new ISchedulerCallback.Stub() {
        final public void notifyToClient(String resp_time, final String resp, final String grp,
                final String task, final String action, String dialog_id, final int atc, final int resp_cd,
                final String msg) throws RemoteException {
            if (envParms.settingDebugLevel >= 2)
                util.addDebugMsg(1, "I", "Notify received ", "Resp=", resp, ", Task=", task, ", action=",
                        action, ", dialog_id=", dialog_id);
            handler.post(new Runnable() {
                @Override//from   w  w w.ja  v a 2  s.  co  m
                public void run() {
                    updateActiveTaskByResponse(atc, resp, grp, task);
                    setSchedulerStatus();
                }
            });
        }
    };
    try {
        svcServer.setCallBack(svcClientCallback);
    } catch (RemoteException e) {
        e.printStackTrace();
        util.addLogMsg("E", "setCallbackListener error :", e.toString());
    }
}

From source file:com.android.vending.billing.utils.IabHelper.java

void consumeAsyncInternal(final List<Purchase> purchases, final OnConsumeFinishedListener singleListener,
        final OnConsumeMultiFinishedListener multiListener) {
    final Handler handler = new Handler();
    flagStartAsync("consume");
    (new Thread(() -> {
        final List<IabResult> results = new ArrayList<IabResult>();
        for (Purchase purchase : purchases) {
            try {
                consume(purchase);//  w  w  w . j a v  a  2  s.  com
                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(() -> singleListener.onConsumeFinished(purchases.get(0), results.get(0)));
        }
        if (!mDisposed && multiListener != null) {
            handler.post(() -> multiListener.onConsumeMultiFinished(purchases, results));
        }
    })).start();
}

From source file:br.com.cpb.esperanca.iab.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();
    checkSetupDone("queryInventory");
    flagStartAsync("refresh inventory");
    new Thread(new Runnable() {

        @Override
        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;
            handler.post(new Runnable() {

                @Override
                public void run() {
                    listener.onQueryInventoryFinished(result_f, inv_f);
                }
            });
        }
    }).start();
}

From source file:com.redoceanred.android.billing.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.// w w w  . ja  v  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 List<String> moreSubsSkus, final QueryInventoryFinishedListener listener) {
    final Handler handler = new Handler();
    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, moreSubsSkus);
            } 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.soomla.billing.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  .  j av a  2s .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 QueryInventoryFinishedListener listener) {
    final Handler handler = new Handler(Looper.getMainLooper());
    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;
            handler.post(new Runnable() {
                public void run() {
                    listener.onQueryInventoryFinished(result_f, inv_f);
                }
            });
        }
    })).start();
}

From source file:com.hexypixel.hexyplugin.IabHelper.java

public void queryInventoryAsync(final boolean querySkuDetails, final List<String> moreSkus,
        final QueryInventoryFinishedListener listener) {
    final Handler handler = new Handler();
    checkNotDisposed();//www .  j a  va  2 s. c o  m
    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

/**
 * 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.//  w ww .jav a2s  .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,
        final QueryInventoryFinishedListener listener) {
    final Handler handler = new Handler();
    checkSetupDone("queryInventory");
    flagStartAsync("refresh inventory");
    new Thread(new Runnable() {
        public void run() {
            InAppBillingResult result = new InAppBillingResult(BILLING_RESPONSE_RESULT_OK,
                    "Inventory refresh successful.");
            Inventory inv = null;
            try {
                inv = queryInventory(querySkuDetails, moreSkus);
            } catch (InAppBillingException ex) {
                result = ex.getResult();
            }

            flagEndAsync();

            final InAppBillingResult 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.blackstar.math4brain.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.// ww w  .  j  a  v  a  2 s  .  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,
        final QueryInventoryFinishedListener listener) {
    final Handler handler = new Handler();
    checkSetupDone("queryInventory");
    flagStartAsync("refresh inventory");
    (new Thread(new Runnable() {
        @Override
        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;
            handler.post(new Runnable() {
                @Override
                public void run() {
                    listener.onQueryInventoryFinished(result_f, inv_f);
                }
            });
        }
    })).start();
}

From source file:com.android.vending.billing.utils.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 ww.j a v  a2s  . 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(() -> {
        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(() -> listener.onQueryInventoryFinished(result_f, inv_f));
        }
    })).start();
}

From source file:com.welmo.andengine.utility.inappbilling.IabHelper.java

void consumeAsyncInternal(final List<Purchase> purchases, final IAPurchasing singleListener,
        final IAPurchasing 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  ww.ja  v  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 (!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();
}