Search in sources :

Example 76 with Parcelable

use of android.os.Parcelable in project platform_frameworks_base by android.

the class Preference method dispatchRestoreInstanceState.

/**
     * Called by {@link #restoreHierarchyState} to retrieve the saved state for this
     * Preference and its children. May be overridden to modify how restoring
     * happens to the children of a Preference. For example, some Preference objects may
     * not want to save state for their children.
     * 
     * @param container The Bundle that holds the previously saved state.
     * @see #restoreHierarchyState
     * @see #onRestoreInstanceState
     */
void dispatchRestoreInstanceState(Bundle container) {
    if (hasKey()) {
        Parcelable state = container.getParcelable(mKey);
        if (state != null) {
            mBaseMethodCalled = false;
            onRestoreInstanceState(state);
            if (!mBaseMethodCalled) {
                throw new IllegalStateException("Derived class did not call super.onRestoreInstanceState()");
            }
        }
    }
}
Also used : Parcelable(android.os.Parcelable)

Example 77 with Parcelable

use of android.os.Parcelable in project platform_frameworks_base by android.

the class TextView method onSaveInstanceState.

@Override
public Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    // Save state if we are forced to
    final boolean freezesText = getFreezesText();
    boolean hasSelection = false;
    int start = -1;
    int end = -1;
    if (mText != null) {
        start = getSelectionStart();
        end = getSelectionEnd();
        if (start >= 0 || end >= 0) {
            // Or save state if there is a selection
            hasSelection = true;
        }
    }
    if (freezesText || hasSelection) {
        SavedState ss = new SavedState(superState);
        if (freezesText) {
            if (mText instanceof Spanned) {
                final Spannable sp = new SpannableStringBuilder(mText);
                if (mEditor != null) {
                    removeMisspelledSpans(sp);
                    sp.removeSpan(mEditor.mSuggestionRangeSpan);
                }
                ss.text = sp;
            } else {
                ss.text = mText.toString();
            }
        }
        if (hasSelection) {
            // XXX Should also save the current scroll position!
            ss.selStart = start;
            ss.selEnd = end;
        }
        if (isFocused() && start >= 0 && end >= 0) {
            ss.frozenWithFocus = true;
        }
        ss.error = getError();
        if (mEditor != null) {
            ss.editorState = mEditor.saveInstanceState();
        }
        return ss;
    }
    return superState;
}
Also used : Parcelable(android.os.Parcelable) Spanned(android.text.Spanned) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) Spannable(android.text.Spannable) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 78 with Parcelable

use of android.os.Parcelable in project carat by amplab.

the class TwoStatePreference method onSaveInstanceState.

@Override
protected Parcelable onSaveInstanceState() {
    final Parcelable superState = super.onSaveInstanceState();
    if (isPersistent()) {
        // No need to save instance state since it's persistent
        return superState;
    }
    final SavedState myState = new SavedState(superState);
    myState.checked = isChecked();
    return myState;
}
Also used : Parcelable(android.os.Parcelable)

Example 79 with Parcelable

use of android.os.Parcelable in project platform_frameworks_base by android.

the class TwoStatePreference method onSaveInstanceState.

@Override
protected Parcelable onSaveInstanceState() {
    final Parcelable superState = super.onSaveInstanceState();
    if (isPersistent()) {
        // No need to save instance state since it's persistent
        return superState;
    }
    final SavedState myState = new SavedState(superState);
    myState.checked = isChecked();
    return myState;
}
Also used : Parcelable(android.os.Parcelable)

Example 80 with Parcelable

use of android.os.Parcelable in project platform_frameworks_base by android.

the class View method dispatchRestoreInstanceState.

/**
     * Called by {@link #restoreHierarchyState(android.util.SparseArray)} to retrieve the
     * state for this view and its children. May be overridden to modify how restoring
     * happens to a view's children; for example, some views may want to not store state
     * for their children.
     *
     * @param container The SparseArray which holds previously saved state.
     *
     * @see #dispatchSaveInstanceState(android.util.SparseArray)
     * @see #restoreHierarchyState(android.util.SparseArray)
     * @see #onRestoreInstanceState(android.os.Parcelable)
     */
protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
    if (mID != NO_ID) {
        Parcelable state = container.get(mID);
        if (state != null) {
            // Log.i("View", "Restoreing #" + Integer.toHexString(mID)
            // + ": " + state);
            mPrivateFlags &= ~PFLAG_SAVE_STATE_CALLED;
            onRestoreInstanceState(state);
            if ((mPrivateFlags & PFLAG_SAVE_STATE_CALLED) == 0) {
                throw new IllegalStateException("Derived class did not call super.onRestoreInstanceState()");
            }
        }
    }
}
Also used : Parcelable(android.os.Parcelable)

Aggregations

Parcelable (android.os.Parcelable)826 Bundle (android.os.Bundle)99 View (android.view.View)85 Intent (android.content.Intent)58 SparseArray (android.util.SparseArray)38 Test (org.junit.Test)31 ArrayList (java.util.ArrayList)26 MenuItem (android.view.MenuItem)23 ImageView (android.widget.ImageView)23 TextView (android.widget.TextView)17 MenuItem (com.actionbarsherlock.view.MenuItem)14 SuppressLint (android.annotation.SuppressLint)13 Dialog (android.app.Dialog)13 MediumTest (android.support.test.filters.MediumTest)13 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)12 Paint (android.graphics.Paint)12 MenuView (com.android.internal.view.menu.MenuView)12 RemoteException (android.os.RemoteException)11 Bitmap (android.graphics.Bitmap)10 ShortcutIconResource (android.content.Intent.ShortcutIconResource)9