Skip to content

[Rendering][Android][Crash]: Fixed the scaling issues for background bitmaps #136

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rankush
Copy link
Contributor

@rankush rankush commented May 8, 2024

Related Issue

FIX FOR : #135

Description

Fixed Scaling Issues for Background Bitmaps

This commit includes significant enhancements to the BackgroundImageLoaderAsync.java file, specifically focusing on the scaling of background images.

Key changes include:

  1. Modification of the getScaleFactorForCover method to return an array of scale factors for both x and y dimensions instead of the maximum of the two. This allows for more precise scaling of the background image.

  2. Addition of checks to ensure that the scaled width and height of the image are not zero or less. This prevents potential crashes due to invalid bitmap dimensions.

  3. Update of the resizeBitmapForCover method to use the separate x and y scale factors when scaling the bitmap. This ensures that the bitmap is scaled correctly in both dimensions.

These changes aim to fix the scaling issues for background bitmaps in Adaptive Cards, improving the visual quality and preventing potential crashes.

Sample Card

{
  "type": "AdaptiveCard",
  "actions": [
    {
      "data": {
        "callback_keyword": "survey_response",
        "survey_name": "TACX WEEK"
      },
      "style": "positive",
      "title": "Submit",
      "type": "Action.Submit"
    }
  ],
  "backgroundImage": {
    "url": "https://www.iconsdb.com/icons/preview/color/ACA0B0/square-xxl.png"
  },
  "body": [
    {
      "items": [
        {
          "horizontalAlignment": "Center",
          "type": "Image",
          "url": "https://www.webex.com/content/dam/wbx/us/images/rebrand/webex-logo.png"
        },
        {
          "color": "accent",
          "horizontalAlignment": "center",
          "isSubtle": true,
          "size": "extraLarge",
          "text": "TACX WEEK",
          "type": "TextBlock",
          "weight": "bolder",
          "wrap": true
        },
        {
          "text": "Hey there! 🌟 Thanks a ton for diving into the TAC week extravaganza with us! 🎉 We hope you had a blast making new connections, trying out cool stuff, and most importantly, having a blast! 🤩 Now, let's keep that fun train rolling – your feedback is our fuel to make the next adventure even more awesome! 🚀 And hey, just so you know, your answers are in incognito as a superhero in disguise – totally **anonymous**! Ready to share your thoughts? Let's do this! 💪",
          "type": "TextBlock",
          "wrap": true
        },
        {
          "columns": [
            {
              "items": [
                {
                  "choices": [
                    {
                      "title": "MX 🇲🇽",
                      "value": "mexico"
                    },
                    {
                      "title": "RTP 🌳",
                      "value": "rtp"
                    },
                    {
                      "title": "RCDN 🏜️",
                      "value": "rcdn"
                    }
                  ],
                  "id": "site",
                  "isMultiSelect": false,
                  "isRequired": false,
                  "label": "1. What site are you from? 📍",
                  "placeholder": "Site",
                  "style": "compact",
                  "type": "Input.ChoiceSet"
                },
                {
                  "choices": [
                    {
                      "title": "East ➡️",
                      "value": "east"
                    },
                    {
                      "title": "West ⬅️",
                      "value": "West"
                    }
                  ],
                  "id": "shift",
                  "isMultiSelect": false,
                  "isRequired": false,
                  "label": "2. What shift are you from? 🧭",
                  "placeholder": "Shift",
                  "style": "compact",
                  "type": "Input.ChoiceSet"
                },
                {
                  "choices": [
                    {
                      "title": "Yes, Onsite 📍",
                      "value": "onsite"
                    },
                    {
                      "title": "Yes, Remote 💻",
                      "value": "remote"
                    },
                    {
                      "title": "Yes, Hybrid 🔄",
                      "value": "hybrid"
                    },
                    {
                      "title": "No 🚫",
                      "value": "no"
                    }
                  ],
                  "id": "attend",
                  "isMultiSelect": false,
                  "isRequired": false,
                  "label": "2. Were you able to attend to any of the sessions?",
                  "placeholder": "Select Option",
                  "style": "expanded",
                  "type": "Input.ChoiceSet"
                },
                {
                  "text": "Please rate each event:",
                  "type": "TextBlock",
                  "wrap": true
                }
              ],
              "type": "Column",
              "width": 1
            }
          ],
          "type": "ColumnSet"
        }
      ],
      "style": "emphasis",
      "type": "Container"
    },
    {
      "items": [
        {
          "horizontalAlignment": "Center",
          "size": "Large",
          "text": "Directory Photos 📸",
          "type": "TextBlock",
          "wrap": true
        },
        {
          "choices": [
            {
              "title": "Informative 📚",
              "value": "Informative"
            },
            {
              "title": "Fun 🎉",
              "value": "Fun"
            },
            {
              "title": "I would do it again 🔁",
              "value": "I would do it again"
            },
            {
              "title": "I learned something 🧠",
              "value": "I learned something"
            },
            {
              "title": "This will change the way I do things ✨",
              "value": "This will change the way I do things"
            },
            {
              "title": "N/A 🚫",
              "value": "N/A"
            }
          ],
          "id": "directory_photos_options",
          "isMultiSelect": true,
          "type": "Input.ChoiceSet"
        },
        {
          "id": "directory_photos_comments",
          "isMultiline": true,
          "isRequired": false,
          "label": "Any comments 💬",
          "maxLength": 0,
          "placeholder": "",
          "style": "text",
          "type": "Input.Text"
        }
      ],
      "spacing": "None",
      "style": "good",
      "type": "Container"
    },
    {
      "items": [
        {
          "horizontalAlignment": "Center",
          "size": "Large",
          "text": "Your Brand Creation 🎨",
          "type": "TextBlock",
          "wrap": true
        },
        {
          "choices": [
            {
              "title": "Informative 📚",
              "value": "Informative"
            },
            {
              "title": "Fun 🎉",
              "value": "Fun"
            },
            {
              "title": "I would do it again 🔁",
              "value": "I would do it again"
            },
            {
              "title": "I learned something 🧠",
              "value": "I learned something"
            },
            {
              "title": "This will change the way I do things ✨",
              "value": "This will change the way I do things"
            },
            {
              "title": "N/A 🚫",
              "value": "N/A"
            }
          ],
          "id": "brand_creation_options",
          "isMultiSelect": true,
          "type": "Input.ChoiceSet"
        },
        {
          "id": "brand_creation_comments",
          "isMultiline": true,
          "isRequired": false,
          "label": "Any comments 💬",
          "maxLength": 0,
          "placeholder": "",
          "style": "text",
          "type": "Input.Text"
        }
      ],
      "spacing": "None",
      "style": "accent",
      "type": "Container"
    },
    {
      "items": [
        {
          "horizontalAlignment": "Center",
          "size": "Large",
          "text": "Speed Mentoring 🏎️",
          "type": "TextBlock",
          "wrap": true
        },
        {
          "choices": [
            {
              "title": "Informative 📚",
              "value": "Informative"
            },
            {
              "title": "Fun 🎉",
              "value": "Fun"
            },
            {
              "title": "I would do it again 🔁",
              "value": "I would do it again"
            },
            {
              "title": "I learned something 🧠",
              "value": "I learned something"
            },
            {
              "title": "This will change the way I do things ✨",
              "value": "This will change the way I do things"
            },
            {
              "title": "N/A 🚫",
              "value": "N/A"
            }
          ],
          "id": "speed_mentoring_options",
          "isMultiSelect": true,
          "type": "Input.ChoiceSet"
        },
        {
          "id": "speed_mentoring_comments",
          "isMultiline": true,
          "isRequired": false,
          "label": "Any comments 💬",
          "maxLength": 0,
          "placeholder": "",
          "style": "text",
          "type": "Input.Text"
        }
      ],
      "spacing": "None",
      "style": "accent",
      "type": "Container"
    },
    {
      "items": [
        {
          "horizontalAlignment": "Center",
          "size": "Large",
          "text": "Cooking Competition ⏲️",
          "type": "TextBlock",
          "wrap": true
        },
        {
          "choices": [
            {
              "title": "Informative 📚",
              "value": "Informative"
            },
            {
              "title": "Fun 🎉",
              "value": "Fun"
            },
            {
              "title": "I would do it again 🔁",
              "value": "I would do it again"
            },
            {
              "title": "I learned something 🧠",
              "value": "I learned something"
            },
            {
              "title": "This will change the way I do things ✨",
              "value": "This will change the way I do things"
            },
            {
              "title": "N/A 🚫",
              "value": "N/A"
            }
          ],
          "id": "cooking_competition_options",
          "isMultiSelect": true,
          "type": "Input.ChoiceSet"
        },
        {
          "id": "cooking_competition_comments",
          "isMultiline": true,
          "isRequired": false,
          "label": "Any comments 💬",
          "maxLength": 0,
          "placeholder": "",
          "style": "text",
          "type": "Input.Text"
        }
      ],
      "spacing": "None",
      "style": "good",
      "type": "Container"
    },
    {
      "items": [
        {
          "horizontalAlignment": "Center",
          "size": "Large",
          "text": "AMA with our Senior Leaders ❓",
          "type": "TextBlock",
          "wrap": true
        },
        {
          "choices": [
            {
              "title": "Informative 📚",
              "value": "Informative"
            },
            {
              "title": "Fun 🎉",
              "value": "Fun"
            },
            {
              "title": "I would do it again 🔁",
              "value": "I would do it again"
            },
            {
              "title": "I learned something 🧠",
              "value": "I learned something"
            },
            {
              "title": "This will change the way I do things ✨",
              "value": "This will change the way I do things"
            },
            {
              "title": "N/A 🚫",
              "value": "N/A"
            }
          ],
          "id": "ama_senior_leaders_options",
          "isMultiSelect": true,
          "type": "Input.ChoiceSet"
        },
        {
          "id": "ama_senior_leaders_comments",
          "isMultiline": true,
          "isRequired": false,
          "label": "Any comments 💬",
          "maxLength": 0,
          "placeholder": "",
          "style": "text",
          "type": "Input.Text"
        }
      ],
      "spacing": "None",
      "style": "accent",
      "type": "Container"
    },
    {
      "items": [
        {
          "horizontalAlignment": "Center",
          "size": "Large",
          "text": "DM Corner 📄",
          "type": "TextBlock",
          "wrap": true
        },
        {
          "choices": [
            {
              "title": "Informative 📚",
              "value": "Informative"
            },
            {
              "title": "Fun 🎉",
              "value": "Fun"
            },
            {
              "title": "I would do it again 🔁",
              "value": "I would do it again"
            },
            {
              "title": "I learned something 🧠",
              "value": "I learned something"
            },
            {
              "title": "This will change the way I do things ✨",
              "value": "This will change the way I do things"
            },
            {
              "title": "N/A 🚫",
              "value": "N/A"
            }
          ],
          "id": "dm_corner_options",
          "isMultiSelect": true,
          "type": "Input.ChoiceSet"
        },
        {
          "id": "dm_corner_comments",
          "isMultiline": true,
          "isRequired": false,
          "label": "Any comments 💬",
          "maxLength": 0,
          "placeholder": "",
          "style": "text",
          "type": "Input.Text"
        }
      ],
      "spacing": "None",
      "style": "good",
      "type": "Container"
    },
    {
      "items": [
        {
          "horizontalAlignment": "Center",
          "size": "Large",
          "text": "Wellbeing Day / Fitness activities 💪",
          "type": "TextBlock",
          "wrap": true
        },
        {
          "choices": [
            {
              "title": "Informative 📚",
              "value": "Informative"
            },
            {
              "title": "Fun 🎉",
              "value": "Fun"
            },
            {
              "title": "I would do it again 🔁",
              "value": "I would do it again"
            },
            {
              "title": "I learned something 🧠",
              "value": "I learned something"
            },
            {
              "title": "This will change the way I do things ✨",
              "value": "This will change the way I do things"
            },
            {
              "title": "N/A 🚫",
              "value": "N/A"
            }
          ],
          "id": "wellbeing_day_fitness_activity_options",
          "isMultiSelect": true,
          "type": "Input.ChoiceSet"
        },
        {
          "id": "wellbeing_day_fitness_activity_comments",
          "isMultiline": true,
          "isRequired": false,
          "label": "Any comments 💬",
          "maxLength": 0,
          "placeholder": "",
          "style": "text",
          "type": "Input.Text"
        }
      ],
      "spacing": "None",
      "style": "accent",
      "type": "Container"
    },
    {
      "items": [
        {
          "horizontalAlignment": "Center",
          "size": "Large",
          "text": "Putt Putt Golf ⛳️",
          "type": "TextBlock",
          "wrap": true
        },
        {
          "choices": [
            {
              "title": "Informative 📚",
              "value": "Informative"
            },
            {
              "title": "Fun 🎉",
              "value": "Fun"
            },
            {
              "title": "I would do it again 🔁",
              "value": "I would do it again"
            },
            {
              "title": "I learned something 🧠",
              "value": "I learned something"
            },
            {
              "title": "This will change the way I do things ✨",
              "value": "This will change the way I do things"
            },
            {
              "title": "N/A 🚫",
              "value": "N/A"
            }
          ],
          "id": "putt_putt_golf_options",
          "isMultiSelect": true,
          "type": "Input.ChoiceSet"
        },
        {
          "id": "putt_putt_golf_comments",
          "isMultiline": true,
          "isRequired": false,
          "label": "Any comments 💬",
          "maxLength": 0,
          "placeholder": "",
          "style": "text",
          "type": "Input.Text"
        }
      ],
      "spacing": "None",
      "style": "good",
      "type": "Container"
    },
    {
      "items": [
        {
          "horizontalAlignment": "Center",
          "size": "Large",
          "text": "Bingo Bingo ⭐️ Technology Trivia",
          "type": "TextBlock",
          "wrap": true
        },
        {
          "choices": [
            {
              "title": "Informative 📚",
              "value": "Informative"
            },
            {
              "title": "Fun 🎉",
              "value": "Fun"
            },
            {
              "title": "I would do it again 🔁",
              "value": "I would do it again"
            },
            {
              "title": "I learned something 🧠",
              "value": "I learned something"
            },
            {
              "title": "This will change the way I do things ✨",
              "value": "This will change the way I do things"
            },
            {
              "title": "N/A 🚫",
              "value": "N/A"
            }
          ],
          "id": "bingo_bingo_technology_trivia_options",
          "isMultiSelect": true,
          "type": "Input.ChoiceSet"
        },
        {
          "id": "bingo_bingo_technology_trivia_comments",
          "isMultiline": true,
          "isRequired": false,
          "label": "Any comments 💬",
          "maxLength": 0,
          "placeholder": "",
          "style": "text",
          "type": "Input.Text"
        }
      ],
      "spacing": "None",
      "style": "accent",
      "type": "Container"
    },
    {
      "items": [
        {
          "horizontalAlignment": "Center",
          "size": "Large",
          "text": "TAC Hero Awards 🏆",
          "type": "TextBlock",
          "wrap": true
        },
        {
          "choices": [
            {
              "title": "Informative 📚",
              "value": "Informative"
            },
            {
              "title": "Fun 🎉",
              "value": "Fun"
            },
            {
              "title": "I would do it again 🔁",
              "value": "I would do it again"
            },
            {
              "title": "I learned something 🧠",
              "value": "I learned something"
            },
            {
              "title": "This will change the way I do things ✨",
              "value": "This will change the way I do things"
            },
            {
              "title": "N/A 🚫",
              "value": "N/A"
            }
          ],
          "id": "tac_hero_awards_options",
          "isMultiSelect": true,
          "type": "Input.ChoiceSet"
        },
        {
          "id": "tac_hero_awards_comments",
          "isMultiline": true,
          "isRequired": false,
          "label": "Any comments 💬",
          "maxLength": 0,
          "placeholder": "",
          "style": "text",
          "type": "Input.Text"
        }
      ],
      "spacing": "None",
      "style": "good",
      "type": "Container"
    },
    {
      "items": [
        {
          "horizontalAlignment": "Center",
          "size": "Large",
          "text": "Video Games 🕹️",
          "type": "TextBlock",
          "wrap": true
        },
        {
          "choices": [
            {
              "title": "Informative 📚",
              "value": "Informative"
            },
            {
              "title": "Fun 🎉",
              "value": "Fun"
            },
            {
              "title": "I would do it again 🔁",
              "value": "I would do it again"
            },
            {
              "title": "I learned something 🧠",
              "value": "I learned something"
            },
            {
              "title": "This will change the way I do things ✨",
              "value": "This will change the way I do things"
            },
            {
              "title": "N/A 🚫",
              "value": "N/A"
            }
          ],
          "id": "video_games_options",
          "isMultiSelect": true,
          "type": "Input.ChoiceSet"
        },
        {
          "id": "video_games_comments",
          "isMultiline": true,
          "isRequired": false,
          "label": "Any comments 💬",
          "maxLength": 0,
          "placeholder": "",
          "style": "text",
          "type": "Input.Text"
        }
      ],
      "spacing": "None",
      "style": "accent",
      "type": "Container"
    }
  ],
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.5"
}

How Verified

Verification of the Fix:

  1. Unit Tests:
    No new unit tests were added as this change is an enhancement and does not introduce new functionality that requires testing. The existing unit tests were sufficient to verify the correctness of the changes.

  2. Existing Tests:
    The existing unit and regression tests were run to ensure that the changes did not introduce any regressions. All tests passed successfully, indicating that the changes are stable and do not adversely affect existing functionality.

  3. Manual Verification:
    Manual testing was performed to verify the changes. This involved running the application and observing the rendering of background images in Adaptive Cards. The images were correctly scaled in both dimensions, and no crashes were observed. This confirms that the changes effectively fix the scaling issues for background bitmaps.

Please note that screenshots or .gif's are not included in this description, but they were used during the manual testing process to confirm the correct rendering of background images without any CRASH

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.

1 participant