Skip to content

Commit

Permalink
1.add time recover,2.fix half window translate bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyufei committed Nov 12, 2018
1 parent c506f52 commit 9f37cd1
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {

implementation 'com.android.support:recyclerview-v7:28.0.0'

// api project(':library')
api project(':library')
// implementation 'com.github.JarvisGG:NestedTouchScrollingLayout:v1.0.0'
implementation 'com.jarvis.library.NestedTouchScrollingLayout:library:1.0.0'
// implementation 'com.jarvis.library.NestedTouchScrollingLayout:library:1.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.view.ViewGroup;
import android.widget.TextView;

import jarvis.com.library.NestedTouchScrollingLayout;
import jarvis.com.nestedtouchscrollinglayout.R;

/**
Expand All @@ -29,6 +30,8 @@ public class RecyclerViewFragment extends BaseChildFragment {

private RecyclerView mContainerRecycler;

private NestedTouchScrollingLayout mNestedTouchScrollingLayout;

private Bundle arg;


Expand All @@ -44,13 +47,31 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_recyclerview, container, false);
mContainerRecycler = view.findViewById(R.id.container_rv);
mNestedTouchScrollingLayout = view.findViewById(R.id.fragment_wrapper);
return view;
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

mNestedTouchScrollingLayout.registerNestScrollChildCallback(new NestedTouchScrollingLayout.INestChildScrollChange() {
@Override
public void onNestChildScrollChange(float deltaY) {

}

@Override
public void onNestChildScrollRelease(float deltaY, int velocityY) {
mNestedTouchScrollingLayout.recover(0, null, 300);
}

@Override
public void onNestChildHorizationScroll(boolean show) {

}
});

mContainerRecycler.setLayoutManager(new LinearLayoutManager(RecyclerViewFragment.this.getContext(), LinearLayoutManager.VERTICAL, false));
mContainerRecycler.setAdapter(new InnerAdapter(RecyclerViewFragment.this.getContext(), 0x9966CC));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class WebViewFragment extends BaseChildFragment {

private WebView mWebView;

private NestedTouchScrollingLayout mNestedTouchScrollingLayout;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -43,13 +45,31 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_webview, container, false);
mWebView = view.findViewById(R.id.web_view);
mNestedTouchScrollingLayout = view.findViewById(R.id.fragment_wrapper);
return view;
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

mNestedTouchScrollingLayout.registerNestScrollChildCallback(new NestedTouchScrollingLayout.INestChildScrollChange() {
@Override
public void onNestChildScrollChange(float deltaY) {

}

@Override
public void onNestChildScrollRelease(float deltaY, int velocityY) {
mNestedTouchScrollingLayout.recover(0);
}

@Override
public void onNestChildHorizationScroll(boolean show) {

}
});

initWebSettings();
initWebViewClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public class NestedTouchScrollingLayout extends FrameLayout implements NestedScr
*/
private boolean isLeftorRightTouchLimit = true;

private boolean isFingerHolderTouch = false;

private List<INestChildScrollChange> mNestChildScrollChangeCallbacks;


Expand Down Expand Up @@ -200,12 +202,15 @@ public boolean onTouchEvent(MotionEvent event) {
mDownSheetTranslation = mSheetTranslation;
velocityTracker.clear();

isFingerHolderTouch = true;

if (mChildView instanceof WebView) {
mWebViewContentHeight = (int) (((WebView)mChildView).getContentHeight() * ((WebView)mChildView).getScale());
}
}

if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
isFingerHolderTouch = false;
isLeftorRightTouchLimit = true;
}

Expand Down Expand Up @@ -293,7 +298,8 @@ private boolean isChildCanScroll(MotionEvent event, float deltaY) {
return (fingerDown && canScrollUp) || (fingerUp && canScrollDown);
}

private boolean canScrollUp(View view, float x, float y) {
protected boolean canScrollUp(View view, float x, float y) {

if (view instanceof WebView) {
return canWebViewScrollUp();
}
Expand All @@ -314,7 +320,7 @@ private boolean canScrollUp(View view, float x, float y) {
return view.canScrollVertically(-1);
}

private boolean canScrollDown(View view, float x, float y) {
protected boolean canScrollDown(View view, float x, float y) {
if (view instanceof WebView) {
return canWebViewScrollDown();
}
Expand Down Expand Up @@ -414,6 +420,10 @@ public void setTranslation(float transY) {
if (mChildView != null) {
mChildView.setTranslationY(transY);
}
if (transY == 0) {
mDownSheetTranslation = getMeasuredHeight();
mOriginTranslate = 0;
}
}

/**
Expand All @@ -425,8 +435,12 @@ public void recover(int target) {
}

public void recover(int target, final Runnable runnable) {
recover(target, runnable, 300);
}

public void recover(int target, final Runnable runnable, int time) {
currentAnimator = ObjectAnimator.ofFloat(this, SHEET_TRANSLATION, target);
currentAnimator.setDuration(300);
currentAnimator.setDuration(time);
currentAnimator.setInterpolator(new DecelerateInterpolator(1.6f));
currentAnimator.addListener(new CancelDetectionAnimationListener() {
@Override
Expand Down Expand Up @@ -483,13 +497,6 @@ private void onActionRelease(MotionEvent event) {
mTransYAnim.setDuration(200L);
mTransYAnim.setInterpolator(PathInterpolatorCompat.create(0.4F, 0.0F, 0.2F, 1.0F));

mTransYAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {

}
});

mTransYAnim.start();
}

Expand Down Expand Up @@ -578,5 +585,11 @@ public int getNestedScrollAxes() {
return super.getNestedScrollAxes();
}

}
public boolean isFingerHolderTouch() {
return isFingerHolderTouch;
}

public float getMinFlingVelocity() {
return minFlingVelocity;
}
}

0 comments on commit 9f37cd1

Please sign in to comment.