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.actionlauncher.api.LiveWallpaperSource.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null) {
        return;/*from  w  w  w .ja v  a  2  s.  c  om*/
    }

    String action = intent.getAction();
    LOGD("LiveWallpaperSource.onHandleIntent() - action:" + action + ", id:" + mName);
    // TODO: permissions?
    if (ACTION_SUBSCRIBE.equals(action)) {
        processSubscribe((ComponentName) intent.getParcelableExtra(EXTRA_SUBSCRIBER_COMPONENT),
                intent.getStringExtra(EXTRA_TOKEN));
    } else if (ACTION_FETCH_PALETTE.equals(action)) {
        publishCurrentPalette();
    } else if (action.equals(ProtocolConstants.ACTION_PUBLISH_STATE)) {
        boolean wallpaperInfoSet = false;
        if (intent.hasExtra(EXTRA_LIVE_WALLPAPER_INFO)) {
            Bundle bundle = intent.getExtras().getBundle(EXTRA_LIVE_WALLPAPER_INFO);
            if (bundle != null) {
                LiveWallpaperInfo info = LiveWallpaperInfo.fromBundle(bundle);
                mCurrentState.setCurrentLiveWallpaperInfo(info);
                LOGD("LiveWallpaperInfo.fromBundle():" + (info != null ? info.toString() : null));
                wallpaperInfoSet = true;
            }
        }
        if (!wallpaperInfoSet) {
            mCurrentState.setCurrentLiveWallpaperInfo(null);
        }
        publishCurrentPalette();
    }
}

From source file:com.owncloud.android.ui.activity.SyncedFoldersActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_REMOTE_FOLDER
            && resultCode == RESULT_OK && mSyncedFolderPreferencesDialogFragment != null) {
        OCFile chosenFolder = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
        mSyncedFolderPreferencesDialogFragment.setRemoteFolderSummary(chosenFolder.getRemotePath());
    }//  w w w .ja  v a  2  s  . c om
    if (requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_LOCAL_FOLDER
            && resultCode == RESULT_OK && mSyncedFolderPreferencesDialogFragment != null) {
        String localPath = data.getStringExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES);
        mSyncedFolderPreferencesDialogFragment.setLocalFolderSummary(localPath);
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:com.globalcollect.gateway.sdk.client.android.exampleapp.fragments.FullWalletConfirmationButtonFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    mProgressDialog.hide();/* w  w w  . jav a2 s.  c  o  m*/

    // retrieve the error code, if available
    int errorCode = -1;
    if (data != null) {
        errorCode = data.getIntExtra(WalletConstants.EXTRA_ERROR_CODE, -1);
    }

    switch (requestCode) {
    case REQUEST_CODE_RESOLVE_LOAD_FULL_WALLET:
        switch (resultCode) {
        case Activity.RESULT_OK:
            if (data != null && data.hasExtra(WalletConstants.EXTRA_FULL_WALLET)) {
                FullWallet fullWallet = data.getParcelableExtra(WalletConstants.EXTRA_FULL_WALLET);
                // the full wallet can now be used to process the customer's payment
                // send the wallet info up to server to process, and to get the result
                // for sending a transaction status
                fetchTransactionStatus(fullWallet);
            } else if (data != null && data.hasExtra(WalletConstants.EXTRA_MASKED_WALLET)) {
                // re-launch the activity with new masked wallet information
                mMaskedWallet = data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET);
                mActivityLaunchIntent.putExtra(Constants.INTENT_MASKED_WALLET, mMaskedWallet);
                startActivity(mActivityLaunchIntent);
            }
            break;
        case Activity.RESULT_CANCELED:
            // nothing to do here
            break;
        default:
            handleError(errorCode);
            break;
        }
        break;
    }
}

