Clean code
This commit is contained in:
parent
9f4e47d2df
commit
d764885c7c
|
|
@ -16,21 +16,28 @@ public class Notice extends Spider {
|
||||||
|
|
||||||
private static final String SPACE = " ";
|
private static final String SPACE = " ";
|
||||||
private ScrollTextView view;
|
private ScrollTextView view;
|
||||||
|
private String text;
|
||||||
|
private int time;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Context context, String extend) {
|
public void init(Context context, String extend) {
|
||||||
super.init(context, extend);
|
super.init(context, extend);
|
||||||
String[] splits = extend.split(";");
|
String[] splits = extend.split(";");
|
||||||
String text = splits[0];
|
this.text = splits[0];
|
||||||
int duration = splits.length > 1 ? Integer.parseInt(splits[1]) : 30;
|
this.time = splits.length > 1 ? Integer.parseInt(splits[1]) : 30;
|
||||||
Init.run(() -> createView(text, duration));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createView(String text, int duration) {
|
@Override
|
||||||
createText(text, duration);
|
public String homeContent(boolean filter) throws Exception {
|
||||||
|
Init.run(this::createView);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createView() {
|
||||||
createLayout();
|
createLayout();
|
||||||
hide(duration);
|
createText();
|
||||||
updateColor();
|
setColor();
|
||||||
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createLayout() {
|
private void createLayout() {
|
||||||
|
|
@ -39,12 +46,12 @@ public class Notice extends Spider {
|
||||||
Utils.addView(view, params);
|
Utils.addView(view, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createText(String text, int duration) {
|
private void createText() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < 2; i++) sb.append(SPACE).append(text);
|
for (int i = 0; i < 2; i++) sb.append(SPACE).append(text);
|
||||||
view = new ScrollTextView(Init.context());
|
view = new ScrollTextView(Init.context());
|
||||||
view.setTextSize(20);
|
view.setTextSize(20);
|
||||||
view.setDuration(duration);
|
view.setDuration(time);
|
||||||
view.setText(sb.toString());
|
view.setText(sb.toString());
|
||||||
view.setTypeface(null, Typeface.BOLD);
|
view.setTypeface(null, Typeface.BOLD);
|
||||||
view.setPadding(0, Utils.dp2px(16), 0, Utils.dp2px(16));
|
view.setPadding(0, Utils.dp2px(16), 0, Utils.dp2px(16));
|
||||||
|
|
@ -52,11 +59,11 @@ public class Notice extends Spider {
|
||||||
view.startScroll();
|
view.startScroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hide(int duration) {
|
private void hide() {
|
||||||
Init.run(() -> Utils.removeView(view), duration * 1000);
|
Init.run(() -> Utils.removeView(view), time * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateColor() {
|
private void setColor() {
|
||||||
Init.run(runnable, 500);
|
Init.run(runnable, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,7 +72,7 @@ public class Notice extends Spider {
|
||||||
public void run() {
|
public void run() {
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
view.setTextColor(Color.argb(255, random.nextInt(128), random.nextInt(128), random.nextInt(128)));
|
view.setTextColor(Color.argb(255, random.nextInt(128), random.nextInt(128), random.nextInt(128)));
|
||||||
updateColor();
|
setColor();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
d14ffa035bb1fef5445e235f28e3ee2f
|
8d3f8cfed4f4ac1731da98acc255b189
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue