Example usage for android.os Bundle getParcelableArrayList

List of usage examples for android.os Bundle getParcelableArrayList

Introduction

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

Prototype

@Nullable
public <T extends Parcelable> ArrayList<T> getParcelableArrayList(@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:com.example.alvarpao.popularmovies.MovieGridFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    // Add the below line in order for this fragment to display and handle menu options.
    setHasOptionsMenu(true);/*from w w w .java 2s  . c o m*/

    if (savedInstanceState != null) {
        //State needs to be restored for this activity, a rotation occurred
        if (savedInstanceState.containsKey(LOADED_MOVIES))
            mMovies = savedInstanceState.getParcelableArrayList(LOADED_MOVIES);
        if (savedInstanceState.containsKey(PAGE_TO_FETCH))
            mPageToFetch = savedInstanceState.getInt(PAGE_TO_FETCH);
        if (savedInstanceState.containsKey(LOADED_PREVIOUS_ITEMS))
            mPreviousTotalItems = savedInstanceState.getInt(LOADED_PREVIOUS_ITEMS);
        if (savedInstanceState.containsKey(SELECTION_OCCURRED))
            mSelectionOccurred = savedInstanceState.getBoolean(SELECTION_OCCURRED);
        if (savedInstanceState.containsKey(CURRENT_SCROLL_POSITION))
            mCurrentScrollPosition = savedInstanceState.getInt(CURRENT_SCROLL_POSITION);
    }

    else
        mMovies = new ArrayList<Movie>();
}

From source file:com.bmd.android.collection.SparseArrayCompatTest.java

public void testParcelable() {

    final ParcelableIntSparseObjectEntry[] parcelableArray = AndroidCollections.iterate(mArray).only()
            .values("4", "1").toParcelableArray(ParcelableIntSparseObjectEntry.class);

    assertThat(parcelableArray).hasSize(2);
    assertThat(parcelableArray[0].getKey()).isEqualTo(1);
    assertThat(parcelableArray[0].getValue()).isEqualTo("1");
    assertThat(parcelableArray[1].getKey()).isEqualTo(4);
    assertThat(parcelableArray[1].getValue()).isEqualTo("4");

    final ArrayList<ParcelableIntSparseObjectEntry<String>> parcelableList = AndroidCollections.iterate(mArray)
            .but().keys(Arrays.asList(1, 2, 3)).reverse().toParcelableList();

    assertThat(parcelableList).hasSize(2);
    assertThat(parcelableList.get(0).getKey()).isEqualTo(4);
    assertThat(parcelableList.get(0).getValue()).isEqualTo("4");
    assertThat(parcelableList.get(1).getKey()).isEqualTo(0);
    assertThat(parcelableList.get(1).getValue()).isEqualTo("0");
    assertThat(parcelableList).containsExactly(SparseEntries.parcelableEntry(4, "4"),
            SparseEntries.parcelableEntry(0, "0"));

    final Bundle bundle = new Bundle();
    bundle.putParcelableArray("array", parcelableArray);
    bundle.putParcelableArrayList("list", parcelableList);

    final Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);/*  www.j  a  v  a 2 s .  c  o m*/

    parcel.setDataPosition(0);

    final Bundle out = parcel.readBundle();
    out.setClassLoader(AndroidCollections.class.getClassLoader());

    assertThat(out.getParcelableArray("array")).isEqualTo(parcelableArray);
    assertThat(out.getParcelableArrayList("list")).isEqualTo(new ArrayList<Parcelable>(parcelableList));

    final ArrayList<ParcelableIntSparseObjectEntry<String>> filledList = new ArrayList<ParcelableIntSparseObjectEntry<String>>(
            2);

    AndroidCollections.iterate(mArray).but().keys(1, 2, 3).reverse().fillParcelable(filledList);

    assertThat(filledList).isEqualTo(parcelableList);

    final ParcelableIntSparseObjectEntry[] filledArray = new ParcelableIntSparseObjectEntry[2];

    AndroidCollections.iterate(mArray).only().value("2").fillParcelable(filledArray);

    assertThat(filledArray[0]).isEqualTo(SparseEntries.parcelableEntry(2, "2"));

    AndroidCollections.iterate(mArray).only().value("2").fillParcelable(filledArray, 1);

    assertThat(filledArray[0]).isEqualTo(SparseEntries.parcelableEntry(2, "2"));
    assertThat(filledArray[0]).isEqualTo(filledArray[1]);

    try {

        AndroidCollections.iterate(mArray).fillParcelable(filledArray);

        fail();

    } catch (final IndexOutOfBoundsException e) {

    }

    final Parcelable[] parcelables = new Parcelable[2];

    AndroidCollections.iterate(mArray).only().to(1).fillParcelable(parcelables);

    assertThat(parcelables).containsExactly(filledArray);
}

