Java Code Examples for android.os.Bundle#putSparseParcelableArray()

The following examples show how to use android.os.Bundle#putSparseParcelableArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: State.java    From flow with Apache License 2.0 6 votes vote down vote up
Bundle toBundle(KeyParceler parceler) {
  Bundle outState = new Bundle();
  outState.putParcelable(KEY, parceler.toParcelable(getKey()));
  int[] viewIds = new int[viewStateById.size()];
  int c = 0;
  for (Map.Entry<Integer, SparseArray<Parcelable>> entry : viewStateById.entrySet()) {
    Integer viewId = entry.getKey();
    viewIds[c++] = viewId;
    SparseArray<Parcelable> viewState = entry.getValue();
    if (viewState.size() > 0) {
      outState.putSparseParcelableArray(VIEW_STATE_PREFIX + viewId, viewState);
    }
  }
  outState.putIntArray(VIEW_STATE_IDS, viewIds);
  if (bundle != null && !bundle.isEmpty()) {
    outState.putBundle(BUNDLE, bundle);
  }
  return outState;
}
 
Example 2
Source File: MenuBuilder.java    From Libraries-for-Android-Developers with MIT License 6 votes vote down vote up
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>();
            }
            v.saveHierarchyState(viewStates);
            if (item.isActionViewExpanded()) {
                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);
    }
}
 
Example 3
Source File: NavigationMenuPresenter.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@NonNull
public Bundle createInstanceState() {
  Bundle state = new Bundle();
  if (checkedItem != null) {
    state.putInt(STATE_CHECKED_ITEM, checkedItem.getItemId());
  }
  // Store the states of the action views.
  SparseArray<ParcelableSparseArray> actionViewStates = new SparseArray<>();
  for (int i = 0, size = items.size(); i < size; i++) {
    NavigationMenuItem navigationMenuItem = items.get(i);
    if (navigationMenuItem instanceof NavigationMenuTextItem) {
      MenuItemImpl item = ((NavigationMenuTextItem) navigationMenuItem).getMenuItem();
      View actionView = item != null ? item.getActionView() : null;
      if (actionView != null) {
        ParcelableSparseArray container = new ParcelableSparseArray();
        actionView.saveHierarchyState(container);
        actionViewStates.put(item.getItemId(), container);
      }
    }
  }
  state.putSparseParcelableArray(STATE_ACTION_VIEWS, actionViewStates);
  return state;
}
 
Example 4
Source File: MenuBuilder.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
private void dispatchSaveInstanceState(Bundle outState) {
    if (mPresenters.isEmpty()) return;

    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);
}
 
Example 5
Source File: NavigationMenuPresenter.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public Parcelable onSaveInstanceState() {
  final Bundle state = new Bundle();
  if (menuView != null) {
    SparseArray<Parcelable> hierarchy = new SparseArray<>();
    menuView.saveHierarchyState(hierarchy);
    state.putSparseParcelableArray(STATE_HIERARCHY, hierarchy);
  }
  if (adapter != null) {
    state.putBundle(STATE_ADAPTER, adapter.createInstanceState());
  }
  if (headerLayout != null) {
    SparseArray<Parcelable> header = new SparseArray<>();
    headerLayout.saveHierarchyState(header);
    state.putSparseParcelableArray(STATE_HEADER, header);
  }
  return state;
}
 
Example 6
Source File: MenuBuilder.java    From zen4android with MIT License 6 votes vote down vote up
private void dispatchSaveInstanceState(Bundle outState) {
    if (mPresenters.isEmpty()) return;

    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);
}
 
Example 7
Source File: MenuBuilder.java    From android-apps with MIT License 6 votes vote down vote up
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>();
            }
            v.saveHierarchyState(viewStates);
            if (item.isActionViewExpanded()) {
                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);
    }
}
 
Example 8
Source File: ShareUtil.java    From ShareSDK with MIT License 5 votes vote down vote up
/**
 * data is sparsearray
 * @param activity Activity
 * @param channel 渠道
 * @param data data
 * @param requestCode requestCode
 */
