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.andrew.apolloMod.activities.QueryBrowserActivity.java

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
    if (mAdapter != null) {
        getQueryCursor(mAdapter.getQueryHandler(), null);
    }/* w w w . ja  v  a 2  s.  c  om*/

    Intent intent = getIntent();
    String action = intent != null ? intent.getAction() : null;

    if (Intent.ACTION_VIEW.equals(action)) {
        // this is something we got from the search bar
        Uri uri = intent.getData();
        String path = uri.toString();
        if (path.startsWith("content://media/external/audio/media/")) {
            // This is a specific file
            String id = uri.getLastPathSegment();
            long[] list = new long[] { Long.valueOf(id) };
            MusicUtils.playAll(this, list, 0);
            finish();
            return;
        } else if (path.startsWith("content://media/external/audio/albums/")) {
            // This is an album, show the songs on it
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
            i.putExtra("album", uri.getLastPathSegment());
            startActivity(i);
            finish();
            return;
        } else if (path.startsWith("content://media/external/audio/artists/")) {
            intent = new Intent(Intent.ACTION_VIEW);

            Bundle bundle = new Bundle();
            bundle.putString(MIME_TYPE, Audio.Artists.CONTENT_TYPE);
            bundle.putString(ARTIST_KEY, uri.getLastPathSegment());
            bundle.putLong(BaseColumns._ID, ApolloUtils.getArtistId(uri.getLastPathSegment(), ARTIST_ID, this));

            intent.setClass(this, TracksBrowser.class);
            intent.putExtras(bundle);
            startActivity(intent);
            return;
        }
    }

    mFilterString = intent.getStringExtra(SearchManager.QUERY);
    if (MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) {
        String focus = intent.getStringExtra(MediaStore.EXTRA_MEDIA_FOCUS);
        String artist = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ARTIST);
        String album = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ALBUM);
        String title = intent.getStringExtra(MediaStore.EXTRA_MEDIA_TITLE);
        if (focus != null) {
            if (focus.startsWith("audio/") && title != null) {
                mFilterString = title;
            } else if (focus.equals(Audio.Albums.ENTRY_CONTENT_TYPE)) {
                if (album != null) {
                    mFilterString = album;
                    if (artist != null) {
                        mFilterString = mFilterString + " " + artist;
                    }
                }
            } else if (focus.equals(Audio.Artists.ENTRY_CONTENT_TYPE)) {
                if (artist != null) {
                    mFilterString = artist;
                }
            }
        }
    }

    setContentView(R.layout.listview);
    mTrackList = getListView();
    mTrackList.setTextFilterEnabled(true);
    if (mAdapter == null) {
        mAdapter = new QueryListAdapter(getApplication(), this, R.layout.listview_items, null, // cursor
                new String[] {}, new int[] {}, 0);
        setListAdapter(mAdapter);
        if (TextUtils.isEmpty(mFilterString)) {
            getQueryCursor(mAdapter.getQueryHandler(), null);
        } else {
            mTrackList.setFilterText(mFilterString);
            mFilterString = null;
        }
    } else {
        mAdapter.setActivity(this);
        setListAdapter(mAdapter);
        mQueryCursor = mAdapter.getCursor();
        if (mQueryCursor != null) {
            init(mQueryCursor);
        } else {
            getQueryCursor(mAdapter.getQueryHandler(), mFilterString);
        }
    }

    LinearLayout emptyness = (LinearLayout) findViewById(R.id.empty_view);
    emptyness.setVisibility(View.GONE);
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.FeedAnchorObj.java

@Override
public void afterDbInsertion(Context context, DbObj obj) {
    Uri feedUri = obj.getContainingFeed().getUri();
    String parentFeedName = obj.getJson().optString(PARENT_FEED_NAME);
    if (parentFeedName == null) {
        Log.e(TAG, "anchor for feed, but no parent given");
        return;//from w  w w . j a  v  a2  s.c om
    }

    Maybe<Group> parentGroup = Group.forFeedName(context, parentFeedName);
    if (!parentGroup.isKnown()) {
        Log.e(TAG, "No parent entry found for " + parentFeedName);
        return;
    }
    Long parentId = -1l;
    try {
        parentId = parentGroup.get().id;
    } catch (NoValError e) {
    }

    String feedName = feedUri.getLastPathSegment();
    Log.d(TAG, "Updating parent_feed_id for " + feedName);
    DBHelper mHelper = DBHelper.getGlobal(context);
    ContentValues cv = new ContentValues();
    cv.put(Group.PARENT_FEED_ID, parentId);
    mHelper.getWritableDatabase().update(Group.TABLE, cv, Group.FEED_NAME + "=?", new String[] { feedName });
    mHelper.close();
}

