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:android.support.car.ui.CarNavExtender.java

/**
 * Reconstruct a CarNavExtender from an existing notification. Can be used to retrieve values.
 *
 * @param notification The notification to retrieve the values from.
 *///from   w  w w  . ja  v a 2  s. c  o m
public CarNavExtender(@NonNull Notification notification) {
    Bundle extras = NotificationCompat.getExtras(notification);
    if (extras == null) {
        return;
    }
    Bundle b = extras.getBundle(EXTRA_CAR_EXTENDER);
    if (b == null) {
        return;
    }

    mIsExtended = b.getBoolean(EXTRA_IS_EXTENDED);
    mContentId = (Long) b.getSerializable(EXTRA_CONTENT_ID);
    // The ternary guarantees that we return either TYPE_HERO or TYPE_NORMAL.
    mType = (b.getInt(EXTRA_TYPE, TYPE_NORMAL) == TYPE_HERO) ? TYPE_HERO : TYPE_NORMAL;
    mContentTitle = b.getCharSequence(Notification.EXTRA_TITLE);
    mContentText = b.getCharSequence(Notification.EXTRA_TEXT);
    mSubText = b.getCharSequence(EXTRA_SUB_TEXT);
    mLargeIcon = b.getParcelable(Notification.EXTRA_LARGE_ICON);
    mActionIcon = b.getInt(EXTRA_ACTION_ICON);
    mContentIntent = b.getParcelable(EXTRA_CONTENT_INTENT);
    mColor = b.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT);
    mNightColor = b.getInt(EXTRA_NIGHT_COLOR, Notification.COLOR_DEFAULT);
    mShowInStream = b.getBoolean(EXTRA_STREAM_VISIBILITY, true);
    mShowAsHeadsUp = b.getBoolean(EXTRA_HEADS_UP_VISIBILITY);
    mIgnoreInStream = b.getBoolean(EXTRA_IGNORE_IN_STREAM);
}

From source file:co.ceryle.segmentedbutton.SegmentedButtonGroup.java

@Override
public void onRestoreInstanceState(Parcelable state) {
    if (state instanceof Bundle) {
        Bundle bundle = (Bundle) state;
        position = bundle.getInt("position");
        state = bundle.getParcelable("state");
    }/*  w  ww  .  j ava  2  s.c  o m*/
    super.onRestoreInstanceState(state);
}

From source file:com.turbulenz.turbulenz.googlepayment.java

void uiThreadDoPurchase(String sku, String extraData) {
    _log("uiThreadDoPurchase: sku: " + sku);

    try {/*from   w  w w.  java 2 s. c  om*/
        Bundle buyIntentBundle = mService.getBuyIntent(3, mActivity.getPackageName(), sku, ITEM_TYPE_INAPP,
                extraData);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            _log("uiThreadDoPurchase: Failed to create intent bundle, " + "response: " + response);
            sendPurchaseFailure(mPurchaseContext, "failed to create Android buy Intent");
            return;
        }

        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        _log("uiThreadDoPurchase: launching buy intent for sku: " + sku + ", with request code: "
                + mPurchaseRequestCode);

        mActivity.startIntentSenderForResult(pendingIntent.getIntentSender(), mPurchaseRequestCode,
                new Intent(), Integer.valueOf(0), // flagsMask
                Integer.valueOf(0), // flagsValues
                Integer.valueOf(0)); // extraFlags
    } catch (SendIntentException e) {
        _error("uiThreadDoPurchase: SendIntentException");
        e.printStackTrace();

        sendPurchaseFailure(mPurchaseContext, "failed to send intent");
    } catch (RemoteException e) {
        _error("uiThreadDoPurchase: RemoteException");
        e.printStackTrace();

        sendPurchaseFailure(mPurchaseContext, "RemoteException: " + e);
    }
}

From source file:eu.alefzero.owncloud.ui.fragment.FileDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    if (savedInstanceState != null) {
        mFile = savedInstanceState.getParcelable(FileDetailFragment.EXTRA_FILE);
        mAccount = savedInstanceState.getParcelable(FileDetailFragment.EXTRA_ACCOUNT);
    }//w  ww. j  ava  2 s . com

    View view = null;
    view = inflater.inflate(mLayout, container, false);
    mView = view;

    if (mLayout == R.layout.file_details_fragment) {
        mView.findViewById(R.id.fdKeepInSync).setOnClickListener(this);
        //mView.findViewById(R.id.fdShareBtn).setOnClickListener(this);
        mView.findViewById(R.id.fdRenameBtn).setOnClickListener(this);
        mView.findViewById(R.id.fdRemoveBtn).setOnClickListener(this);
        mPreview = (ImageView) mView.findViewById(R.id.fdPreview);
    }

    updateFileDetails();
    return view;
}

