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.snowdream.wallpaper.ImagePagerActivity.java

private void initData(Bundle savedInstanceState) {
    Bundle bundle = getIntent().getExtras();
    List<Image> images = bundle.getParcelableArrayList(Extra.IMAGES);
    int pagerPosition = bundle.getInt(Extra.IMAGE_POSITION, 0);

    if (savedInstanceState != null) {
        pagerPosition = savedInstanceState.getInt(STATE_POSITION);
    }//from  w ww  . j av a  2s.com

    options = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.ic_empty)
            .showImageOnFail(R.drawable.ic_error).resetViewBeforeLoading().cacheOnDisc()
            .imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565)
            .displayer(new FadeInBitmapDisplayer(300)).build();

    mHandler = new Handler();

    pager.setAdapter(new ImagePagerAdapter(this, images, options));
    pager.setCurrentItem(pagerPosition);
}

From source file:com.example.android.popularmovies.fragments.MovieReviewsFragment.java

private void onRestoreState(Bundle savedInstanceState) {
    if (savedInstanceState == null) {
        loadReviews(1);//w  w w . ja v a  2 s.c o  m
    } else {
        if (savedInstanceState.containsKey(REVIEWS_ADAPTER_STATE)) {
            ArrayList<Review> reviewsArrayList = savedInstanceState
                    .getParcelableArrayList(REVIEWS_ADAPTER_STATE);
            mReviewAdapter.setReviewsData(reviewsArrayList);
        }
        if (savedInstanceState.containsKey(MOVIE_ACTIVE)) {
            mMovie = savedInstanceState.getParcelable(MOVIE_ACTIVE);
        }
    }
}

From source file:com.github.jobs.ui.fragment.JobListFragment.java

public void onFinished(Bundle resultData) {
    ArrayList<Parcelable> parcelableArrayList = resultData.getParcelableArrayList(SearchJobsResolver.DATA_JOBS);
    if (parcelableArrayList == null) {
        return;/*  w w  w.  j  a v a  2s . c o m*/
    }
    ArrayList<Job> jobs = new ArrayList<Job>();
    for (Parcelable parcelable : parcelableArrayList) {
        jobs.add((Job) parcelable);
    }
    mAdapter.addItems(jobs);
    if (jobs.size() == 0) {
        removeFooterFromList();
    } else {
        addFooterToList();
    }
    mLoading = false;
}

From source file:net.lp.actionbarpoirot.tasks.TaskManager.java

/**
 * Restore saved tasks from the per-instance state.
 * /* w w  w . j  a  v a2s  .c o  m*/
 * @param context
 * @param savedInstanceState
 */
protected void restoreSavedTasks(C context, Bundle savedInstanceState) {
    // Restore saved tasks.
    ArrayList<Parcelable> savedTaskList = savedInstanceState.getParcelableArrayList(KEY_TASK_LIST);
    for (Parcelable taskBundle : savedTaskList) {
        try {
            // TODO BUG: Since setting the productId will only happen a
            // short while after the task is created/restored, in the mean
            // time the screen may be rotated and the task will tried to be
            // saved but there will be no productId so it will be omitted.
            // This makes the task go away if you rotate often and early on
            // in the progress. In Shelves this is slightly different
            // because checks for restoring are done first before
            // instantiating a new task object. Allthough I believe the same
            // bug is present in Shelves too. Not a deal breaker currently.
            VisibleTask task = null;
            try {
                task = (VisibleTask<?, ?, ?, ?, ?>) Class
                        .forName(((Bundle) taskBundle).getString(KEY_TASK_CLASS)).newInstance();
            } catch (InstantiationException e) {
                // Because the class we are trying to instantiate might be a
                // non-static nested class, we need to pass in a first
                // parameter, even for the empty constructor, which is the
                // object of its outer class. The non-static class is in the
                // object of its outer class. Only a static nested class
                // would be directly accessible as above.
                task = (VisibleTask<?, ?, ?, ?, ?>) Class
                        .forName(((Bundle) taskBundle).getString(KEY_TASK_CLASS))
                        .getConstructor(new Class[] { context.getClass() }).newInstance(context);
            }
            task.restart(context, ((Bundle) taskBundle));
            if (PoirotWindow.DEBUG)
                Log.d(VisibleTask.TAG, "Restoring task state");
            tasks.add(task);
        } catch (TaskExistsException e) {
            if (PoirotWindow.DEBUG)
                Log.d(VisibleTask.TAG, "Tried restoring task state but task exists");
            UiUtilities.showToast(context.getApplicationContext(), R.string.progress_failed_task_exists);
        } catch (TaskUnavailableException e) {

            if (PoirotWindow.DEBUG)
                Log.d(VisibleTask.TAG, "Tried restoring task state but no room for another AsyncTask");
            UiUtilities.showToast(context.getApplicationContext(), R.string.task_no_room);

        } catch (TaskInvalidStateException e) {
            if (PoirotWindow.DEBUG)
                Log.d(VisibleTask.TAG, "Tried restoring task state (but invalid state)"); //ignore
            //e.printStackTrace();

        } catch (TaskRefusedException e) {
            if (PoirotWindow.DEBUG)
                Log.d(VisibleTask.TAG, "Tried restoring task state but product exists");
            UiUtilities.showToast(context.getApplicationContext(), R.string.progress_failed_product_exists);

        } catch (Throwable e) {
            // Other SpecificTaskDomainExceptions-Throwables
            // (SpecificAddTaskDomainExceptions,
            // SpecificExportTaskDomainExceptions or
            // SpecificSearchTaskDomainExceptions) than
            // ProductExistsException should not occur.
            // TaskExistsExceptions for Export should not occur.

            if (PoirotWindow.DEBUG)
                Log.d(TaskManager.TAG, "Other throwable");
        }
    }
}

