Skip to content

Commit 463eeb6

Browse files
authored
Merge branch 'microsoft:main' into fork-main
2 parents 4b9d9b8 + ce47f49 commit 463eeb6

File tree

9 files changed

+201
-12
lines changed

9 files changed

+201
-12
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
3+
"type": "AdaptiveCard",
4+
"version": "1.3",
5+
"body": [
6+
{
7+
"type": "TextBlock",
8+
"text": "1. First item in the list;"
9+
},
10+
{
11+
"type": "TextBlock",
12+
"text": "2. Second item in the list;"
13+
},
14+
{
15+
"type": "TextBlock",
16+
"text": "3. Third item in the list;"
17+
},
18+
{
19+
"type": "TextBlock",
20+
"text": "10. The tenth thing\r10. The list is still going!\r10. Should be 12!",
21+
"wrap": true
22+
}
23+
]
24+
}

source/android/adaptivecards/src/androidTest/java/io/adaptivecards/objectmodel/TextBlockPropertiesTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,32 @@ public void TestNumberedList () throws Exception
380380
Assert.assertEquals(expectedHtml, html);
381381
}
382382

383+
@Test
384+
public void TestNumberedListHonoursStart () throws Exception
385+
{
386+
final String textWithNewLines = "18. Green\r19. Orange\r20. Blue";
387+
// This looks counter intuitive but without the replacement of '\n\r' for "<br/>" the
388+
// output will only contain a blank space where '\n' is expected
389+
final String expectedHtml = "18. Green\n19. Orange\n20. Blue";
390+
391+
String html = RendererUtil.handleSpecialText(textWithNewLines).toString();
392+
393+
Assert.assertEquals(expectedHtml, html);
394+
}
395+
396+
@Test
397+
public void TestNumberedListIncrementsCorrectly () throws Exception
398+
{
399+
final String textWithNewLines = "18. Green\r18. Orange\r18. Blue";
400+
// This looks counter intuitive but without the replacement of '\n\r' for "<br/>" the
401+
// output will only contain a blank space where '\n' is expected
402+
final String expectedHtml = "18. Green\n19. Orange\n20. Blue";
403+
404+
String html = RendererUtil.handleSpecialText(textWithNewLines).toString();
405+
406+
Assert.assertEquals(expectedHtml, html);
407+
}
408+
383409
// This string is the result for an empty textblock or a textblock with all default values
384410
public static final String s_defaultTextBlock = "{\"text\":\"\",\"type\":\"TextBlock\"}\n";
385411

source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/ActionLayoutRenderer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ public View renderActions(
4949
HostConfig hostConfig,
5050
RenderArgs renderArgs) throws AdaptiveFallbackException
5151
{
52-
long size;
53-
if (baseActionElementList == null || (size = baseActionElementList.size()) <= 0)
52+
53+
if (baseActionElementList == null)
5454
{
5555
return null;
5656
}
5757

58+
long size = baseActionElementList.size();
59+
5860
LinearLayout actionButtonsLayout = new LinearLayout(context);
5961
actionButtonsLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
6062
int alignment = hostConfig.GetActions().getActionAlignment().swigValue();

source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/readonly/RendererUtil.java

Lines changed: 127 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
import android.text.Html;
88
import android.text.Spanned;
99

10+
import org.xml.sax.Attributes;
11+
import org.xml.sax.ContentHandler;
12+
import org.xml.sax.Locator;
13+
import org.xml.sax.SAXException;
1014
import org.xml.sax.XMLReader;
1115

16+
import java.util.ArrayDeque;
1217
import java.util.Calendar;
1318
import java.util.GregorianCalendar;
1419

@@ -122,17 +127,27 @@ public static CharSequence trimHtmlString(Spanned htmlString)
122127
}
123128