From source file:com.ekumen.tangobot.application.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

    // Load raw resources
    for (Pair<Integer, String> ip : mResourcesToLoad) {
        mOpenedResources.add(new ParameterLoaderNode.Resource(
                getResources().openRawResource(ip.first.intValue()), ip.second));
    }/* w  w w .j  a  va  2 s . c  o m*/

    mSharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    // UI
    initializeUI();

    // USB handling code
    mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    mUsbPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
    mUsbAttachedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            mLog.info("Received USB Intent");
            if (intent.getAction() == ACTION_USB_PERMISSION
                    && intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                onDeviceReady((UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE));
            }
        }
    };
    mUsbDetachedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            mLog.info("Received USB disconnection Intent");
            UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
            onDeviceDetached(device);
        }
    };
}

From source file:com.ntsync.android.sync.activities.ShopActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // Postpone a Payment-Result to onResumeFragment, back from payment
    // returns null-data.
    PaymentConfirmation confirm = null;/*from   ww w .  j av  a  2  s  .c o  m*/
    if (data != null) {
        confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
    }
    paymentResult = new PaymentResult(resultCode, confirm);
}

From source file:com.cmput301w17t07.moody.EditMoodActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    UserController userController = new UserController();
    userName = userController.readUsername(EditMoodActivity.this).toString();
    setContentView(R.layout.activity_edit_mood);
    setUpMenuBar(this);

    // get the mood object that was selected
    Intent intent = getIntent();
    editMood = (Mood) intent.getSerializableExtra("editMood");
    date = editMood.getDate();/*  ww w. j  a v  a 2  s  .c o m*/
    bitmapImage = (Bitmap) intent.getParcelableExtra("bitmapback");
    editBitmapImage = bitmapImage;
    deletedPic = (int) intent.getExtras().getInt("bitmapdelete");
    latitude = editMood.getLatitude();
    longitude = editMood.getLongitude();
    image = (ImageView) findViewById(R.id.editImageView);
    final TextView location = (TextView) findViewById(R.id.locationText);
    address = editMood.getDisplayLocation();
    location.setText(address);

    if (latitude == 0 && longitude == 0) {
        location1 = null;
    }
    displayAttributes();
    if (deletedPic == 1) {
        image.setImageBitmap(null);
    }

    //set up the button and imageButton
    ImageButton editLocation = (ImageButton) findViewById(R.id.location);
    editLocation.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            locationText = (TextView) findViewById(R.id.locationText);
            locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            //check available tools
            List<String> locationList = locationManager.getProviders(true);
            if (locationList.contains(LocationManager.GPS_PROVIDER)) {
                provider = LocationManager.GPS_PROVIDER;
            } else if (locationList.contains(LocationManager.NETWORK_PROVIDER)) {
                provider = LocationManager.NETWORK_PROVIDER;
            } else {
                Toast.makeText(getApplicationContext(), "Please check your permissions", Toast.LENGTH_LONG)
                        .show();
            }
            //check the permission
            if (ActivityCompat.checkSelfPermission(getApplicationContext(),
                    android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(getApplicationContext(),
                            android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                Toast.makeText(getApplicationContext(),
                        "Getting location failed, Please check the application permissions", Toast.LENGTH_SHORT)
                        .show();
                return;
            }

            location1 = locationManager.getLastKnownLocation(provider);
            if (location1 == null) {
                latitude = 0;
                longitude = 0;
            } else {
                latitude = location1.getLatitude();
                longitude = location1.getLongitude();
            }

            //get the location name by latitude and longitude
            Geocoder gcd = new Geocoder(EditMoodActivity.this, Locale.getDefault());
            try {
                List<Address> addresses = gcd.getFromLocation(latitude, longitude, 1);

                if (addresses.size() > 0)
                    address = "  " + addresses.get(0).getFeatureName() + " "
                            + addresses.get(0).getThoroughfare() + ", " + addresses.get(0).getLocality() + ", "
                            + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryCode();
                location.setText(address);
            } catch (Exception e) {
                e.printStackTrace();
            }

            final ImageButton deleteLocation = (ImageButton) findViewById(R.id.deleteLocation);
            deleteLocation.setVisibility(View.VISIBLE);
            deleteLocation.setEnabled(true);
        }
    });

    editLocation.setOnLongClickListener(new View.OnLongClickListener() {
        public boolean onLongClick(View view) {
            moodMessage_text = Description.getText().toString();
            editMood.setMoodMessage(moodMessage_text);
            editMood.setDate(date);
            Intent editLocation = new Intent(EditMoodActivity.this, EditLocation.class);
            editLocation.putExtra("EditMood", editMood);
            editLocation.putExtra("bitmap", compress(editBitmapImage));
            startActivity(editLocation);
            return true;
        }
    });

    final ImageButton deleteLocation = (ImageButton) findViewById(R.id.deleteLocation);
    deleteLocation.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            location1 = null;
            locationText = (TextView) findViewById(R.id.locationText);
            address = null;
            locationText.setText(address);
            latitude = 0;
            longitude = 0;
            deleteLocation.setVisibility(View.INVISIBLE);
            deleteLocation.setEnabled(false);
        }
    });

    ImageButton editCameraButton = (ImageButton) findViewById(R.id.editCamera);
    editCameraButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            try {
                Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                startActivityForResult(intent, 1);
            } catch (Exception e) {
                Intent intent = new Intent(getApplicationContext(), EditMoodActivity.class);
                startActivity(intent);
            }
        }
    });

    editCameraButton.setOnLongClickListener(new View.OnLongClickListener() {
        public boolean onLongClick(View view) {
            try {
                Intent intent = new Intent("android.intent.action.PICK");
                intent.setType("image/*");
                startActivityForResult(intent, 0);
            } catch (Exception e) {
                Intent intent = new Intent(getApplicationContext(), EditMoodActivity.class);
                startActivity(intent);
            }
            return true;
        }
    });

    ImageButton PickerButton = (ImageButton) findViewById(R.id.EditDate);
    PickerButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            innit();
            TimeDialog.show();
        }
    });
    Button submitButton = (Button) findViewById(R.id.button5);
    submitButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            moodMessage_text = Description.getText().toString();
            MoodController moodController = new MoodController();
            editBitmapImage = bitmapImage;
            AchievementManager.initManager(EditMoodActivity.this);
            AchievementController achievementController = new AchievementController();
            achievements = achievementController.getAchievements();
            achievements.firstTimeEditFlag = 1;
            achievementController.saveAchievements();

            if (!moodController.editMood(EmotionText, userName, moodMessage_text, latitude, longitude,
                    editBitmapImage, SocialSituation, date, address, editMood, EditMoodActivity.this)) {
                Toast.makeText(EditMoodActivity.this, "Mood message length is too long. Please try again",
                        Toast.LENGTH_SHORT).show();
            } else {
                Intent intent = new Intent(EditMoodActivity.this, TimelineActivity.class);
                startActivity(intent);
                finish();
            }
        }
    });

    // TODO button needs only display when image present in Mood
    final ImageButton deletePicture = (ImageButton) findViewById(R.id.deletePicture);
    if (editBitmapImage == null || deletedPic == 1) {
        deletePicture.setVisibility(View.INVISIBLE);
        deletePicture.setEnabled(false);
    }
    deletePicture.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            bitmapImage = null;
            editBitmapImage = null;
            image.setImageDrawable(null);
            deletePicture.setVisibility(View.INVISIBLE);
            deletePicture.setEnabled(false);
        }
    });
}

