Skip to content
Commit 38432882 authored by George Mount's avatar George Mount
Browse files

Remove access to private field mFactorySet.

Fixes: 123769585
Test: compiled framework

mFactorySet is being modified by app developers to reset the factory
on an existing LayoutInflater. Instead, a developer should use
LayoutInflater#cloneInContext() to create a new LayoutInflater
and set the factory on it instead.

This is often desired at the Activity level, so that any part of
the application getting a LayoutInflater using the Activity as
a Context will get the LayoutInflater with a custom factory. To
do this, the Activity has to replace the returned LayoutInflater.
Something like this should work:

  private LayoutInflater mLayoutInflater;

  @Override
  public Object getSystemService(String name) {
    if (Context.LAYOUT_INFLATER_SERVICE.equals(name)) {
      if (mLayoutInflater == null) {
        mLayoutInflater =
          ((LayoutInflater)super.getSystemService(name)).cloneInContext(this);
        mLayoutInflater.setFactory(new CustomLayoutFactory());
      }
      return mLayoutInflater;
    }
    return super.getSystemService(name);
  }

Change-Id: I155ea9538c5783b32301252fb3fb9baa1cc92036
parent 23f34cd6
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment