Example usage for android.net Uri getLastPathSegment

List of usage examples for android.net Uri getLastPathSegment

Introduction

In this page you can find the example usage for android.net Uri getLastPathSegment.

Prototype

@Nullable
public abstract String getLastPathSegment();

Source Link

Document

Gets the decoded last segment in the path.

Usage

From source file:org.ale.scanner.zotero.data.BibItem.java

public void writeToDB(ContentResolver cr) {
    ContentValues values = toContentValues();
    if (mId == NO_ID) {
        Uri row = cr.insert(Database.BIBINFO_URI, values);
        int id = Integer.parseInt(row.getLastPathSegment());
        setId(id);/*from w ww. j  av a 2s . co m*/
    } else {
        cr.update(Database.BIBINFO_URI, values, BibItem._ID + "=?", new String[] { String.valueOf(mId) });
    }
}

From source file:com.example.android.honeypad.ui.HomeActivity.java

@Override
public void onNoteCreated(Uri noteUri) {
    NoteListFragment list = (NoteListFragment) getSupportFragmentManager().findFragmentById(R.id.list);
    list.setActivatedNoteAfterLoad(Long.valueOf(noteUri.getLastPathSegment()));
}

From source file:com.owncloud.android.providers.UsersAndGroupsSearchProvider.java

private Cursor searchForUsersOrGroups(Uri uri) {
    MatrixCursor response = null;/*from w w w. j ava2s  . com*/

    String userQuery = uri.getLastPathSegment().toLowerCase();

    /// need to trust on the AccountUtils to get the current account since the query in the client side is not
    /// directly started by our code, but from SearchView implementation
    Account account = AccountUtils.getCurrentOwnCloudAccount(getContext());

    /// request to the OC server about users and groups matching userQuery
    GetRemoteShareesOperation searchRequest = new GetRemoteShareesOperation(userQuery, REQUESTED_PAGE,
            RESULTS_PER_PAGE);
    RemoteOperationResult result = searchRequest.execute(account, getContext());
    List<JSONObject> names = new ArrayList<JSONObject>();
    if (result.isSuccess()) {
        for (Object o : result.getData()) {
            // Get JSonObjects from response
            names.add((JSONObject) o);
        }
    } else {
        showErrorMessage(result);
    }

    /// convert the responses from the OC server to the expected format
    if (names.size() > 0) {
        response = new MatrixCursor(COLUMNS);
        Iterator<JSONObject> namesIt = names.iterator();
        int count = 0;
        JSONObject item;
        String displayName;
        Uri dataUri;
        Uri userBaseUri = new Uri.Builder().scheme("content").authority(DATA_USER).build();
        Uri groupBaseUri = new Uri.Builder().scheme("content").authority(DATA_GROUP).build();
        try {
            while (namesIt.hasNext()) {
                item = namesIt.next();
                String userName = item.getString(GetRemoteShareesOperation.PROPERTY_LABEL);
                JSONObject value = item.getJSONObject(GetRemoteShareesOperation.NODE_VALUE);
                byte type = (byte) value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE);
                String shareWith = value.getString(GetRemoteShareesOperation.PROPERTY_SHARE_WITH);
                if (GetRemoteShareesOperation.GROUP_TYPE.equals(type)) {
                    displayName = getContext().getString(R.string.share_group_clarification, userName);
                    dataUri = Uri.withAppendedPath(groupBaseUri, shareWith);
                } else {
                    displayName = userName;
                    dataUri = Uri.withAppendedPath(userBaseUri, shareWith);
                }
                response.newRow().add(count++) // BaseColumns._ID
                        .add(displayName) // SearchManager.SUGGEST_COLUMN_TEXT_1
                        .add(dataUri);
            }
        } catch (JSONException e) {
            Log_OC.e(TAG, "Exception while parsing data of users/groups", e);
        }
    }

    return response;
}

From source file:com.mutu.gpstracker.breadcrumbs.DownloadBreadcrumbsTrackTask.java

