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.linroid.pushapp.ui.send.SendActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_PACKAGE)) {
        this.pack = intent.getParcelableExtra(EXTRA_PACKAGE);
    } else if (intent.hasExtra(EXTRA_APPLICATION_INFO)) {
        this.appInfo = intent.getParcelableExtra(EXTRA_APPLICATION_INFO);
    } else {//from  ww w.j  a  va 2 s. c  o m
        throw new IllegalArgumentException("EXTRA_PACKAGE or EXTRA_APPLICATION_INFO extra data required");
    }
    dialog = new ProgressDialog(this);
    dialog.setMessage(getString(R.string.msg_upload_prepare));
    dialog.setMax(100);
    dialog.setCancelable(false);
    dialog.setIndeterminate(true);
    getSupportFragmentManager().beginTransaction().replace(R.id.container, new DeviceFragment()).commit();

    App.from(this).component().inject(this);
}

From source file:com.gsma.rcs.ri.messaging.geoloc.EditGeoloc.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
        return;/*from w w w  .j  a  v  a  2  s.c  o  m*/
    }
    switch (requestCode) {
    case REQUEST_CODE_SELECT_GEOLOC:
        Geoloc geoloc = data.getParcelableExtra(EXTRA_GEOLOC);
        mLatitudeEdit.setText(String.valueOf(geoloc.getLatitude()));
        mLongitudeEdit.setText(String.valueOf(geoloc.getLongitude()));
        break;
    }
}

From source file:com.money.manager.ex.search.SearchActivity.java

/**
 * Read the search request from the intent, if the activity was invoked from elsewhere.
 *//* w  ww  .  jav a 2 s  . c  o m*/
private void handleSearchRequest() {
    Intent intent = getIntent();
    if (intent == null)
        return;

    // see if we have the search criteria.
    Parcelable searchParcel = intent.getParcelableExtra(EXTRA_SEARCH_PARAMETERS);
    SearchParameters searchParameters = Parcels.unwrap(searchParcel);

    if (searchParameters != null) {
        getSearchFragment().setSearchParameters(searchParameters);
        performSearch();
    }
}

From source file:com.adkdevelopment.e_contact.DetailFragment.java

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

    View rootView = inflater.inflate(R.layout.detail_fragment_task, container, false);
    mUnbinder = ButterKnife.bind(this, rootView);

    // to prevent multiple calls to getContext()
    Context context = getContext();

    Intent intent = getActivity().getIntent();
    TaskItem newsItem;//from   ww w .j  ava  2s  . c o  m

    if (intent.hasExtra(TaskItem.TASKITEM)) {

        newsItem = intent.getParcelableExtra(TaskItem.TASKITEM);

        // Time parsing and creating a nice textual version (should be changed to Calendar)
        String dateCreated = Utilities.getFormattedDate(newsItem.getCreated());
        String dateRegistered = Utilities.getFormattedDate(newsItem.getRegistered());
        String dateAssigned = Utilities.getFormattedDate(newsItem.getAssigned());

        mTaskTitleText.setText(Utilities.getType(context, newsItem.getType()));
        mTaskStatus.setText(Utilities.getStatus(context, newsItem.getStatus()));

        // sets color of a status TextView shape according to the schema
        GradientDrawable gradientDrawable = (GradientDrawable) mTaskStatus.getBackground();
        gradientDrawable.setColor(Utilities.getBackgroundColor(context, newsItem.getStatus()));

        mTaskCreatedDate.setText(dateCreated);
        mTaskRegisteredDate.setText(dateRegistered);
        mTaskAssignedDate.setText(dateAssigned);
        mTaskResponsibleName.setText(newsItem.getResponsible());
        mTaskDescription.setText(Html.fromHtml(newsItem.getDescription()));

        Cursor cursor = context.getContentResolver().query(PhotosColumns.CONTENT_URI, null,
                PhotosColumns.TASK_ID + " LIKE ?", new String[] { "" + newsItem.getDatabaseId() }, null);

        if (cursor != null) {
            List<String> photos = new ArrayList<>(cursor.getCount());

            while (cursor.moveToNext()) {
                photos.add(cursor.getString(cursor.getColumnIndex(PhotosColumns.URL)));
            }
            cursor.close();
            newsItem.setPhoto(photos);
        }

    } else {
        // If there is no outside intent - fetch example photos
        List<String> dummyPhotos = new ArrayList<>();
        dummyPhotos.addAll(Arrays.asList(getResources().getStringArray(R.array.task_image_links)));

        newsItem = new TaskItem();
        newsItem.setPhoto(dummyPhotos);
    }

    // To boost performance as we know that size won't change
    mRecyclerView.setHasFixedSize(true);

    // Horizontal LayoutManager
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context, RecyclerView.HORIZONTAL, false);

    mRecyclerView.setLayoutManager(layoutManager);

    // Adapter with data about different activities
    PhotoAdapter photoAdapter = new PhotoAdapter(newsItem.getPhoto(), context, this);
    mRecyclerView.setAdapter(photoAdapter);

    return rootView;
}

