Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
YoKeyword committed Feb 5, 2018
2 parents 00b8db8 + 76762fd commit 327de61
Show file tree
Hide file tree
Showing 7 changed files with 1,612 additions and 23 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ The first demo shows the basic usage of the library. The second one shows the wa
**1、build.gradle**
````gradle
// appcompat-v7 is required
compile 'me.yokeyword:fragmentation:1.2.5'
compile 'me.yokeyword:fragmentation:1.2.6'
// If you don't want to extends SupportActivity/Fragment and would like to customize your own support, just rely on fragmentation-core
// compile 'me.yokeyword:fragmentation-core:1.2.5'
// compile 'me.yokeyword:fragmentation-core:1.2.6'
// To get SwipeBack feature, rely on both fragmentation & fragmentation-swipeback
compile 'me.yokeyword:fragmentation:1.2.5'
compile 'me.yokeyword:fragmentation:1.2.6'
// Swipeback is based on fragmentation. Refer to SwipeBackActivity/Fragment for your Customized SupportActivity/Fragment
compile 'me.yokeyword:fragmentation-swipeback:1.2.5'
compile 'me.yokeyword:fragmentation-swipeback:1.2.6'
// To simplify the communication between Fragments.
compile 'me.yokeyword:eventbus-activity-scope:1.1.0'
Expand Down
4 changes: 2 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ compile 'me.yokeyword:fragmentation:1.2.5'
// compile 'me.yokeyword:fragmentation-core:1.2.5'
// 如果想使用SwipeBack 滑动边缘退出Fragment/Activity功能,完整的添加规则如下:
compile 'me.yokeyword:fragmentation:1.2.5'
compile 'me.yokeyword:fragmentation:1.2.6'
// swipeback基于fragmentation, 如果是自定制SupportActivity/Fragment,则参照SwipeBackActivity/Fragment实现即可
compile 'me.yokeyword:fragmentation-swipeback:1.2.5'
compile 'me.yokeyword:fragmentation-swipeback:1.2.6'
// Activity作用域的EventBus,更安全,可有效避免after onSavenInstanceState()异常
compile 'me.yokeyword:eventbus-activity-scope:1.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void onPause() {
public void onDestroyView() {
mSupport.getSupportDelegate().mFragmentClickable = true;
getVisibleDelegate().onDestroyView();
getHandler().removeCallbacksAndMessages(null);
getHandler().removeCallbacks(mNotifyEnterAnimEndRunnable);
}

