-
Notifications
You must be signed in to change notification settings - Fork 593
[Android] Add options page for setting custom elements #3292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
almedina-ms
merged 4 commits into
master
from
user/almedina-ms/AndroidAppOptionalFeatures
Aug 7, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
af7130f
Add options page for setting custom elements
almedina-ms 664f1de
Merge branch 'master' into user/almedina-ms/AndroidAppOptionalFeatures
almedina-ms 9049171
Fix tabs
almedina-ms 6b23f26
Merge branch 'master' into user/almedina-ms/AndroidAppOptionalFeatures
almedina-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", | ||
| "type": "AdaptiveCard", | ||
| "version": "1.0", | ||
| "body": [ | ||
| { | ||
| "type": "blah", | ||
| "secret": "This is a custom element" | ||
| } | ||
| ] | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
.../io/adaptivecards/adaptivecardssample/CustomObjects/Actions/CustomGreenActionElement.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package io.adaptivecards.adaptivecardssample.CustomObjects.Actions; | ||
|
|
||
| import io.adaptivecards.objectmodel.ActionType; | ||
| import io.adaptivecards.objectmodel.BaseActionElement; | ||
|
|
||
| public class CustomGreenActionElement extends BaseActionElement | ||
| { | ||
|
|
||
| public CustomGreenActionElement(ActionType type) { | ||
| super(type); | ||
| } | ||
|
|
||
| public String getMessage() | ||
| { | ||
| return m_message; | ||
| } | ||
|
|
||
| private final String m_message = "Smell you later!"; | ||
| public static final String CustomActionId = "greenAction"; | ||
| } |
28 changes: 28 additions & 0 deletions
28
...a/io/adaptivecards/adaptivecardssample/CustomObjects/Actions/CustomGreenActionParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package io.adaptivecards.adaptivecardssample.CustomObjects.Actions; | ||
|
|
||
| import io.adaptivecards.objectmodel.ActionElementParser; | ||
| import io.adaptivecards.objectmodel.ActionType; | ||
| import io.adaptivecards.objectmodel.BaseActionElement; | ||
| import io.adaptivecards.objectmodel.JsonValue; | ||
| import io.adaptivecards.objectmodel.ParseContext; | ||
|
|
||
| public class CustomGreenActionParser extends ActionElementParser | ||
| { | ||
| @Override | ||
| public BaseActionElement Deserialize(ParseContext context, JsonValue value) | ||
| { | ||
| CustomGreenActionElement element = new CustomGreenActionElement(ActionType.Custom); | ||
| element.SetElementTypeString(CustomGreenActionElement.CustomActionId); | ||
| element.SetId("greenActionDeserialize"); | ||
| return element; | ||
| } | ||
|
|
||
| @Override | ||
| public BaseActionElement DeserializeFromString(ParseContext context, String jsonString) | ||
| { | ||
| CustomGreenActionElement element = new CustomGreenActionElement(ActionType.Custom); | ||
| element.SetElementTypeString(CustomGreenActionElement.CustomActionId); | ||
| element.SetId("greenActionDeserialize"); | ||
| return element; | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
...io/adaptivecards/adaptivecardssample/CustomObjects/Actions/CustomGreenActionRenderer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package io.adaptivecards.adaptivecardssample.CustomObjects.Actions; | ||
|
|
||
| import android.app.Activity; | ||
| import android.content.Context; | ||
| import android.support.v4.app.FragmentManager; | ||
| import android.view.ViewGroup; | ||
| import android.widget.Button; | ||
|
|
||
| import io.adaptivecards.adaptivecardssample.R; | ||
| import io.adaptivecards.objectmodel.BaseActionElement; | ||
| import io.adaptivecards.objectmodel.HostConfig; | ||
| import io.adaptivecards.renderer.BaseActionElementRenderer; | ||
| import io.adaptivecards.renderer.RenderArgs; | ||
| import io.adaptivecards.renderer.RenderedAdaptiveCard; | ||
| import io.adaptivecards.renderer.actionhandler.ICardActionHandler; | ||
|
|
||
| public class CustomGreenActionRenderer extends BaseActionElementRenderer | ||
| { | ||
| public CustomGreenActionRenderer(Activity activity) | ||
| { | ||
| m_activity = activity; | ||
| } | ||
|
|
||
| @Override | ||
| public Button render(RenderedAdaptiveCard renderedCard, | ||
| Context context, | ||
| FragmentManager fragmentManager, | ||
| ViewGroup viewGroup, | ||
| BaseActionElement baseActionElement, | ||
| ICardActionHandler cardActionHandler, | ||
| HostConfig hostConfig, | ||
| RenderArgs renderArgs) | ||
| { | ||
| Button greenActionButton = new Button(context); | ||
|
|
||
| CustomGreenActionElement customAction = (CustomGreenActionElement) baseActionElement.findImplObj(); | ||
|
|
||
| greenActionButton.setBackgroundColor(m_activity.getResources().getColor(R.color.greenActionColor)); | ||
| greenActionButton.setText(customAction.getMessage()); | ||
| greenActionButton.setAllCaps(false); | ||
| greenActionButton.setOnClickListener(new BaseActionElementRenderer.ActionOnClickListener(renderedCard, baseActionElement, cardActionHandler)); | ||
|
|
||
| viewGroup.addView(greenActionButton); | ||
|
|
||
| return greenActionButton; | ||
| } | ||
|
|
||
| private Activity m_activity; | ||
| } |
29 changes: 29 additions & 0 deletions
29
...va/io/adaptivecards/adaptivecardssample/CustomObjects/Actions/CustomRedActionElement.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package io.adaptivecards.adaptivecardssample.CustomObjects.Actions; | ||
|
|
||
| import io.adaptivecards.objectmodel.ActionType; | ||
| import io.adaptivecards.objectmodel.BaseActionElement; | ||
|
|
||
| public class CustomRedActionElement extends BaseActionElement | ||
| { | ||
|
|
||
| public CustomRedActionElement(ActionType type) { | ||
| super(type); | ||
| } | ||
|
|
||
| public String getBackwardString() | ||
| { | ||
| return m_backwardsString; | ||
| } | ||
|
|
||
| public void setBackwardString(String s) | ||
| { | ||
| m_backwardsString = new String(); | ||
| for(int i = s.length() - 1; i >= 0; i--) | ||
| { | ||
| m_backwardsString += s.charAt(i); | ||
| } | ||
| } | ||
|
|
||
| private String m_backwardsString; | ||
| public static final String CustomActionId = "redAction"; | ||
| } |
46 changes: 46 additions & 0 deletions
46
...ava/io/adaptivecards/adaptivecardssample/CustomObjects/Actions/CustomRedActionParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package io.adaptivecards.adaptivecardssample.CustomObjects.Actions; | ||
|
|
||
| import org.json.JSONException; | ||
| import org.json.JSONObject; | ||
|
|
||
| import io.adaptivecards.objectmodel.ActionElementParser; | ||
| import io.adaptivecards.objectmodel.ActionType; | ||
| import io.adaptivecards.objectmodel.BaseActionElement; | ||
| import io.adaptivecards.objectmodel.JsonValue; | ||
| import io.adaptivecards.objectmodel.ParseContext; | ||
|
|
||
| public class CustomRedActionParser extends ActionElementParser | ||
| { | ||
| @Override | ||
| public BaseActionElement Deserialize(ParseContext context, JsonValue value) | ||
| { | ||
| CustomRedActionElement element = new CustomRedActionElement(ActionType.Custom); | ||
| element.SetElementTypeString(CustomRedActionElement.CustomActionId); | ||
| element.SetId("backwardActionDeserialize"); | ||
| String val = value.getString(); | ||
| try { | ||
| JSONObject obj = new JSONObject(val); | ||
| element.setBackwardString(obj.getString("backwardString")); | ||
| } catch (JSONException e) { | ||
| e.printStackTrace(); | ||
| element.setBackwardString("deliaF"); | ||
| } | ||
| return element; | ||
| } | ||
|
|
||
| @Override | ||
| public BaseActionElement DeserializeFromString(ParseContext context, String jsonString) | ||
| { | ||
| CustomRedActionElement element = new CustomRedActionElement(ActionType.Custom); | ||
| element.SetElementTypeString(CustomRedActionElement.CustomActionId); | ||
| element.SetId("backwardActionDeserialize"); | ||
| try { | ||
| JSONObject obj = new JSONObject(jsonString); | ||
| element.setBackwardString(obj.getString("backwardString")); | ||
| } catch (JSONException e) { | ||
| e.printStackTrace(); | ||
| element.setBackwardString("deliaF"); | ||
| } | ||
| return element; | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
...a/io/adaptivecards/adaptivecardssample/CustomObjects/Actions/CustomRedActionRenderer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package io.adaptivecards.adaptivecardssample.CustomObjects.Actions; | ||
|
|
||
| import android.app.Activity; | ||
| import android.content.Context; | ||
| import android.support.v4.app.FragmentManager; | ||
| import android.view.ViewGroup; | ||
| import android.widget.Button; | ||
|
|
||
| import io.adaptivecards.adaptivecardssample.R; | ||
| import io.adaptivecards.objectmodel.BaseActionElement; | ||
| import io.adaptivecards.objectmodel.HostConfig; | ||
| import io.adaptivecards.renderer.BaseActionElementRenderer; | ||
| import io.adaptivecards.renderer.RenderArgs; | ||
| import io.adaptivecards.renderer.RenderedAdaptiveCard; | ||
| import io.adaptivecards.renderer.actionhandler.ICardActionHandler; | ||
|
|
||
| public class CustomRedActionRenderer extends BaseActionElementRenderer | ||
| { | ||
| public CustomRedActionRenderer(Activity activity) | ||
| { | ||
| m_activity = activity; | ||
| } | ||
|
|
||
| @Override | ||
| public Button render(RenderedAdaptiveCard renderedCard, | ||
| Context context, | ||
| FragmentManager fragmentManager, | ||
| ViewGroup viewGroup, | ||
| BaseActionElement baseActionElement, | ||
| ICardActionHandler cardActionHandler, | ||
| HostConfig hostConfig, | ||
| RenderArgs renderArgs) | ||
| { | ||
| Button backwardActionButton = new Button(context); | ||
|
|
||
| CustomRedActionElement customAction = (CustomRedActionElement) baseActionElement.findImplObj(); | ||
|
|
||
| backwardActionButton.setBackgroundColor(m_activity.getResources().getColor(R.color.redActionColor)); | ||
| backwardActionButton.setText(customAction.getBackwardString()); | ||
| backwardActionButton.setAllCaps(false); | ||
| backwardActionButton.setOnClickListener(new BaseActionElementRenderer.ActionOnClickListener(renderedCard, baseActionElement, cardActionHandler)); | ||
|
|
||
| viewGroup.addView(backwardActionButton); | ||
|
|
||
| return backwardActionButton; | ||
| } | ||
|
|
||
| private Activity m_activity; | ||
| } |
47 changes: 47 additions & 0 deletions
47
.../io/adaptivecards/adaptivecardssample/CustomObjects/Actions/ShowCardOverrideRenderer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package io.adaptivecards.adaptivecardssample.CustomObjects.Actions; | ||
|
|
||
| import android.app.Activity; | ||
| import android.content.Context; | ||
| import android.support.v4.app.FragmentManager; | ||
| import android.view.ViewGroup; | ||
| import android.widget.Button; | ||
|
|
||
| import io.adaptivecards.adaptivecardssample.R; | ||
| import io.adaptivecards.objectmodel.BaseActionElement; | ||
| import io.adaptivecards.objectmodel.HostConfig; | ||
| import io.adaptivecards.renderer.BaseActionElementRenderer; | ||
| import io.adaptivecards.renderer.RenderArgs; | ||
| import io.adaptivecards.renderer.RenderedAdaptiveCard; | ||
| import io.adaptivecards.renderer.actionhandler.ICardActionHandler; | ||
|
|
||
| public class ShowCardOverrideRenderer extends BaseActionElementRenderer | ||
| { | ||
|
|
||
| public ShowCardOverrideRenderer(Activity activity) | ||
| { | ||
| m_activity = activity; | ||
| } | ||
|
|
||
| @Override | ||
| public Button render(RenderedAdaptiveCard renderedCard, | ||
| Context context, | ||
| FragmentManager fragmentManager, | ||
| ViewGroup viewGroup, | ||
| BaseActionElement baseActionElement, | ||
| ICardActionHandler cardActionHandler, | ||
| HostConfig hostConfig, | ||
| RenderArgs renderArgs) | ||
| { | ||
| Button button = new Button(context); | ||
|
|
||
| button.setBackgroundColor(m_activity.getResources().getColor(R.color.yellowActionColor)); | ||
| button.setText(baseActionElement.GetTitle() +"(ShowCard)"); | ||
|
|
||
| button.setOnClickListener(new BaseActionElementRenderer.ActionOnClickListener(renderedCard, context, fragmentManager, viewGroup, baseActionElement, cardActionHandler, hostConfig)); | ||
|
|
||
| viewGroup.addView(button); | ||
| return button; | ||
| } | ||
|
|
||
| private Activity m_activity; | ||
| } |
53 changes: 53 additions & 0 deletions
53
...ava/io/adaptivecards/adaptivecardssample/CustomObjects/CardElements/CustomBlahParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package io.adaptivecards.adaptivecardssample.CustomObjects.CardElements; | ||
|
|
||
| import org.json.JSONException; | ||
| import org.json.JSONObject; | ||
|
|
||
| import io.adaptivecards.adaptivecardssample.MainActivityAdaptiveCardsSample; | ||
| import io.adaptivecards.objectmodel.BaseCardElement; | ||
| import io.adaptivecards.objectmodel.BaseCardElementParser; | ||
| import io.adaptivecards.objectmodel.CardElementType; | ||
| import io.adaptivecards.objectmodel.JsonValue; | ||
| import io.adaptivecards.objectmodel.ParseContext; | ||
|
|
||
| public class CustomBlahParser extends BaseCardElementParser | ||
| { | ||
| @Override | ||
| public BaseCardElement Deserialize(ParseContext context, JsonValue value) | ||
| { | ||
| CustomCardElement element = new CustomCardElement(CardElementType.Custom); | ||
| element.SetElementTypeString("blah"); | ||
| element.SetId("BlahDeserialize"); | ||
| String val = value.getString(); | ||
| try | ||
| { | ||
| JSONObject obj = new JSONObject(val); | ||
| element.setSecretString(obj.getString("secret")); | ||
| } | ||
| catch (JSONException e) | ||
| { | ||
| e.printStackTrace(); | ||
| element.setSecretString("Failed"); | ||
| } | ||
| return element; | ||
| } | ||
|
|
||
| @Override | ||
| public BaseCardElement DeserializeFromString(ParseContext context, String jsonString) | ||
| { | ||
| CustomCardElement element = new CustomCardElement(CardElementType.Custom); | ||
| element.SetElementTypeString("blah"); | ||
| element.SetId("BlahDeserialize"); | ||
| try | ||
| { | ||
| JSONObject obj = new JSONObject(jsonString); | ||
| element.setSecretString(obj.getString("secret")); | ||
| } | ||
| catch (JSONException e) | ||
| { | ||
| e.printStackTrace(); | ||
| element.setSecretString("Failed"); | ||
| } | ||
| return element; | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
...a/io/adaptivecards/adaptivecardssample/CustomObjects/CardElements/CustomBlahRenderer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package io.adaptivecards.adaptivecardssample.CustomObjects.CardElements; | ||
|
|
||
| import android.content.Context; | ||
| import android.support.v4.app.FragmentManager; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.widget.TextView; | ||
|
|
||
| import io.adaptivecards.objectmodel.BaseCardElement; | ||
| import io.adaptivecards.objectmodel.HostConfig; | ||
| import io.adaptivecards.renderer.BaseCardElementRenderer; | ||
| import io.adaptivecards.renderer.RenderArgs; | ||
| import io.adaptivecards.renderer.RenderedAdaptiveCard; | ||
| import io.adaptivecards.renderer.actionhandler.ICardActionHandler; | ||
|
|
||
| public class CustomBlahRenderer extends BaseCardElementRenderer | ||
| { | ||
| @Override | ||
| public View render(RenderedAdaptiveCard renderedAdaptiveCard, | ||
| Context context, | ||
| FragmentManager fragmentManager, | ||
| ViewGroup viewGroup, | ||
| BaseCardElement baseCardElement, | ||
| ICardActionHandler cardActionHandler, | ||
| HostConfig hostConfig, | ||
| RenderArgs renderArgs) | ||
| { | ||
| TextView textView = new TextView(context); | ||
|
|
||
| CustomCardElement element = (CustomCardElement) baseCardElement.findImplObj(); | ||
|
|
||
| textView.setText(element.getSecretString()); | ||
|
|
||
| textView.setAllCaps(true); | ||
|
|
||
| viewGroup.addView(textView); | ||
|
|
||
| return textView; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.