Example usage for android.os Bundle putSerializable

List of usage examples for android.os Bundle putSerializable

Introduction

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

Prototype

@Override
public void putSerializable(@Nullable String key, @Nullable Serializable value) 

Source Link

Document

Inserts a Serializable value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:com.github.mobile.ui.gist.GistFilesPagerAdapter.java

@Override
public Fragment getItem(final int position) {
    GistFile file = files[position];//from   ww  w.  ja v a2s.  com
    Fragment fragment = new GistFileFragment();
    Bundle args = new Bundle();
    args.putSerializable(EXTRA_GIST_FILE, file);
    fragment.setArguments(args);
    return fragment;
}

From source file:com.jerrellmardis.amphitheatre.task.DownloadTaskHelper.java

public static void traverseSmbFiles(SmbFile root, NtlmPasswordAuthentication auth)
        throws SmbException, MalformedURLException {
    int fileCount = 0;
    boolean video_folder = false;
    final Video v = new Video();
    Handler h = new Handler(Looper.getMainLooper()) {
        @Override//www. jav a2 s . c  o m
        public void handleMessage(Message msg) {
            //                            super.handleMessage(msg);
            Video vid = (Video) msg.getData().getSerializable("VIDEO");
            Log.d(TAG, "Handle " + msg.getData().getInt("WHEN") + " " + vid.getName());
            updateSingleVideo(vid, null);
        }

    };

    for (SmbFile f : root.listFiles()) {
        if (f.getParent().contains("Entertainment Media")) {
            //                Log.d(TAG, "Discovered "+f.getPath()+" "+f.isDirectory());
        }
        if (f.isDirectory()) {
            try {
                //TODO Port VOB folder support to USB and internal storage
                SmbFile[] directoryContents = f.listFiles();
                //                    Log.d(TAG, "Going into directory "+f.getPath());
                //If this works, then we can explore
                //Let's do some quick name checking to for time savings
                if (f.getName().contains("Entertainment Media")) {
                    //                        Log.d(TAG, Arrays.asList(f.listFiles()).toString());
                }
                if (!f.getName().contains("iTunes") && !f.getName().contains("Digi Pix")
                        && !f.getName().contains("AppData") && !f.getName().startsWith(".")
                        && !f.getName().contains("Avid") && !f.getName().contains("Spotify")
                        && !f.getName().contains("audacity_temp") && !f.getName().contains("Media_previews")
                        && !f.getName().contains("GFX_previews")
                        && !f.getName().contains("Samsung Install Files") && !f.getName().contains("AE Renders")
                        && !f.getName().contains("LocalData") && !f.getName().contains("$RECYCLE")
                        && !f.getName().contains("Encore DVD") && !f.getName().contains("16 GB Photo card")
                        && !f.getName().contains("Ignore") && !f.getName().contains("Documents") //TEMP
                        && !f.getName().contains("Downloads") //TEMP
                        && !f.getName().contains("TypeGEMs") //TEMP
                        && !f.getName().contains("KofC7032Web") //TEMP
                        && !f.getName().contains("hype mobile docs") //TEMP
                        && !f.getName().contains("Thrive Music Video") //TEMP
                        /*&& f.getPath().contains("Entertainment") //TEMP*/
                        && !f.getName().contains("Preview Files")) {
                    Log.d(TAG, "Check " + f.getPath());
                    traverseSmbFiles(f, auth);
                } else {
                    //                        Log.d(TAG, "Don't check " + f.getPath());
                }
            } catch (Exception e) {
                //This folder isn't accessible
                Log.d(TAG, "Inaccessible: " + f.getName() + " " + e.getMessage());
                //This will save us time in the traversal
            }
        } else/* if(f.getPath().contains("Films"))*/ { //TEMP
            //Is this something we want to add?
            //                Log.d(TAG, "Non-directory "+f.getPath());
            if (VideoUtils.isVideoFile(f.getPath())) {
                Log.d(TAG, f.getName() + " is a video");
                //Perhaps. Let's do some checking.
                /* VOB check
                If the files are in a structure like:
                { Movie Name } -> VIDEO_TS -> VTS_nn_n.vob
                        
                Then use the movie name as the source, and each vob url will
                be added in a comma-separated list to the video url string
                */

                if (f.getPath().contains("VIDEO_TS")) {
                    Log.d(TAG, "Special case for " + f.getPath());
                    //We have a special case!
                    String grandparentPath = f.getPath().substring(0, f.getPath().indexOf("VIDEO_TS"));
                    SmbFile grandparent = new SmbFile(grandparentPath, auth);

                    //Let's delete this video and all like it from our video database
                    //TODO Makes more sense to not delete and replace a video, just to update in place
                    //                        Log.d(TAG, "Purge where video_url like "+"%" + grandparent.getPath().replace("'", "\'") + "%");
                    List<Video> videos = Select.from(Video.class).where(Condition.prop("video_url")
                            .like("%" + grandparent.getPath().replace("'", "\'") + "%")).list();
                    //                        Log.d(TAG, "Purging "+videos.size()+" item(s)");
                    for (Video vx : videos) {
                        //                            Log.d(TAG, "Deleting "+vx.getVideoUrl());
                        vx.delete();
                    }

                    v.setName(grandparent.getName().replace("/", "").replace("_", " ") + ".avi"); //FIXME VOB currently not supported
                    v.setSource(FileSource.SMB);
                    v.setIsMatched(true); //Kind of a lie, but we know it's a thing!
                    //Get all the video files
                    ArrayList<String> urls = new ArrayList<>();
                    for (SmbFile f2 : grandparent.listFiles()) {
                        for (SmbFile f3 : f2.listFiles()) {
                            if (VideoUtils.isVideoFile(f3.getPath())) {
                                //Presumably in order
                                urls.add(f3.getPath());
                            }
                        }
                    }
                    //                        Log.d(TAG, urls.toString()); //This works well
                    v.setVideoUrl(urls);
                    video_folder = true;
                } else {
                    //Add the video like normal
                    //Let's delete this video and all like it from our video database
                    List<Video> videos = Select.from(Video.class)
                            .where(Condition.prop("video_url").like("%" + f.getPath().replace("'", "''") + "%"))
                            .list();
                    //                        Log.d(TAG, "Purging "+videos.size()+" item(s)");
                    for (Video vx : videos) {
                        //                            Log.d(TAG, "Deleting "+vx.getVideoUrl());
                        vx.delete();
                    }

                    v.setName(f.getName());
                    v.setSource(FileSource.SMB);
                    v.setVideoUrl(f.getPath());

                    fileCount++;
                    //Send a request to update metadata every second, to prevent as many 429 errors and memory exceptions
                    Message m = new Message();
                    Bundle mBundle = new Bundle();
                    mBundle.putSerializable("VIDEO", v.clone());
                    mBundle.putInt("WHEN", (int) (1000 * fileCount + Math.round(Math.random() * 100)));
                    m.setData(mBundle);
                    //                        h.sendEmptyMessageDelayed(1000 * fileCount, 1000 * fileCount);
                    h.sendMessageDelayed(m, 1000 * fileCount);
                    Log.d(TAG, "Queued " + mBundle.getInt("WHEN") + "  -  " + v.getName());
                    v.save(); //Need to save here, otherwise purging won't work as expected
                }

                //                    Log.d(TAG, v.toString());

                //                    return;
            }
            //Ignore otherwise
        }
    }
    //Let's do VOB video
    if (video_folder) {
        //            Log.d(TAG, "Done rooting through "+root.getPath());
        Log.d(TAG, "Created info for VOB " + v.toString());
        fileCount++;
        //Send a request to update metadata every second, to prevent as many 429 errors and memory exceptions
        Message m = new Message();
        Bundle mBundle = new Bundle();
        mBundle.putSerializable("VIDEO", v.clone());
        m.setData(mBundle);
        //                        h.sendEmptyMessageDelayed(1000 * fileCount, 1000 * fileCount);
        h.sendMessageDelayed(m, 1000 * fileCount);
        Log.d(TAG, "Queued " + 1000 * fileCount + "  -  " + v.getName());
        v.save(); //Need to save here, otherwise purging won't work as expected
    }
}

