Java Code Examples for android.os.Bundle.getSparseParcelableArray()

The following are Jave code examples for showing how to use getSparseParcelableArray() of the android.os.Bundle class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: CSipSimple   File: MenuBuilder.java   View Source Code Vote up 7 votes
private void dispatchRestoreInstanceState(Bundle state) {
    SparseArray<Parcelable> presenterStates = state.getSparseParcelableArray(PRESENTER_KEY);

    if (presenterStates == null || mPresenters.isEmpty()) return;

    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) {
                Parcelable parcel = presenterStates.get(id);
                if (parcel != null) {
                    presenter.onRestoreInstanceState(parcel);
                }
            }
        }
    }
}
 
Example 2
Project: bananapeel   File: TabAdapter.java   View Source Code Vote up 7 votes
@Override
public void restoreState(Parcelable state, ClassLoader loader)
{
	if(state != null)
	{
		Bundle bundle = (Bundle)state;
		bundle.setClassLoader(loader);
		SparseArray fss = bundle.getSparseParcelableArray("states");
		for(TabFragment fragment : tabFragments)
		{
			if(curTransaction == null)
				curTransaction = fragmentManager.beginTransaction();
			curTransaction.remove(fragment);
		}
		savedStates.clear();
		tabFragments.clear();
		if(fss != null)
		{
			for(int i = 0; i < fss.size(); i++)
				savedStates.put(fss.keyAt(i), (Fragment.SavedState)fss.valueAt(i));
		}
	}
}
 
Example 3
Project: PicShow-zhaipin   File: FragmentListPageAdapter.java   View Source Code Vote up 7 votes
@Override
    public void restoreState(Parcelable state, ClassLoader loader) {
        if (state != null) {
            Bundle bundle = (Bundle) state;
            bundle.setClassLoader(loader);
            mSavedState.clear();
            mFragments.clear();
            if (bundle.containsKey("states")) {
                mSavedState = bundle.getSparseParcelableArray("states");
            }
            Iterable<String> keys = bundle.keySet();
            for (String key : keys) {
                if (key.startsWith("f")) {
                    int index = Integer.parseInt(key.substring(1));
                    Fragment f = mFragmentManager.getFragment(bundle, key);
                    if (f != null) {
                        f.setMenuVisibility(false);
                        mFragments.put(index, f);
                    } else {
//						Log.w(TAG, "Bad fragment at key " + key);
                    }
                }
            }
        }
    }
 
Example 4
Project: boohee_v5.6   File: MenuBuilder.java   View Source Code Vote up 7 votes
private void dispatchRestoreInstanceState(Bundle state) {
    SparseArray<Parcelable> presenterStates = state.getSparseParcelableArray(PRESENTER_KEY);
    if (presenterStates != null && !this.mPresenters.isEmpty()) {
        Iterator i$ = this.mPresenters.iterator();
        while (i$.hasNext()) {
            WeakReference<MenuPresenter> ref = (WeakReference) i$.next();
            MenuPresenter presenter = (MenuPresenter) ref.get();
            if (presenter == null) {
                this.mPresenters.remove(ref);
            } else {
                int id = presenter.getId();
                if (id > 0) {
                    Parcelable parcel = (Parcelable) presenterStates.get(id);
                    if (parcel != null) {
                        presenter.onRestoreInstanceState(parcel);
                    }
                }
            }
        }
    }
}
 
Example 5
Project: boohee_v5.6   File: MenuBuilder.java   View Source Code Vote up 7 votes
public void restoreActionViewStates(Bundle states) {
    if (states != null) {
        SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(getActionViewStatesKey());
        int itemCount = size();
        for (int i = 0; i < itemCount; i++) {
            MenuItem item = getItem(i);
            View v = MenuItemCompat.getActionView(item);
            if (!(v == null || v.getId() == -1)) {
                v.restoreHierarchyState(viewStates);
            }
            if (item.hasSubMenu()) {
                ((SubMenuBuilder) item.getSubMenu()).restoreActionViewStates(states);
            }
        }
        int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID);
        if (expandedId > 0) {
            MenuItem itemToExpand = findItem(expandedId);
            if (itemToExpand != null) {
                MenuItemCompat.expandActionView(itemToExpand);
            }
        }
    }
}
 