From source file:com.appsimobile.appsii.module.apps.AppsProvider.java

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    SqlArguments args = new SqlArguments(uri, selection, selectionArgs);

    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    int count;/*w  ww.jav  a 2s .  c  o m*/

    int match = sURLMatcher.match(uri);
    switch (match) {
    case TABLE_APPS_ITEM: {
        String id = uri.getLastPathSegment();
        count = db.delete(args.table, "_id=" + id, args.args);
        break;
    }
    case TABLE_APPS: {
        count = db.delete(args.table, args.where, args.args);
        break;
    }
    case TABLE_TAGS_ITEM: {
        String id = uri.getLastPathSegment();
        count = db.delete(args.table, "_id=" + id, args.args);
        break;
    }
    case TABLE_TAGS: {
        count = db.delete(args.table, args.where, args.args);
        break;
    }
    case TABLE_HISTORY_ITEM: {
        String id = uri.getLastPathSegment();
        count = db.delete(args.table, "_id=" + id, args.args);
        break;
    }
    case TABLE_HISTORY: {
        count = db.delete(args.table, args.where, args.args);
        break;
    }
    default: {
        throw new IllegalArgumentException("Unknown URL " + uri);
    }
    }
    if (count > 0) {
        sendNotify(uri);
    }

    return count;
}

From source file:com.hivewallet.androidclient.wallet.AddressBookProvider.java

@Override
public int update(final Uri uri, final ContentValues values, final String selection,
        final String[] selectionArgs) {
    if (uri.getPathSegments().size() != 1)
        throw new IllegalArgumentException(uri.toString());

    final String address = uri.getLastPathSegment();

    final int count = helper.getWritableDatabase().update(DATABASE_TABLE, values, KEY_ADDRESS + "=?",
            new String[] { address });

    if (count > 0)
        getContext().getContentResolver().notifyChange(uri, null);

    return count;
}

From source file:eu.e43.impeller.activity.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    m_pendingIntent = false;/*from   www  . j a  v  a  2  s  .c om*/
    Log.i(TAG, "New intent " + intent);

    if (intent.hasExtra(Constants.EXTRA_ACCOUNT)) {
        haveGotAccount((Account) intent.getParcelableExtra(Constants.EXTRA_ACCOUNT));
    }

    if (m_account == null) {
        setIntent(intent);
        m_pendingIntent = true;
        return;
    }

    String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action)) {
        Uri uri = intent.getData();
        if (uri == null)
            return;

        Uri id = null;
        if (uri.getScheme().equals("content") && uri.getHost().equals("eu.e43.impeller.content")) {
            id = Uri.parse(uri.getLastPathSegment());
        } else {
            id = uri;
        }

        setIntent(intent);
        showObjectInMode(Mode.OBJECT, id);
    } else if (Constants.ACTION_SHOW_FEED.equals(action)) {
        showFeed((Constants.FeedID) intent.getSerializableExtra(Constants.EXTRA_FEED_ID));
    } else {
        Log.d(TAG, "Unknown new intent " + intent);
    }
}

From source file:org.kontalk.ui.ConversationsActivity.java

void openConversation(Uri threadUri, boolean creatingGroup) {
    if (isDualPane()) {
        // load conversation
        String userId = threadUri.getLastPathSegment();
        Conversation conv = Conversation.loadFromUserId(this, userId);

        // get the old fragment
        AbstractComposeFragment f = getCurrentConversation();

        // check if we are replacing the same fragment
        Conversation oldConv = (f != null ? f.getConversation() : null);
        if (oldConv == null || conv == null || !oldConv.getRecipient().equals(conv.getRecipient())) {
            if (conv == null)
                f = AbstractComposeFragment.fromUserId(this, userId, creatingGroup);
            else//from w  ww .  j a  v  a 2s.  c  o m
                f = AbstractComposeFragment.fromConversation(this, conv, creatingGroup);

            // Execute a transaction, replacing any existing fragment
            // with this one inside the frame.
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.fragment_compose_message, f);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            ft.commitAllowingStateLoss();
        }
    } else {
        Intent i = ComposeMessage.fromUserId(this, threadUri.getLastPathSegment(), creatingGroup);
        if (i != null)
            startActivity(i);
        else
            Toast.makeText(this, R.string.contact_not_registered, Toast.LENGTH_LONG).show();
    }
}

From source file:org.teleportr.Ride.java

