0

I'm developing an android application by following the Clean Architecture by uncle bob. One of the principles of the clean architecture is the Domain layer uses "pure java" and don't use android classes to increase test-ability. My problem is that one of my use cases should receive Bitmap as input and Bitmap exists only under the android package which is not available to me. my data layer should receive the Bitmap from the domain layer. Is there an object to bridge between the java and android packages?

Ofek Regev
  • 467
  • 4
  • 18
  • `java.awt.image.BufferedImage` might be the closest equivalent. those just cannot be casted; but could extend either `Bitmap` or `BufferedImage` and add method `.toBufferedImage()` or `.toBitmap()`. – Martin Zeitler Mar 04 '19 at 16:11

2 Answers2

4

Overall using bitmap can be considered as the exceptional case and it is ok to use it in domain layer.

But if it is not ok for you then there are 3 possible solutions for this case:

1) You can use bitmap file path or resource id in domain layer if it is possible and then retrive needed bitmap in view, data layers.

2) You can create wrapper class which includes bitmap as field and use it in domain layer.

3) Convert it to ByteBuffer/ByteArray and use it in domain layer.

Valerii
  • 395
  • 1
  • 2
  • 8
  • I've considered using bytebuffer but 2 way conversion seems to be an expensive operation. using the string path is not an option because the bitmap is not a file. and creating a wrapper is probably impossible because my domain layer is a java lib which means no android package classes... – Ofek Regev Mar 05 '19 at 07:24
0

So after a bit of digging I've found this answer which helped me import the android sdk packages to a java library. So if you're facing the same problem of using android sdk in java library tha's the solution I used. Note: when importing the android.jar your java library cannot be used outside of android application.

Ofek Regev
  • 467
  • 4
  • 18