Example 6
Project: CSipSimple   File: MenuBuilder.java   View Source Code Vote up 6 votes
public void restoreActionViewStates(Bundle states) {
    if (states == null) {
        return;
    }

    SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(
            getActionViewStatesKey());

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && viewStates == null) {
        //Fixes Issue #652 with sdk <= 2.3.6
        return;
    }

    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) {
            v.restoreHierarchyState(viewStates);
        }
        if (item.hasSubMenu()) {
            final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
            subMenu.restoreActionViewStates(states);
        }
    }

    final int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID);
    if (expandedId > 0) {
        MenuItem itemToExpand = findItem(expandedId);
        if (itemToExpand != null) {
            itemToExpand.expandActionView();
        }
    }
}
 
Example 7
Project: NeoTerm   File: ChildRecyclerAdapter.java   View Source Code Vote up 6 votes
@Override
public final void restoreInstanceState(@Nullable final Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        savedInstanceStates =
                savedInstanceState.getSparseParcelableArray(SAVED_INSTANCE_STATES_EXTRA);
    }
}
 
Example 8
Project: ChromeLikeTabSwitcher   File: ContentRecyclerAdapter.java   View Source Code Vote up 6 votes
@Override
public final void restoreInstanceState(@Nullable final Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        savedInstanceStates =
                savedInstanceState.getSparseParcelableArray(SAVED_INSTANCE_STATES_EXTRA);
    }
}
 
Example 9
Project: boohee_v5.6   File: NavigationMenuPresenter.java   View Source Code Vote up 6 votes
public void restoreInstanceState(Bundle state) {
    Iterator i$;
    int checkedItem = state.getInt(STATE_CHECKED_ITEM, 0);
    if (checkedItem != 0) {
        this.mUpdateSuspended = true;
        i$ = this.mItems.iterator();
        while (i$.hasNext()) {
            NavigationMenuItem item = (NavigationMenuItem) i$.next();
            if (item instanceof NavigationMenuTextItem) {
                MenuItemImpl menuItem = ((NavigationMenuTextItem) item).getMenuItem();
                if (menuItem != null && menuItem.getItemId() == checkedItem) {
                    setCheckedItem(menuItem);
                    break;
                }
            }
        }
        this.mUpdateSuspended = false;
        prepareMenuItems();
    }
    SparseArray<ParcelableSparseArray> actionViewStates = state.getSparseParcelableArray(STATE_ACTION_VIEWS);
    i$ = this.mItems.iterator();
    while (i$.hasNext()) {
        NavigationMenuItem navigationMenuItem = (NavigationMenuItem) i$.next();
        if (navigationMenuItem instanceof NavigationMenuTextItem) {
            MenuItemImpl item2 = ((NavigationMenuTextItem) navigationMenuItem).getMenuItem();
            View actionView = item2 != null ? item2.getActionView() : null;
            if (actionView != null) {
                actionView.restoreHierarchyState((SparseArray) actionViewStates.get(item2.getItemId()));
            }
        }
    }
}
 
Example 10
Project: boohee_v5.6   File: NavigationMenuPresenter.java   View Source Code Vote up 6 votes
public void onRestoreInstanceState(Parcelable parcelable) {
    Bundle state = (Bundle) parcelable;
    SparseArray<Parcelable> hierarchy = state.getSparseParcelableArray("android:menu:list");
    if (hierarchy != null) {
        this.mMenuView.restoreHierarchyState(hierarchy);
    }
    Bundle adapterState = state.getBundle(STATE_ADAPTER);
    if (adapterState != null) {
        this.mAdapter.restoreInstanceState(adapterState);
    }
}
 
