Skip to content

Commit b151877

Browse files
committed
Improve DefaultAutoAdaptStrategy
1 parent c8300dd commit b151877

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

autosize/src/main/java/me/jessyan/autosize/DefaultAutoAdaptStrategy.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,38 @@
3838
*/
3939
public class DefaultAutoAdaptStrategy implements AutoAdaptStrategy {
4040
@Override
41-
public void applyAdapt(Activity activity) {
41+
public void applyAdapt(Object target, Activity activity) {
4242

4343
//检查是否开启了外部三方库的适配模式, 只要不主动调用 ExternalAdaptManager 的方法, 下面的代码就不会执行
4444
if (AutoSizeConfig.getInstance().getExternalAdaptManager().isRun()) {
45-
if (AutoSizeConfig.getInstance().getExternalAdaptManager().isCancelAdapt(activity.getClass())) {
46-
LogUtils.w(String.format(Locale.ENGLISH, "%s canceled the adaptation!", activity.getClass().getName()));
45+
if (AutoSizeConfig.getInstance().getExternalAdaptManager().isCancelAdapt(target.getClass())) {
46+
LogUtils.w(String.format(Locale.ENGLISH, "%s canceled the adaptation!", target.getClass().getName()));
4747
AutoSize.cancelAdapt(activity);
4848
return;
4949
} else {
5050
ExternalAdaptInfo info = AutoSizeConfig.getInstance().getExternalAdaptManager()
51-
.getExternalAdaptInfoOfActivity(activity.getClass());
51+
.getExternalAdaptInfoOfActivity(target.getClass());
5252
if (info != null) {
53-
LogUtils.d(String.format(Locale.ENGLISH, "%s used %s for adaptation!", activity.getClass().getName(), ExternalAdaptInfo.class.getName()));
53+
LogUtils.d(String.format(Locale.ENGLISH, "%s used %s for adaptation!", target.getClass().getName(), ExternalAdaptInfo.class.getName()));
5454
AutoSize.autoConvertDensityOfExternalAdaptInfo(activity, info);
5555
return;
5656
}
5757
}
5858
}
5959

60-
//如果 activity 实现 CancelAdapt 接口表示放弃适配, 所有的适配效果都将失效
61-
if (activity instanceof CancelAdapt) {
62-
LogUtils.w(String.format(Locale.ENGLISH, "%s canceled the adaptation!", activity.getClass().getName()));
60+
//如果 target 实现 CancelAdapt 接口表示放弃适配, 所有的适配效果都将失效
61+
if (target instanceof CancelAdapt) {
62+
LogUtils.w(String.format(Locale.ENGLISH, "%s canceled the adaptation!", target.getClass().getName()));
6363
AutoSize.cancelAdapt(activity);
6464
return;
6565
}
6666

67-
//如果 activity 实现 CustomAdapt 接口表示该 activity 想自定义一些用于适配的参数, 从而改变最终的适配效果
68-
if (activity instanceof CustomAdapt) {
69-
LogUtils.d(String.format(Locale.ENGLISH, "%s implemented by %s!", activity.getClass().getName(), CustomAdapt.class.getName()));
70-
AutoSize.autoConvertDensityOfCustomAdapt(activity, (CustomAdapt) activity);
67+
//如果 target 实现 CustomAdapt 接口表示该 target 想自定义一些用于适配的参数, 从而改变最终的适配效果
68+
if (target instanceof CustomAdapt) {
69+
LogUtils.d(String.format(Locale.ENGLISH, "%s implemented by %s!", target.getClass().getName(), CustomAdapt.class.getName()));
70+
AutoSize.autoConvertDensityOfCustomAdapt(activity, (CustomAdapt) target);
7171
} else {
72-
LogUtils.d(String.format(Locale.ENGLISH, "%s used the global configuration.", activity.getClass().getName()));
72+
LogUtils.d(String.format(Locale.ENGLISH, "%s used the global configuration.", target.getClass().getName()));
7373
AutoSize.autoConvertDensityOfGlobal(activity);
7474
}
7575
}

0 commit comments

Comments
 (0)