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