Example usage for android.content Intent getParcelableExtra

List of usage examples for android.content Intent getParcelableExtra

Introduction

In this page you can find the example usage for android.content Intent getParcelableExtra.

Prototype

public <T extends Parcelable> T getParcelableExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.mattprecious.notisync.activity.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CODE_WIZARD:
        if (resultCode == RESULT_OK) {
            startService();//from w  ww. j av  a2s .co  m
        } else if (!Preferences.getCompletedWizard(this)) {
            finish();
        }

        break;
    case REQUEST_CODE_EDIT_PROFILE:
        switch (resultCode) {
        case RESULT_OK:
            Crouton.showText(this, R.string.profile_saved, Style.CONFIRM, R.id.content_wrapper);
            break;
        case RESULT_CANCELED:
            Crouton.showText(this, R.string.profile_discarded, Style.INFO, R.id.content_wrapper);
            break;
        case RESULT_CODE_PROFILE_DELETED:
            if (undoBarController != null) {
                undoBarController.showUndoBar(true, getString(R.string.profile_deleted),
                        data.getParcelableExtra("profile"));
            }
            break;
        }

        break;
    default:
        super.onActivityResult(requestCode, resultCode, data);
        break;
    }
}

From source file:com.example.multi_ndef.Frag_Write.java

/**
 * Called when our blank tag is scanned executing the PendingIntent
 *//*from   w w  w.j  ava 2s  .  co m*/
//@SuppressLint("InlinedApi")
@Override
public void onNewIntent(Intent intent) {
    try {

        if (mInWriteMode) {
            mInWriteMode = false;

            // write to newly scanned tag
            Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
            Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

            ma.setCurrentTag(tagFromIntent);

            boolean cardCheck = false;

            cardCheck = varifyTag();

            if (cardCheck) {

                writeTag(tag);

            }

            else if (!cardCheck)

            {

                Toast toast = Toast.makeText(getApplicationContext(),
                        "Verification failed. Please use STMicroelectronics SR Tag to continue.",
                        Toast.LENGTH_LONG);
                toast.setGravity(Gravity.CENTER | Gravity.CENTER, 0, 0);
                toast.show();

            }
        }

    }

    catch (Exception e) {

    }

}

From source file:com.google.android.apps.iosched.ui.SessionsFragment.java

public void reloadFromArguments(Bundle arguments) {
    // Teardown from previous arguments
    if (mCursor != null) {
        getActivity().stopManagingCursor(mCursor);
        mCursor = null;/*from w  ww  .  j  av  a  2 s.  co  m*/
    }

    mCheckedPosition = -1;
    setListAdapter(null);

    mHandler.cancelOperation(SearchQuery._TOKEN);
    mHandler.cancelOperation(SessionsQuery._TOKEN);
    mHandler.cancelOperation(TracksQuery._TOKEN);

    // Load new arguments
    final Intent intent = BaseActivity.fragmentArgumentsToIntent(arguments);
    final Uri sessionsUri = intent.getData();
    final int sessionQueryToken;

    if (sessionsUri == null) {
        return;
    }

    String[] projection;
    if (!ScheduleContract.Sessions.isSearchUri(sessionsUri)) {
        mAdapter = new SessionsAdapter(getActivity());
        projection = SessionsQuery.PROJECTION;
        sessionQueryToken = SessionsQuery._TOKEN;

    } else {
        mAdapter = new SearchAdapter(getActivity());
        projection = SearchQuery.PROJECTION;
        sessionQueryToken = SearchQuery._TOKEN;
    }

    setListAdapter(mAdapter);

    // Start background query to load sessions
    mHandler.startQuery(sessionQueryToken, null, sessionsUri, projection, null, null,
            ScheduleContract.Sessions.DEFAULT_SORT);

    // If caller launched us with specific track hint, pass it along when
    // launching session details. Also start a query to load the track info.
    mTrackUri = intent.getParcelableExtra(SessionDetailFragment.EXTRA_TRACK);
    if (mTrackUri != null) {
        mHandler.startQuery(TracksQuery._TOKEN, mTrackUri, TracksQuery.PROJECTION);
    }
}

From source file:com.piusvelte.sonet.core.StatusDialog.java

