From e211b0f23162e9d5658888ee75818bc53227b4f4 Mon Sep 17 00:00:00 2001 From: k-joseph Date: Sun, 14 Mar 2021 15:31:04 +0300 Subject: [PATCH 1/3] Added support for managing nuumber of replays of cycles before stopping --- .../java/com/vinay/ticker/lib/TickerView.java | 62 +++++++++++++------ 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/tickerview/src/main/java/com/vinay/ticker/lib/TickerView.java b/tickerview/src/main/java/com/vinay/ticker/lib/TickerView.java index 23ca7f5..19655e4 100644 --- a/tickerview/src/main/java/com/vinay/ticker/lib/TickerView.java +++ b/tickerview/src/main/java/com/vinay/ticker/lib/TickerView.java @@ -37,7 +37,9 @@ public class TickerView extends HorizontalScrollView { private TextView lastTicker; private List childViews = null; private LinearLayout linearLayout; - + private Integer replays; + private Integer nextLoop = 2; + private boolean replaysCompleted = false; public TickerView(Context context) { super(context); @@ -60,6 +62,13 @@ public TickerView(Context context, AttributeSet attrs, int defStyleAttr, int def init(context, null); } + /** + * Use this method to set the number of times the tickerView/scolling all messages should happen + */ + public void setReplays(Integer replays) { + this.replays = replays; + } + /** * If the views are added to the container view, the tickers start showing up. This method calls {@code showTickers()} */ @@ -78,7 +87,6 @@ protected void onDetachedFromWindow() { super.onDetachedFromWindow(); } - /** * This method initialized the View container by adding a horizontal {@code LinearLayout} onside the root view. * @@ -117,7 +125,6 @@ public void setDisplacement(int displacement) { this.displacement = (int) Math.ceil((displacement) * 5.0 / 100.0); } - /** * Saves the views collection to be plotted in the ticker view. * @@ -149,6 +156,7 @@ public void addChildView(View childView) { * 5. We add {@code ViewTreeObserver.OnGlobalLayoutListener} to intercept changes in global layout and start auto scrolling by calling {@code startAutoScrolling()} method. */ public void showTickers() { + replaysCompleted = false; if (linearLayout != null) { linearLayout.removeAllViews(); } @@ -237,31 +245,45 @@ public void run() { *

* The logic in place is to get a {@code Rect} and set it for custom last marker ticker(invisible). An additional {@code Rect} object is created whose horizontal bounds are * for how much the view has scrolled added to its width. Once we have both of these objects, we simply check if the {@code Rect}object for last custom ticker view (invisible) - * intersects with the current screen {@code Rect} object, as soon as the condition is met, which means the last hidden view has scrolled on to the screen, which in tern means all the ticker items have been shown, we set the scroll position to 0 again,, and the scrolling starts from the first Tivker view again. + * intersects with the current screen {@code Rect} object, as soon as the condition is met, which means the last hidden view has scrolled on to the screen, which in tern means all the ticker items have been shown, we set the scroll position to 0 again,, and the scrolling starts from the first Ticker view again. */ public void moveScrollView() { - try { - scrollPos = (int) (getScrollX() + displacement); - - final Rect bounds = new Rect(); - lastTicker.getHitRect(bounds); - - final Rect scrollBounds = new Rect(getScrollX(), getScrollY(), getScrollX() - + getWidth(), getScrollY() + getHeight()); - - if (Rect.intersects(scrollBounds, bounds)) { - // is visible - scrollPos = 0; - scrollTo(scrollPos, 0); - } else { - smoothScrollTo(scrollPos, 0); + if(!replaysCompleted) { + boolean continuing = scrollPos == -1; + scrollPos = continuing ? 0 : (int) (getScrollX() + displacement); + final Rect bounds = new Rect(); + lastTicker.getHitRect(bounds); + + final Rect scrollBounds = new Rect(getScrollX(), getScrollY(), getScrollX() + + getWidth(), getScrollY() + getHeight()); + + if (Rect.intersects(scrollBounds, bounds)) { + if(continuing) { + nextLoop = 2; + restartScroll(); + } else if(replays != null && nextLoop > replays) {//last replay + replaysCompleted = true; + scrollPos = -1;// sets a tracker the picking up a next call after a former replays end + } else { + nextLoop++; + restartScroll(); + } + } else { + smoothScrollTo(scrollPos, 0); + } } } catch (Exception e) { e.printStackTrace(); } } + private void restartScroll() { + // is visible + scrollPos = 0; + scrollTo(scrollPos, 0); + } + /** * This method cancels {@code Timer} and {@code TimerTask} and there callback. */ @@ -291,4 +313,4 @@ private void clearTimerTaks(TimerTask timerTask) { timerTask.cancel(); } } -} +} \ No newline at end of file From bd2de9d8b3e5453a49bc49cf884f80b8a72d47e0 Mon Sep 17 00:00:00 2001 From: k-joseph Date: Sun, 14 Mar 2021 17:35:53 +0300 Subject: [PATCH 2/3] added removeChildViews --- README.md | 6 ++++++ gradle.properties | 2 ++ gradlew | 0 .../src/main/java/com/vinay/ticker/lib/TickerView.java | 7 +++++++ 4 files changed, 15 insertions(+) mode change 100644 => 100755 gradlew diff --git a/README.md b/README.md index bb7fd6a..7aba874 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,12 @@ for (int index = 0; index < 50; index++) { tickerView.addChildView(tv); } +// Call setReplays(replays) to set numper of times to loop/scroll entire messages +tickerView.setReplays(replays) + +// Call removeChildViews to remove all child views +tickerView.removeChildViews() + // Call the showTickers() to show them on the screen tickerView.showTickers(); diff --git a/gradle.properties b/gradle.properties index 743d692..e046a62 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,3 +11,5 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true + +version=1.0 \ No newline at end of file diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/tickerview/src/main/java/com/vinay/ticker/lib/TickerView.java b/tickerview/src/main/java/com/vinay/ticker/lib/TickerView.java index 19655e4..834f027 100644 --- a/tickerview/src/main/java/com/vinay/ticker/lib/TickerView.java +++ b/tickerview/src/main/java/com/vinay/ticker/lib/TickerView.java @@ -146,6 +146,13 @@ public void addChildView(View childView) { this.childViews.add(childView); } + /** + * + */ + public void removeChildViews() { + this.childViews = null; + } + /** * This method to show the child views added by {@code addChildView()} or {@code setChildViews(List childViews)} methods. * Method Details: From f959cf7a728775322b8397f20179c3bed8dbc2e4 Mon Sep 17 00:00:00 2001 From: k-joseph Date: Mon, 15 Mar 2021 19:34:14 +0300 Subject: [PATCH 3/3] defaulting replays to 0 --- .../main/java/com/vinay/ticker/lib/TickerView.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tickerview/src/main/java/com/vinay/ticker/lib/TickerView.java b/tickerview/src/main/java/com/vinay/ticker/lib/TickerView.java index 834f027..d603e4a 100644 --- a/tickerview/src/main/java/com/vinay/ticker/lib/TickerView.java +++ b/tickerview/src/main/java/com/vinay/ticker/lib/TickerView.java @@ -38,7 +38,7 @@ public class TickerView extends HorizontalScrollView { private List childViews = null; private LinearLayout linearLayout; private Integer replays; - private Integer nextLoop = 2; + private Integer loop = 1; private boolean replaysCompleted = false; public TickerView(Context context) { @@ -267,14 +267,14 @@ public void moveScrollView() { if (Rect.intersects(scrollBounds, bounds)) { if(continuing) { - nextLoop = 2; + loop = 1; restartScroll(); - } else if(replays != null && nextLoop > replays) {//last replay + } else if(replays >= loop) { + loop++; + restartScroll(); + } else { replaysCompleted = true; scrollPos = -1;// sets a tracker the picking up a next call after a former replays end - } else { - nextLoop++; - restartScroll(); } } else { smoothScrollTo(scrollPos, 0);