Skip to content
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

[Android] Update input error visual cue rendering to support custom background drawables #4942

Merged
merged 24 commits into from
Oct 28, 2020

Conversation

almedina-ms
Copy link
Contributor

@almedina-ms almedina-ms commented Oct 20, 2020

An accident happened and #4895 got merged, redoing the PR
Fixes #4830

Description

Adds options to modify the rendering of the error visual cues for validated inputs. The original version of this feature only considered the default drawable which has a transparent background, due to this when tinting the background it could have unintended side effect such as tinting the whole background, such as in the example below

image

For this fix we added two new attributes called adaptiveUsingCustomTextInputs and adaptiveUsingCustomChoiceSetInputs.

  • adaptiveUsingCustomTextInputs: boolean flag that signalize the renderer to set the state_error with a value of true instead of tinting the text input background.
  • adaptiveUsingCustomChoiceSetInputs: boolean flag to control some internal rendering for compact choice sets. If the value is set to true but no background is provided results may vary

On the other hand we added a new drawable state called state_error which allows customers to define background drawables which define how an invalid input would look like

Finally, we also added two new drawable selector files adaptive_choiceset_compact_background.xml and adaptive_choiceset_expanded_background.xml:

  • compact drawable: controls the background for compact choicesets, if the adaptiveUsingCustomTextInputs flag is not set or set to false, the drawable is applied to a linear layout that encloses the spinner and is tinted in attention color.
  • expanded drawable: controls the background for expanded choicesets (mono and multi select) and the background for Toggle inputs. In all cases this background is tinted with the attention color to mimic the current JS and iOS behaviours.

How Verified

The fix was verified by adding the previously mentioned properties into our app theme (which will be modified for each of the examples below)

<item name="adaptiveUsingCustomTextInputs">true</item>
<item name="adaptiveUsingCustomChoiceSetInputs">true</item>
<item name="android:editTextBackground">@drawable/layered_edit_text_styles</item>

For reference, layered_edit_text_styles is a selector which only defines a drawable for invalid state and a default drawable

<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:adaptivecards="http://schemas.android.com/apk/res-auto" >
    <item adaptivecards:state_error="true" android:drawable="@drawable/layered_edit_text_invalid" />
    <item android:drawable="@drawable/layered_edit_text" />
</selector>

Example 1: No custom inputs

<item name="adaptiveUsingCustomTextInputs">false</item>
<!-- <item name="android:editTextBackground">@drawable/layered_edit_text_styles</item> -->

image

Example 2: Having a custom drawable, but stating that is not using custom inputs

<item name="adaptiveUsingCustomTextInputs">false</item>
<item name="android:editTextBackground">@drawable/layered_edit_text_styles</item>

image

NOTE: the image is tinted, as it has a semi transparent background color it tints it in a lighter shade of Attention color

Example 3: Having a custom drawable

<item name="adaptiveUsingCustomTextInputs">true</item>
<item name="android:editTextBackground">@drawable/layered_edit_text_styles</item>

image

Example 4: Default behavior for choiceset and toggle input validations

<item name="adaptiveUsingCustomChoiceSetInputs">false</item>

Also, the default behaviour for choiceset inputs validation has changed to show a border around the inputs

image

Toggle Input has changed too

image

And the default behaviour of compact choice set is as follows

image

Example 5: Overriding a compact choiceset

styles.xml

<item name="adaptiveUsingCustomChoiceSetInputs">true</item>

The default background drawable for spinners can be updated by creating a file called adaptive_choiceset_compact_background.xml in the drawables folder, in this file an state_error flag can be set in the selector to define how the compact choice set should look like

adaptive_choiceset_compact_background.xml in drawables folder

<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:adaptivecards="http://schemas.android.com/apk/res-auto">
    <item adaptivecards:state_error="true">
        <layer-list android:opacity="transparent">
            <item android:gravity="left" android:width="300dp" android:end="300dp">
                <shape>
                    <solid android:color="@color/colorWhite">
                    </solid>
                </shape>
            </item>
            <item android:gravity="left" android:width="100dp" android:start="300dp">
                <shape>
                    <solid android:color="@color/colorAccent">
                    </solid> 
                </shape>
            </item>
            <item android:width="100dp" android:start="300dp" android:height="40dp">
                <bitmap android:src="@drawable/cat1" android:gravity="fill"/>
            </item>
        </layer-list>
    </item>
</selector>

image

Example 6: Overriding the rendering of expanded choicesets

The rendering for the expanded choice set and toggle inputs can also be modified (in this case no flag is required), the only consideration is that the border is always tinted with the attention color to keep consistency. As can be seen in the image below, the corners can be changed to be more rounded or change the width of the enclosing rectangle

image

Microsoft Reviewers: Open in CodeFlow

@shalinijoshi19
Copy link
Member

shalinijoshi19 commented Oct 23, 2020

@almedina-ms this is running into asome Android build failures

@shalinijoshi19
Copy link
Member

@jwoo-msft is this actually going into 20.10?

Copy link
Member

@golddove golddove left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think we should try to detect custom input rather than requiring a flag, but this is something we can revisit in the future, as it wouldn't be a breaking change.

@almedina-ms almedina-ms added this to the 20.10 milestone Oct 26, 2020
@ghost ghost added the AdaptiveCards v20.10 label Oct 26, 2020
@almedina-ms almedina-ms merged commit 0f95107 into main Oct 28, 2020
@almedina-ms almedina-ms deleted the user/almedina-ms/Android_UpdateErrorCue branch October 28, 2020 00:29
rankush pushed a commit to rankush/AdaptiveCards that referenced this pull request May 8, 2024
…ackground drawables (microsoft#4942)

* Save Container Card Id in RenderArgs constructor

* Change input hint to rectangle around input

* Change edit text style in case we ever need it

* Udate visual cues and add support for custom inputs

* Clean PR a little bit

* Add visual cues for choice elements

* Update API to support compact choiceset styling

* Add visual cues for choice elements (microsoft#4940)

* Add samples in mobile app

* Add first changes

* Fix PR comments regarding API documentation and new lines

* Update name for error state

* Update the implementation for a better merge

Co-authored-by: Paul Campbell <paulcam@microsoft.com>
Co-authored-by: shalinijoshi19 <shalinij@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android][Input validation error] [Input validation error UX]
4 participants