Skip to content

Commit b39305a

Browse files
author
chengwangyong
committed
merge
2 parents 2887a6b + 7b8204b commit b39305a

File tree

104 files changed

+609
-1704
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+609
-1704
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/appcompat_v7_23_1_1.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.idea/libraries/hamcrest_core_1_3.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.idea/libraries/junit_4_12.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.idea/libraries/support_annotations_23_1_1.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.idea/libraries/support_v4_23_1_1.xml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.idea/misc.xml

Lines changed: 25 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FragmentStack.iml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id="FragmentStack" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="java-gradle" name="Java-Gradle">
5+
<configuration>
6+
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
7+
<option name="BUILDABLE" value="false" />
8+
</configuration>
9+
</facet>
10+
</component>
11+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
12+
<exclude-output />
13+
<content url="file://$MODULE_DIR$">
14+
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
15+
</content>
16+
<orderEntry type="inheritedJdk" />
17+
<orderEntry type="sourceFolder" forTests="false" />
18+
</component>
19+
</module>

README.md

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,122 @@
1-
# FragmentStack
2-
A simple and easy to use a single Activity hosting multiple Fragment Library
1+
#FragmentStack
2+
3+
4+
>一个封装了启动模式的Fragment便捷使用库,方便构建单Activity+多Fragment轻量级框架。
5+
6+
## 一 为什么要写这个库
7+
8+
1.Fragment创建速度完胜Activity,在长期的开发实践中,明显感觉到Fragment响应速度,内存占用等方面拥有巨大的优势,将页面fragment化有助于提升app流畅度;
9+
10+
2.fragment创建和使用相比Activity更加麻烦,其中,回退栈管理,动画,关闭,隐藏等不便于使用,需要进一步封装提升效率;
11+
12+
3.fragment缺少启动模式,使得管理起来很有难度,很多在Activity上很常见的需求在Fragment使用需要更多更复杂的技巧,不利于快速开发;
13+
14+
## 二 它能为你做什么
15+
16+
1.替代传统的Activity页面,轻量化页面;
17+
18+
2.开启,关闭,动画,回退栈,生命周期回调等操作更加方便,一行代码即可搞定;
19+
20+
3.自带Activity四种启动模式,接管了系统的回退栈,很常见的场景,如 用户中心--->注册用户--->注册成功--->返回原来的用户中心,就可以设置启动模式为singleTask,注册成功后退出当前任务栈,或者设置用户中心singleInstance,直接new创建后再onNewInstance()方法中更新数据即可,框架自动remove上层fragment;
21+
22+
23+
## 三 配置和开始使用
24+
25+
对于如何导入,也是相当的简单,android studio的用户,直接:
26+
27+
然后,在你的项目中,MainActivity继承RootActivity
28+
29+
30+
public class MainActivity extends RootActivity {
31+
32+
@Override
33+
protected RootFragment getRootFragment() {
34+
return new HomeFragment();
35+
}
36+
37+
@Override
38+
public void onCreateNow(Bundle savedInstanceState) {
39+
setAnim(R.anim.next_in, R.anim.next_out, R.anim.quit_in, R.anim.quit_out);
40+
}
41+
}
42+
43+
44+
Fragment继承BaseFragment
45+
46+
public class HomeFragment extends RootFragment{
47+
48+
@Nullable
49+
@Override
50+
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
51+
52+
}
53+
}
54+
55+
56+
接下来,可以自由方便的使用Fragment了;
57+
58+
59+
60+
## 四 API说明
61+
1.打开一个新的Fragment;
62+
63+
常规方式
64+
65+
open(new Fragment());
66+
67+
带参形式
68+
69+
open(new Fragment());
70+
在新Fragment中用Bundle bundle = getArguments();获取
71+
72+
带启动模式形式,支持四种启动模式(实际项目中以singleTask最为实用);
73+
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);
78+
79+
80+
设置页面切换动画
81+
82+
setAnim(R.anim.next_in, R.anim.next_out, R.anim.quit_in, R.anim.quit_out);
83+
84+
进入下一个页面,两个页面的回调,只需重写
85+
86+
private void onNowHidden() {
87+
88+
}
89+
90+
private void onNextShow() {
91+
92+
}
93+
94+
Fragment获取依赖的Activity
95+
96+
RootActivity root = getRoot();
97+
98+
singleTop,fragment被重复创建的回调
99+
100+
@Override
101+
public void onNewIntent() {
102+
}
103+
104+
若需要监听按键事件,只需设置sKeyCallBack
105+
106+
setKeyCallBack(new KeyCallBack() {
107+
@Override
108+
public boolean onKeyDown(int keyCode, KeyEvent event) {
109+
return false;
110+
}
111+
});
112+
113+
114+
使用效果:
115+
116+
<img src="play.gif"/>
117+
118+
此框架已在本公司商业项目使用:
119+
120+
南瓜电影[http://www.wandoujia.com/apps/cn.vcinema.cinema](http://www.wandoujia.com/apps/cn.vcinema.cinema)
121+
122+

0 commit comments

Comments
 (0)