WMS是一个复杂的模块,就像一个很大的家族,里面有各种角色,认识类图就像是认识WMS模块中的各个角色,不先把人认清楚了,怎么更好的理解他们之间的交互?
我觉得,这也是面向对象的语言魅力,面向对象的语言构建了一个小小的世界,每一个类都是其中的一个角色。
这是WMS模块中的始祖级别的类,WMS中所有的类都继承于它。
ConfigurationContainer类中主要有三个Configuration对象,Configuration 本事就是各种基础参数 mode的记录
mRequestedOverrideConfiguration:当前应用主动请求的Configuration
mResolvedOverrideConfiguration:mRequestedOverrideConfiguration 经过子类的的调整后的对应容器请求的config,子类会重现相关的方法。
mFullConfiguration:当前使用的Configuration。
onConfigurationChanged()
从方法的注释中可以看到,这个方法的作用是当父节点更新后,需要更新自己的全部configuration.
public abstract class ConfigurationContainer<E extends ConfigurationContainer> {
//下面三个Configuration对象是配置相关的基础对象,onfiguration对象本身主要是一些参数的配置。
/**
* Contains requested override configuration settings applied to this configuration container. 当前应用主动请求的所有config
*/
private Configuration mRequestedOverrideConfiguration = new Configuration();
/**
* Contains the requested override configuration with parent and policy constraints applied.
* This is the set of overrides that gets applied to the full and merged configurations.为mRequestedOverrideConfiguration 经过子类的的调整后的对应容器请求的config
*/
private Configuration mResolvedOverrideConfiguration = new Configuration();
/**
* Contains full configuration applied to this configuration container. Corresponds to full
* parent's config with applied {@link #mResolvedOverrideConfiguration}.为父亲的config(mFullConfiguration) 加上自己的mResolvedOverrideConfiguration 组合成自身的mResolvedOverrideConfiguration
*/
private Configuration mFullConfiguration = new Configuration();//这个是返回的configuration
/**
* Returns full configuration applied to this configuration container.
* This method should be used for getting settings applied in each particular level of the
* hierarchy.从getConfiguration函数中可以看出,mFullConfiguration是在使用的congfiguration
*/
public Configuration getConfiguration() {
return mFullConfiguration;
}
//onConfigurationChanged 当配置发生改变时调用,会在onParentChanged中调用
public void onConfigurationChanged(Configuration newParentConfig) {
mResolvedTmpConfig.setTo(mResolvedOverrideConfiguration); //先保存mResolvedOverrideConfiguration
resolveOverrideConfiguration(newParentConfig);//mResolvedOverrideConfiguration从newParentConfig中算出来
mFullConfiguration.setTo(newParentConfig);//mFullConfiguration 设为 newParentConfig
mFullConfiguration.updateFrom(mResolvedOverrideConfiguration);//重新计算mFullConfiguration
onMergedOverrideConfigurationChanged();
if (!mResolvedTmpConfig.equals(mResolvedOverrideConfiguration)) {
// This depends on the assumption that change-listeners don't do
// their own override resolution. This way, dependent hierarchies
// can stay properly synced-up with a primary hierarchy's constraints.
// Since the hierarchies will be merged, this whole thing will go away
// before the assumption will be broken.
// Inform listeners of the change.
for (int i = mChangeListeners.size() - 1; i >= 0; --i) {
mChangeListeners.get(i).onRequestedOverrideConfigurationChanged(
mResolvedOverrideConfiguration);//通知子节点更新
}
}
for (int i = mChangeListeners.size() - 1; i >= 0; --i) {
mChangeListeners.get(i).onMergedOverrideConfigurationChanged(
mMergedOverrideConfiguration);
}
for (int i = getChildCount() - 1; i >= 0; --i) {
dispatchConfigurationToChild(getChildAt(i), mFullConfiguration);
}
}
//应该是parent发生变化是被调用
void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) {
// Removing parent usually means that we've detached this entity to destroy it or to attach
// to another parent. In both cases we don't need to update the configuration now.
if (newParent != null) {
// Update full configuration of this container and all its children.
onConfigurationChanged(newParent.mFullConfiguration);
// Update merged override configuration of this container and all its children.
onMergedOverrideConfigurationChanged();
}
}
}
and all its children.
onMergedOverrideConfigurationChanged();
}
}
}