├── .classpath
├── .project
├── .settings
├── org.eclipse.core.resources.prefs
└── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── README.md
├── bin
├── AndroidManifest.xml
├── EmojiDrop.apk
├── classes.dex
├── dexedLibs
│ └── android-support-v4-f5a83daaf654e457a49c3294e03f4e02.jar
├── jarlist.cache
├── res
│ └── crunch
│ │ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ │ └── drawable-xxhdpi
│ │ ├── dog.png
│ │ └── ic_launcher.png
└── resources.ap_
├── 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
│ ├── dog.png
│ └── ic_launcher.png
├── layout
│ ├── activity_main.xml
│ ├── fragment_main.xml
│ ├── item_left.xml
│ └── item_right.xml
├── menu
│ └── main.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
├── values-w820dp
│ └── dimens.xml
└── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
└── example
└── emojidrop
├── EmojiView.java
├── MainActivity.java
├── Message.java
└── Point.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | EmojiDrop
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 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=UTF-8
3 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 仿QQ输入关键字 表情掉落
2 |
3 | 输入 aa 可以出现小狗表情的掉落的效果
4 |
5 | 掉落动画开始后可以滑动Listview 表情位置不会出错
6 |
7 | 
8 |
--------------------------------------------------------------------------------
/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/bin/EmojiDrop.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/bin/EmojiDrop.apk
--------------------------------------------------------------------------------
/bin/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/bin/classes.dex
--------------------------------------------------------------------------------
/bin/dexedLibs/android-support-v4-f5a83daaf654e457a49c3294e03f4e02.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/bin/dexedLibs/android-support-v4-f5a83daaf654e457a49c3294e03f4e02.jar
--------------------------------------------------------------------------------
/bin/jarlist.cache:
--------------------------------------------------------------------------------
1 | # cache for current jar dependency. DO NOT EDIT.
2 | # format is
3 | # Encoding is UTF-8
4 |
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/bin/res/crunch/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/bin/res/crunch/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/bin/res/crunch/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xxhdpi/dog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/bin/res/crunch/drawable-xxhdpi/dog.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/bin/res/crunch/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/resources.ap_:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/bin/resources.ap_
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/ic_launcher-web.png
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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-19
15 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/dog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/res/drawable-xxhdpi/dog.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyjAndroid/EmojiDrop/9738d2500bed0a27b83da114441b72125b36df03/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
15 |
16 |
23 |
24 |
29 |
30 |
35 |
36 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/res/layout/item_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
--------------------------------------------------------------------------------
/res/layout/item_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
--------------------------------------------------------------------------------
/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
12 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 | 64dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | EmojiDrop
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/com/example/emojidrop/EmojiView.java:
--------------------------------------------------------------------------------
1 | package com.example.emojidrop;
2 |
3 | import java.util.List;
4 |
5 | import android.animation.Animator;
6 | import android.animation.Animator.AnimatorListener;
7 | import android.animation.ValueAnimator;
8 | import android.animation.ValueAnimator.AnimatorUpdateListener;
9 | import android.annotation.SuppressLint;
10 | import android.content.Context;
11 | import android.graphics.Bitmap;
12 | import android.graphics.BitmapFactory;
13 | import android.graphics.Canvas;
14 | import android.graphics.Color;
15 | import android.graphics.Paint;
16 | import android.graphics.Paint.Style;
17 | import android.graphics.Path;
18 | import android.graphics.PathMeasure;
19 | import android.util.AttributeSet;
20 | import android.view.View;
21 | import android.view.animation.AccelerateInterpolator;
22 | import android.view.animation.BounceInterpolator;
23 |
24 | public class EmojiView extends View {
25 |
26 | private PathMeasure pathMeasure;
27 | private Path path;
28 | private Paint mPaint;
29 | private List points;
30 | private float[] mCurrentPosition = new float[2];
31 | private boolean flag = true;
32 |
33 | public EmojiView(Context context) {
34 | this(context, null);
35 | }
36 |
37 | public EmojiView(Context context, AttributeSet attrs, int defStyle) {
38 | super(context, attrs, defStyle);
39 | init();
40 | }
41 |
42 | public EmojiView(Context context, AttributeSet attrs) {
43 | this(context, attrs, 0);
44 | }
45 |
46 | private void init() {
47 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
48 | mPaint.setStyle(Style.STROKE);
49 | mPaint.setColor(Color.RED);
50 |
51 | pathMeasure = new PathMeasure();
52 | mCurrentPosition = new float[2];
53 | }
54 |
55 | public void setPoint(List pointList,int location) {
56 | this.points = pointList;
57 | path = new Path();
58 |
59 | Point point1 = pointList.get(0);
60 | Point point2 = pointList.get(1);
61 | if(flag){
62 | if(0==point1.getLocation()){
63 | path.moveTo(100, -10);
64 | path.quadTo(100, -10,point1.getX(), point1.getY());
65 | }else{
66 | path.moveTo(600, -10);
67 | path.quadTo(600, -10,point1.getX(), point1.getY());
68 | }
69 | flag = false;
70 | }else{
71 | path.moveTo(point1.getX(), point1.getY());
72 | }
73 |
74 | if (point1.getLocation() == point2.getLocation()) {
75 | if (0 == point2.getLocation()) {
76 | path.cubicTo(point1.getX(), point1.getY(), point1.getX() + 50,
77 | point1.getY() - 100, point2.getX()+50, point2.getY());
78 | point2.setX(point2.getX()+50);
79 | } else {
80 | path.cubicTo(point1.getX(), point1.getY(), point1.getX() - 50,
81 | point1.getY() - 100, point2.getX()-50, point2.getY());
82 | point2.setX(point2.getX()-50);
83 | }
84 | } else {
85 | if (0 == point1.getLocation())
86 | path.cubicTo(point1.getX(), point1.getY(), point1.getX() + 250,
87 | point1.getY() - 200, point2.getX(), point2.getY());
88 | else
89 | path.cubicTo(point1.getX(), point1.getY(), point1.getX() - 250,
90 | point1.getY() - 200, point2.getX(), point2.getY());
91 | }
92 |
93 | pathMeasure.setPath(path, false);
94 | }
95 |
96 | @SuppressLint("DrawAllocation")
97 | protected void onDraw(Canvas canvas) {
98 | super.onDraw(canvas);
99 | canvas.drawColor(Color.TRANSPARENT);
100 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
101 | R.drawable.dog);
102 | canvas.drawBitmap(bitmap, mCurrentPosition[0], mCurrentPosition[1]-bitmap.getHeight(),
103 | mPaint);
104 | }
105 |
106 | public void startPathAnim(long duration) {
107 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(0,
108 | pathMeasure.getLength());
109 | valueAnimator.setDuration(duration);
110 | valueAnimator.setInterpolator(new AccelerateInterpolator());
111 | valueAnimator.addUpdateListener(new AnimatorUpdateListener() {
112 |
113 | @Override
114 | public void onAnimationUpdate(ValueAnimator animation) {
115 | float value = (Float) animation.getAnimatedValue();
116 | // 获取当前点坐标封装到mCurrentPosition
117 | pathMeasure.getPosTan(value, mCurrentPosition, null);
118 | postInvalidate();
119 | }
120 | });
121 | valueAnimator.addListener(new AnimatorListener() {
122 |
123 | @Override
124 | public void onAnimationStart(Animator animation) {
125 | }
126 |
127 | @Override
128 | public void onAnimationRepeat(Animator animation) {
129 | }
130 |
131 | @Override
132 | public void onAnimationEnd(Animator animation) {
133 | if(points.size()<1){
134 | return;
135 | }
136 | path = new Path();
137 | Point point = points.get(1);
138 | path.moveTo(point.getX(), point.getY());
139 | path.quadTo(point.getX(), point.getY(),point.getX(), point.getY()-30);
140 | path.quadTo(point.getX(), point.getY()-30,point.getX(), point.getY());
141 | pathMeasure.setPath(path, false);
142 |
143 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(0,
144 | pathMeasure.getLength());
145 | valueAnimator.setDuration(1500);
146 | valueAnimator.setInterpolator(new BounceInterpolator());
147 | valueAnimator.addUpdateListener(new AnimatorUpdateListener() {
148 |
149 | @Override
150 | public void onAnimationUpdate(ValueAnimator animation) {
151 | float value = (Float) animation.getAnimatedValue();
152 | // 获取当前点坐标封装到mCurrentPosition
153 | pathMeasure.getPosTan(value, mCurrentPosition, null);
154 | postInvalidate();
155 | }
156 | });
157 | valueAnimator.addListener(new AnimatorListener() {
158 |
159 | @Override
160 | public void onAnimationStart(Animator animation) {
161 | }
162 |
163 | @Override
164 | public void onAnimationRepeat(Animator animation) {
165 | }
166 |
167 | @Override
168 | public void onAnimationEnd(Animator animation) {
169 | if(points.size()>=3){
170 | points.remove(0);
171 | setPoint(points,points.get(0).getLocation());
172 | startPathAnim(1500);
173 | }else{
174 | setVisibility(View.GONE);
175 | }
176 | }
177 |
178 | @Override
179 | public void onAnimationCancel(Animator animation) {
180 | }
181 | });
182 | valueAnimator.start();
183 | }
184 |
185 | @Override
186 | public void onAnimationCancel(Animator animation) {
187 | }
188 | });
189 | valueAnimator.start();
190 | }
191 |
192 | }
193 |
--------------------------------------------------------------------------------
/src/com/example/emojidrop/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.emojidrop;
2 |
3 | import java.util.ArrayList;
4 |
5 | import android.app.Activity;
6 | import android.os.Bundle;
7 | import android.os.Handler;
8 | import android.view.MotionEvent;
9 | import android.view.View;
10 | import android.view.View.OnClickListener;
11 | import android.view.View.OnTouchListener;
12 | import android.view.ViewGroup;
13 | import android.view.Window;
14 | import android.widget.BaseAdapter;
15 | import android.widget.Button;
16 | import android.widget.EditText;
17 | import android.widget.ListView;
18 | import android.widget.RelativeLayout;
19 | import android.widget.RelativeLayout.LayoutParams;
20 | import android.widget.TextView;
21 |
22 | public class MainActivity extends Activity implements OnClickListener {
23 |
24 | private ArrayList dateList;
25 | private ListView mListView;
26 | private RelativeLayout rl;
27 | private Button mBtnLeft;
28 | private Button mBtnRight;
29 | private EditText mEdit;
30 | private MyListAdapter myListAdapter;
31 | private EmojiView emojiView;
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | this.requestWindowFeature(Window.FEATURE_NO_TITLE);
37 | setContentView(R.layout.activity_main);
38 |
39 | initView();
40 | initData();
41 |
42 | }
43 |
44 | private void initData() {
45 | dateList = new ArrayList();
46 | dateList.add(new Message("aaaaaa", 0));//left:0 right:1
47 | dateList.add(new Message("aaaaaa", 1));
48 | dateList.add(new Message("aaaaaa", 1));
49 | dateList.add(new Message("aaaaaa", 0));
50 |
51 | myListAdapter = new MyListAdapter();
52 | mListView.setAdapter(myListAdapter);
53 | }
54 |
55 | private void initView() {
56 | mListView = (ListView) findViewById(R.id.list_id);
57 | rl = (RelativeLayout) findViewById(R.id.rl);
58 | mBtnLeft = (Button) findViewById(R.id.btn_left);
59 | mBtnRight = (Button) findViewById(R.id.btn_right);
60 | mEdit = (EditText) findViewById(R.id.edit);
61 |
62 | mBtnLeft.setOnClickListener(this);
63 | mBtnRight.setOnClickListener(this);
64 |
65 | mListView.setOnTouchListener(new OnTouchListener() {
66 | float startY = 0;
67 | @Override
68 | public boolean onTouch(View v, MotionEvent event) {
69 | switch (event.getAction()) {
70 | case MotionEvent.ACTION_DOWN:
71 | startY = event.getY();
72 | break;
73 | case MotionEvent.ACTION_MOVE:
74 | float y = event.getY();
75 | float moveY = y -startY ;
76 | startY = y;
77 | //获取手指滑动的偏移量 使动画不会位置错乱
78 | if(emojiView!=null){
79 | LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
80 | layoutParams.topMargin = (int) (emojiView.getTop()+moveY);
81 | emojiView.setLayoutParams(layoutParams);
82 | }
83 |
84 | break;
85 | case MotionEvent.ACTION_UP:
86 |
87 | break;
88 |
89 | }
90 | return false;
91 | }
92 | });
93 | }
94 |
95 | /**
96 | * 获取状态栏的高度
97 | *
98 | * @return
99 | */
100 | public int getStatusBarHeight() {
101 | int result = 0;
102 | int resourceId = getResources().getIdentifier("status_bar_height",
103 | "dimen", "android");
104 | if (resourceId > 0) {
105 | result = getResources().getDimensionPixelSize(resourceId);
106 | }
107 | return result;
108 | }
109 |
110 | class MyListAdapter extends BaseAdapter {
111 |
112 | @Override
113 | public int getCount() {
114 | return dateList.size();
115 | }
116 |
117 | @Override
118 | public Object getItem(int position) {
119 | return dateList.get(position);
120 | }
121 |
122 | @Override
123 | public long getItemId(int position) {
124 | return position;
125 | }
126 |
127 | @Override
128 | public View getView(int position, View convertView, ViewGroup parent) {
129 | ViewHolder mViewHolder;
130 | int type = getItemViewType(position);
131 | if (convertView == null) {
132 | if (0 == type)
133 | convertView = View.inflate(MainActivity.this,
134 | R.layout.item_left, null);
135 | else {
136 | convertView = View.inflate(MainActivity.this,
137 | R.layout.item_right, null);
138 | }
139 | mViewHolder = createViewHolder(convertView);
140 | convertView.setTag(mViewHolder);
141 | } else {
142 | mViewHolder = (ViewHolder) convertView.getTag();
143 | }
144 |
145 | mViewHolder.mTextView.setText(dateList.get(position).getContent());
146 |
147 | return convertView;
148 | }
149 |
150 | @Override
151 | public int getItemViewType(int position) {
152 | return dateList.get(position).getLocation();
153 | }
154 |
155 | @Override
156 | public int getViewTypeCount() {
157 | return 2;
158 | }
159 |
160 | }
161 |
162 | private ViewHolder createViewHolder(View view) {
163 | ViewHolder viewHolder = new ViewHolder();
164 | viewHolder.mTextView = (TextView) view.findViewById(R.id.item_text);
165 | return viewHolder;
166 | }
167 |
168 | class ViewHolder {
169 | private TextView mTextView;
170 | }
171 |
172 | @Override
173 | public void onClick(View v) {
174 | if(!mEdit.getText().toString().isEmpty()){
175 | switch (v.getId()) {
176 | case R.id.btn_left:
177 | dateList.add(new Message(mEdit.getText().toString(), 0));
178 | break;
179 | case R.id.btn_right:
180 | dateList.add(new Message(mEdit.getText().toString(), 1));
181 | break;
182 |
183 | }
184 | myListAdapter.notifyDataSetChanged();
185 | new Handler().postDelayed(new Runnable() {
186 | @Override
187 | public void run() {
188 | //在这过滤是否有关键词,有则开启动画
189 | if("aa".equals(mEdit.getText().toString())){
190 | int firstVisiblePosition = mListView.getFirstVisiblePosition();
191 |
192 | int lastVisiblePosition = mListView.getLastVisiblePosition();
193 | ArrayList arrayList = new ArrayList();
194 | for (int i = 0, currentPos = firstVisiblePosition; i <= lastVisiblePosition-firstVisiblePosition; i++,currentPos++) {
195 | View v1 = mListView.getChildAt(i);
196 | if(v1==null){
197 | return;
198 | }
199 | View tx = v1.findViewById(R.id.item_text);
200 | int[] p = new int[2];
201 | tx.getLocationInWindow(p);
202 |
203 | Point point = new Point();
204 | if (0 == dateList.get(currentPos).getLocation()) {
205 | point.setLocation(dateList.get(currentPos).getLocation());
206 | point.setXY(p[0] + 100, p[1] - getStatusBarHeight() - i);
207 | } else {
208 | point.setLocation(dateList.get(currentPos).getLocation());
209 | point.setXY(600, p[1] - getStatusBarHeight() - i);
210 | }
211 | arrayList.add(point);
212 | }
213 |
214 | emojiView = new EmojiView(MainActivity.this);
215 | rl.addView(emojiView,1);
216 | emojiView.setPoint(arrayList, arrayList.get(0).getLocation());
217 | emojiView.startPathAnim(1500);
218 | }
219 | }
220 | }, 1000);
221 | }
222 | }
223 | }
224 |
--------------------------------------------------------------------------------
/src/com/example/emojidrop/Message.java:
--------------------------------------------------------------------------------
1 | package com.example.emojidrop;
2 |
3 | public class Message {
4 |
5 | private String content;
6 | private int location;//left:0 right:1
7 | public String getContent() {
8 | return content;
9 | }
10 | public int getLocation() {
11 | return location;
12 | }
13 | public void setContent(String content) {
14 | this.content = content;
15 | }
16 | public void setLocation(int location) {
17 | this.location = location;
18 | }
19 |
20 |
21 | public Message(String content,int location){
22 | this.content = content;
23 | this.location = location;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/com/example/emojidrop/Point.java:
--------------------------------------------------------------------------------
1 | package com.example.emojidrop;
2 |
3 | public class Point {
4 |
5 | private float x;
6 |
7 | private float y;
8 |
9 | private int location;//left:0 right:1
10 |
11 | public int getLocation() {
12 | return location;
13 | }
14 |
15 | public void setLocation(int location) {
16 | this.location = location;
17 | }
18 |
19 | public float getX() {
20 | return x;
21 | }
22 |
23 | public float getY() {
24 | return y;
25 | }
26 |
27 | public void setX(float x) {
28 | this.x = x;
29 | }
30 |
31 | public void setY(float y) {
32 | this.y = y;
33 | }
34 |
35 | public void setXY(float x,float y){
36 | this.x = x;
37 | this.y = y;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------