From f794c4f19e6ef6066dfc9f67c2126b55c40f684b Mon Sep 17 00:00:00 2001 From: vishalduggal Date: Thu, 26 Feb 2015 09:56:37 -0800 Subject: [PATCH 1/4] [TIMOB-18363] Stop using deprecated API --- .../src/java/ti/modules/titanium/ui/widget/TiUISlider.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java index 2c2a32b330b..3001f5426c1 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java @@ -1,6 +1,6 @@ /** * Appcelerator Titanium Mobile - * Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved. + * Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved. * Licensed under the terms of the Apache Public License * Please see the LICENSE included with this distribution for details. */ @@ -105,11 +105,11 @@ public void processProperties(KrollDict d) private void updateRange() { minRange = Math.max(minRange, min); minRange = Math.min(minRange, max); - proxy.setProperty("minRange", minRange, false); + proxy.setProperty("minRange", minRange); maxRange = Math.min(maxRange, max); maxRange = Math.max(maxRange, minRange); - proxy.setProperty("maxRange", maxRange, false); + proxy.setProperty("maxRange", maxRange); } private void updateControl() { From 0d5fae84e6d1fc9cff2c9d555f386affd7073fbf Mon Sep 17 00:00:00 2001 From: vishalduggal Date: Fri, 27 Feb 2015 10:48:45 -0800 Subject: [PATCH 2/4] [TIMOB-18363] Allow specifying either left or right --- .../titanium/ui/widget/TiUISlider.java | 77 ++++++++++++------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java index 3001f5426c1..2f90c8229f0 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java @@ -37,6 +37,7 @@ public class TiUISlider extends TiUIView private int minRange; private int maxRange; private int scaleFactor; + private ClipDrawable rightClipDrawable; private SoftReference thumbDrawable; @@ -95,11 +96,22 @@ public void processProperties(KrollDict d) updateThumb(seekBar, d); } - if (d.containsKey("leftTrackImage") && d.containsKey("rightTrackImage")) { + if (d.containsKey("leftTrackImage") || d.containsKey("rightTrackImage")) { updateTrackingImages(seekBar, d); } updateRange(); updateControl(); + updateRightDrawable(); + } + + private void updateRightDrawable() + { + if(rightClipDrawable != null) { + SeekBar seekBar = (SeekBar) getNativeView(); + double percent = (double) seekBar.getProgress()/ (double)seekBar.getMax(); + int level = 10000 - (int)Math.floor(percent*10000); + rightClipDrawable.setLevel(level); + } } private void updateRange() { @@ -151,42 +163,53 @@ private void updateThumb(SeekBar seekBar, KrollDict d) private void updateTrackingImages(SeekBar seekBar, KrollDict d) { - TiFileHelper tfh = null; String leftImage = TiConvert.toString(d, "leftTrackImage"); String rightImage = TiConvert.toString(d, "rightTrackImage"); - if (leftImage != null && rightImage != null) { - if (tfh == null) { - tfh = new TiFileHelper(seekBar.getContext()); - } + + Drawable leftDrawable = null; + Drawable rightDrawable = null; + TiFileHelper tfh = new TiFileHelper(seekBar.getContext()); + + if(leftImage != null) { String leftUrl = proxy.resolveUrl(null, leftImage); - String rightUrl = proxy.resolveUrl(null, rightImage); - - Drawable rightDrawable = tfh.loadDrawable(rightUrl, false, true); - Drawable leftDrawable = tfh.loadDrawable(leftUrl, false, true); - if (rightDrawable != null && leftDrawable != null) { - Drawable[] lda = { - rightDrawable, - new ClipDrawable(leftDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) - }; - LayerDrawable ld = new LayerDrawable(lda); - ld.setId(0, android.R.id.background); - ld.setId(1, android.R.id.progress); - seekBar.setProgressDrawable(ld); - } else { + if(leftUrl != null) { + leftDrawable = tfh.loadDrawable(leftUrl, false, true); if (leftDrawable == null) { Log.e(TAG, "Unable to locate left image for progress bar: " + leftUrl); } + } + } + + if(rightImage != null) { + String rightUrl = proxy.resolveUrl(null, rightImage); + if(rightUrl != null) { + rightDrawable = tfh.loadDrawable(rightUrl, false, true); if (rightDrawable == null) { Log.e(TAG, "Unable to locate right image for progress bar: " + rightUrl); } - // release - leftDrawable = null; - rightDrawable = null; } - } else if (leftImage == null && rightImage == null) { - seekBar.setProgressDrawable(null); + } + + if(leftDrawable != null || rightDrawable != null) { + LayerDrawable ld = null; + if(rightDrawable == null) { + Drawable[] lda = {new ClipDrawable(leftDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL)}; + ld = new LayerDrawable(lda); + ld.setId(0, android.R.id.progress); + } else if(leftDrawable == null) { + rightClipDrawable = new ClipDrawable(rightDrawable, Gravity.RIGHT, ClipDrawable.HORIZONTAL); + Drawable[] lda = {rightClipDrawable}; + ld = new LayerDrawable(lda); + ld.setId(0, android.R.id.secondaryProgress); + } else { + Drawable[] lda = {rightDrawable, new ClipDrawable(leftDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL)}; + ld = new LayerDrawable(lda); + ld.setId(0, android.R.id.background); + ld.setId(1, android.R.id.progress); + } + seekBar.setProgressDrawable(ld); } else { - Log.w(TAG, "Custom tracking images must both be set before they will be drawn."); + Log.w(TAG, "Custom tracking images could not be loaded."); } } @@ -268,6 +291,8 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { pos = maxRange; } + updateRightDrawable(); + Drawable thumb = (thumbDrawable != null) ? thumbDrawable.get() : null; KrollDict offset = new KrollDict(); offset.put(TiC.EVENT_PROPERTY_X, 0); From 40c33b5a179891c697cf9bae3d79090ee3e56ba3 Mon Sep 17 00:00:00 2001 From: vishalduggal Date: Fri, 27 Feb 2015 11:05:44 -0800 Subject: [PATCH 3/4] [TIMOB-18363] Doc Update --- apidoc/Titanium/UI/Slider.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apidoc/Titanium/UI/Slider.yml b/apidoc/Titanium/UI/Slider.yml index 3aa3c0b10b5..d1ce15140a9 100644 --- a/apidoc/Titanium/UI/Slider.yml +++ b/apidoc/Titanium/UI/Slider.yml @@ -24,6 +24,10 @@ description: | On Android, both `min` and `max` must be specified for the slider to work properly. + Earlier versions of the Titanium SDK implicitly enforced that both the [leftTrackImage](Titanium.UI.Slider.leftTrackImage) and + [rightTrackImage](Titanium.UI.Slider.rightTrackImage) properties be specified before the properties would be honored. Beginning with + Titanium SDK 4.0.0 this limitation has been removed. However it is recommended that either both or neither be specified. + extends: Titanium.UI.View excludes: events: [ 'pinch' ] @@ -234,6 +238,8 @@ properties: - name: leftTrackImage summary: Image URL of the slider left track. + description: | + See introduction of the component for implementation specific information on Android Platform. type: String platforms: [android, iphone, ipad] @@ -339,6 +345,8 @@ properties: - name: rightTrackImage summary: Image URL of the slider right track. + description: | + See introduction of the component for implementation specific information on Android Platform. type: String platforms: [android, iphone, ipad] From 63308ff0f5be8776ef672de6709bf2666ccc2f10 Mon Sep 17 00:00:00 2001 From: vishalduggal Date: Fri, 27 Feb 2015 11:52:06 -0800 Subject: [PATCH 4/4] [TIMOB-18363] Formatting --- .../ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java index 2f90c8229f0..271317ccb2f 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java @@ -109,8 +109,8 @@ private void updateRightDrawable() if(rightClipDrawable != null) { SeekBar seekBar = (SeekBar) getNativeView(); double percent = (double) seekBar.getProgress()/ (double)seekBar.getMax(); - int level = 10000 - (int)Math.floor(percent*10000); - rightClipDrawable.setLevel(level); + int level = 10000 - (int)Math.floor(percent*10000); + rightClipDrawable.setLevel(level); } }