Skip to content

Commit

Permalink
Merge the text heading branch into main (microsoft#5620)
Browse files Browse the repository at this point in the history
* [shared] Parser support for TextBlock headings changes (microsoft#5577)

* [Shared] Text Heading Support

* Added Samples

* changed spaces to tabs in .json

* [iOS] Text heading changes (microsoft#5584)

* [Shared] Text Heading Support

* Added Samples

* [iOS] Text heading changes

* [Android][Accessibility] TextBlock style: heading (microsoft#5587)

* [Android] Accessible Headings

* Bump to 1.5

* Missed SWIG enum

* [UWP][Shared] Implement Text Heading Object model for UWP and fix shared model serialization (microsoft#5601)

* [UWP][Shared] Added host config and UWP renderer support for heading style (microsoft#5612)

* [Schema] Add Text Block style property to schema (microsoft#5615)

* [Schema] Add Text Block style property to schema

* Update schema version from "1.5" to "vNext"

* Updated specs

Co-authored-by: Joseph Woo <[email protected]>
Co-authored-by: Risheek Rajolu <[email protected]>
Co-authored-by: Adaptive Cards Specs CI <[email protected]>
  • Loading branch information
4 people authored Apr 6, 2021
1 parent 7b93826 commit 5627857
Show file tree
Hide file tree
Showing 21 changed files with 369 additions and 357 deletions.
82 changes: 82 additions & 0 deletions source/android/adaptivecards/src/main/cpp/objectmodel_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7438,6 +7438,54 @@ SWIGEXPORT jint JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectMode
}


SWIGEXPORT jlong JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_getTextStyleEnum(JNIEnv *jenv, jclass jcls) {
jlong jresult = 0 ;
AdaptiveCards::EnumHelpers::EnumMapping< AdaptiveCards::TextStyle > *result = 0 ;

(void)jenv;
(void)jcls;
result = (AdaptiveCards::EnumHelpers::EnumMapping< AdaptiveCards::TextStyle > *) &AdaptiveCards::EnumHelpers::getTextStyleEnum();
*(AdaptiveCards::EnumHelpers::EnumMapping< AdaptiveCards::TextStyle > **)&jresult = result;
return jresult;
}


SWIGEXPORT jstring JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_TextStyleToString(JNIEnv *jenv, jclass jcls, jint jarg1) {
jstring jresult = 0 ;
AdaptiveCards::TextStyle arg1 ;
std::string *result = 0 ;

(void)jenv;
(void)jcls;
arg1 = (AdaptiveCards::TextStyle)jarg1;
result = (std::string *) &AdaptiveCards::TextStyleToString(arg1);
jresult = jenv->NewStringUTF(result->c_str());
return jresult;
}


SWIGEXPORT jint JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_TextStyleFromString(JNIEnv *jenv, jclass jcls, jstring jarg1) {
jint jresult = 0 ;
std::string *arg1 = 0 ;
AdaptiveCards::TextStyle result;

(void)jenv;
(void)jcls;
if(!jarg1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string");
return 0;
}
const char *arg1_pstr = (const char *)jenv->GetStringUTFChars(jarg1, 0);
if (!arg1_pstr) return 0;
std::string arg1_str(arg1_pstr);
arg1 = &arg1_str;
jenv->ReleaseStringUTFChars(jarg1, arg1_pstr);
result = (AdaptiveCards::TextStyle)AdaptiveCards::TextStyleFromString((std::string const &)*arg1);
jresult = (jint)result;
return jresult;
}


SWIGEXPORT jlong JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_getTextSizeEnum(JNIEnv *jenv, jclass jcls) {
jlong jresult = 0 ;
AdaptiveCards::EnumHelpers::EnumMapping< AdaptiveCards::TextSize > *result = 0 ;
Expand Down Expand Up @@ -26962,6 +27010,40 @@ SWIGEXPORT jlong JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectMod
}


SWIGEXPORT jint JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_TextBlock_1GetStyle(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jint jresult = 0 ;
AdaptiveCards::TextBlock *arg1 = (AdaptiveCards::TextBlock *) 0 ;
std::shared_ptr< AdaptiveCards::TextBlock const > *smartarg1 = 0 ;
AdaptiveCards::TextStyle result;

(void)jenv;
(void)jcls;
(void)jarg1_;

smartarg1 = *(std::shared_ptr< const AdaptiveCards::TextBlock > **)&jarg1;
arg1 = (AdaptiveCards::TextBlock *)(smartarg1 ? smartarg1->get() : 0);
result = (AdaptiveCards::TextStyle)((AdaptiveCards::TextBlock const *)arg1)->GetStyle();
jresult = (jint)result;
return jresult;
}


SWIGEXPORT void JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_TextBlock_1SetStyle(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2) {
AdaptiveCards::TextBlock *arg1 = (AdaptiveCards::TextBlock *) 0 ;
AdaptiveCards::TextStyle arg2 ;
std::shared_ptr< AdaptiveCards::TextBlock > *smartarg1 = 0 ;

(void)jenv;
(void)jcls;
(void)jarg1_;

smartarg1 = *(std::shared_ptr< AdaptiveCards::TextBlock > **)&jarg1;
arg1 = (AdaptiveCards::TextBlock *)(smartarg1 ? smartarg1->get() : 0);
arg2 = (AdaptiveCards::TextStyle)jarg2;
(arg1)->SetStyle(arg2);
}


SWIGEXPORT jint JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_TextBlock_1GetTextSize(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jint jresult = 0 ;
AdaptiveCards::TextBlock *arg1 = (AdaptiveCards::TextBlock *) 0 ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ public static InlineElementType InlineElementTypeFromString(String t) {
return InlineElementType.swigToEnum(AdaptiveCardObjectModelJNI.InlineElementTypeFromString(t));
}

public static SWIGTYPE_p_AdaptiveCards__EnumHelpers__EnumMappingT_AdaptiveCards__TextStyle_t getTextStyleEnum() {
return new SWIGTYPE_p_AdaptiveCards__EnumHelpers__EnumMappingT_AdaptiveCards__TextStyle_t(AdaptiveCardObjectModelJNI.getTextStyleEnum(), false);
}

public static String TextStyleToString(TextStyle t) {
return AdaptiveCardObjectModelJNI.TextStyleToString(t.swigValue());
}

public static TextStyle TextStyleFromString(String t) {
return TextStyle.swigToEnum(AdaptiveCardObjectModelJNI.TextStyleFromString(t));
}

public static SWIGTYPE_p_AdaptiveCards__EnumHelpers__EnumMappingT_AdaptiveCards__TextSize_t getTextSizeEnum() {
return new SWIGTYPE_p_AdaptiveCards__EnumHelpers__EnumMappingT_AdaptiveCards__TextSize_t(AdaptiveCardObjectModelJNI.getTextSizeEnum(), false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ public class AdaptiveCardObjectModelJNI {
public final static native long getInlineElementTypeEnum();
public final static native String InlineElementTypeToString(int jarg1);
public final static native int InlineElementTypeFromString(String jarg1);
public final static native long getTextStyleEnum();
public final static native String TextStyleToString(int jarg1);
public final static native int TextStyleFromString(String jarg1);
public final static native long getTextSizeEnum();
public final static native String TextSizeToString(int jarg1);
public final static native int TextSizeFromString(String jarg1);
Expand Down Expand Up @@ -1314,6 +1317,8 @@ public class AdaptiveCardObjectModelJNI {
public final static native String TextBlock_GetText(long jarg1, TextBlock jarg1_);
public final static native void TextBlock_SetText(long jarg1, TextBlock jarg1_, String jarg2);
public final static native long TextBlock_GetTextForDateParsing(long jarg1, TextBlock jarg1_);
public final static native int TextBlock_GetStyle(long jarg1, TextBlock jarg1_);
public final static native void TextBlock_SetStyle(long jarg1, TextBlock jarg1_, int jarg2);
public final static native int TextBlock_GetTextSize(long jarg1, TextBlock jarg1_);
public final static native void TextBlock_SetTextSize(long jarg1, TextBlock jarg1_, int jarg2);
public final static native int TextBlock_GetTextWeight(long jarg1, TextBlock jarg1_);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.2
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */

package io.adaptivecards.objectmodel;

public class SWIGTYPE_p_AdaptiveCards__EnumHelpers__EnumMappingT_AdaptiveCards__TextStyle_t {
private transient long swigCPtr;

protected SWIGTYPE_p_AdaptiveCards__EnumHelpers__EnumMappingT_AdaptiveCards__TextStyle_t(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
swigCPtr = cPtr;
}

protected SWIGTYPE_p_AdaptiveCards__EnumHelpers__EnumMappingT_AdaptiveCards__TextStyle_t() {
swigCPtr = 0;
}

protected static long getCPtr(SWIGTYPE_p_AdaptiveCards__EnumHelpers__EnumMappingT_AdaptiveCards__TextStyle_t obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public DateTimePreparser GetTextForDateParsing() {
return new DateTimePreparser(AdaptiveCardObjectModelJNI.TextBlock_GetTextForDateParsing(swigCPtr, this), true);
}

public TextStyle GetStyle() {
return TextStyle.swigToEnum(AdaptiveCardObjectModelJNI.TextBlock_GetStyle(swigCPtr, this));
}

public void SetStyle(TextStyle value) {
AdaptiveCardObjectModelJNI.TextBlock_SetStyle(swigCPtr, this, value.swigValue());
}

public TextSize GetTextSize() {
return TextSize.swigToEnum(AdaptiveCardObjectModelJNI.TextBlock_GetTextSize(swigCPtr, this));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.2
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */

package io.adaptivecards.objectmodel;

public enum TextStyle {
Paragraph(0),
Heading;

public final int swigValue() {
return swigValue;
}

public static TextStyle swigToEnum(int swigValue) {
TextStyle[] swigValues = TextStyle.class.getEnumConstants();
if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
return swigValues[swigValue];
for (TextStyle swigEnum : swigValues)
if (swigEnum.swigValue == swigValue)
return swigEnum;
throw new IllegalArgumentException("No enum " + TextStyle.class + " with value " + swigValue);
}

@SuppressWarnings("unused")
private TextStyle() {
this.swigValue = SwigNext.next++;
}

@SuppressWarnings("unused")
private TextStyle(int swigValue) {
this.swigValue = swigValue;
SwigNext.next = swigValue+1;
}

@SuppressWarnings("unused")
private TextStyle(TextStyle swigEnum) {
this.swigValue = swigEnum.swigValue;
SwigNext.next = this.swigValue+1;
}

private final int swigValue;

private static class SwigNext {
private static int next = 0;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class AdaptiveCardRenderer
{
public static final String VERSION = "1.4";
public static final String VERSION = "1.5";

protected AdaptiveCardRenderer()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,40 @@
import android.content.Context;
import android.graphics.Typeface;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.AccessibilityDelegateCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.text.Layout;
import android.text.Selection;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ClickableSpan;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.HashMap;

import io.adaptivecards.objectmodel.BaseCardElement;
import io.adaptivecards.objectmodel.ContainerStyle;
import io.adaptivecards.objectmodel.FontType;
import io.adaptivecards.objectmodel.ForegroundColor;
import io.adaptivecards.objectmodel.HeightType;
import io.adaptivecards.renderer.RenderArgs;
import io.adaptivecards.renderer.RenderedAdaptiveCard;
import io.adaptivecards.renderer.TagContent;
import io.adaptivecards.renderer.Util;
import io.adaptivecards.renderer.actionhandler.ICardActionHandler;
import io.adaptivecards.objectmodel.BaseCardElement;
import io.adaptivecards.objectmodel.HorizontalAlignment;
import io.adaptivecards.objectmodel.HostConfig;
import io.adaptivecards.objectmodel.TextBlock;
import io.adaptivecards.objectmodel.TextSize;
import io.adaptivecards.objectmodel.TextStyle;
import io.adaptivecards.objectmodel.TextWeight;
import io.adaptivecards.renderer.BaseCardElementRenderer;

import java.util.HashMap;
import io.adaptivecards.renderer.RenderArgs;
import io.adaptivecards.renderer.RenderedAdaptiveCard;
import io.adaptivecards.renderer.TagContent;
import io.adaptivecards.renderer.Util;
import io.adaptivecards.renderer.actionhandler.ICardActionHandler;

public class TextBlockRenderer extends BaseCardElementRenderer
{
Expand Down Expand Up @@ -69,6 +70,24 @@ public static void setTextSize(TextView textView, FontType type, TextSize textSi
textView.setTextSize(TextRendererUtil.getTextSize(type, textSize, hostConfig));
}

/**
* Applies given TextStyle to the given TextView
* @param textView TextView to apply style to
* @param style TextStyle to apply
*/
private static void applyTextStyle(TextView textView, final TextStyle style)
{
// Indicate Heading to accessibility service
// TODO: Refactor to ViewCompat.setAccessibilityHeading after AndroidX upgrade
ViewCompat.setAccessibilityDelegate(textView, new AccessibilityDelegateCompat() {
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
info.setHeading(style == TextStyle.Heading);
}
});
}

public void setTextFormat(TextView textView, HostConfig hostConfig, FontType type, TextWeight textWeight)
{
Typeface typeface = TextRendererUtil.getTextFormat(hostConfig, type, textWeight == TextWeight.Lighter);
Expand Down Expand Up @@ -201,6 +220,7 @@ public View render(
setTextSize(textView, textBlock.GetFontType(), textBlock.GetTextSize(), hostConfig);
setTextColor(textView, textBlock.GetTextColor(), hostConfig, textBlock.GetIsSubtle(), renderArgs.getContainerStyle());
setTextAlignment(textView, textBlock.GetHorizontalAlignment());
applyTextStyle(textView, textBlock.GetStyle());

int maxLines = (int)textBlock.GetMaxLines();
if (maxLines > 0 && textBlock.GetWrap())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
"lineColor": "#FF000000"
},
"actions": {
"maxActions": 6,
"maxActions": 7,
"spacing": "Default",
"buttonSpacing": 10,
"showCard": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ + (ACOAdaptiveCardParseResult *)fromJson:(NSString *)payload;
if (payload) {
try {
ACOAdaptiveCard *card = [[ACOAdaptiveCard alloc] init];
std::shared_ptr<ParseResult> parseResult = AdaptiveCard::DeserializeFromString(std::string([payload UTF8String]), std::string("1.4"));
std::shared_ptr<ParseResult> parseResult = AdaptiveCard::DeserializeFromString(std::string([payload UTF8String]), std::string("1.5"));
NSMutableArray *acrParseWarnings;
std::vector<std::shared_ptr<AdaptiveCardParseWarning>> parseWarnings = parseResult->GetWarnings();
for (const auto &warning : parseWarnings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ - (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup
// if html rendering is skipped, remove p tags from both ends (<p>, </p>)
content = [[NSMutableAttributedString alloc] initWithString:text attributes:descriptor];
}
lab.editable = NO;

lab.textContainer.lineFragmentPadding = 0;
lab.textContainerInset = UIEdgeInsetsZero;
lab.layoutManager.usesFontLeading = false;
Expand Down Expand Up @@ -121,6 +121,10 @@ - (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup
lab.textContainer.maximumNumberOfLines = 1;
}

if (txtBlck->GetStyle() == TextStyle::Heading) {
lab.accessibilityTraits |= UIAccessibilityTraitHeader;
}

[lab setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];

if (txtBlck->GetHeight() == HeightType::Auto) {
Expand Down
Loading

0 comments on commit 5627857

Please sign in to comment.