Example usage for android.os Bundle getParcelableArray

List of usage examples for android.os Bundle getParcelableArray

Introduction

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

Prototype

@Nullable
public Parcelable[] getParcelableArray(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:Main.java

public static Bundle[] getBundleArrayFromBundle(Bundle bundle, String key) {
    Parcelable[] array = bundle.getParcelableArray(key);
    if ((array instanceof Bundle[]) || array == null) {
        return (Bundle[]) array;
    }// w w w  .j  a va 2  s.  c  o m
    Bundle[] typedArray = (Bundle[]) Arrays.copyOf(array, array.length, Bundle[].class);
    bundle.putParcelableArray(key, typedArray);
    return typedArray;
}

From source file:Main.java

/**
 * This method extracts a {@link Parcelable} array from the {@link Bundle},
 * and returns it in an array whose type is the exact {@link Parcelable}
 * subclass. This is needed because {@link Bundle#getParcelable(String)}
 * returns an array of {@link Parcelable}, and we would get
 * {@link ClassCastException} when we assign it to {@link Parcelable}
 * subclass arrays./* w ww  .  j a v  a2s.  com*/
 * 
 * For more info, see <a
 * href="https://github.com/excilys/androidannotations/issues/1208">this</a>
 * url.
 * 
 * @param bundle
 *            the bundle holding the array which is extracted
 * @param key
 *            the array is associated with this key
 * @param type
 *            the desired type of the returned array
 * @param <T>
 *            the element type of the returned array
 * @return a {@link Parcelable} subclass typed array which holds the objects
 *         from {@link Bundle#getParcelableArray(String)} or
 *         <code>null</code> if {@link Bundle#getParcelableArray(String)}
 *         returned <code>null</code> for the key
 */
@SuppressWarnings("unchecked")
public static <T extends Parcelable> T[] getParcelableArray(Bundle bundle, String key, Class<T[]> type) {
    Parcelable[] value = bundle.getParcelableArray(key);
    if (value == null) {
        return null;
    }
    Object copy = Array.newInstance(type.getComponentType(), value.length);
    System.arraycopy(value, 0, copy, 0, value.length);
    return (T[]) copy;
}

From source file:io.v.android.apps.syncslides.QuestionDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle args = getArguments();
    final Question[] questions = (Question[]) args.getParcelableArray(QUESTIONER_LIST_KEY);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    String[] questioners = new String[questions.length];
    for (int i = 0; i < questions.length; i++) {
        questioners[i] = questions[i].getName();
    }/*from  ww w  . j  ava2  s. co  m*/
    builder.setTitle(R.string.question_message).setItems(questioners, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            sendResult(questions[which].getId());
        }
    });
    return builder.create();
}

From source file:com.arrata.user.cameratest.AspectRatioFragment.java

@NonNull
@Override/*from w w w .java 2s.co m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Bundle args = getArguments();
    final AspectRatio[] ratios = (AspectRatio[]) args.getParcelableArray(ARG_ASPECT_RATIOS);
    if (ratios == null) {
        throw new RuntimeException("No ratios");
    }
    final AspectRatio current = args.getParcelable(ARG_CURRENT_ASPECT_RATIO);
    final AspectRatioAdapter adapter = new AspectRatioAdapter(ratios, current);
    return new AlertDialog.Builder(getActivity()).setAdapter(adapter, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int position) {
            mListener.onAspectRatioSelected(ratios[position]);
        }
    }).create();
}

From source file:de.vanita5.twittnuker.fragment.support.DeleteUserListMembersDialogFragment.java

private ParcelableUser[] getUsers() {
    final Bundle args = getArguments();
    if (!args.containsKey(EXTRA_USERS))
        return null;
    final Parcelable[] array = args.getParcelableArray(EXTRA_USERS);
    if (array == null)
        return null;
    final ParcelableUser[] users = new ParcelableUser[array.length];
    for (int i = 0, j = users.length; i < j; i++) {
        users[i] = (ParcelableUser) array[i];
    }//w w w  . j  av  a  2 s. co m
    return users;
}

From source file:nz.ac.otago.psyanlab.common.designer.EditorSectionManager.java

public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        // Store fragment saved states.
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);/*ww  w  . j a va  2  s  .c om*/
        Parcelable[] fragmentSavedStates = bundle.getParcelableArray("states");
        int[] stateKeys = bundle.getIntArray("state_keys");
        mSavedState.clear();
        if (fragmentSavedStates != null) {
            for (int i = 0; i < fragmentSavedStates.length; i++) {
                mSavedState.put(stateKeys[i], (Fragment.SavedState) fragmentSavedStates[i]);
            }
        }

        mCurrentPosition = bundle.getInt("current_position");
    }
}

From source file:com.andorn.powertask.adapters.CustomFragmentStatePagerAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);/*from w w w .  ja va2  s  .c o m*/
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i = 0; i < fss.length; i++) {
                mSavedState.add((Fragment.SavedState) fss[i]);
            }
        }
        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) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}

From source file:jahirfiquitiva.iconshowcase.fragments.base.FragmentStatePagerAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);//  w w  w.ja v a 2s.c  o m
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (Parcelable fs : fss) {
                mSavedState.add((Fragment.SavedState) fs);
            }
        }
        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) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                }
            }
        }
    }
}

From source file:com.example.study.studyproject.adapter.FragmentStatePagerAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);/* w  w w  .ja v a 2 s . co  m*/
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i = 0; i < fss.length; i++) {
                mSavedState.add((Fragment.SavedState) fss[i]);
            }
        }
        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) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {

                }
            }
        }
    }
}

From source file:com.liu.Account.view.emojicon.EmojiconGridFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    GridView gridView = (GridView) view.findViewById(R.id.Emoji_GridView);
    Bundle bundle = getArguments();
    if (bundle == null) {
        mData = People.DATA;/*from   w w  w.  j  ava 2  s .co  m*/
        mUseSystemDefault = false;
    } else {
        Parcelable[] parcels = bundle.getParcelableArray(EMOJICONS_KEY);
        mData = new Emojicon[parcels.length];
        for (int i = 0; i < parcels.length; i++) {
            mData[i] = (Emojicon) parcels[i];
        }
        mUseSystemDefault = bundle.getBoolean(USE_SYSTEM_DEFAULT_KEY);
    }
    gridView.setAdapter(new EmojiAdapter(view.getContext(), mData, mUseSystemDefault));
    gridView.setOnItemClickListener(this);
}