Skip to content

Commit

Permalink
Merge branch 'master' into clean-template-engine-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
dclaux committed Aug 26, 2019
2 parents 0c95658 + 95bfaec commit f72a586
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.adaptivecards.objectmodel;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.test.mock.MockContext;
import android.widget.LinearLayout;

import junit.framework.Assert;

import org.junit.Test;

import io.adaptivecards.renderer.AdaptiveCardRenderer;
import io.adaptivecards.renderer.RenderedAdaptiveCard;
import io.adaptivecards.renderer.registration.CardRendererRegistration;

public class FeatureRegistrationRenderTest
{

static {
System.loadLibrary("adaptivecards-native-lib");
}

@Test
public void TestDefaultRendering() throws Exception
{
final String cardJson =
"{\"$schema\": \"http:https://adaptivecards.io/schemas/adaptive-card.json\"," +
"\"type\": \"AdaptiveCard\"," +
"\"version\": \"1.0\"," +
"\"body\": [{\"type\": \"TextBlock\",\"text\": \"This is some text\"}]" +
"}";

HostConfig hostConfig = new HostConfig();

ParseContext parseContext = new ParseContext();
ParseResult parseResult = AdaptiveCard.DeserializeFromString(cardJson, AdaptiveCardRenderer.VERSION, parseContext);
Context context = InstrumentationRegistry.getTargetContext();
AdaptiveCardRenderer.getInstance().render(context, null, parseResult.GetAdaptiveCard(), null, hostConfig);
}

@Test
public void TestFeatureRegistrationRendering() throws Exception
{
final String cardJson =
"{\"$schema\": \"http:https://adaptivecards.io/schemas/adaptive-card.json\"," +
"\"type\": \"AdaptiveCard\"," +
"\"version\": \"1.0\"," +
"\"body\": [{\"type\": \"TextBlock\",\"text\": \"This is some text\"}]" +
"}";

HostConfig hostConfig = new HostConfig();

ParseContext parseContext = new ParseContext();
ParseResult parseResult = AdaptiveCard.DeserializeFromString(cardJson, AdaptiveCardRenderer.VERSION, parseContext);
Context context = InstrumentationRegistry.getTargetContext();

FeatureRegistration featureRegistration = new FeatureRegistration();
featureRegistration.AddFeature("featureName", "1.0");
CardRendererRegistration.getInstance().registerFeatureRegistration(featureRegistration);

AdaptiveCardRenderer.getInstance().render(context, null, parseResult.GetAdaptiveCard(), null, hostConfig);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ else if ((fallbackActionElement = BaseActionElement.dynamic_cast(fallbackElement
throw new AdaptiveFallbackException(fallbackElement);
}

if (!fallbackElement.MeetsRequirements(featureRegistration))
if ((featureRegistration != null) && (!fallbackElement.MeetsRequirements(featureRegistration)))
{
throw new AdaptiveFallbackException(fallbackElement, featureRegistration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ else if ((fallbackCardElement = BaseCardElement.dynamic_cast(fallbackElement)) =
throw new AdaptiveFallbackException(fallbackCardElement);
}

if (!fallbackElement.MeetsRequirements(featureRegistration))
if ((featureRegistration != null) && (!fallbackElement.MeetsRequirements(featureRegistration)))
{
throw new AdaptiveFallbackException(fallbackCardElement, featureRegistration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,22 @@ private void onSubmit(BaseActionElement actionElement, RenderedAdaptiveCard rend
Map<String, String> keyValueMap = renderedAdaptiveCard.getInputs();
if (!data.isEmpty())
{
try {
JSONObject object = new JSONObject(data);
try
{
JSONObject object = null;
if (!data.equals("null\n"))
{
object = new JSONObject(data);
}
else
{
object = new JSONObject();
}

showToast("Submit data: " + object.toString() + "\nInput: " + keyValueMap.toString(), Toast.LENGTH_LONG);
} catch (JSONException e) {
}
catch (JSONException e)
{
showToast(e.toString(), Toast.LENGTH_LONG);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,22 +263,36 @@ public void run()
this.runOnUiThread(new RunnableExtended(this, text, duration));
}

private void onSubmit(BaseActionElement actionElement, RenderedAdaptiveCard renderedAdaptiveCard) {
private void onSubmit(BaseActionElement actionElement, RenderedAdaptiveCard renderedAdaptiveCard)
{
SubmitAction submitAction = null;
if (actionElement instanceof SubmitAction) {
if (actionElement instanceof SubmitAction)
{
submitAction = (SubmitAction) actionElement;
} else if ((submitAction = SubmitAction.dynamic_cast(actionElement)) == null) {
}
else if ((submitAction = SubmitAction.dynamic_cast(actionElement)) == null)
{
throw new InternalError("Unable to convert BaseActionElement to ShowCardAction object model.");
}

String data = submitAction.GetDataJson();
Map<String, String> keyValueMap = renderedAdaptiveCard.getInputs();
if (!data.isEmpty())
{
try {
JSONObject object = new JSONObject(data);
try
{
JSONObject object = null;
if (!data.equals("null\n"))
{
object = new JSONObject(data);
}
else
{
object = new JSONObject();
}
showToast("Submit data: " + object.toString() + "\nInput: " + keyValueMap.toString(), Toast.LENGTH_LONG);
} catch (JSONException e) {
}
catch (JSONException e) {
showToast(e.toString(), Toast.LENGTH_LONG);
}
}
Expand Down

0 comments on commit f72a586

Please sign in to comment.