@Override
protected void onPostExecute(Uri result) {
    super.onPostExecute(result);

    long ogtTrackId = Long.parseLong(result.getLastPathSegment());
    Uri metadataUri = Uri.withAppendedPath(ContentUris.withAppendedId(Tracks.CONTENT_URI, ogtTrackId),
            "metadata");

    BreadcrumbsTracks tracks = mAdapter.getBreadcrumbsTracks();
    Integer bcTrackId = mTrack.second;
    Integer bcBundleId = tracks.getBundleIdForTrackId(bcTrackId);
    //TODO Integer bcActivityId = tracks.getActivityIdForBundleId(bcBundleId);
    String bcDifficulty = tracks.getValueForItem(mTrack, BreadcrumbsTracks.DIFFICULTY);
    String bcRating = tracks.getValueForItem(mTrack, BreadcrumbsTracks.RATING);
    String bcPublic = tracks.getValueForItem(mTrack, BreadcrumbsTracks.ISPUBLIC);
    String bcDescription = tracks.getValueForItem(mTrack, BreadcrumbsTracks.DESCRIPTION);

    ArrayList<ContentValues> metaValues = new ArrayList<ContentValues>();
    if (bcTrackId != null) {
        metaValues.add(buildContentValues(BreadcrumbsTracks.TRACK_ID, Long.toString(bcTrackId)));
    }//ww w  .ja va2  s.  c o  m
    if (bcDescription != null) {
        metaValues.add(buildContentValues(BreadcrumbsTracks.DESCRIPTION, bcDescription));
    }
    if (bcDifficulty != null) {
        metaValues.add(buildContentValues(BreadcrumbsTracks.DIFFICULTY, bcDifficulty));
    }
    if (bcRating != null) {
        metaValues.add(buildContentValues(BreadcrumbsTracks.RATING, bcRating));
    }
    if (bcPublic != null) {
        metaValues.add(buildContentValues(BreadcrumbsTracks.ISPUBLIC, bcPublic));
    }
    if (bcBundleId != null) {
        metaValues.add(buildContentValues(BreadcrumbsTracks.BUNDLE_ID, Integer.toString(bcBundleId)));
    }
    //      if (bcActivityId != null)
    //      {
    //         metaValues.add(buildContentValues(BreadcrumbsTracks.ACTIVITY_ID, Integer.toString(bcActivityId)));
    //      }
    ContentResolver resolver = mContext.getContentResolver();
    resolver.bulkInsert(metadataUri, metaValues.toArray(new ContentValues[1]));

    tracks.addSyncedTrack(ogtTrackId, mTrack.second);

}

From source file:de.aw.awlib.gv.CalendarReminder.java

/**
 * Erstellt einen Event im ausgewaehlten Caleendar
 *
 * @param calendarID/*from   w w w. j a v  a2 s  .  c  om*/
 *         ID des ausgewaehlten Kalenders
 * @param start
 *         Startdatum des Events
 * @param dauer
 *         Dauer des Events
 * @param title
 *         Title des Events
 * @param body
 *         Body des Events (optional)
 * @return die ID des eingefuegten Events. -1, wenn ein Fehler aufgetreten ist.
 */
public long createEvent(long calendarID, @NonNull Date start, long dauer, @NonNull String title,
        @Nullable String body) {
    long id = -1;
    if (ContextCompat.checkSelfPermission(mContext,
            Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED) {
        ContentResolver cr = mContext.getContentResolver();
        ContentValues values = createEventValues(calendarID, start, dauer, title, body);
        Uri uri = cr.insert(Events.CONTENT_URI, values);
        if (uri != null) {
            id = Long.parseLong(uri.getLastPathSegment());
        }
    }
    return id;
}

From source file:com.github.snowdream.android.apps.imageviewer.ImageViewerActivity.java

@Override
public void onPageSelected(int position) {
    Log.i("onPageSelected position:" + position);
    if (imageUrls != null && imageUrls.size() > position) {
        imageUri = imageUrls.get(position);

        Uri uri = Uri.parse(imageUri);
        fileName = uri.getLastPathSegment();
        getSupportActionBar().setSubtitle(fileName);
        Log.i("The path of the image is: " + imageUri);
    }//from   w  ww.  j  a  va  2 s . c  om

    Intent shareIntent = createShareIntent();
    if (shareIntent != null) {
        doShare(shareIntent);
    }
    Log.i("onPageSelected imageUri:" + imageUri);
}

From source file:com.android.gallery3d.filtershow.info.InfoPanel.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getDialog() != null) {
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    }/*from   www .ja  v a 2s  .  c  om*/

    mMainView = (LinearLayout) inflater.inflate(R.layout.filtershow_info_panel, null, false);

    mImageThumbnail = (ImageView) mMainView.findViewById(R.id.imageThumbnail);
    Bitmap bitmap = MasterImage.getImage().getFilteredImage();
    mImageThumbnail.setImageBitmap(bitmap);

    mImageName = (TextView) mMainView.findViewById(R.id.imageName);
    mImageSize = (TextView) mMainView.findViewById(R.id.imageSize);
    mExifData = (TextView) mMainView.findViewById(R.id.exifData);
    TextView exifLabel = (TextView) mMainView.findViewById(R.id.exifLabel);

    HistogramView histogramView = (HistogramView) mMainView.findViewById(R.id.histogramView);
    histogramView.setBitmap(bitmap);

    Uri uri = MasterImage.getImage().getUri();
    String path = ImageLoader.getLocalPathFromUri(getActivity(), uri);
    Uri localUri = null;
    if (path != null) {
        localUri = Uri.parse(path);
    }

    if (localUri != null) {
        mImageName.setText(localUri.getLastPathSegment());
    }
    Rect originalBounds = MasterImage.getImage().getOriginalBounds();
    mImageSize.setText("" + originalBounds.width() + " x " + originalBounds.height());

    List<ExifTag> exif = MasterImage.getImage().getEXIF();
    String exifString = "";
    boolean hasExifData = false;
    if (exif != null) {
        for (ExifTag tag : exif) {
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_MODEL, R.string.filtershow_exif_model);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_APERTURE_VALUE,
                    R.string.filtershow_exif_aperture);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_FOCAL_LENGTH,
                    R.string.filtershow_exif_focal_length);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_ISO_SPEED_RATINGS,
                    R.string.filtershow_exif_iso);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_SUBJECT_DISTANCE,
                    R.string.filtershow_exif_subject_distance);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_DATE_TIME_ORIGINAL,
                    R.string.filtershow_exif_date);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_F_NUMBER,
                    R.string.filtershow_exif_f_stop);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_EXPOSURE_TIME,
                    R.string.filtershow_exif_exposure_time);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_COPYRIGHT,
                    R.string.filtershow_exif_copyright);
            hasExifData = true;
        }
    }
    if (hasExifData) {
        exifLabel.setVisibility(View.VISIBLE);
        mExifData.setText(Html.fromHtml(exifString));
    } else {
        exifLabel.setVisibility(View.GONE);
    }
    return mMainView;
}

