Skip to content

Commit

Permalink
Fix Button spacing issues and add horizontal scroll view in case acti…
Browse files Browse the repository at this point in the history
…ons orientation is horizontal . (#1452)

* fix button spacing bugs and add horizontal scroll view to buttons

* fix blank line

* add scrollview only if actions alignment is horizontal

* add comments

* added check to see if selected item is within range

* improve fact set renderer

* remove unnecessary changes
  • Loading branch information
rednivrug15 authored and Gilles Khouzam committed May 21, 2018
1 parent 1383df4 commit 3cc71a8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.adaptivecards.objectmodel.BaseCardElementVector;
import io.adaptivecards.objectmodel.ContainerStyle;
import io.adaptivecards.objectmodel.HostConfig;
import io.adaptivecards.objectmodel.Spacing;
import io.adaptivecards.renderer.action.ActionElementRenderer;
import io.adaptivecards.renderer.actionhandler.ICardActionHandler;
import io.adaptivecards.renderer.http.HttpRequestHelper;
Expand Down Expand Up @@ -244,6 +245,11 @@ else if (alignment == ActionAlignment.Center.swigValue())
actionButtonsLayout.setOrientation(LinearLayout.HORIZONTAL);
}


Spacing spacing = hostConfig.getActions().getSpacing();
/* Passing false for seperator since we do not have any configuration for seperator in actionsConfig */
BaseCardElementRenderer.setSpacingAndSeparator(context, viewGroup, spacing, false, hostConfig, true /* Horizontal Line */);

if (viewGroup != null)
{
if(actionButtonsLayoutOrientation == ActionsOrientation.Horizontal.swigValue())
Expand All @@ -267,6 +273,15 @@ else if (alignment == ActionAlignment.Center.swigValue())
ActionElementRenderer.getInstance().render(renderedCard, context, fragmentManager, actionButtonsLayout, actionElement, cardActionHandler, hostConfig);
}

if (viewGroup != null && hostConfig.getActions().getActionsOrientation().swigValue() == ActionsOrientation.Horizontal.swigValue())
{
HorizontalScrollView horizontalScrollView = new HorizontalScrollView(context);
horizontalScrollView.setHorizontalScrollBarEnabled(false);
viewGroup.removeView(actionButtonsLayout);
horizontalScrollView.addView(actionButtonsLayout);
viewGroup.addView(horizontalScrollView);
}

if (i >= maxActions && size != maxActions)
{
renderedCard.addWarning(new AdaptiveWarning(AdaptiveWarning.MAX_ACTIONS_EXCEEDED, "A maximum of " + maxActions + " actions are allowed"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public Button renderButton(
if (orientation == ActionsOrientation.Horizontal)
{
layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
long spacing = hostConfig.getActions().getButtonSpacing();
layoutParams.rightMargin = Util.dpToPixels(context, spacing);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public String getInput()
{
// no need to validate
ChoiceSetInput choiceSetInput = (ChoiceSetInput) m_baseInputElement;
return (String) getSpinner().getSelectedItem();
int index = getSpinner().getSelectedItemPosition();
String selectedItem = "";
if (index >= 0 && index < choiceSetInput.GetChoices().size())
{
selectedItem = choiceSetInput.GetChoices().get(index).GetValue();
}
return selectedItem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
Expand Down Expand Up @@ -40,7 +41,7 @@ public static FactSetRenderer getInstance()
return s_instance;
}

static TextView createTextView(Context context, String text, TextConfig textConfig, HostConfig hostConfig, long spacing, ContainerStyle containerStyle)
static TextView createTextView(Context context, String text, TextConfig textConfig, HostConfig hostConfig, long spacing, ContainerStyle containerStyle, boolean isValue)
{
TextView textView = new TextView(context);
textView.setText(text);
Expand All @@ -51,10 +52,18 @@ static TextView createTextView(Context context, String text, TextConfig textConf
textView.setSingleLine(!textConfig.getWrap());
textView.setMaxWidth(Util.dpToPixels(context, textConfig.getMaxWidth()));
textView.setEllipsize(TextUtils.TruncateAt.END);

GridLayout.LayoutParams parem = new GridLayout.LayoutParams(
GridLayout.spec(GridLayout.UNDEFINED),
GridLayout.spec(GridLayout.UNDEFINED));

parem.rightMargin = (int) spacing;
if (isValue)
{
parem.width = 0;
parem.setGravity(Gravity.FILL_HORIZONTAL);
}

textView.setLayoutParams(parem);
return textView;
}
Expand Down Expand Up @@ -93,8 +102,8 @@ else if ((factSet = FactSet.dynamic_cast(baseCardElement)) == null)
for (int i = 0; i < factVectorSize; i++)
{
Fact fact = factVector.get(i);
gridLayout.addView(createTextView(context, fact.GetTitle(), hostConfig.getFactSet().getTitle(), hostConfig, spacing, containerStyle));
gridLayout.addView(createTextView(context, fact.GetValue(), hostConfig.getFactSet().getValue(), hostConfig, 0, containerStyle));
gridLayout.addView(createTextView(context, fact.GetTitle(), hostConfig.getFactSet().getTitle(), hostConfig, spacing, containerStyle, false));
gridLayout.addView(createTextView(context, fact.GetValue(), hostConfig.getFactSet().getValue(), hostConfig, 0, containerStyle, true));
}

viewGroup.addView(gridLayout);
Expand Down

0 comments on commit 3cc71a8

Please sign in to comment.