From source file:ca.spencerelliott.mercury.Changesets.java

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    this.requestWindowFeature(Window.FEATURE_PROGRESS);
    this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setContentView(R.layout.changesets);

    //Cancel any notifications previously setup
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(1);/*from w  w  w .  j  a va 2  s  .  co  m*/

    //Create a new array list for the changesets
    changesets_list = new ArrayList<Map<String, ?>>();
    changesets_data = new ArrayList<Beans.ChangesetBean>();

    //Get the list view to store the changesets
    changesets_listview = (ListView) findViewById(R.id.changesets_list);

    TextView empty_text = (TextView) findViewById(R.id.changesets_empty_text);

    //Set the empty view
    changesets_listview.setEmptyView(empty_text);

    //Use a simple adapter to display the changesets based on the array list made earlier
    changesets_listview.setAdapter(new SimpleAdapter(this, changesets_list, R.layout.changeset_item,
            new String[] { COMMIT, FORMATTED_INFO },
            new int[] { R.id.changesets_commit, R.id.changesets_info }));

    //Set the on click listener
    changesets_listview.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {
            Intent intent = new Intent(Changesets.this, ChangesetViewer.class);

            //Pass the changeset information to the changeset viewer
            Bundle params = new Bundle();
            params.putString("changeset_commit_text", changesets_data.get(position).getTitle());
            params.putString("changeset_changes", changesets_data.get(position).getContent());
            params.putLong("changeset_updated", changesets_data.get(position).getUpdated());
            params.putString("changeset_authors", changesets_data.get(position).getAuthor());
            params.putString("changeset_link", changesets_data.get(position).getLink());
            //params.putBoolean("is_https", is_https);

            intent.putExtras(params);

            startActivity(intent);
        }

    });

    //Register the list view for opening the context menu
    registerForContextMenu(changesets_listview);

    //Get the intent passed by the program
    if (getIntent() != null) {
        //Check to see if this is a search window
        if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) {
            //Change the title of the activity and the empty text of the list so it looks like a search window
            this.setTitle(R.string.search_results_label);
            empty_text.setText(R.string.search_results_empty);

            //Retrieve the query the user entered
            String query = getIntent().getStringExtra(SearchManager.QUERY);

            //Convert the query to lower case
            query = query.toLowerCase();

            //Retrieve the bundle data
            Bundle retrieved_data = getIntent().getBundleExtra(SearchManager.APP_DATA);

            //If the bundle was passed, grab the changeset data
            if (retrieved_data != null) {
                changesets_data = retrieved_data
                        .getParcelableArrayList("ca.spencerelliott.mercury.SEARCH_DATA");
            }

            //If we're missing changeset data, stop here
            if (changesets_data == null)
                return;

            //Create a new array list to store the changesets that were a match
            ArrayList<Beans.ChangesetBean> search_beans = new ArrayList<Beans.ChangesetBean>();

            //Loop through each changeset
            for (Beans.ChangesetBean b : changesets_data) {
                //Check to see if any changesets match
                if (b.getTitle().toLowerCase().contains(query)) {
                    //Get the title and date of the commit
                    String commit_text = b.getTitle();
                    Date commit_date = new Date(b.getUpdated());

                    //Add a new changeset to display in the list view
                    changesets_list.add(createChangeset(
                            (commit_text.length() > 30 ? commit_text.substring(0, 30) + "..." : commit_text),
                            b.getRevisionID() + " - " + commit_date.toLocaleString()));

                    //Add this bean to the list of found search beans
                    search_beans.add(b);
                }
            }

            //Switch the changeset data over to the changeset data that was a match
            changesets_data = search_beans;

            //Update the list in the activity
            list_handler.sendEmptyMessage(SUCCESSFUL);

            //Notify the activity that it is a search window
            is_search_window = true;

            //Stop loading here
            return;
        }

        //Get the data from the intent
        Uri data = getIntent().getData();

        if (data != null) {
            //Extract the path in the intent
            String path_string = data.getEncodedPath();

            //Split it by the forward slashes
            String[] split_path = path_string.split("/");

            //Make sure a valid path was passed
            if (split_path.length == 3) {
                //Get the repository id from the intent
                repo_id = Long.parseLong(split_path[2].toString());
            } else {
                //Notify the user if there was a problem
                Toast.makeText(this, R.string.invalid_intent, 1000).show();
            }
        }
    }

    //Retrieve the changesets
    refreshChangesets();
}

