Search in sources :

Example 21 with LogWriter

use of android.util.LogWriter in project XobotOS by xamarin.

the class FragmentManagerImpl method saveAllState.

Parcelable saveAllState() {
    // Make sure all pending operations have now been executed to get
    // our state update-to-date.
    execPendingActions();
    mStateSaved = true;
    if (mActive == null || mActive.size() <= 0) {
        return null;
    }
    // First collect all active fragments.
    int N = mActive.size();
    FragmentState[] active = new FragmentState[N];
    boolean haveFragments = false;
    for (int i = 0; i < N; i++) {
        Fragment f = mActive.get(i);
        if (f != null) {
            haveFragments = true;
            FragmentState fs = new FragmentState(f);
            active[i] = fs;
            if (f.mState > Fragment.INITIALIZING && fs.mSavedFragmentState == null) {
                fs.mSavedFragmentState = saveFragmentBasicState(f);
                if (f.mTarget != null) {
                    if (f.mTarget.mIndex < 0) {
                        String msg = "Failure saving state: " + f + " has target not in fragment manager: " + f.mTarget;
                        Slog.e(TAG, msg);
                        dump("  ", null, new PrintWriter(new LogWriter(Log.ERROR, TAG, Log.LOG_ID_SYSTEM)), new String[] {});
                        throw new IllegalStateException(msg);
                    }
                    if (fs.mSavedFragmentState == null) {
                        fs.mSavedFragmentState = new Bundle();
                    }
                    putFragment(fs.mSavedFragmentState, FragmentManagerImpl.TARGET_STATE_TAG, f.mTarget);
                    if (f.mTargetRequestCode != 0) {
                        fs.mSavedFragmentState.putInt(FragmentManagerImpl.TARGET_REQUEST_CODE_STATE_TAG, f.mTargetRequestCode);
                    }
                }
            } else {
                fs.mSavedFragmentState = f.mSavedFragmentState;
            }
            if (DEBUG)
                Log.v(TAG, "Saved state of " + f + ": " + fs.mSavedFragmentState);
        }
    }
    if (!haveFragments) {
        if (DEBUG)
            Log.v(TAG, "saveAllState: no fragments!");
        return null;
    }
    int[] added = null;
    BackStackState[] backStack = null;
    // Build list of currently added fragments.
    if (mAdded != null) {
        N = mAdded.size();
        if (N > 0) {
            added = new int[N];
            for (int i = 0; i < N; i++) {
                added[i] = mAdded.get(i).mIndex;
                if (DEBUG)
                    Log.v(TAG, "saveAllState: adding fragment #" + i + ": " + mAdded.get(i));
            }
        }
    }
    // Now save back stack.
    if (mBackStack != null) {
        N = mBackStack.size();
        if (N > 0) {
            backStack = new BackStackState[N];
            for (int i = 0; i < N; i++) {
                backStack[i] = new BackStackState(this, mBackStack.get(i));
                if (DEBUG)
                    Log.v(TAG, "saveAllState: adding back stack #" + i + ": " + mBackStack.get(i));
            }
        }
    }
    FragmentManagerState fms = new FragmentManagerState();
    fms.mActive = active;
    fms.mAdded = added;
    fms.mBackStack = backStack;
    return fms;
}
Also used : Bundle(android.os.Bundle) LogWriter(android.util.LogWriter) PrintWriter(java.io.PrintWriter)

Example 22 with LogWriter

use of android.util.LogWriter in project android_frameworks_base by DirtyUnicorns.

the class BackStackRecord method popFromBackStack.

