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

The following examples show how to use android.os.Bundle#getSparseParcelableArray() . These examples are extracted from open source projects. 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 Project: android-apps   File: MenuBuilder.java    License: MIT License 6 votes vote down vote up
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
Source Project: MHViewer   File: BaseScene.java    License: Apache License 2.0 6 votes vote down vote up
public final View createDrawerView(LayoutInflater inflater,
                                   @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    drawerView = onCreateDrawerView(inflater, container, savedInstanceState);

    if (drawerView != null) {
        SparseArray<Parcelable> saved = drawerViewState;
        if (saved == null && savedInstanceState != null) {
            saved = savedInstanceState.getSparseParcelableArray(KEY_DRAWER_VIEW_STATE);
        }
        if (saved != null) {
            drawerView.restoreHierarchyState(saved);
        }
    }

    return drawerView;
}
 
Example 3
Source Project: zhangshangwuda   File: MenuBuilder.java    License: Apache License 2.0 6 votes vote down vote up
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 4
Source Project: HeaderView   File: HeaderView.java    License: MIT License 6 votes vote down vote up
@Override
protected void onRestoreInstanceState(Parcelable state) {
    Log.d(TAG, "onRestoreInstanceState");
    if (state instanceof Bundle) {
        Bundle bundle = (Bundle) state;
        state = bundle.getParcelable("superState");
        //RESTORE CUSTOM VALUES
        profileSparseArray = bundle.getSparseParcelableArray(PROFILE_LIST) == null ? new SparseArray<>() : bundle.getSparseParcelableArray(PROFILE_LIST);
        populateAvatar();
    }
    if (hvFragmentManager != null) {
        ProfileChooserFragment profileChooserFragment = (ProfileChooserFragment) hvFragmentManager.findFragmentByTag(ProfileChooserFragment.FRAGMENT_TAG);
        if (profileChooserFragment != null) {
            profileChooserFragment.setCallback(HeaderView.this);
            profileChooserFragment.updateTypeface(typeface);
        }
    }
    super.onRestoreInstanceState(state);
}
 
Example 5
/**
 * Retrieves the instance of {@link CustomTabColorSchemeParams} from an Intent for a given
 * color scheme. Uses values passed directly into {@link CustomTabsIntent.Builder} (e.g. via
 * {@link Builder#setToolbarColor}) as defaults.
 *
 * @param intent Intent to retrieve the color scheme parameters from.
 * @param colorScheme A constant representing a color scheme. Should not be
 *                    {@link #COLOR_SCHEME_SYSTEM}.
 * @return An instance of {@link CustomTabColorSchemeParams} with retrieved parameters.
 */
@NonNull
public static CustomTabColorSchemeParams getColorSchemeParams(@NonNull Intent intent,
        @ColorScheme int colorScheme) {
    if (colorScheme < 0 || colorScheme > COLOR_SCHEME_MAX
            || colorScheme == COLOR_SCHEME_SYSTEM) {
        throw new IllegalArgumentException("Invalid colorScheme: " + colorScheme);
    }

    Bundle extras = intent.getExtras();
    if (extras == null) {
        return CustomTabColorSchemeParams.fromBundle(null);
    }

    CustomTabColorSchemeParams defaults = CustomTabColorSchemeParams.fromBundle(extras);
    SparseArray<Bundle> paramBundles = extras.getSparseParcelableArray(
            EXTRA_COLOR_SCHEME_PARAMS);
    if (paramBundles != null) {
        Bundle bundleForScheme = paramBundles.get(colorScheme);
        if (bundleForScheme != null) {
            return CustomTabColorSchemeParams.fromBundle(bundleForScheme)
                    .withDefaults(defaults);
        }
    }
    return defaults;
}
 
Example 6
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 7
Source Project: EhViewer   File: BaseScene.java    License: Apache License 2.0 6 votes vote down vote up
public final View createDrawerView(LayoutInflater inflater,
    @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    drawerView = onCreateDrawerView(inflater, container, savedInstanceState);

    if (drawerView != null) {
        SparseArray<Parcelable> saved = drawerViewState;
        if (saved == null && savedInstanceState != null) {
            saved = savedInstanceState.getSparseParcelableArray(KEY_DRAWER_VIEW_STATE);
        }
        if (saved != null) {
            drawerView.restoreHierarchyState(saved);
        }
    }

    return drawerView;
}
 
