Java Code Examples for android.view.LayoutInflater#Factory2

The following examples show how to use android.view.LayoutInflater#Factory2 . 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: PrettyLayoutInflater.java    From pretty with MIT License 6 votes vote down vote up
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));
}
 
Example 2
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 3
Source File: DynamicTheme.java    From dynamic-support with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: PandroidViewFactory.java    From pandroid with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 5
Source File: PandroidApplication.java    From pandroid with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: LayoutInflaterCompat.java    From Neptune with Apache License 2.0 5 votes vote down vote up
/**
 * 给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);
}
 
Example 7
Source File: SkinActivity.java    From chameleon with Apache License 2.0 5 votes vote down vote up
@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);
    }

    // 自己的逻辑
}
 
Example 8
Source File: SceneLayoutInflater.java    From scene with Apache License 2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 9
Source File: LayoutFactoryWrapper.java    From pretty with MIT License 4 votes vote down vote up
public LayoutFactoryWrapper(@NotNull LayoutInflater inflater, @Nullable LayoutInflater.Factory2 baseFactory) {
    this.inflater = inflater;
    this.base = baseFactory;
}
 
Example 10
Source File: BackgroundFactory.java    From BackgroundLibrary with Apache License 2.0 4 votes vote down vote up
public void setInterceptFactory2(LayoutInflater.Factory2 factory) {
    mViewCreateFactory2 = factory;
}
 
Example 11
Source File: LayoutInflaterCompat.java    From Neptune with Apache License 2.0 4 votes vote down vote up
CompatPrivateFactory(LayoutInflater.Factory2 factory) {
    mOrigFactory = factory;
}
 
Example 12
Source File: InjectedInflaterV11.java    From NightOwl with Apache License 2.0 4 votes vote down vote up
public LayoutInflater.Factory2 getCoreFactory() {
    return mFactory;
}
 
Example 13
Source File: LiveThemeViewFactory.java    From revolution-irc with GNU General Public License v3.0 4 votes vote down vote up
public LiveThemeViewFactory(LiveThemeManager liveThemeManager,
                            LayoutInflater.Factory2 parentFactory) {
    mLiveThemeManager = liveThemeManager;
    mParentFactory = parentFactory;
}
 
Example 14
Source File: InjectedInflaterV11.java    From NightOwl with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static LayoutInflater.Factory2 wrap(LayoutInflater.Factory2 factory){
    return new Factory2WrapperImpl(factory);
}
 
Example 15
Source File: InjectedInflaterV11.java    From NightOwl with Apache License 2.0 4 votes vote down vote up
private PrivateFactoryWrapperImpl(LayoutInflater.Factory2 factory, InjectedInflaterBase inflater) {
    super(inflater);
    mFactory = factory;
}
 
Example 16
Source File: MaterialEmojiLayoutFactory.java    From Emoji with Apache License 2.0 4 votes vote down vote up
public MaterialEmojiLayoutFactory(@Nullable final LayoutInflater.Factory2 delegate) {
  super(delegate);
}
 
Example 17
Source File: PrettyLayoutInflater.java    From pretty with MIT License 4 votes vote down vote up
protected PrettyLayoutInflater(LayoutInflater original, Context newContext, LayoutInflater.Factory2 wrappedFactory, Pretty pretty) {
	super(original, newContext);
	this.pretty = pretty;
	super.setFactory2(new PrettyLayoutFactory(this, wrappedFactory, pretty));
}
 
Example 18
Source File: InjectedInflaterV11.java    From NightOwl with Apache License 2.0 4 votes vote down vote up
private Factory2WrapperImpl(LayoutInflater.Factory2 factory) {
    mFactory = factory;
}
 
Example 19
Source File: DynamicSystemActivity.java    From dynamic-support with Apache License 2.0 2 votes vote down vote up
/**
 * 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();
}
 
Example 20
Source File: PandroidFactoryProvider.java    From pandroid with Apache License 2.0 votes vote down vote up
List<LayoutInflater.Factory2> getLayoutInflaterFactories();