-
Notifications
You must be signed in to change notification settings - Fork 4
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
Added support for managing number replays & removing childViews #3
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -37,7 +37,9 @@ public class TickerView extends HorizontalScrollView { | |||||||||
private TextView lastTicker; | ||||||||||
private List<View> childViews = null; | ||||||||||
private LinearLayout linearLayout; | ||||||||||
|
||||||||||
private Integer replays; | ||||||||||
private Integer loop = 1; | ||||||||||
Comment on lines
+40
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use primitive type for better memory usage?
Suggested change
|
||||||||||
private boolean replaysCompleted = false; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can remove explicit assignment to false since it's already the default value
Suggested change
|
||||||||||
|
||||||||||
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. | ||||||||||
* | ||||||||||
|
@@ -139,6 +146,13 @@ public void addChildView(View childView) { | |||||||||
this.childViews.add(childView); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* | ||||||||||
*/ | ||||||||||
Comment on lines
+149
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove empty comment |
||||||||||
public void removeChildViews() { | ||||||||||
this.childViews = null; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* This method to show the child views added by {@code addChildView()} or {@code setChildViews(List<View> childViews)} methods. | ||||||||||
* Method Details: | ||||||||||
|
@@ -149,6 +163,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 +252,45 @@ public void run() { | |||||||||
* <p> | ||||||||||
* 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) { | ||||||||||
loop = 1; | ||||||||||
restartScroll(); | ||||||||||
} 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 { | ||||||||||
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 +320,4 @@ private void clearTimerTaks(TimerTask timerTask) { | |||||||||
timerTask.cancel(); | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
} |
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.
numper -> number