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] Adding support for RatingInput and readOnly Rating Element #144

Merged
merged 18 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
200ca69
Merge branch 'main' of https://github.com/microsoft/AdaptiveCards-Mobile
singhmanp0707 May 17, 2024
473b954
Merge branch 'abhipandey/rating_element' of https://github.com/micros…
singhmanp0707 May 17, 2024
15a9c79
swig changes
singhmanp0707 May 20, 2024
027f375
Revert "swig changes"
singhmanp0707 May 20, 2024
970f024
Merge branch 'abhipandey/rating_element' of https://github.com/micros…
singhmanp0707 May 22, 2024
d99e21f
Merge branch 'abhipandey/rating_element' of https://github.com/micros…
singhmanp0707 May 22, 2024
86e7129
Merge branch 'abhipandey/rating_element' of https://github.com/micros…
singhmanp0707 May 23, 2024
e922852
implementation of rating element
singhmanp0707 May 23, 2024
957a65b
support count for default style for read only rating element
singhmanp0707 May 23, 2024
95040cf
revert gradle.properties version change
singhmanp0707 May 23, 2024
e394cb6
set state to activated for read only stars
singhmanp0707 May 23, 2024
b95fdb7
Merge branch 'abhipandey/rating_element' of https://github.com/micros…
singhmanp0707 May 27, 2024
0a43a20
Merge branch 'main' of https://github.com/microsoft/AdaptiveCards-Mob…
singhmanp0707 May 30, 2024
3c64c59
addressed review comments
singhmanp0707 May 30, 2024
9ee53af
added default case in switch statement
singhmanp0707 May 31, 2024
926774b
addressed review comments
singhmanp0707 May 31, 2024
24f120b
addressed review comments
singhmanp0707 Jun 3, 2024
7009428
Merge branch 'main' of https://github.com/microsoft/AdaptiveCards-Mob…
singhmanp0707 Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions samples/HostConfig/microsoft-teams-dark.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,33 @@
"warp": true
},
"spacing": 16
}
}
},
"ratingInput": {
"filledStar": {
"marigoldColor": "#F2C661",
"neutralColor": "#E1E1E1"
},

"emptyStar": {
"marigoldColor": "#F2C661",
"neutralColor": "#E1E1E1"
},

"ratingTextColor": "#000000",
"countTextColor": "#000000"
},
"ratingLabel": {
"filledStar": {
"marigoldColor": "#EAA300",
"neutralColor": "#E1E1E1"
},

"emptyStar": {
"marigoldColor": "#835B00",
"neutralColor": "#404040"
},

"ratingTextColor": "#E1E1E1",
"countTextColor": "#E1E1E1"
}
}
32 changes: 30 additions & 2 deletions samples/HostConfig/microsoft-teams-light.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,33 @@
"warp": true
},
"spacing": 16
}
}
},
"ratingInput": {
"filledStar": {
"marigoldColor": "#EAA300",
"neutralColor": "#212121"
},

"emptyStar": {
"marigoldColor": "#EAA300",
"neutralColor": "#212121"
},

"ratingTextColor": "#000000",
"countTextColor": "#000000"
},
"ratingLabel": {
"filledStar": {
"marigoldColor": "#EAA300",
"neutralColor": "#242424"
},

"emptyStar": {
"marigoldColor": "#F9E2AE",
"neutralColor": "#E1E1E1"
},

"ratingTextColor": "#000000",
"countTextColor": "#000000"
}
}
72 changes: 72 additions & 0 deletions samples/v1.5/Scenarios/RatingInput.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"type": "AdaptiveCard",
"$schema": "https://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.5",
"body": [
{
"type": "TextBlock",
"size": "Large",
"text": "Rating input"
},
{
"type": "Input.Rating",
"id": "rating1",
"size": "medium",
"isRequired": true,
"label": "Pick a rating",
"errorMessage": "Please pick a rating",
"horizontalAlignment": "left",
"max": 5
},
{
"type": "Input.Rating",
"id": "rating2",
"label": "Pick a rating",
"size": "large",
"isRequired": true,
"errorMessage": "Please pick a rating",
"color": "marigold",
"value": 2,
"horizontalAlignment": "left",
"max": 5
},
{
"type": "TextBlock",
"size": "large",
"text": "Read-only ratings",
"separator": true,
"spacing": "extraLarge"
},
{
"type": "Rating",
"value": 3.2,
"size": "medium",
"horizontalAlignment": "left",
"count": 10
},
{
"type": "Rating",
"max": 20,
"value": 3.2,
"color": "marigold",
"size": "large",
"horizontalAlignment": "left",
"count": 150
},
{
"type": "Rating",
"style": "compact",
"value": 3.2,
"color": "marigold",
"count": 1500,
"size": "large",
"horizontalAlignment": "left"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Submit"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ open class FluentIconImageLoaderAsync(
private fun getDrawableFromSVG(svgString: String, context: Context): BitmapDrawable {
val svg = parseSvgString(context, svgString)
val picture = svg.renderToPicture()
var bitmap = Bitmap.createBitmap(picture.width, picture.height, Bitmap.Config.ARGB_8888)
val bitmap = Bitmap.createBitmap(picture.width, picture.height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
picture.draw(canvas)
var drawable = BitmapDrawable(context.resources, bitmap)
val color = Color.parseColor(iconColor)
val drawable = BitmapDrawable(context.resources, bitmap)
val color = try {
Color.parseColor(iconColor)
} catch (e: IllegalArgumentException) {
Color.BLACK
}
drawable.setColorFilter(color, android.graphics.PorterDuff.Mode.SRC_IN)
return drawable
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package io.adaptivecards.renderer.input

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.fragment.app.FragmentManager
import io.adaptivecards.objectmodel.BaseCardElement
import io.adaptivecards.objectmodel.HostConfig
import io.adaptivecards.objectmodel.RatingInput
import io.adaptivecards.renderer.BaseCardElementRenderer
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.renderer.inputhandler.InputUtils.updateInputHandlerInputWatcher
import io.adaptivecards.renderer.inputhandler.RatingInputHandler
import io.adaptivecards.renderer.layout.RatingStarInputView
import io.adaptivecards.renderer.readonly.RatingElementRendererUtil

/**
* Renderer for rating input element
**/
object RatingInputRenderer: BaseCardElementRenderer() {
override fun render(
renderedCard: RenderedAdaptiveCard,
context: Context,
fragmentManager: FragmentManager,
viewGroup: ViewGroup,
baseCardElement: BaseCardElement,
cardActionHandler: ICardActionHandler?,
hostConfig: HostConfig,
renderArgs: RenderArgs
): View {
val ratingInput = Util.castTo(baseCardElement, RatingInput::class.java)
val ratingInputHandler = RatingInputHandler(ratingInput, renderedCard, renderArgs.containerCardId)
val view = RatingStarInputView(
context,
hostConfig,
ratingInput
) as LinearLayout
RatingElementRendererUtil.applyHorizontalAlignment(view, ratingInput.GetHorizontalAlignment(), renderArgs)
ratingInputHandler.setView(view)
renderedCard.registerInputHandler(ratingInputHandler, renderArgs.containerCardId)
ratingInputHandler.updateInputHandlerInputWatcher()
view.tag = TagContent(ratingInput, ratingInputHandler)
viewGroup.addView(view)
return view
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package io.adaptivecards.renderer.inputhandler

import android.view.accessibility.AccessibilityEvent
import io.adaptivecards.objectmodel.BaseInputElement
import io.adaptivecards.objectmodel.RatingInput
import io.adaptivecards.renderer.RenderedAdaptiveCard
import io.adaptivecards.renderer.Util
import io.adaptivecards.renderer.layout.RatingStarInputView
import io.adaptivecards.renderer.layout.RatingStarInputViewListener

/**
* Input handler for Rating input
**/
class RatingInputHandler(
baseInputElement: BaseInputElement,
renderedAdaptiveCard: RenderedAdaptiveCard?,
cardId: Long
): BaseInputHandler(baseInputElement, renderedAdaptiveCard, cardId) {

override fun getInput() = (m_view as RatingStarInputView).getRating().toString()

override fun setInput(input: String) {
try {
(m_view as RatingStarInputView).setRating(input.toDouble())
} catch(e: NumberFormatException) {
return
}
}

override fun setFocusToView() {
val focusView = (m_view as RatingStarInputView).getChildAt(0)
Util.forceFocus(focusView)
focusView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED)
}

override fun isValid(showError: Boolean): Boolean {
var isValid = true
if (m_baseInputElement.GetIsRequired()) {
isValid = try {
input.toDouble() > 0
} catch(e: NumberFormatException) {
false
}
}
isValid = isValid && isValidOnSpecifics(input)
if (showError) {
showValidationErrors(isValid)
}
return isValid
}

override fun resetValue() {
val ratingInput = Util.castTo(m_baseInputElement, RatingInput::class.java)
input = ratingInput.GetValue().toString()
singhmanp0707 marked this conversation as resolved.
Show resolved Hide resolved
}

override fun registerInputObserver() {
(m_view as RatingStarInputView).setRatingStarInputViewListener(object: RatingStarInputViewListener {
override fun onRatingChanged() {
notifyAllInputWatchers()
}
})
singhmanp0707 marked this conversation as resolved.
Show resolved Hide resolved
addValueChangedActionInputWatcher()
}
}
Loading