From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_feature_dfu);
    isBLESupported();//w  ww.j  a v a  2  s . c o m
    setGUI();

    // restore saved state
    if (savedInstanceState != null) {
        mFilePath = savedInstanceState.getString(DATA_FILE_PATH);
        mFileStreamUri = savedInstanceState.getParcelable(DATA_FILE_STREAM);
        mStatusOk = savedInstanceState.getBoolean(DATA_STATUS);
        mUploadButton.setEnabled(mStatusOk);
    }
    mSelectedDevice = getIntent().getParcelableExtra(ModuleActivity.EXTRA_BLE_DEVICE);
}

From source file:com.android.contacts.group.GroupMembersFragment.java

@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    if (savedState == null) {
        mGroupUri = getArguments().getParcelable(ARG_GROUP_URI);
    } else {// www  .ja v a 2 s .c o  m
        mIsEditMode = savedState.getBoolean(KEY_IS_EDIT_MODE);
        mGroupUri = savedState.getParcelable(KEY_GROUP_URI);
        mGroupMetaData = savedState.getParcelable(KEY_GROUP_METADATA);
    }
    maybeAttachCheckBoxListener();
}

From source file:com.app.encontreibvrr.uploadImagem.MainActivityStorage.java

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

    // Initialize Firebase Auth
    mAuth = FirebaseAuth.getInstance();/*from  w  w w  .j  a v  a 2s .c om*/

    // Initialize Firebase Storage Ref
    // [START get_storage_ref]
    mStorageRef = FirebaseStorage.getInstance().getReference();
    // [END get_storage_ref]

    // Click listeners
    findViewById(R.id.button_camera).setOnClickListener(this);
    findViewById(R.id.button_sign_in).setOnClickListener(this);
    findViewById(R.id.button_download).setOnClickListener(this);

    // Restore instance state
    if (savedInstanceState != null) {
        mFileUri = savedInstanceState.getParcelable(KEY_FILE_URI);
        mDownloadUrl = savedInstanceState.getParcelable(KEY_DOWNLOAD_URL);
    }
    // Restore instance state
    if (savedInstanceState != null) {
        mFileUri = savedInstanceState.getParcelable(KEY_FILE_URI);
        mDownloadUrl = savedInstanceState.getParcelable(KEY_DOWNLOAD_URL);
    }

    // Download receiver
    mDownloadReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG, "downloadReceiver:onReceive:" + intent);
            hideProgressDialog();

            if (MyDownloadService.ACTION_COMPLETED.equals(intent.getAction())) {
                String path = intent.getStringExtra(MyDownloadService.EXTRA_DOWNLOAD_PATH);
                long numBytes = intent.getLongExtra(MyDownloadService.EXTRA_BYTES_DOWNLOADED, 0);

                // Alert success
                showMessageDialog(getString(R.string.success),
                        String.format(Locale.getDefault(), "%d bytes downloaded from %s", numBytes, path));
            }

            if (MyDownloadService.ACTION_ERROR.equals(intent.getAction())) {
                String path = intent.getStringExtra(MyDownloadService.EXTRA_DOWNLOAD_PATH);

                // Alert failure
                showMessageDialog("Error",
                        String.format(Locale.getDefault(), "Failed to download from %s", path));
            }
        }
    };
}

From source file:fr.shywim.antoinedaniel.ui.MainActivity.java