From source file:com.bmd.android.collection.SupportLongSparseArrayTest.java

public void testParcelable() {

    final ParcelableLongSparseObjectEntry[] parcelableArray = AndroidCollections.iterate(mArray).only()
            .values("4", "1").toParcelableArray(ParcelableLongSparseObjectEntry.class);

    assertThat(parcelableArray).hasSize(2);
    assertThat(parcelableArray[0].getKey()).isEqualTo(1);
    assertThat(parcelableArray[0].getValue()).isEqualTo("1");
    assertThat(parcelableArray[1].getKey()).isEqualTo(4);
    assertThat(parcelableArray[1].getValue()).isEqualTo("4");

    final ArrayList<ParcelableLongSparseObjectEntry<String>> parcelableList = AndroidCollections.iterate(mArray)
            .but().keys(Arrays.asList(1L, 2L, 3L)).reverse().toParcelableList();

    assertThat(parcelableList).hasSize(2);
    assertThat(parcelableList.get(0).getKey()).isEqualTo(4);
    assertThat(parcelableList.get(0).getValue()).isEqualTo("4");
    assertThat(parcelableList.get(1).getKey()).isEqualTo(0);
    assertThat(parcelableList.get(1).getValue()).isEqualTo("0");
    assertThat(parcelableList).containsExactly(SparseEntries.parcelableEntry(4L, "4"),
            SparseEntries.parcelableEntry(0L, "0"));

    final Bundle bundle = new Bundle();
    bundle.putParcelableArray("array", parcelableArray);
    bundle.putParcelableArrayList("list", parcelableList);

    final Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);//www  . jav a  2 s .  com

    parcel.setDataPosition(0);

    final Bundle out = parcel.readBundle();
    out.setClassLoader(AndroidCollections.class.getClassLoader());

    assertThat(out.getParcelableArray("array")).isEqualTo(parcelableArray);
    assertThat(out.getParcelableArrayList("list")).isEqualTo(new ArrayList<Parcelable>(parcelableList));

    final ArrayList<ParcelableLongSparseObjectEntry<String>> filledList = new ArrayList<ParcelableLongSparseObjectEntry<String>>(
            2);

    AndroidCollections.iterate(mArray).but().keys(1, 2, 3).reverse().fillParcelable(filledList);

    assertThat(filledList).isEqualTo(parcelableList);

    final ParcelableLongSparseObjectEntry[] filledArray = new ParcelableLongSparseObjectEntry[2];

    AndroidCollections.iterate(mArray).only().value("2").fillParcelable(filledArray);

    assertThat(filledArray[0]).isEqualTo(SparseEntries.parcelableEntry(2L, "2"));

    AndroidCollections.iterate(mArray).only().value("2").fillParcelable(filledArray, 1);

    assertThat(filledArray[0]).isEqualTo(SparseEntries.parcelableEntry(2L, "2"));
    assertThat(filledArray[0]).isEqualTo(filledArray[1]);

    try {

        AndroidCollections.iterate(mArray).fillParcelable(filledArray);

        fail();

    } catch (final IndexOutOfBoundsException e) {

    }

    final Parcelable[] parcelables = new Parcelable[2];

    AndroidCollections.iterate(mArray).only().to(1).fillParcelable(parcelables);

    assertThat(parcelables).containsExactly(filledArray);
}

From source file:com.pericstudio.drawit.fragments.TestFragmentOne.java

