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

Commit ab36acb3 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fixe some stuff.

Addresses these bugs:

3061847 - With no headers, PreferenceActivity crashes
2888426 - minor typo in DevicePolicyManagerService.ActiveAdmin.writeToXml()
3159155 - IllegalStateException:"Can not perform this action after
    onSaveInstanceState" while dismissing a DialogFragment
3155995 - PopupWindow.showAtLocation does not respect LayoutParams

Also tweak the new fragment APIs to use abstract classes instead of
interfaces as base classes.

Change-Id: I9c0b4337fe0e304b737b5f7c2762762372bb3020
parent 2cf17ed7
Loading
Loading
Loading
Loading
+45 −7
Original line number Diff line number Diff line
@@ -28065,13 +28065,22 @@
</parameter>
</method>
</class>
<interface name="FragmentManager"
<class name="FragmentManager"
 extends="java.lang.Object"
 abstract="true"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<constructor name="FragmentManager"
 type="android.app.FragmentManager"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</constructor>
<method name="addOnBackStackChangedListener"
 return="void"
 abstract="true"
@@ -28262,7 +28271,7 @@
 visibility="public"
>
</field>
</interface>
</class>
<interface name="FragmentManager.BackStackEntry"
 abstract="true"
 static="true"
@@ -28323,13 +28332,22 @@
>
</method>
</interface>
<interface name="FragmentTransaction"
<class name="FragmentTransaction"
 extends="java.lang.Object"
 abstract="true"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<constructor name="FragmentTransaction"
 type="android.app.FragmentTransaction"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</constructor>
<method name="add"
 return="android.app.FragmentTransaction"
 abstract="true"
@@ -28401,6 +28419,17 @@
 visibility="public"
>
</method>
<method name="commitAllowingStateLoss"
 return="int"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="disallowAddToBackStack"
 return="android.app.FragmentTransaction"
 abstract="true"
@@ -28686,7 +28715,7 @@
 visibility="public"
>
</field>
</interface>
</class>
<class name="Instrumentation"
 extends="java.lang.Object"
 abstract="false"
@@ -30281,13 +30310,22 @@
</parameter>
</method>
</class>
<interface name="LoaderManager"
<class name="LoaderManager"
 extends="java.lang.Object"
 abstract="true"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<constructor name="LoaderManager"
 type="android.app.LoaderManager"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</constructor>
<method name="getLoader"
 return="android.content.Loader&lt;D&gt;"
 abstract="true"
@@ -30348,7 +30386,7 @@
<parameter name="id" type="int">
</parameter>
</method>
</interface>
</class>
<interface name="LoaderManager.LoaderCallbacks"
 abstract="true"
 static="true"
@@ -30392,7 +30430,7 @@
 abstract="true"
 static="false"
 final="false"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<implements name="android.content.Loader.OnLoadCompleteListener">
+11 −3
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ final class BackStackState implements Parcelable {
/**
 * @hide Entry of an operation on the fragment back stack.
 */
final class BackStackRecord implements FragmentTransaction,
final class BackStackRecord extends FragmentTransaction implements
        FragmentManager.BackStackEntry, Runnable {
    static final String TAG = "BackStackEntry";

@@ -417,6 +417,14 @@ final class BackStackRecord implements FragmentTransaction,
    }

    public int commit() {
        return commitInternal(false);
    }

    public int commitAllowingStateLoss() {
        return commitInternal(true);
    }
    
    int commitInternal(boolean allowStateLoss) {
        if (mCommitted) throw new IllegalStateException("commit already called");
        if (FragmentManagerImpl.DEBUG) Log.v(TAG, "Commit: " + this);
        mCommitted = true;
@@ -425,7 +433,7 @@ final class BackStackRecord implements FragmentTransaction,
        } else {
            mIndex = -1;
        }
        mManager.enqueueAction(this);
        mManager.enqueueAction(this, allowStateLoss);
        return mIndex;
    }
    
