1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
| package me.yokeyword.sample.demo_flow.base;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.animation.Animation;
import me.yokeyword.fragmentation.ExtraTransaction;
import me.yokeyword.fragmentation.ISupportFragment;
import me.yokeyword.fragmentation.SupportFragmentDelegate;
import me.yokeyword.fragmentation.SupportHelper;
import me.yokeyword.fragmentation.anim.FragmentAnimator;
/**
* 展示自定制的MySupportFragment,不继承SupportFragment
* Created by YoKey on 17/6/24.
*/
public class MySupportFragment extends Fragment implements ISupportFragment {
final SupportFragmentDelegate mDelegate = new SupportFragmentDelegate(this);
protected FragmentActivity _mActivity;
@Override
public SupportFragmentDelegate getSupportDelegate() {
return mDelegate;
}
/**
* Perform some extra transactions.
* 额外的事务:自定义Tag,添加SharedElement动画,操作非回退栈Fragment
*/
@Override
public ExtraTransaction extraTransaction() {
return mDelegate.extraTransaction();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mDelegate.onAttach(activity);
_mActivity = mDelegate.getActivity();
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDelegate.onCreate(savedInstanceState);
}
@Override
public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
return mDelegate.onCreateAnimation(transit, enter, nextAnim);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mDelegate.onActivityCreated(savedInstanceState);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mDelegate.onSaveInstanceState(outState);
}
@Override
public void onResume() {
super.onResume();
mDelegate.onResume();
}
@Override
public void onPause() {
super.onPause();
mDelegate.onPause();
}
@Override
public void onDestroyView() {
mDelegate.onDestroyView();
super.onDestroyView();
}
@Override
public void onDestroy() {
mDelegate.onDestroy();
super.onDestroy();
}
@Override
public void onHiddenChanged(boolean hidden) {
super.onHiddenChanged(hidden);
mDelegate.onHiddenChanged(hidden);
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
mDelegate.setUserVisibleHint(isVisibleToUser);
}
/**
* Causes the Runnable r to be added to the action queue.
* <p>
* The runnable will be run after all the previous action has been run.
* <p>
* 前面的事务全部执行后 执行该Action
*
* @deprecated Use {@link #post(Runnable)} instead.
*/
@Deprecated
@Override
public void enqueueAction(Runnable runnable) {
mDelegate.enqueueAction(runnable);
}
/**
* Causes the Runnable r to be added to the action queue.
* <p>
* The runnable will be run after all the previous action has been run.
* <p>
* 前面的事务全部执行后 执行该Action
*/
@Override
public void post(Runnable runnable) {
mDelegate.post(runnable);
}
/**
* Called when the enter-animation end.
* 入栈动画 结束时,回调
*/
@Override
public void onEnterAnimationEnd(Bundle savedInstanceState) {
mDelegate.onEnterAnimationEnd(savedInstanceState);
}
/**
* Lazy initial,Called when fragment is first called.
* <p>
* 同级下的 懒加载 + ViewPager下的懒加载 的结合回调方法
*/
@Override
public void onLazyInitView(@Nullable Bundle savedInstanceState) {
mDelegate.onLazyInitView(savedInstanceState);
}
/**
* Called when the fragment is visible.
* 当Fragment对用户可见时回调
* <p>
* Is the combination of [onHiddenChanged() + onResume()/onPause() + setUserVisibleHint()]
*/
@Override
public void onSupportVisible() {
mDelegate.onSupportVisible();
}
/**
* Called when the fragment is invivible.
* <p>
* Is the combination of [onHiddenChanged() + onResume()/onPause() + setUserVisibleHint()]
*/
@Override
public void onSupportInvisible() {
mDelegate.onSupportInvisible();
}
/**
* Return true if the fragment has been supportVisible.
*/
@Override
final public boolean isSupportVisible() {
return mDelegate.isSupportVisible();
}
/**
* Set fragment animation with a higher priority than the ISupportActivity
* 设定当前Fragmemt动画,优先级比在SupportActivity里高
*/
@Override
public FragmentAnimator onCreateFragmentAnimator() {
return mDelegate.onCreateFragmentAnimator();
}
/**
* 获取设置的全局动画 copy
*
* @return FragmentAnimator
*/
@Override
public FragmentAnimator getFragmentAnimator() {
return mDelegate.getFragmentAnimator();
}
/**
* 设置Fragment内的全局动画
*/
@Override
public void setFragmentAnimator(FragmentAnimator fragmentAnimator) {
mDelegate.setFragmentAnimator(fragmentAnimator);
}
/**
* 按返回键触发,前提是SupportActivity的onBackPressed()方法能被调用
*
* @return false则继续向上传递, true则消费掉该事件
*/
@Override
public boolean onBackPressedSupport() {
return mDelegate.onBackPressedSupport();
}
/**
* 类似 {@link Activity#setResult(int, Intent)}
* <p>
* Similar to {@link Activity#setResult(int, Intent)}
*
* @see #startForResult(ISupportFragment, int)
*/
@Override
public void setFragmentResult(int resultCode, Bundle bundle) {
mDelegate.setFragmentResult(resultCode, bundle);
}
/**
* 类似 {@link Activity#onActivityResult(int, int, Intent)}
* <p>
* Similar to {@link Activity#onActivityResult(int, int, Intent)}
*
* @see #startForResult(ISupportFragment, int)
*/
@Override
public void onFragmentResult(int requestCode, int resultCode, Bundle data) {
mDelegate.onFragmentResult(requestCode, resultCode, data);
}
/**
* 在start(TargetFragment,LaunchMode)时,启动模式为SingleTask/SingleTop, 回调TargetFragment的该方法
* 类似 {@link Activity#onNewIntent(Intent)}
* <p>
* Similar to {@link Activity#onNewIntent(Intent)}
*
* @param args putNewBundle(Bundle newBundle)
* @see #start(ISupportFragment, int)
*/
@Override
public void onNewBundle(Bundle args) {
mDelegate.onNewBundle(args);
}
/**
* 添加NewBundle,用于启动模式为SingleTask/SingleTop时
*
* @see #start(ISupportFragment, int)
*/
@Override
public void putNewBundle(Bundle newBundle) {
mDelegate.putNewBundle(newBundle);
}
/****************************************以下为可选方法(Optional methods)******************************************************/
// 自定制Support时,可移除不必要的方法
/**
* 隐藏软键盘
*/
protected void hideSoftInput() {
mDelegate.hideSoftInput();
}
/**
* 显示软键盘,调用该方法后,会在onPause时自动隐藏软键盘
*/
protected void showSoftInput(final View view) {
mDelegate.showSoftInput(view);
}
/**
* 加载根Fragment, 即Activity内的第一个Fragment 或 Fragment内的第一个子Fragment
*
* @param containerId 容器id
* @param toFragment 目标Fragment
*/
public void loadRootFragment(int containerId, ISupportFragment toFragment) {
mDelegate.loadRootFragment(containerId, toFragment);
}
public void loadRootFragment(int containerId, ISupportFragment toFragment, boolean addToBackStack, boolean allowAnim) {
mDelegate.loadRootFragment(containerId, toFragment, addToBackStack, allowAnim);
}
public void start(ISupportFragment toFragment) {
mDelegate.start(toFragment);
}
/**
* @param launchMode Similar to Activity's LaunchMode.
*/
public void start(final ISupportFragment toFragment, @LaunchMode int launchMode) {
mDelegate.start(toFragment, launchMode);
}
/**
* Launch an fragment for which you would like a result when it poped.
*/
public void startForResult(ISupportFragment toFragment, int requestCode) {
mDelegate.startForResult(toFragment, requestCode);
}
/**
* Start the target Fragment and pop itself
*/
public void startWithPop(ISupportFragment toFragment) {
mDelegate.startWithPop(toFragment);
}
/**
* @see #popTo(Class, boolean)
* +
* @see #start(ISupportFragment)
*/
public void startWithPopTo(ISupportFragment toFragment, Class<?> targetFragmentClass, boolean includeTargetFragment) {
mDelegate.startWithPopTo(toFragment, targetFragmentClass, includeTargetFragment);
}
public void replaceFragment(ISupportFragment toFragment, boolean addToBackStack) {
mDelegate.replaceFragment(toFragment, addToBackStack);
}
public void pop() {
mDelegate.pop();
}
/**
* Pop the last fragment transition from the manager's fragment
* back stack.
* <p>
* 出栈到目标fragment
*
* @param targetFragmentClass 目标fragment
* @param includeTargetFragment 是否包含该fragment
*/
public void popTo(Class<?> targetFragmentClass, boolean includeTargetFragment) {
mDelegate.popTo(targetFragmentClass, includeTargetFragment);
}
/**
* 获取栈内的fragment对象
*/
public <T extends ISupportFragment> T findChildFragment(Class<T> fragmentClass) {
return SupportHelper.findFragment(getChildFragmentManager(), fragmentClass);
}
}
|