Example 11
Project: auto-value-bundle   File: AutoValue_TestClassBundled.java   View Source Code Vote up 6 votes
public static TestClassBundled unbundle(Bundle bundle, Gson gson) {
    return new AutoValue_TestClassBundled(
            bundle,
            bundle.getByte("some_byte"),
            bundle.getBoolean("some_boolean"),
            bundle.getShort("some_short"),
            bundle.getInt("some_int"),
            bundle.getLong("some_long"),
            bundle.getChar("some_char"),
            bundle.getFloat("some_float"),
            bundle.getDouble("some_double"),
            bundle.getString("some_string"),
            bundle.getCharSequence("some_char_sequence"),
            bundle.getParcelable("some_parcelable"),
            bundle.getParcelableArrayList("some_parcelable_array_list"),
            bundle.getSparseParcelableArray("some_parcelable_sparse_array"),
            bundle.getSerializable("some_serializable"),
            bundle.getIntegerArrayList("some_integer_array_list"),
            bundle.getStringArrayList("some_string_array_list"),
            bundle.getCharSequenceArrayList("some_char_sequence_array_list"),
            bundle.getByteArray("some_byte_array"),
            bundle.getShortArray("some_short_array"),
            bundle.getCharArray("some_char_array"),
            bundle.getFloatArray("some_float_array"),
            gson.fromJson(bundle.getString("some_unknown_object"), new com.google.common.reflect.TypeToken<UnknownObject>(){}.getType()),
            gson.fromJson(bundle.getString("some_unknown_object_list"), new com.google.common.reflect.TypeToken<ArrayList<UnknownObject>>(){}.getType()),
            gson.fromJson(bundle.getString("test_enum"), new com.google.common.reflect.TypeToken<TestEnum>(){}.getType()));
}
 
Example 12
Project: imageviewer   File: ViewHolder.java   View Source Code Vote up 6 votes
void onRestoreInstanceState(Parcelable state) {
    if (state instanceof Bundle) {
        Bundle bundle = (Bundle) state;
        SparseArray<Parcelable> ss = bundle.containsKey(STATE) ? bundle.getSparseParcelableArray(STATE) : null;
        if (ss != null) {
            itemView.restoreHierarchyState(ss);
        }
    }
}
 
Example 13
Project: imageviewer   File: RecyclingPagerAdapter.java   View Source Code Vote up 6 votes
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state instanceof Bundle) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        SparseArray<Parcelable> ss = bundle.containsKey(STATE) ? bundle.getSparseParcelableArray(STATE) : null;
        mSavedStates = ss != null ? ss : new SparseArray<Parcelable>();
    }
    super.restoreState(state, loader);
}
 
Example 14
Project: GitHub   File: Injector.java   View Source Code Vote up 5 votes
public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(Bundle state, String key) {
    return state.getSparseParcelableArray(key + baseKey);
}
 
Example 15
Project: android-state   File: InjectionHelper.java   View Source Code Vote up 5 votes
public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(Bundle state, String key) {
    return state.getSparseParcelableArray(key + mBaseKey);
}
 
Example 16
Project: AndroidMuseumBleManager   File: AdRecordStore.java   View Source Code Vote up 5 votes
public AdRecordStore(final Parcel in) {
    final Bundle b = in.readBundle(getClass().getClassLoader());
    mAdRecords = b.getSparseParcelableArray("records_array");
    mLocalNameComplete = b.getString("local_name_complete");
    mLocalNameShort = b.getString("local_name_short");
}
 
