Example usage for android.os Bundle putSparseParcelableArray

List of usage examples for android.os Bundle putSparseParcelableArray

Introduction

In this page you can find the example usage for android.os Bundle putSparseParcelableArray.

Prototype

public void putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value) 

Source Link

Document

Inserts a SparceArray of Parcelable values into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:com.codetroopers.betterpickers.calendardatepicker.CalendarDatePickerDialogFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt(KEY_SELECTED_YEAR, mCalendar.get(Calendar.YEAR));
    outState.putInt(KEY_SELECTED_MONTH, mCalendar.get(Calendar.MONTH));
    outState.putInt(KEY_SELECTED_DAY, mCalendar.get(Calendar.DAY_OF_MONTH));
    outState.putInt(KEY_WEEK_START, mWeekStart);
    outState.putLong(KEY_DATE_START, mMinDate.getDateInMillis());
    outState.putLong(KEY_DATE_END, mMaxDate.getDateInMillis());
    outState.putInt(KEY_CURRENT_VIEW, mCurrentView);
    outState.putInt(KEY_THEME, mStyleResId);
    int listPosition = -1;
    if (mCurrentView == MONTH_AND_DAY_VIEW) {
        listPosition = mDayPickerView.getMostVisiblePosition();
    } else if (mCurrentView == YEAR_VIEW) {
        listPosition = mYearPickerView.getFirstVisiblePosition();
        outState.putInt(KEY_LIST_POSITION_OFFSET, mYearPickerView.getFirstPositionOffset());
    }/*  ww w  .ja va2 s  . c o m*/
    outState.putInt(KEY_LIST_POSITION, listPosition);
    outState.putSparseParcelableArray(KEY_DISABLED_DAYS, mDisabledDays);
}

From source file:de.eidottermihi.rpicheck.activity.MainActivity.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    // saving query data of current device
    if (currentDevice != null) {
        LOGGER.debug("Saving instance state (current device)");
        outState.putSerializable(CURRENT_DEVICE, currentDevice);
        if (allDevices == null) {
            LOGGER.debug("Saving new instance of all devices.");
            allDevices = new SparseArray<RaspberryDeviceBean>();
            allDevices.put(currentDevice.getId(), currentDevice);
        } else {//from w  ww  .  j  av a2s  .  c o m
            LOGGER.debug("Adding current device to all devices.");
            allDevices.put(currentDevice.getId(), currentDevice);
        }
    }
    if (allDevices != null) {
        outState.putSparseParcelableArray(ALL_DEVICES, allDevices);
    }
    outState.putString("bug:fix", "no empty outstate");
    super.onSaveInstanceState(outState);
}

From source file:com.actionbarsherlock.internal.view.menu.MenuBuilder.java

private void dispatchSaveInstanceState(Bundle outState) {
    if (mPresenters.isEmpty())
        return;/*from ww w  . j  a  va 2 s .c o m*/

    SparseArray<Parcelable> presenterStates = new SparseArray<Parcelable>();

    for (WeakReference<MenuPresenter> ref : mPresenters) {
        final MenuPresenter presenter = ref.get();
        if (presenter == null) {
            mPresenters.remove(ref);
        } else {
            final int id = presenter.getId();
            if (id > 0) {
                final Parcelable state = presenter.onSaveInstanceState();
                if (state != null) {
                    presenterStates.put(id, state);
                }
            }
        }
    }

    outState.putSparseParcelableArray(PRESENTER_KEY, presenterStates);
}

From source file:com.actionbarsherlock.internal.view.menu.MenuBuilder.java

public void saveActionViewStates(Bundle outStates) {
    SparseArray<Parcelable> viewStates = null;

    final int itemCount = size();
    for (int i = 0; i < itemCount; i++) {
        final MenuItem item = getItem(i);
        final View v = item.getActionView();
        if (v != null && v.getId() != View.NO_ID) {
            if (viewStates == null) {
                viewStates = new SparseArray<Parcelable>();
            }/*from w w w  . j  av  a2 s  . c  o  m*/
            v.saveHierarchyState(viewStates);
        }
        if (item.hasSubMenu()) {
            final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
            subMenu.saveActionViewStates(outStates);
        }
    }

    if (viewStates != null) {
        outStates.putSparseParcelableArray(getActionViewStatesKey(), viewStates);
    }
}