From source file:com.github.jobs.ui.fragment.EditTemplateFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != Activity.RESULT_OK) {
        return;/*from   w w  w.  java 2  s  .  co  m*/
    }
    switch (requestCode) {
    case SOUserPickerActivity.REQUEST_CODE:
        if (data == null) {
            // meh... there was no data
            return;
        }
        Parcelable userParcel = data.getParcelableExtra(SOUserPickerActivity.EXTRA_USER);
        if (userParcel instanceof SOUser) {
            SOUser soUser = (SOUser) userParcel;
            // create new cover letter service
            TemplateService soService = new TemplateService();
            soService.setType(StackOverflowService.TYPE);
            soService.setData(soUser.getLink());

            // push cover letter to the fragment holding template information
            addTemplateService(soService);

            // add the website service if possible
            if (soUser.getWebsiteUrl() != null) {
                TemplateService webService = new TemplateService();
                webService.setType(WebsiteService.TYPE);
                webService.setData(soUser.getWebsiteUrl());
                addTemplateService(webService);
            }
            viewUtils.toast(R.string.so_link_added);
        }
        break;
    case ServiceChooserDialog.REQUEST_CODE:
        int serviceId = data.getIntExtra(ServiceChooserDialog.RESULT_SERVICE_ID, -1);
        if (serviceId == -1) {
            Parcelable[] templateServices = data.getParcelableArrayExtra(ServiceChooserDialog.RESULT_SERVICES);
            if (templateServices != null) {
                for (Parcelable templateService : templateServices) {
                    addTemplateService((TemplateService) templateService);
                }
            }
        } else {
            if (serviceId == R.id.service_so) {
                Intent intent = new Intent(getActivity(), SOUserPickerActivity.class);
                startActivityForResult(intent, SOUserPickerActivity.REQUEST_CODE);
            } else {
                TemplateService templateService = getTemplateFromResult(serviceId, data);
                if (templateService != null) {
                    addTemplateService(templateService);
                }
            }
        }
        break;
    }
}