@Nullable
@Override//  w w  w .ja v a2  s.c o m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View layout = inflater.inflate(R.layout.fragment_test_one, container, false);
    tvTest = (TextView) layout.findViewById(R.id.tv_no_drawing);
    mSwipeRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refreshSwipeWIP);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mRecyclerWIP = (RecyclerView) layout.findViewById(R.id.recyclerWIP);
    mRecyclerWIP.setLayoutManager(new LinearLayoutManager(getActivity()));
    //        loadWIPDrawings();
    mDrawingAdapter = new RecyclerViewAdapterDrawing(getActivity(), drawingsWIP);
    mRecyclerWIP.setAdapter(mDrawingAdapter);
    mDecorator = new RecyclerViewDecorator();
    mRecyclerWIP.addItemDecoration(mDecorator);

    if (savedInstanceState != null) {
        T.showLongDebug(getActivity(), "Saved Instance State");
        drawingsWIP = savedInstanceState.getParcelableArrayList(STATE_DRAWINGS_WIP);
        tvTest.setVisibility(View.INVISIBLE);
    } else {
        loadWIPDrawings();
    }

    mDrawingAdapter.setData(drawingsWIP);

    fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);

    mRecyclerWIP.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (dy > 20) {
                L.d("Scrolling", dy + "");
                fab.hide();
            } else if (dy < -20) {
                fab.show();
                L.d("Scrolling", dy + "");
            }

        }
    });

    return layout;
}

From source file:com.github.chenxiaolong.dualbootpatcher.switcher.InAppFlashingFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (savedInstanceState != null) {
        ArrayList<MbtoolAction> savedActions = savedInstanceState.getParcelableArrayList(EXTRA_PENDING_ACTIONS);
        mPendingActions.addAll(savedActions);
    }/*from   w  w  w  .ja  v  a 2 s  .c o  m*/

    mProgressBar = (ProgressBar) getActivity().findViewById(R.id.card_list_loading);
    RecyclerView cardListView = (RecyclerView) getActivity().findViewById(R.id.card_list);

    mAdapter = new PendingActionCardAdapter(getActivity(), mPendingActions);
    cardListView.setHasFixedSize(true);
    cardListView.setAdapter(mAdapter);

    DragSwipeItemTouchCallback itemTouchCallback = new DragSwipeItemTouchCallback(this);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchCallback);
    itemTouchHelper.attachToRecyclerView(cardListView);

    LinearLayoutManager llm = new LinearLayoutManager(getActivity());
    llm.setOrientation(LinearLayoutManager.VERTICAL);
    cardListView.setLayoutManager(llm);

    final FloatingActionMenu fabMenu = (FloatingActionMenu) getActivity().findViewById(R.id.fab_add_item_menu);
    FloatingActionButton fabAddPatchedFile = (FloatingActionButton) getActivity()
            .findViewById(R.id.fab_add_patched_file);
    FloatingActionButton fabAddBackup = (FloatingActionButton) getActivity().findViewById(R.id.fab_add_backup);

    fabAddPatchedFile.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            addPatchedFile();
            fabMenu.close(true);
        }
    });
    fabAddBackup.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            addBackup();
            fabMenu.close(true);
        }
    });

    if (savedInstanceState != null) {
        mSelectedUri = savedInstanceState.getParcelable(EXTRA_SELECTED_URI);
        mSelectedUriFileName = savedInstanceState.getString(EXTRA_SELECTED_URI_FILE_NAME);
        mSelectedBackupDirUri = savedInstanceState.getParcelable(EXTRA_SELECTED_BACKUP_DIR_URI);
        mSelectedBackupName = savedInstanceState.getString(EXTRA_SELECTED_BACKUP_NAME);
        mSelectedBackupTargets = savedInstanceState.getStringArray(EXTRA_SELECTED_BACKUP_TARGETS);
        mSelectedRomId = savedInstanceState.getString(EXTRA_SELECTED_ROM_ID);
        mZipRomId = savedInstanceState.getString(EXTRA_ZIP_ROM_ID);
        mAddType = (Type) savedInstanceState.getSerializable(EXTRA_ADD_TYPE);
        mTaskIdVerifyZip = savedInstanceState.getInt(EXTRA_TASK_ID_VERIFY_ZIP);
        mQueryingMetadata = savedInstanceState.getBoolean(EXTRA_QUERYING_METADATA);
    }

    try {
        mActivityCallback = (OnReadyStateChangedListener) getActivity();
    } catch (ClassCastException e) {
        throw new ClassCastException(getActivity().toString() + " must implement OnReadyStateChangedListener");
    }

    mActivityCallback.onReady(!mPendingActions.isEmpty());

    mPrefs = getActivity().getSharedPreferences("settings", 0);

    if (savedInstanceState == null) {
        boolean shouldShow = mPrefs.getBoolean(PREF_SHOW_FIRST_USE_DIALOG, true);
        if (shouldShow) {
            FirstUseDialog d = FirstUseDialog.newInstance(this, R.string.in_app_flashing_title,
                    R.string.in_app_flashing_dialog_first_use);
            d.show(getFragmentManager(), CONFIRM_DIALOG_FIRST_USE);
        }
    }

    getActivity().getLoaderManager().initLoader(0, null, this);
}