void startBuyFlow() {
    if (IAPService == null) {
        // TODO: res
        Toast.makeText(this, "Impossible de faire des achats sur un appareil non support par Google.",
                Toast.LENGTH_LONG).show();
        return;/*w  ww . ja  va2  s .  c  om*/
    }

    try {
        Bundle buyIntentBundle = IAPService.getBuyIntent(3, getPackageName(), utils.SKU_DONATE, "inapp", null);
        int responseCode = (int) buyIntentBundle.get("RESPONSE_CODE");
        switch (responseCode) {
        case 0: // BILLING_RESPONSE_RESULT_OK
            PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
            try {
                if (pendingIntent != null) {
                    IntentSender sender = pendingIntent.getIntentSender();
                    startIntentSenderForResult(sender, PURCHASE_REQUEST_CODE, new Intent(), 0, 0, 0);
                }
            } catch (IntentSender.SendIntentException e) {
                Toast.makeText(mContext, R.string.error, Toast.LENGTH_SHORT).show();
            }
            break;
        case 1: // BILLING_RESPONSE_RESULT_USER_CANCELED
            break;
        case 3: // BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE
            Toast.makeText(mContext, R.string.error, Toast.LENGTH_SHORT);
            break;
        case 4: // BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE
            Toast.makeText(mContext, R.string.error, Toast.LENGTH_SHORT);
            break;
        case 5: // BILLING_RESPONSE_RESULT_DEVELOPER_ERROR
            Toast.makeText(mContext, R.string.error, Toast.LENGTH_SHORT);
            break;
        case 6: // BILLING_RESPONSE_RESULT_ERROR
            Toast.makeText(mContext, R.string.error, Toast.LENGTH_SHORT);
            break;
        case 7: // BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED
            PrefUtils.setUserDonated(this, true);
            Toast.makeText(mContext, R.string.toast_purchase_thanks, Toast.LENGTH_LONG).show();
            mAdView.destroy();
            LinearLayout adLayout = (LinearLayout) findViewById(R.id.adLayout);
            adLayout.setVisibility(View.GONE);
            break;
        case 8: // BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED
            break;
        }
    } catch (RemoteException e) {
        Toast.makeText(mContext, R.string.error, Toast.LENGTH_SHORT).show();
    }
}

From source file:ch.berta.fabio.fabprogress.FabProgress.java

@Override
protected void onRestoreInstanceState(Parcelable state) {
    if (state instanceof Bundle) {
        Bundle bundle = (Bundle) state;

        mIsComplete = bundle.getBoolean(STATE_COMPLETE);
        if (mIsComplete) {
            fadeOut(false, false);/*www .  ja v  a2 s. c  o  m*/
        } else {
            mAnimState = bundle.getInt(STATE_ANIM);
            switch (mAnimState) {
            case ANIM_SHOWING:
                startProgress();
                break;
            case FINAL_ANIM_SHOWING:
                startProgress();
                startProgressFinalAnimation();
                break;
            }
        }

        state = bundle.getParcelable(STATE_SUPER);
    }

    super.onRestoreInstanceState(state);
}

From source file:com.example.alvarpao.popularmovies.MovieDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.movie_detail_fragment, container, false);

    // Get the fragmnent's arguments in case the fragment has been created when in
    // two-pane mode. If that is the case, retrieve the selected movie's info from the
    // arguments not the intent.
    Bundle arguments = getArguments();//  w w w .j a  va  2  s  .c  o m

    // If in one-pane mode get intent instead to get the passed movie info
    if (arguments == null)
        arguments = getActivity().getIntent().getExtras();

    // Restore state of DetailsFragment if there was a rotation
    if (savedInstanceState != null) {

        if (savedInstanceState.containsKey(MOVIE))
            mMovie = savedInstanceState.getParcelable(MOVIE);

        if (savedInstanceState.containsKey(SCROLL_POSITION))
            mScrollPosition = savedInstanceState.getInt(SCROLL_POSITION);
    }

    else {
        if (arguments != null)
            mMovie = arguments.getParcelable(MOVIE_DETAILS);
    }

    // Initialize Movie Details' recycler view
    mMovieDetailsRecyclerView = (RecyclerView) rootView.findViewById(R.id.movieDetailsRecyclerViewer);
    mMovieDetailsRecyclerView.setLayoutManager(new LinearLayoutManager(mMovieDetailsRecyclerView.getContext()));
    mMovieDetailsRecyclerView.setItemAnimator(null);

    if ((arguments != null) && (mMovie != null)) {
        // Initially the trailers and reviews arrays are empty, it is not after the
        // getExtraMovieInfo() is called that the adapter is populated.

        mMovieDetailsAdapter = new MovieDetailsRecyclerAdapter(getActivity(), mMovie, mMovie.trailers,
                mMovie.reviews);
        // Make sure the trailers and reviews for the adapter are reset
        mMovieDetailsRecyclerView.setAdapter(mMovieDetailsAdapter);

        // Restore scroll position for Recycler View
        if (savedInstanceState != null)
            mMovieDetailsRecyclerView.getLayoutManager().scrollToPosition(mScrollPosition);

        //No needed to retrieve trailers and reviews if there was a rotation
        if (savedInstanceState == null) {
            mMovieDetailsAdapter.clearTrailersAndReviews();
            mMovieDetailsAdapter.notifyDataSetChanged();
            getExtraMovieInfo();
        }
    }

    return rootView;
}