Java Code Examples for android.view.LayoutInflater#getFactory()

The following examples show how to use android.view.LayoutInflater#getFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LayoutInflaterCompat.java    From Android-skin-support with MIT License 6 votes vote down vote up
/**
 * Attach a custom Factory interface for creating views while using
 * this LayoutInflater. This must not be null, and can only be set once;
 * after setting, you can not change the factory.
 *
 * @see LayoutInflater#setFactory(android.view.LayoutInflater.Factory)
 * @deprecated Use {@link #setFactory2(LayoutInflater, LayoutInflater.Factory2)} instead to set
 * and {@link LayoutInflater#getFactory2()} to get the factory.
 */
@Deprecated
public static void setFactory(
        LayoutInflater inflater, LayoutInflaterFactory factory) {
    if (Build.VERSION.SDK_INT >= 21) {
        inflater.setFactory2(factory != null ? new LayoutInflaterCompat.Factory2Wrapper(factory) : null);
    } else {
        final LayoutInflater.Factory2 factory2 = factory != null
                ? new LayoutInflaterCompat.Factory2Wrapper(factory) : null;
        inflater.setFactory2(factory2);

        final LayoutInflater.Factory f = inflater.getFactory();
        if (f instanceof LayoutInflater.Factory2) {
            // The merged factory is now set to getFactory(), but not getFactory2() (pre-v21).
            // We will now try and force set the merged factory to mFactory2
            forceSetFactory2(inflater, (LayoutInflater.Factory2) f);
        } else {
            // Else, we will force set the original wrapped Factory2
            forceSetFactory2(inflater, factory2);
        }
    }
}
 
Example 2
Source File: LayoutInflaterCompat.java    From Android-skin-support with MIT License 6 votes vote down vote up
/**
 * Attach a custom {@link LayoutInflater.Factory2} for creating views while using
 * this {@link LayoutInflater}. This must not be null, and can only be set once;
 * after setting, you can not change the factory.
 *
 * @see LayoutInflater#setFactory2(android.view.LayoutInflater.Factory2)
 */
public static void setFactory2(
        LayoutInflater inflater, LayoutInflater.Factory2 factory) {
    inflater.setFactory2(factory);

    if (Build.VERSION.SDK_INT < 21) {
        final LayoutInflater.Factory f = inflater.getFactory();
        if (f instanceof LayoutInflater.Factory2) {
            // The merged factory is now set to getFactory(), but not getFactory2() (pre-v21).
            // We will now try and force set the merged factory to mFactory2
            forceSetFactory2(inflater, (LayoutInflater.Factory2) f);
        } else {
            // Else, we will force set the original wrapped Factory2
            forceSetFactory2(inflater, factory);
        }
    }
}
 
Example 3
Source File: PluginFactoryCompat.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
static void setFactory(LayoutInflater inflater, PluginFactoryInterface factory) {
    if (Build.VERSION.SDK_INT >=11) {
        final LayoutInflater.Factory2 factory2 = factory != null
                ? new FactoryWrapper2(factory) : null;
        inflater.setFactory2(factory2);

        if (Build.VERSION.SDK_INT < 21) {
            final LayoutInflater.Factory f = inflater.getFactory();
            if (f instanceof LayoutInflater.Factory2) {
                // The merged factory is now set to getFactory(), but not getFactory2() (pre-v21).
                // We will now try and force set the merged factory to mFactory2
                forceSetFactory2(inflater, (LayoutInflater.Factory2) f);
            } else {
                // Else, we will force set the original wrapped Factory2
                forceSetFactory2(inflater, factory2);
            }
        }
    } else {
        final LayoutInflater.Factory factory1 = factory != null
                ? new FactoryWrapper(factory) : null;
        inflater.setFactory(factory1);
    }

}
 
Example 4
Source File: SkinLayoutInflater.java    From chameleon with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化
 *
 * @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;
        }
    }
}
 
Example 5
Source File: PluginViewFactory.java    From Android-Plugin-Framework with MIT License 5 votes vote down vote up
public void installViewFactory() {
	LogUtil.d("安装PluginViewFactory");
	LayoutInflater layoutInflater = mContext.getLayoutInflater();
	if (layoutInflater.getFactory() == null) {
		PluginFactoryCompat.setFactory(layoutInflater, this);
	} else {
		LogUtil.d("The Activity's LayoutInflater already has a Factory installed"
				+ " so we can not install plugin's");
	}
	LogUtil.d("安装PluginViewFactory完成");
}
 
Example 6
Source File: LayoutInflaterCompat.java    From Android-skin-support with MIT License 3 votes vote down vote up
/**
 * 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;
}