diff --git a/app/src/main/java/com/github/catvod/spider/Notice.java b/app/src/main/java/com/github/catvod/spider/Notice.java index 56a949ec..946e2696 100644 --- a/app/src/main/java/com/github/catvod/spider/Notice.java +++ b/app/src/main/java/com/github/catvod/spider/Notice.java @@ -2,43 +2,68 @@ package com.github.catvod.spider; import android.content.Context; import android.graphics.Color; +import android.graphics.Typeface; import android.view.Gravity; import android.widget.FrameLayout; import com.github.catvod.crawler.Spider; -import com.github.catvod.ui.MarqueeView; +import com.github.catvod.ui.ScrollTextView; import com.github.catvod.utils.Utils; import java.util.Random; public class Notice extends Spider { - private MarqueeView view; + private static final String SPACE = " "; + private ScrollTextView view; + private String text; + private int time; @Override public void init(Context context, String extend) { super.init(context, extend); - Init.run(() -> createView(extend)); + String[] splits = extend.split(";"); + this.text = splits[0]; + this.time = splits.length > 1 ? Integer.parseInt(splits[1]) : 30; } - private void createView(String extend) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < 3; i++) sb.append(extend).append(" "); - view = new MarqueeView(Init.context()); - view.setText(sb.toString()); - view.setBackgroundColor(Color.argb(200, 255, 255, 255)); - FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, Utils.dp2px(56)); - params.gravity = Gravity.TOP; - Utils.addView(view, params); - updateColor(); + @Override + public String homeContent(boolean filter) throws Exception { + Init.run(this::createView); + return ""; + } + + private void createView() { + createText(); + createRoot(); + setColor(); hide(); } - private void hide() { - Init.run(() -> Utils.removeView(view), 30 * 1000); + private void createText() { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 2; i++) sb.append(SPACE).append(text); + view = new ScrollTextView(Init.context()); + view.setTextSize(20); + view.setDuration(time); + view.setText(sb.toString()); + view.setTypeface(null, Typeface.BOLD); + view.setPadding(0, Utils.dp2px(16), 0, Utils.dp2px(16)); + view.setBackgroundColor(Color.argb(200, 255, 255, 255)); + view.startScroll(); } - private void updateColor() { + private void createRoot() { + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); + params.gravity = Gravity.TOP; + Utils.addView(view, params); + } + + private void hide() { + Init.run(() -> Utils.removeView(view), time * 1000); + } + + private void setColor() { Init.run(runnable, 500); } @@ -46,8 +71,8 @@ public class Notice extends Spider { @Override public void run() { Random random = new Random(); - view.setTextColor(Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256))); - updateColor(); + view.setTextColor(Color.argb(255, random.nextInt(128), random.nextInt(128), random.nextInt(128))); + setColor(); } }; } diff --git a/app/src/main/java/com/github/catvod/ui/MarqueeView.java b/app/src/main/java/com/github/catvod/ui/MarqueeView.java deleted file mode 100644 index b038265f..00000000 --- a/app/src/main/java/com/github/catvod/ui/MarqueeView.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.github.catvod.ui; - -import android.animation.ValueAnimator; -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Canvas; -import android.text.method.LinkMovementMethod; -import android.util.AttributeSet; -import android.view.Gravity; -import android.view.MotionEvent; -import android.widget.HorizontalScrollView; -import android.widget.RelativeLayout; -import android.widget.TextView; - -public class MarqueeView extends HorizontalScrollView { - - private TextView mTextView; - private TextView mGhostTextView; - private int viewWidth; - private int measureText; - private int mOffset = 0; - private int mGhostOffset = 0; - private int spacing = 100; - private int speed = 1; - - private ValueAnimator valueAnimator; - - public MarqueeView(Context context) { - this(context, null); - } - - public MarqueeView(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public MarqueeView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - initLayout(); - initAnim(); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - viewWidth = getMeasuredWidth(); - } - - @Override - protected void onSizeChanged(int w, int h, int oldw, int oldh) { - super.onSizeChanged(w, h, oldw, oldh); - if (measureText > viewWidth) { - startAnim(); - } else { - stopAnim(); - } - } - - private void initLayout() { - RelativeLayout relativeLayout = new RelativeLayout(getContext()); - LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); - relativeLayout.setLayoutParams(layoutParams); - addView(relativeLayout); - mTextView = createTextView(); - mGhostTextView = createTextView(); - relativeLayout.addView(mTextView); - relativeLayout.addView(mGhostTextView); - } - - private void initAnim() { - valueAnimator = ValueAnimator.ofFloat(0, measureText); - valueAnimator.addUpdateListener(animatorUpdateListener); - valueAnimator.setRepeatCount(ValueAnimator.INFINITE); - valueAnimator.setRepeatMode(ValueAnimator.RESTART); - } - - public void setSpacing(int spacing) { - this.spacing = spacing; - } - - public void setSpeed(int speed) { - this.speed = speed; - } - - public void setText(CharSequence text) { - mTextView.setText(text); - mGhostTextView.setText(text); - measureText = (int) mTextView.getPaint().measureText(text, 0, text.length()); - resetMarqueeView(); - if (measureText > viewWidth) { - startAnim(); - } else { - stopAnim(); - } - } - - public void setTextColor(int color) { - mTextView.setTextColor(color); - mGhostTextView.setTextColor(color); - } - - private TextView createTextView() { - TextView textView = new TextView(getContext()); - textView.setPadding(0, 0, 0, 0); - textView.setSingleLine(); - textView.setTextSize(20); - LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); - textView.setLayoutParams(layoutParams); - textView.setGravity(Gravity.CENTER_VERTICAL); - textView.setMovementMethod(LinkMovementMethod.getInstance()); - return textView; - } - - private void resetMarqueeView() { - mOffset = 0; - mGhostOffset = measureText + spacing; - mGhostTextView.setX(mGhostOffset); - invalidate(); - } - - public void startAnim() { - valueAnimator.setDuration(measureText); - stopAnim(); - valueAnimator.start(); - } - - public void stopAnim() { - valueAnimator.cancel(); - resetMarqueeView(); - } - - ValueAnimator.AnimatorUpdateListener animatorUpdateListener = new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - mOffset -= speed; - mGhostOffset -= speed; - if (mOffset + measureText < 0) { - mOffset = mGhostOffset + measureText + spacing; - } - if (mGhostOffset + measureText < 0) { - mGhostOffset = mOffset + measureText + spacing; - } - invalidate(); - } - }; - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - if (mTextView == null || mGhostTextView == null) return; - mTextView.setX(mOffset); - mGhostTextView.setX(mGhostOffset); - } - - @SuppressLint("ClickableViewAccessibility") - @Override - public boolean onTouchEvent(MotionEvent ev) { - return true; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/github/catvod/ui/ScrollTextView.java b/app/src/main/java/com/github/catvod/ui/ScrollTextView.java new file mode 100644 index 00000000..8d016f35 --- /dev/null +++ b/app/src/main/java/com/github/catvod/ui/ScrollTextView.java @@ -0,0 +1,57 @@ +package com.github.catvod.ui; + +import android.content.Context; +import android.graphics.Rect; +import android.text.TextPaint; +import android.util.AttributeSet; +import android.view.animation.LinearInterpolator; +import android.widget.Scroller; +import android.widget.TextView; + +public class ScrollTextView extends TextView { + + private final Scroller scroller; + private int duration; + + public ScrollTextView(Context context) { + this(context, null); + } + + public ScrollTextView(Context context, AttributeSet attrs) { + this(context, attrs, android.R.attr.textViewStyle); + } + + public ScrollTextView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + setSingleLine(); + setEllipsize(null); + setHorizontallyScrolling(true); + setScroller(scroller = new Scroller(getContext(), new LinearInterpolator())); + } + + public void setDuration(int duration) { + this.duration = duration; + } + + public void startScroll() { + scroller.startScroll(-getWidth(), 0, calculateScrollingLen(), 0, duration * 1000); + } + + public void stopScroll() { + if (scroller != null) scroller.abortAnimation(); + } + + private int calculateScrollingLen() { + TextPaint paint = getPaint(); + Rect rect = new Rect(); + String text = getText().toString(); + paint.getTextBounds(text, 0, text.length(), rect); + return rect.width() + getWidth(); + } + + @Override + public void computeScroll() { + super.computeScroll(); + if (scroller != null && scroller.isFinished()) stopScroll(); + } +} \ No newline at end of file diff --git a/jar/custom_spider.jar b/jar/custom_spider.jar index 5d79d164..20a8127e 100644 Binary files a/jar/custom_spider.jar and b/jar/custom_spider.jar differ diff --git a/jar/custom_spider.jar.md5 b/jar/custom_spider.jar.md5 index 3dd15d4c..4ab296d4 100644 --- a/jar/custom_spider.jar.md5 +++ b/jar/custom_spider.jar.md5 @@ -1 +1 @@ -8cb598596c187e9b24ff1fe92523f43c +73954c18f409c0cadb91e6a4aff10381 diff --git a/json/adult.json b/json/adult.json index d95b36fb..f1b0ac19 100644 --- a/json/adult.json +++ b/json/adult.json @@ -1,5 +1,5 @@ { - "spider": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar;md5;8cb598596c187e9b24ff1fe92523f43c", + "spider": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar;md5;73954c18f409c0cadb91e6a4aff10381", "wallpaper": "https://gao.chuqiuyu.tk", "sites": [ { diff --git a/json/config.json b/json/config.json index 6ac11048..0c4a9ceb 100644 --- a/json/config.json +++ b/json/config.json @@ -1,5 +1,5 @@ { - "spider": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar;md5;8cb598596c187e9b24ff1fe92523f43c", + "spider": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar;md5;73954c18f409c0cadb91e6a4aff10381", "wallpaper": "http://饭太硬.ga/深色壁纸/api.php", "sites": [ {