-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 55232d6
Showing
42 changed files
with
1,660 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.2" | ||
defaultConfig { | ||
applicationId "info.fangjie.pulltorefresh" | ||
minSdkVersion 15 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(include: ['*.jar'], dir: 'libs') | ||
compile project(':library') | ||
|
||
compile 'com.android.support:appcompat-v7:25.1.1' | ||
compile 'com.android.support:recyclerview-v7:25.1.1' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/FangJie/Library/Android-SDK/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/info/fangjie/demo/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package info.fangjie.demo; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest { | ||
@Test public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("info.fangjie.pulltorefresh", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="info.fangjie.demo" | ||
> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/icon" | ||
android:label="@string/app_name" | ||
android:roundIcon="@drawable/icon" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme" | ||
> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name=".RecyclerStyle1Activity"> | ||
</activity> | ||
<activity android:name=".RecyclerStyle2Activity"> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package info.fangjie.demo; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.Button; | ||
|
||
/** | ||
* Created by FangJie on 2017/3/3. | ||
*/ | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private Button recyclerViewStyle1; | ||
private Button recyclerViewStyle2; | ||
private Button recyclerViewStyle3; | ||
|
||
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
recyclerViewStyle1=(Button)findViewById(R.id.btn_recycler_style1); | ||
recyclerViewStyle2=(Button)findViewById(R.id.btn_recycler_style2); | ||
|
||
recyclerViewStyle1.setOnClickListener(new View.OnClickListener() { | ||
@Override public void onClick(View v) { | ||
Intent intent=new Intent(MainActivity.this,RecyclerStyle1Activity.class); | ||
startActivity(intent); | ||
} | ||
}); | ||
|
||
recyclerViewStyle2.setOnClickListener(new View.OnClickListener() { | ||
@Override public void onClick(View v) { | ||
Intent intent=new Intent(MainActivity.this,RecyclerStyle2Activity.class); | ||
startActivity(intent); | ||
} | ||
}); | ||
|
||
|
||
|
||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
app/src/main/java/info/fangjie/demo/RecyclerListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package info.fangjie.demo; | ||
|
||
import android.content.Context; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
/** | ||
* Created by FangJie on 2017/3/2. | ||
*/ | ||
public class RecyclerListAdapter extends RecyclerView.Adapter<RecyclerListAdapter.ViewHolder>{ | ||
|
||
private Context context; | ||
|
||
private int count=20; | ||
|
||
public void setCount(int count) { | ||
this.count = count; | ||
} | ||
|
||
public RecyclerListAdapter(Context context){ | ||
this.context=context; | ||
} | ||
|
||
@Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_list, parent, false)); | ||
} | ||
|
||
@Override public void onBindViewHolder(ViewHolder holder, int position) { | ||
holder.textView.setText((position+1)+": This is Title"); | ||
} | ||
|
||
@Override public int getItemCount() { | ||
return count; | ||
} | ||
|
||
class ViewHolder extends RecyclerView.ViewHolder{ | ||
public TextView textView; | ||
public ViewHolder(View itemView) { | ||
super(itemView); | ||
textView=(TextView) itemView.findViewById(R.id.tv_item_title); | ||
|
||
} | ||
} | ||
} | ||
|
123 changes: 123 additions & 0 deletions
123
app/src/main/java/info/fangjie/demo/RecyclerStyle1Activity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package info.fangjie.demo; | ||
|
||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.os.Message; | ||
import android.support.v7.app.ActionBar; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.MenuItem; | ||
import android.widget.TextView; | ||
import info.fangjie.pulltorefresh.DefaultLoadMoerListener; | ||
import info.fangjie.pulltorefresh.DefaultRefreshListener; | ||
import info.fangjie.pulltorefresh.PullRefreshLayout; | ||
|
||
public class RecyclerStyle1Activity extends AppCompatActivity { | ||
|
||
private RecyclerView recyclerview; | ||
private RecyclerListAdapter adapter; | ||
private PullRefreshLayout pullrefreshlayout; | ||
private TextView textViewHeader, textViewBottom; | ||
|
||
private Handler handler = new Handler() { | ||
@Override public void handleMessage(Message msg) { | ||
super.handleMessage(msg); | ||
if (msg.what == 1) { | ||
pullrefreshlayout.setRefresh(false); | ||
} else { | ||
pullrefreshlayout.setLoading(false); | ||
} | ||
} | ||
}; | ||
|
||
@Override protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.recycler_style1); | ||
ActionBar actionBar = getSupportActionBar(); | ||
actionBar.setDisplayHomeAsUpEnabled(true); | ||
actionBar.setTitle("Recycler Style1"); | ||
adapter = new RecyclerListAdapter(this); | ||
recyclerview = (RecyclerView) findViewById(R.id.recyclerview); | ||
recyclerview.setLayoutManager(new LinearLayoutManager(this)); | ||
pullrefreshlayout = (PullRefreshLayout) findViewById(R.id.pullrefreshlayout); | ||
textViewHeader = (TextView) findViewById(R.id.tv_refresh_header); | ||
textViewBottom = (TextView) findViewById(R.id.tv_refresh_footer); | ||
|
||
recyclerview.setAdapter(adapter); | ||
pullrefreshlayout.setRefreshListener(new DefaultRefreshListener() { | ||
@Override public void onPullOverTarget() { | ||
textViewHeader.setText("松开刷新"); | ||
} | ||
|
||
@Override public void onPullBelowTarget() { | ||
textViewHeader.setText("再拉一点就可以刷新了"); | ||
} | ||
|
||
@Override public void onPullBegin() { | ||
textViewHeader.setText("再拉一点就可以刷新了"); | ||
} | ||
|
||
@Override public void onRefreshing() { | ||
textViewHeader.setText("正在刷新"); | ||
new Thread() { | ||
@Override public void run() { | ||
super.run(); | ||
try { | ||
Thread.sleep(3000); | ||
handler.sendEmptyMessage(1); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
; | ||
}.start(); | ||
} | ||
}); | ||
|
||
pullrefreshlayout.setLoadMoreListener(new DefaultLoadMoerListener() { | ||
|
||
@Override public void onPullBegin() { | ||
textViewBottom.setText("再拉一点"); | ||
} | ||
|
||
@Override public void onPullBelowTarget() { | ||
textViewBottom.setText("再拉一点"); | ||
} | ||
|
||
@Override public void onPullOverTarget() { | ||
textViewBottom.setText("松开就可以加载了"); | ||
} | ||
|
||
@Override public void onLoading() { | ||
textViewBottom.setText("正在加载"); | ||
new Thread() { | ||
@Override public void run() { | ||
super.run(); | ||
try { | ||
Thread.sleep(3000); | ||
handler.sendEmptyMessage(2); | ||
adapter.setCount(adapter.getItemCount() + 20); | ||
adapter.notifyDataSetChanged(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
; | ||
}.start(); | ||
} | ||
}); | ||
} | ||
|
||
@Override public boolean onOptionsItemSelected(MenuItem item) { | ||
switch (item.getItemId()) { | ||
case android.R.id.home: | ||
this.finish(); | ||
return true; | ||
default: | ||
return super.onOptionsItemSelected(item); | ||
} | ||
} | ||
} |
Oops, something went wrong.