NOTE: the actual question(s) is in the What my questions are
section. The other sections are provided for giving better overview of the problem.
TASK
I want to decorate Android view using the Decorator design pattern. For my question I will be using decorating ViewPager
as an example, but I believe the solution will be more general.
WHY DO I NEED IT
I want to be able to reuse different augmentations on the standard views in different solutions of mine. E.g. now I have timer-switching ViewPager
and ViewPager
that notifies me when the user reaches its end. With this solution I am aiming at adding auto-switching notifying ViewPager
(i.e. combining both my current extensions) in my next solution a one-liner. Decorator pattern is exactly for that.
WHAT MY CURRENT APPROACH IS
ViewPager
in ViewPagerDecorator
I also did the desired extensions of the decorator - AutoSwitchViewPager
and NotifyOutOfBoundsViewPager
(based on this). Now I can even do
new AutoSwitchViewPager(new NotifyOutOfBoundsViewPager(viewPager))
.
ViewPager
from layout propagating its xml attributes to the decorated view.WHAT MY QUESTIONS ARE
LayoutParameters
at least)ViewStub
, but I did not find a way to inflate ViewStub
with something completely run-time constructed (without using xml Layout). Is there such a way?WHAT HAVE I READ
I have stumbled upon these related resources:
After weeks of struggle and applying few different design approaches I think that I finally got the solution! As the solution is not as easy to explain as to fit in SO post I created a blog post to explain all my struggles. I also accompany my explanations with source code to demonstrate my ideas available here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With