From source file:com.google.android.gms.samples.wallet.ConfirmationActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CODE_CHANGE_MASKED_WALLET:
        if (resultCode == Activity.RESULT_OK && data.hasExtra(WalletConstants.EXTRA_MASKED_WALLET)) {
            mMaskedWallet = data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET);
            ((FullWalletConfirmationButtonFragment) getResultTargetFragment())
                    .updateMaskedWallet(mMaskedWallet);
            displayLoyaltyInformation();
        }//from   w  w w. j a v a  2s  .  c om
        // you may also want to use the new masked wallet data here, say to recalculate
        // shipping or taxes if shipping address changed
        break;
    case WalletConstants.RESULT_ERROR:
        int errorCode = data.getIntExtra(WalletConstants.EXTRA_ERROR_CODE, 0);
        handleError(errorCode);
        break;
    default:
        super.onActivityResult(requestCode, resultCode, data);
        break;
    }
}

From source file:com.dgsd.android.ShiftTracker.Service.NotificationService.java

@Override
protected void onHandleIntent(final Intent inIntent) {
    final String action = inIntent.getAction();
    if (TextUtils.isEmpty(action)) {
        return;/*from  w w  w.  j  a va2s  . c o m*/
    }

    if (TextUtils.equals(action, ACTION_SHOW_ALARM)) {
        final Shift shift = inIntent.getParcelableExtra(EXTRA_SHIFT);
        if (shift != null && shift.id != -1) {
            showAlarmNotification(shift);
        }
    }
}

From source file:com.qiscus.sdk.filepicker.MediaDetailsActivity.java

private void initView() {
    Intent intent = getIntent();
    if (intent != null) {
        fileType = intent.getIntExtra(FilePickerConst.EXTRA_FILE_TYPE, FilePickerConst.MEDIA_TYPE_IMAGE);
        PhotoDirectory photoDirectory = intent.getParcelableExtra(PhotoDirectory.class.getSimpleName());
        if (photoDirectory != null) {
            setUpView(photoDirectory);/* ww  w.  j  a  v  a  2s  .co m*/
            PickerManager.getInstance().setPickerManagerListener(this);
        }
    }
}