From source file:com.github.marcosalis.kraken.demo.activities.PhotosListViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list_view);

    final PhotosSize size = (PhotosSize) getIntent().getSerializableExtra(PhotosListFragment.ARGS_PHOTOS_SIZE);
    final Bundle args = new Bundle();
    args.putSerializable(PhotosListFragment.ARGS_PHOTOS_SIZE, size);

    switch (size) {
    case SMALL://  www.j  ava  2 s  . c o  m
        setTitle(R.string.title_listview_small);
        break;
    case FULL_SCREEN:
        setTitle(R.string.title_listview_fullscreen);
        break;
    }

    final Fragment fragment = Fragment.instantiate(this,
            "com.github.marcosalis.kraken.demo.fragments.PhotosListFragment", args);
    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment).commit();
}

From source file:com.agna.setmaster.ui.base.dialog.BaseBottomSheetDialog.java

@Override
public void onSaveInstanceState(Bundle outState) {
    outState.putSerializable(STATE_PARENT_TYPE, parentType);
    super.onSaveInstanceState(outState);
}

From source file:com.jjoseba.podemosquotes.fragment.MainActivityFragment.java

@OnItemLongClick(R.id.quotesGrid)
public boolean gridItemLongCLick(AdapterView<?> parent, View view, int position, long id) {
    Quote quote = adapter.getItem(position);
    Log.d(TAG, quote.getQuote());/*from w  w  w.  j a va  2s.co m*/

    Bundle args = new Bundle();
    args.putSerializable(QuoteDialog.DIALOG_QUOTE, quote);

    QuoteDialog dialog = new QuoteDialog();
    dialog.setArguments(args);
    dialog.show(this.getFragmentManager(), TAG);
    return true;
}

