Search code examples
androidinheritanceandroid-gallery

Subclassing Gallery widget to create "Ticker" behavior


This is mostly a philosophy question, as the actual problem is solved. The SDK provides a Gallery class. This Gallery is 90% of what I need, it's just missing 2 things. One I want to implement an extra Runnable that triggers periodic advances to the next item, and two I need it to animate the scroll between items.

The auto periodic advance was easy. However I came across major issues implementing the scoll animation between items. Now I've solved this by override setSelection to essential be a wrapper to onFling.

My background is primarily Python at this point, so this implementation feels kinda dirty to me. I'm calculating a velocity based on the parents width and then calling onFling(null, null, my_calculated_velocity, 0). This feels really wrong to me, what if for some reason the way google calculates distance from velocity changes?

Now I look through the source of Gallery, and I see tons of ways that feel a ton better to me: moveNext scrollToChild mFlingRunnable.startUsingDistance

None of which are accessible from a subclass of Gallery. In Python there is no real concept of private, so I find it frustrating to no end that when I subclass something in java I end up having to copy paste 2/3's of the class just to override a single behavior.

So the question is am I doing something wrong that's leading me to attempt to do things in ways that are against the Java grain or can I just expect to be frustrated everytime I sit down to work on an android project and find all the methods that do what I need to be be private or default, rather than public or protected?


Solution

  • Gallery is as previously mentioned not a very nice class to extend. A better way here would actually be just getting the source and using that.

    FYI the velocity DO change, if the device for some reason locks up momentarily.

    You are not doing something wrong, it's the class that is designed wrong/for something else.