From source file:cl.smartcities.isci.transportinspector.dialogs.BusSelectionDialog.java

@NonNull
@Override//from   w  ww  . j a  v a  2 s .c  o  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog dialog;
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());

    LayoutInflater inflater = this.getActivity().getLayoutInflater();
    final View dialog_view = inflater.inflate(R.layout.bus_selection_dialog, null);
    final Typeface iconTypeface = Typeface.createFromAsset(this.getContext().getAssets(),
            getActivity().getString(R.string.icon_font));
    ((TextView) dialog_view.findViewById(R.id.suggestion_icon)).setTypeface(iconTypeface);

    builder.setView(dialog_view);
    builder.setCancelable(false);
    dialog = builder.create();

    final Bundle bundle = getArguments();
    ArrayList<Bus> buses = null;

    if (bundle != null) {
        buses = bundle.getParcelableArrayList(NotificationState.BUSES);
    }

    if (buses != null && !buses.isEmpty()) {
        dialog_view.findViewById(R.id.list_view).setVisibility(View.VISIBLE);
        setBusMap(buses);
        ArrayList<String> serviceList = new ArrayList<>();
        serviceList.addAll(this.busMap.keySet());
        BusSelectionAdapter adapter = new BusSelectionAdapter(this.getContext(), serviceList, busMap,
                new BusSelectionAdapter.ListViewAdapterListener() {
                    @Override
                    public void onPositiveClick(Bus bus) {
                        dialog.cancel();
                        listener.onPositiveClick(bus);
                    }

                    @Override
                    public void onNegativeClick() {
                        dialog.cancel();
                        listener.onNegativeClick();
                    }
                });
        ListView listView = (ListView) dialog_view.findViewById(R.id.list_view);

        listView.setAdapter(adapter);

        if (adapter.getCount() > VISIBLE_BUSES) {
            View item = adapter.getView(0, null, listView);
            item.measure(0, 0);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT,
                    (int) ((VISIBLE_BUSES + 0.5) * item.getMeasuredHeight()));
            listView.setLayoutParams(params);
        }

    }

    Button otherAcceptButton = (Button) dialog_view.findViewById(R.id.accept);
    otherAcceptButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText serviceEditText = (EditText) dialog_view.findViewById(R.id.service_edit_text);
            EditText licensePlateEditText = (EditText) dialog_view.findViewById(R.id.license_plate_edit_text);
            String service = serviceEditText.getText().toString();
            String licensePlate = licensePlateEditText.getText().toString();
            ServiceHelper helper = new ServiceHelper(getContext());

            if (ServiceValidator.validate(service) && helper.getColorId(Util.formatServiceName(service)) != 0) {
                service = Util.formatServiceName(service);
                if (licensePlate.equals("")) {
                    licensePlate = Constants.DUMMY_LICENSE_PLATE;
                } else if (!LicensePlateValidator.validate(licensePlate)) {
                    Toast.makeText(getContext(), R.string.bus_selection_warning_plate, Toast.LENGTH_SHORT)
                            .show();
                    return;
                }
            } else {
                Toast.makeText(getContext(), R.string.bus_selection_warning_service, Toast.LENGTH_SHORT).show();
                return;
            }

            final Bus bus = new Bus(Util.formatServiceName(service), licensePlate);
            InputMethodManager imm = (InputMethodManager) getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

            Log.d("BusSelectionDialog", "hiding soft input");

            Timer timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    BusSelectionDialog.this.getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            dialog.cancel();
                            listener.onPositiveClick(bus);
                        }
                    });
                }
            }, 500);
            //dialog.cancel();
            // TODO(aantoine): This call is to quick, some times the keyboard is not
            // out of the window when de sliding panel shows up.
            //listener.onPositiveClick(bus);
        }
    });

    /* set cancel button to close dialog */
    dialog_view.findViewById(R.id.close_dialog).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.cancel();
            listener.onNegativeClick();
        }
    });
    ((Button) dialog_view.findViewById(R.id.close_dialog)).setTypeface(iconTypeface);
    dialog.setCanceledOnTouchOutside(false);

    return dialog;
}