+10 −2
Original line number Diff line number Diff line
@@ -256,6 +256,10 @@ public class DialogFragment extends Fragment
     * the fragment.
     */
    public void dismiss() {
        dismissInternal(false);
    }

    void dismissInternal(boolean allowStateLoss) {
        if (mDialog != null) {
            mDialog.dismiss();
            mDialog = null;
@@ -353,7 +357,11 @@ public class DialogFragment extends Fragment

    public void onDismiss(DialogInterface dialog) {
        if (!mRemoved) {
            dismiss();
            // Note: we need to use allowStateLoss, because the dialog
            // dispatches this asynchronously so we can receive the call
            // after the activity is paused.  Worst case, when the user comes
            // back to the activity they see the dialog again.
            dismissInternal(true);
        }
    }

+19 −19
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ import java.util.ArrayList;
 * Interface for interacting with {@link Fragment} objects inside of an
 * {@link Activity}
 */
public interface FragmentManager {
public abstract class FragmentManager {
    /**
     * Representation of an entry on the fragment back stack, as created
     * with {@link FragmentTransaction#addToBackStack(String)
@@ -96,7 +96,7 @@ public interface FragmentManager {
     * in the state, and if changes are made after the state is saved then they
     * will be lost.</p>
     */
    public FragmentTransaction openTransaction();
    public abstract FragmentTransaction openTransaction();

    /**
     * Finds a fragment that was identified by the given id either when inflated
@@ -106,7 +106,7 @@ public interface FragmentManager {
     * on the back stack associated with this ID are searched.
     * @return The fragment if found or null otherwise.
     */
    public Fragment findFragmentById(int id);
    public abstract Fragment findFragmentById(int id);

    /**
     * Finds a fragment that was identified by the given tag either when inflated
@@ -116,7 +116,7 @@ public interface FragmentManager {
     * on the back stack are searched.
     * @return The fragment if found or null otherwise.
     */
    public Fragment findFragmentByTag(String tag);
    public abstract Fragment findFragmentByTag(String tag);

    /**
     * Flag for {@link #popBackStack(String, int)}
@@ -132,7 +132,7 @@ public interface FragmentManager {
     * Pop the top state off the back stack.  Returns true if there was one
     * to pop, else false.
     */
    public boolean popBackStack();
    public abstract boolean popBackStack();

    /**
     * Pop the last fragment transition from the manager's fragment
@@ -143,7 +143,7 @@ public interface FragmentManager {
     * the named state itself is popped. If null, only the top state is popped.
     * @param flags Either 0 or {@link #POP_BACK_STACK_INCLUSIVE}.
     */
    public boolean popBackStack(String name, int flags);
    public abstract boolean popBackStack(String name, int flags);

    /**
     * Pop all back stack states up to the one with the given identifier.
@@ -155,29 +155,29 @@ public interface FragmentManager {
     * the named state itself is popped.
     * @param flags Either 0 or {@link #POP_BACK_STACK_INCLUSIVE}.
     */
    public boolean popBackStack(int id, int flags);
    public abstract boolean popBackStack(int id, int flags);

    /**
     * Return the number of entries currently in the back stack.
     */
    public int countBackStackEntries();
    public abstract int countBackStackEntries();

    /**
     * Return the BackStackEntry at index <var>index</var> in the back stack;
     * entries start index 0 being the bottom of the stack.
     */
    public BackStackEntry getBackStackEntry(int index);
    public abstract BackStackEntry getBackStackEntry(int index);

    /**
     * Add a new listener for changes to the fragment back stack.
     */
    public void addOnBackStackChangedListener(OnBackStackChangedListener listener);
    public abstract void addOnBackStackChangedListener(OnBackStackChangedListener listener);

    /**
     * Remove a listener that was previously added with
     * {@link #addOnBackStackChangedListener(OnBackStackChangedListener)}.
     */
    public void removeOnBackStackChangedListener(OnBackStackChangedListener listener);
    public abstract void removeOnBackStackChangedListener(OnBackStackChangedListener listener);

    /**
     * Put a reference to a fragment in a Bundle.  This Bundle can be
@@ -189,7 +189,7 @@ public interface FragmentManager {
     * @param key The name of the entry in the bundle.
     * @param fragment The Fragment whose reference is to be stored.
     */
    public void putFragment(Bundle bundle, String key, Fragment fragment);
    public abstract void putFragment(Bundle bundle, String key, Fragment fragment);

    /**
     * Retrieve the current Fragment instance for a reference previously
@@ -200,7 +200,7 @@ public interface FragmentManager {
     * @return Returns the current Fragment instance that is associated with
     * the given reference.
     */
    public Fragment getFragment(Bundle bundle, String key);
    public abstract Fragment getFragment(Bundle bundle, String key);

    /**
     * Print the FragmentManager's state into the given stream.
@@ -210,7 +210,7 @@ public interface FragmentManager {
     * @param writer A PrintWriter to which the dump is to be set.
     * @param args additional arguments to the dump request.
     */
    public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args);
    public abstract void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args);
}

final class FragmentManagerState implements Parcelable {
@@ -252,7 +252,7 @@ final class FragmentManagerState implements Parcelable {
/**
 * Container for fragments associated with an activity.
 */
final class FragmentManagerImpl implements FragmentManager {
final class FragmentManagerImpl extends FragmentManager {
    static final boolean DEBUG = true;
    static final String TAG = "FragmentManager";
    
@@ -849,8 +849,8 @@ final class FragmentManagerImpl implements FragmentManager {
        return null;
    }
    
    public void enqueueAction(Runnable action) {
        if (mStateSaved) {
    public void enqueueAction(Runnable action, boolean allowStateLoss) {
        if (!allowStateLoss && mStateSaved) {
            throw new IllegalStateException(
                    "Can not perform this action after onSaveInstanceState");
        }
@@ -991,7 +991,7 @@ final class FragmentManagerImpl implements FragmentManager {
                    bss.popFromBackStack(true);
                    reportBackStackChanged();
                }
            });
            }, false);
        } else {
            int index = -1;
            if (name != null || id >= 0) {
@@ -1042,7 +1042,7 @@ final class FragmentManagerImpl implements FragmentManager {
                    }
                    reportBackStackChanged();
                }
            });
            }, false);
        }
        return true;
    }