From source file:android.support.v7.internal.view.menu.MenuBuilder.java

public void saveActionViewStates(Bundle outStates) {
    SparseArray<Parcelable> viewStates = null;

    final int itemCount = size();
    for (int i = 0; i < itemCount; i++) {
        final MenuItem item = getItem(i);
        final View v = MenuItemCompat.getActionView(item);
        if (v != null && v.getId() != View.NO_ID) {
            if (viewStates == null) {
                viewStates = new SparseArray<Parcelable>();
            }/*from  w  w  w  . j  a va2  s  .  co m*/
            v.saveHierarchyState(viewStates);
            if (MenuItemCompat.isActionViewExpanded(item)) {
                outStates.putInt(EXPANDED_ACTION_VIEW_ID, item.getItemId());
            }
        }
        if (item.hasSubMenu()) {
            final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
            subMenu.saveActionViewStates(outStates);
        }
    }

    if (viewStates != null) {
        outStates.putSparseParcelableArray(getActionViewStatesKey(), viewStates);
    }
}

From source file:android.app.FragmentManager.java

Bundle saveFragmentBasicState(Fragment f) {
    Bundle result = null;

    if (mStateBundle == null) {
        mStateBundle = new Bundle();
    }/*from www . j  av  a2 s  . c  o  m*/
    f.performSaveInstanceState(mStateBundle);
    if (!mStateBundle.isEmpty()) {
        result = mStateBundle;
        mStateBundle = null;
    }

    if (f.mView != null) {
        saveFragmentViewState(f);
    }
    if (f.mSavedViewState != null) {
        if (result == null) {
            result = new Bundle();
        }
        result.putSparseParcelableArray(FragmentManagerImpl.VIEW_STATE_TAG, f.mSavedViewState);
    }
    if (!f.mUserVisibleHint) {
        if (result == null) {
            result = new Bundle();
        }
        // Only add this if it's not the default value
        result.putBoolean(FragmentManagerImpl.USER_VISIBLE_HINT_TAG, f.mUserVisibleHint);
    }

    return result;
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    // NOTE: Do NOT do this. Ever. This is a terrible and horrifying hack.
    ////w ww.ja  v a2 s  . c  om
    // Home loads the content of the workspace on a background thread. This
    // means that
    // a previously focused view will be, after orientation change, added to
    // the view
    // hierarchy at an undeterminate time in the future. If we were to
    // invoke
    // super.onRestoreInstanceState() here, the focus restoration would fail
    // because the
    // view to focus does not exist yet.
    //
    // However, not invoking super.onRestoreInstanceState() is equally bad.
    // In such a case,
    // panels would not be restored properly. For instance, if the menu is
    // open then the
    // user changes the orientation, the menu would not be opened in the new
    // orientation.
    //
    // To solve both issues Home messes up with the internal state of the
    // bundle to remove
    // the properties it does not want to see restored at this moment. After
    // invoking
    // super.onRestoreInstanceState(), it removes the panels state.
    //
    // Later, when the workspace is done loading, Home calls
    // super.onRestoreInstanceState()
    // again to restore focus and other view properties. It will not,
    // however, restore
    // the panels since at this point the panels' state has been removed
    // from the bundle.
    //
    // This is a bad example, do not do this.
    //
    // If you are curious on how this code was put together, take a look at
    // the following
    // in Android's source code:
    // - Activity.onRestoreInstanceState()
    // - PhoneWindow.restoreHierarchyState()
    // - PhoneWindow.DecorView.onAttachedToWindow()
    //
    // The source code of these various methods shows what states should be
    // kept to
    // achieve what we want here.

    Bundle windowState = savedInstanceState.getBundle("android:viewHierarchyState");
    SparseArray<Parcelable> savedStates = null;
    int focusedViewId = View.NO_ID;

    if (windowState != null) {
        savedStates = windowState.getSparseParcelableArray("android:views");
        windowState.remove("android:views");
        focusedViewId = windowState.getInt("android:focusedViewId", View.NO_ID);
        windowState.remove("android:focusedViewId");
    }

    super.onRestoreInstanceState(savedInstanceState);

    if (windowState != null) {
        windowState.putSparseParcelableArray("android:views", savedStates);
        windowState.putInt("android:focusedViewId", focusedViewId);
        windowState.remove("android:Panels");
    }

    mSavedInstanceState = savedInstanceState;
}