|
38 | 38 | */ |
39 | 39 | public class DefaultAutoAdaptStrategy implements AutoAdaptStrategy { |
40 | 40 | @Override |
41 | | - public void applyAdapt(Activity activity) { |
| 41 | + public void applyAdapt(Object target, Activity activity) { |
42 | 42 |
|
43 | 43 | //检查是否开启了外部三方库的适配模式, 只要不主动调用 ExternalAdaptManager 的方法, 下面的代码就不会执行 |
44 | 44 | 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())); |
47 | 47 | AutoSize.cancelAdapt(activity); |
48 | 48 | return; |
49 | 49 | } else { |
50 | 50 | ExternalAdaptInfo info = AutoSizeConfig.getInstance().getExternalAdaptManager() |
51 | | - .getExternalAdaptInfoOfActivity(activity.getClass()); |
| 51 | + .getExternalAdaptInfoOfActivity(target.getClass()); |
52 | 52 | 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())); |
54 | 54 | AutoSize.autoConvertDensityOfExternalAdaptInfo(activity, info); |
55 | 55 | return; |
56 | 56 | } |
57 | 57 | } |
58 | 58 | } |
59 | 59 |
|
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())); |
63 | 63 | AutoSize.cancelAdapt(activity); |
64 | 64 | return; |
65 | 65 | } |
66 | 66 |
|
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); |
71 | 71 | } 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())); |
73 | 73 | AutoSize.autoConvertDensityOfGlobal(activity); |
74 | 74 | } |
75 | 75 | } |
|
0 commit comments