@Override
protected void onResume() {
    super.onResume();
    Intent intent = getIntent();
    if (intent != null) {
        if (intent.hasExtra(Widgets.INSTANT_UPLOAD)) {
            mFilePath = intent.getStringExtra(Widgets.INSTANT_UPLOAD);
            Log.d(TAG, "upload photo?" + mFilePath);
        } else {/* w  w w .  j av a  2s  . com*/
            mData = intent.getData();
            if (mData != null) {
                mData = intent.getData();
                if (intent.hasExtra(LauncherIntent.Extra.Scroll.EXTRA_SOURCE_BOUNDS))
                    mRect = intent.getParcelableExtra(LauncherIntent.Extra.Scroll.EXTRA_SOURCE_BOUNDS);
                else
                    mRect = intent.getSourceBounds();
                Log.d(TAG, "data:" + mData.toString());
                // need to use a thread here to avoid anr
                mLoadingDialog = new ProgressDialog(this);
                mLoadingDialog.setMessage(getString(R.string.status_loading));
                mLoadingDialog.setCancelable(true);
                mLoadingDialog.setOnCancelListener(new OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface arg0) {
                        if (mStatusLoader != null)
                            mStatusLoader.cancel(true);
                        finish();
                    }
                });
                mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                        new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                                finish();
                            }
                        });
                mLoadingDialog.show();
                mStatusLoader = new StatusLoader();
                mStatusLoader.execute();
            }
        }
    }
    if (mFilePath != null) {
        mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.uploadprompt)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        startActivityForResult(
                                Sonet.getPackageIntent(getApplicationContext(), SonetCreatePost.class)
                                        .putExtra(Widgets.INSTANT_UPLOAD, mFilePath),
                                RESULT_REFRESH);
                        dialog.dismiss();
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        StatusDialog.this.finish();
                    }
                }).create();
        mDialog.show();
    } else {
        // check if the dialog is still loading
        if (mFinish)
            finish();
        else if ((mLoadingDialog == null) || !mLoadingDialog.isShowing())
            showDialog();
    }
}

From source file:com.grass.caishi.cc.activity.RegisterActivity.java

/**
 * onActivityResult//from  w w w  .  j  a v  a2s  .c  o m
 */
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == USERPIC_REQUEST_CODE_CAMERA) { // ?
        if (cameraFile != null && cameraFile.exists()) {
            // Log.d("cameraFile"+cameraFile.getAbsolutePath());
            // ?uri imageUri = Uri.fromFile(cameraFile);
            cropImageUri(Uri.fromFile(cameraFile), 300, 300, USERPIC_REQUEST_CODE_CUT);

        }
    } else if (requestCode == USERPIC_REQUEST_CODE_LOCAL) { // ?
        if (data != null) {
            Uri selectedImage = data.getData();
            if (selectedImage != null) {
                cropImageUri(selectedImage, 300, 300, USERPIC_REQUEST_CODE_CUT);
                // Log.d("log","selectedImage"+selectedImage);

            }
        }
    } else if (requestCode == USERPIC_REQUEST_CODE_CUT) {// ?
        // ?
        if (data != null) {
            Bitmap bitmap = data.getParcelableExtra("data");
            if (bitmap == null) {
                Toast.makeText(RegisterActivity.this, "??", Toast.LENGTH_SHORT).show();
            } else {
                user_logo.setBackgroundColor(Color.parseColor("#00000000"));
                user_logo.setImageBitmap(bitmap);
                lastFile = saveJPGE_After(bitmap, cameraFile); // ????
            }
        } else {
            // Log.e(TAG, "CHOOSE_SMALL_PICTURE: data = " + data);
        }
    }
}

From source file:com.digitalarx.android.files.services.FileUploader.java

