Example usage for android.os Bundle putParcelable

List of usage examples for android.os Bundle putParcelable

Introduction

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

Prototype

public void putParcelable(@Nullable String key, @Nullable Parcelable value) 

Source Link

Document

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

Usage

From source file:edu.stanford.mobisocial.dungbeetle.ui.ViewContactActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_feed_home);

    checked = new boolean[filterTypes.length];

    for (int x = 0; x < filterTypes.length; x++) {
        checked[x] = true;//  w  w w  . j  a va2  s  .  c  o  m
    }

    findViewById(R.id.btn_broadcast).setVisibility(View.GONE);
    mContactId = getIntent().getLongExtra("contact_id", -1);
    if (mContactId == -1) {
        Uri data = getIntent().getData();
        if (data != null) {
            try {
                mContactId = Long.parseLong(data.getLastPathSegment());
            } catch (NumberFormatException e) {
            }
        }
    }

    Bundle args = new Bundle();
    args.putLong("contact_id", mContactId);
    Fragment profileFragment = new ViewProfileFragment();
    profileFragment.setArguments(args);
    if (mContactId == Contact.MY_ID) {
        doTitleBar(this, "My Profile");
        mLabels.add("View");
        mLabels.add("Edit");
        mFragments.add(profileFragment);
        mFragments.add(new EditProfileFragment());

        // TODO: Legitimize this. Move objects to a randomly generated private feed
        // Ability to "move" private feeds.
        // Have a "feedPtrObj" that tracks your current private. Store in-app feed.
        Uri privateUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/feeds/private");
        mLabels.add("Notes");
        Fragment feedView = new FeedViewFragment();
        args = new Bundle(args);
        args.putParcelable(FeedViewFragment.ARG_FEED_URI, privateUri);
        feedView.setArguments(args);
        mFragments.add(feedView);
    } else {
        String title = "Profile";
        Uri feedUri = null;
        try {
            Contact contact = Contact.forId(this, mContactId).get();
            title = contact.name;
            feedUri = contact.getFeedUri();
        } catch (NoValError e) {
        }
        args.putParcelable(FeedViewFragment.ARG_FEED_URI, feedUri);
        doTitleBar(this, title);
        mLabels.add("Feed");
        mLabels.add("Apps");
        mLabels.add("Profile");
        Fragment feedView = new FeedViewFragment();
        feedView.setArguments(args);
        Fragment appView = new AppsViewFragment();
        appView.setArguments(args);

        mFragments.add(feedView);
        mFragments.add(appView);
        mFragments.add(profileFragment);

        if (MusubiBaseActivity.getInstance().isDeveloperModeEnabled()) {
            FeedView sharingView = new PresenceView();
            sharingView.getFragment().setArguments(args);
            mLabels.add(sharingView.getName());
            mFragments.add(sharingView.getFragment());
        }
    }

    PagerAdapter adapter = new ViewFragmentAdapter(getSupportFragmentManager(), mFragments);
    mViewPager = (ViewPager) findViewById(R.id.feed_pager);
    mViewPager.setAdapter(adapter);
    mViewPager.setOnPageChangeListener(this);

    ViewGroup group = (ViewGroup) findViewById(R.id.tab_frame);
    int i = 0;
    for (String s : mLabels) {
        Button button = new Button(this);
        button.setText(s);
        button.setTextSize(18f);

        button.setLayoutParams(CommonLayouts.FULL_HEIGHT);
        button.setTag(i++);
        button.setOnClickListener(mViewSelected);

        group.addView(button);
        mButtons.add(button);
    }

    // Listen for future changes
    Uri feedUri;
    if (mContactId == Contact.MY_ID) {
        feedUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/feeds/me");
    } else {
        feedUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts");
    }
    mProfileContentObserver = new ProfileContentObserver(mHandler);
    getContentResolver().registerContentObserver(feedUri, true, mProfileContentObserver);

    onPageSelected(0);
}

From source file:androidx.navigation.NavController.java