124129
// Class to replace ul and li tags
125-
public static class UlTagHandler implements Html.TagHandler
130+
public static class UlTagHandler implements Html.TagHandler, ContentHandler
126131
{
127132
private int tagNumber = 0;
128133
private boolean orderedList = false;
134+
private ContentHandler defaultContentHandler = null;
135+
private Editable text = null;
136+
private ArrayDeque<Boolean> tagStatusQueue = new ArrayDeque<>();
129137

130-
@Override
131-
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader)
138+
private String getAttribute(String attributeName, Attributes attributes)
139+
{
140+
return attributes.getValue(attributeName);
141+
}
142+
143+
public boolean handleTag(boolean opening, String tag, Editable output, Attributes attributes)
132144
{
145+
boolean tagWasHandled = false;
146+
133147
if (tag.equals("ul") && !opening)
134148
{
135149
output.append("\n");
150+
tagWasHandled = true;
136151
}
137152

138153
if (tag.equals("listItem") && opening)
@@ -148,13 +163,121 @@ public void handleTag(boolean opening, String tag, Editable output, XMLReader xm
148163
{
149164
output.append("\n• ");
150165
}
166+
tagWasHandled = true;
151167
}
152168

153169
if (tag.equals("ol") && opening)
154170
{
155171
orderedList = true;
156-
tagNumber = 1;
172+
String tagNumberString = getAttribute("start", attributes);
173+
174+
int retrievedTagNumber = 1;
175+
if (tagNumberString != null)
176+
{
177+
retrievedTagNumber = Integer.parseInt(tagNumberString);
178+
}
179+
180+
tagNumber = retrievedTagNumber;
181+
tagWasHandled = true;
157182
}
183+
184+
return tagWasHandled;
185+
}
186+
187+
@Override
188+
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader)
189+
{
190+
if (defaultContentHandler == null)
191+
{
192+
// save input text
193+
text = output;
194+
195+
// store default XMLReader object
196+
defaultContentHandler = xmlReader.getContentHandler();
197+
198+
// replace content handler with our own that forwards to calls to default when needed
199+
xmlReader.setContentHandler(this);
200+
201+
// handle endElement() callback for <inject/> tag
202+
tagStatusQueue.addLast(Boolean.FALSE);
203+
}
204+
}
205+
206+
// ContentHandler override methods
207+
@Override
208+
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
209+
{
210+
boolean isHandled = handleTag(true, localName, text, attributes);
211+
tagStatusQueue.addLast(isHandled);
212+
213+
if (!isHandled)
214+
{
215+
defaultContentHandler.startElement(uri, localName, qName, attributes);
216+
}
217+
}
218+
219+
@Override
220+
public void endElement(String uri, String localName, String qName) throws SAXException
221+
{
222+
if (!tagStatusQueue.removeLast())
223+
{
224+
defaultContentHandler.endElement(uri, localName, qName);
225+
}
226+
227+
handleTag(false, localName, text, (Attributes)null);
228+
}
229+
230+
@Override
231+
public void setDocumentLocator(Locator locator)
232+
{
233+
defaultContentHandler.setDocumentLocator(locator);
234+
}
235+
236+
@Override
237+
public void startDocument() throws SAXException
238+
{
239+
defaultContentHandler.startDocument();
240+
}
241+
242+
@Override
243+
public void endDocument() throws SAXException
244+
{
245+
defaultContentHandler.endDocument();
246+
}
247+
248+
@Override
249+
public void startPrefixMapping(String prefix, String uri) throws SAXException
250+
{
251+
defaultContentHandler.startPrefixMapping(prefix, uri);
252+
}
253+
254+
@Override
255+
public void endPrefixMapping(String prefix) throws SAXException
256+
{
257+
defaultContentHandler.endPrefixMapping(prefix);
258+
}
259+
260+
@Override
261+
public void characters(char[] chars, int start, int length) throws SAXException {
262+
defaultContentHandler.characters(chars, start, length);
263+
}
264+
265+
@Override
266+
public void ignorableWhitespace(char[] chars, int start, int length) throws SAXException
267+
{
268+
defaultContentHandler.ignorableWhitespace(chars, start, length);
269+
}
270+
271+
@Override
272+
public void processingInstruction(String target, String data) throws SAXException
273+
{
274+
defaultContentHandler.processingInstruction(target, data);
275+
}
276+
277+
@Override
278+
public void skippedEntity(String name) throws SAXException
279+
{
280+
defaultContentHandler.skippedEntity(name);
158281
}
159282
}
160283

source/android/uitestapp/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ android {
2929
// including shared samples in APK assets
3030
assets {
3131
srcDirs {
32-
"../../../samples/v1.3/Scenarios/"
32+
["../../../samples/v1.3/Scenarios/",
33+
"../../../samples/v1.5/Test/"]
3334
}
3435
}
3536
}

source/android/uitestapp/src/androidTest/java/io.adaptivecards.uitestapp/UiTests.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import org.junit.Rule
88
import io.adaptivecards.uitestapp.RenderCardUiTestAppActivity
99
import kotlin.Throws
1010
import androidx.test.espresso.Espresso
11+
import androidx.test.espresso.ViewAction
12+
import androidx.test.espresso.ViewAssertion
1113
import org.hamcrest.Matchers
1214
import androidx.test.espresso.action.ViewActions
1315
import io.adaptivecards.uitestapp.TestHelpers
@@ -58,4 +60,17 @@ class UiTests {
5860
TestHelpers.goToInputsScreen()
5961
Espresso.onData(Matchers.`is`(RetrievedInput("dueDate", "2021-02-04"))).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
6062
}
63+
64+
@Test
65+
@Throws(Exception::class)
66+
fun RenderedMarkdownStartsWithRightNumber() {
67+
Espresso.onData(Matchers.`is`("TextBlock.Markdown.NumberStart.json")).perform(ViewActions.click())
68+
TestHelpers.goToRenderedCardScreen()
69+
70+
Espresso.onView(ViewMatchers.withText("1. First item in the list;")).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
71+
Espresso.onView(ViewMatchers.withText("2. Second item in the list;")).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
72+
Espresso.onView(ViewMatchers.withText("3. Third item in the list;")).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
73+
74+
Espresso.onView(ViewMatchers.withText("10. The tenth thing\n11. The list is still going!\n12. Should be 12!")).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
75+
}
6176
}

source/android/uitestapp/src/main/java/io/adaptivecards/uitestapp/ui/test_cases/TestCasesFragment.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ class TestCasesFragment : Fragment() {
4040

4141
private fun populateTestCaseList () {
4242
try {
43-
val something : MutableList<String> = mutableListOf("a", "b", "c")
44-
4543
val activity : FragmentActivity = requireActivity();
4644
val assets : AssetManager = activity.assets;
4745
val assetsList = assets.list("");

source/nodejs/adaptivecards-designer/src/adaptivecards-designer.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -949,18 +949,18 @@ a.default-ac-anchor:visited:active {
949949
height: 31px;
950950
background-color: #EEEEEE;
951951
color: black;
952-
border: 1px solid #CCCCCC;
952+
border: 1px solid #888888;
953953
border-radius: 2px;
954954
}
955955

956956
.default-ac-pushButton:hover, .acd-dialog-button:hover {
957957
/* background-color: #DDDDDD; */
958-
border: 1px solid #BBBBBB;
958+
border: 1px solid #777777;
959959
}
960960

961961
.default-ac-pushButton:active, .acd-dialog-button:active {
962962
/* background-color: #CCCCCC; */
963-
border: 1px solid #BBBBBB;
963+
border: 1px solid #777777;
964964
}
965965

966966
.default-ac-pushButton.subdued {
2.92 KB
Loading

0 commit comments

Comments
 (0)