From source file:org.godotengine.godot.storage.DownloadService.java

private void downloadToFile(final String downloadPath, final String downloadTo) {
    if (Utils.isExternalStorageWritable()) {
        Utils.d("SD:CanWrite");
    } else {/*from  w  w w.jav a 2  s .  c  om*/
        Utils.d("SD:CannotWrite");
    }

    File rootPath = new File(Environment.getExternalStorageDirectory(), downloadTo);

    if (!rootPath.exists()) {
        rootPath.mkdirs();
    }

    Uri fileUri = Uri.parse(downloadPath);
    File localFile = new File(rootPath, fileUri.getLastPathSegment());

    taskStarted();
    showProgressNotification("Progress downloading", 0, 0);

    mStorageRef.child(downloadPath).getFile(localFile)
            .addOnProgressListener(new OnProgressListener<FileDownloadTask.TaskSnapshot>() {
                @Override
                public void onProgress(FileDownloadTask.TaskSnapshot taskSnapshot) {
                    long totalBytes = taskSnapshot.getTotalByteCount();
                    long bytesDownloaded = taskSnapshot.getBytesTransferred();

                    onMainProgress(downloadPath, bytesDownloaded, totalBytes);
                }
            }).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
                    onMainSuccess(downloadPath, taskSnapshot.getTotalByteCount());
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception exception) {
                    onMainFailure(downloadPath, exception);
                }
            });
}

From source file:com.packpublishing.asynchronousandroid.chapter5.UploadArtworkIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Uri data = intent.getData();
    Log.i("Upload Service", "New  upload file " + data.toString());

    // unique id per upload, so each has its own notification
    int id = Integer.parseInt(data.getLastPathSegment());
    String msg = String.format("Uploading %s.jpg", id);

    ProgressNotificationCallback progress = new ProgressNotificationCallback(this, id, msg);
    // On Upload sucess
    if (mImageUploader.upload(data, progress)) {
        Log.i("Upload Service", "Upload complete for file " + data.toString());
        progress.onComplete(String.format("Upload finished for %s.jpg", id));
    } else {// ww w .  ja  v  a2 s.  com
        Log.i("Upload Service", "Upload failed for file " + data.toString());
        progress.onComplete(String.format("Upload failed %s.jpg", id));
    }
}

From source file:com.example.linhdq.test.documents.viewing.single.TableOfContentsActivity.java

@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
    final Uri documentUri = getIntent().getData();
    final String selection = DocumentContentProvider.Columns.PARENT_ID + "=? OR "
            + DocumentContentProvider.Columns.ID + "=?";
    final String[] args = new String[] { documentUri.getLastPathSegment(), documentUri.getLastPathSegment() };
    return new CursorLoader(this, DocumentContentProvider.CONTENT_URI, PROJECTION, selection, args,
            "created ASC");
}