Permalink
Browse files

Reimplement scroll with NestedScrolling APIs

  • Loading branch information...
race604 committed Aug 20, 2015
1 parent 7faad47 commit 4efa6a0f6cdd563fe36092218a9db7037f3dacee
View
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
View
@@ -71,9 +71,9 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/22.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/jp.wasabeef/recyclerview-animators/1.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
@@ -90,13 +90,13 @@
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="recyclerview-v7-22.1.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.0.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-animators-1.2.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.0" level="project" />
<orderEntry type="module" module-name="library" exported="" />
</component>
</module>
View
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.race604.flyrefresh"
minSdkVersion 11
targetSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
@@ -21,8 +21,8 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile project(':library')
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'jp.wasabeef:recyclerview-animators:1.2.0@aar'
}
@@ -70,6 +70,18 @@ private void initDataSet() {
mDataSet.add(new ItemData(Color.parseColor("#76A9FC"), R.mipmap.ic_assessment_white_24dp, "Meeting Minutes", new Date(2014 - 1900, 2, 9)));
mDataSet.add(new ItemData(Color.GRAY, R.mipmap.ic_folder_white_24dp, "Favorites Photos", new Date(2014 - 1900, 1, 3)));
mDataSet.add(new ItemData(Color.GRAY, R.mipmap.ic_folder_white_24dp, "Photos", new Date(2014 - 1900, 0, 9)));
mDataSet.add(new ItemData(Color.parseColor("#76A9FC"), R.mipmap.ic_assessment_white_24dp, "Meeting Minutes", new Date(2014 - 1900, 2, 9)));
mDataSet.add(new ItemData(Color.GRAY, R.mipmap.ic_folder_white_24dp, "Favorites Photos", new Date(2014 - 1900, 1, 3)));
mDataSet.add(new ItemData(Color.GRAY, R.mipmap.ic_folder_white_24dp, "Photos", new Date(2014 - 1900, 0, 9)));
mDataSet.add(new ItemData(Color.parseColor("#76A9FC"), R.mipmap.ic_assessment_white_24dp, "Meeting Minutes", new Date(2014 - 1900, 2, 9)));
mDataSet.add(new ItemData(Color.GRAY, R.mipmap.ic_folder_white_24dp, "Favorites Photos", new Date(2014 - 1900, 1, 3)));
mDataSet.add(new ItemData(Color.GRAY, R.mipmap.ic_folder_white_24dp, "Photos", new Date(2014 - 1900, 0, 9)));
mDataSet.add(new ItemData(Color.parseColor("#76A9FC"), R.mipmap.ic_assessment_white_24dp, "Meeting Minutes", new Date(2014 - 1900, 2, 9)));
mDataSet.add(new ItemData(Color.GRAY, R.mipmap.ic_folder_white_24dp, "Favorites Photos", new Date(2014 - 1900, 1, 3)));
mDataSet.add(new ItemData(Color.GRAY, R.mipmap.ic_folder_white_24dp, "Photos", new Date(2014 - 1900, 0, 9)));
}
private void addItemData() {
View
@@ -5,13 +5,13 @@ apply plugin: 'com.jfrog.bintray'
version = "1.0.2"
android {
compileSdkVersion 22
compileSdkVersion 23
buildToolsVersion "22.0.1"
resourcePrefix "flyrefresh__"
defaultConfig {
minSdkVersion 11
targetSdkVersion 22
targetSdkVersion 23
versionCode 3
versionName version
}
@@ -25,8 +25,8 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
}
def siteUrl = 'https://github.com/race604/FlyRefresh'
View
@@ -87,11 +87,11 @@
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="design-22.2.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.0" level="project" />
<orderEntry type="library" exported="" name="design-23.0.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.0" level="project" />
</component>
</module>

This file was deleted.

Oops, something went wrong.
@@ -38,11 +38,6 @@ public FlyRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) {
init(context);
}
public FlyRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
private void init(Context context) {
MountanScenceView headerView = new MountanScenceView(getContext());
LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mHeaderController.getMaxHeight());
@@ -11,13 +11,10 @@
private float mOverDistance;
private float mResistance = 0.5f;
private float mStartX;
private float mStartY;
private int mOffsetX;
private int mOffsetY;
private boolean mIsInTouch = false;
private int mStartPos = -1;
private int mCurrentPos = -1;
private float mScroll = 0;
private int mMaxScroll = 0;
private int mMinScroll = 0;
public HeaderController(int height, int maxHeight, int minHeight) {
@@ -34,7 +31,9 @@ public void setSize(int height, int maxHeight, int minHeight) {
mMinHegiht = Math.max(0, minHeight);
mOverDistance = mMaxHegiht - mHeight;
mCurrentPos = mStartPos = mHeight;
mScroll = 0;
mMaxScroll = mHeight - mMinHegiht;
mMinScroll = mHeight - mMaxHegiht;
}
public int getMaxHeight() {
@@ -49,91 +48,81 @@ public int getHeight() {
return mHeight;
}
public int getCurrentPos() {
return mCurrentPos;
public int getScroll() {
return (int) mScroll;
}
public int getOffsetX() {
return mOffsetX;
public int getMaxScroll() {
return mMaxScroll;
}
public int getOffsetY() {
return mOffsetY;
public int getMinScroll() {
return mMinScroll;
}
public boolean isInTouch() {
return mIsInTouch;
}
public boolean hasMoved() {
return mStartPos != mCurrentPos;
}
public boolean canMoveUp() {
return mCurrentPos > mMinHegiht;
}
public boolean canMoveDown() {
return mCurrentPos < mMaxHegiht;
public int getCurPosition() {
return (int) (mHeight - mScroll);
}
public void onTouchRelease() {
mIsInTouch = false;
}
public void onTouchDown(float x, float y) {
mIsInTouch = true;
mStartX = x;
mStartY = y;
mOffsetX = mOffsetY = 0;
startMove();
public boolean isInTouch() {
return mIsInTouch;
}
public void onTouchMove(float x, float y) {
mOffsetX = (int) (x - mStartX);
mOffsetY = (int) (y - mStartY);
/**
* Check if can scroll down to show top
* @return
*/
public boolean canScrollDown() {
return mScroll > mMinScroll;
}
public void startMove() {
mStartPos = mCurrentPos;
/**
* Check if can scroll up to show bottom
* @return
*/
public boolean canScrollUp() {
return mScroll < mMaxScroll;
}
public int willMove(float deltaY) {
public int move(float deltaY) {
float willTo;
if (mStartPos > mHeight) {
willTo = mStartPos + deltaY * mResistance;
if (willTo < mHeight) {
willTo = mHeight + (willTo - mHeight) / mResistance;
float consumed = deltaY;
if (mScroll >= 0) {
willTo = mScroll + deltaY;
if (willTo < 0) {
willTo = willTo * mResistance;
if (willTo < mMinScroll) {
consumed -= (willTo - mMinScroll) / mResistance;
willTo = mMinScroll;
}
} else if (willTo > mMaxHegiht) {
consumed -= willTo - mMaxScroll;
willTo = mMaxScroll;
}
} else {
willTo = mStartPos + deltaY;
if (willTo > mHeight) {
willTo = mHeight + (willTo - mHeight) * mResistance;
willTo = mScroll + deltaY * mResistance;
if (willTo > 0) {
willTo = willTo / mResistance;
if (willTo > mMaxScroll) {
consumed -= willTo - mMaxScroll;
willTo = mMaxScroll;
}
} else if (willTo < mMinScroll) {
consumed -= willTo - mMinScroll;
willTo = mMinScroll;
}
}
int offsetY = Math.max(mMinHegiht, Math.min(mMaxHegiht, (int)willTo));
int move = offsetY - mCurrentPos;
mCurrentPos = offsetY;
return move;
}
public int moveTo(float pos) {
int offsetY = Math.max(mMinHegiht, Math.min(mMaxHegiht, (int)pos));
int delta = offsetY - mCurrentPos;
mCurrentPos = offsetY;
return delta;
mScroll = willTo;
return (int) consumed;
}
public boolean isOverHeight() {
return mCurrentPos > mHeight;
return mScroll < 0;
}
public float getMovePercentage() {
if (mCurrentPos >= mHeight) {
return (mCurrentPos - mHeight) / mOverDistance;
} else {
return (mCurrentPos - mHeight) / mOverDistance;
}
return -mScroll / mOverDistance;
}
public boolean needSendRefresh() {

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 4efa6a0

Please sign in to comment.