interaction = Interaction.Factory.parseInteraction(interactionString); if (interaction != null) { switch (interaction.getType()) { case Survey: defaultVal = false;
public DisplayType getDisplayType() { try { if (isNull(KEY_DISPLAY_TYPE)) { return getDefaultDisplayType(); } return DisplayType.parse(getString(KEY_DISPLAY_TYPE)); } catch (JSONException e) { logException(e); } return DisplayType.unknown; }
@Override public InteractionLauncher launcherForInteraction(Interaction interaction) { return launcherLookup.get(interaction.getDisplayType()); }
@Override public boolean launch(Context context, Interaction interaction) { if (!NotificationUtils.isNotificationChannelEnabled(context, NOTIFICATION_CHANNEL_DEFAULT)) { ApptentiveLog.e(NOTIFICATIONS, "Unable to engage notification interaction: notification channel is disabled"); return false; } final Intent launchIntent = new Intent(context, ApptentiveNotificationInteractionBroadcastReceiver.class); launchIntent.setAction(NOTIFICATION_ACTION_DISPLAY); launchIntent.putExtra(NOTIFICATION_EXTRA_INTERACTION_TYPE, interaction.getType().name()); launchIntent.putExtra(NOTIFICATION_EXTRA_INTERACTION_DEFINITION, interaction.toString()); context.sendBroadcast(launchIntent); return true; } }
public InteractionConfiguration getConfiguration() { try { if (!isNull(KEY_CONFIGURATION)) { return new InteractionConfiguration(getJSONObject(KEY_CONFIGURATION).toString()); } } catch (JSONException e) { logException(e); } return new InteractionConfiguration(); }
/** * In addition to returning the Interactions contained in this payload, this method reformats the Interactions from a * list into a map. The map is then used for further Interaction lookup. * @return */ public Interactions getInteractions() { try { if (!isNull(Interactions.KEY_NAME)) { Object obj = get(Interactions.KEY_NAME); if (obj instanceof JSONArray) { Interactions interactions = new Interactions(); JSONArray interactionsJSONArray = (JSONArray) obj; for (int i = 0; i < interactionsJSONArray.length(); i++) { Interaction interaction = Interaction.Factory.parseInteraction(interactionsJSONArray.getString(i)); if (interaction != null) { interactions.put(interaction.getId(), interaction); } else { // This is an unknown Interaction type. Probably for a future SDK version. } } return interactions; } } } catch (JSONException e) { ApptentiveLog.w(INTERACTIONS, e, "Unable to load Interactions from InteractionManifest."); logException(e); } return null; }
@Override public boolean launch(Context context, Interaction interaction) { Intent intent = new Intent(); intent.setClass(context.getApplicationContext(), ApptentiveViewActivity.class); intent.putExtra(Constants.FragmentConfigKeys.TYPE, Constants.FragmentTypes.INTERACTION); intent.putExtra(Interaction.KEY_NAME, interaction.toString()); /* non-activity context start an Activity, but it requires that a new task be created. * This may fit specific use cases, but can create non-standard back stack behaviors in * hosting application. non-activity context include application context, context from Service * ContentProvider, and BroadcastReceiver */ if (!(context instanceof Activity)) { // check if any activity from the hosting app is running at foreground Activity activity = ApptentiveInternal.getInstance().getCurrentTaskStackTopActivity(); if (activity != null) { context = activity; } else { // If no foreground activity from the host app, launch Apptentive interaction as a new task intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); } } context.startActivity(intent); return true; } }
public static synchronized boolean engageInternal(Context context, Conversation conversation, Interaction interaction, String eventName, String data) { return engage(context, conversation, "com.apptentive", interaction.getType().name(), interaction.getId(), eventName, data, null, (ExtendedData[]) null); }
data.put(Action.KEY_LABEL, action.getLabel()); data.put(TextModalInteraction.EVENT_KEY_ACTION_POSITION, index); data.put(TextModalInteraction.EVENT_KEY_INVOKED_INTERACTION_ID, invokedInteraction == null ? JSONObject.NULL : invokedInteraction.getId()); data.put(TextModalInteraction.KEY_DISPLAY_TYPE, interaction.getDisplayType().name()); } catch (JSONException e) {
switch (interaction.getType()) { case UpgradeMessage: return UpgradeMessageFragment.newInstance(bundle);
private static boolean doEngage(Conversation conversation, Context context, String eventLabel) { checkConversationQueue(); Interaction interaction = conversation.getApplicableInteraction(eventLabel, true); if (interaction != null) { String versionName = ApptentiveInternal.getInstance().getApplicationVersionName(); int versionCode = ApptentiveInternal.getInstance().getApplicationVersionCode(); conversation.getEventData().storeInteractionForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, interaction.getId()); launchInteraction(context, interaction); return true; } ApptentiveLog.d(INTERACTIONS, "No interaction to show for event: '%s'", eventLabel); return false; }
ApptentiveLog.i(INTERACTIONS, "Launching interaction: '%s'", interaction.getType()); InteractionLauncher launcher = LAUNCHER_FACTORY.launcherForInteraction(interaction); if (launcher != null) {
data.put(Action.KEY_LABEL, buttonAction.getLabel()); data.put(TextModalInteraction.EVENT_KEY_ACTION_POSITION, position); data.put(TextModalInteraction.EVENT_KEY_INVOKED_INTERACTION_ID, invokedInteraction == null ? JSONObject.NULL : invokedInteraction.getId()); } catch (JSONException e) { ApptentiveLog.e(e, "Error creating Event data object.");
@Test public void navigateToLinkInteractionNew() { String json = loadTextAssetAsString(TEST_DATA_DIR + "/testNavigateToLinkInteractionNew.json"); Interaction interaction = Interaction.Factory.parseInteraction(json); assertTrue(interaction.getType().equals(Interaction.Type.NavigateToLink)); NavigateToLinkInteraction link = (NavigateToLinkInteraction) interaction; assertEquals("http://pages.ebay.com/link/?nav=item.view&id=221648890812", link.getUrl()); assertTrue(link.getTarget().equals(NavigateToLinkInteraction.Target.New)); }
@Test public void navigateToLinkInteractionSelf() { String json = loadTextAssetAsString(TEST_DATA_DIR + "/testNavigateToLinkInteractionSelf.json"); Interaction interaction = Interaction.Factory.parseInteraction(json); assertTrue(interaction.getType().equals(Interaction.Type.NavigateToLink)); NavigateToLinkInteraction link = (NavigateToLinkInteraction) interaction; assertEquals("http://pages.ebay.com/link/?nav=item.view&id=221648890812", link.getUrl()); assertTrue(link.getTarget().equals(NavigateToLinkInteraction.Target.Self)); }