Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b2852cab authored by Jason Monk's avatar Jason Monk
Browse files

Allow FragmentContainer to play a role in fragment construction

This allows class swapping, dependency injection, and other fun
stuff.

Test: manual
Change-Id: I93e17ccf9cebb6f542903d31597b5ea41544e069
parent fabf8e81
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -4586,6 +4586,7 @@ package android.app {
  public abstract class FragmentContainer {
    ctor public FragmentContainer();
    method public android.app.Fragment instantiate(android.content.Context, java.lang.String, android.os.Bundle);
    method public abstract android.view.View onFindViewById(int);
    method public abstract boolean onHasView();
  }
+1 −0
Original line number Diff line number Diff line
@@ -4742,6 +4742,7 @@ package android.app {
  public abstract class FragmentContainer {
    ctor public FragmentContainer();
    method public android.app.Fragment instantiate(android.content.Context, java.lang.String, android.os.Bundle);
    method public abstract android.view.View onFindViewById(int);
    method public abstract boolean onHasView();
  }
+1 −0
Original line number Diff line number Diff line
@@ -4596,6 +4596,7 @@ package android.app {
  public abstract class FragmentContainer {
    ctor public FragmentContainer();
    method public android.app.Fragment instantiate(android.content.Context, java.lang.String, android.os.Bundle);
    method public abstract android.view.View onFindViewById(int);
    method public abstract boolean onHasView();
  }
+7 −3
Original line number Diff line number Diff line
@@ -102,15 +102,19 @@ final class FragmentState implements Parcelable {
        mSavedFragmentState = in.readBundle();
    }

    public Fragment instantiate(FragmentHostCallback host, Fragment parent,
            FragmentManagerNonConfig childNonConfig) {
    public Fragment instantiate(FragmentHostCallback host, FragmentContainer container,
            Fragment parent, FragmentManagerNonConfig childNonConfig) {
        if (mInstance == null) {
            final Context context = host.getContext();
            if (mArguments != null) {
                mArguments.setClassLoader(context.getClassLoader());
            }

            if (container != null) {
                mInstance = container.instantiate(context, mClassName, mArguments);
            } else {
                mInstance = Fragment.instantiate(context, mClassName, mArguments);
            }

            if (mSavedFragmentState != null) {
                mSavedFragmentState.setClassLoader(context.getClassLoader());
+11 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package android.app;

import android.annotation.IdRes;
import android.annotation.Nullable;
import android.content.Context;
import android.os.Bundle;
import android.view.View;

/**
@@ -35,4 +37,13 @@ public abstract class FragmentContainer {
     * Return {@code true} if the container holds any view.
     */
    public abstract boolean onHasView();

    /**
     * Creates an instance of the specified fragment, can be overridden to construct fragments
     * with dependencies, or change the fragment being constructed. By default just calls
     * {@link Fragment#instantiate(Context, String, Bundle)}.
     */
    public Fragment instantiate(Context context, String className, Bundle arguments) {
        return Fragment.instantiate(context, className, arguments);
    }
}
Loading