public static void showShareDialog(Activity activity, int channel, SparseArray<ShareEntity> data, int requestCode) {
    if (null == activity || activity.isFinishing()) {
        return;
    }
    Intent intent = new Intent(activity, ShareDialogActivity.class);
    Bundle bundle = new Bundle();
    bundle.putSparseParcelableArray(ShareConstant.EXTRA_SHARE_DATA, data);
    intent.putExtra(ShareConstant.EXTRA_SHARE_DATA, bundle);
    intent.putExtra(ShareConstant.EXTRA_SHARE_CHANNEL, channel);
    activity.startActivityForResult(intent, requestCode);
}
 
Example 9
Source File: HeaderView.java    From HeaderView with MIT License 5 votes vote down vote up
@Override
protected Parcelable onSaveInstanceState() {
    Log.d(TAG, "onSaveInstanceState");
    Bundle bundle = new Bundle();
    bundle.putParcelable("superState", super.onSaveInstanceState());
    //STORE CUSTOM VALUES
    bundle.putSparseParcelableArray(PROFILE_LIST, profileSparseArray);
    return bundle;
}
 
Example 10
Source File: AdRecordStore.java    From AndroidBleManager with Apache License 2.0 5 votes vote down vote up
@Override
public void writeToParcel(final Parcel parcel, final int arg1) {
    final Bundle b = new Bundle();
    b.putString("local_name_complete", mLocalNameComplete);
    b.putString("local_name_short", mLocalNameShort);
    b.putSparseParcelableArray("records_array", mAdRecords);

    parcel.writeBundle(b);
}
 
Example 11
Source File: RecyclerPagerAdapter.java    From recycler-pager-adapter with Apache License 2.0 5 votes vote down vote up
@Override
public Parcelable saveState() {
  Bundle bundle = new Bundle();
  for (ViewHolder viewHolder : getAttachedViewHolders()) {
    mSavedStates.put(getItemId(viewHolder.mPosition), viewHolder.onSaveInstanceState());
  }
  bundle.putSparseParcelableArray(STATE, mSavedStates);
  return bundle;
}
 
Example 12
Source File: AdRecordStore.java    From BLE with Apache License 2.0 5 votes vote down vote up
@Override
public void writeToParcel(final Parcel parcel, final int arg1) {
    final Bundle b = new Bundle();
    b.putString(LOCAL_NAME_COMPLETE, mLocalNameComplete);
    b.putString(LOCAL_NAME_SHORT, mLocalNameShort);
    b.putSparseParcelableArray(RECORDS_ARRAY, mAdRecords);
    parcel.writeBundle(b);
}
 
Example 13
Source File: ViewsStateBundle.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
/**
 * @return the saved views states
 */
public final Bundle saveAsBundle() {
    if (mChildStates == null || mChildStates.size() == 0) {
        return null;
    }
    Map<String, SparseArray<Parcelable>> snapshot = mChildStates.snapshot();
    Bundle bundle = new Bundle();
    for (Iterator<Entry<String, SparseArray<Parcelable>>> i =
            snapshot.entrySet().iterator(); i.hasNext(); ) {
        Entry<String, SparseArray<Parcelable>> e = i.next();
        bundle.putSparseParcelableArray(e.getKey(), e.getValue());
    }
    return bundle;
}
 
Example 14
Source File: RecyclerPagerAdapter.java    From recycler-pager-adapter with Apache License 2.0 5 votes vote down vote up
private Parcelable onSaveInstanceState() {
  SparseArray<Parcelable> state = new SparseArray<>();
  itemView.saveHierarchyState(state);
  Bundle bundle = new Bundle();
  bundle.putSparseParcelableArray(STATE, state);
  return bundle;
}
 
Example 15
Source File: RecyclingPagerAdapter.java    From photo-viewer with Apache License 2.0 5 votes vote down vote up
@Override
public Parcelable saveState() {
    Bundle bundle = new Bundle();
    for (ViewHolder viewHolder : getAttachedViewHolders()) {
        mSavedStates.put(getItemId(viewHolder.mPosition), viewHolder.onSaveInstanceState());
    }
    bundle.putSparseParcelableArray(STATE, mSavedStates);
    return bundle;
}
 
Example 16
Source File: BaseScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
    super.onSaveInstanceState(outState);

    if (drawerView != null) {
        drawerViewState = new SparseArray<>();
        drawerView.saveHierarchyState(drawerViewState);
        outState.putSparseParcelableArray(KEY_DRAWER_VIEW_STATE, drawerViewState);
    }
}
 