From source file:com.xamoom.android.xamoomcontentblocks.XamoomContentFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
        mYoutubeApiKey = getArguments().getString(YOUTUBE_API_KEY);
        mContentBlockAdapter.setYoutubeApiKey(mYoutubeApiKey);
    }/*  w w  w .j a va2s  . c o m*/

    if (savedInstanceState != null) {
        mYoutubeApiKey = savedInstanceState.getString(YOUTUBE_API_KEY);
        mContentBlockAdapter.setYoutubeApiKey(mYoutubeApiKey);
        showSpotMapContentLinks = savedInstanceState.getBoolean(SHOW_SPOT_MAP_CONTENT_LINKS);
        mContent = savedInstanceState.getParcelable(CONTENT);
        mContentBlocks = savedInstanceState.getParcelableArrayList(CONTENT_BLOCKS);
        mContentBlockAdapter.setContentBlocks(mContentBlocks);
        mEnduserApi = savedInstanceState.getParcelable(ENDUSER_API);
        mContentBlockAdapter.setEnduserApi(mEnduserApi);
    }
}

From source file:org.sufficientlysecure.keychain.ui.EncryptFilesFragment.java

/**
 * Inflate the layout for this fragment/*from  w  w  w. ja v  a  2s. co  m*/
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.encrypt_files_fragment, container, false);
    mSelectedFiles = (RecyclerView) view.findViewById(R.id.selected_files_list);

    mSelectedFiles.addItemDecoration(new SpacesItemDecoration(FormattingUtils.dpToPx(getActivity(), 4)));
    mSelectedFiles.setHasFixedSize(true);
    mSelectedFiles.setLayoutManager(new LinearLayoutManager(getActivity()));
    mSelectedFiles.setItemAnimator(new DefaultItemAnimator());

    mFilesAdapter = new FilesAdapter(getActivity(), new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            addInputUri();
        }
    });
    mSelectedFiles.setAdapter(mFilesAdapter);

    Bundle args = savedInstanceState == null ? getArguments() : savedInstanceState;

    mPendingInputUris = new ArrayList<>();

    ArrayList<Uri> inputUris = args.getParcelableArrayList(ARG_URIS);
    if (inputUris != null) {
        mPendingInputUris.addAll(inputUris);
        processPendingInputUris();
    }

    return view;
}

From source file:com.bmd.android.collection.LongSparseArrayTest.java