Example 17
Project: ChromeLikeTabSwitcher   File: TabSwitcherDecorator.java   View Source Code Vote up 5 votes
/**
 * The method, which is invoked by a {@link TabSwitcher} to apply the decorator. It initializes
 * the view holder pattern, which is provided by the decorator and then delegates the method
 * call to the decorator's custom implementation of the method <code>onShowTab(...):void</code>.
 *
 * @param context
 *         The context, the tab switcher belongs to, as an instance of the class {@link
 *         Context}. The context may not be null
 * @param tabSwitcher
 *         The tab switcher, whose tabs are visualized by the decorator, as an instance of the
 *         class {@link TabSwitcher}. The tab switcher may not be null
 * @param view
 *         The view, which is used to visualize the tab, as an instance of the class {@link
 *         View}. The view may not be null
 * @param tab
 *         The tab, which should be visualized, as an instance of the class {@link Tab}. The tab
 *         may not be null
 * @param index
 *         The index of the tab, which should be visualized, as an {@link Integer} value
 * @param savedInstanceState
 *         The bundle, which has previously been used to save the state of the view as an
 *         instance of the class {@link Bundle} or null, if no saved state is available
 */
public final void applyDecorator(@NonNull final Context context,
                                 @NonNull final TabSwitcher tabSwitcher,
                                 @NonNull final View view, @NonNull final Tab tab,
                                 final int index, @Nullable final Bundle savedInstanceState) {
    setCurrentParentView(view);
    int viewType = getViewType(tab, index);

    if (savedInstanceState != null) {
        SparseArray<Parcelable> viewStates =
                savedInstanceState.getSparseParcelableArray(VIEW_HIERARCHY_STATE_EXTRA);

        if (viewStates != null) {
            view.restoreHierarchyState(viewStates);
        }
    }

    onShowTab(context, tabSwitcher, view, tab, index, viewType, savedInstanceState);
}
 
Example 18
Project: magellan   File: Screen.java   View Source Code Vote up 5 votes
final void restore(Bundle savedInstanceState) {
  if (viewState == null && savedInstanceState != null) {
    viewState = savedInstanceState.getSparseParcelableArray(VIEW_STATE + hashCode());
  }
}
 
Example 19
Project: boohee_v5.6   File: ListMenuPresenter.java   View Source Code Vote up 5 votes
public void restoreHierarchyState(Bundle inState) {
    SparseArray<Parcelable> viewStates = inState.getSparseParcelableArray(VIEWS_TAG);
    if (viewStates != null) {
        this.mMenuView.restoreHierarchyState(viewStates);
    }
}
 
Example 20
Project: NeoTerm   File: TabSwitcherDecorator.java   View Source Code Vote up 5 votes
/**
 * The method, which is invoked by a {@link TabSwitcher} to apply the decorator. It initializes
 * the view holder pattern, which is provided by the decorator and then delegates the method
 * call to the decorator's custom implementation of the method <code>onShowTab(...):void</code>.
 *
 * @param context
 *         The context, the tab switcher belongs to, as an instance of the class {@link
 *         Context}. The context may not be null
 * @param tabSwitcher
 *         The tab switcher, whose tabs are visualized by the decorator, as an instance of the
 *         class {@link TabSwitcher}. The tab switcher may not be null
 * @param view
 *         The view, which is used to visualize the tab, as an instance of the class {@link
 *         View}. The view may not be null
 * @param tab
 *         The tab, which should be visualized, as an instance of the class {@link Tab}. The tab
 *         may not be null
 * @param index
 *         The index of the tab, which should be visualized, as an {@link Integer} value
 * @param savedInstanceState
 *         The bundle, which has previously been used to save the state of the view as an
 *         instance of the class {@link Bundle} or null, if no saved state is available
 */
public final void applyDecorator(@NonNull final Context context,
                                 @NonNull final TabSwitcher tabSwitcher,
                                 @NonNull final View view, @NonNull final Tab tab,
                                 final int index, @Nullable final Bundle savedInstanceState) {
    setCurrentParentView(view);
    int viewType = getViewType(tab, index);

    if (savedInstanceState != null) {
        SparseArray<Parcelable> viewStates =
                savedInstanceState.getSparseParcelableArray(VIEW_HIERARCHY_STATE_EXTRA);

        if (viewStates != null) {
            view.restoreHierarchyState(viewStates);
        }
    }

    onShowTab(context, tabSwitcher, view, tab, index, viewType, savedInstanceState);
}