+46 −30
Original line number Diff line number Diff line
@@ -3,16 +3,16 @@ package android.app;
/**
 * API for performing a set of Fragment operations.
 */
public interface FragmentTransaction {
public abstract class FragmentTransaction {
    /**
     * Calls {@link #add(int, Fragment, String)} with a 0 containerViewId.
     */
    public FragmentTransaction add(Fragment fragment, String tag);
    public abstract FragmentTransaction add(Fragment fragment, String tag);
    
    /**
     * Calls {@link #add(int, Fragment, String)} with a null tag.
     */
    public FragmentTransaction add(int containerViewId, Fragment fragment);
    public abstract FragmentTransaction add(int containerViewId, Fragment fragment);
    
    /**
     * Add a fragment to the activity state.  This fragment may optionally
@@ -29,12 +29,12 @@ public interface FragmentTransaction {
     * 
     * @return Returns the same FragmentTransaction instance.
     */
    public FragmentTransaction add(int containerViewId, Fragment fragment, String tag);
    public abstract FragmentTransaction add(int containerViewId, Fragment fragment, String tag);
    
    /**
     * Calls {@link #replace(int, Fragment, String)} with a null tag.
     */
    public FragmentTransaction replace(int containerViewId, Fragment fragment);
    public abstract FragmentTransaction replace(int containerViewId, Fragment fragment);
    