public void onDestroy() {
Expand Down Expand Up @@ -551,6 +551,7 @@ private void fixAnimationListener(Animation enterAnim) {
mSupport.getSupportDelegate().mFragmentClickable = false;
// AnimationListener is not reliable.
getHandler().postDelayed(mNotifyEnterAnimEndRunnable, enterAnim.getDuration());
mSupport.getSupportDelegate().mFragmentClickable = true;

if (mEnterAnimListener != null) {
getHandler().post(new Runnable() {
Expand All @@ -566,7 +567,8 @@ public void run() {
private Runnable mNotifyEnterAnimEndRunnable = new Runnable() {
@Override
public void run() {
notifyEnterAnimEnd();
if (mFragment == null) return;
mSupportF.onEnterAnimationEnd(mSaveInstanceState);
}
};

Expand Down Expand Up @@ -600,13 +602,7 @@ private int getWindowBackground() {
}

private void notifyEnterAnimEnd() {
getHandler().post(new Runnable() {
@Override
public void run() {
if (mFragment == null) return;
mSupportF.onEnterAnimationEnd(mSaveInstanceState);
}
});
getHandler().post(mNotifyEnterAnimEndRunnable);
mSupport.getSupportDelegate().mFragmentClickable = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ private void addDebugFragmentRecord(List<DebugFragmentRecord> fragmentRecords, F
} else {
for (int j = 0; j < backStackCount; j++) {
FragmentManager.BackStackEntry entry = fragment.getFragmentManager().getBackStackEntryAt(j);
if (entry.getName().equals(fragment.getTag())) {
if ((entry.getName() != null && entry.getName().equals(fragment.getTag()))
|| (entry.getName() == null && fragment.getTag() == null)) {
break;
}
if (j == backStackCount - 1) {
Expand Down
4 changes: 2 additions & 2 deletions fragmentation_swipeback/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Activity内Fragment数大于1时,滑动返回的是Fragment,否则滑动返
1、项目下app的build.gradle中依赖:
````gradle
// appcompat v7包是必须的
compile 'me.yokeyword:fragmentation:1.2.5'
compile 'me.yokeyword:fragmentation-swipeback:1.2.5'
compile 'me.yokeyword:fragmentation:1.2.6'
compile 'me.yokeyword:fragmentation-swipeback:1.2.6'
````
2、如果Activity也需要支持SwipeBack,则继承SwipeBackActivity:
````java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentationMagician;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.ViewDragHelper;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
Expand Down Expand Up @@ -64,6 +63,11 @@ public class SwipeBackLayout extends FrameLayout {
*/
public static final int STATE_SETTLING = ViewDragHelper.STATE_SETTLING;

/**
* A view is currently drag finished.
*/
public static final int STATE_FINISHED = 3;

private static final int DEFAULT_SCRIM_COLOR = 0x99000000;
private static final float DEFAULT_PARALLAX = 0.33f;
private static final int FULL_ALPHA = 255;
Expand Down Expand Up @@ -129,6 +133,13 @@ private void init() {
setEdgeOrientation(EDGE_LEFT);
}

/**
* Get ViewDragHelper
*/
public ViewDragHelper getViewDragHelper() {
return mHelper;
}

/**
* Set scroll threshold, we will close the activity, when scrollPercent over
* this value
Expand Down Expand Up @@ -221,6 +232,7 @@ public interface OnSwipeListener {
* @see #STATE_IDLE
* @see #STATE_DRAGGING
* @see #STATE_SETTLING
* @see #STATE_FINISHED
*/
void onDragStateChange(int state);

Expand Down Expand Up @@ -413,7 +425,7 @@ public boolean tryCaptureView(View child, int pointerId) {
mCurrentSwipeOrientation = EDGE_RIGHT;
}

if (mListeners != null && !mListeners.isEmpty()) {
if (mListeners != null) {
for (OnSwipeListener listener : mListeners) {
listener.onEdgeTouch(mCurrentSwipeOrientation);
}
Expand Down Expand Up @@ -468,8 +480,7 @@ public void onViewPositionChanged(View changedView, int left, int top, int dx, i
mContentTop = top;
invalidate();

if (mListeners != null && !mListeners.isEmpty()
&& mHelper.getViewDragState() == STATE_DRAGGING && mScrollPercent <= 1 && mScrollPercent > 0) {
if (mListeners != null && mHelper.getViewDragState() == STATE_DRAGGING && mScrollPercent <= 1 && mScrollPercent > 0) {
for (OnSwipeListener listener : mListeners) {
listener.onDragScrolled(mScrollPercent);
}
Expand All @@ -480,10 +491,12 @@ public void onViewPositionChanged(View changedView, int left, int top, int dx, i
if (mCallOnDestroyView) return;

if (!((Fragment) mFragment).isDetached()) {
onDragFinished();
mFragment.getSupportDelegate().popQuiet();
}
} else {
if (!mActivity.isFinishing()) {
onDragFinished();
mActivity.finish();
mActivity.overridePendingTransition(0, 0);
}
Expand Down Expand Up @@ -522,7 +535,7 @@ public void onViewReleased(View releasedChild, float xvel, float yvel) {
@Override
public void onViewDragStateChanged(int state) {
super.onViewDragStateChanged(state);
if (mListeners != null && !mListeners.isEmpty()) {
if (mListeners != null) {
for (OnSwipeListener listener : mListeners) {
listener.onDragStateChange(state);
}
Expand All @@ -538,6 +551,14 @@ public void onEdgeTouched(int edgeFlags, int pointerId) {
}
}

private void onDragFinished() {
if (mListeners != null) {
for (OnSwipeListener listener : mListeners) {
listener.onDragStateChange(STATE_FINISHED);
}
}
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (!mEnable) return super.onInterceptTouchEvent(ev);
Expand Down
Loading

0 comments on commit 327de61

Please sign in to comment.