下面列出了android.view.LayoutInflater#Factory ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
View view = null;
if (context instanceof LayoutInflater.Factory) {
view = ((LayoutInflater.Factory) context).onCreateView(name, context, attrs);
}
if (factory != null && view == null) {
view = factory.onCreateView(name, context, attrs);
}
if (view == null) {
view = createViewOrFailQuietly(name, context, attrs);
}
if (view != null) {
onViewCreated(view, name, context, attrs);
}
return view;
}
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
View view = null;
if (context instanceof LayoutInflater.Factory) {
view = ((LayoutInflater.Factory) context).onCreateView(name, context, attrs);
}
if (factory != null && view == null) {
view = factory.onCreateView(name, context, attrs);
}
if (view == null) {
view = createViewOrFailQuietly(name, context, attrs);
}
if (view != null) {
onViewCreated(view, name, context, attrs);
}
return view;
}
private View callActivityOnCreateView(View parent, String name, Context context, AttributeSet attrs) {
View view = null;
if (mOriginalWindowCallback instanceof LayoutInflater.Factory) {
view = ((LayoutInflater.Factory) mOriginalWindowCallback)
.onCreateView(name, context, attrs);
}
if (view != null) {
return view;
}
if(Build.VERSION.SDK_INT >= 11) {
if (mOriginalWindowCallback instanceof LayoutInflater.Factory2) {
return ((LayoutInflater.Factory2) mOriginalWindowCallback)
.onCreateView(parent, name, context, attrs);
}
}
return null;
}
@Override
public void setFactory(LayoutInflater.Factory factory) {
super.setFactory(factory);
if (this.mLayoutInflater != null) {
this.mLayoutInflater.setFactory(factory);
}
}
private void createLayoutInflaterIfNeeded() {
if (this.mLayoutInflater != null) {
return;
}
Context context = null;
if (this.mScene.getTheme() == 0) {
context = this.mScene.requireActivity();
} else {
context = this.mScene.requireSceneContext();
}
//create new LayoutInflater
this.mLayoutInflater = this.mScene.requireActivity().getLayoutInflater().cloneInContext(context);
LayoutInflater.Filter filter = getFilter();
if (filter != null) {
this.mLayoutInflater.setFilter(filter);
}
LayoutInflater.Factory2 factory2 = getFactory2();
if (factory2 != null) {
this.mLayoutInflater.setFactory2(factory2);
} else {
LayoutInflater.Factory factory = getFactory();
if (factory != null) {
this.mLayoutInflater.setFactory(factory);
}
}
}
/**
* 初始化
*
* @param original
*/
private void init(LayoutInflater original) {
//将自己设置为LayoutInflaterFactory,接管view的创建
setFactory2(this);
if (mConstructorArgsField != null) {
try {
mConstructorArgs = (Object[]) mConstructorArgsField.get(this);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
//将自己注册到换肤监听
SkinEngine.registerSkinObserver(this);
if (original == null) {
return;
}
if (original instanceof SkinLayoutInflater) {
SkinLayoutInflater skinLayoutInflater = (SkinLayoutInflater) original;
this.mFactory = skinLayoutInflater.mFactory;
this.mFactory2 = skinLayoutInflater.mFactory2;
} else {
LayoutInflater.Factory factory = original.getFactory();
if (factory instanceof LayoutInflater.Factory2) {
mFactory2 = (Factory2) factory;
} else {
mFactory = factory;
}
}
}
@Override
public void setFactory(LayoutInflater.Factory factory) {
// Only set our factory and wrap calls to the Factory trying to be set!
if (!(factory instanceof WrapperFactory)) {
super.setFactory(new WrapperFactory(factory, this));
} else {
super.setFactory(factory);
}
}
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
View view = null;
name = transfer(name);
if (context instanceof LayoutInflater.Factory) {
view = ((LayoutInflater.Factory) context).onCreateView(name, context, attrs);
}
if (view == null && wrapped != null) {
view = wrapped.onCreateView(name, context, attrs);
}
if (view == null) {
view = createViewOrFailQuietly(name, context, attrs);
}
return view;
}
public LayoutInflater.Factory getFactory() {
return mFactory;
}
public void setInterceptFactory(LayoutInflater.Factory factory) {
mViewCreateFactory = factory;
}
public void setInterceptFactory(LayoutInflater.Factory factory) {
mViewCreateFactory = factory;
}
public CalligraphyFactory(LayoutInflater.Factory factory, int attributeId) {
this.factory = factory;
this.mAttributeId = attributeId;
}
public CustomTypefaceFactory(Context context, CustomTypeface customTypeface,
LayoutInflater.Factory factory) {
mContext = context;
mCustomTypeface = customTypeface;
mFactory = factory;
}
public static LayoutInflater.Factory wrap(InjectedInflaterBase inflater, LayoutInflater.Factory factory){
return new FactoryWrapperImpl(inflater,factory);
}
private FactoryWrapperImpl(LayoutInflater.Factory factory) {
mFactory = factory;
}
public static LayoutInflater.Factory wrap(LayoutInflater.Factory factory){
return new FactoryWrapperImpl(factory);
}
LayoutInflater.Factory getLayoutInflaterFactory() {
return this;
}
public PluginViewInflater(Context context, final LayoutInflater.Factory viewfactory) {
mContext = context;
mViewfactory = viewfactory;
}
public PluginViewFactory(Activity context, Window window, LayoutInflater.Factory viewfactory) {
mContext = context;
mWindow = window;
mOriginalWindowCallback = window.getCallback();
mViewfactory = viewfactory;
}
/**
* Return the current {@link LayoutInflaterFactory} (or null). This is
* called on each element name. If the factory returns a View, add that
* to the hierarchy. If it returns null, proceed to call onCreateView(name).
*
* @return The {@link LayoutInflaterFactory} associated with the
* {@link LayoutInflater}. Will be {@code null} if the inflater does not
* have a {@link LayoutInflaterFactory} but a raw {@link LayoutInflater.Factory}.
* @see LayoutInflater#getFactory()
* @deprecated Use {@link #setFactory2(LayoutInflater, LayoutInflater.Factory2)} to set and
* {@link LayoutInflater#getFactory2()} to get the factory.
*/
@Deprecated
public static LayoutInflaterFactory getFactory(LayoutInflater inflater) {
LayoutInflater.Factory factory = inflater.getFactory();
if (factory instanceof LayoutInflaterCompat.Factory2Wrapper) {
return ((LayoutInflaterCompat.Factory2Wrapper) factory).mDelegateFactory;
}
return null;
}