/**
 * Entry point to add one or several files to the queue of uploads.
 * //from  ww w  . ja  v  a2  s  . c  o m
 * New uploads are added calling to startService(), resulting in a call to
 * this method. This ensures the service will keep on working although the
 * caller activity goes away.
 */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE)
            || !(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return Service.START_NOT_STICKY;
    }
    int uploadType = intent.getIntExtra(KEY_UPLOAD_TYPE, -1);
    if (uploadType == -1) {
        Log_OC.e(TAG, "Incorrect upload type provided");
        return Service.START_NOT_STICKY;
    }
    Account account = intent.getParcelableExtra(KEY_ACCOUNT);

    String[] localPaths = null, remotePaths = null, mimeTypes = null;
    OCFile[] files = null;
    if (uploadType == UPLOAD_SINGLE_FILE) {

        if (intent.hasExtra(KEY_FILE)) {
            files = new OCFile[] { intent.getParcelableExtra(KEY_FILE) };

        } else {
            localPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) };
            remotePaths = new String[] { intent.getStringExtra(KEY_REMOTE_FILE) };
            mimeTypes = new String[] { intent.getStringExtra(KEY_MIME_TYPE) };
        }

    } else { // mUploadType == UPLOAD_MULTIPLE_FILES

        if (intent.hasExtra(KEY_FILE)) {
            files = (OCFile[]) intent.getParcelableArrayExtra(KEY_FILE); // TODO
                                                                         // will
                                                                         // this
                                                                         // casting
                                                                         // work
                                                                         // fine?

        } else {
            localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE);
            remotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE);
            mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
        }
    }

    FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver());

    boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
    boolean isInstant = intent.getBooleanExtra(KEY_INSTANT_UPLOAD, false);
    int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_COPY);

    if (intent.hasExtra(KEY_FILE) && files == null) {
        Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent");
        return Service.START_NOT_STICKY;

    } else if (!intent.hasExtra(KEY_FILE)) {
        if (localPaths == null) {
            Log_OC.e(TAG, "Incorrect array for local paths provided in upload intent");
            return Service.START_NOT_STICKY;
        }
        if (remotePaths == null) {
            Log_OC.e(TAG, "Incorrect array for remote paths provided in upload intent");
            return Service.START_NOT_STICKY;
        }
        if (localPaths.length != remotePaths.length) {
            Log_OC.e(TAG, "Different number of remote paths and local paths!");
            return Service.START_NOT_STICKY;
        }

        files = new OCFile[localPaths.length];
        for (int i = 0; i < localPaths.length; i++) {
            files[i] = obtainNewOCFileToUpload(remotePaths[i], localPaths[i],
                    ((mimeTypes != null) ? mimeTypes[i] : (String) null), storageManager);
            if (files[i] == null) {
                // TODO @andomaex add failure Notification
                return Service.START_NOT_STICKY;
            }
        }
    }

    AccountManager aMgr = AccountManager.get(this);
    String version = aMgr.getUserData(account, Constants.KEY_OC_VERSION);
    OwnCloudVersion ocv = new OwnCloudVersion(version);

    boolean chunked = FileUploader.chunkedUploadIsSupported(ocv);
    AbstractList<String> requestedUploads = new Vector<String>();
    String uploadKey = null;
    UploadFileOperation newUpload = null;
    try {
        for (int i = 0; i < files.length; i++) {
            uploadKey = buildRemoteName(account, files[i].getRemotePath());
            newUpload = new UploadFileOperation(account, files[i], chunked, isInstant, forceOverwrite,
                    localAction, getApplicationContext());
            if (isInstant) {
                newUpload.setRemoteFolderToBeCreated();
            }
            mPendingUploads.putIfAbsent(uploadKey, newUpload); // Grants that the file only upload once time

            newUpload.addDatatransferProgressListener(this);
            newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
            requestedUploads.add(uploadKey);
        }

    } catch (IllegalArgumentException e) {
        Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
        return START_NOT_STICKY;

    } catch (IllegalStateException e) {
        Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
        return START_NOT_STICKY;

    } catch (Exception e) {
        Log_OC.e(TAG, "Unexpected exception while processing upload intent", e);
        return START_NOT_STICKY;

    }

    if (requestedUploads.size() > 0) {
        Message msg = mServiceHandler.obtainMessage();
        msg.arg1 = startId;
        msg.obj = requestedUploads;
        mServiceHandler.sendMessage(msg);
    }
    Log_OC.i(TAG, "mPendingUploads size:" + mPendingUploads.size());
    return Service.START_NOT_STICKY;
}

