Clean code
This commit is contained in:
parent
c19fe4bcb9
commit
9f4e47d2df
|
|
@ -29,8 +29,8 @@ public class Notice extends Spider {
|
|||
private void createView(String text, int duration) {
|
||||
createText(text, duration);
|
||||
createLayout();
|
||||
hide(duration);
|
||||
updateColor();
|
||||
hide();
|
||||
}
|
||||
|
||||
private void createLayout() {
|
||||
|
|
@ -52,8 +52,8 @@ public class Notice extends Spider {
|
|||
view.startScroll();
|
||||
}
|
||||
|
||||
private void hide() {
|
||||
Init.run(() -> Utils.removeView(view), 30 * 1000);
|
||||
private void hide(int duration) {
|
||||
Init.run(() -> Utils.removeView(view), duration * 1000);
|
||||
}
|
||||
|
||||
private void updateColor() {
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import android.widget.TextView;
|
|||
|
||||
public class ScrollTextView extends TextView {
|
||||
|
||||
private Scroller scroller;
|
||||
private int duration = 30;
|
||||
private final Scroller scroller;
|
||||
private int duration;
|
||||
|
||||
public ScrollTextView(Context context) {
|
||||
this(context, null);
|
||||
|
|
@ -25,7 +25,8 @@ public class ScrollTextView extends TextView {
|
|||
super(context, attrs, defStyle);
|
||||
setSingleLine();
|
||||
setEllipsize(null);
|
||||
setVisibility(INVISIBLE);
|
||||
setHorizontallyScrolling(true);
|
||||
setScroller(scroller = new Scroller(getContext(), new LinearInterpolator()));
|
||||
}
|
||||
|
||||
public void setDuration(int duration) {
|
||||
|
|
@ -33,14 +34,11 @@ public class ScrollTextView extends TextView {
|
|||
}
|
||||
|
||||
public void startScroll() {
|
||||
int width = -1 * getWidth();
|
||||
setHorizontallyScrolling(true);
|
||||
setScroller(scroller = new Scroller(getContext(), new LinearInterpolator()));
|
||||
int scrollingLen = calculateScrollingLen();
|
||||
int distance = scrollingLen - (getWidth() + width);
|
||||
scroller.startScroll(width, 0, distance, 0, duration * 1000);
|
||||
setVisibility(VISIBLE);
|
||||
invalidate();
|
||||
scroller.startScroll(-getWidth(), 0, calculateScrollingLen(), 0, duration * 1000);
|
||||
}
|
||||
|
||||
public void stopScroll() {
|
||||
if (scroller != null) scroller.abortAnimation();
|
||||
}
|
||||
|
||||
private int calculateScrollingLen() {
|
||||
|
|
@ -54,10 +52,6 @@ public class ScrollTextView extends TextView {
|
|||
@Override
|
||||
public void computeScroll() {
|
||||
super.computeScroll();
|
||||
if (scroller == null) return;
|
||||
if (scroller.isFinished()) {
|
||||
scroller.abortAnimation();
|
||||
setVisibility(GONE);
|
||||
}
|
||||
if (scroller != null && scroller.isFinished()) stopScroll();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
e18bc0418a1fe5f288275132c9d719b3
|
||||
d14ffa035bb1fef5445e235f28e3ee2f
|
||||
|
|
|
|||
Loading…
Reference in New Issue