From source file:ca.ualberta.cmput301.as1.czervos_notes.RenameCounterActivity.java

/**
 * Takes user's input name and converts it to a string, then bundles it
 * to send back to the main activity (CounterListActivity).
 * @param view/*from  w  w w .j ava2s.c  om*/
 */
public void renameCounter(View view) {
    EditText editText = (EditText) findViewById(R.id.enter_counter_name);
    // Gets name input from edittext & converts to string
    String counterName = editText.getText().toString();
    Intent intent = new Intent(this, CounterListActivity.class);
    Bundle bundle = new Bundle();
    bundle.putSerializable("renameCounter", counterName);
    intent.putExtras(bundle);
    startActivity(intent);
}

From source file:com.krod.adapter.PagerManager.java

public PagerManager addFragments(List<BaseViewHolder> dataList) {
    for (BaseViewHolder itemEntity : dataList) {
        Fragment fragment = itemEntity.getFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(DATA, itemEntity);
        fragment.setArguments(bundle);//  w w w  .  ja v  a  2 s  .c o m
        fragmentList.add(fragment);
    }
    return this;
}

From source file:brian.chisholm.test.helloworldmap.MainActivity.java

public void getLocationDetails(OfficeLocation officeLocation) {
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle(officeLocation.getName());
    LocationDetailsFragment ldf = new LocationDetailsFragment();
    Bundle args = new Bundle();
    args.putSerializable("location", officeLocation);
    ldf.setArguments(args);/* www  .  ja  va2 s .co  m*/
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.setCustomAnimations(R.anim.slide_in, R.anim.slide_out, R.anim.pop_slide_in,
            R.anim.pop_slide_out);
    ;
    transaction.replace(R.id.container, ldf);
    transaction.addToBackStack(null);
    transaction.commit();
}

From source file:edu.htl3r.schoolplanner.gui.selectScreen.ViewTypeSpinnerOnItemSelectedListener.java

public void fireEvent(int position) {
    ViewType item = getViewType(position);
    // Falls kein SpinnerMemory verwendet wird
    if (spinnerMemory != null)
        spinnerMemory.setSelectedViewType(item);

    Bundle bundle = new Bundle();
    bundle.putSerializable(BundleConstants.SELECTED_VIEW_TYPE, item);
    intent.putExtras(bundle);/*from  ww  w. ja  va  2  s. c om*/
    this.parent.startActivity(intent);
}

From source file:Main.java

public static Intent mapToIntent(Context context, Class<?> clazz, Map<String, Object> map) {
    Intent intent = new Intent(context, clazz);
    Bundle bundle = new Bundle();
    if (map != null && map.size() > 0) {
        for (String key : map.keySet()) {
            if (map.get(key) instanceof String) {
                bundle.putString(key, (String) map.get(key));
            } else if (map.get(key) instanceof Integer) {
                bundle.putInt(key, (Integer) map.get(key));
            } else if (map.get(key) instanceof Boolean) {
                bundle.putBoolean(key, (Boolean) map.get(key));
            } else if (map.get(key) instanceof Double) {
                bundle.putDouble(key, (Double) map.get(key));
            } else if (map.get(key) instanceof Long) {
                bundle.putLong(key, (Long) map.get(key));
            } else if (map.get(key) instanceof Float) {
                bundle.putFloat(key, (Float) map.get(key));
            } else if (map.get(key) instanceof Double) {
                bundle.putDouble(key, (Double) map.get(key));
            } else if (map.get(key) instanceof Serializable) {
                bundle.putSerializable(key, (Serializable) map.get(key));
            } else if (map.get(key) instanceof Parcelable) {
                bundle.putParcelable(key, (Parcelable) map.get(key));
            }// w  w  w. j av a2  s . co m
        }
    }
    return intent.putExtras(bundle);
}