public Uri store(Context ctx) {
    if (!cv.containsKey(MODE))
        mode(Mode.CAR);//from  w  w  w. j  av  a  2 s.  c  o m
    if (!cv.containsKey(ACTIVE))
        activate();
    if (!cv.containsKey(PRICE))
        price(-1);
    if (!cv.containsKey(DIRTY))
        cv.put(DIRTY, FLAG_DRAFT);
    if (details != null)
        cv.put(DETAILS, details.toString());
    Uri ride;
    cv.put(PARENT_ID, 0);
    ride = ctx.getContentResolver().insert(RidesProvider.getRidesUri(ctx), cv);
    Integer id = Integer.valueOf(ride.getLastPathSegment());
    System.out.println("STORED " + id);
    if (subrides != null) {
        for (ContentValues v : subrides) {
            v.put(PARENT_ID, id);
            ctx.getContentResolver().insert(RidesProvider.getRidesUri(ctx), v);
            //                System.out.println("  SUB  " + Integer.valueOf(ride.getLastPathSegment()));
        }
    }
    return ride;
}

From source file:com.confidentsoftware.themebuilder.FlickrParser.java

private int addImagesFromJson(long wordId, String text, JSONObject queryResult) throws JSONException {
    JSONArray photos = queryResult.getJSONArray("photo");
    int numImages = 0;
    for (int i = 0; i < photos.length(); i++) {
        JSONObject photo = null;//w  w  w.j a  v  a  2s  .co m
        try {
            photo = photos.getJSONObject(i);
        } catch (JSONException e) {
            continue;
        }
        try {
            if (isPhotoOk(photo)) {
                String url = photo.getString(PHOTO_URL);
                String title = photo.getString("title");
                if (title.length() > MAX_TITLE_LENGTH) {
                    title = title.substring(0, MAX_TITLE_LENGTH - 3) + "...";
                }
                String id = photo.getString("id");
                Log.d(TAG, "Image: " + id);
                Uri imageUri = Images.findImage(mCr, Sites.CONTENT_URI_FLICKR, id);
                if (imageUri != null) {
                    Log.d(TAG, "Found existing image: " + imageUri);
                    // Just insert the mapping
                    Uri mappingUri = Dictionary.Words.CONTENT_URI.buildUpon().appendPath(String.valueOf(wordId))
                            .appendPath(Dictionary.PATH_IMAGES).appendPath(imageUri.getLastPathSegment())
                            .build();
                    Cursor c = mCr.query(mappingUri, PROJECTION_ID, null, null, null);
                    try {
                        if (!c.moveToNext()) {
                            mCr.insert(mappingUri, null);
                        }
                    } finally {
                        c.close();
                    }
                } else {
                    ContentValues values = new ContentValues();
                    values.put(Images.URL, url);
                    values.put(Images.SITE, ContentUris.parseId(Sites.CONTENT_URI_FLICKR));
                    values.put(Images.SITE_UNIQUE_NAME, id);
                    values.put(Images.WIDTH, photo.getInt(PHOTO_WIDTH));
                    values.put(Images.HEIGHT, photo.getInt(PHOTO_HEIGHT));
                    values.put(Images.THUMB_URL, photo.getString(THUMB_URL));
                    values.put(Images.NUM_FAVORITES, getNumFavorites(id));
                    imageUri = mCr.insert(Dictionary.BASE_CONTENT_URI.buildUpon()
                            .appendPath(Dictionary.PATH_WORDS).appendPath(String.valueOf(wordId))
                            .appendPath(Dictionary.PATH_IMAGES).build(), values);
                    //
                    // String ownerName = photo.getString("owner");
                    // Author author = findAuthor(ownerName);
                    // if (author == null) {
                    // author = buildAuthor(ownerName);
                    // }
                    // TODO set license
                    // image.setLicense(License.getLicenseByFlickrId(photo
                    // .getInt("license")));
                    // dbHelper.getImageDao().create(image);
                }
                // dbHelper.getWordImageDao().create(
                // new WordImage(word, image));
                numImages++;
            }
        } catch (JSONException e) {
            // Catch here so that we continue through the loop
            Log.w(TAG, "Error parsing photo: " + photo, e);
        }
    }
    return numImages;
}

From source file:com.github.barteksc.sample.PDFViewActivity.java

public String getFileName(Uri uri) {
    String result = null;// w w w .  jav a 2 s.c o  m
    if (uri.getScheme().equals("content")) {
        Cursor cursor = getContentResolver().query(uri, null, null, null, null);
        try {
            if (cursor != null && cursor.moveToFirst()) {
                result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }
    if (result == null) {
        result = uri.getLastPathSegment();
    }
    return result;
}

From source file:com.hivewallet.androidclient.wallet.AddressBookProvider.java

@Override
public int delete(final Uri uri, final String selection, final String[] selectionArgs) {
    final List<String> pathSegments = uri.getPathSegments();
    if (pathSegments.size() != 1)
        throw new IllegalArgumentException(uri.toString());

    final String address = uri.getLastPathSegment();

    final int count = helper.getWritableDatabase().delete(DATABASE_TABLE, KEY_ADDRESS + "=?",
            new String[] { address });

    if (count > 0)
        getContext().getContentResolver().notifyChange(uri, null);

    return count;
}