Example 8
@Override
public void onRestoreInstanceState(final Parcelable parcelable) {
  if (parcelable instanceof Bundle) {
    Bundle state = (Bundle) parcelable;
    SparseArray<Parcelable> hierarchy = state.getSparseParcelableArray(STATE_HIERARCHY);
    if (hierarchy != null) {
      menuView.restoreHierarchyState(hierarchy);
    }
    Bundle adapterState = state.getBundle(STATE_ADAPTER);
    if (adapterState != null) {
      adapter.restoreInstanceState(adapterState);
    }
    SparseArray<Parcelable> header = state.getSparseParcelableArray(STATE_HEADER);
    if (header != null) {
      headerLayout.restoreHierarchyState(header);
    }
  }
}
 
Example 9
@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 10
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 11
@Override
public final void restoreInstanceState(@Nullable final Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        savedInstanceStates =
                savedInstanceState.getSparseParcelableArray(SAVED_INSTANCE_STATES_EXTRA);
    }
}
 
Example 12
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 13
Source Project: flowless   File: State.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
static State fromBundle(@NonNull Bundle savedState, @NonNull KeyParceler parceler) {
    Object key = parceler.toKey(savedState.getParcelable("KEY"));
    State state = new State(key);
    state.viewState = savedState.getSparseParcelableArray("VIEW_STATE");
    state.bundle = savedState.getBundle("BUNDLE");
    return state;
}
 
Example 14
Source Project: zhangshangwuda   File: MenuBuilder.java    License: Apache License 2.0 5 votes vote down vote up
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 15
Source Project: Mortar-architect   File: History.java    License: MIT License 5 votes vote down vote up
private static Entry fromBundle(Bundle bundle, StackableParceler parceler) {
    StackablePath path = parceler.unwrap(bundle.getParcelable(PATH_KEY));

    // new entry with new scope instance, but preserving previous scope name
    Entry entry = new Entry(bundle.getString(SCOPE_KEY), path, bundle.getInt(NAV_TYPE_KEY));
    entry.state = bundle.getSparseParcelableArray(STATE_KEY);
    return entry;
}
 
Example 16
Source Project: flow   File: State.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull static State fromBundle(@NonNull Bundle savedState, @NonNull KeyParceler parceler) {
  Object key = parceler.toKey(savedState.getParcelable(KEY));
  State state = new State(key);
  int[] viewIds = checkNotNull(savedState.getIntArray(VIEW_STATE_IDS), "Null view state ids?");
  for (int viewId : viewIds) {
    SparseArray<Parcelable> viewState =
        savedState.getSparseParcelableArray(VIEW_STATE_PREFIX + viewId);
    if (viewState != null) {
      state.viewStateById.put(viewId, viewState);
    }
  }
  state.bundle = savedState.getBundle(BUNDLE);
  return state;
}
 
Example 17
private 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 18
Source Project: magellan   File: Screen.java    License: Apache License 2.0 4 votes vote down vote up
final void restore(Bundle savedInstanceState) {
  if (viewState == null && savedInstanceState != null) {
    viewState = savedInstanceState.getSparseParcelableArray(VIEW_STATE + hashCode());
  }
}
 
Example 19
Source Project: fragnums   File: BackstackFrame.java    License: Apache License 2.0 4 votes vote down vote up
@Override public BackstackFrame createFromParcel(Parcel source) {
  Screen screen = Screen.values()[source.readInt()];
  Bundle bundle = source.readBundle();
  SparseArray<Parcelable> viewState = bundle.getSparseParcelableArray("viewState");
  return new BackstackFrame(screen, viewState);
}
 
Example 20
public void restoreInstanceState(Bundle savedInstanceState) {
  openedPositions = savedInstanceState.getSparseParcelableArray(OPENED_STATES);
  if (openedPositions == null) {
    openedPositions = new SparseArray<>();
  }
}