From source file:com.google.android.apps.mytracks.io.file.ImportActivity.java

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

    Intent intent = getIntent();
    importAll = intent.getBooleanExtra(EXTRA_IMPORT_ALL, false);
    trackFileFormat = intent.getParcelableExtra(EXTRA_TRACK_FILE_FORMAT);
    if (trackFileFormat == null) {
        trackFileFormat = TrackFileFormat.GPX;
    }/*  w  ww .  ja v  a2 s .  c  o m*/

    if (!FileUtils.isExternalStorageAvailable()) {
        Toast.makeText(this, R.string.external_storage_not_available, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    if (importAll) {
        path = FileUtils.buildExternalDirectoryPath(trackFileFormat == TrackFileFormat.KML ? "kml" : "gpx");
        if (!FileUtils.isDirectory(new File(path))) {
            Toast.makeText(this, getString(R.string.import_no_directory, path), Toast.LENGTH_LONG).show();
            finish();
            return;
        }
    } else {
        String action = intent.getAction();
        if (!(Intent.ACTION_ATTACH_DATA.equals(action) || Intent.ACTION_VIEW.equals(action))) {
            Log.d(TAG, "Invalid action: " + intent);
            finish();
            return;
        }

        Uri data = intent.getData();
        if (!UriUtils.isFileUri(data)) {
            Log.d(TAG, "Invalid data: " + intent);
            finish();
            return;
        }
        path = data.getPath();
    }

    Object retained = getLastNonConfigurationInstance();
    if (retained instanceof ImportAsyncTask) {
        importAsyncTask = (ImportAsyncTask) retained;
        importAsyncTask.setActivity(this);
    } else {
        importAsyncTask = new ImportAsyncTask(this, importAll, trackFileFormat, path);
        importAsyncTask.execute();
    }
}

From source file:ca.mudar.mtlaucasou.services.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    if (receiver != null) {
        receiver.send(STATUS_RUNNING, Bundle.EMPTY);
    }/*from   w  w  w  . j  a  v a 2  s.  c om*/

    final Context context = this;

    try {
        // Bulk of sync work, performed by executing several fetches from
        // local and online sources.

        final long startLocal = System.currentTimeMillis();

        /**
         * Five Assets files to load, so progress goes by 20%.
         */
        Bundle bundle = new Bundle();
        bundle.putInt(Const.KEY_BUNDLE_PROGRESS_INCREMENT, 20);

        // Parse values from local cache first, since SecurityServices copy
        // or network might be down.

        receiver.send(STATUS_RUNNING, bundle);
        mLocalExecutor.execute(context, KmlLocalAssets.FIRE_HALLS,
                new RemotePlacemarksHandler(FireHalls.CONTENT_URI, true));

        receiver.send(STATUS_RUNNING, bundle);
        mLocalExecutor.execute(context, KmlLocalAssets.SPVM_STATIONS,
                new RemotePlacemarksHandler(SpvmStations.CONTENT_URI, true));

        receiver.send(STATUS_RUNNING, bundle);
        mLocalExecutor.execute(context, KmlLocalAssets.WATER_SUPPLIES,
                new RemotePlacemarksHandler(WaterSupplies.CONTENT_URI));

        receiver.send(STATUS_RUNNING, bundle);
        mLocalExecutor.execute(context, KmlLocalAssets.EMERGENCY_HOSTELS,
                new RemotePlacemarksHandler(EmergencyHostels.CONTENT_URI));

        receiver.send(STATUS_RUNNING, bundle);
        mLocalExecutor.execute(context, KmlLocalAssets.CONDITIONED_PLACES,
                new RemotePlacemarksHandler(ConditionedPlaces.CONTENT_URI));

        Log.v(TAG, "Sync duration: " + (System.currentTimeMillis() - startLocal) + " ms");

        // TODO: update data from remote source
        // Always hit remote SecurityServices for any updates
        // final long startRemote = System.currentTimeMillis();
        // mRemoteExecutor
        // .executeGet(WORKSHEETS_URL, new
        // RemoteSecurityServicesHandler(mRemoteExecutor));
        // Log.d(TAG, "remote sync took " + (System.currentTimeMillis() -
        // startRemote) + "ms");

    } catch (Exception e) {
        Log.e(TAG, e.getMessage());

        if (receiver != null) {
            /**
             * Pass back error to surface listener
             */
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    }

    if (receiver != null) {
        receiver.send(STATUS_FINISHED, Bundle.EMPTY);
    }
}

From source file:org.cvasilak.jboss.mobile.app.service.UploadToJBossServerService.java

@Override
protected void onHandleIntent(Intent intent) {
    // initialize

    // extract details
    Server server = intent.getParcelableExtra("server");
    String directory = intent.getStringExtra("directory");
    String filename = intent.getStringExtra("filename");

    // get the json parser from the application
    JsonParser jsonParser = new JsonParser();

    // start the ball rolling...
    final NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    builder.setTicker(String.format(getString(R.string.notif_ticker), filename))
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_notif_large))
            .setSmallIcon(R.drawable.ic_stat_notif_small)
            .setContentTitle(String.format(getString(R.string.notif_title), filename))
            .setContentText(getString(R.string.notif_content_init))
            // to avoid NPE on android 2.x where content intent is required
            // set an empty content intent
            .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0)).setOngoing(true);

    // notify user that upload is starting
    mgr.notify(NOTIFICATION_ID, builder.build());

    // reset ticker for any subsequent notifications
    builder.setTicker(null);/*from  w w  w . ja  v a 2s  .c  o  m*/

    AbstractHttpClient client = CustomHTTPClient.getHttpClient();

    // enable digest authentication
    if (server.getUsername() != null && !server.getUsername().equals("")) {
        Credentials credentials = new UsernamePasswordCredentials(server.getUsername(), server.getPassword());

        client.getCredentialsProvider().setCredentials(
                new AuthScope(server.getHostname(), server.getPort(), AuthScope.ANY_REALM), credentials);
    }

    final File file = new File(directory, filename);
    final long length = file.length();

    try {
        CustomMultiPartEntity multipart = new CustomMultiPartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,
                new CustomMultiPartEntity.ProgressListener() {
                    @Override
                    public void transferred(long num) {
                        // calculate percentage

                        //System.out.println("transferred: " + num);

                        int progress = (int) ((num * 100) / length);

                        builder.setContentText(String.format(getString(R.string.notif_content), progress));

                        mgr.notify(NOTIFICATION_ID, builder.build());
                    }
                });

        multipart.addPart(file.getName(), new FileBody(file));

        HttpPost httpRequest = new HttpPost(server.getHostPort() + "/management/add-content");
        httpRequest.setEntity(multipart);

        HttpResponse serverResponse = client.execute(httpRequest);

        BasicResponseHandler handler = new BasicResponseHandler();
        JsonObject reply = jsonParser.parse(handler.handleResponse(serverResponse)).getAsJsonObject();

        if (!reply.has("outcome")) {
            throw new RuntimeException(getString(R.string.invalid_response));
        } else {
            // remove the 'upload in-progress' notification
            mgr.cancel(NOTIFICATION_ID);

            String outcome = reply.get("outcome").getAsString();

            if (outcome.equals("success")) {

                String BYTES_VALUE = reply.get("result").getAsJsonObject().get("BYTES_VALUE").getAsString();

                Intent resultIntent = new Intent(this, UploadCompletedActivity.class);
                // populate it
                resultIntent.putExtra("server", server);
                resultIntent.putExtra("BYTES_VALUE", BYTES_VALUE);
                resultIntent.putExtra("filename", filename);
                resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

                // the notification id for the 'completed upload' notification
                // each completed upload will have a different id
                int notifCompletedID = (int) System.currentTimeMillis();

                builder.setContentTitle(getString(R.string.notif_title_uploaded))
                        .setContentText(String.format(getString(R.string.notif_content_uploaded), filename))
                        .setContentIntent(
                                // we set the (2nd param request code to completedID)
                                // see http://tinyurl.com/kkcedju
                                PendingIntent.getActivity(this, notifCompletedID, resultIntent,
                                        PendingIntent.FLAG_UPDATE_CURRENT))
                        .setAutoCancel(true).setOngoing(false);

                mgr.notify(notifCompletedID, builder.build());

            } else {
                JsonElement elem = reply.get("failure-description");

                if (elem.isJsonPrimitive()) {
                    throw new RuntimeException(elem.getAsString());
                } else if (elem.isJsonObject())
                    throw new RuntimeException(
                            elem.getAsJsonObject().get("domain-failure-description").getAsString());
            }
        }

    } catch (Exception e) {
        builder.setContentText(e.getMessage()).setAutoCancel(true).setOngoing(false);

        mgr.notify(NOTIFICATION_ID, builder.build());
    }
}