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

RMET-2912 OSBarcodeLib-Android - Screen UI for Tablet and only scan frame area #10

Merged
merged 23 commits into from
Dec 7, 2023

Conversation

alexgerardojacinto
Copy link
Collaborator

@alexgerardojacinto alexgerardojacinto commented Dec 6, 2023

Description

  • This PR adds two different things:
    • Screen UI for tablets, for both portrait and landscape orientations.
    • Cropping each image to be analysed either with MLKit or ZXing, so that only the frame area is scanned.
      • This also required some refactored, so that we use Bitmap objects for both libraries. Before, we were only using bitmaps for ZXing, because MLKit can deal with ImageProxy objects. Since we want to crop the image, we need to use a Bitmap. This way, we also avoid code repetition.
  • The PR also includes the necessary unit tests.

Context

References: https://outsystemsrd.atlassian.net/browse/RMET-2912

Type of changes

  • Fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Refactor (cosmetic changes)
  • Breaking change (change that would cause existing functionality to not work as expected)

Platforms affected

  • Android
  • iOS
  • JavaScript

Tests

MABS 9 build: https://intranet.outsystems.net/MABS/BuildDetail.aspx?BuildId=ed8778ad27785e820008bbd3ffcc4ea52e3e0f62
MABS 10 build: https://intranet.outsystems.net/MABS/BuildDetail.aspx?BuildId=5c41618abb4ebfa0044ef94a00a88bfa971e5153

Tested in Pixel 7 with Android 14, and Pixel C tablet emulator with Android 14.

Screenshots (if appropriate)

UI for Tablets:

Portrait

Screenshot 2023-12-06 at 17 53 10

Landscape

Screenshot 2023-12-06 at 17 52 29

Only scan the frame area:

screen-20231206-180638.mp4

Checklist

  • Pull request title follows the format RNMT-XXXX <title>
  • Code follows code style of this project
  • CHANGELOG.md file is correctly updated
  • Changes require an update to the documentation
    • Documentation has been updated accordingly

Context: According to Android's documentation, we should use the Window size classes to determine if the device the app is running on is a phone or a tablet. When in Portrait, we should use the window width to determine this (99.96% of phones will have a compact width). When in Landscape, the height of the window should be used (99.78% of phones will have a compact height). More info here: https://developer.android.com/guide/topics/large-screens/support-different-screen-sizes#window_size_classes, and here: https://developer.android.com/jetpack/compose/layouts/adaptive

References: https://outsystemsrd.atlassian.net/browse/RMET-2912
Context: According to Android's documentation, we should use the Window size classes to determine if the device the app is running on is a phone or a tablet. When in Portrait, we should use the window width to determine this (99.96% of phones will have a compact width). When in Landscape, the height of the window should be used (99.78% of phones will have a compact height). More info here: https://developer.android.com/guide/topics/large-screens/support-different-screen-sizes#window_size_classes, and here: https://developer.android.com/jetpack/compose/layouts/adaptive

Why we are using the landscape UI (ScanScreenUILandscape) for tablets for both orientations, portrait and landscape: because for tablets, the arrangement of the elements in the screen is always the same, in a row, where the buttons are to the right of the scan area (rectangle). This way, we can avoid code repetition.

References: https://outsystemsrd.atlassian.net/browse/RMET-2912
Context: Since we want to "crop" the image passed to analyze, we need to use a Bitmap object to represent the image, so that we can "crop" it. This wouldn't be possible using the ImageProxy object directly.

References: https://outsystemsrd.atlassian.net/browse/RMET-2912
Context: Since we want to "crop" the image passed to analyze, we need to use a Bitmap object to represent the image, so that we can "crop" it. This wouldn't be possible using the ImageProxy object directly. Since both libraries (ZXing and MLKit) now use a Bitmap, we might as well refactor the code and avoid code repetition.

References: https://outsystemsrd.atlassian.net/browse/RMET-2912
Context: Since we only want to look for barcodes within the frame, we need to crop the image (bitmap) to analyze, before passing it to MLKit or ZXing.

References: https://outsystemsrd.atlassian.net/browse/RMET-2912https://outsystemsrd.atlassian.net/browse/RMET-2912
@alexgerardojacinto alexgerardojacinto changed the title Feat/rmet 2912/screen tablet RMET-2912 OSBarcodeLib-Android - Screen UI for Tablet and only scan frame area Dec 6, 2023
val image = InputImage.fromMediaImage(
mediaImage,
val image = InputImage.fromBitmap(
imageBitmap,
imageProxy.imageInfo.rotationDegrees
)
runBlocking {

Choose a reason for hiding this comment

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

Is needed to use runBlocking here when MLKit already provides the async work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right, nice catch! We don't need to use runBlocking in this case. I think we used to have more code after scanner.process(image) and so that's why it had the runBlocking.

Context: The call to scanner.process is asynchronous, as it should be. As such, we don't need to use runBlocking here.

References: https://outsystemsrd.atlassian.net/browse/RMET-2912
Copy link

sonarcloud bot commented Dec 7, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@alexgerardojacinto alexgerardojacinto merged commit 2880eec into development Dec 7, 2023
7 checks passed
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.

4 participants