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:com.chatwing.whitelabel.fragments.ConversationMessagesFragment.java

private void onCreateConversationResult(Conversation conversation) {
    if (conversation == null) {
        return;// w w  w. j av  a2  s  . c om
    }
    //Create conversation if not existed
    ContentValues conversationContentValues = ConversationTable.getContentValues(conversation,
            mUserManager.getCurrentUser());
    Cursor cursor = null;
    try {
        cursor = getActivity().getContentResolver().query(
                ChatWingContentProvider.getConversationWithIdUri(conversation.getId()),
                new String[] { ConversationTable.CONVERSATION_ID }, null, null, null);
        if (cursor.getCount() == 0) {
            Uri insert = getActivity().getContentResolver()
                    .insert(ChatWingContentProvider.getConversationsUri(), conversationContentValues);
            if ("-1".equals(insert.getLastPathSegment())) {
                LogUtils.v("insert conversation failed ");
                return;
            }
        }

        mCurrentConversationManager.loadConversation(conversation.getId());
    } finally {
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
    }
}

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

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

From source file:dev.drsoran.moloko.activities.TaskActivity.java

public String getTaskIdFromIntent() {
    String taskId = null;//from ww  w  .j  a va2s  .  c  o m

    final Uri taskUri = getIntent().getData();

    if (taskUri != null)
        taskId = taskUri.getLastPathSegment();

    return taskId;
}

From source file:org.wheelmap.android.fragment.POIsListWorkerFragment.java

public long createNewPOI() {
    // create new POI and start editing
    ContentValues cv = new ContentValues();
    cv.put(Wheelmap.POIs.NAME, getString(R.string.new_default_name));
    cv.put(Wheelmap.POIs.COORD_LAT, Math.ceil(mLocation.getLatitude() * 1E6));
    cv.put(Wheelmap.POIs.COORD_LON, Math.ceil(mLocation.getLongitude() * 1E6));
    cv.put(Wheelmap.POIs.CATEGORY_ID, 1);
    cv.put(Wheelmap.POIs.NODETYPE_ID, 1);

    Uri new_pois = getActivity().getContentResolver().insert(Wheelmap.POIs.CONTENT_URI, cv);

    // edit activity
    Log.i(TAG, new_pois.toString());
    long poiId = Long.parseLong(new_pois.getLastPathSegment());
    return poiId;
}

From source file:com.geekandroid.sdk.sample.crop.ResultActivity.java

private void copyFileToDownloads(Uri croppedFileUri) throws Exception {
    String downloadsDirectoryPath = Environment
            .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
    String filename = String.format("%d_%s", Calendar.getInstance().getTimeInMillis(),
            croppedFileUri.getLastPathSegment());

    File saveFile = new File(downloadsDirectoryPath, filename);

    FileInputStream inStream = new FileInputStream(new File(croppedFileUri.getPath()));
    FileOutputStream outStream = new FileOutputStream(saveFile);
    FileChannel inChannel = inStream.getChannel();
    FileChannel outChannel = outStream.getChannel();
    inChannel.transferTo(0, inChannel.size(), outChannel);
    inStream.close();//from  w ww.java2s.c  o  m
    outStream.close();

    showNotification(saveFile);
}

From source file:ir.rasen.charsoo.controller.image_loader.core.download.BaseImageDownloader.java

/**
 * Retrieves {@link InputStream} of image by URI (image is accessed using {@link ContentResolver}).
 *
 * @param imageUri Image URI// ww w .jav a 2s .  c  om
 * @param extra    Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object)
 *                 DisplayImageOptions.extraForDownloader(Object)}; can be null
 * @return {@link InputStream} of image
 * @throws FileNotFoundException if the provided URI could not be opened
 */
protected InputStream getStreamFromContent(String imageUri, Object extra) throws FileNotFoundException {
    ContentResolver res = context.getContentResolver();

    Uri uri = Uri.parse(imageUri);
    if (isVideoContentUri(uri)) { // video thumbnail
        Long origId = Long.valueOf(uri.getLastPathSegment());
        Bitmap bitmap = MediaStore.Video.Thumbnails.getThumbnail(res, origId,
                MediaStore.Images.Thumbnails.MINI_KIND, null);
        if (bitmap != null) {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bitmap.compress(CompressFormat.PNG, 0, bos);
            return new ByteArrayInputStream(bos.toByteArray());
        }
    } else if (imageUri.startsWith(CONTENT_CONTACTS_URI_PREFIX)) { // contacts photo
        return getContactPhotoStream(uri);
    }

    return res.openInputStream(uri);
}

