├── .classpath
├── .gitignore
├── .project
├── AndroidManifest.xml
├── 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
│ ├── yh_dynamic_content_bg1.png
│ ├── yh_dynamic_content_bg2.png
│ ├── yh_dynamic_item_comment1.png
│ ├── yh_dynamic_item_comment2.png
│ ├── yh_dynamic_item_more.png
│ ├── yh_dynamic_item_scomment1.png
│ ├── yh_dynamic_item_scomment2.png
│ ├── yh_dynamic_item_szan1.png
│ ├── yh_dynamic_item_szan2.png
│ ├── yh_dynamic_item_zan1.png
│ └── yh_dynamic_item_zan2.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── drawable
│ ├── x_yh_dynamic_content_bg.xml
│ ├── x_yh_dynamic_item_commemt.xml
│ ├── x_yh_dynamic_item_scommemt.xml
│ ├── x_yh_dynamic_item_szan1.xml
│ ├── x_yh_dynamic_item_szan2.xml
│ ├── x_yh_dynamic_item_zan1.xml
│ └── x_yh_dynamic_item_zan2.xml
├── layout
│ ├── yh_dynamic_detail.xml
│ ├── yh_dynamic_detail_head.xml
│ ├── yh_dynamic_detail_list.xml
│ ├── yh_dynamic_item.xml
│ ├── yh_dynamic_item_commently.xml
│ └── yh_dynamic_main.xml
└── values
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
└── myexample
└── dynamic
├── activity
├── DynamicActivity.java
└── DynamicDetailActivity.java
├── adapter
├── DynamicAdapter.java
├── DynamicCommentAdapter.java
└── DynamicPageAdapter.java
├── bean
├── Dynamic.java
├── DynamicComment.java
├── User.java
└── UserClickSpan.java
├── fragment
└── DynamicDetailFragment.java
└── view
├── DynamicDetailHeadView.java
└── DynamicItemView.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Custom
2 | _site
3 |
4 | # Ant
5 | MANIFEST.MF
6 | ./*.jar
7 | build.num
8 | build
9 |
10 | # ADT
11 | .settings
12 | local.properties
13 | bin
14 | gen
15 | _layouts
16 | proguard.cfg
17 |
18 | # OSX
19 | .DS_Store
20 |
21 | # Github
22 | gh-pages
23 |
24 | # Gradle
25 | .gradle
26 | build
27 |
28 | # IDEA
29 | *.iml
30 | *.ipr
31 | *.iws
32 | out
33 | .idea
34 |
35 | # Maven
36 | target
37 | release.properties
38 |
39 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Dynamic
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 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
15 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/ic_launcher-web.png
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/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-8
15 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/yh_dynamic_content_bg1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-xhdpi/yh_dynamic_content_bg1.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/yh_dynamic_content_bg2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-xhdpi/yh_dynamic_content_bg2.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/yh_dynamic_item_comment1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-xhdpi/yh_dynamic_item_comment1.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/yh_dynamic_item_comment2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-xhdpi/yh_dynamic_item_comment2.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/yh_dynamic_item_more.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-xhdpi/yh_dynamic_item_more.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/yh_dynamic_item_scomment1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-xhdpi/yh_dynamic_item_scomment1.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/yh_dynamic_item_scomment2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-xhdpi/yh_dynamic_item_scomment2.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/yh_dynamic_item_szan1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-xhdpi/yh_dynamic_item_szan1.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/yh_dynamic_item_szan2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-xhdpi/yh_dynamic_item_szan2.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/yh_dynamic_item_zan1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-xhdpi/yh_dynamic_item_zan1.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/yh_dynamic_item_zan2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-xhdpi/yh_dynamic_item_zan2.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djun100/android-source-WeChat-friends/a60906f415c67faeb10cbf76dc5252e957501533/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable/x_yh_dynamic_content_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/drawable/x_yh_dynamic_item_commemt.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/res/drawable/x_yh_dynamic_item_scommemt.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/res/drawable/x_yh_dynamic_item_szan1.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/res/drawable/x_yh_dynamic_item_szan2.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/res/drawable/x_yh_dynamic_item_zan1.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/res/drawable/x_yh_dynamic_item_zan2.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/res/layout/yh_dynamic_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/res/layout/yh_dynamic_detail_head.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
16 |
17 |
21 |
22 |
23 |
26 |
27 |
32 |
33 |
40 |
41 |
48 |
49 |
50 |
51 |
57 |
58 |
59 |
65 |
66 |
73 |
74 |
82 |
83 |
84 |
85 |
92 |
93 |
98 |
99 |
107 |
108 |
109 |
118 |
119 |
120 |
127 |
128 |
132 |
133 |
138 |
139 |
140 |
148 |
149 |
150 |
157 |
158 |
162 |
163 |
168 |
169 |
170 |
178 |
179 |
180 |
181 |
--------------------------------------------------------------------------------
/res/layout/yh_dynamic_detail_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
17 |
18 |
24 |
25 |
29 |
30 |
33 |
34 |
40 |
41 |
48 |
49 |
55 |
56 |
57 |
58 |
62 |
63 |
64 |
65 |
73 |
74 |
79 |
80 |
86 |
87 |
88 |
101 |
102 |
109 |
110 |
111 |
112 |
113 |
118 |
119 |
120 |
124 |
125 |
126 |
130 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/res/layout/yh_dynamic_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
16 |
17 |
21 |
22 |
23 |
26 |
27 |
32 |
33 |
40 |
41 |
48 |
49 |
50 |
51 |
57 |
58 |
59 |
65 |
66 |
73 |
74 |
82 |
83 |
84 |
85 |
92 |
93 |
98 |
99 |
107 |
108 |
109 |
118 |
119 |
120 |
127 |
128 |
132 |
133 |
138 |
139 |
140 |
148 |
149 |
150 |
157 |
158 |
162 |
163 |
168 |
169 |
170 |
178 |
179 |
180 |
185 |
186 |
187 |
188 |
193 |
197 |
198 |
201 |
202 |
208 |
209 |
216 |
217 |
218 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
235 |
236 |
237 |
238 |
--------------------------------------------------------------------------------
/res/layout/yh_dynamic_item_commently.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
13 |
14 |
15 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/res/layout/yh_dynamic_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
26 |
27 |
32 |
33 |
39 |
40 |
41 |
54 |
55 |
62 |
63 |
64 |
65 |
66 |
71 |
72 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Dynamic
4 |
5 |
6 | 57dip
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/com/myexample/dynamic/activity/DynamicActivity.java:
--------------------------------------------------------------------------------
1 | package com.myexample.dynamic.activity;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.graphics.Rect;
7 | import android.os.Bundle;
8 | import android.os.Handler;
9 | import android.util.Log;
10 | import android.view.View;
11 | import android.view.ViewTreeObserver.OnGlobalLayoutListener;
12 | import android.view.inputmethod.InputMethodManager;
13 | import android.widget.EditText;
14 | import android.widget.LinearLayout;
15 | import android.widget.ListView;
16 | import android.widget.Toast;
17 |
18 | import com.myexample.dynamic.R;
19 | import com.myexample.dynamic.adapter.DynamicAdapter;
20 |
21 | public class DynamicActivity extends Activity{
22 |
23 | private LinearLayout commentLy;
24 | private EditText editText;
25 | private ListView listView;
26 | private boolean kbflag;
27 |
28 | private int p,vh;
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.yh_dynamic_main);
34 |
35 | listView=(ListView) findViewById(R.id.listview);
36 | commentLy=(LinearLayout) findViewById(R.id.comment_ly);
37 | editText=(EditText) findViewById(R.id.editText);
38 | listView.setAdapter(new DynamicAdapter(DynamicActivity.this,handler));
39 |
40 | //监听界面的变化,判断当前页面键盘是否显示
41 | final View activityRootView = findViewById(R.id.rl);
42 | activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
43 |
44 | @Override
45 | public void onGlobalLayout() {
46 | if(kbflag){
47 | Rect r = new Rect();
48 | activityRootView.getWindowVisibleDisplayFrame(r);
49 | int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
50 | // Log.e("", "heightDiff:"+heightDiff+" (r.bottom - r.top):"+(r.bottom - r.top));
51 | if (heightDiff<100) {
52 | commentLy.setVisibility(View.GONE);
53 | kbflag=false;
54 | }
55 | }
56 |
57 | }
58 | });
59 |
60 | }
61 |
62 | private Handler handler=new Handler(){
63 | public void handleMessage(android.os.Message msg) {
64 |
65 | switch (msg.what) {
66 | case 411:
67 | Intent intent=new Intent(DynamicActivity.this,DynamicDetailActivity.class);
68 | startActivity(intent);
69 | break;
70 | case 510:
71 | //评论
72 | commentLy.setVisibility(View.VISIBLE);
73 | editText.setFocusable(true);
74 | editText.requestFocus();
75 | editText.setHint("来说说你的想法");
76 | editText.setTag("-1");
77 | showKeyBoard();
78 | p=msg.arg1;
79 | vh=msg.arg2;
80 | scrollList();
81 | Toast.makeText(DynamicActivity.this, "评论", Toast.LENGTH_SHORT).show();
82 | break;
83 | case 511:
84 | //回复
85 | commentLy.setVisibility(View.VISIBLE);
86 | editText.setFocusable(true);
87 | editText.requestFocus();
88 | // editText.setHint("回复"+comment.getNickname()+":");
89 | // editText.setTag(comment.getFriendId());
90 | showKeyBoard();
91 | p=msg.arg1;
92 | vh=msg.arg2;
93 | //第一次显示 commentLy没有高度 所以有问题 建议大家固定commentLy的高度 写死在代码
94 | //先设置默认的高 R.dimen.commentLy_height 如果要记住之前的评论内容的话
95 | // vh+=commentLy.getMeasuredHeight();
96 | vh+=getResources().getDimension(R.dimen.commentLy_height);
97 | scrollList();
98 | Toast.makeText(DynamicActivity.this, "回复", Toast.LENGTH_SHORT).show();
99 | break;
100 |
101 | }
102 | };
103 | };
104 |
105 | private void scrollList(){
106 | handler.postDelayed(new Runnable() {
107 |
108 | @Override
109 | public void run() {
110 | int h=listView.getHeight();
111 | Log.e("xxxxxxxxxx", "h:"+h+" vh:"+vh);
112 | listView.setSelectionFromTop(p, h-vh);
113 | }
114 | }, 300);
115 | }
116 |
117 | private void showKeyBoard(){
118 | handler.postDelayed(new Runnable() {
119 | @Override
120 | public void run() {
121 | InputMethodManager imm=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
122 | imm.showSoftInput(editText, InputMethodManager.RESULT_SHOWN);
123 | imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
124 | kbflag=true;
125 | }
126 | }, 100);
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/com/myexample/dynamic/activity/DynamicDetailActivity.java:
--------------------------------------------------------------------------------
1 | package com.myexample.dynamic.activity;
2 |
3 | import java.util.ArrayList;
4 |
5 | import android.app.Activity;
6 | import android.os.Bundle;
7 | import android.support.v4.app.FragmentActivity;
8 | import android.support.v4.view.ViewPager;
9 |
10 | import com.myexample.dynamic.R;
11 | import com.myexample.dynamic.adapter.DynamicPageAdapter;
12 | import com.myexample.dynamic.bean.Dynamic;
13 |
14 | public class DynamicDetailActivity extends FragmentActivity{
15 |
16 | ViewPager viewPager;
17 | DynamicPageAdapter pageAdapter;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.yh_dynamic_detail);
23 |
24 | viewPager=(ViewPager)findViewById(R.id.dynamic_detail_viewpage);
25 | ArrayList list=new ArrayList();
26 | for (int i = 0; i < 40; i++) {
27 | list.add(new Dynamic());
28 | }
29 |
30 | pageAdapter=new DynamicPageAdapter(DynamicDetailActivity.this, list);
31 | viewPager.setAdapter(pageAdapter);
32 |
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/myexample/dynamic/adapter/DynamicAdapter.java:
--------------------------------------------------------------------------------
1 | package com.myexample.dynamic.adapter;
2 |
3 | import java.util.ArrayList;
4 |
5 | import android.content.Context;
6 | import android.os.Handler;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.BaseAdapter;
10 |
11 | import com.myexample.dynamic.bean.DynamicComment;
12 | import com.myexample.dynamic.bean.User;
13 | import com.myexample.dynamic.view.DynamicItemView;
14 |
15 | public class DynamicAdapter extends BaseAdapter{
16 |
17 | private Context context;
18 | private Handler handler;
19 |
20 |
21 | public DynamicAdapter(Context context,Handler handler){
22 | this.context=context;
23 | this.handler=handler;
24 | }
25 |
26 | @Override
27 | public int getCount() {
28 | return 10;
29 | }
30 |
31 | @Override
32 | public Object getItem(int position) {
33 | return position;
34 | }
35 |
36 | @Override
37 | public long getItemId(int position) {
38 | return position;
39 | }
40 |
41 | @Override
42 | public View getView(int position, View convertView, ViewGroup parent) {
43 |
44 | DynamicItemView itemView=null;
45 | if(convertView==null){
46 | itemView=new DynamicItemView(context);
47 | convertView=itemView.view;
48 | convertView.setTag(itemView);
49 | }else{
50 | itemView=(DynamicItemView)convertView.getTag();
51 | }
52 | itemView.setHandler(handler);
53 | itemView.setPosition(position);
54 | itemView.setZan(getUserList());
55 | itemView.setComment(getDynamicComments());
56 |
57 | itemView.setCommentClick();
58 |
59 | return convertView;
60 | }
61 |
62 |
63 |
64 | public static ArrayList getDynamicComments() {
65 | ArrayList list = new ArrayList();
66 | DynamicComment comment1=new DynamicComment();
67 | comment1.setNickname("麻仓叶");
68 | comment1.setContent("1楼 测试");
69 |
70 | DynamicComment comment2=new DynamicComment();
71 | comment2.setNickname("麻仓叶");
72 | comment2.setContent("2楼 还是我");
73 |
74 | DynamicComment comment3=new DynamicComment();
75 | comment3.setNickname("阿拉波");
76 | comment3.setContent("我现在在最上面");
77 | comment3.setReuserId(3+"");
78 | comment3.setReuserName("麻仓叶");
79 | list.add(comment3);
80 | list.add(comment2);
81 | list.add(comment1);
82 | return list;
83 | }
84 |
85 | public static ArrayList getDynamicComments2() {
86 | ArrayList list = new ArrayList();
87 | for (int i = 0; i < 7; i++) {
88 | DynamicComment comment1=new DynamicComment();
89 | comment1.setNickname("麻仓叶");
90 | comment1.setContent("1楼 测试");
91 |
92 | DynamicComment comment2=new DynamicComment();
93 | comment2.setNickname("麻仓叶");
94 | comment2.setContent("2楼 还是我");
95 |
96 | DynamicComment comment3=new DynamicComment();
97 | comment3.setNickname("阿拉波");
98 | comment3.setContent("我现在在最上面");
99 | comment3.setReuserId(3+"");
100 | comment3.setReuserName("麻仓叶");
101 | list.add(comment3);
102 | list.add(comment2);
103 | list.add(comment1);
104 | }
105 |
106 | return list;
107 | }
108 |
109 |
110 | public static ArrayList getUserList() {
111 | ArrayList list = new ArrayList();
112 | User t1 = new User();
113 | t1.setName("麻仓叶");
114 | User t2 = new User();
115 | t2.setName("阿拉波");
116 | User t3 = new User();
117 | t3.setName("张三");
118 | User t4 = new User();
119 | t4.setName("空虚");
120 | User t5 = new User();
121 | t5.setName("寂寞");
122 | User t6 = new User();
123 | t6.setName("冷");
124 | list.add(t1);
125 | list.add(t2);
126 | list.add(t3);
127 | list.add(t4);
128 | list.add(t5);
129 | list.add(t6);
130 | return list;
131 | }
132 |
133 | }
134 |
--------------------------------------------------------------------------------
/src/com/myexample/dynamic/adapter/DynamicCommentAdapter.java:
--------------------------------------------------------------------------------
1 | package com.myexample.dynamic.adapter;
2 | import com.myexample.dynamic.R;
3 | import com.myexample.dynamic.bean.DynamicComment;
4 | import com.myexample.dynamic.bean.UserClickSpan;
5 |
6 | import android.content.Context;
7 | import android.os.Handler;
8 | import android.text.Spannable;
9 | import android.text.SpannableString;
10 | import android.text.method.LinkMovementMethod;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.*;
15 | import android.view.LayoutInflater;
16 | import java.util.List;
17 |
18 | public class DynamicCommentAdapter extends BaseAdapter{
19 |
20 | private Context context;
21 | private List list;
22 | private Handler handler;
23 |
24 | public DynamicCommentAdapter(Context context,List list, Handler handler){
25 | this.context=context;
26 | this.list=list;
27 | this.handler=handler;
28 | }
29 |
30 | @Override
31 | public View getView(int position, View view, ViewGroup parent) {
32 | ItemView item=null;
33 | if(view==null){
34 | item=new ItemView();
35 | view=LayoutInflater.from(context).inflate(R.layout.yh_dynamic_item_commently, null);
36 | item.contentTx=(TextView)view.findViewById(R.id.circle_item_commentContentTx);
37 | item.contentTx.setMovementMethod(LinkMovementMethod.getInstance());
38 | view.setTag(item);
39 | }else{
40 | item=(ItemView)view.getTag();
41 | }
42 |
43 | DynamicComment cc=list.get(position);
44 |
45 | //直接评论为-1 回复为 回复人id
46 | if("-1".equals(cc.getReuserId())){
47 | int start=0;
48 | int end=0+cc.getNickname().length()+1;
49 | String content=cc.getContent()==null?"":cc.getContent();
50 |
51 | SpannableString tSS = new SpannableString(cc.getNickname()+":"+content);
52 | tSS.setSpan(new UserClickSpan(context,cc.getUserId(),cc.getNickname()), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
53 | item.contentTx.setText(tSS);
54 | }else{
55 | int start1=0;
56 | int end1=0+cc.getNickname().length();
57 | String content=cc.getContent()==null?"":cc.getContent();
58 |
59 | int start2=end1+2;
60 | int end2=start2+cc.getReuserName().length()+1;
61 |
62 | SpannableString tSS = new SpannableString(cc.getNickname()+"回复"+cc.getReuserName()+":"+content);
63 | tSS.setSpan(new UserClickSpan(context,cc.getUserId(),cc.getNickname()), start1, end1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
64 | tSS.setSpan(new UserClickSpan(context,cc.getReuserId(),cc.getReuserName()), start2, end2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
65 | item.contentTx.setText(tSS);
66 | }
67 |
68 |
69 | final int p=position;
70 | item.contentTx.setOnClickListener(new View.OnClickListener() {
71 | @Override
72 | public void onClick(View v) {
73 | long t2=System.currentTimeMillis();
74 | if(Math.abs(UserClickSpan.clickTime-t2)<500){
75 | return;
76 | }
77 |
78 | if(handler!=null){
79 | handler.obtainMessage(511,p+1,v.getMeasuredHeight()).sendToTarget();
80 | }
81 | }
82 | });
83 |
84 | return view;
85 | }
86 |
87 | class ItemView{
88 | public TextView contentTx;
89 |
90 |
91 | }
92 |
93 | @Override
94 | public int getCount() {
95 | return list.size();
96 | }
97 |
98 | @Override
99 | public Object getItem(int position) {
100 | return list.get(position);
101 | }
102 |
103 | @Override
104 | public long getItemId(int position) {
105 | return position;
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/src/com/myexample/dynamic/adapter/DynamicPageAdapter.java:
--------------------------------------------------------------------------------
1 | package com.myexample.dynamic.adapter;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.app.FragmentActivity;
8 | import android.support.v4.app.FragmentStatePagerAdapter;
9 | import android.util.Log;
10 |
11 | import com.myexample.dynamic.bean.Dynamic;
12 | import com.myexample.dynamic.fragment.DynamicDetailFragment;
13 |
14 | public class DynamicPageAdapter extends FragmentStatePagerAdapter{
15 |
16 |
17 | private List list;
18 | private FragmentActivity activity;
19 |
20 | public DynamicPageAdapter(FragmentActivity activity,List list) {
21 | super(activity.getSupportFragmentManager());
22 | if(list==null)list=new ArrayList();
23 | this.activity=activity;
24 | this.list=list;
25 | }
26 |
27 |
28 |
29 | @Override
30 | public Fragment getItem(int position) {
31 | // return list.get(position);
32 | DynamicDetailFragment fragment=new DynamicDetailFragment();
33 | fragment.setPosition(position);
34 | return fragment;
35 | }
36 |
37 |
38 | /**
39 | * 这个方法是判断 activity 跳转到别的页面后 回来是否刷新的,
40 | * 可能跳转后 回来list发生改变 当前positon对应的fragment不是之前的fragment
41 | */
42 | @Override
43 | public int getItemPosition(Object object) {
44 | DynamicDetailFragment fragment=(DynamicDetailFragment)object;
45 | int position=fragment.getPosition();
46 | if(position>list.size()-1)return POSITION_NONE;
47 | Dynamic dynamic=list.get(position);
48 | if(dynamic.getDynamicId().equals(fragment.getDynamicId())){
49 | Log.e("相同", "getItemPosition相同");
50 | return POSITION_UNCHANGED;
51 | }else{
52 | Log.e("不同", "getItemPosition不同");
53 | return POSITION_NONE;
54 | }
55 | }
56 |
57 |
58 | @Override
59 | public int getCount() {
60 | return list.size();
61 | }
62 |
63 |
64 |
65 | public void notifyDataSetChanged(List list) {
66 | if(list==null)list=new ArrayList();
67 | this.list=list;
68 | super.notifyDataSetChanged();
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/com/myexample/dynamic/bean/Dynamic.java:
--------------------------------------------------------------------------------
1 | package com.myexample.dynamic.bean;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Dynamic implements Serializable {
6 |
7 | /**
8 | *
9 | */
10 | private static final long serialVersionUID = 5564165575483463086L;
11 |
12 | private String dynamicId;
13 |
14 | public String getDynamicId() {
15 | return dynamicId;
16 | }
17 |
18 | public void setDynamicId(String dynamicId) {
19 | this.dynamicId = dynamicId;
20 | }
21 |
22 |
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/com/myexample/dynamic/bean/DynamicComment.java:
--------------------------------------------------------------------------------
1 | package com.myexample.dynamic.bean;
2 |
3 | import java.io.Serializable;
4 |
5 | public class DynamicComment implements Serializable{
6 |
7 | /**
8 | *
9 | */
10 | private static final long serialVersionUID = -4609309963793818156L;
11 | private String commendId;
12 | private String userId;
13 | private String nickname;
14 | private String content;
15 | private String reuserId="-1";
16 | private String reuserName;
17 | public String getCommendId() {
18 | return commendId;
19 | }
20 | public void setCommendId(String commendId) {
21 | this.commendId = commendId;
22 | }
23 |
24 | public String getUserId() {
25 | return userId;
26 | }
27 | public void setUserId(String userId) {
28 | this.userId = userId;
29 | }
30 | public String getNickname() {
31 | return nickname;
32 | }
33 | public void setNickname(String nickname) {
34 | this.nickname = nickname;
35 | }
36 | public String getContent() {
37 | return content;
38 | }
39 | public void setContent(String content) {
40 | this.content = content;
41 | }
42 | public String getReuserId() {
43 | return reuserId;
44 | }
45 | public void setReuserId(String reuserId) {
46 | this.reuserId = reuserId;
47 | }
48 | public String getReuserName() {
49 | return reuserName;
50 | }
51 | public void setReuserName(String reuserName) {
52 | this.reuserName = reuserName;
53 | }
54 |
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/com/myexample/dynamic/bean/User.java:
--------------------------------------------------------------------------------
1 | package com.myexample.dynamic.bean;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 | import java.util.concurrent.ConcurrentHashMap;
6 |
7 | /**
8 | * @author jialn 用户_bean(个人全部字段)
9 | */
10 | public class User implements Serializable {
11 | private Long userId;
12 |
13 | private String name;
14 |
15 | public Long getUserId() {
16 | return userId;
17 | }
18 |
19 | public void setUserId(Long userId) {
20 | this.userId = userId;
21 | }
22 |
23 | public String getName() {
24 | return name;
25 | }
26 |
27 | public void setName(String name) {
28 | this.name = name;
29 | }
30 |
31 |
32 |
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/com/myexample/dynamic/bean/UserClickSpan.java:
--------------------------------------------------------------------------------
1 | package com.myexample.dynamic.bean;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.text.TextPaint;
6 | import android.text.style.ClickableSpan;
7 | import android.util.Log;
8 | import android.view.View;
9 | import android.widget.Toast;
10 |
11 | public class UserClickSpan extends ClickableSpan{
12 |
13 | private String userId;
14 | private String name;
15 | private String color="#6a8694";
16 | private Context context;
17 | public static long clickTime;
18 |
19 | public UserClickSpan(Context context,String userId,String name){
20 | this.userId=userId;
21 | this.name=name;
22 | this.context=context;
23 | }
24 |
25 | public UserClickSpan(Context context,String userId,String name,String color){
26 | this.userId=userId;
27 | this.name=name;
28 | this.context=context;
29 | this.color=color;
30 | }
31 |
32 | @Override
33 | public void onClick(View widget) {
34 | clickTime=System.currentTimeMillis();
35 | Log.e("我点击了", "我点击了");
36 | Toast.makeText(context, "我点击了:"+name, Toast.LENGTH_SHORT).show();
37 | }
38 |
39 | @Override
40 | public void updateDrawState(TextPaint ds) {
41 | ds.setColor(Color.parseColor(color));
42 | ds.setUnderlineText(false);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/com/myexample/dynamic/fragment/DynamicDetailFragment.java:
--------------------------------------------------------------------------------
1 | package com.myexample.dynamic.fragment;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.Rect;
6 | import android.os.Bundle;
7 | import android.os.Handler;
8 | import android.support.v4.app.Fragment;
9 | import android.util.Log;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.view.ViewTreeObserver.OnGlobalLayoutListener;
14 | import android.view.inputmethod.InputMethodManager;
15 | import android.widget.Button;
16 | import android.widget.EditText;
17 | import android.widget.LinearLayout;
18 | import android.widget.ListView;
19 | import android.widget.RelativeLayout;
20 | import android.widget.Toast;
21 |
22 | import com.myexample.dynamic.R;
23 | import com.myexample.dynamic.activity.DynamicActivity;
24 | import com.myexample.dynamic.activity.DynamicDetailActivity;
25 | import com.myexample.dynamic.adapter.DynamicAdapter;
26 | import com.myexample.dynamic.adapter.DynamicCommentAdapter;
27 | import com.myexample.dynamic.bean.DynamicComment;
28 | import com.myexample.dynamic.view.DynamicDetailHeadView;
29 |
30 | public class DynamicDetailFragment extends Fragment{
31 |
32 | private int position;
33 | private String dynamicId;
34 |
35 | private View view;
36 | private EditText editText;
37 | private ListView listView;
38 | private Button commentBtn;
39 | private RelativeLayout unclickRl;
40 | private LinearLayout commentLy,commentShowLy;
41 | private DynamicDetailHeadView headView;
42 | private boolean kbflag;
43 |
44 | private int p,vh;
45 |
46 | public DynamicDetailFragment(){
47 |
48 | }
49 |
50 | @Override
51 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
52 | view=inflater.inflate(R.layout.yh_dynamic_detail_list, container, false);
53 | listView=(ListView)view.findViewById(R.id.listview);
54 | commentLy=(LinearLayout)view.findViewById(R.id.comment_ly);
55 | commentBtn=(Button)view.findViewById(R.id.dynamic_item_comment_btn);
56 | editText=(EditText)view.findViewById(R.id.editText);
57 | commentShowLy=(LinearLayout)view.findViewById(R.id.comment_show_ly);
58 | unclickRl=(RelativeLayout)view.findViewById(R.id.unclick_rl);
59 |
60 | //把headview抽出去 可以用群里的生成find 生成
61 | headView=new DynamicDetailHeadView(getActivity(),handler);
62 | listView.addHeaderView(headView.view);
63 | listView.setAdapter(null);
64 |
65 |
66 | headView.setZan(DynamicAdapter.getUserList());
67 | headView.setComment(position);
68 | headView.contentTx.setText("当前是fragment+"+position);
69 | //空实现 为了让事件不往下传递
70 | unclickRl.setOnClickListener(new View.OnClickListener() {
71 |
72 | @Override
73 | public void onClick(View arg0) {
74 |
75 | }
76 | });
77 |
78 |
79 | commentBtn.setOnClickListener(new View.OnClickListener() {
80 | @Override
81 | public void onClick(View arg0) {
82 | handler.obtainMessage(510).sendToTarget();
83 |
84 | }
85 | });
86 |
87 | //异步加载数据 这里模拟一下
88 | handler.postDelayed(new Runnable() {
89 |
90 | @Override
91 | public void run() {
92 |
93 | listView.setAdapter(new DynamicCommentAdapter(getActivity(), DynamicAdapter.getDynamicComments2(), handler));
94 | unclickRl.setVisibility(View.GONE);
95 | }
96 | }, 1000);
97 |
98 | //监听界面的变化,判断当前页面键盘是否显示
99 | final View activityRootView = view.findViewById(R.id.rl);
100 | activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
101 |
102 | @Override
103 | public void onGlobalLayout() {
104 | if(kbflag){
105 | Rect r = new Rect();
106 | activityRootView.getWindowVisibleDisplayFrame(r);
107 | int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
108 | // Log.e("", "heightDiff:"+heightDiff+" (r.bottom - r.top):"+(r.bottom - r.top));
109 | if (heightDiff<100) {
110 | commentLy.setVisibility(View.GONE);
111 | // commentShowLy.setVisibility(View.VISIBLE);
112 | kbflag=false;
113 | }
114 | }
115 |
116 | }
117 | });
118 |
119 | return view;
120 | }
121 |
122 |
123 | private Handler handler=new Handler(){
124 | public void handleMessage(android.os.Message msg) {
125 |
126 | switch (msg.what) {
127 | case 510:
128 | //评论
129 | commentLy.setVisibility(View.VISIBLE);
130 | editText.setFocusable(true);
131 | editText.requestFocus();
132 | editText.setHint("来说说你的想法");
133 | editText.setTag("-1");
134 | showKeyBoard();
135 | // p=msg.arg1;
136 | // vh=msg.arg2;
137 | // scrollList();
138 | Toast.makeText(getActivity(), "评论", Toast.LENGTH_SHORT).show();
139 | break;
140 | case 511:
141 | //回复
142 | commentLy.setVisibility(View.VISIBLE);
143 | editText.setFocusable(true);
144 | editText.requestFocus();
145 | editText.setText("");
146 | editText.setHint("回复 xxx:");
147 | // editText.setTag(comment.getFriendId());
148 | showKeyBoard();
149 | p=msg.arg1;
150 | vh=msg.arg2;
151 | Log.e("getMeasuredHeight之前", "vh:"+vh);
152 | if(commentLy.getMeasuredHeight()==0){
153 | vh+=getResources().getDimension(R.dimen.commentLy_height)-commentShowLy.getMeasuredHeight();
154 | }else{
155 | vh+=commentLy.getMeasuredHeight()-commentShowLy.getMeasuredHeight();
156 | }
157 | Log.e("getMeasuredHeight之后", "vh:"+vh);
158 | scrollList();
159 | Toast.makeText(getActivity(), "回复", Toast.LENGTH_SHORT).show();
160 | break;
161 |
162 | }
163 | };
164 | };
165 |
166 | private void scrollList(){
167 | handler.postDelayed(new Runnable() {
168 |
169 | @Override
170 | public void run() {
171 | int h=listView.getMeasuredHeight();
172 | Log.e("xxxxxxxxxx", "h:"+h+" vh:"+vh+" "+p);
173 | listView.setSelectionFromTop(p, h-vh);
174 | }
175 | }, 300);
176 | }
177 |
178 | private void showKeyBoard(){
179 | handler.postDelayed(new Runnable() {
180 | @Override
181 | public void run() {
182 | InputMethodManager imm=(InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
183 | imm.showSoftInput(editText, InputMethodManager.RESULT_SHOWN);
184 | imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
185 | kbflag=true;
186 | }
187 | }, 100);
188 | }
189 |
190 |
191 | public int getPosition() {
192 | return position;
193 | }
194 |
195 | public void setPosition(int position) {
196 | this.position = position;
197 | }
198 |
199 | public String getDynamicId() {
200 | return dynamicId;
201 | }
202 |
203 | public void setDynamicId(String dynamicId) {
204 | this.dynamicId = dynamicId;
205 | }
206 |
207 |
208 |
209 |
210 | }
211 |
--------------------------------------------------------------------------------
/src/com/myexample/dynamic/view/DynamicDetailHeadView.java:
--------------------------------------------------------------------------------
1 | package com.myexample.dynamic.view;
2 | import java.util.ArrayList;
3 |
4 | import com.myexample.dynamic.R;
5 | import com.myexample.dynamic.bean.DynamicComment;
6 | import com.myexample.dynamic.bean.User;
7 | import com.myexample.dynamic.bean.UserClickSpan;
8 |
9 | import android.content.Context;
10 | import android.graphics.Color;
11 | import android.os.Handler;
12 | import android.text.SpannableStringBuilder;
13 | import android.text.Spanned;
14 | import android.text.TextPaint;
15 | import android.text.method.LinkMovementMethod;
16 | import android.text.style.ClickableSpan;
17 | import android.view.View;
18 | import android.widget.*;
19 | import android.widget.TextView.BufferType;
20 | import android.view.LayoutInflater;
21 |
22 | public class DynamicDetailHeadView {
23 |
24 | public View view;
25 | public Context context;
26 | private Handler handler;
27 |
28 | public ImageView picImg;
29 | public ImageView charmImg;
30 | public ImageView headImg;
31 | public TextView commentTx;
32 | public TextView zanTx;
33 | public RelativeLayout contentRl;
34 | public RelativeLayout picRl;
35 | public RelativeLayout imgRl;
36 | public TextView contentTx;
37 | public ImageView itemImg;
38 |
39 |
40 | public DynamicDetailHeadView(Context context,Handler handler){
41 | view=LayoutInflater.from(context).inflate(R.layout.yh_dynamic_detail_head, null);
42 | this.context=context;
43 | this.handler=handler;
44 | find();
45 | }
46 |
47 |
48 | public DynamicDetailHeadView(View view,Context context){
49 | this.view=view;
50 | this.context=context;
51 | find();
52 | }
53 |
54 | private void find() {
55 | picImg=(ImageView)view.findViewById(R.id.dynamic_item_content_pic_img);
56 | charmImg=(ImageView)view.findViewById(R.id.dynamic_item_charm_img);
57 | headImg=(ImageView)view.findViewById(R.id.dynamic_item_head_img);
58 | commentTx=(TextView)view.findViewById(R.id.dynamic_item_comment_tx);
59 | zanTx=(TextView)view.findViewById(R.id.dynamic_item_zan_tx);
60 | contentRl=(RelativeLayout)view.findViewById(R.id.dynamic_item_content_rl);
61 | picRl=(RelativeLayout)view.findViewById(R.id.dynamic_item_content_pic_rl);
62 | imgRl=(RelativeLayout)view.findViewById(R.id.dynamic_item_img_rl);
63 | contentTx=(TextView)view.findViewById(R.id.dynamic_item_content_tx);
64 | itemImg=(ImageView)view.findViewById(R.id.dynamic_item_img);
65 | zanTx.setMovementMethod(LinkMovementMethod.getInstance());
66 | commentTx.setMovementMethod(LinkMovementMethod.getInstance());
67 | }
68 |
69 |
70 | public void setZan(ArrayList list) {
71 | String str = "查看全部" + list.size() + "次赞 ";
72 | int start = 0;
73 | int end = str.length();
74 |
75 | SpannableStringBuilder builder = new SpannableStringBuilder(str);
76 | builder.setSpan(new ClickableSpan() {
77 |
78 | @Override
79 | public void onClick(View widget) {
80 | Toast.makeText(context, "查看全部赞", Toast.LENGTH_SHORT).show();
81 | }
82 |
83 | @Override
84 | public void updateDrawState(TextPaint ds) {
85 | ds.setColor(Color.parseColor("#a7a6a8"));
86 | ds.setUnderlineText(false);
87 | }
88 | }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
89 |
90 | if (list.size() > 0) {
91 | for (int i = 0; i < list.size(); i++) {
92 | start = end;
93 | User u = list.get(i);
94 | builder.append("" + u.getName());
95 | end += u.getName().length();
96 | builder.setSpan(new UserClickSpan(context, u.getUserId()+"",u.getName()), start, end, 0);
97 | if (i != list.size() - 1) {
98 | builder.append(",");
99 | end++;
100 | }
101 | }
102 | }
103 | zanTx.setText(builder, BufferType.SPANNABLE);
104 | }
105 |
106 |
107 | public void setComment(int count){
108 | String str = count+"条评论 ";
109 | int start = 0;
110 | int end = str.length();
111 |
112 | SpannableStringBuilder builder = new SpannableStringBuilder(str);
113 | builder.setSpan(new ClickableSpan() {
114 |
115 | @Override
116 | public void onClick(View widget) {
117 | // Toast.makeText(context, "查看全部评论", Toast.LENGTH_SHORT).show();
118 | handler.obtainMessage(411).sendToTarget();
119 | }
120 |
121 | @Override
122 | public void updateDrawState(TextPaint ds) {
123 | ds.setColor(Color.parseColor("#a7a6a8"));
124 | ds.setUnderlineText(false);
125 | }
126 | }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
127 |
128 | commentTx.setText(builder, BufferType.SPANNABLE);
129 |
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/src/com/myexample/dynamic/view/DynamicItemView.java:
--------------------------------------------------------------------------------
1 | package com.myexample.dynamic.view;
2 |
3 | import java.util.ArrayList;
4 |
5 | import android.content.Context;
6 | import android.graphics.Color;
7 | import android.os.Handler;
8 | import android.text.Spannable;
9 | import android.text.SpannableString;
10 | import android.text.SpannableStringBuilder;
11 | import android.text.Spanned;
12 | import android.text.TextPaint;
13 | import android.text.method.LinkMovementMethod;
14 | import android.text.style.ClickableSpan;
15 | import android.util.Log;
16 | import android.view.LayoutInflater;
17 | import android.view.View;
18 | import android.widget.Button;
19 | import android.widget.ImageView;
20 | import android.widget.LinearLayout;
21 | import android.widget.RelativeLayout;
22 | import android.widget.TextView;
23 | import android.widget.TextView.BufferType;
24 | import android.widget.Toast;
25 |
26 | import com.myexample.dynamic.R;
27 | import com.myexample.dynamic.bean.DynamicComment;
28 | import com.myexample.dynamic.bean.User;
29 | import com.myexample.dynamic.bean.UserClickSpan;
30 |
31 | public class DynamicItemView {
32 |
33 | public View view;
34 | public Context context;
35 | private Handler handler;
36 | private int position;
37 |
38 | public TextView contentTx;
39 | public TextView zanTx;
40 | public TextView commentTx;
41 | public ImageView headImg;
42 | public RelativeLayout picRl;
43 | public ImageView img;
44 | public RelativeLayout imgRl;
45 | public ImageView charmimg;
46 | public RelativeLayout contentRl;
47 | public LinearLayout commentLy;
48 | public ImageView picImg;
49 | public Button commentBtn;
50 |
51 |
52 | public DynamicItemView(Context context) {
53 | view = LayoutInflater.from(context).inflate(R.layout.yh_dynamic_item, null);
54 | this.context = context;
55 | find();
56 | }
57 |
58 | public DynamicItemView(View view, Context context) {
59 | this.view = view;
60 | this.context = context;
61 | find();
62 | }
63 |
64 |
65 |
66 | public int getPosition() {
67 | return position;
68 | }
69 |
70 | public void setPosition(int position) {
71 | this.position = position;
72 | }
73 |
74 | public Handler getHandler() {
75 | return handler;
76 | }
77 |
78 | public void setHandler(Handler handler) {
79 | this.handler = handler;
80 | }
81 |
82 | private void find() {
83 | contentTx = (TextView) view.findViewById(R.id.dynamic_item_content_tx);
84 | zanTx = (TextView) view.findViewById(R.id.dynamic_item_zan_tx);
85 | commentTx = (TextView) view.findViewById(R.id.dynamic_item_comment_tx);
86 | headImg = (ImageView) view.findViewById(R.id.dynamic_item_head_img);
87 | commentBtn = (Button) view.findViewById(R.id.dynamic_item_comment_btn);
88 | picRl = (RelativeLayout) view.findViewById(R.id.dynamic_item_content_pic_rl);
89 | img = (ImageView) view.findViewById(R.id.dynamic_item_img);
90 | imgRl = (RelativeLayout) view.findViewById(R.id.dynamic_item_img_rl);
91 | charmimg = (ImageView) view.findViewById(R.id.dynamic_item_charm_img);
92 | contentRl = (RelativeLayout) view.findViewById(R.id.dynamic_item_content_rl);
93 | commentLy = (LinearLayout) view.findViewById(R.id.dynamic_item_comment_ly);
94 | picImg = (ImageView) view.findViewById(R.id.dynamic_item_content_pic_img);
95 | zanTx.setMovementMethod(LinkMovementMethod.getInstance());
96 | commentTx.setMovementMethod(LinkMovementMethod.getInstance());
97 | }
98 |
99 | public void setZan(ArrayList list) {
100 | String str = "查看全部" + list.size() + "次赞 ";
101 | int start = 0;
102 | int end = str.length();
103 |
104 | SpannableStringBuilder builder = new SpannableStringBuilder(str);
105 | builder.setSpan(new ClickableSpan() {
106 |
107 | @Override
108 | public void onClick(View widget) {
109 | Toast.makeText(context, "查看全部赞", Toast.LENGTH_SHORT).show();
110 | }
111 |
112 | @Override
113 | public void updateDrawState(TextPaint ds) {
114 | ds.setColor(Color.parseColor("#a7a6a8"));
115 | ds.setUnderlineText(false);
116 | }
117 | }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
118 |
119 | if (list.size() > 0) {
120 | for (int i = 0; i < list.size(); i++) {
121 | start = end;
122 | User u = list.get(i);
123 | builder.append("" + u.getName());
124 | end += u.getName().length();
125 | builder.setSpan(new UserClickSpan(context, u.getUserId()+"",u.getName()), start, end, 0);
126 | if (i != list.size() - 1) {
127 | builder.append(",");
128 | end++;
129 | }
130 | }
131 | }
132 | zanTx.setText(builder, BufferType.SPANNABLE);
133 | }
134 |
135 |
136 | public void setCommentClick(){
137 | commentBtn.setOnClickListener(new View.OnClickListener() {
138 |
139 | @Override
140 | public void onClick(View v) {
141 | if(handler!=null){
142 | handler.obtainMessage(510,position,view.getMeasuredHeight()).sendToTarget();
143 | }
144 | }
145 | });
146 | }
147 |
148 | public void setComment(ArrayList list){
149 | String str = "查看全部" + list.size() + "条评论 ";
150 | int start = 0;
151 | int end = str.length();
152 |
153 | SpannableStringBuilder builder = new SpannableStringBuilder(str);
154 | builder.setSpan(new ClickableSpan() {
155 |
156 | @Override
157 | public void onClick(View widget) {
158 | // Toast.makeText(context, "查看全部评论", Toast.LENGTH_SHORT).show();
159 | handler.obtainMessage(411).sendToTarget();
160 | }
161 |
162 | @Override
163 | public void updateDrawState(TextPaint ds) {
164 | ds.setColor(Color.parseColor("#a7a6a8"));
165 | ds.setUnderlineText(false);
166 | }
167 | }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
168 |
169 | commentTx.setText(builder, BufferType.SPANNABLE);
170 |
171 | initCommentLayout(list);
172 | }
173 |
174 | private void initCommentLayout(ArrayList list){
175 | commentLy.removeAllViewsInLayout();
176 | if(list!=null&&list.size()>0){
177 | for (int i = 0; i< list.size(); i++) {
178 | DynamicComment cc=list.get(i);
179 |
180 | View ll=LayoutInflater.from(context).inflate(R.layout.yh_dynamic_item_commently, null);
181 | TextView contentTx=(TextView) ll.findViewById(R.id.circle_item_commentContentTx);
182 | contentTx.setMovementMethod(LinkMovementMethod.getInstance());
183 | //直接评论为-1 回复为 回复人id
184 | if("-1".equals(cc.getReuserId())){
185 | int start=0;
186 | int end=0+cc.getNickname().length()+1;
187 | String content=cc.getContent()==null?"":cc.getContent();
188 |
189 | SpannableString tSS = new SpannableString(cc.getNickname()+":"+content);
190 | tSS.setSpan(new UserClickSpan(context,cc.getUserId(),cc.getNickname()), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
191 | contentTx.setText(tSS);
192 | commentLy.addView(ll);
193 | }else{
194 | int start1=0;
195 | int end1=0+cc.getNickname().length();
196 | String content=cc.getContent()==null?"":cc.getContent();
197 |
198 | int start2=end1+2;
199 | int end2=start2+cc.getReuserName().length()+1;
200 |
201 | SpannableString tSS = new SpannableString(cc.getNickname()+"回复"+cc.getReuserName()+":"+content);
202 | tSS.setSpan(new UserClickSpan(context,cc.getUserId(),cc.getNickname()), start1, end1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
203 | tSS.setSpan(new UserClickSpan(context,cc.getReuserId(),cc.getReuserName()), start2, end2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
204 | contentTx.setText(tSS);
205 | commentLy.addView(ll);
206 | }
207 |
208 | contentTx.setOnClickListener(new View.OnClickListener() {
209 | @Override
210 | public void onClick(View v) {
211 | long t2=System.currentTimeMillis();
212 | if(Math.abs(UserClickSpan.clickTime-t2)<500){
213 | return;
214 | }
215 | Log.e("contentTx.setOnClickListener", "contentTx.setOnClickListener");
216 |
217 |
218 | // Log.e("view ", "view:"+view.getMeasuredHeight()+" "+view.getTop()+" "+view.getBottom());
219 | // Log.e("v ", "v:"+v.getMeasuredHeight()+" "+v.getTop()+" "+v.getBottom());
220 |
221 | int[] a1=new int[2];
222 | view.getLocationOnScreen(a1);
223 | int[] a2=new int[2];
224 | v.getLocationOnScreen(a2);
225 |
226 | Log.e("view ", "view:"+a1[0]+" "+a1[1]+" ");
227 | Log.e("v ", "v:"+a2[0]+" "+a2[1]+" "+v.getMeasuredHeight());
228 |
229 | if(handler!=null){
230 | handler.obtainMessage(511,position,a2[1]-a1[1]+v.getMeasuredHeight()).sendToTarget();
231 | }
232 | }
233 | });
234 |
235 | }
236 |
237 | }else{
238 | commentLy.setVisibility(View.GONE);
239 | }
240 | }
241 |
242 |
243 | }
244 |
--------------------------------------------------------------------------------