Example 17
Source File: SwipeOpenItemTouchHelper.java    From SwipeOpenItemTouchHelper with Apache License 2.0 4 votes vote down vote up
public void onSaveInstanceState(Bundle outState) {
  outState.putSparseParcelableArray(OPENED_STATES, openedPositions);
}
 
Example 18
Source File: ContentRecyclerAdapter.java    From ChromeLikeTabSwitcher with Apache License 2.0 4 votes vote down vote up
@Override
public final void saveInstanceState(@NonNull final Bundle outState) {
    outState.putSparseParcelableArray(SAVED_INSTANCE_STATES_EXTRA, savedInstanceStates);
}
 
Example 19
Source File: BackstackFrame.java    From fragnums with Apache License 2.0 4 votes vote down vote up
@Override public void writeToParcel(Parcel dest, int flags) {
  dest.writeInt(screen.ordinal());
  Bundle bundle = new Bundle();
  bundle.putSparseParcelableArray("viewState", viewState);
  dest.writeBundle(bundle);
}
 
Example 20
Source File: MeepoUtils.java    From Meepo with Apache License 2.0 4 votes vote down vote up
public static void putValueToBundle(
        @NonNull Bundle bundle, @NonNull String key, @NonNull Object value) {
    if (value instanceof String) {
        bundle.putString(key, (String) value);
    } else if (value instanceof Integer) {
        bundle.putInt(key, (int) value);
    } else if (value instanceof Boolean) {
        bundle.putBoolean(key, (boolean) value);
    } else if (value instanceof Long) {
        bundle.putLong(key, (long) value);
    } else if (value instanceof Short) {
        bundle.putShort(key, (short) value);
    } else if (value instanceof Double) {
        bundle.putDouble(key, (double) value);
    } else if (value instanceof Float) {
        bundle.putFloat(key, (float) value);
    } else if (value instanceof Character) {
        bundle.putChar(key, (char) value);
    } else if (value instanceof Byte) {
        bundle.putByte(key, (byte) value);
    } else if (value instanceof CharSequence) {
        bundle.putCharSequence(key, (CharSequence) value);
    } else if (value instanceof Bundle) {
        bundle.putBundle(key, (Bundle) value);
    } else if (value instanceof Parcelable) {
        bundle.putParcelable(key, (Parcelable) value);
    } else if (value instanceof String[]) {
        bundle.putStringArray(key, (String[]) value);
    } else if (value instanceof int[]) {
        bundle.putIntArray(key, (int[]) value);
    } else if (value instanceof boolean[]) {
        bundle.putBooleanArray(key, (boolean[]) value);
    } else if (value instanceof long[]) {
        bundle.putLongArray(key, (long[]) value);
    } else if (value instanceof short[]) {
        bundle.putShortArray(key, (short[]) value);
    } else if (value instanceof double[]) {
        bundle.putDoubleArray(key, (double[]) value);
    } else if (value instanceof float[]) {
        bundle.putFloatArray(key, (float[]) value);
    } else if (value instanceof char[]) {
        bundle.putCharArray(key, (char[]) value);
    } else if (value instanceof byte[]) {
        bundle.putByteArray(key, (byte[]) value);
    } else if (value instanceof CharSequence[]) {
        bundle.putCharSequenceArray(key, (CharSequence[]) value);
    } else if (value instanceof Parcelable[]) {
        bundle.putParcelableArray(key, (Parcelable[]) value);
    } else if (value instanceof ArrayList) {
        bundle.putIntegerArrayList(key, (ArrayList<Integer>) value);
    } else if (value instanceof SparseArray) {
        bundle.putSparseParcelableArray(key, (SparseArray<? extends Parcelable>) value);
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            if (value instanceof IBinder) {
                bundle.putBinder(key, (IBinder) value);
                return;
            }
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            if (value instanceof Size) {
                bundle.putSize(key, (Size) value);
                return;
            } else if (value instanceof SizeF) {
                bundle.putSizeF(key, (SizeF) value);
                return;
            }
        }
        if (value instanceof Serializable) {
            bundle.putSerializable(key, (Serializable) value);
            return;
        }

        throw new RuntimeException(String.format(Locale.getDefault(),
                "Arguments extra %s has wrong type %s.", key, value.getClass().getName()));
    }
}