From source file:com.fabernovel.alertevoirie.data.CategoryProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    JSONArray array = new JSONArray();
    try {/*from   w  w w  . j a  v a2  s  .com*/
        String categoryId = JsonData.VALUE_NULL;
        switch (uriMatcher.match(uri)) {
        case CATEGORIES_ID:
            categoryId = uri.getLastPathSegment();
            //$FALL-THROUGH$
        case CATEGORIES:
            JSONObject parent = categories.getJSONObject(categoryId);
            if (parent.has(JsonData.PARAM_CATEGORY_CHILDREN)) {
                JSONArray subset = parent.getJSONArray(JsonData.PARAM_CATEGORY_CHILDREN);
                for (int i = 0; i < subset.length(); i++) {
                    JSONObject obj = categories.getJSONObject(subset.getString(i));
                    obj.put(BaseColumns._ID, (long) Integer.valueOf(subset.getString(i)));
                    array.put(obj);
                }
            }
            break;

        case CATEGORY_ID:
            categoryId = uri.getLastPathSegment();
            array.put(categories.getJSONObject(categoryId));
            Log.d(Constants.PROJECT_TAG, "category returned = " + categories.getJSONObject(categoryId));
            break;

        default:
            return null;
        }

    } catch (NumberFormatException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    Cursor c = new JSONCursor(array, projection);
    if (c != null)
        c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}

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

public void initData() {
    imageLoader = ImageLoader.getInstance();
    imageUrls = new ArrayList<String>();

    Intent intent = getIntent();/*from  w w  w  . j  a  v a  2 s  . c o m*/
    if (intent != null) {
        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            imageUrls = bundle.getStringArrayList(Extra.IMAGES);
            imagePosition = bundle.getInt(Extra.IMAGE_POSITION, 0);
            imageMode = bundle.getInt(Extra.IMAGE_MODE, 0);
            Log.i("The snowdream bundle path of the image is: " + imageUri);
        }

        Uri uri = (Uri) intent.getData();
        if (uri != null) {
            imageUri = uri.getPath();
            fileName = uri.getLastPathSegment();
            getSupportActionBar().setSubtitle(fileName);
            Log.i("The path of the image is: " + imageUri);

            File file = new File(imageUri);

            imageUri = "file://" + imageUri;
            File dir = file.getParentFile();
            if (dir != null) {
                FileFilter fileFilter = new FileFilter() {
                    @Override
                    public boolean accept(File f) {
                        if (f != null) {
                            String extension = MimeTypeMap
                                    .getFileExtensionFromUrl(Uri.encode(f.getAbsolutePath()));
                            if (!TextUtils.isEmpty(extension)) {
                                String mimeType = MimeTypeMap.getSingleton()
                                        .getMimeTypeFromExtension(extension);
                                if (!TextUtils.isEmpty(mimeType) && mimeType.contains("image")) {
                                    return true;
                                }
                            }
                        }
                        return false;
                    }
                };

                File[] files = dir.listFiles(fileFilter);

                if (files != null && files.length > 0) {
                    int size = files.length;

                    for (int i = 0; i < size; i++) {
                        imageUrls.add("file://" + files[i].getAbsolutePath());
                    }
                    imagePosition = imageUrls.indexOf(imageUri);
                    imageMode = 1;
                    Log.i("Image Position:" + imagePosition);
                }

            } else {
                imageUrls.add("file://" + imageUri);
                imagePosition = 0;
                imageMode = 0;
            }
        }
    }

    else

    {
        Log.w("The intent is null!");
    }

}

From source file:de.bahnhoefe.deutschlands.bahnhofsfotos.MyDataActivity.java

private void receiveUploadToken(Intent intent) {
    if (intent != null) {
        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            Uri data = intent.getData();
            if (data != null) {
                profile.setUploadToken(data.getLastPathSegment());
                etUploadToken.setText(profile.getUploadToken());
                baseApplication.setUploadToken(profile.getUploadToken());
                loadRemoteProfile();/* www .  j  a v a  2 s.  c o  m*/
            }
        }
    }
}

From source file:de.hshannover.f4.trust.ironcontrol.view.SimpleRequestFragment.java

public String saveSubscribtion(String savedName) {
    if (!isNameValid(savedName)) {
        return null;
    }//from w  w w  .  j  a  va2 s .c o m

    String id = getExistSubscriptionId(savedName);

    if (id != null) {
        return id;
    }

    String startIdentifier = sStartIdentifier.getSelectedItem().toString();
    String startIdentifierValue = etStartIdentifier.getText().toString();
    int maxDepth = sbMaxDepth.getProgress();

    ContentValues publishValues = new ContentValues();
    publishValues.put(Requests.COLUMN_NAME, savedName);
    publishValues.put(Requests.COLUMN_IDENTIFIER1, startIdentifier);
    publishValues.put(Requests.COLUMN_IDENTIFIER1_Value, startIdentifierValue);
    publishValues.put(Requests.COLUMN_MAX_DEPTH, maxDepth);

    Uri returnUri = getActivity().getContentResolver().insert(DBContentProvider.SUBSCRIPTION_URI,
            publishValues);
    return returnUri.getLastPathSegment();

}