From source file:com.example.jesse.barscan.BarcodeCaptureActivity.java

/**
 * onTap returns the tapped barcode result to the calling Activity.
 *//*from   w w w . j  ava  2  s. c om*/
public boolean onTap(float rawX, float rawY) {
    // Find tap point in preview frame coordinates.
    int[] location = new int[2];
    mGraphicOverlay.getLocationOnScreen(location);
    float x = (rawX - location[0]) / mGraphicOverlay.getWidthScaleFactor();
    float y = (rawY - location[1]) / mGraphicOverlay.getHeightScaleFactor();

    // Find the barcode whose center is closest to the tapped point.
    Barcode best = null;
    float bestDistance = Float.MAX_VALUE;
    for (BarcodeGraphic graphic : mGraphicOverlay.getGraphics()) {
        Barcode barcode = graphic.getBarcode();
        if (barcode.getBoundingBox().contains((int) x, (int) y)) {
            // Exact hit, no need to keep looking.
            best = barcode;
            break;
        }
        float dx = x - barcode.getBoundingBox().centerX();
        float dy = y - barcode.getBoundingBox().centerY();
        float distance = (dx * dx) + (dy * dy); // actually squared distance
        if (distance < bestDistance) {
            best = barcode;
            bestDistance = distance;
        }
    }

    if (best != null) {
        Intent data = new Intent();
        data.putExtra(BarcodeObject, best);
        setResult(CommonStatusCodes.SUCCESS, data);

        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.barcode_toast,
                (ViewGroup) findViewById(R.id.custom_toast_container));

        Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
        //Barcode.DriverLicense dlBarcode = barcode.driverLicense;

        Barcode.DriverLicense sample = barcode.driverLicense;

        TextView name = (TextView) layout.findViewById(R.id.name);
        TextView address = (TextView) layout.findViewById(R.id.address);
        TextView cityStateZip = (TextView) layout.findViewById(R.id.cityStateZip);
        TextView gender = (TextView) layout.findViewById(R.id.gender);
        TextView dob = (TextView) layout.findViewById(R.id.dob);
        TableLayout tbl = (TableLayout) layout.findViewById(R.id.tableLayout);

        try {
            int age = DateDifference.generateAge(sample.birthDate);
            if (age < minAge)
                tbl.setBackgroundColor(Color.parseColor("#980517"));
            else
                tbl.setBackgroundColor(Color.parseColor("#617C17"));

        } catch (ParseException e) {
            e.printStackTrace();
        }

        String cityContent = new String(
                sample.addressCity + ", " + sample.addressState + " " + (sample.addressZip).substring(0, 5));

        address.setText(sample.addressStreet);
        cityStateZip.setText(cityContent);

        String genderString;
        if ((sample.gender).equals("1"))
            genderString = "Male";
        else if ((sample.gender).equals("2"))
            genderString = "Female";
        else
            genderString = "Other";

        gender.setText(genderString);

        dob.setText((sample.birthDate).substring(0, 2) + "/" + (sample.birthDate).substring(2, 4) + "/"
                + (sample.birthDate).substring(4, 8));

        String nameString = new String(sample.firstName + " " + sample.middleName + " " + sample.lastName);

        name.setText(nameString);

        Toast toast = new Toast(getApplicationContext());
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setView(layout);
        toast.show();

        Date today = Calendar.getInstance().getTime();
        String reportDate = df.format(today);
        SQLiteDatabase db = helper.getWritableDatabase();
        ContentValues row = new ContentValues();
        row.put("dateVar", reportDate);
        row.put("dobVar", sample.birthDate);
        row.put("zipVar", sample.addressZip);
        row.put("genderVar", genderString);
        db.insert("test", null, row);
        db.close();

        return true;
    }
    return false;
}