public void testParcelable() {

    if (VERSION.SDK_INT < VERSION_CODES.JELLY_BEAN) {

        return;/* ww  w.  j av  a2  s.c  o m*/
    }

    final ParcelableLongSparseObjectEntry[] parcelableArray = AndroidCollections.iterate(mArray).only()
            .values("4", "1").toParcelableArray(ParcelableLongSparseObjectEntry.class);

    assertThat(parcelableArray).hasSize(2);
    assertThat(parcelableArray[0].getKey()).isEqualTo(1);
    assertThat(parcelableArray[0].getValue()).isEqualTo("1");
    assertThat(parcelableArray[1].getKey()).isEqualTo(4);
    assertThat(parcelableArray[1].getValue()).isEqualTo("4");

    final ArrayList<ParcelableLongSparseObjectEntry<String>> parcelableList = AndroidCollections.iterate(mArray)
            .but().keys(Arrays.asList(1L, 2L, 3L)).reverse().toParcelableList();

    assertThat(parcelableList).hasSize(2);
    assertThat(parcelableList.get(0).getKey()).isEqualTo(4);
    assertThat(parcelableList.get(0).getValue()).isEqualTo("4");
    assertThat(parcelableList.get(1).getKey()).isEqualTo(0);
    assertThat(parcelableList.get(1).getValue()).isEqualTo("0");
    assertThat(parcelableList).containsExactly(SparseEntries.parcelableEntry(4L, "4"),
            SparseEntries.parcelableEntry(0L, "0"));

    final Bundle bundle = new Bundle();
    bundle.putParcelableArray("array", parcelableArray);
    bundle.putParcelableArrayList("list", parcelableList);

    final Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);

    parcel.setDataPosition(0);

    final Bundle out = parcel.readBundle();
    out.setClassLoader(AndroidCollections.class.getClassLoader());

    assertThat(out.getParcelableArray("array")).isEqualTo(parcelableArray);
    assertThat(out.getParcelableArrayList("list")).isEqualTo(new ArrayList<Parcelable>(parcelableList));

    final ArrayList<ParcelableLongSparseObjectEntry<String>> filledList = new ArrayList<ParcelableLongSparseObjectEntry<String>>(
            2);

    AndroidCollections.iterate(mArray).but().keys(1, 2, 3).reverse().fillParcelable(filledList);

    assertThat(filledList).isEqualTo(parcelableList);

    final ParcelableLongSparseObjectEntry[] filledArray = new ParcelableLongSparseObjectEntry[2];

    AndroidCollections.iterate(mArray).only().value("2").fillParcelable(filledArray);

    assertThat(filledArray[0]).isEqualTo(SparseEntries.parcelableEntry(2L, "2"));

    AndroidCollections.iterate(mArray).only().value("2").fillParcelable(filledArray, 1);

    assertThat(filledArray[0]).isEqualTo(SparseEntries.parcelableEntry(2L, "2"));
    assertThat(filledArray[0]).isEqualTo(filledArray[1]);

    try {

        AndroidCollections.iterate(mArray).fillParcelable(filledArray);

        fail();

    } catch (final IndexOutOfBoundsException e) {

    }

    final Parcelable[] parcelables = new Parcelable[2];

    AndroidCollections.iterate(mArray).only().to(1).fillParcelable(parcelables);

    assertThat(parcelables).containsExactly(filledArray);
}

From source file:it.geosolutions.android.map.MapsActivity.java

/**
 * Create the markers and add them to the MarkerOverlay
 * Gets it from the Intent or from the savedInstanceState
 * Assign them the proper <GeoPoint> if missing
 * @param savedInstanceState//from   w  ww . j av  a 2 s  .  c o m
 */
private void createMarkers(Bundle savedInstanceState) {
    List<MarkerDTO> markerDTOs = null;
    // add the OverlayItem to the ArrayItemizedOverlay
    ArrayList<DescribedMarker> markers = null;
    if (savedInstanceState != null) {
        markerDTOs = savedInstanceState.getParcelableArrayList(MapsActivity.PARAMETERS.MARKERS);
        markers = MarkerUtils.markerDTO2DescribedMarkers(this, markerDTOs);
    } else {
        markerDTOs = getIntent().getParcelableArrayListExtra(MapsActivity.PARAMETERS.MARKERS);
        markers = MarkerUtils.markerDTO2DescribedMarkers(this, markerDTOs);
        //retieve geopoint if missing
        if (getIntent().getExtras() == null) {
            return;
        }
        featureIdField = getIntent().getExtras().getString(PARAMETERS.FEATURE_ID_FIELD);
        if (featureIdField == null) {
            featureIdField = FEATURE_DEFAULT_ID;
        }
        if (!MarkerUtils.assignFeaturesFromDb(markers, featureIdField)) {
            Toast.makeText(this, R.string.error_unable_getfeature_db, Toast.LENGTH_LONG).show();
            canConfirm = false;
            //TODO dialog : download features for this area?
        }
    }
    // create an ItemizedOverlay with the default marker

    overlayManager.getMarkerOverlay().getOverlayItems().addAll(markers);
    //TODO uncomment this if an element is present already

    // add the ArrayItemizedOverlay to the MapView

}