From source file:com.musenkishi.wally.activities.ImageDetailsActivity.java

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

    setToolbar((Toolbar) findViewById(R.id.toolbar));

    if (getToolbar() != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(Color.TRANSPARENT);
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }/*from w w  w .java2  s. co  m*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getToolbar().setPadding(0, getStatusBarHeight(), 0, 0);
        }
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");
    }

    final Intent intent = getIntent();
    String action = intent.getAction();

    if (Intent.ACTION_VIEW.equals(action)) {
        pageUri = Uri.parse(intent.getDataString());
        if ("wally".equalsIgnoreCase(pageUri.getScheme())) {
            pageUri = pageUri.buildUpon().scheme("http").build();
        }
    }

    setupViews();
    setupHandlers();

    Size size = new Size(16, 9);

    if (intent.hasExtra(INTENT_EXTRA_IMAGE)) {
        final Image image = intent.getParcelableExtra(INTENT_EXTRA_IMAGE);
        final Bitmap thumbBitmap = WallyApplication.getBitmapThumb();

        if (thumbBitmap != null) {

            size = fitToWidthAndKeepRatio(image.getWidth(), image.getHeight());

            photoView.getLayoutParams().width = size.getWidth();
            photoView.getLayoutParams().height = size.getHeight();

            Bitmap blurBitMap;
            try {
                blurBitMap = Blur.apply(imageHolder.getContext(), thumbBitmap);
            } catch (ArrayIndexOutOfBoundsException e) {
                //Blur couldn't be applied. Show regular thumbnail instead.
                blurBitMap = thumbBitmap;
            }
            photoView.setImageBitmap(blurBitMap);
        }
    }
    setupPaddings(size, false);

    if (savedInstanceState == null) {
        getPage(pageUri.toString());
    } else if (savedInstanceState.containsKey(STATE_IMAGE_PAGE)) {
        imagePage = savedInstanceState.getParcelable(STATE_IMAGE_PAGE);
    }

    if (imagePage != null) {
        Message msgObj = uiHandler.obtainMessage();
        msgObj.what = MSG_PAGE_FETCHED;
        msgObj.obj = imagePage;
        uiHandler.sendMessage(msgObj);
    } else {
        getPage(pageUri.toString());
    }

}

From source file:com.google.android.apps.iosched.ui.VendorsFragment.java

public void reloadFromArguments(Bundle arguments) {
    // Teardown from previous arguments
    if (mCursor != null) {
        getActivity().stopManagingCursor(mCursor);
        mCursor = null;/*from   w w w.  j a v a2 s  . co  m*/
    }

    mCheckedPosition = -1;
    setListAdapter(null);

    mHandler.cancelOperation(SearchQuery._TOKEN);
    mHandler.cancelOperation(VendorsQuery._TOKEN);

    // Load new arguments
    final Intent intent = BaseActivity.fragmentArgumentsToIntent(arguments);
    final Uri vendorsUri = intent.getData();
    final int vendorQueryToken;

    if (vendorsUri == null) {
        return;
    }

    String[] projection;
    if (!ScheduleContract.Vendors.isSearchUri(vendorsUri)) {
        mAdapter = new VendorsAdapter(getActivity());
        projection = VendorsQuery.PROJECTION;
        vendorQueryToken = VendorsQuery._TOKEN;

    } else {
        Log.d("VendorsFragment/reloadFromArguments", "A search URL definitely gets passed in.");
        mAdapter = new SearchAdapter(getActivity());
        projection = SearchQuery.PROJECTION;
        vendorQueryToken = SearchQuery._TOKEN;
    }

    setListAdapter(mAdapter);

    // Start background query to load vendors
    mHandler.startQuery(vendorQueryToken, null, vendorsUri, projection, null, null,
            ScheduleContract.Vendors.DEFAULT_SORT);

    // If caller launched us with specific track hint, pass it along when
    // launching vendor details. Also start a query to load the track info.
    mTrackUri = intent.getParcelableExtra(SessionDetailFragment.EXTRA_TRACK);
    if (mTrackUri != null) {
        mHandler.startQuery(TracksQuery._TOKEN, mTrackUri, TracksQuery.PROJECTION);
    }
}

From source file:com.lullabot.android.apps.iosched.ui.SessionsFragment.java

public void reloadFromArguments(Bundle arguments) {
    // Teardown from previous arguments
    if (mCursor != null) {
        // TODO: THIS IS WHAT WE NEED TO INSPECT FOR THE ARGUMENT BEING PASSED IN,
        // I THINK, but maybe is the Session Adapter because thats whats used to build the query.
        getActivity().stopManagingCursor(mCursor);
        mCursor = null;/* w w  w . j av a 2  s  .  co  m*/
    }

    mCheckedPosition = -1;
    setListAdapter(null);

    mHandler.cancelOperation(SearchQuery._TOKEN);
    mHandler.cancelOperation(SessionsQuery._TOKEN);
    mHandler.cancelOperation(TracksQuery._TOKEN);

    // Load new arguments
    final Intent intent = BaseActivity.fragmentArgumentsToIntent(arguments);
    final Uri sessionsUri = intent.getData();
    final int sessionQueryToken;

    if (sessionsUri == null) {
        return;
    }

    String[] projection;
    if (!ScheduleContract.Sessions.isSearchUri(sessionsUri)) {
        mAdapter = new SessionsAdapter(getActivity());
        projection = SessionsQuery.PROJECTION;
        sessionQueryToken = SessionsQuery._TOKEN;

    } else {
        mAdapter = new SearchAdapter(getActivity());
        projection = SearchQuery.PROJECTION;
        sessionQueryToken = SearchQuery._TOKEN;
    }

    setListAdapter(mAdapter);

    // Start background query to load sessions
    mHandler.startQuery(sessionQueryToken, null, sessionsUri, projection, null, null,
            ScheduleContract.Sessions.DEFAULT_SORT);

    // If caller launched us with specific track hint, pass it along when
    // launching session details. Also start a query to load the track info.
    mTrackUri = intent.getParcelableExtra(SessionDetailFragment.EXTRA_TRACK);
    if (mTrackUri != null) {
        mHandler.startQuery(TracksQuery._TOKEN, mTrackUri, TracksQuery.PROJECTION);
    }
}