Factory2 ( )源码实例Demo

android.view.LayoutInflater#Factory2 ( )源码实例Demo

下面列出了android.view.LayoutInflater#Factory2 ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dynamic-support   文件: DynamicTheme.java
/**
 * Attach a local context to this theme.
 * <p>It can be an activity in case different themes are required for different activities.
 *
 * @param localContext The context to be attached with this theme.
 * @param layoutInflater The layout inflater factory for the local context.
 *                       <p>{@code null} to use no custom layout inflater.
 *
 * @return The {@link DynamicTheme} object to allow for chaining of calls to set methods.
 */
public DynamicTheme attach(@NonNull Context localContext,
        @Nullable LayoutInflater.Factory2 layoutInflater) {
    this.mLocalContext = localContext;
    this.mDefaultLocalTheme = new DynamicAppTheme(COLOR_PRIMARY_DEFAULT,
            COLOR_PRIMARY_DARK_DEFAULT, COLOR_ACCENT_DEFAULT, FONT_SCALE_DEFAULT,
            CORNER_SIZE_DEFAULT, Theme.BackgroundAware.ENABLE);
    this.mLocalTheme = new DynamicAppTheme();

    if (localContext instanceof Activity && layoutInflater != null
            && ((Activity) localContext).getLayoutInflater().getFactory2() == null) {
        LayoutInflaterCompat.setFactory2(((Activity) localContext)
                .getLayoutInflater(), layoutInflater);
    }

    return this;
}
 
/**
 * 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);
        }
    }
}
 
源代码3 项目: pretty   文件: PrettyLayoutInflater.java
public PrettyLayoutInflater(Pretty pretty, final Activity activity) {
	super(activity);

	this.pretty = pretty;

	// if the activity is a FragmentActivity from the support lib then lets wrap it
	// so the <fragment> tags still work
	try {
		Class<?> fragAct = Class.forName("android.support.v4.app.FragmentActivity");
		if (fragAct != null && fragAct.isInstance(activity)) {
			// FragmentActivity is a Factory1, not Factory2
			wrappedFactory = new LayoutInflater.Factory2() {
				@Override
				public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
					return onCreateView(name, context, attrs);
				}

				@Override
				public View onCreateView(String name, Context context, AttributeSet attrs) {
					return activity.onCreateView(name, context, attrs);
				}
			};
		}
	} catch (Exception ignored) { /* ignored */ }
	super.setFactory2(new PrettyLayoutFactory(this, wrappedFactory, pretty));
}
 
源代码4 项目: scene   文件: SceneLayoutInflater.java
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);
        }
    }
}
 
源代码5 项目: pandroid   文件: PandroidViewFactory.java
@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
    for (LayoutInflater.Factory2 factory2 : factories) {
        View result = factory2.onCreateView(parent, name, context, attrs);
        if (result != null)
            return result;
    }
    return appDelegate.createView(parent, name, context, attrs);
}
 
源代码6 项目: chameleon   文件: SkinActivity.java
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getLayoutInflater();
    mLayoutInfalter.applyCurrentSkin();
    // AppCompatActivity 需要设置
    AppCompatDelegate delegate = this.getDelegate();
    if (delegate instanceof LayoutInflater.Factory2) {
        mLayoutInfalter.setFactory2((LayoutInflater.Factory2) delegate);
    }

    // 自己的逻辑
}
 
源代码7 项目: Neptune   文件: LayoutInflaterCompat.java
/**
 * 给LayoutInflater设置privateFactory
 * 解决同名View或者Fragment冲突的问题
 */
public static void setPrivateFactory(LayoutInflater inflater) {
    LayoutInflater.Factory2 factory2 = null;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        // 5.0以下重复设置privateFactory没有FactoryMerger,而Activity会把自己设置成privateFactory
        factory2 = ReflectionUtils.on(inflater).get("mPrivateFactory");
    }
    LayoutInflater.Factory2 privateFactory = new CompatPrivateFactory(factory2);
    Class<?>[] paramTypes = new Class[]{LayoutInflater.Factory2.class};
    ReflectionUtils.on(inflater).call("setPrivateFactory", sMethods, paramTypes, privateFactory);
}
 
