Since this is a time constrained project with a lot of small geometry problem solving, I decided to work by quickly implementing imperfect solutions that work, adding some tests and then refactoring to make it cleaner
I ran a bit out of time so the refactor is not ideal and the test coverage is not great as well, also because a lot of the code relies on Android framework classes for graphical rendering which I partly abstracted away but not as much as I would like
I have not made a full architecture since the project is fairly small and I was time constrained but I tried to create a simple and usable API, similar to Glide
: Templater.get().load(R.raw.json).into(templateView)
Basically you get an instance of Templater
that you can use to load
a Template
(the objects defined in JSON) into
a TemplateView
In more details:
load
parses the Json into aTemplate
class that has its own logic to compute a list ofRectangle
that are a platform independent representation of a Canvas view- then in
into
,Templater
computes thoseRectangles
back into Android instances likeRect
,RectF
,Bitmap
, ... and gives them toTemplateView
TemplateView
then draws them on the canvas when it's ready (thanks to a custom setter withpostInvalidate()
)- bitmaps are drawn on the canvas with
drawBitmap(bitmap, src, dest, paint)
:src
describes the part of the bitmap that is projected anddest
is theRect
in which the bitmap is projected - The bitmap dragging handling is done inside of
TemplateView
:onTouch
, user inputs modifysrc
to offset the bitmap visible part.
I made a simple ServiceLocator
instead of a real Dependency Injection solution because it was enough for a small project
I focused mainly on offloading as much work as possible away from the main thread and from onDraw
so that it does only drawing, no allocations, etc
Ideally, I would have wanted to:
- correctly interface and inject classes to allow full test coverage
- remove most logic from
Template
and keep it as a simple data class - abstract the fragging logic away from
TemplateView
- extract all the "engine" code into its own module and keep
app
as just a sample - implementing two-finger gestures to scale bitmaps
- try to implement it in Compose !
KotlinX Serialization
to parse JSON with a simple syntaxGlide
to fetch images as Bitmaps easilyKotlin
Coroutines for simple async work- Picsum to fetch random images