|
|
@@ -2,6 +2,8 @@ package com.atmob.voiceai.widget;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.content.Context;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Looper;
|
|
|
import android.text.method.ScrollingMovementMethod;
|
|
|
import android.util.AttributeSet;
|
|
|
import android.view.MotionEvent;
|
|
|
@@ -11,6 +13,9 @@ import androidx.annotation.Nullable;
|
|
|
|
|
|
public class AutoScrollTextView extends androidx.appcompat.widget.AppCompatTextView {
|
|
|
|
|
|
+ private static final Handler MAIN_HANDLER = new Handler(Looper.getMainLooper());
|
|
|
+ private Runnable autoScrollRunnable;
|
|
|
+
|
|
|
|
|
|
public AutoScrollTextView(@NonNull Context context) {
|
|
|
this(context, null);
|
|
|
@@ -27,6 +32,14 @@ public class AutoScrollTextView extends androidx.appcompat.widget.AppCompatTextV
|
|
|
|
|
|
private void init() {
|
|
|
setMovementMethod(ScrollingMovementMethod.getInstance());
|
|
|
+ autoScrollRunnable = () -> {
|
|
|
+ int scrollY = getScrollY();
|
|
|
+ if (scrollY < getLineHeight() * getLineCount() - getHeight()) {
|
|
|
+ scrollY += 1;
|
|
|
+ scrollTo(0, scrollY);
|
|
|
+ }
|
|
|
+ MAIN_HANDLER.postDelayed(autoScrollRunnable, 50);
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -39,29 +52,17 @@ public class AutoScrollTextView extends androidx.appcompat.widget.AppCompatTextV
|
|
|
|
|
|
public void startScroll() {
|
|
|
scrollTo(0, 0);
|
|
|
- postScroll();
|
|
|
+ MAIN_HANDLER.postDelayed(autoScrollRunnable, 3000);
|
|
|
}
|
|
|
|
|
|
public void stopScroll() {
|
|
|
- getHandler().removeCallbacksAndMessages(null);
|
|
|
+ MAIN_HANDLER.removeCallbacksAndMessages(null);
|
|
|
}
|
|
|
|
|
|
- private void postScroll() {
|
|
|
- post(() -> {
|
|
|
- int scrollY = getScrollY();
|
|
|
- scrollY += 1;
|
|
|
- scrollTo(0, scrollY);
|
|
|
- if (scrollY >= getLineHeight() * getLineCount() - getHeight()) {
|
|
|
-// scrollTo(0, 0);
|
|
|
- stopScroll();
|
|
|
- }
|
|
|
- postDelayed(this::postScroll, 50);
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
protected void onDetachedFromWindow() {
|
|
|
super.onDetachedFromWindow();
|
|
|
- removeCallbacks(this::postScroll);
|
|
|
+ stopScroll();
|
|
|
}
|
|
|
}
|