Skip to content

Commit 01e56f5

Browse files
committed
add demo items
1 parent 2478b2c commit 01e56f5

File tree

14 files changed

+155
-38
lines changed

14 files changed

+155
-38
lines changed

.idea/modules.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FlyRefresh.iml

Lines changed: 0 additions & 19 deletions
This file was deleted.

app/app.iml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="FlyRefresh" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="FlyReresh" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>
@@ -70,6 +70,7 @@
7070
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
7171
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
7272
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.1.1/jars" />
73+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/22.1.1/jars" />
7374
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.1.1/jars" />
7475
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
7576
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
@@ -88,6 +89,7 @@
8889
</content>
8990
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
9091
<orderEntry type="sourceFolder" forTests="false" />
92+
<orderEntry type="library" exported="" name="recyclerview-v7-22.1.1" level="project" />
9193
<orderEntry type="library" exported="" name="support-annotations-22.1.1" level="project" />
9294
<orderEntry type="library" exported="" name="support-v4-22.1.1" level="project" />
9395
<orderEntry type="library" exported="" name="appcompat-v7-22.1.1" level="project" />

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ dependencies {
2323
compile fileTree(include: ['*.jar'], dir: 'libs')
2424
compile 'com.android.support:appcompat-v7:22.1.1'
2525
compile project(':library')
26+
compile 'com.android.support:recyclerview-v7:22.1.1'
2627
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.race604.flyrefresh.sample;
2+
3+
import android.graphics.Color;
4+
5+
import java.util.Date;
6+
7+
/**
8+
* Created by Jing on 15/5/27.
9+
*/
10+
public class ItemData {
11+
int color;
12+
public int icon;
13+
public String title;
14+
public Date time;
15+
16+
public ItemData(int color, int icon, String title, Date time) {
17+
this.color = color;
18+
this.icon = icon;
19+
this.title = title;
20+
this.time = time;
21+
}
22+
23+
public ItemData(int icon, String title) {
24+
this(Color.DKGRAY, icon, title, new Date());
25+
}
26+
}
Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,43 @@
11
package com.race604.flyrefresh.sample;
22

3+
import android.content.Context;
4+
import android.graphics.Color;
5+
import android.graphics.drawable.ShapeDrawable;
6+
import android.graphics.drawable.shapes.OvalShape;
37
import android.os.Bundle;
48
import android.support.v7.app.AppCompatActivity;
9+
import android.support.v7.widget.LinearLayoutManager;
10+
import android.support.v7.widget.RecyclerView;
511
import android.support.v7.widget.Toolbar;
12+
import android.view.LayoutInflater;
613
import android.view.Menu;
714
import android.view.MenuItem;
8-
import android.widget.ArrayAdapter;
15+
import android.view.View;
16+
import android.view.ViewGroup;
917
import android.widget.ImageView;
10-
import android.widget.ListView;
18+
import android.widget.TextView;
1119

1220
import com.race604.flyrefresh.FlyRefreshLayout;
1321
import com.race604.flyrefresh.PullHeaderLayout;
1422

23+
import java.text.DateFormat;
24+
import java.text.SimpleDateFormat;
25+
import java.util.ArrayList;
26+
import java.util.Date;
27+
1528
public class MainActivity extends AppCompatActivity implements PullHeaderLayout.OnPullListener {
1629

1730
private FlyRefreshLayout mFlylayout;
18-
private ListView mListView;
31+
private RecyclerView mListView;
1932

20-
private static final String[] INIT_DATA = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",
21-
"Nine", "Ten"};
33+
private ItemAdapter mAdapter;
2234

23-
private ArrayAdapter<String> mAdapter;
35+
private ArrayList<ItemData> mDataSet = new ArrayList<>();
2436

2537
@Override
2638
protected void onCreate(Bundle savedInstanceState) {
2739
super.onCreate(savedInstanceState);
40+
initDataSet();
2841
setContentView(R.layout.activity_main);
2942

3043
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
@@ -35,29 +48,30 @@ protected void onCreate(Bundle savedInstanceState) {
3548

3649
mFlylayout.setOnPullListener(this);
3750

38-
mListView = (ListView) findViewById(R.id.list);
51+
mListView = (RecyclerView) findViewById(R.id.list);
52+
53+
mListView.setLayoutManager(new LinearLayoutManager(this));
54+
mAdapter = new ItemAdapter(this);
3955

40-
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
41-
mAdapter.addAll(INIT_DATA);
42-
mAdapter.addAll(INIT_DATA);
4356
mListView.setAdapter(mAdapter);
4457
}
4558

59+
private void initDataSet() {
60+
mDataSet.add(new ItemData(Color.parseColor("#76A9FC"), R.mipmap.ic_assessment_white_24dp, "Meeting Minutes", new Date(2014 - 1900, 2, 9)));
61+
mDataSet.add(new ItemData(Color.GRAY, R.mipmap.ic_folder_white_24dp, "Favorites Photos", new Date(2014 - 1900, 1, 3)));
62+
mDataSet.add(new ItemData(Color.GRAY, R.mipmap.ic_folder_white_24dp, "Photos", new Date(2014 - 1900, 0, 9)));
63+
}
64+
4665
@Override
4766
public boolean onCreateOptionsMenu(Menu menu) {
48-
// Inflate the menu; this adds items to the action bar if it is present.
4967
getMenuInflater().inflate(R.menu.menu_main, menu);
5068
return true;
5169
}
5270

5371
@Override
5472
public boolean onOptionsItemSelected(MenuItem item) {
55-
// Handle action bar item clicks here. The action bar will
56-
// automatically handle clicks on the Home/Up button, so long
57-
// as you specify a parent activity in AndroidManifest.xml.
5873
int id = item.getItemId();
5974

60-
//noinspection SimplifiableIfStatement
6175
if (id == R.id.action_settings) {
6276
return true;
6377
}
@@ -74,4 +88,52 @@ public void onStartRefresh(PullHeaderLayout view) {
7488
public void onPullProgress(PullHeaderLayout view, int state, float progress) {
7589

7690
}
91+
92+
private class ItemAdapter extends RecyclerView.Adapter<ItemViewHolder> {
93+
94+
private LayoutInflater mInflater;
95+
private DateFormat dateFormat;
96+
97+
public ItemAdapter(Context context) {
98+
mInflater = LayoutInflater.from(context);
99+
dateFormat = SimpleDateFormat.getDateInstance();
100+
}
101+
102+
@Override
103+
public ItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
104+
View view = mInflater.inflate(R.layout.view_list_item, viewGroup, false);
105+
return new ItemViewHolder(view);
106+
}
107+
108+
@Override
109+
public void onBindViewHolder(ItemViewHolder itemViewHolder, int i) {
110+
final ItemData data = mDataSet.get(i);
111+
ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
112+
drawable.getPaint().setColor(data.color);
113+
itemViewHolder.icon.setBackgroundDrawable(drawable);
114+
itemViewHolder.icon.setImageResource(data.icon);
115+
itemViewHolder.title.setText(data.title);
116+
itemViewHolder.subTitle.setText(dateFormat.format(data.time));
117+
}
118+
119+
@Override
120+
public int getItemCount() {
121+
return mDataSet.size();
122+
}
123+
}
124+
125+
private static class ItemViewHolder extends RecyclerView.ViewHolder {
126+
127+
ImageView icon;
128+
TextView title;
129+
TextView subTitle;
130+
131+
public ItemViewHolder(View itemView) {
132+
super(itemView);
133+
icon = (ImageView) itemView.findViewById(R.id.icon);
134+
title = (TextView) itemView.findViewById(R.id.title);
135+
subTitle = (TextView) itemView.findViewById(R.id.subtitle);
136+
}
137+
138+
}
77139
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
android:layout_height="match_parent"
1010
tools:context=".MainActivity">
1111

12-
<ListView android:id="@+id/list"
12+
<android.support.v7.widget.RecyclerView
13+
android:id="@+id/list"
1314
android:layout_width="match_parent"
1415
android:layout_height="match_parent"
1516
android:background="#FFFFFF"/>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="wrap_content"
5+
android:gravity="center_vertical"
6+
android:orientation="horizontal"
7+
android:padding="4dp">
8+
9+
<ImageView
10+
android:id="@+id/icon"
11+
android:layout_width="40dp"
12+
android:layout_height="40dp"
13+
android:scaleType="centerInside"
14+
android:layout_margin="4dp"/>
15+
16+
<LinearLayout
17+
android:layout_width="0dp"
18+
android:layout_height="wrap_content"
19+
android:layout_weight="1"
20+
android:orientation="vertical"
21+
android:layout_margin="4dp">
22+
23+
<TextView
24+
android:id="@+id/title"
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:textSize="18sp"
28+
android:textAppearance="?attr/titleTextAppearance" />
29+
30+
<TextView
31+
android:id="@+id/subtitle"
32+
android:layout_width="wrap_content"
33+
android:layout_height="wrap_content"
34+
android:textSize="16sp"
35+
android:layout_marginTop="4dp"
36+
android:textAppearance="?attr/subtitleTextAppearance" />
37+
</LinearLayout>
38+
39+
<ImageView
40+
android:layout_width="30dp"
41+
android:layout_height="30dp"
42+
android:scaleType="centerInside"
43+
android:src="@mipmap/ic_info_grey600_18dp" />
44+
</LinearLayout>
Loading
Loading
Loading
Binary file not shown.
Binary file not shown.

library/library.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="FlyRefresh" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="FlyReresh" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>

0 commit comments

Comments
 (0)