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:de.geithonline.abattlwp.billinghelper.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 .java 2 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 QueryInventoryFinishedListener listener) {
    final Handler handler = new Handler();
    checkNotDisposed();
    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 (final IabException ex) {
                result = ex.getResult();
            }

            flagEndAsync();

            final IabResult result_f = result;
            final Inventory inv_f = inv;
            if (!mDisposed && listener != null) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        listener.onQueryInventoryFinished(result_f, inv_f);
                    }
                });
            }
        }
    })).start();
}

From source file:com.kyleshaver.minuteofangle.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  .j a v a  2 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

/**
 * 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.
 *
 * @param querySkuDetails as in {@link #queryInventory}
 * @param moreSkus        as in {@link #queryInventory}
 * @param listener        The listener to notify when the refresh operation completes.
 *//* w w  w. j a v a 2s . c om*/
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();
            } catch (Exception e) {
                result = new IabResult(BILLING_RESPONSE_RESULT_ERROR, "Error");
            }

            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.android.trivialdrivesample.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.  j  a  v a  2 s. c om
 *
 * @param querySkuDetails as in {@link #queryInventory}
 * @param moreItemSkus as in {@link #queryInventory}
 * @param moreSubsSkus as in {@link #queryInventory}
 * @param listener The listener to notify when the refresh operation completes.
 */
public void queryInventoryAsync(final boolean querySkuDetails, final List<String> moreItemSkus,
        final List<String> moreSubsSkus, final QueryInventoryFinishedListener listener)
        throws IabAsyncInProgressException {
    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, moreItemSkus, moreSubsSkus);
            } 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:org.mobicents.restcomm.android.client.sdk.RCConnection.java

@Override
public void onIceDisconnected() {
    // Notice that this is actually means that media connectivity has been lost, hence showing an error (maps to IceConnectionState.DISCONNECTED)
    Handler mainHandler = new Handler(RCClient.getContext().getMainLooper());
    Runnable myRunnable = new Runnable() {
        @Override/*ww w .jav a2  s.c  om*/
        public void run() {
            RCLogger.i(TAG, "onIceDisconnected");
            logAndToast("ICE disconnected");
            iceConnected = false;
            handleDisconnect("Connectivity-Drop");
        }
    };
    mainHandler.post(myRunnable);
}

From source file:org.mobicents.restcomm.android.client.sdk.RCConnection.java

public void onLocalVideo(VideoTrack videoTrack) {
    Handler mainHandler = new Handler(RCClient.getContext().getMainLooper());
    Runnable myRunnable = new Runnable() {
        @Override/*  ww w  . j ava  2  s .c o  m*/
        public void run() {
            RCLogger.i(TAG, "onLocalVideo");
            localVideoReceived = true;
            updateVideoView(VideoViewState.LOCAL_VIEW_RECEIVED);
            listener.onLocalVideo(RCConnection.this);
        }
    };
    mainHandler.post(myRunnable);
}

From source file:org.mobicents.restcomm.android.client.sdk.RCConnection.java

public void onRemoteVideo(VideoTrack videoTrack) {
    Handler mainHandler = new Handler(RCClient.getContext().getMainLooper());
    Runnable myRunnable = new Runnable() {
        @Override//from  w  ww  . j a v a 2 s. c  o m
        public void run() {
            RCLogger.i(TAG, "onRemoteVideo");
            remoteVideoReceived = true;
            updateVideoView(VideoViewState.REMOTE_VIEW_RECEIVED);
            listener.onRemoteVideo(RCConnection.this);
        }
    };
    mainHandler.post(myRunnable);
}

From source file:com.cyberwalkabout.childrentv.subscription.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 a v  a  2 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();
            } catch (IllegalStateException ex) {
                result = new IabResult(BILLING_RESPONSE_RESULT_ERROR, "Helper is not setup.");
            }

            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.segma.trim.InAppBillingUtilities.InAppBillingHelper.java

void consumeAsyncInternal(final List<Purchase> purchases, final OnConsumeFinishedListener singleListener,
        final OnConsumeMultiFinishedListener multiListener) throws InAppBillingAsyncInProgressException {
    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 w  w w.  j a va 2s  . c  o m*/
                    results.add(new InAppBillingResult(BILLING_RESPONSE_RESULT_OK,
                            "Successful consume of sku " + purchase.getStockKeepingUnit()));
                } catch (InAppBillingException 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.tafayor.selfcamerashot.taflib.iab.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  .j  a  v a 2s .  com*/
 *
 * @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();
            }

            catch (Exception ex) {
                ex.printStackTrace();
                return;
            }
            //end edit

            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();
}