From source file:com.android.email.EmailNotificationController.java

@Override
public void handleUpdateNotificationIntent(Context context, Intent intent) {
    final Uri accountUri = intent.getParcelableExtra(UIProvider.UpdateNotificationExtras.EXTRA_ACCOUNT);
    final Uri folderUri = intent.getParcelableExtra(UIProvider.UpdateNotificationExtras.EXTRA_FOLDER);
    final int unreadCount = intent.getIntExtra(UIProvider.UpdateNotificationExtras.EXTRA_UPDATED_UNREAD_COUNT,
            0);//w ww  .j a  v a 2  s.  co m
    final int unseenCount = intent.getIntExtra(UIProvider.UpdateNotificationExtras.EXTRA_UPDATED_UNSEEN_COUNT,
            0);

    final ContentResolver contentResolver = context.getContentResolver();

    final Cursor accountCursor = contentResolver.query(accountUri, UIProvider.ACCOUNTS_PROJECTION, null, null,
            null);

    if (accountCursor == null) {
        LogUtils.e(LOG_TAG, "Null account cursor for account " + accountUri);
        return;
    }

    com.android.mail.providers.Account account = null;
    try {
        if (accountCursor.moveToFirst()) {
            account = com.android.mail.providers.Account.builder().buildFrom(accountCursor);
        }
    } finally {
        accountCursor.close();
    }

    if (account == null) {
        LogUtils.d(LOG_TAG, "Tried to create a notification for a missing account " + accountUri);
        return;
    }

    final Cursor folderCursor = contentResolver.query(folderUri, UIProvider.FOLDERS_PROJECTION, null, null,
            null);

    if (folderCursor == null) {
        LogUtils.e(LOG_TAG, "Null folder cursor for account " + accountUri + ", mailbox " + folderUri);
        return;
    }

    Folder folder = null;
    try {
        if (folderCursor.moveToFirst()) {
            folder = new Folder(folderCursor);
        } else {
            LogUtils.e(LOG_TAG, "Empty folder cursor for account " + accountUri + ", mailbox " + folderUri);
            return;
        }
    } finally {
        folderCursor.close();
    }

    // TODO: we don't always want getAttention to be true, but we don't necessarily have a
    // good heuristic for when it should or shouldn't be.
    NotificationUtils.sendSetNewEmailIndicatorIntent(context, unreadCount, unseenCount, account, folder,
            true /* getAttention */);
}

From source file:com.laevatein.internal.ui.PhotoSelectionActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUEST_CODE_CAPTURE && resultCode == Activity.RESULT_OK) {
        Uri captured = mMediaStoreCompat.getCapturedPhotoUri(data, mCapturePhotoUriHolder);
        if (captured != null) {
            mCollection.add(captured);//from  w  ww  . java2s.c  o  m
            mMediaStoreCompat.cleanUp(mCapturePhotoUriHolder);
        }
        supportInvalidateOptionsMenu();
    } else if (requestCode == REQUEST_CODE_PREVIEW && resultCode == Activity.RESULT_OK) {
        boolean checked = data.getBooleanExtra(ImagePreviewActivity.EXTRA_RESULT_CHECKED, false);
        Item item = data.getParcelableExtra(ImagePreviewActivity.EXTRA_RESULT_ITEM);
        if (checked) {
            mCollection.add(item.buildContentUri());
        } else {
            mCollection.remove(item.buildContentUri());
        }
        PhotoSelectionViewHelper.refreshGridView(this);
        supportInvalidateOptionsMenu();
    }
}