Example usage for android.util LogWriter LogWriter

List of usage examples for android.util LogWriter LogWriter

Introduction

In this page you can find the example usage for android.util LogWriter LogWriter.

Prototype

@UnsupportedAppUsage
public LogWriter(int priority, String tag) 

Source Link

Document

Create a new Writer that sends to the log with the given priority and tag.

Usage

From source file:android.app.FragmentManager.java

private void throwException(RuntimeException ex) {
    Log.e(TAG, ex.getMessage());/* w  ww .j ava2  s  .  co  m*/
    LogWriter logw = new LogWriter(Log.ERROR, TAG);
    PrintWriter pw = new PrintWriter(logw);
    if (mActivity != null) {
        Log.e(TAG, "Activity state:");
        try {
            mActivity.dump("  ", null, pw, new String[] {});
        } catch (Exception e) {
            Log.e(TAG, "Failed dumping state", e);
        }
    } else {
        Log.e(TAG, "Fragment manager state:");
        try {
            dump("  ", null, pw, new String[] {});
        } catch (Exception e) {
            Log.e(TAG, "Failed dumping state", e);
        }
    }
    throw ex;
}

From source file:android.app.FragmentManager.java

private void throwException(RuntimeException ex) {
    Log.e(TAG, ex.getMessage());//from  w ww .j a  v  a  2 s.com
    LogWriter logw = new LogWriter(Log.ERROR, TAG);
    PrintWriter pw = new FastPrintWriter(logw, false, 1024);
    if (mActivity != null) {
        Log.e(TAG, "Activity state:");
        try {
            mActivity.dump("  ", null, pw, new String[] {});
        } catch (Exception e) {
            pw.flush();
            Log.e(TAG, "Failed dumping state", e);
        }
    } else {
        Log.e(TAG, "Fragment manager state:");
        try {
            dump("  ", null, pw, new String[] {});
        } catch (Exception e) {
            pw.flush();
            Log.e(TAG, "Failed dumping state", e);
        }
    }
    pw.flush();
    throw ex;
}

From source file:android.app.FragmentManager.java

void restoreAllState(Parcelable state, ArrayList<Fragment> nonConfig) {
    // If there is no saved state at all, then there can not be
    // any nonConfig fragments either, so that is that.
    if (state == null)
        return;// w  w  w. ja v a 2 s  . c  om
    FragmentManagerState fms = (FragmentManagerState) state;
    if (fms.mActive == null)
        return;

    // First re-attach any non-config instances we are retaining back
    // to their saved state, so we don't try to instantiate them again.
    if (nonConfig != null) {
        for (int i = 0; i < nonConfig.size(); i++) {
            Fragment f = nonConfig.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(mActivity.getClassLoader());
                f.mSavedViewState = fs.mSavedFragmentState
                        .getSparseParcelableArray(FragmentManagerImpl.VIEW_STATE_TAG);
            }
        }
    }

    // Build the full list of active fragments, instantiating them from
    // their saved state.
    mActive = new ArrayList<Fragment>(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) {
            Fragment f = fs.instantiate(mActivity, mParent);
            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<Integer>();
            }
            if (DEBUG)
                Log.v(TAG, "restoreAllState: avail #" + i);
            mAvailIndices.add(i);
        }
    }

    // Update the target of all retained fragments.
    if (nonConfig != null) {
        for (int i = 0; i < nonConfig.size(); i++) {
            Fragment f = nonConfig.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 PrintWriter(logw);
                bse.dump("  ", pw, false);
            }
            mBackStack.add(bse);
            if (bse.mIndex >= 0) {
                setBackStackIndex(bse.mIndex, bse);
            }
        }
    } else {
        mBackStack = null;
    }
}

From source file:android.app.FragmentManager.java

void restoreAllState(Parcelable state, ArrayList<Fragment> nonConfig) {
    // If there is no saved state at all, then there can not be
    // any nonConfig fragments either, so that is that.
    if (state == null)
        return;/*  w ww.  jav  a 2 s  . com*/
    FragmentManagerState fms = (FragmentManagerState) state;
    if (fms.mActive == null)
        return;

    // First re-attach any non-config instances we are retaining back
    // to their saved state, so we don't try to instantiate them again.
    if (nonConfig != null) {
        for (int i = 0; i < nonConfig.size(); i++) {
            Fragment f = nonConfig.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(mActivity.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<Fragment>(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) {
            Fragment f = fs.instantiate(mActivity, mParent);
            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<Integer>();
            }
            if (DEBUG)
                Log.v(TAG, "restoreAllState: avail #" + i);
            mAvailIndices.add(i);
        }
    }

    // Update the target of all retained fragments.
    if (nonConfig != null) {
        for (int i = 0; i < nonConfig.size(); i++) {
            Fragment f = nonConfig.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;
    }
}