    /**
     * Replace an existing fragment that was added to a container.  This is
@@ -52,7 +52,7 @@ public interface FragmentTransaction {
     * 
     * @return Returns the same FragmentTransaction instance.
     */
    public FragmentTransaction replace(int containerViewId, Fragment fragment, String tag);
    public abstract FragmentTransaction replace(int containerViewId, Fragment fragment, String tag);
    
    /**
     * Remove an existing fragment.  If it was added to a container, its view
@@ -62,7 +62,7 @@ public interface FragmentTransaction {
     * 
     * @return Returns the same FragmentTransaction instance.
     */
    public FragmentTransaction remove(Fragment fragment);
    public abstract FragmentTransaction remove(Fragment fragment);
    
    /**
     * Hides an existing fragment.  This is only relevant for fragments whose
@@ -73,7 +73,7 @@ public interface FragmentTransaction {
     * 
     * @return Returns the same FragmentTransaction instance.
     */
    public FragmentTransaction hide(Fragment fragment);
    public abstract FragmentTransaction hide(Fragment fragment);
    
    /**
     * Hides a previously hidden fragment.  This is only relevant for fragments whose
@@ -84,55 +84,55 @@ public interface FragmentTransaction {
     * 
     * @return Returns the same FragmentTransaction instance.
     */
    public FragmentTransaction show(Fragment fragment);
    public abstract FragmentTransaction show(Fragment fragment);

    /**
     * @return <code>true</code> if this transaction contains no operations,
     * <code>false</code> otherwise.
     */
    public boolean isEmpty();
    public abstract boolean isEmpty();
    
    /**
     * Bit mask that is set for all enter transitions.
     */
    public final int TRANSIT_ENTER_MASK = 0x1000;
    public static final int TRANSIT_ENTER_MASK = 0x1000;
    
    /**
     * Bit mask that is set for all exit transitions.
     */
    public final int TRANSIT_EXIT_MASK = 0x2000;
    public static final int TRANSIT_EXIT_MASK = 0x2000;
    
    /** Not set up for a transition. */
    public final int TRANSIT_UNSET = -1;
    public static final int TRANSIT_UNSET = -1;
    /** No animation for transition. */
    public final int TRANSIT_NONE = 0;
    public static final int TRANSIT_NONE = 0;
    /** Fragment is being added onto the stack */
    public final int TRANSIT_FRAGMENT_OPEN = 1 | TRANSIT_ENTER_MASK;
    public static final int TRANSIT_FRAGMENT_OPEN = 1 | TRANSIT_ENTER_MASK;
    /** Fragment is being removed from the stack */
    public final int TRANSIT_FRAGMENT_CLOSE = 2 | TRANSIT_EXIT_MASK;
    public static final int TRANSIT_FRAGMENT_CLOSE = 2 | TRANSIT_EXIT_MASK;
    /** Fragment is being added in a 'next' operation*/
    public final int TRANSIT_FRAGMENT_NEXT = 3 | TRANSIT_ENTER_MASK;
    public static final int TRANSIT_FRAGMENT_NEXT = 3 | TRANSIT_ENTER_MASK;
    /** Fragment is being removed in a 'previous' operation */
    public final int TRANSIT_FRAGMENT_PREV = 4 | TRANSIT_EXIT_MASK;
    public static final int TRANSIT_FRAGMENT_PREV = 4 | TRANSIT_EXIT_MASK;

    /**
     * Set specific animation resources to run for the fragments that are
     * entering and exiting in this transaction.
     */
    public FragmentTransaction setCustomAnimations(int enter, int exit);
    public abstract FragmentTransaction setCustomAnimations(int enter, int exit);
    
    /**
     * Select a standard transition animation for this transaction.  May be
     * one of {@link #TRANSIT_NONE}, {@link #TRANSIT_FRAGMENT_OPEN},
     * or {@link #TRANSIT_FRAGMENT_CLOSE}
     */
    public FragmentTransaction setTransition(int transit);
    public abstract FragmentTransaction setTransition(int transit);

