New feature: TitleBarIndicator can now split titles around their center #104
Conversation
…split around their center point. This is useful if you don't know in advance how long your page labels are going to be, or if you have long titles that constantly bump into one another.
That method was barely readable anymore, so I broke some key code paths down into smaller methods.
Jake Wharton » Android-ViewPagerIndicator #4 FAILURE |
I get that same build failure on my dev machine, but I think it's unrelated to my commits. It's missing an artifact which is flagged as deprecated on the project page: Failed to execute goal on project sample: Could not resolve dependencies for project com.viewpagerindicator:sample:apk:2.3.1: Could not find artifact com.directionalviewpager:library:jar:1.2.0 |
It's fixed on the |
Thanks Jake--if you're interested, here's a screendump of how it looks like: https://skitch.com/kaeppler/en6cc/title-bar-indicator I'm still trying to figure out how to make fading edges work (I think the custom onDraw breaks that), but that's unrelated. |
Hold on with merging this back actually, I have a very small patch upcoming that will make fading edges work. This goes very well visually with the TitleBarIndicator and the centerClip so I guess it's fine to merge this as part of centerClip. |
You can enable fading edges using standard Android attributes: android:fadingEdge="horizontal" android:fadingEdgeLength="30dp" There is one additional attribute that is usually computed by Android by inspecting scroll state, but since there is no scrolling in TitlePageIndicator, we need to inject this manually via a custom attribute: fadingEdgeStrength="0.5" This is a value between 0 and 1, and defaults to 1. It affects how long/strong the fading effect is.
Jake Wharton » Android-ViewPagerIndicator #5 FAILURE |
Hey Jake, have you had a chance to review this? We're about to release it with our app next week. |
One thing to note: to enable fading edges, one must use a different Android attribute on ICS and beyond. On Gingerbread, one must set In our app I simply set both in the style sheet to make sure it works on all platform versions (or alternatively, provide a custom v14 style sheet.) |
Cherry-picking the b0d029d commit worked great for me to add faded edges to my app. It might be good to add something to the sample app demonstrating this behavior since it's not immediately obvious that it's possible. |
I'm trying to bring in your fading-edge stuff now but it has a few problems:
|
private void clipToCenter(Rect curViewBound, int edge) { | ||
int width = curViewBound.width(); | ||
curViewBound.left = (int) (edge - (width / 2)); | ||
curViewBound.right = (int) (edge + (width / 2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't calculate width / 2
twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seriously? I think this makes it easier to read than using a halfWidth or widthByTwo variable, and I don't think the CPU will sweat over dividing a number by 2...
If you feel strong about it, I can change it though. I usually code with the mindset to strive for easier readability of code rather than micro improving expressions that the JVM will optimize away anyway.
I would've preferred these three commit as separate pull requests. Much easier to review and get merged. |
Yeah sorry for that, will keep that in mind. To answer your other remarks: ad 1) Yes of course it does, to get fading edges, you enable it first... that's how it works in all Android widgets that support fading edges. The strength attribute is merely a modifier when fading edges are enabled and it defaults to a standard value so setting it is not mandatory. See http://developer.android.com/reference/android/R.attr.html#fadingEdge and fadingEdgeLength for an equivalent example. ad 2) Good point, I'll add them. ad 3) Why not? It would be odd to fade the text, but not the underline. The fading edge effect in Android always fades everything. We should stick to that behavior. |
The underline serves as a static divider between the titlepager and the content. It doesn't make sense to fade it, plus it'll look horrible. |
bump |
New attribute clipToCenter[BOOL] makes titles in TitlePageIndicator split around their center point.
This is useful if you don't know in advance how long your page labels are going to be, or if you have long titles that constantly bump into one another.
First commit contains all the feature changes. The second commit contains a code refactoring, since I found onDraw was barely legible anymore.
Tested on Nexus One and Galaxy Nexus.
I couldn't add a sample Activity, since the sample app doesn't compile for me. I think I opened an issue for that already.