From source file:ar.org.fsadosky.iptablesmanager.fragment.ApplicationsListFragment.java

@Override
public void onViewStateRestored(Bundle savedInstanceState) {
    super.onViewStateRestored(savedInstanceState);
    if (savedInstanceState != null) {
        ArrayList<ApplicationItem> applications = savedInstanceState.getParcelableArrayList(LIST_STATE);
        this.applications = new ApplicationsStatus(applications);
        searchItems = savedInstanceState.getParcelableArrayList(SEARCH_STATE);
    }//from   w w  w.ja  va  2 s.c  om
}

From source file:fr.cph.chicago.fragment.BikeFragment.java

@Override
public final boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_refresh:
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mActivity);
        boolean loadBike = sharedPref.getBoolean("divvy_bike", true);
        if (loadBike) {
            MenuItem menuItem = item;
            menuItem.setActionView(R.layout.progressbar);
            menuItem.expandActionView();

            new DivvyAsyncTask().execute();

            Bundle bundle = mActivity.getIntent().getExtras();
            List<BikeStation> bikeStations = bundle.getParcelableArrayList("bikeStations");

            if (bikeStations == null) {
                mActivity.startRefreshAnimation();
                mActivity.new LoadData().execute();
            }//from  w w w  .  j av  a  2 s  .com
        }
        Util.trackAction(mActivity, R.string.analytics_category_ui, R.string.analytics_action_press,
                R.string.analytics_action_refresh_bike, 0);
        return false;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.lloydtorres.stately.login.SwitchNationDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.fragment_dialog_recycler, null);

    // Restore saved state
    if (savedInstanceState != null) {
        logins = savedInstanceState.getParcelableArrayList(LOGINS_KEY);
    }/* ww w  .  java2s  . com*/

    initRecycler(view);

    // Build actual dialog
    DialogInterface.OnClickListener dialogListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            SparkleHelper.startAddNation(getContext());
        }
    };

    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext(),
            RaraHelper.getThemeMaterialDialog(getContext()));
    dialogBuilder.setTitle(R.string.menu_switch).setView(view).setPositiveButton(R.string.add_nation,
            dialogListener);

    return dialogBuilder.create();
}

From source file:com.liferay.mobile.screens.base.list.BaseListScreenletView.java

@Override
protected void onRestoreInstanceState(Parcelable inState) {
    Bundle state = (Bundle) inState;
    Parcelable superState = state.getParcelable(STATE_SUPER);

    super.onRestoreInstanceState(superState);

    List<E> entries = state.getParcelableArrayList(STATE_ENTRIES);

    A adapter = getAdapter();//  w  w w. j  a v  a  2s .c  o m
    adapter.setRowCount(state.getInt(STATE_ROW_COUNT));
    adapter.getEntries().addAll(entries == null ? new ArrayList<E>() : entries);
    adapter.notifyDataSetChanged();

    List labelFields = state.getStringArrayList(STATE_LABEL_FIELDS);

    getAdapter().setLabelFields(labelFields);

    firstRow = state.getInt(STATE_FIRST_ROW);
}

From source file:me.diskstation.ammon.gpsrunner.ui.OverviewFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (savedInstanceState != null) {
        ArrayList<Parcelable> parcelable = savedInstanceState.getParcelableArrayList("waypoints");
        if (waypoints.size() == 0 && parcelable != null) {

            if (parcelable.size() > 0) {
                for (int i = 0; i < parcelable.size(); i++) {
                    waypoints.add((LatLng) parcelable.get(i));
                }//from w  ww.ja  v  a  2s . c om
                updatePolyline(waypoints, waypoints.get(waypoints.size() - 1));
            }
        }
        if (savedInstanceState.containsKey("run")) {
            Bundle run = savedInstanceState.getBundle("run");
            if (run != null) {
                update(savedInstanceState.getBundle("run"));
            }
        }

    }
}