Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TimeCountDownStrategy & demo #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/src/main/java/com/yy/mobile/rollingtext/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class MainActivity extends AppCompatActivity {

Expand Down Expand Up @@ -68,6 +69,22 @@ public void run() {
}
}, 2000L);

final RollingTextView countDown = findViewById(R.id.rollingTextView4);
countDown.addCharOrder(CharOrder.Number);
countDown.addCharOrder(":");
countDown.setAnimationDuration(500L);
countDown.setAnimationInterpolator(new AccelerateDecelerateInterpolator());
countDown.setCharStrategy(Strategy.TimeCountDownAnimation(Direction.SCROLL_DOWN));
handler.post(new Runnable() {
@Override
public void run() {
Date date = new Date();
date.setTime(System.currentTimeMillis());
countDown.setText(new SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(date));
handler.postDelayed(this, 1000L);
}
});

final RollingTextView stickyText = findViewById(R.id.stickyText);
stickyText.setAnimationDuration(3000L);
stickyText.addCharOrder("0123456789abcdef");
Expand Down
26 changes: 25 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,35 @@
android:text="CarryBit"
android:textSize="14sp" />

<com.yy.mobile.rollingtextview.RollingTextView
android:id="@+id/rollingTextView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/rollingTextView3"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="0"
android:textColor="#ffff00ff"
android:textSize="35sp"
android:textStyle="italic" />

<com.yy.mobile.rollingtextview.RollingTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/rollingTextView4"
android:layout_alignParentLeft="true"
android:layout_marginLeft="40dp"
android:layout_toLeftOf="@+id/rollingTextView4"
android:gravity="start|center_vertical"
android:padding="10dp"
android:text="CountDown"
android:textSize="14sp" />

<RelativeLayout
android:id="@+id/stickyLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/rollingTextView3"
android:layout_below="@id/rollingTextView4"
android:layout_marginTop="10dp">

<com.yy.mobile.rollingtextview.RollingTextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,13 @@ object Strategy {
@JvmStatic
fun StickyAnimation(factor: Double): CharOrderStrategy =
StickyStrategy(factor)

/**
* 倒计时动画:
* 保持相同顺序
*
* the animation use for count down, all the character are same direction
*/
@JvmStatic
fun TimeCountDownAnimation(direction: Direction): CharOrderStrategy = TimeCountDownStrategy(direction)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.yy.mobile.rollingtextview.strategy

/**
* Created by qiu on 2018/10/10.
* E-mail: [email protected]
* YY: 909017428
*/
open class TimeCountDownStrategy(private val direction: Direction) : SimpleCharOrderStrategy() {

override fun findCharOrder(
sourceChar: Char,
targetChar: Char,
index: Int,
order: Iterable<Char>?): Pair<List<Char>, Direction> {

return if (sourceChar == targetChar) {
listOf(targetChar) to direction

} else listOf(sourceChar, targetChar) to direction
}
}