public TransitionState popFromBackStack(boolean doStateMove, TransitionState state, SparseArray<Fragment> firstOutFragments, SparseArray<Fragment> lastInFragments) {
    if (FragmentManagerImpl.DEBUG) {
        Log.v(TAG, "popFromBackStack: " + this);
        LogWriter logw = new LogWriter(Log.VERBOSE, TAG);
        PrintWriter pw = new FastPrintWriter(logw, false, 1024);
        dump("  ", null, pw, null);
        pw.flush();
    }
    if (mManager.mCurState >= Fragment.CREATED) {
        if (state == null) {
            if (firstOutFragments.size() != 0 || lastInFragments.size() != 0) {
                state = beginTransition(firstOutFragments, lastInFragments, true);
            }
        } else if (!doStateMove) {
            setNameOverrides(state, mSharedElementTargetNames, mSharedElementSourceNames);
        }
    }
    bumpBackStackNesting(-1);
    Op op = mTail;
    while (op != null) {
        switch(op.cmd) {
            case OP_ADD:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popExitAnim;
                    mManager.removeFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            case OP_REPLACE:
                {
                    Fragment f = op.fragment;
                    if (f != null) {
                        f.mNextAnim = op.popExitAnim;
                        mManager.removeFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                    }
                    if (op.removed != null) {
                        for (int i = 0; i < op.removed.size(); i++) {
                            Fragment old = op.removed.get(i);
                            old.mNextAnim = op.popEnterAnim;
                            mManager.addFragment(old, false);
                        }
                    }
                }
                break;
            case OP_REMOVE:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popEnterAnim;
                    mManager.addFragment(f, false);
                }
                break;
            case OP_HIDE:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popEnterAnim;
                    mManager.showFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            case OP_SHOW:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popExitAnim;
                    mManager.hideFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            case OP_DETACH:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popEnterAnim;
                    mManager.attachFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            case OP_ATTACH:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popExitAnim;
                    mManager.detachFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            default:
                {
                    throw new IllegalArgumentException("Unknown cmd: " + op.cmd);
                }
        }
        op = op.prev;
    }
    if (doStateMove) {
        mManager.moveToState(mManager.mCurState, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle, true);
        state = null;
    }
    if (mIndex >= 0) {
        mManager.freeBackStackIndex(mIndex);
        mIndex = -1;
    }
    return state;
}
Also used : LogWriter(android.util.LogWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 23 with LogWriter

use of android.util.LogWriter in project android_frameworks_base by DirtyUnicorns.

the class FragmentManagerImpl method restoreAllState.

void restoreAllState(Parcelable state, FragmentManagerNonConfig nonConfig) {
    // any nonConfig fragments either, so that is that.
    if (state == null)
        return;
    FragmentManagerState fms = (FragmentManagerState) state;
    if (fms.mActive == null)
        return;
    List<FragmentManagerNonConfig> childNonConfigs = null;
    // to their saved state, so we don't try to instantiate them again.
    if (nonConfig != null) {
        List<Fragment> nonConfigFragments = nonConfig.getFragments();
        childNonConfigs = nonConfig.getChildNonConfigs();
        final int count = nonConfigFragments != null ? nonConfigFragments.size() : 0;
        for (int i = 0; i < count; i++) {
            Fragment f = nonConfigFragments.get(i);
            if (DEBUG)
                Log.v(TAG, "restoreAllState: re-attaching retained " + f);
            FragmentState fs = fms.mActive[f.mIndex];
            fs.mInstance = f;
            f.mSavedViewState = null;
            f.mBackStackNesting = 0;
            f.mInLayout = false;
            f.mAdded = false;
            f.mTarget = null;
            if (fs.mSavedFragmentState != null) {
                fs.mSavedFragmentState.setClassLoader(mHost.getContext().getClassLoader());
                f.mSavedViewState = fs.mSavedFragmentState.getSparseParcelableArray(FragmentManagerImpl.VIEW_STATE_TAG);
                f.mSavedFragmentState = fs.mSavedFragmentState;
            }
        }
    }
    // Build the full list of active fragments, instantiating them from
    // their saved state.
    mActive = new ArrayList<>(fms.mActive.length);
    if (mAvailIndices != null) {
        mAvailIndices.clear();
    }
    for (int i = 0; i < fms.mActive.length; i++) {
        FragmentState fs = fms.mActive[i];
        if (fs != null) {
            FragmentManagerNonConfig childNonConfig = null;
            if (childNonConfigs != null && i < childNonConfigs.size()) {
                childNonConfig = childNonConfigs.get(i);
            }
            Fragment f = fs.instantiate(mHost, mParent, childNonConfig);
            if (DEBUG)
                Log.v(TAG, "restoreAllState: active #" + i + ": " + f);
            mActive.add(f);
            // Now that the fragment is instantiated (or came from being
            // retained above), clear mInstance in case we end up re-restoring
            // from this FragmentState again.
            fs.mInstance = null;
        } else {
            mActive.add(null);
            if (mAvailIndices == null) {
                mAvailIndices = new ArrayList<>();
            }
            if (DEBUG)
                Log.v(TAG, "restoreAllState: avail #" + i);
            mAvailIndices.add(i);
        }
    }
    // Update the target of all retained fragments.
    if (nonConfig != null) {
        List<Fragment> nonConfigFragments = nonConfig.getFragments();
        final int count = nonConfigFragments != null ? nonConfigFragments.size() : 0;
        for (int i = 0; i < count; i++) {
            Fragment f = nonConfigFragments.get(i);
            if (f.mTargetIndex >= 0) {
                if (f.mTargetIndex < mActive.size()) {
                    f.mTarget = mActive.get(f.mTargetIndex);
                } else {
                    Log.w(TAG, "Re-attaching retained fragment " + f + " target no longer exists: " + f.mTargetIndex);
                    f.mTarget = null;
                }
            }
        }
    }
    // Build the list of currently added fragments.
    if (fms.mAdded != null) {
        mAdded = new ArrayList<Fragment>(fms.mAdded.length);
        for (int i = 0; i < fms.mAdded.length; i++) {
            Fragment f = mActive.get(fms.mAdded[i]);
            if (f == null) {
                throwException(new IllegalStateException("No instantiated fragment for index #" + fms.mAdded[i]));
            }
            f.mAdded = true;
            if (DEBUG)
                Log.v(TAG, "restoreAllState: added #" + i + ": " + f);
            if (mAdded.contains(f)) {
                throw new IllegalStateException("Already added!");
            }
            mAdded.add(f);
        }
    } else {
        mAdded = null;
    }
    // Build the back stack.
    if (fms.mBackStack != null) {
        mBackStack = new ArrayList<BackStackRecord>(fms.mBackStack.length);
        for (int i = 0; i < fms.mBackStack.length; i++) {
            BackStackRecord bse = fms.mBackStack[i].instantiate(this);
            if (DEBUG) {
                Log.v(TAG, "restoreAllState: back stack #" + i + " (index " + bse.mIndex + "): " + bse);
                LogWriter logw = new LogWriter(Log.VERBOSE, TAG);
                PrintWriter pw = new FastPrintWriter(logw, false, 1024);
                bse.dump("  ", pw, false);
                pw.flush();
            }
            mBackStack.add(bse);
            if (bse.mIndex >= 0) {
                setBackStackIndex(bse.mIndex, bse);
            }
        }
    } else {
        mBackStack = null;
    }
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) LogWriter(android.util.LogWriter) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 24 with LogWriter

use of android.util.LogWriter in project android_frameworks_base by AOSPA.

the class BackStackRecord method popFromBackStack.

public TransitionState popFromBackStack(boolean doStateMove, TransitionState state, SparseArray<Fragment> firstOutFragments, SparseArray<Fragment> lastInFragments) {
    if (FragmentManagerImpl.DEBUG) {
        Log.v(TAG, "popFromBackStack: " + this);
        LogWriter logw = new LogWriter(Log.VERBOSE, TAG);
        PrintWriter pw = new FastPrintWriter(logw, false, 1024);
        dump("  ", null, pw, null);
        pw.flush();
    }
    if (mManager.mCurState >= Fragment.CREATED) {
        if (state == null) {
            if (firstOutFragments.size() != 0 || lastInFragments.size() != 0) {
                state = beginTransition(firstOutFragments, lastInFragments, true);
            }
        } else if (!doStateMove) {
            setNameOverrides(state, mSharedElementTargetNames, mSharedElementSourceNames);
        }
    }
    bumpBackStackNesting(-1);
    Op op = mTail;
    while (op != null) {
        switch(op.cmd) {
            case OP_ADD:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popExitAnim;
                    mManager.removeFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            case OP_REPLACE:
                {
                    Fragment f = op.fragment;
                    if (f != null) {
                        f.mNextAnim = op.popExitAnim;
                        mManager.removeFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                    }
                    if (op.removed != null) {
                        for (int i = 0; i < op.removed.size(); i++) {
                            Fragment old = op.removed.get(i);
                            old.mNextAnim = op.popEnterAnim;
                            mManager.addFragment(old, false);
                        }
                    }
                }
                break;
            case OP_REMOVE:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popEnterAnim;
                    mManager.addFragment(f, false);
                }
                break;
            case OP_HIDE:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popEnterAnim;
                    mManager.showFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            case OP_SHOW:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popExitAnim;
                    mManager.hideFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            case OP_DETACH:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popEnterAnim;
                    mManager.attachFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            case OP_ATTACH:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popExitAnim;
                    mManager.detachFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            default:
                {
                    throw new IllegalArgumentException("Unknown cmd: " + op.cmd);
                }
        }
        op = op.prev;
    }
    if (doStateMove) {
        mManager.moveToState(mManager.mCurState, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle, true);
        state = null;
    }
    if (mIndex >= 0) {
        mManager.freeBackStackIndex(mIndex);
        mIndex = -1;
    }
    return state;
}
Also used : LogWriter(android.util.LogWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 25 with LogWriter

use of android.util.LogWriter in project android_frameworks_base by AOSPA.

the class FragmentManagerImpl method restoreAllState.

void restoreAllState(Parcelable state, FragmentManagerNonConfig nonConfig) {
    // any nonConfig fragments either, so that is that.
    if (state == null)
        return;
    FragmentManagerState fms = (FragmentManagerState) state;
    if (fms.mActive == null)
        return;
    List<FragmentManagerNonConfig> childNonConfigs = null;
    // to their saved state, so we don't try to instantiate them again.
    if (nonConfig != null) {
        List<Fragment> nonConfigFragments = nonConfig.getFragments();
        childNonConfigs = nonConfig.getChildNonConfigs();
        final int count = nonConfigFragments != null ? nonConfigFragments.size() : 0;
        for (int i = 0; i < count; i++) {
            Fragment f = nonConfigFragments.get(i);
            if (DEBUG)
                Log.v(TAG, "restoreAllState: re-attaching retained " + f);
            FragmentState fs = fms.mActive[f.mIndex];
            fs.mInstance = f;
            f.mSavedViewState = null;
            f.mBackStackNesting = 0;
            f.mInLayout = false;
            f.mAdded = false;
            f.mTarget = null;
            if (fs.mSavedFragmentState != null) {
                fs.mSavedFragmentState.setClassLoader(mHost.getContext().getClassLoader());
                f.mSavedViewState = fs.mSavedFragmentState.getSparseParcelableArray(FragmentManagerImpl.VIEW_STATE_TAG);
                f.mSavedFragmentState = fs.mSavedFragmentState;
            }
        }
    }
    // Build the full list of active fragments, instantiating them from
    // their saved state.
    mActive = new ArrayList<>(fms.mActive.length);
    if (mAvailIndices != null) {
        mAvailIndices.clear();
    }
    for (int i = 0; i < fms.mActive.length; i++) {
        FragmentState fs = fms.mActive[i];
        if (fs != null) {
            FragmentManagerNonConfig childNonConfig = null;
            if (childNonConfigs != null && i < childNonConfigs.size()) {
                childNonConfig = childNonConfigs.get(i);
            }
            Fragment f = fs.instantiate(mHost, mParent, childNonConfig);
            if (DEBUG)
                Log.v(TAG, "restoreAllState: active #" + i + ": " + f);
            mActive.add(f);
            // Now that the fragment is instantiated (or came from being
            // retained above), clear mInstance in case we end up re-restoring
            // from this FragmentState again.
            fs.mInstance = null;
        } else {
            mActive.add(null);
            if (mAvailIndices == null) {
                mAvailIndices = new ArrayList<>();
            }
            if (DEBUG)
                Log.v(TAG, "restoreAllState: avail #" + i);
            mAvailIndices.add(i);
        }
    }
    // Update the target of all retained fragments.
    if (nonConfig != null) {
        List<Fragment> nonConfigFragments = nonConfig.getFragments();
        final int count = nonConfigFragments != null ? nonConfigFragments.size() : 0;
        for (int i = 0; i < count; i++) {
            Fragment f = nonConfigFragments.get(i);
            if (f.mTargetIndex >= 0) {
                if (f.mTargetIndex < mActive.size()) {
                    f.mTarget = mActive.get(f.mTargetIndex);
                } else {
                    Log.w(TAG, "Re-attaching retained fragment " + f + " target no longer exists: " + f.mTargetIndex);
                    f.mTarget = null;
                }
            }
        }
    }
    // Build the list of currently added fragments.
    if (fms.mAdded != null) {
        mAdded = new ArrayList<Fragment>(fms.mAdded.length);
        for (int i = 0; i < fms.mAdded.length; i++) {
            Fragment f = mActive.get(fms.mAdded[i]);
            if (f == null) {
                throwException(new IllegalStateException("No instantiated fragment for index #" + fms.mAdded[i]));
            }
            f.mAdded = true;
            if (DEBUG)
                Log.v(TAG, "restoreAllState: added #" + i + ": " + f);
            if (mAdded.contains(f)) {
                throw new IllegalStateException("Already added!");
            }
            mAdded.add(f);
        }
    } else {
        mAdded = null;
    }
    // Build the back stack.
    if (fms.mBackStack != null) {
        mBackStack = new ArrayList<BackStackRecord>(fms.mBackStack.length);
        for (int i = 0; i < fms.mBackStack.length; i++) {
            BackStackRecord bse = fms.mBackStack[i].instantiate(this);
            if (DEBUG) {
                Log.v(TAG, "restoreAllState: back stack #" + i + " (index " + bse.mIndex + "): " + bse);
                LogWriter logw = new LogWriter(Log.VERBOSE, TAG);
                PrintWriter pw = new FastPrintWriter(logw, false, 1024);
                bse.dump("  ", pw, false);
                pw.flush();
            }
            mBackStack.add(bse);
            if (bse.mIndex >= 0) {
                setBackStackIndex(bse.mIndex, bse);
            }
        }
    } else {
        mBackStack = null;
    }
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) LogWriter(android.util.LogWriter) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Aggregations

LogWriter (android.util.LogWriter)31 PrintWriter (java.io.PrintWriter)31 FastPrintWriter (com.android.internal.util.FastPrintWriter)24 NotFoundException (android.content.res.Resources.NotFoundException)5 SuperNotCalledException (android.util.SuperNotCalledException)5 Bundle (android.os.Bundle)1