public String getId() { return optString(KEY_ID, null); }
public static com.apptentive.android.sdk.module.engagement.interaction.model.common.Action parseAction(String actionString) { try { Type action = Type.unknown; JSONObject actionObject = new JSONObject(actionString); if (actionObject.has(KEY_ACTION)) { action = Type.parse(actionObject.getString(KEY_ACTION)); } switch (action) { case dismiss: return new DismissAction(actionString); case interaction: return new LaunchInteractionAction(actionString); case unknown: break; } } catch (JSONException e) { logException(e); } return null; } }
List<Action> actions = null; if (actionsObject != null) { actions = actionsObject.getAsList(); totalChars += button.getLabel().length(); final int position = i; Button button = (Button) inflater.inflate(R.layout.apptentive_textmodal_interaction_button, bottomArea, false); button.setText(buttonAction.getLabel()); switch (buttonAction.getType()) { case dismiss: button.setOnClickListener(guarded(new View.OnClickListener() {
List<Action> actions = interaction.getActions().getAsList(); final Action action = actions.get(index); Action.Type actionType = action.getType(); ApptentiveLog.v(NOTIFICATION_INTERACTIONS, "Note Notification button pressed with index %d and action type %s", index, actionType.name()); switch (actionType) { case interaction: { data.put(TextModalInteraction.EVENT_KEY_ACTION_ID, action.getId()); data.put(Action.KEY_LABEL, action.getLabel()); data.put(TextModalInteraction.EVENT_KEY_ACTION_POSITION, index); data.put(TextModalInteraction.KEY_DISPLAY_TYPE, interaction.getDisplayType().name());
@Test public void textModalInteraction() { String json = loadTextAssetAsString(TEST_DATA_DIR + "/testTextModalInteraction.json"); Interaction interaction = Interaction.Factory.parseInteraction(json); assertTrue(interaction.getType().equals(Interaction.Type.TextModal)); TextModalInteraction textModalInteraction = (TextModalInteraction) interaction; assertEquals("548cc5dd49f63bb5c2000001", textModalInteraction.getId()); assertEquals("External Deep Links", textModalInteraction.getTitle()); assertEquals("This example allow testing how external deep links are opened.", textModalInteraction.getBody()); List<Action> actions = textModalInteraction.getActions().getAsList(); { Action action = actions.get(0); assertEquals("eBay - Same Task", action.getLabel()); assertTrue(action.getType().equals(Action.Type.interaction)); } } }
List<Invocation> invocations = launchInteractionAction.getInvocations(); String interactionIdToLaunch = null; data.put(TextModalInteraction.EVENT_KEY_ACTION_ID, action.getId()); 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());
public List<Action> getAsList() { List<Action> ret = new ArrayList<Action>(); try { for (int i = 0; i < length(); i++) { Action button = Action.Factory.parseAction(getJSONObject(i).toString()); if (button != null) { ret.add(button); } } } catch (JSONException e) { ApptentiveLog.w(INTERACTIONS, e, "Exception parsing interactions array."); logException(e); } return ret; } }
@Override public void onClick(View view) { JSONObject data = new JSONObject(); try { data.put(TextModalInteraction.EVENT_KEY_ACTION_ID, buttonAction.getId()); data.put(Action.KEY_LABEL, buttonAction.getLabel()); data.put(TextModalInteraction.EVENT_KEY_ACTION_POSITION, position); } catch (JSONException e) { ApptentiveLog.e(e, "Error creating Event data object."); logException(e); } engageInternal(TextModalInteraction.EVENT_NAME_DISMISS, data.toString()); transit(); } }));
public List<Invocation> getInvocations() { List<Invocation> invocations = new ArrayList<Invocation>(); try { if (!isNull(KEY_INVOKES)) { JSONArray invocationsArray= getJSONArray(KEY_INVOKES); if (invocationsArray != null) { for (int i = 0; i < invocationsArray.length(); i++) { JSONObject invocationObject = invocationsArray.getJSONObject(i); Invocation invocation = new Invocation(invocationObject.toString()); invocations.add(invocation); } } } } catch (JSONException e) { logException(e); } return invocations; }
public static Type parse(String name) { try { return Type.valueOf(name); } catch (IllegalArgumentException e) { ApptentiveLog.v(INTERACTIONS, "Error parsing unknown Action.Type: " + name); logException(e); } return unknown; } }
public Actions getActions() { try { InteractionConfiguration configuration = getConfiguration(); if (configuration != null && configuration.has(KEY_ACTIONS)) { return new Actions(configuration.getString(KEY_ACTIONS)); } } catch (JSONException e) { logException(e); } return null; } }
@Override public void onClick(View view) { LaunchInteractionAction launchInteractionButton = (LaunchInteractionAction) buttonAction; List<Invocation> invocations = launchInteractionButton.getInvocations(); String interactionIdToLaunch = null; for (Invocation invocation : invocations) { data.put(TextModalInteraction.EVENT_KEY_ACTION_ID, buttonAction.getId()); 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());
public String getLabel() { return optString(KEY_LABEL, null); }