Skip to content

Commit 5366ad0

Browse files
committed
Create FragmentLifecycleCallbacksImpl
1 parent e9ad609 commit 5366ad0

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2018 JessYan
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package me.jessyan.autosize;
17+
18+
import android.os.Bundle;
19+
import android.support.v4.app.Fragment;
20+
import android.support.v4.app.FragmentManager;
21+
22+
/**
23+
* ================================================
24+
* {@link FragmentLifecycleCallbacksImpl} 可用来代替在 BaseFragment 中加入适配代码的传统方式
25+
* {@link FragmentLifecycleCallbacksImpl} 这种方案类似于 AOP, 面向接口, 侵入性低, 方便统一管理, 扩展性强, 并且也支持适配三方库的 {@link Fragment}
26+
* <p>
27+
* Created by JessYan on 2018/8/25 13:52
28+
* <a href="mailto:[email protected]">Contact me</a>
29+
* <a href="https://github.com/JessYanCoding">Follow me</a>
30+
* ================================================
31+
*/
32+
public class FragmentLifecycleCallbacksImpl extends FragmentManager.FragmentLifecycleCallbacks {
33+
/**
34+
* 屏幕适配逻辑策略类
35+
*/
36+
private AutoAdaptStrategy mAutoAdaptStrategy;
37+
38+
public FragmentLifecycleCallbacksImpl(AutoAdaptStrategy autoAdaptStrategy) {
39+
mAutoAdaptStrategy = autoAdaptStrategy;
40+
}
41+
42+
@Override
43+
public void onFragmentCreated(FragmentManager fm, Fragment f, Bundle savedInstanceState) {
44+
if (mAutoAdaptStrategy != null) {
45+
mAutoAdaptStrategy.applyAdapt(f, f.getActivity());
46+
}
47+
}
48+
49+
/**
50+
* 设置屏幕适配逻辑策略类
51+
*
52+
* @param autoAdaptStrategy {@link AutoAdaptStrategy}
53+
*/
54+
public void setAutoAdaptStrategy(AutoAdaptStrategy autoAdaptStrategy) {
55+
mAutoAdaptStrategy = autoAdaptStrategy;
56+
}
57+
}

0 commit comments

Comments
 (0)