Skip to content

Commit a0c5dc7

Browse files
committed
v0.1.3新增跳动文本
1 parent 3db6db0 commit a0c5dc7

File tree

8 files changed

+466
-0
lines changed

8 files changed

+466
-0
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<activity android:name=".meis.MeiRoseActivity"></activity>
4242
<activity android:name=".meis.MeiFireflyActivity"></activity>
4343
<activity android:name=".meis.MeiPraiseActivity"></activity>
44+
<activity android:name=".meis.MeiEvaporateActivity"></activity>
4445
</application>
4546

4647
</manifest>

app/src/main/java/com/demo/widget/meis/MainActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,8 @@ public void onFirefly(View view) {
6666
public void onPraise(View view) {
6767
startActivity(new Intent(this, MeiPraiseActivity.class));
6868
}
69+
70+
public void onEva(View view) {
71+
startActivity(new Intent(this, MeiEvaporateActivity.class));
72+
}
6973
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.demo.widget.meis;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.support.v7.widget.Toolbar;
7+
import android.view.View;
8+
import android.widget.Button;
9+
10+
import com.demo.widget.R;
11+
import com.meis.widget.evaporate.EvaporateTextView;
12+
13+
/**
14+
* Created by wenshi on 2018/11/23.
15+
* Description
16+
*/
17+
public class MeiEvaporateActivity extends AppCompatActivity {
18+
19+
private Toolbar mToolbar;
20+
private EvaporateTextView mEvaporateTextView;
21+
private Button mBtn;
22+
private int index = 0;
23+
24+
@Override
25+
protected void onCreate(@Nullable Bundle savedInstanceState) {
26+
super.onCreate(savedInstanceState);
27+
setContentView(R.layout.mei_evaporate_activity);
28+
29+
mToolbar = findViewById(R.id.toolbar);
30+
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
31+
@Override
32+
public void onClick(View v) {
33+
finish();
34+
}
35+
});
36+
37+
mEvaporateTextView = findViewById(R.id.etv);
38+
mBtn = findViewById(R.id.btn);
39+
mBtn.setOnClickListener(new View.OnClickListener() {
40+
@Override
41+
public void onClick(View v) {
42+
if (index >= (sentences.length - 1)) {
43+
index = 0;
44+
}
45+
mEvaporateTextView.animateText(sentences[index++]);
46+
}
47+
});
48+
49+
mEvaporateTextView.animateText("hello world");
50+
}
51+
52+
private String[] sentences = {
53+
"A material",
54+
"metaphor is the unifying theory",
55+
"of a rationalized space and a system of motion",
56+
"material",
57+
"grounded",
58+
"in tactile reality",
59+
"inspired",
60+
"study of paper and ink",
61+
"understand",
62+
"new affordances",
63+
"The fundamentals of light, surface, and movement are key to conveying how objects move",
64+
"interact",
65+
"divides space",
66+
"fundamentals",
67+
"欢迎关注文淑",
68+
"文淑博客",
69+
"Android"
70+
};
71+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
7+
<android.support.v7.widget.Toolbar
8+
android:id="@+id/toolbar"
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:background="@color/colorPrimary"
12+
app:navigationIcon="@mipmap/ic_arrow_back_white_24dp"
13+
app:title="Evaporate文本"
14+
app:titleTextColor="#FFF" />
15+
16+
<com.meis.widget.evaporate.EvaporateTextView
17+
android:id="@+id/etv"
18+
android:layout_width="match_parent"
19+
android:layout_height="100dp"
20+
android:background="#000"
21+
android:gravity="center_horizontal"
22+
android:paddingTop="8dp"
23+
android:textColor="#fff"
24+
android:textSize="20sp"
25+
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
26+
27+
<Button
28+
android:id="@+id/btn"
29+
android:layout_width="match_parent"
30+
android:layout_height="48dp"
31+
android:background="@color/colorPrimary"
32+
android:gravity="center"
33+
android:text="切换文本"
34+
android:textColor="#fff"
35+
android:textSize="16sp"
36+
app:layout_constraintBottom_toBottomOf="parent"
37+
app:layout_constraintTop_toTopOf="parent" />
38+
39+
40+
</android.support.constraint.ConstraintLayout>