    /**
     * Set a custom style resource that will be used for resolving transit
     * animations.
     */
    public FragmentTransaction setTransitionStyle(int styleRes);
    public abstract FragmentTransaction setTransitionStyle(int styleRes);
    
    /**
     * Add this transaction to the back stack.  This means that the transaction
@@ -141,7 +141,7 @@ public interface FragmentTransaction {
     *
     * @param name An optional name for this back stack state, or null.
     */
    public FragmentTransaction addToBackStack(String name);
    public abstract FragmentTransaction addToBackStack(String name);

    /**
     * Returns true if this FragmentTransaction is allowed to be added to the back
@@ -150,14 +150,14 @@ public interface FragmentTransaction {
     *
     * @return True if {@link #addToBackStack(String)} is permitted on this transaction.
     */
    public boolean isAddToBackStackAllowed();
    public abstract boolean isAddToBackStackAllowed();

    /**
     * Disallow calls to {@link #addToBackStack(String)}. Any future calls to
     * addToBackStack will throw {@link IllegalStateException}. If addToBackStack
     * has already been called, this method will throw IllegalStateException.
     */
    public FragmentTransaction disallowAddToBackStack();
    public abstract FragmentTransaction disallowAddToBackStack();

    /**
     * Set the full title to show as a bread crumb when this transaction
@@ -165,14 +165,14 @@ public interface FragmentTransaction {
     *
     * @param res A string resource containing the title.
     */
    public FragmentTransaction setBreadCrumbTitle(int res);
    public abstract FragmentTransaction setBreadCrumbTitle(int res);

    /**
     * Like {@link #setBreadCrumbTitle(int)} but taking a raw string; this
     * method is <em>not</em> recommended, as the string can not be changed
     * later if the locale changes.
     */
    public FragmentTransaction setBreadCrumbTitle(CharSequence text);
    public abstract FragmentTransaction setBreadCrumbTitle(CharSequence text);

    /**
     * Set the short title to show as a bread crumb when this transaction
@@ -180,23 +180,39 @@ public interface FragmentTransaction {
     *
     * @param res A string resource containing the title.
     */
    public FragmentTransaction setBreadCrumbShortTitle(int res);
    public abstract FragmentTransaction setBreadCrumbShortTitle(int res);

    /**
     * Like {@link #setBreadCrumbShortTitle(int)} but taking a raw string; this
     * method is <em>not</em> recommended, as the string can not be changed
     * later if the locale changes.
     */
    public FragmentTransaction setBreadCrumbShortTitle(CharSequence text);
    public abstract FragmentTransaction setBreadCrumbShortTitle(CharSequence text);

    /**
     * Schedules a commit of this transaction.  Note that the commit does
     * Schedules a commit of this transaction.  The commit does
     * not happen immediately; it will be scheduled as work on the main thread
     * to be done the next time that thread is ready.
     *
     * <p class="note">A transaction can only be committed with this method
     * prior to its containing activity saving its state.  If the commit is
     * attempted after that point, an exception will be thrown.  This is
     * because the state after the commit can be lost if the activity needs to
     * be restored from its state.  See {@link #commitAllowingStateLoss()} for
     * situations where it may be okay to lose the commit.</p>
     * 
     * @return Returns the identifier of this transaction's back stack entry,
     * if {@link #addToBackStack(String)} had been called.  Otherwise, returns
     * a negative number.
     */
    public int commit();
    public abstract int commit();

    /**
     * Like {@link #commit} but allows the commit to be executed after an
     * activity's state is saved.  This is dangerous because the commit can
     * be lost if the activity needs to later be restored from its state, so
     * this should only be used for cases where it is okay for the UI state
     * to change unexpectedly on the user.
     */
    public abstract int commitAllowingStateLoss();
}
Loading