Skip to content

Commit c6a7813

Browse files
committed
冒泡活动轮播
列表标签太多变成...
1 parent 518be18 commit c6a7813

12 files changed

Lines changed: 115 additions & 40 deletions

app/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ dependencies {
4545
compile 'com.prolificinteractive:parallaxpager:2.2.0'
4646
compile 'uk.co.chrisjenx:calligraphy:2.0.1'
4747
compile 'com.dlazaro66.qrcodereaderview:qrcodereaderview:1.0.0'
48-
48+
compile('cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2') {
49+
exclude module: 'support-v4'
50+
}
4951
}
5052

5153
//################

app/src/main/java/net/coding/program/common/widget/FlowLabelLayout.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import android.content.Context;
44
import android.util.AttributeSet;
55
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.widget.TextView;
68

79
import net.coding.program.R;
810
import net.coding.program.model.TopicLabelObject;
@@ -17,22 +19,45 @@
1719
*/
1820
public class FlowLabelLayout extends FlowLayout {
1921

22+
TextView textLabel; // 用来计算高度的,不添加子控件
23+
int itemExtra = 0; // item 除了文字外占用的空间长度,包括 padding,merge
24+
2025
public FlowLabelLayout(Context context, AttributeSet attributeSet) {
2126
super(context, attributeSet);
27+
28+
textLabel = (LabelTextView) LayoutInflater.from(getContext()).inflate(R.layout.project_topic_list_item_label, this, false);
29+
itemExtra = getResources().getDimensionPixelSize(R.dimen.label_list_item_merge_right) +
30+
getResources().getDimensionPixelSize(R.dimen.label_list_item_padding_left) * 2;
2231
}
2332

24-
public void setLabels(List<TopicLabelObject> list) {
33+
public void setLabels(final List<TopicLabelObject> list, int width) {
2534
if (list.isEmpty()) {
2635
setVisibility(GONE);
2736
return;
2837
}
2938

39+
setLabelViews(list, width);
40+
}
41+
42+
private void setLabelViews(List<TopicLabelObject> list, int flowWidth) {
3043
setVisibility(VISIBLE);
3144
removeAllViews();
45+
46+
int realWidth = 0;
47+
48+
float endWidth = textLabel.getPaint().measureText("...");
3249
for (TopicLabelObject item : list) {
33-
LabelTextView label = (LabelTextView) LayoutInflater.from(getContext()).inflate(R.layout.project_topic_list_item_label, this, false);
34-
addView(label);
35-
label.setText(item.name, item.getColor());
50+
float itemWidth = textLabel.getPaint().measureText(item.name) + itemExtra;
51+
if (realWidth + itemWidth + endWidth < flowWidth) {
52+
realWidth += itemWidth;
53+
LabelTextView label = (LabelTextView) LayoutInflater.from(getContext()).inflate(R.layout.project_topic_list_item_label, this, false);
54+
addView(label);
55+
label.setText(item.name, item.getColor());
56+
} else {
57+
View end = LayoutInflater.from(getContext()).inflate(R.layout.project_topic_list_item_label_more, this, false);
58+
addView(end);
59+
break;
60+
}
3661
}
3762
}
3863
}

app/src/main/java/net/coding/program/maopao/MaopaoListFragment.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
import java.util.ArrayList;
6060
import java.util.Calendar;
6161

62+
import cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPager;
63+
6264
@EFragment(R.layout.fragment_maopao_list)
6365
public class MaopaoListFragment extends RefreshBaseFragment implements FootUpdate.LoadMore, StartActivity {
6466

@@ -448,12 +450,16 @@ protected void init() {
448450
final ArrayList<BannerObject> banners = AccountInfo.getMaopaoBanners(getActivity());
449451
if (!banners.isEmpty()) {
450452
View bannerLayout = mInflater.inflate(R.layout.maopao_banner_view_pager, null);
451-
ViewPager banner = (ViewPager) bannerLayout.findViewById(R.id.bannerViewPager);
453+
AutoScrollViewPager banner = (AutoScrollViewPager) bannerLayout.findViewById(R.id.bannerViewPager);
452454
ViewGroup.LayoutParams layoutParams = banner.getLayoutParams();
453455
layoutParams.height = (int) ((MyApp.sWidthPix - getResources().getDimensionPixelSize(R.dimen.padding_12) * 2) * 0.3);
454456
banner.setLayoutParams(layoutParams);
455457
BannerAdapter bannerAdapter = new BannerAdapter(getChildFragmentManager(), banners);
456458
banner.setAdapter(bannerAdapter);
459+
banner.startAutoScroll(10 * 1000);
460+
banner.setScrollDurationFactor(2);
461+
462+
banner.setSlideBorderMode(AutoScrollViewPager.SLIDE_BORDER_MODE_CYCLE);
457463

458464
final IndicatorView bannerIndicator = (IndicatorView) bannerLayout.findViewById(R.id.indicatorView);
459465
bannerIndicator.setCount(banners.size(), 0);

app/src/main/java/net/coding/program/project/detail/TaskListFragment.java

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.animation.ValueAnimator;
55
import android.content.DialogInterface;
66
import android.content.Intent;
7+
import android.graphics.PorterDuff;
78
import android.os.Bundle;
89
import android.view.LayoutInflater;
910
import android.view.View;
@@ -20,6 +21,7 @@
2021
import com.loopj.android.http.RequestParams;
2122
import com.melnykov.fab.FloatingActionButton;
2223

24+
import net.coding.program.MyApp;
2325
import net.coding.program.R;
2426
import net.coding.program.common.BlankViewDisplay;
2527
import net.coding.program.common.Global;
@@ -173,7 +175,7 @@ protected void init() {
173175
fab.setVisibility(View.GONE);
174176
// listView.setAnimExecutor(new AnimationExecutor());
175177
View footer = getActivity().getLayoutInflater().inflate(R.layout.divide_15_top, null);
176-
listView.addFooterView(footer);
178+
listView.addFooterView(footer, null, false);
177179
listView.setAdapter(mAdapter);
178180

179181
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@@ -454,12 +456,14 @@ public View getView(int position, View convertView, ViewGroup parent) {
454456
holder.mCheckBox = (CheckBox) convertView.findViewById(R.id.checkbox);
455457
holder.mTitle = (TextView) convertView.findViewById(R.id.title);
456458
holder.mDeadline = (TextView) convertView.findViewById(R.id.deadline);
459+
holder.mDeadline.setBackgroundResource(R.drawable.task_list_item_deadline_background);
457460
holder.mName = (TextView) convertView.findViewById(R.id.name);
458461
holder.mTime = (TextView) convertView.findViewById(R.id.time);
459462
holder.mDiscuss = (TextView) convertView.findViewById(R.id.discuss);
460463
holder.mIcon = (ImageView) convertView.findViewById(R.id.icon);
461464
holder.mTaskPriority = convertView.findViewById(R.id.taskPriority);
462465
holder.mTaskDes = convertView.findViewById(R.id.taskDes);
466+
holder.mLayoutDeadline = convertView.findViewById(R.id.layoutDeadline);
463467
holder.flowLabelLayout = (FlowLabelLayout) convertView.findViewById(R.id.flowLayout);
464468
convertView.setTag(holder);
465469
} else {
@@ -474,7 +478,12 @@ public View getView(int position, View convertView, ViewGroup parent) {
474478
holder.mDiscuss.setText(String.valueOf(data.comments));
475479
iconfromNetwork(holder.mIcon, data.owner.avatar);
476480

477-
holder.flowLabelLayout.setLabels(data.labels);
481+
482+
int flowWidth = MyApp.sWidthPix - Global.dpToPx(100 + 12); // item 左边空 100 dp,右边空12dp
483+
if (!data.deadline.isEmpty()) {
484+
flowWidth -= Global.dpToPx(55);
485+
}
486+
holder.flowLabelLayout.setLabels(data.labels, flowWidth);
478487

479488
final int pos = position;
480489

@@ -496,29 +505,43 @@ public View getView(int position, View convertView, ViewGroup parent) {
496505

497506
holder.mTaskPriority.setBackgroundResource(priorityIcons[data.priority]);
498507

508+
if (data.deadline.isEmpty() && data.labels.isEmpty()) {
509+
holder.mLayoutDeadline.setVisibility(View.GONE);
510+
} else {
511+
holder.mLayoutDeadline.setVisibility(View.VISIBLE);
512+
}
513+
514+
int[] taskColors = new int[]{
515+
0xfff49f31,
516+
0xff97ba66,
517+
0xfff24b4b,
518+
0xffb2c6d0,
519+
0xffc7c8c7
520+
};
521+
499522
if (data.deadline.isEmpty()) {
500523
holder.mDeadline.setVisibility(View.GONE);
501524
} else {
502525
holder.mDeadline.setVisibility(View.VISIBLE);
503526

504527
if (data.deadline.equals(mToday)) {
505528
holder.mDeadline.setText("今天");
506-
holder.mDeadline.setBackgroundResource(R.drawable.round_rect_shape_yellow);
529+
holder.setDeadlineColor(taskColors[0]);
507530
} else if (data.deadline.equals(mTomorrow)) {
508531
holder.mDeadline.setText("明天");
509-
holder.mDeadline.setBackgroundResource(R.drawable.round_rect_shape_green);
532+
holder.setDeadlineColor(taskColors[1]);
510533
} else {
511534
if (data.deadline.compareTo(mToday) < 0) {
512-
holder.mDeadline.setBackgroundResource(R.drawable.round_rect_shape_red);
535+
holder.setDeadlineColor(taskColors[2]);
513536
} else {
514-
holder.mDeadline.setBackgroundResource(R.drawable.round_rect_shape_gray_light);
537+
holder.setDeadlineColor(taskColors[3]);
515538
}
516539
String num[] = data.deadline.split("-");
517540
holder.mDeadline.setText(String.format("%s/%s", num[1], num[2]));
518541
}
519542

520543
if (data.isDone()) {
521-
holder.mDeadline.setBackgroundResource(R.drawable.round_rect_shape_gray);
544+
holder.setDeadlineColor(taskColors[4]);
522545
}
523546
}
524547

@@ -589,16 +612,18 @@ class ViewHolder {
589612
TextView mTitle;
590613

591614
TextView mDeadline;
592-
593615
TextView mName;
594616
TextView mTime;
595617
TextView mDiscuss;
596-
597618
View mTaskPriority;
598-
599619
View mTaskDes;
600-
620+
View mLayoutDeadline;
601621
FlowLabelLayout flowLabelLayout;
622+
623+
public void setDeadlineColor(int color) {
624+
mDeadline.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN);
625+
mDeadline.setTextColor(color);
626+
}
602627
}
603628
}
604629

app/src/main/java/net/coding/program/project/detail/TopicListFragment.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.widget.TextView;
1515

1616
import net.coding.program.FootUpdate;
17+
import net.coding.program.MyApp;
1718
import net.coding.program.R;
1819
import net.coding.program.common.BlankViewDisplay;
1920
import net.coding.program.common.Global;
@@ -144,7 +145,8 @@ public View getView(int position, View convertView, ViewGroup parent) {
144145
holder.time.setText(Global.changeHyperlinkColor(Global.dayToNow(data.created_at)));
145146
holder.discuss.setText(String.format("%d", data.child_count));
146147

147-
holder.flowLayout.setLabels(data.labels);
148+
int flowWidth = MyApp.sWidthPix - Global.dpToPx(66 + 12);
149+
holder.flowLayout.setLabels(data.labels, flowWidth);
148150

149151
if (position == (getCount() - 1)) {
150152
loadMore();
@@ -331,7 +333,7 @@ protected String getLink() {
331333
if (dropdownLabel.current != null && !TextUtils.isEmpty(dropdownLabel.current.value)) {
332334
url += "&labelId=" + dropdownLabel.current.value;
333335
}
334-
return url.toString();
336+
return url;
335337
}
336338

337339
@Click
2.46 KB
Loading

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,38 @@
6363
android:layout_marginTop="12dp"
6464
android:orientation="vertical">
6565

66-
<net.coding.program.common.widget.FlowLabelLayout
67-
android:id="@+id/flowLayout"
68-
android:layout_width="match_parent"
69-
android:layout_height="wrap_content"
70-
android:layout_marginBottom="6dp" />
71-
7266
<LinearLayout
67+
android:id="@+id/layoutDeadline"
7368
android:layout_width="match_parent"
74-
android:layout_height="wrap_content"
75-
android:gravity="center_vertical"
69+
android:layout_height="20dp"
70+
android:layout_marginBottom="6dp"
7671
android:orientation="horizontal">
7772

7873
<TextView
7974
android:id="@+id/deadline"
8075
android:layout_width="wrap_content"
81-
android:layout_height="wrap_content"
82-
android:layout_marginRight="10dp"
76+
android:layout_height="match_parent"
77+
android:layout_marginRight="@dimen/label_list_item_merge_right"
8378
android:background="@drawable/round_rect_shape_green"
79+
android:gravity="center"
8480
android:paddingLeft="3dp"
8581
android:paddingRight="3dp"
8682
android:text="aaa"
8783
android:textColor="@color/white"
88-
android:textSize="12dp" />
84+
android:textSize="12sp" />
85+
86+
<net.coding.program.common.widget.FlowLabelLayout
87+
android:id="@+id/flowLayout"
88+
android:layout_width="0dp"
89+
android:layout_height="match_parent"
90+
android:layout_weight="1" />
91+
</LinearLayout>
92+
93+
<LinearLayout
94+
android:layout_width="match_parent"
95+
android:layout_height="wrap_content"
96+
android:gravity="center_vertical"
97+
android:orientation="horizontal">
8998

9099
<include layout="@layout/common_name" />
91100

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
</LinearLayout>
4141

42-
<android.support.v4.view.ViewPager
42+
<cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPager
4343
android:id="@+id/bannerViewPager"
4444
android:layout_width="match_parent"
4545
android:layout_height="200dp"
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<net.coding.program.common.widget.LabelTextView xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="wrap_content"
4-
android:layout_height="wrap_content"
4+
android:layout_height="20dp"
55
android:layout_centerVertical="true"
66
android:layout_marginBottom="6dp"
7-
android:layout_marginRight="6dp"
7+
android:layout_marginRight="@dimen/label_list_item_merge_right"
88
android:background="@drawable/project_topic_label_bg"
99
android:gravity="center"
1010
android:includeFontPadding="false"
1111
android:maxEms="8"
1212
android:maxLines="1"
13-
android:paddingBottom="2dp"
14-
android:paddingLeft="3dp"
15-
android:paddingRight="3dp"
16-
android:paddingTop="2dp"
13+
android:paddingLeft="@dimen/label_list_item_padding_left"
14+
android:paddingRight="@dimen/label_list_item_padding_left"
1715
android:singleLine="true"
1816
android:text="标签"
1917
android:textColor="@color/green"
20-
android:textSize="10sp" />
18+
android:textSize="12sp" />
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="wrap_content"
4+
android:layout_height="wrap_content"
5+
android:text="..." />

0 commit comments

Comments
 (0)