private static void notifyFailure(final LoginCallback callback, final String errorMessage) { if (callback != null) { DispatchQueue.mainQueue().dispatchAsync(new DispatchTask() { @Override protected void execute() { callback.onLoginFail(errorMessage); } }); } }
protected void dispatchOnMainQueue(DispatchTask task) { DispatchQueue.mainQueue().dispatchAsync(task); }
protected void dispatchOnMainQueue(DispatchTask task) { DispatchQueue.mainQueue().dispatchAsync(task); }
/** * Our SDK must connect to our server at least once to download initial configuration for Message * Center. Call this method to see whether or not Message Center can be displayed. This task is * performed asynchronously. * * @param callback Called after we check to see if Message Center can be displayed, but before it * is displayed. Called with true if an Interaction will be displayed, else false. */ public static void canShowMessageCenter(BooleanCallback callback) { dispatchConversationTask(new ConversationDispatchTask(callback, DispatchQueue.mainQueue()) { @Override protected boolean execute(Conversation conversation) { return ApptentiveInternal.canShowMessageCenterInternal(conversation); } }, "check message center availability"); }
/** * This method can be used to determine if a call to one of the <strong><code>engage()</code></strong> methods such as * {@link #engage(Context, String)} using the same event name will * result in the display of an Interaction. This is useful if you need to know whether an Interaction will be * displayed before you create a UI Button, etc. * * @param event A unique String representing the line this method is called on. For instance, you may want to have * the ability to target interactions to run after the user uploads a file in your app. You may then * call <strong><code>engage(activity, "finished_upload");</code></strong> */ public static synchronized void queryCanShowInteraction(final String event, BooleanCallback callback) { dispatchConversationTask(new ConversationDispatchTask(callback, DispatchQueue.mainQueue()) { @Override protected boolean execute(Conversation conversation) { return canShowLocalAppInteraction(conversation, event); } }, "check if interaction can be shown"); }
/** * Opens the Apptentive Message Center UI Activity, and allows custom data to be sent with the * next message the user sends. If the user sends multiple messages, this data will only be sent * with the first message sent after this method is invoked. Additional invocations of this method * with custom data will repeat this process. If Message Center is closed without a message being * sent, the custom data is cleared. This task is performed asynchronously. Message Center * configuration may not have been downloaded yet when this is called. * * @param context The context from which to launch the Message Center. This should be an * Activity, except in rare cases where you don't have access to one, in which * case Apptentive Message Center will launch in a new task. * @param callback Called after we check to see if Message Center can be displayed, but before * it is displayed. Called with true if an Interaction will be displayed, else * false. * @param customData A Map of String keys to Object values. Objects may be Strings, Numbers, or * Booleans. If any message is sent by the Person, this data is sent with it, * and then cleared. If no message is sent, this data is discarded. */ public static void showMessageCenter(final Context context, final BooleanCallback callback, final Map<String, Object> customData) { dispatchConversationTask(new ConversationDispatchTask(callback, DispatchQueue.mainQueue()) { @Override protected boolean execute(Conversation conversation) { return ApptentiveInternal.getInstance().showMessageCenterInternal(context, customData); } }, "show message center"); }
public void notifyHostUnreadMessagesListeners(final int unreadMessages) { checkConversationQueue(); // we dispatch listeners on the main queue for (WeakReference<UnreadMessagesListener> listenerRef : hostUnreadMessagesListeners) { final UnreadMessagesListener listener = listenerRef.get(); if (listener != null) { DispatchQueue.mainQueue().dispatchAsync(new DispatchTask() { @Override protected void execute() { listener.onUnreadMessageCountChanged(unreadMessages); } }); } } }
public static void launchMessageCenterErrorActivity(final Context context) { if (!isMainQueue()) { mainQueue().dispatchAsync(new DispatchTask() { @Override protected void execute() { launchMessageCenterErrorActivity(context); } }); return; } if (context != null) { Intent intent = MessageCenterInteraction.generateMessageCenterErrorIntent(context); if (!(context instanceof Activity)) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); } context.startActivity(intent); } }
public static void showToast(final Context context, final String message, final int duration) { if (!DispatchQueue.isMainQueue()) { DispatchQueue.mainQueue().dispatchAsync(new DispatchTask() { @Override protected void execute() { showToast(context, message, duration); } }); return; } try { Toast.makeText(context, message, duration).show(); } catch (Exception e) { ApptentiveLog.e(e, "Exception while trying to display toast message"); logException(e); } }
@Override protected boolean execute(Conversation conversation) { String apptentivePushData = ApptentiveInternal.getApptentivePushNotificationData(intent); final PendingIntent intent = ApptentiveInternal.generatePendingIntentFromApptentivePushData(conversation, apptentivePushData); DispatchQueue.mainQueue().dispatchAsync(new DispatchTask() { @Override protected void execute() { callback.onPendingIntent(intent); } }); return true; } }, "build pending intent");
@Override protected boolean execute(Conversation conversation) { String apptentivePushData = ApptentiveInternal.getApptentivePushNotificationData(bundle); final PendingIntent intent = ApptentiveInternal.generatePendingIntentFromApptentivePushData(conversation, apptentivePushData); DispatchQueue.mainQueue().dispatchAsync(new DispatchTask() { @Override protected void execute() { callback.onPendingIntent(intent); } }); return true; } }, "build pending intent");
@Override protected boolean execute(Conversation conversation) { String apptentivePushData = ApptentiveInternal.getApptentivePushNotificationData(data); final PendingIntent intent = ApptentiveInternal.generatePendingIntentFromApptentivePushData(conversation, apptentivePushData); DispatchQueue.mainQueue().dispatchAsync(new DispatchTask() { @Override protected void execute() { callback.onPendingIntent(intent); } }); return true; } }, "build pending intent");
private void showDebugNotification(final Context context) { final String subject = getSubject(context); final File[] attachments = listAttachments(context); DispatchQueue.mainQueue().dispatchAsync(new DispatchTask() { @Override protected void execute() { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = TroubleshootingNotificationBuilder.buildNotification(context, subject, getSystemInfo(context), attachments, emailRecipients); Assert.assertNotNull(notification, "Failed to create troubleshooting notification"); if (notificationManager != null) { notificationManager.notify(NOTIFICATION_ID, notification); } } }); }
dispatchConversationTask(new ConversationDispatchTask(callback, DispatchQueue.mainQueue()) { @Override protected boolean execute(Conversation conversation) { dispatchConversationTask(new ConversationDispatchTask(callback, DispatchQueue.mainQueue()) { @Override protected boolean execute(Conversation conversation) {
public void notifyAuthenticationFailedListener(final Apptentive.AuthenticationFailedReason reason, String conversationIdOfFailedRequest) { checkConversationQueue(); if (isConversationActive()) { String activeConversationId = getConversation().getConversationId(); if (StringUtils.equal(activeConversationId, conversationIdOfFailedRequest)) { final Apptentive.AuthenticationFailedListener listener = authenticationFailedListenerRef != null ? authenticationFailedListenerRef.get() : null; if (listener != null) { // we need to dispatch listener on the main queue DispatchQueue.mainQueue().dispatchAsync(new DispatchTask() { @Override protected void execute() { listener.onAuthenticationFailed(reason); } }); } } } }
@Test public void testSchedulingTasksWithException() { DispatchQueue.mainQueue().dispatchAsyncOnce(new DispatchTask() { @Override protected void execute() { addResult("task-1"); } }); DispatchQueue.mainQueue().dispatchAsyncOnce(new DispatchTask() { @Override protected void execute() { throw new RuntimeException(); // throwing an exception should not break the queue } }); DispatchQueue.mainQueue().dispatchAsyncOnce(new DispatchTask() { @Override protected void execute() { addResult("task-2"); } }); dispatchTasks(); assertResult("task-1", "task-2"); } }
DispatchQueue.mainQueue().dispatchAsyncOnce(toastMessageNotifierTask.setMessage(messageOnToast));
@Test public void testSchedulingTasksOnce() { DispatchTask task = new DispatchTask() { @Override protected void execute() { addResult("executed"); } }; assertTrue(DispatchQueue.mainQueue().dispatchAsyncOnce(task)); assertFalse(DispatchQueue.mainQueue().dispatchAsyncOnce(task)); assertFalse(DispatchQueue.mainQueue().dispatchAsyncOnce(task)); dispatchTasks(); assertResult("executed"); assertTrue(DispatchQueue.mainQueue().dispatchAsyncOnce(task)); assertFalse(DispatchQueue.mainQueue().dispatchAsyncOnce(task)); assertFalse(DispatchQueue.mainQueue().dispatchAsyncOnce(task)); dispatchTasks(); assertResult("executed"); DispatchQueue.mainQueue().dispatchAsync(task); DispatchQueue.mainQueue().dispatchAsync(task); dispatchTasks(); assertResult("executed", "executed"); }
mainQueue().dispatchAsync(new DispatchTask() { @Override protected void execute() {