Skip to content

Commit f7603f2

Browse files
author
cwy545177162@163.com
committed
Update Readme
1 parent 481b8f4 commit f7603f2

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ Fragment继承BaseFragment
7171

7272
带启动模式形式,支持四种启动模式(实际项目中以singleTask最为实用);
7373

74-
open(new Fragment1(), null, FragmentStack.STANDARD);
75-
open(new Fragment1(), null, FragmentStack.SINGLE_TOP);
76-
open(new Fragment1(), null, FragmentStack.SINGLE_TASK);
77-
open(new Fragment1(), null, FragmentStack.SINGLE_INSTANCE);
74+
open(new Fragment1(), null, StackManager.STANDARD);
75+
open(new Fragment1(), null, StackManager.SINGLE_TOP);
76+
open(new Fragment1(), null, StackManager.SINGLE_TASK);
77+
open(new Fragment1(), null, StackManager.SINGLE_INSTANCE);
7878

7979

8080
设置页面切换动画

simple/src/main/java/com/mrwang/simple/HomeFragment.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import android.view.View;
77
import android.view.ViewGroup;
88

9-
import com.mrwang.stacklibrary.FragmentStack;
109
import com.mrwang.stacklibrary.RootFragment;
10+
import com.mrwang.stacklibrary.StackManager;
1111

1212

1313
/**
@@ -38,17 +38,17 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
3838
public void onClick(View v) {
3939
switch (v.getId()) {
4040
case R.id.standard:
41-
open(new Fragment1(), null, FragmentStack.STANDARD);
41+
open(new Fragment1(), null, StackManager.STANDARD);
4242
break;
4343
case R.id.single_top:
44-
open(new Fragment1(), null, FragmentStack.SINGLE_TOP);
44+
open(new Fragment1(), null, StackManager.SINGLE_TOP);
4545

4646
break;
4747
case R.id.single_task:
48-
open(new Fragment1(), null, FragmentStack.SINGLE_TASK);
48+
open(new Fragment1(), null, StackManager.SINGLE_TASK);
4949
break;
5050
case R.id.single_instance:
51-
open(new Fragment1(), null, FragmentStack.SINGLE_INSTANCE);
51+
open(new Fragment1(), null, StackManager.SINGLE_INSTANCE);
5252
break;
5353
}
5454
}

stacklibrary/src/main/java/com/mrwang/stacklibrary/FragmentStack.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
* Time: 19:39
1212
*/
1313
public class FragmentStack {
14-
public static final int STANDARD = 0x11;
15-
public static final int SINGLE_TOP = 0x12;
16-
public static final int SINGLE_TASK = 0x13;
17-
public static final int SINGLE_INSTANCE = 0x14;
18-
19-
2014
private ArrayList<ArrayList<RootFragment>> stackList = new ArrayList<>();
2115
private ArrayList<RootFragment> stack;
2216
private CloseFragment listener;

stacklibrary/src/main/java/com/mrwang/stacklibrary/RootFragment.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.os.Bundle;
44
import android.support.annotation.AnimRes;
5+
import android.support.annotation.IntDef;
56
import android.support.annotation.NonNull;
67
import android.support.v4.app.Fragment;
78
import android.support.v4.app.FragmentActivity;
@@ -65,7 +66,8 @@ public void open(@NonNull RootFragment fragment, Bundle bundle) {
6566
* @param bundle bundle
6667
* @param stackMode stackMode,{@link FragmentStack#STANDARD} or more
6768
*/
68-
public void open(@NonNull RootFragment fragment, Bundle bundle, int stackMode) {
69+
70+
public void open(@NonNull RootFragment fragment, Bundle bundle,int stackMode) {
6971
getRoot().manager.addFragment(this, fragment, bundle, stackMode);
7072
}
7173

stacklibrary/src/main/java/com/mrwang/stacklibrary/StackManager.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.os.Bundle;
44
import android.support.annotation.AnimRes;
5+
import android.support.annotation.IntDef;
56
import android.support.annotation.NonNull;
67
import android.support.v4.app.Fragment;
78
import android.support.v4.app.FragmentActivity;
@@ -31,6 +32,11 @@ public class StackManager implements CloseFragment {
3132
private Animation next_out;
3233
private int dialog_in;
3334
private int dialog_out;
35+
public static final int STANDARD = 0x11;
36+
public static final int SINGLE_TOP = 0x12;
37+
public static final int SINGLE_TASK = 0x13;
38+
public static final int SINGLE_INSTANCE = 0x14;
39+
public static final int KEEP_CURRENT = 0x15;
3440

3541
/**
3642
* Set the time to click to Prevent repeated clicks,default 500ms
@@ -106,25 +112,25 @@ public void setAnim(@AnimRes int nextIn, @AnimRes int nextOut, @AnimRes int quit
106112
/**
107113
* Jump to the specified fragment
108114
*/
109-
public void addFragment(RootFragment from, RootFragment to, Bundle bundle, int stackMode) {
110-
if (stackMode != 0) {
115+
public void addFragment(RootFragment from, RootFragment to, Bundle bundle,@StackMode int stackMode) {
116+
if (stackMode != KEEP_CURRENT) {
111117
currentMode = stackMode;
112118
}
113119
if (bundle != null) {
114120
to.setArguments(bundle);
115121
}
116122
switch (currentMode) {
117-
case FragmentStack.SINGLE_TOP:
123+
case SINGLE_TOP:
118124
if (!stack.putSingleTop(to)) {
119125
addFragment(from, to);
120126
}
121127
break;
122-
case FragmentStack.SINGLE_TASK:
128+
case SINGLE_TASK:
123129
if (!stack.putSingleTask(to)) {
124130
addFragment(from, to);
125131
}
126132
break;
127-
case FragmentStack.SINGLE_INSTANCE:
133+
case SINGLE_INSTANCE:
128134
stack.putSingleInstance(to);
129135
addFragment(from, to);
130136
break;
@@ -146,7 +152,7 @@ public void openFragment(RootFragment from, RootFragment to) {
146152
* Jump to the specified fragment with a parameter form
147153
*/
148154
public void addFragment(RootFragment from, RootFragment to, Bundle bundle) {
149-
addFragment(from, to, bundle, 0);
155+
addFragment(from, to, bundle, KEEP_CURRENT);
150156
}
151157

152158
/**
@@ -313,4 +319,10 @@ public void show(RootFragment fragment) {
313319
view.startAnimation(next_in);
314320
}
315321
}
322+
323+
@IntDef({STANDARD, SINGLE_TOP, SINGLE_TASK,SINGLE_INSTANCE,KEEP_CURRENT})
324+
public @interface StackMode {
325+
326+
}
327+
316328
}

0 commit comments

Comments
 (0)