Java Code Examples for android.view.LayoutInflater#setFactory2()
The following examples show how to use
android.view.LayoutInflater#setFactory2() .
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: BackgroundLibrary.java From BackgroundLibrary with Apache License 2.0 | 6 votes |
public static LayoutInflater inject(Context context) { LayoutInflater inflater; if (context instanceof Activity) { inflater = ((Activity) context).getLayoutInflater(); } else { inflater = LayoutInflater.from(context); } if (inflater == null) { return null; } if (inflater.getFactory2() == null) { BackgroundFactory factory = setDelegateFactory(context); inflater.setFactory2(factory); } else if (!(inflater.getFactory2() instanceof BackgroundFactory)) { forceSetFactory2(inflater); } return inflater; }
Example 2
Source File: BackgroundLibrary.java From BackgroundLibrary with Apache License 2.0 | 6 votes |
public static LayoutInflater inject(Context context) { LayoutInflater inflater; if (context instanceof Activity) { inflater = ((Activity) context).getLayoutInflater(); } else { inflater = LayoutInflater.from(context); } if (inflater == null) { return null; } if (inflater.getFactory2() == null) { BackgroundFactory factory = setDelegateFactory(context); inflater.setFactory2(factory); } else if (!(inflater.getFactory2() instanceof BackgroundFactory)) { forceSetFactory2(inflater); } return inflater; }
Example 3
Source File: LayoutInflaterCompat.java From Android-skin-support with MIT License | 6 votes |
/** * 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 4
Source File: LayoutInflaterCompat.java From Android-skin-support with MIT License | 6 votes |
/** * 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 5
Source File: PluginFactoryCompat.java From Android-Plugin-Framework with MIT License | 6 votes |
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 6
Source File: Folivora.java From Folivora with Apache License 2.0 | 5 votes |
/** * Install Folivora's ViewFactory to current context. note that if * you are using AppCompatActivity, this method should called after * your activity's super.onCreate() method, since AppCompatDelegate * will install a {@link LayoutInflater.Factory2} factory2 to this * context. * * @param ctx context to enable folivora support */ public static void installViewFactory(Context ctx) { LayoutInflater inflater = LayoutInflater.from(ctx); LayoutInflater.Factory2 factory2 = inflater.getFactory2(); if (factory2 instanceof FolivoraViewFactory) return; FolivoraViewFactory viewFactory = new FolivoraViewFactory(); viewFactory.mFactory2 = factory2; if (factory2 != null) { FolivoraViewFactory.forceSetFactory2(inflater, viewFactory); } else { inflater.setFactory2(viewFactory); } }
Example 7
Source File: FolivoraPreview.java From Folivora with Apache License 2.0 | 5 votes |
private static void installViewFactoryIfNeeded() { Collection<BridgeContext> contexts = peekContexts(); for (BridgeContext context : contexts) { LayoutInflater inflater = LayoutInflater.from(context); if (inflater.getFactory2() == null) { inflater.setFactory2(new ViewFactory(inflater, context.getLayoutlibCallback())); } } }
Example 8
Source File: PluginInterceptActivity.java From Phantom with Apache License 2.0 | 4 votes |
private void initLayoutInflater() { mLayoutInflater = (LayoutInflater) super.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (null != mLayoutInflater) { mLayoutInflater.setFactory2(this); } }