├── .gitattributes
├── .gitignore
├── README.md
└── TypeTextView
├── .classpath
├── .project
├── .settings
└── org.eclipse.core.resources.prefs
├── AndroidManifest.xml
├── bin
├── AndroidManifest.xml
├── TypeTextView.apk
├── classes.dex
├── classes
│ └── com
│ │ └── uperone
│ │ ├── typetext
│ │ └── view
│ │ │ ├── TypeTextView$1.class
│ │ │ ├── TypeTextView$OnTypeViewListener.class
│ │ │ ├── TypeTextView$TypeTimerTask$1.class
│ │ │ ├── TypeTextView$TypeTimerTask.class
│ │ │ └── TypeTextView.class
│ │ └── typetextview
│ │ ├── BaseActivity.class
│ │ ├── BuildConfig.class
│ │ ├── R$attr.class
│ │ ├── R$drawable.class
│ │ ├── R$id.class
│ │ ├── R$layout.class
│ │ ├── R$raw.class
│ │ ├── R$string.class
│ │ ├── R.class
│ │ ├── TypeTextViewActivity$1.class
│ │ └── TypeTextViewActivity.class
├── dexedLibs
│ ├── android-support-v4-72f6caf5237504f63c425bd17b7894f6.jar
│ └── annotations-e51552d4fbe0d7bd5d4bb1349e013f21.jar
├── res
│ └── crunch
│ │ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ │ └── drawable-xxhdpi
│ │ └── ic_launcher.png
└── resources.ap_
├── gen
└── com
│ └── uperone
│ └── typetextview
│ ├── BuildConfig.java
│ └── R.java
├── ic_launcher-web.png
├── libs
└── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── layout
│ └── activity_type_text_view_layout.xml
├── raw
│ └── type_in.wav
└── values
│ └── strings.xml
└── src
└── com
└── uperone
├── typetext
└── view
│ └── TypeTextView.java
└── typetextview
├── BaseActivity.java
└── TypeTextViewActivity.java
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # Windows shortcuts
18 | *.lnk
19 |
20 | # =========================
21 | # Operating System Files
22 | # =========================
23 |
24 | # OSX
25 | # =========================
26 |
27 | .DS_Store
28 | .AppleDouble
29 | .LSOverride
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear on external disk
35 | .Spotlight-V100
36 | .Trashes
37 |
38 | # Directories potentially created on remote AFP share
39 | .AppleDB
40 | .AppleDesktop
41 | Network Trash Folder
42 | Temporary Items
43 | .apdisk
44 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## 说明
2 |
3 | **描述:**模仿打字机的效果,字一个一个地蹦出来,伴随打字机的声音。
4 |
5 | **效果:**
6 |
7 | 
8 |
9 | ## 使用说明:
10 |
11 | 1. 在xml文件中定义:
12 |
13 |
18 |
19 | 2. 在代码中实例化:
20 |
21 | mTypeTextView = ( TypeTextView )findViewById(R.id.typeTxtId);
22 | mTypeTextView.setOnTypeViewListener( new OnTypeViewListener( ) {
23 | @Override
24 | public void onTypeStart() {
25 | print( "onTypeStart" );
26 | }
27 |
28 | @Override
29 | public void onTypeOver() {
30 | print( "onTypeOver" );
31 | }
32 | });
33 |
34 | 3. 调用start方法:
35 |
36 | mTypeTextView.start( TEST_DATA );
37 |
38 | ## 关于作者:
39 |
40 | **姓名:**张明云
41 |
42 | **博客:**[zmywly8866](http://zmywly8866.github.io/)
43 |
44 | **知乎:**[zmywly8866](http://www.zhihu.com/people/zhang-ming-yun-97)
45 |
46 | **简书:**[zmywly8866](http://www.jianshu.com/users/e6885381f7d4/latest_articles)
--------------------------------------------------------------------------------
/TypeTextView/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/TypeTextView/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | TypeTextView
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/TypeTextView/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=UTF-8
3 |
--------------------------------------------------------------------------------
/TypeTextView/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/TypeTextView/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/TypeTextView/bin/TypeTextView.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/TypeTextView.apk
--------------------------------------------------------------------------------
/TypeTextView/bin/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes.dex
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetext/view/TypeTextView$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetext/view/TypeTextView$1.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetext/view/TypeTextView$OnTypeViewListener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetext/view/TypeTextView$OnTypeViewListener.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetext/view/TypeTextView$TypeTimerTask$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetext/view/TypeTextView$TypeTimerTask$1.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetext/view/TypeTextView$TypeTimerTask.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetext/view/TypeTextView$TypeTimerTask.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetext/view/TypeTextView.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetext/view/TypeTextView.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetextview/BaseActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetextview/BaseActivity.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetextview/BuildConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetextview/BuildConfig.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetextview/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetextview/R$attr.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetextview/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetextview/R$drawable.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetextview/R$id.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetextview/R$id.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetextview/R$layout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetextview/R$layout.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetextview/R$raw.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetextview/R$raw.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetextview/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetextview/R$string.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetextview/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetextview/R.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetextview/TypeTextViewActivity$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetextview/TypeTextViewActivity$1.class
--------------------------------------------------------------------------------
/TypeTextView/bin/classes/com/uperone/typetextview/TypeTextViewActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/classes/com/uperone/typetextview/TypeTextViewActivity.class
--------------------------------------------------------------------------------
/TypeTextView/bin/dexedLibs/android-support-v4-72f6caf5237504f63c425bd17b7894f6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/dexedLibs/android-support-v4-72f6caf5237504f63c425bd17b7894f6.jar
--------------------------------------------------------------------------------
/TypeTextView/bin/dexedLibs/annotations-e51552d4fbe0d7bd5d4bb1349e013f21.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/dexedLibs/annotations-e51552d4fbe0d7bd5d4bb1349e013f21.jar
--------------------------------------------------------------------------------
/TypeTextView/bin/res/crunch/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/res/crunch/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/TypeTextView/bin/res/crunch/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/res/crunch/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/TypeTextView/bin/res/crunch/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/res/crunch/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/TypeTextView/bin/res/crunch/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/res/crunch/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/TypeTextView/bin/resources.ap_:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/bin/resources.ap_
--------------------------------------------------------------------------------
/TypeTextView/gen/com/uperone/typetextview/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.uperone.typetextview;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/TypeTextView/gen/com/uperone/typetextview/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.uperone.typetextview;
9 |
10 | public final class R {
11 | public static final class attr {
12 | }
13 | public static final class drawable {
14 | public static final int ic_launcher=0x7f020000;
15 | }
16 | public static final class id {
17 | public static final int showBtnId=0x7f060001;
18 | public static final int typeTxtId=0x7f060000;
19 | }
20 | public static final class layout {
21 | public static final int activity_type_text_view_layout=0x7f030000;
22 | }
23 | public static final class raw {
24 | public static final int type_in=0x7f040000;
25 | }
26 | public static final class string {
27 | public static final int app_name=0x7f050000;
28 | public static final int hello_world=0x7f050001;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/TypeTextView/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/ic_launcher-web.png
--------------------------------------------------------------------------------
/TypeTextView/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/TypeTextView/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/TypeTextView/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-15
15 |
--------------------------------------------------------------------------------
/TypeTextView/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/TypeTextView/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/TypeTextView/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/TypeTextView/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/TypeTextView/res/layout/activity_type_text_view_layout.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
11 |
12 |
20 |
21 |
--------------------------------------------------------------------------------
/TypeTextView/res/raw/type_in.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zmywly8866/TypeTextView/1333ca66d6e3fbff5527ea58d064da75ebee10f8/TypeTextView/res/raw/type_in.wav
--------------------------------------------------------------------------------
/TypeTextView/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | TypeTextView
5 | Hello world!
6 |
7 |
8 |
--------------------------------------------------------------------------------
/TypeTextView/src/com/uperone/typetext/view/TypeTextView.java:
--------------------------------------------------------------------------------
1 | package com.uperone.typetext.view;
2 |
3 | import java.util.Timer;
4 | import java.util.TimerTask;
5 |
6 | import android.content.Context;
7 | import android.media.MediaPlayer;
8 | import android.text.TextUtils;
9 | import android.util.AttributeSet;
10 | import android.widget.TextView;
11 |
12 | import com.uperone.typetextview.R;
13 |
14 | /**
15 | * 模拟打字机效果
16 | *
17 | * */
18 | public class TypeTextView extends TextView {
19 | private Context mContext = null;
20 | private MediaPlayer mMediaPlayer = null;
21 | private String mShowTextString = null;
22 | private Timer mTypeTimer = null;
23 | private OnTypeViewListener mOnTypeViewListener = null;
24 | private static final int TYPE_TIME_DELAY = 80;
25 | private int mTypeTimeDelay = TYPE_TIME_DELAY; // 打字间隔
26 |
27 | public TypeTextView(Context context, AttributeSet attrs, int defStyle) {
28 | super(context, attrs, defStyle);
29 | initTypeTextView( context );
30 | }
31 |
32 | public TypeTextView(Context context, AttributeSet attrs) {
33 | super(context, attrs);
34 | initTypeTextView( context );
35 | }
36 |
37 | public TypeTextView(Context context) {
38 | super(context);
39 | initTypeTextView( context );
40 | }
41 |
42 | public void setOnTypeViewListener( OnTypeViewListener onTypeViewListener ){
43 | mOnTypeViewListener = onTypeViewListener;
44 | }
45 |
46 | public void start( final String textString ){
47 | start( textString, TYPE_TIME_DELAY );
48 | }
49 |
50 | public void start( final String textString, final int typeTimeDelay ){
51 | if( TextUtils.isEmpty( textString ) || typeTimeDelay < 0 ){
52 | return;
53 | }
54 | post( new Runnable( ) {
55 | @Override
56 | public void run() {
57 | mShowTextString = textString;
58 | mTypeTimeDelay = typeTimeDelay;
59 | setText( "" );
60 | startTypeTimer( );
61 | if( null != mOnTypeViewListener ){
62 | mOnTypeViewListener.onTypeStart( );
63 | }
64 | }
65 | });
66 | }
67 |
68 | public void stop( ){
69 | stopTypeTimer( );
70 | stopAudio();
71 | }
72 |
73 | private void initTypeTextView( Context context ){
74 | mContext = context;
75 | }
76 |
77 | private void startTypeTimer( ){
78 | stopTypeTimer( );
79 | mTypeTimer = new Timer( );
80 | mTypeTimer.schedule( new TypeTimerTask(), mTypeTimeDelay );
81 | }
82 |
83 | private void stopTypeTimer( ){
84 | if( null != mTypeTimer ){
85 | mTypeTimer.cancel( );
86 | mTypeTimer = null;
87 | }
88 | }
89 |
90 | private void startAudioPlayer() {
91 | stopAudio();
92 | playAudio( R.raw.type_in );
93 | }
94 |
95 | private void playAudio( int audioResId ){
96 | try{
97 | stopAudio( );
98 | mMediaPlayer = MediaPlayer.create( mContext, audioResId );
99 | mMediaPlayer.start( );
100 | }catch( Exception e ){
101 | e.printStackTrace();
102 | }
103 | }
104 |
105 | private void stopAudio( ){
106 | if( mMediaPlayer != null && mMediaPlayer.isPlaying( ) ){
107 | mMediaPlayer.stop( );
108 | mMediaPlayer.release( );
109 | mMediaPlayer = null;
110 | }
111 | }
112 |
113 | class TypeTimerTask extends TimerTask{
114 | @Override
115 | public void run() {
116 | post(new Runnable( ) {
117 | @Override
118 | public void run() {
119 | if( getText( ).toString( ).length( ) < mShowTextString.length( ) ){
120 | setText( mShowTextString.substring(0, getText( ).toString( ).length( ) + 1 ) );
121 | startAudioPlayer();
122 | startTypeTimer( );
123 | }else{
124 | stopTypeTimer( );
125 | if( null != mOnTypeViewListener ){
126 | mOnTypeViewListener.onTypeOver( );
127 | }
128 | }
129 | }
130 | });
131 | }
132 | }
133 |
134 | public interface OnTypeViewListener{
135 | public void onTypeStart( );
136 | public void onTypeOver( );
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/TypeTextView/src/com/uperone/typetextview/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.uperone.typetextview;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | public abstract class BaseActivity extends Activity {
7 | @Override
8 | protected void onCreate(Bundle savedInstanceState) {
9 | super.onCreate(savedInstanceState);
10 | init( );
11 | }
12 |
13 | private void init( ){
14 | setContentView( );
15 | findViews( );
16 | getData( );
17 | showConent( );
18 | }
19 |
20 | public abstract void setContentView( );
21 | public abstract void findViews( );
22 | public abstract void getData( );
23 | public abstract void showConent( );
24 | }
25 |
--------------------------------------------------------------------------------
/TypeTextView/src/com/uperone/typetextview/TypeTextViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.uperone.typetextview;
2 |
3 | import android.view.View;
4 |
5 | import com.uperone.typetext.view.TypeTextView;
6 | import com.uperone.typetext.view.TypeTextView.OnTypeViewListener;
7 |
8 | public class TypeTextViewActivity extends BaseActivity {
9 | private TypeTextView mTypeTextView = null;
10 | private static final String TEST_DATA = "题主我觉得你大概是被我们的同事三天两头就去问问题要材料搞烦了。。不过我们每年都来,一来就好几个月,在会议室里面天天熬到半夜这样的事情我们也是没有办法的啊!因为作为一个企业,无论是私企还是国企,公司的所有者和经营者一般都是分开的。所谓所有者,就是股东,而经营者就是企业各级管理人员。";
11 |
12 | @Override
13 | public void setContentView() {
14 | setContentView(R.layout.activity_type_text_view_layout);
15 | }
16 |
17 | @Override
18 | public void findViews() {
19 | mTypeTextView = ( TypeTextView )findViewById(R.id.typeTxtId);
20 | mTypeTextView.setOnTypeViewListener( new OnTypeViewListener( ) {
21 | @Override
22 | public void onTypeStart() {
23 | print( "onTypeStart" );
24 | }
25 |
26 | @Override
27 | public void onTypeOver() {
28 | print( "onTypeOver" );
29 | }
30 | });
31 | }
32 |
33 | @Override
34 | public void getData() {
35 |
36 | }
37 |
38 | @Override
39 | public void showConent() {
40 | mTypeTextView.start( TEST_DATA );
41 | }
42 |
43 | public void onClick( View v ){
44 | if( v.getId( ) == R.id.showBtnId ){
45 | showConent( );
46 | }
47 | }
48 |
49 | private void print( String printStr ){
50 | System.out.println( "TAG == TypeTextViewActivity, info == " + printStr );
51 | }
52 | }
53 |
--------------------------------------------------------------------------------