Example usage for android.os Bundle getParcelable

List of usage examples for android.os Bundle getParcelable

Introduction

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

Prototype

@Nullable
public <T extends Parcelable> T getParcelable(@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:uk.co.senab.photoview.sample.ViewPagerActivity.java

public void contributetwoDollars() {
    new Thread(new Runnable() {
        public void run() {
            ArrayList skuList = new ArrayList();
            skuList.add(twoDollars);//from w w  w.  j ava2s  . co m
            Bundle querySkus = new Bundle();
            querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
            final Bundle skuDetails;
            try {

                skuDetails = mservice.getSkuDetails(3, getPackageName(), "inapp", querySkus);

                int response = skuDetails.getInt("RESPONSE_CODE");
                if (response == 0) {

                    ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");

                    for (String thisResponse : responseList) {
                        JSONObject object = new JSONObject(thisResponse);
                        String sku = object.getString("productId");
                        String price = object.getString("price");
                        if (sku.equals(twoDollars)) {
                            System.out.println("price " + price);
                            Bundle buyIntentBundle = mservice.getBuyIntent(3, getPackageName(), sku, "inapp",
                                    "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
                            PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
                            startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(),
                                    Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
                        }
                    }
                }
                //
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SendIntentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }).start();

}

From source file:uk.co.senab.photoview.sample.ViewPagerActivity.java

public void contributeThreeDollars() {
    new Thread(new Runnable() {
        public void run() {
            ArrayList skuList = new ArrayList();
            skuList.add(threeDollars);/*from  w ww .j  a v  a  2  s. c  o  m*/
            Bundle querySkus = new Bundle();
            querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
            final Bundle skuDetails;
            try {

                skuDetails = mservice.getSkuDetails(3, getPackageName(), "inapp", querySkus);

                int response = skuDetails.getInt("RESPONSE_CODE");
                if (response == 0) {

                    ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");

                    for (String thisResponse : responseList) {
                        JSONObject object = new JSONObject(thisResponse);
                        String sku = object.getString("productId");
                        String price = object.getString("price");
                        if (sku.equals(threeDollars)) {
                            System.out.println("price " + price);
                            Bundle buyIntentBundle = mservice.getBuyIntent(3, getPackageName(), sku, "inapp",
                                    "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
                            PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
                            startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(),
                                    Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
                        }
                    }
                }
                //
            } catch (RemoteException e) {
                // 
                e.printStackTrace();
            } catch (JSONException e) {
                // 
                e.printStackTrace();
            } catch (SendIntentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }).start();

}

From source file:uk.co.senab.photoview.sample.ViewPagerActivity.java

public void contributeFourDollars() {
    new Thread(new Runnable() {
        public void run() {
            ArrayList skuList = new ArrayList();
            skuList.add(fourDollars);// w  w  w  .ja  v a 2  s  .com
            Bundle querySkus = new Bundle();
            querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
            final Bundle skuDetails;
            try {

                skuDetails = mservice.getSkuDetails(3, getPackageName(), "inapp", querySkus);

                int response = skuDetails.getInt("RESPONSE_CODE");
                if (response == 0) {

                    ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");

                    for (String thisResponse : responseList) {
                        JSONObject object = new JSONObject(thisResponse);
                        String sku = object.getString("productId");
                        String price = object.getString("price");
                        if (sku.equals(fourDollars)) {
                            System.out.println("price " + price);
                            Bundle buyIntentBundle = mservice.getBuyIntent(3, getPackageName(), sku, "inapp",
                                    "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
                            PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
                            startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(),
                                    Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
                        }
                    }
                }
                //
            } catch (RemoteException e) {
                // 
                e.printStackTrace();
            } catch (JSONException e) {
                // 
                e.printStackTrace();
            } catch (SendIntentException e) {
                // 
                e.printStackTrace();
            }
        }
    }).start();

}

From source file:com.customdatepicker.time.TimePickerDialog.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_INITIAL_TIME)
            && savedInstanceState.containsKey(KEY_IS_24_HOUR_VIEW)) {
        mInitialTime = savedInstanceState.getParcelable(KEY_INITIAL_TIME);
        mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW);
        mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE);
        mTitle = savedInstanceState.getString(KEY_TITLE);
        mThemeDark = savedInstanceState.getBoolean(KEY_THEME_DARK);
        mThemeDarkChanged = savedInstanceState.getBoolean(KEY_THEME_DARK_CHANGED);
        mAccentColor = savedInstanceState.getInt(KEY_ACCENT);
        mVibrate = savedInstanceState.getBoolean(KEY_VIBRATE);
        mDismissOnPause = savedInstanceState.getBoolean(KEY_DISMISS);
        mSelectableTimes = (Timepoint[]) savedInstanceState.getParcelableArray(KEY_SELECTABLE_TIMES);
        mMinTime = savedInstanceState.getParcelable(KEY_MIN_TIME);
        mMaxTime = savedInstanceState.getParcelable(KEY_MAX_TIME);
        mEnableSeconds = savedInstanceState.getBoolean(KEY_ENABLE_SECONDS);
        mEnableMinutes = savedInstanceState.getBoolean(KEY_ENABLE_MINUTES);
        mOkResid = savedInstanceState.getInt(KEY_OK_RESID);
        mOkString = savedInstanceState.getString(KEY_OK_STRING);
        mOkColor = savedInstanceState.getInt(KEY_OK_COLOR);
        mCancelResid = savedInstanceState.getInt(KEY_CANCEL_RESID);
        mCancelString = savedInstanceState.getString(KEY_CANCEL_STRING);
        mCancelColor = savedInstanceState.getInt(KEY_CANCEL_COLOR);
        mVersion = (Version) savedInstanceState.getSerializable(KEY_VERSION);
    }//w  w  w  .j  a v  a2 s. c  o  m
}

From source file:android.support.mediacompat.service.ServiceBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    if (ACTION_CALL_MEDIA_BROWSER_SERVICE_METHOD.equals(intent.getAction()) && extras != null) {
        StubMediaBrowserServiceCompat service = StubMediaBrowserServiceCompat.sInstance;
        int method = extras.getInt(KEY_METHOD_ID, 0);

        switch (method) {
        case NOTIFY_CHILDREN_CHANGED:
            service.notifyChildrenChanged(extras.getString(KEY_ARGUMENT));
            break;
        case SEND_DELAYED_NOTIFY_CHILDREN_CHANGED:
            service.sendDelayedNotifyChildrenChanged();
            break;
        case SEND_DELAYED_ITEM_LOADED:
            service.sendDelayedItemLoaded();
            break;
        case CUSTOM_ACTION_SEND_PROGRESS_UPDATE:
            service.mCustomActionResult.sendProgressUpdate(extras.getBundle(KEY_ARGUMENT));
            break;
        case CUSTOM_ACTION_SEND_ERROR:
            service.mCustomActionResult.sendError(extras.getBundle(KEY_ARGUMENT));
            break;
        case CUSTOM_ACTION_SEND_RESULT:
            service.mCustomActionResult.sendResult(extras.getBundle(KEY_ARGUMENT));
            break;
        case SET_SESSION_TOKEN:
            StubMediaBrowserServiceCompatWithDelayedMediaSession.sInstance.callSetSessionToken();
            break;
        }//from   w w  w.j  a  va2 s . co m
    } else if (ACTION_CALL_MEDIA_SESSION_METHOD.equals(intent.getAction()) && extras != null) {
        MediaSessionCompat session = StubMediaBrowserServiceCompat.sSession;
        int method = extras.getInt(KEY_METHOD_ID, 0);

        switch (method) {
        case SET_EXTRAS:
            session.setExtras(extras.getBundle(KEY_ARGUMENT));
            break;
        case SET_FLAGS:
            session.setFlags(extras.getInt(KEY_ARGUMENT));
            break;
        case SET_METADATA:
            session.setMetadata((MediaMetadataCompat) extras.getParcelable(KEY_ARGUMENT));
            break;
        case SET_PLAYBACK_STATE:
            session.setPlaybackState((PlaybackStateCompat) extras.getParcelable(KEY_ARGUMENT));
            break;
        case SET_QUEUE:
            List<QueueItem> items = extras.getParcelableArrayList(KEY_ARGUMENT);
            session.setQueue(items);
            break;
        case SET_QUEUE_TITLE:
            session.setQueueTitle(extras.getCharSequence(KEY_ARGUMENT));
            break;
        case SET_SESSION_ACTIVITY:
            session.setSessionActivity((PendingIntent) extras.getParcelable(KEY_ARGUMENT));
            break;
        case SET_CAPTIONING_ENABLED:
            session.setCaptioningEnabled(extras.getBoolean(KEY_ARGUMENT));
            break;
        case SET_REPEAT_MODE:
            session.setRepeatMode(extras.getInt(KEY_ARGUMENT));
            break;
        case SET_SHUFFLE_MODE:
            session.setShuffleMode(extras.getInt(KEY_ARGUMENT));
            break;
        case SEND_SESSION_EVENT:
            Bundle arguments = extras.getBundle(KEY_ARGUMENT);
            session.sendSessionEvent(arguments.getString("event"), arguments.getBundle("extras"));
            break;
        case SET_ACTIVE:
            session.setActive(extras.getBoolean(KEY_ARGUMENT));
            break;
        case RELEASE:
            session.release();
            break;
        case SET_PLAYBACK_TO_LOCAL:
            session.setPlaybackToLocal(extras.getInt(KEY_ARGUMENT));
            break;
        case SET_PLAYBACK_TO_REMOTE:
            ParcelableVolumeInfo volumeInfo = extras.getParcelable(KEY_ARGUMENT);
            session.setPlaybackToRemote(new VolumeProviderCompat(volumeInfo.controlType, volumeInfo.maxVolume,
                    volumeInfo.currentVolume) {
            });
            break;
        case SET_RATING_TYPE:
            session.setRatingType(RatingCompat.RATING_5_STARS);
            break;
        }
    }
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    setInstanceFromBundle(getArguments());

    final View rootView = inflater.inflate(R.layout.folder_list, container, false);
    mListView = (ListView) rootView.findViewById(android.R.id.list);
    mListView.setEmptyView(null);/*  w  ww. j a  v  a 2  s . c o  m*/
    mListView.setDivider(null);
    addListHeader(inflater, rootView, mListView);
    if (savedState != null && savedState.containsKey(BUNDLE_LIST_STATE)) {
        mListView.onRestoreInstanceState(savedState.getParcelable(BUNDLE_LIST_STATE));
    }
    if (savedState != null && savedState.containsKey(BUNDLE_SELECTED_FOLDER)) {
        mSelectedFolderUri = new FolderUri(Uri.parse(savedState.getString(BUNDLE_SELECTED_FOLDER)));
        mSelectedDrawerItemCategory = savedState.getInt(BUNDLE_SELECTED_ITEM_TYPE);
        mSelectedFolderType = savedState.getInt(BUNDLE_SELECTED_TYPE);
    } else if (mParentFolder != null) {
        mSelectedFolderUri = mParentFolder.folderUri;
        // No selected folder type required for hierarchical lists.
    }
    if (savedState != null) {
        mInboxPresent = savedState.getBoolean(BUNDLE_INBOX_PRESENT, true);
    } else {
        mInboxPresent = true;
    }

    mMiniDrawerView = (MiniDrawerView) rootView.findViewById(R.id.mini_drawer);

    // Create default animator listeners
    mMiniDrawerFadeOutListener = new FadeAnimatorListener(mMiniDrawerView, true /* fadeOut */);
    mListViewFadeOutListener = new FadeAnimatorListener(mListView, true /* fadeOut */);
    mMiniDrawerFadeInListener = new FadeAnimatorListener(mMiniDrawerView, false /* fadeOut */);
    mListViewFadeInListener = new FadeAnimatorListener(mListView, false /* fadeOut */);

    return rootView;
}

From source file:androidx.media.MediaController2.java

void onConnectedNotLocked(Bundle data) {
    // is enough or should we pass it while connecting?
    final SessionCommandGroup2 allowedCommands = SessionCommandGroup2
            .fromBundle(data.getBundle(ARGUMENT_ALLOWED_COMMANDS));
    final int playerState = data.getInt(ARGUMENT_PLAYER_STATE);
    final int bufferingState = data.getInt(ARGUMENT_BUFFERING_STATE);
    final PlaybackStateCompat playbackStateCompat = data.getParcelable(ARGUMENT_PLAYBACK_STATE_COMPAT);
    final int repeatMode = data.getInt(ARGUMENT_REPEAT_MODE);
    final int shuffleMode = data.getInt(ARGUMENT_SHUFFLE_MODE);
    final List<MediaItem2> playlist = MediaUtils2
            .fromMediaItem2ParcelableArray(data.getParcelableArray(ARGUMENT_PLAYLIST));
    final MediaItem2 currentMediaItem = MediaItem2.fromBundle(data.getBundle(ARGUMENT_MEDIA_ITEM));
    final PlaybackInfo playbackInfo = PlaybackInfo.fromBundle(data.getBundle(ARGUMENT_PLAYBACK_INFO));
    final MediaMetadata2 metadata = MediaMetadata2.fromBundle(data.getBundle(ARGUMENT_PLAYLIST_METADATA));
    if (DEBUG) {//  www . j a  v  a  2s.c o m
        Log.d(TAG, "onConnectedNotLocked sessionCompatToken=" + mToken.getSessionCompatToken()
                + ", allowedCommands=" + allowedCommands);
    }
    boolean close = false;
    try {
        synchronized (mLock) {
            if (mIsReleased) {
                return;
            }
            if (mConnected) {
                Log.e(TAG, "Cannot be notified about the connection result many times."
                        + " Probably a bug or malicious app.");
                close = true;
                return;
            }
            mAllowedCommands = allowedCommands;
            mPlayerState = playerState;
            mBufferingState = bufferingState;
            mPlaybackStateCompat = playbackStateCompat;
            mRepeatMode = repeatMode;
            mShuffleMode = shuffleMode;
            mPlaylist = playlist;
            mCurrentMediaItem = currentMediaItem;
            mPlaylistMetadata = metadata;
            mConnected = true;
            mPlaybackInfo = playbackInfo;
        }
        mCallbackExecutor.execute(new Runnable() {
            @Override
            public void run() {
                // Note: We may trigger ControllerCallbacks with the initial values
                // But it's hard to define the order of the controller callbacks
                // Only notify about the
                mCallback.onConnected(MediaController2.this, allowedCommands);
            }
        });
    } finally {
        if (close) {
            // Trick to call release() without holding the lock, to prevent potential deadlock
            // with the developer's custom lock within the ControllerCallback.onDisconnected().
            close();
        }
    }
}

From source file:com.example.mapdemo.LiteListDemoActivity.java

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

    // creating GPS Class object
    // User location
    gps = new GPSTracker(this);
    Bundle b = getIntent().getExtras();

    nearPlaces = (PlacesList) b.getSerializable("near_places");
    places = nearPlaces.results;/*w w w. j  a v a2  s .com*/

    LIST_LOCATIONS = new NamedLocation[nearPlaces.results.size()];
    imageUrls = new String[nearPlaces.results.size()];

    // TODO This i++ resembles C. Can be buggy memory leaks
    int i = 0;
    for (Place place : places) {
        // creating new HashMap
        HashMap<String, String> placesmap = new HashMap<String, String>();
        HashMap<String, NamedLocation> locationsmap = new HashMap<String, NamedLocation>();
        placesmap.put(KEY_ID, place.id);
        placesmap.put(KEY_ID, place.name);
        placesmap.put(KEY_ADDRESS, place.address);
        placesmap.put(KEY_THUMB_URL, place.office_image_url);
        placesList.add(placesmap);
        // Array to sort locations
        LIST_LOCATIONS[i] = new NamedLocation(place.name, new LatLng(place.location.lat, place.location.lng),
                place.formatted_phone_number, place.address, place.office_image_url, place.vicinity);

        locationmapList.add(locationsmap);
        locations.add(new NamedLocation(place.name, new LatLng(place.location.lat, place.location.lng),
                place.formatted_phone_number, place.address, place.office_image_url, place.vicinity));

        // Get image URL's
        imageUrls[i] = place.office_image_url;
        i++;
    }

    Collections.sort(locations);

    //  list=(ListView)findViewById(R.id.listview);
    // Getting adapter by passing xml data ArrayList
    //    lAdapter=new LazyAdapter(this.getApplicationContext(), places);
    //   list.setAdapter(lAdapter);
    GoogleType obj = b.getParcelable("GoogleType");

    // Set a custom list adapter for a list of locations
    mAdapter = new MapAdapter(this, R.layout.lite_list_demo_row, locations);

    // Set a custom list adapter for a list of locations
    //     mAdapter = new MapAdapter(this, locations_list);
    mList = (ListFragment) getSupportFragmentManager().findFragmentById(R.id.list);
    mList.setListAdapter(mAdapter);

    mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    // Set a RecyclerListener to clean up MapView from ListView
    AbsListView lv = mList.getListView();
    lv.setRecyclerListener(mRecycleListener);
}

From source file:com.amaze.filemanager.fragments.Main.java

void retrieveFromSavedInstance(final Bundle savedInstanceState) {

    Bundle b = new Bundle();
    String cur = savedInstanceState.getString("CURRENT_PATH");
    if (cur != null) {
        b.putInt("index", savedInstanceState.getInt("index"));
        b.putInt("top", savedInstanceState.getInt("top"));
        scrolls.put(cur, b);//w w  w  .  j  av  a  2s .  c  om

        openMode = savedInstanceState.getInt("openMode", 0);
        if (openMode == 1)
            smbPath = savedInstanceState.getString("SmbPath");
        LIST_ELEMENTS = savedInstanceState.getParcelableArrayList("list");
        folder_count = savedInstanceState.getInt("folder_count", 0);
        file_count = savedInstanceState.getInt("file_count", 0);
        results = savedInstanceState.getBoolean("results");
        adapter = (Recycleradapter) savedInstanceState.getParcelable("adapter");
        createViews(LIST_ELEMENTS, true, (CURRENT_PATH), openMode, true, !IS_LIST);
        if (savedInstanceState.getBoolean("selection")) {

            for (int i : savedInstanceState.getIntegerArrayList("position")) {
                adapter.toggleChecked(i);
            }
        }
    }
}