app/src/main/res/layout/meis_activity.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,31 @@
248248

249249
</android.support.v7.widget.CardView>
250250

251+
<android.support.v7.widget.CardView
252+
android:id="@+id/cv_eva"
253+
android:layout_width="match_parent"
254+
android:layout_height="wrap_content"
255+
android:layout_marginLeft="8dp"
256+
android:layout_marginRight="8dp"
257+
android:layout_marginTop="16dp"
258+
android:foreground="?attr/selectableItemBackground"
259+
android:onClick="onEva"
260+
app:cardBackgroundColor="@android:color/white"
261+
app:cardPreventCornerOverlap="false"
262+
app:cardUseCompatPadding="true">
263+
264+
<TextView
265+
android:layout_width="match_parent"
266+
android:layout_height="wrap_content"
267+
android:gravity="center"
268+
android:padding="16dp"
269+
android:text="跳动的文本"
270+
android:textAllCaps="false"
271+
android:textColor="#999999"
272+
android:textSize="16sp" />
273+
274+
</android.support.v7.widget.CardView>
275+
251276
</LinearLayout>
252277
</android.support.v4.widget.NestedScrollView>
253278
</LinearLayout>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.meis.widget.evaporate;
2+
3+
/**
4+
* Created by wenshi on 2018/11/22.
5+
* Description
6+
*/
7+
public class CharacterDiffResult {
8+
public char c;
9+
public int fromIndex;
10+
public int moveIndex;
11+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.meis.widget.evaporate;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashSet;
5+
import java.util.List;
6+
import java.util.Set;
7+
8+
/**
9+
* Created by wenshi on 2018/11/23.
10+
* Description
11+
*/
12+
public class CharacterUtils {
13+
public static List<CharacterDiffResult> diff(CharSequence oldText, CharSequence newText) {
14+
15+
List<CharacterDiffResult> differentList = new ArrayList<>();
16+
Set<Integer> skip = new HashSet<>();
17+
18+
for (int i = 0; i < oldText.length(); i++) {
19+
char c = oldText.charAt(i);
20+
for (int j = 0; j < newText.length(); j++) {
21+
if (!skip.contains(j) && c == newText.charAt(j)) {
22+
skip.add(j);
23+
CharacterDiffResult different = new CharacterDiffResult();
24+
different.c = c;
25+
different.fromIndex = i;
26+
different.moveIndex = j;
27+
differentList.add(different);
28+
break;
29+
}
30+
}
31+
}
32+
return differentList;
33+
}
34+
35+
public static int needMove(int index, List<CharacterDiffResult> differentList) {
36+
for (CharacterDiffResult different : differentList) {
37+
if (different.fromIndex == index) {
38+
return different.moveIndex;
39+
}
40+
}
41+
return -1;
42+
}
43+
44+
public static boolean stayHere(int index, List<CharacterDiffResult> differentList) {
45+
for (CharacterDiffResult different : differentList) {
46+
if (different.moveIndex == index) {
47+
return true;
48+
}
49+
}
50+
return false;
51+
}
52+
53+
54+
// 计算x坐标的位置
55+
public static float getOffset(int from, int move, float progress, float startX, float oldStartX,
56+
List<Float> gaps, List<Float> oldGaps) {
57+
58+
float dist = startX;
59+
for (int i = 0; i < move; i++) {
60+
dist += gaps.get(i);
61+
}
62+
63+
float cur = oldStartX;
64+
for (int i = 0; i < from; i++) {
65+
cur += oldGaps.get(i);
66+
}
67+
68+
return cur + (dist - cur) * progress;
69+
70+
}
71+
}

0 commit comments

Comments
 (0)