/**
 * Checks the given Intent for a Navigation deep link and navigates to the deep link if present.
 * This is called automatically for you the first time you set the graph if you've passed in an
 * {@link Activity} as the context when constructing this NavController, but should be manually
 * called if your Activity receives new Intents in {@link Activity#onNewIntent(Intent)}.
 * <p>/*from   w ww .j  av a  2s  .  c o  m*/
 * The types of Intents that are supported include:
 * <ul>
 *     <ol>Intents created by {@link NavDeepLinkBuilder} or
 *     {@link #createDeepLink()}. This assumes that the current graph shares
 *     the same hierarchy to get to the deep linked destination as when the deep link was
 *     constructed.</ol>
 *     <ol>Intents that include a {@link Intent#getData() data Uri}. This Uri will be checked
 *     against the Uri patterns added via {@link NavDestination#addDeepLink(String)}.</ol>
 * </ul>
 * <p>The {@link #getGraph() navigation graph} should be set before calling this method.</p>
 * @param intent The Intent that may contain a valid deep link
 * @return True if the navigation controller found a valid deep link and navigated to it.
 * @see NavDestination#addDeepLink(String)
 */
public boolean onHandleDeepLink(@Nullable Intent intent) {
    if (intent == null) {
        return false;
    }
    Bundle extras = intent.getExtras();
    int[] deepLink = extras != null ? extras.getIntArray(KEY_DEEP_LINK_IDS) : null;
    Bundle bundle = new Bundle();
    Bundle deepLinkExtras = extras != null ? extras.getBundle(KEY_DEEP_LINK_EXTRAS) : null;
    if (deepLinkExtras != null) {
        bundle.putAll(deepLinkExtras);
    }
    if ((deepLink == null || deepLink.length == 0) && intent.getData() != null) {
        Pair<NavDestination, Bundle> matchingDeepLink = mGraph.matchDeepLink(intent.getData());
        if (matchingDeepLink != null) {
            deepLink = matchingDeepLink.first.buildDeepLinkIds();
            bundle.putAll(matchingDeepLink.second);
        }
    }
    if (deepLink == null || deepLink.length == 0) {
        return false;
    }
    bundle.putParcelable(KEY_DEEP_LINK_INTENT, intent);
    int flags = intent.getFlags();
    if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0 && (flags & Intent.FLAG_ACTIVITY_CLEAR_TASK) == 0) {
        // Someone called us with NEW_TASK, but we don't know what state our whole
        // task stack is in, so we need to manually restart the whole stack to
        // ensure we're in a predictably good state.
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(mContext)
                .addNextIntentWithParentStack(intent);
        taskStackBuilder.startActivities();
        if (mActivity != null) {
            mActivity.finish();
        }
        return true;
    }
    if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
        // Start with a cleared task starting at our root when we're on our own task
        if (!mBackStack.isEmpty()) {
            navigate(mGraph.getStartDestination(), bundle, new NavOptions.Builder()
                    .setPopUpTo(mGraph.getId(), true).setEnterAnim(0).setExitAnim(0).build());
        }
        int index = 0;
        while (index < deepLink.length) {
            int destinationId = deepLink[index++];
            NavDestination node = findDestination(destinationId);
            if (node == null) {
                throw new IllegalStateException("unknown destination during deep link: "
                        + NavDestination.getDisplayName(mContext, destinationId));
            }
            node.navigate(bundle, new NavOptions.Builder().setEnterAnim(0).setExitAnim(0).build());
        }
        return true;
    }
    // Assume we're on another apps' task and only start the final destination
    NavGraph graph = mGraph;
    for (int i = 0; i < deepLink.length; i++) {
        int destinationId = deepLink[i];
        NavDestination node = i == 0 ? mGraph : graph.findNode(destinationId);
        if (node == null) {
            throw new IllegalStateException("unknown destination during deep link: "
                    + NavDestination.getDisplayName(mContext, destinationId));
        }
        if (i != deepLink.length - 1) {
            // We're not at the final NavDestination yet, so keep going through the chain
            graph = (NavGraph) node;
        } else {
            // Navigate to the last NavDestination, clearing any existing destinations
            node.navigate(bundle, new NavOptions.Builder().setPopUpTo(mGraph.getId(), true).setEnterAnim(0)
                    .setExitAnim(0).build());
        }
    }
    return true;
}

From source file:com.xdyou.sanguo.GameSanGuo.java

public Request newFaceBookRequest(Session session, String imageName, String message, GraphPlace graphPlace,
        Callback callback) {/*from  ww  w.jav a 2  s.  com*/
    // ?
    if (session != null && session.isOpened()) {
        System.out.println(
                "go2play -- session = " + session.toString() + "session.isOpened : " + session.isOpened());
        Bitmap image = null;
        if (imageName != null) {
            image = BitmapFactory.decodeFile(imageName);
            System.out.println("go2play -- image " + image);
        }

        Bundle parameters = new Bundle();
        // ??
        if (graphPlace != null) {
            parameters.putString("place", graphPlace.getId());
        }
        // ?
        if (message != null) {
            parameters.putString("message", message);
        }
        // ?
        if (image != null) {
            parameters.putParcelable("picture", image);
            // ?
            return new Request(session, "me/photos", parameters, HttpMethod.POST, callback);
        }
        // ???
        return new Request(session, "me/feed", parameters, HttpMethod.POST, callback);
    } else {
        System.out.println("session is null or session is closed!");
        return null;
    }
}

From source file:de.sourcestream.movieDB.controller.SearchList.java

/**
 * Called to ask the fragment to save its current dynamic state,
 * so it can later be reconstructed in a new instance of its process is restarted.
 *
 * @param outState Bundle in which to place your saved state.
 *//*from w w  w .java  2  s.  c  o m*/
@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    // Used to avoid bug where we add item in the back stack
    // and if we change orientation twice the item from the back stack has null values
    if (save != null)
        outState.putBundle("save", save);
    else {
        Bundle send = new Bundle();
        send.putInt("totalPages", totalPages);
        send.putString("title", getTitle());
        if (backState == 1) {
            send.putInt("backState", 1);
            send.putParcelableArrayList("listData", searchList);
            // used to restore the scroll listener variables
            send.putInt("currentPage", endlessScrollListener.getCurrentPage());
            send.putInt("oldCount", endlessScrollListener.getOldCount());
            send.putBoolean("loading", endlessScrollListener.getLoading());
            // Save scroll position
            if (listView != null) {
                Parcelable listState = listView.onSaveInstanceState();
                send.putParcelable("listViewScroll", listState);
            }
        } else {
            send.putInt("backState", 0);
            send.putString("query", query);
        }
        outState.putBundle("save", send);
    }
}

From source file:com.facebook.Request.java

/**
 * Creates a new Request configured to upload a photo to the user's default photo album.
 *
 * @param session/*  w ww.ja  v  a2 s  . co  m*/
 *            the Session to use, or null; if non-null, the session must be in an opened state
 * @param image
 *            the image to upload
 * @param callback
 *            a callback that will be called when the request is completed to handle success or error conditions
 * @return a Request that is ready to execute
 */
public static Request newUploadPhotoRequest(Session session, Bitmap image, Callback callback) {
    Bundle parameters = new Bundle(1);
    parameters.putParcelable(PICTURE_PARAM, image);

    return new Request(session, MY_PHOTOS, parameters, HttpMethod.POST, callback);
}

From source file:com.facebook.Request.java

/**
 * Creates a new Request configured to upload an image to create a staging resource. Staging resources
 * allow you to post binary data such as images, in preparation for a post of an Open Graph object or action
 * which references the image. The URI returned when uploading a staging resource may be passed as the image
 * property for an Open Graph object or action.
 *
 * @param session/* w w w  .  j a v  a2 s  . com*/
 *            the Session to use, or null; if non-null, the session must be in an opened state
 * @param image
 *            the image to upload
 * @param callback
 *            a callback that will be called when the request is completed to handle success or error conditions
 * @return a Request that is ready to execute
 */
public static Request newUploadStagingResourceWithImageRequest(Session session, Bitmap image,
        Callback callback) {
    Bundle parameters = new Bundle(1);
    parameters.putParcelable(STAGING_PARAM, image);

    return new Request(session, MY_STAGING_RESOURCES, parameters, HttpMethod.POST, callback);
}

From source file:com.facebook.Request.java

/**
 * Creates a new Request configured to upload a photo to the user's default photo album. The photo
 * will be read from the specified stream.
 *
 * @param session  the Session to use, or null; if non-null, the session must be in an opened state
 * @param file     the file containing the photo to upload
 * @param callback a callback that will be called when the request is completed to handle success or error conditions
 * @return a Request that is ready to execute
 *///from w ww .j  a  va  2s  . c  om
public static Request newUploadPhotoRequest(Session session, File file, Callback callback)
        throws FileNotFoundException {
    ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    Bundle parameters = new Bundle(1);
    parameters.putParcelable(PICTURE_PARAM, descriptor);

    return new Request(session, MY_PHOTOS, parameters, HttpMethod.POST, callback);
}

From source file:com.facebook.Request.java

/**
 * Creates a new Request configured to upload a photo to the user's default photo album. The photo
 * will be read from the specified file descriptor.
 *
 * @param session  the Session to use, or null; if non-null, the session must be in an opened state
 * @param file     the file to upload//from www  .j  ava2s.co m
 * @param callback a callback that will be called when the request is completed to handle success or error conditions
 * @return a Request that is ready to execute
 */
public static Request newUploadVideoRequest(Session session, File file, Callback callback)
        throws FileNotFoundException {
    ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    Bundle parameters = new Bundle(1);
    parameters.putParcelable(file.getName(), descriptor);

    return new Request(session, MY_VIDEOS, parameters, HttpMethod.POST, callback);
}

From source file:com.facebook.Request.java

/**
 * Creates a new Request configured to upload an image to create a staging resource. Staging resources
 * allow you to post binary data such as images, in preparation for a post of an Open Graph object or action
 * which references the image. The URI returned when uploading a staging resource may be passed as the image
 * property for an Open Graph object or action.
 *
 * @param session/*from   w  ww . jav  a 2s  .c o m*/
 *            the Session to use, or null; if non-null, the session must be in an opened state
 * @param file
 *            the file containing the image to upload
 * @param callback
 *            a callback that will be called when the request is completed to handle success or error conditions
 * @return a Request that is ready to execute
 */
public static Request newUploadStagingResourceWithImageRequest(Session session, File file, Callback callback)
        throws FileNotFoundException {
    ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    ParcelFileDescriptorWithMimeType descriptorWithMimeType = new ParcelFileDescriptorWithMimeType(descriptor,
            "image/png");
    Bundle parameters = new Bundle(1);
    parameters.putParcelable(STAGING_PARAM, descriptorWithMimeType);

    return new Request(session, MY_STAGING_RESOURCES, parameters, HttpMethod.POST, callback);
}

From source file:com.android.mail.ui.AnimatedAdapter.java

public void onSaveInstanceState(Bundle outState) {
    long[] lastDeleting = new long[mLastDeletingItems.size()];
    for (int i = 0; i < lastDeleting.length; i++) {
        lastDeleting[i] = mLastDeletingItems.get(i);
    }//from w  w  w.  jav a 2  s  .c  o  m
    outState.putLongArray(LAST_DELETING_ITEMS, lastDeleting);
    if (hasLeaveBehinds()) {
        if (mLastLeaveBehind != -1) {
            outState.putParcelable(LEAVE_BEHIND_ITEM_DATA,
                    mLeaveBehindItems.get(mLastLeaveBehind).getLeaveBehindData());
            outState.putLong(LEAVE_BEHIND_ITEM_ID, mLastLeaveBehind);
        }
        for (LeaveBehindItem item : mLeaveBehindItems.values()) {
            if (mLastLeaveBehind == -1 || item.getData().id != mLastLeaveBehind) {
                item.commit();
            }
        }
    }
}