Ejemplo n.º 1
0
  public void store(Context context, Bundle outState) {
    synchronized (this) {
      List<State> list = mSaveStates.get(context);
      if (list == null) return;

      for (State state : list) {
        Class<?> type = state.field.getType();
        Dispatcher dispatcher;
        if (Parcelable.class.isAssignableFrom(type))
          dispatcher = sDispatchers.get(Parcelable.class);
        else if (Parcelable[].class.isAssignableFrom(type))
          dispatcher = sDispatchers.get(Parcelable[].class);
        else if (Serializable.class.isAssignableFrom(type))
          dispatcher = sDispatchers.get(Serializable.class);
        else if (SparseArray.class.isAssignableFrom(type))
          dispatcher = sDispatchers.get(SparseArray.class);
        else dispatcher = sDispatchers.get(type);

        if (dispatcher == null) throw new ProvisionException("Unsupported type: " + type.getName());

        Object value = InjectorUtils.getField(state.receiver, state.field);
        dispatcher.dispatch(outState, key(state.receiver, state.field), value);
      }
    }
  }
Ejemplo n.º 2
0
  private void restore(Context context, Object receiver, Field field) {
    Bundle bundle = mSavedStateBundles.get(context);
    if (bundle == null) return;

    Object value = bundle.get(key(receiver, field));
    if (value == null) return;

    InjectorUtils.setField(receiver, field, value);
  }
Ejemplo n.º 3
0
  public void registerSavedStateBundle(Context context, Bundle bundle) {
    synchronized (this) {
      mSavedStateBundles.put(context, bundle);
      List<State> list = mSaveStates.get(context);
      if (list == null) return;

      for (State state : list) {
        Object value = bundle.get(key(state.receiver, state.field));
        if (value == null && state.field.getType().isPrimitive()) continue;

        InjectorUtils.setField(state.receiver, state.field, value);
      }
    }
  }