Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-20267] Android: fix slider track showing #8863

Merged
merged 2 commits into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@Kroll.proxy(creatableInModule=UIModule.class, propertyAccessors = {
"min", "max", "minRange",
"maxRange", "thumbImage",
TiC.PROPERTY_SPLIT_TRACK,
"leftTrackImage","rightTrackImage",
TiC.PROPERTY_VALUE
})
Expand All @@ -25,6 +26,7 @@ public class SliderProxy extends TiViewProxy
public SliderProxy()
{
super();
defaultValues.put(TiC.PROPERTY_SPLIT_TRACK, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ public void processProperties(KrollDict d)
} else {
maxRange = max;
}

if (d.containsKey("thumbImage")) {
updateThumb(seekBar, d);
}

if (d.containsKey(TiC.PROPERTY_SPLIT_TRACK)) {
seekBar.setSplitTrack(TiConvert.toBoolean(d.get(TiC.PROPERTY_SPLIT_TRACK)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you guard this line to apply only for API 21 and above? It causes crashes on lower levels since it was added for Lollipop.

https://developer.android.com/reference/android/widget/AbsSeekBar.html#setSplitTrack(boolean)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch Yordan.

We also have to watch out in case the property value is not a boolean. So, the code should look something like this...

if (Build.VERSION.SDK_INT  >= 21) {
	ApiLevel21.setSplitTrack(this.seekBar, TiConvert.toBoolean([[value]], false));
}

private static class ApiLevel21
{
	private ApiLevel21() {}

	public void setSplitTrack(SeekBar seekBar, boolean enabled)
	{
		if (seekBar != null) {
			seekBar.setSplitTrack(enabled);
		}
	}
}

The static inner class above avoids the opcode warning on the lower API levels.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
if (d.containsKey("leftTrackImage") || d.containsKey("rightTrackImage")) {
updateTrackingImages(seekBar, d);
}
Expand Down Expand Up @@ -267,6 +268,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
//updateThumb(seekBar, proxy.getDynamicProperties());
//seekBar.invalidate();
Log.i(TAG, "Dynamically changing thumbImage is not yet supported. Native control doesn't draw");
} else if (key.equals(TiC.PROPERTY_SPLIT_TRACK)) {
seekBar.setSplitTrack(TiConvert.toBoolean(newValue));
} else if (key.equals("leftTrackImage") || key.equals("rightTrackImage")) {
//updateTrackingImages(seekBar, proxy.getDynamicProperties());
//seekBar.invalidate();
Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,11 @@ public class TiC
*/
public static final String PROPERTY_SPLIT_ACTIONBAR = "splitActionBar";

/**
* @module.api
*/
public static final String PROPERTY_SPLIT_TRACK = "splitTrack";

/**
* @module.api
*/
Expand Down
7 changes: 7 additions & 0 deletions apidoc/Titanium/UI/Slider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,13 @@ properties:
type: String
platforms: [iphone, ipad]

- name: splitTrack
summary: Separates the thumbImage from the slider track.
type: Boolean
default: false
since: 6.2.0
platforms: [android]

- name: thumbImage
summary: Image for the slider thumb.
description: |
Expand Down