源代码8 项目: pandroid   文件: PandroidApplication.java
/**
 * factories to use in the layout inflater. If pandroid view support is enable CompatViewFactory
 * will be added
 *
 * @return list of custom LayoutInflater factories
 */
@Override
public List<LayoutInflater.Factory2> getLayoutInflaterFactories() {
    ArrayList<LayoutInflater.Factory2> factories = new ArrayList<>();
    if (PandroidConfig.VIEW_SUPPORT) {
        factories.add(new PandroidCompatViewFactory());
    }
    return factories;
}
 
源代码9 项目: NightOwl   文件: InjectedInflaterV11.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static LayoutInflater.Factory2 wrap(LayoutInflater.Factory2 factory){
    return new Factory2WrapperImpl(factory);
}
 
源代码10 项目: NightOwl   文件: InjectedInflaterV11.java
public LayoutInflater.Factory2 getCoreFactory() {
    return mFactory;
}
 
源代码11 项目: BackgroundLibrary   文件: BackgroundFactory.java
public void setInterceptFactory2(LayoutInflater.Factory2 factory) {
    mViewCreateFactory2 = factory;
}
 
源代码12 项目: pretty   文件: LayoutFactoryWrapper.java
public LayoutFactoryWrapper(@NotNull LayoutInflater inflater, @Nullable LayoutInflater.Factory2 baseFactory) {
    this.inflater = inflater;
    this.base = baseFactory;
}
 
源代码13 项目: Neptune   文件: LayoutInflaterCompat.java
CompatPrivateFactory(LayoutInflater.Factory2 factory) {
    mOrigFactory = factory;
}
 
源代码14 项目: revolution-irc   文件: LiveThemeViewFactory.java
public LiveThemeViewFactory(LiveThemeManager liveThemeManager,
                            LayoutInflater.Factory2 parentFactory) {
    mLiveThemeManager = liveThemeManager;
    mParentFactory = parentFactory;
}
 
源代码15 项目: NightOwl   文件: InjectedInflaterV11.java
private PrivateFactoryWrapperImpl(LayoutInflater.Factory2 factory, InjectedInflaterBase inflater) {
    super(inflater);
    mFactory = factory;
}
 
源代码16 项目: Emoji   文件: MaterialEmojiLayoutFactory.java
public MaterialEmojiLayoutFactory(@Nullable final LayoutInflater.Factory2 delegate) {
  super(delegate);
}
 
源代码17 项目: pretty   文件: PrettyLayoutInflater.java
protected PrettyLayoutInflater(LayoutInflater original, Context newContext, LayoutInflater.Factory2 wrappedFactory, Pretty pretty) {
	super(original, newContext);
	this.pretty = pretty;
	super.setFactory2(new PrettyLayoutFactory(this, wrappedFactory, pretty));
}
 
源代码18 项目: NightOwl   文件: InjectedInflaterV11.java
private Factory2WrapperImpl(LayoutInflater.Factory2 factory) {
    mFactory = factory;
}
 
源代码19 项目: dynamic-support   文件: DynamicSystemActivity.java
/**
 * Returns a layout inflater factory for this activity.
 * <p>It will be used to replace the app compat widgets with their dynamic counterparts
 * to provide the support for dynamic theme.
 *
 * <p><p>Override this method to provide a custom layout inflater.
 *
 * @return The layout inflater factory for this activity.
 */
protected @Nullable LayoutInflater.Factory2 getDynamicLayoutInflater() {
    return new DynamicLayoutInflater();
}
 
源代码20 项目: pandroid   文件: PandroidFactoryProvider.java
List<LayoutInflater.Factory2> getLayoutInflaterFactories();