Example usage for android.net Uri getPathSegments

List of usage examples for android.net Uri getPathSegments

Introduction

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

Prototype

public abstract List<String> getPathSegments();

Source Link

Document

Gets the decoded path segments.

Usage

From source file:com.determinato.feeddroid.parser.RssParser.java

/**
 * {@inheritDoc}/*from ww w  . java  2  s . co m*/
 */
public void characters(char[] ch, int start, int length) {
    // Are we in the Channel or in a Post?
    if ((mId == -1) && (mState & STATE_IN_TITLE) != 0) {

        ContentValues values = new ContentValues();

        values.put(FeedDroid.Channels.TITLE, new String(ch, start, length));
        values.put(FeedDroid.Channels.URL, mRssUrl);
        values.put(FeedDroid.Channels.FOLDER_ID, mFolderId);

        Uri added = mResolver.insert(FeedDroid.Channels.CONTENT_URI, values);

        mId = Long.parseLong(added.getPathSegments().get(1));

        mState &= ~STATE_IN_TITLE;

        return;
    }

    if ((mState & STATE_IN_ITEM) == 0)
        return;

    StringBuilder str = new StringBuilder();
    switch (mState) {
    case STATE_IN_ITEM | STATE_IN_ITEM_TITLE:
        str.append(new String(ch, start, length).trim());
        if (mPostBuf.title == null)
            mPostBuf.title = str.toString();
        else
            mPostBuf.title += str.toString();
        break;
    case STATE_IN_ITEM | STATE_IN_ITEM_DESC:
        str.append(new String(ch, start, length).trim());
        if (mPostBuf.desc == null)
            mPostBuf.desc = str.toString();
        else
            mPostBuf.desc += str.toString();
        break;
    case STATE_IN_ITEM | STATE_IN_ITEM_LINK:
        mPostBuf.link = new String(ch, start, length).trim();
        break;
    case STATE_IN_ITEM | STATE_IN_ITEM_DATE:
        mPostBuf.setDate(new String(ch, start, length).trim());
        break;
    case STATE_IN_ITEM | STATE_IN_ITEM_AUTHOR:
        mPostBuf.author = new String(ch, start, length).trim();
        if (mPostBuf.author == null)
            mPostBuf.author = "";
        break;

    default:
    }
}

From source file:com.navjagpal.fileshare.WebServer.java

private String getFileListing(Uri uri) {
    int folderId = Integer.parseInt(uri.getPathSegments().get(1));
    Uri fileUri = FileSharingProvider.Files.CONTENT_URI;
    String where = FileSharingProvider.Files.Columns.FOLDER_ID + "=" + folderId;
    Cursor c = mContext.getContentResolver().query(fileUri, null, where, null, null);
    int nameIndex = c.getColumnIndexOrThrow(FileSharingProvider.Files.Columns.DISPLAY_NAME);
    int idIndex = c.getColumnIndexOrThrow(FileSharingProvider.Files.Columns._ID);
    String s = "";
    boolean hasMusic = false;
    while (c.moveToNext()) {
        String name = c.getString(nameIndex);
        int id = c.getInt(idIndex);
        s += fileToLink(name, id) + "<br/>";
        if (name.endsWith(".mp3")) {
            hasMusic = true;//from  w  w w.  j a va2 s.com
        }
    }
    c.close();
    if (hasMusic) {
        s += getPlaylistLink(folderId) + "<br/>";
    }
    s += getZipLink(folderId) + "<br/>";
    return s;
}

From source file:org.floens.chan.ui.activity.BoardActivity.java

/**
 * Handle opening from an external url./*from   ww w  .  j  av a  2s.  c  o m*/
 *
 * @param startUri
 */
private void handleIntentURI(Uri startUri) {
    List<String> parts = startUri.getPathSegments();

    if (parts.size() == 1) {
        // Board mode
        String rawBoard = parts.get(0);
        if (ChanApplication.getBoardManager().getBoardExists(rawBoard)) {
            // To clear the flag
            loadBoard(rawBoard);
            loadBoard(rawBoard);
        } else {
            handleIntentURIFallback(startUri.toString());
        }
    } else if (parts.size() == 3) {
        // Thread mode
        String rawBoard = parts.get(0);
        int no = -1;

        try {
            no = Integer.parseInt(parts.get(2));
        } catch (NumberFormatException e) {
        }

        if (no >= 0 && ChanApplication.getBoardManager().getBoardExists(rawBoard)) {
            startLoadingThread(new Loadable(rawBoard, no));
        } else {
            handleIntentURIFallback(startUri.toString());
            return;
        }
    } else {
        showUrlOpenPicker(startUri.toString());
    }
}

From source file:com.manning.androidhacks.hack043.provider.BatchNumbersContentProvider.java

@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    int count = 0;
    switch (sUriMatcher.match(uri)) {
    case ITEM://from w  w  w .  ja  va2s.c  o m
        count = db.update(TABLE_NAME, values, selection, selectionArgs);
        break;
    case ITEM_ID:
        count = db.update(TABLE_NAME, values, COLUMN_ID + "=" + uri.getPathSegments().get(1)
                + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ")" : ""), selectionArgs);
        break;
    default:
        throw new RuntimeException("Unknown URI " + uri);
    }

    getContext().getContentResolver().notifyChange(uri, null);
    return count;
}

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;
}

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:com.mutu.gpstracker.breadcrumbs.UploadBreadcrumbsTrackTask.java

@Override
protected void onPostExecute(Uri result) {
    BreadcrumbsTracks tracks = mService.getBreadcrumbsTracks();
    Uri metadataUri = Uri.withAppendedPath(mTrackUri, "metadata");
    List<String> segments = result.getPathSegments();
    Integer bcTrackId = Integer.valueOf(segments.get(segments.size() - 2));

    ArrayList<ContentValues> metaValues = new ArrayList<ContentValues>();

    metaValues.add(buildContentValues(BreadcrumbsTracks.TRACK_ID, Long.toString(bcTrackId)));
    if (mDescription != null) {
        metaValues.add(buildContentValues(BreadcrumbsTracks.DESCRIPTION, mDescription));
    }/*  w ww  . j a va  2 s.c  om*/
    if (mIsPublic != null) {
        metaValues.add(buildContentValues(BreadcrumbsTracks.ISPUBLIC, mIsPublic));
    }
    metaValues.add(buildContentValues(BreadcrumbsTracks.BUNDLE_ID, mBundleId));
    metaValues.add(buildContentValues(BreadcrumbsTracks.ACTIVITY_ID, mActivityId));

    // Store in OGT provider
    ContentResolver resolver = mContext.getContentResolver();
    resolver.bulkInsert(metadataUri, metaValues.toArray(new ContentValues[1]));

    // Store in Breadcrumbs adapter
    tracks.addSyncedTrack(Long.valueOf(mTrackUri.getLastPathSegment()), bcTrackId);
    if (mIsBundleCreated) {
        mService.getBreadcrumbsTracks().addBundle(Integer.parseInt(mBundleId), mBundleName, mBundleDescription);
    }
    //"http://api.gobreadcrumbs.com/v1/tracks/" + trackId + "/placemarks.gpx"
    mService.getBreadcrumbsTracks().addTrack(bcTrackId, mName, Integer.valueOf(mBundleId), mDescription, null,
            null, null, mIsPublic, null, null, null, null, null);

    super.onPostExecute(result);
}

From source file:com.manning.androidhacks.hack023.provider.TodoContentProvider.java

@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    int count = 0;
    switch (sUriMatcher.match(uri)) {
    case TODO://from   w  w  w  . j a  v  a2 s .  c  o m
        count = db.update(TODO_TABLE_NAME, values, selection, selectionArgs);
        break;
    case TODO_ID:
        count = db.update(TODO_TABLE_NAME, values, COLUMN_ID + "=" + uri.getPathSegments().get(1)
                + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ")" : ""), selectionArgs);
        break;
    default:
        throw new RuntimeException("Unknown URI " + uri);
    }

    getContext().getContentResolver().notifyChange(uri, null);
    return count;
}

From source file:com.google.android.apps.iosched.ui.gtv.GoogleTVSessionLivestreamActivity.java

/**
 * Reloads all data in the activity and fragments from a given uri
 *///from w w w . j  a  v a2  s  . co m
private void reloadFromUri(Uri newUri) {
    if (newUri != null && newUri.getPathSegments().size() >= 2) {
        mSessionId = Sessions.getSessionId(newUri);
        getSupportLoaderManager().restartLoader(SessionSummaryQuery._TOKEN, null, this);
    }
}

From source file:com.rightscale.provider.Dashboard.java

@Override
public Cursor query(Uri uri, String[] columns, String where, String[] whereArgs, String sortBy) {
    try {/*w w w .  j  a  va2  s  . c o m*/
        List<String> segments = uri.getPathSegments();
        DashboardSession session = createSession(getContext());
        String[] args = null;

        session.login();

        if (segments.size() == 1 && segments.get(0).equals("accounts")) {
            //Special case: asking for index of accounts
            AccountsResource accounts = new AccountsResource(session);
            return accounts.index();
        }

        if (segments.size() < 3 || !segments.get(0).equals("accounts")) {
            throw new DashboardError("Unknown content URI: " + uri);
        }

        if (segments.get(2).equals("deployments")) {
            if ((args = parseWhereArgs(where, whereArgs, WHERE_ACCOUNT_AND_ID)) != null) {
                // SELECT ... FROM deployments WHERE id = ?
                session.setCurrentAccount(args[0]);
                DeploymentsResource deployments = new DeploymentsResource(session, args[0]);
                return deployments.show(args[1]);
            } else if ((args = parseWhereArgs(where, whereArgs, WHERE_ACCOUNT)) != null) {
                // SELECT ... FROM deployments
                session.setCurrentAccount(args[0]);
                DeploymentsResource deployments = new DeploymentsResource(session, args[0]);
                return deployments.index();
            } else {
                throw new DashboardError("Unknown where-clause: " + where);
            }
        } else if (segments.get(2).equals("servers")) {
            if ((args = parseWhereArgs(where, whereArgs, WHERE_ACCOUNT_AND_DEPLOYMENT)) != null) {
                // SELECT ... FROM servers WHERE deployment_id = ?
                session.setCurrentAccount(args[0]);
                ServersResource servers = new ServersResource(session, args[0]);
                return servers.indexForDeployment(args[1]);
            } else if ((args = parseWhereArgs(where, whereArgs, WHERE_ACCOUNT_AND_ID)) != null) {
                // SELECT ... FROM servers WHERE id = ?
                session.setCurrentAccount(args[0]);
                ServersResource servers = new ServersResource(session, args[0]);
                return servers.show(args[1]);
            } else if ((args = parseWhereArgs(where, whereArgs, WHERE_ACCOUNT)) != null) {
                // SELECT ... FROM servers
                session.setCurrentAccount(args[0]);
                ServersResource servers = new ServersResource(session, args[0]);
                return servers.index();
            } else {
                throw new DashboardError("Unknown where-clause: " + where);
            }
        } else if (segments.get(2).equals("server_settings")) {
            if ((args = parseWhereArgs(where, whereArgs, WHERE_ACCOUNT_AND_SERVER)) != null) {
                // SELECT ... FROM server_settings WHERE server_id = ?
                session.setCurrentAccount(args[0]);
                ServerSettingsResource serverSettings = new ServerSettingsResource(session, args[0]);
                return serverSettings.showForServer(args[1]);
            } else {
                throw new DashboardError("Unknown where-clause: " + where);
            }
        } else if (segments.get(2).equals("server_monitors")) {
            if ((args = parseWhereArgs(where, whereArgs, WHERE_ACCOUNT_AND_SERVER)) != null) {
                // SELECT ... FROM server_monitors WHERE server_id = ?
                session.setCurrentAccount(args[0]);
                ServerMonitorsResource serverMonitors = new ServerMonitorsResource(session, args[0]);
                return serverMonitors.indexForServer(args[1]);
            } else {
                throw new DashboardError("Unknown where-clause: " + where);
            }
        } else if (segments.get(2).equals("server_templates")) {
            if ((args = parseWhereArgs(where, whereArgs, WHERE_ACCOUNT_AND_ID)) != null) {
                // SELECT ... FROM server_templates WHERE id = ?
                session.setCurrentAccount(args[0]);
                ServerTemplatesResource serverTemplates = new ServerTemplatesResource(session, args[0]);
                return serverTemplates.show(args[1]);
            } else if ((args = parseWhereArgs(where, whereArgs, WHERE_ACCOUNT)) != null) {
                session.setCurrentAccount(args[0]);
                ServerTemplatesResource serverTemplates = new ServerTemplatesResource(session, args[0]);
                return serverTemplates.index();
            } else {
                throw new DashboardError("Unknown where-clause: " + where);
            }
        } else if (segments.get(2).equals("server_template_executables")) {
            if ((args = parseWhereArgs(where, whereArgs,
                    WHERE_ACCOUNT_AND_SERVER_TEMPLATE_AND_APPLY)) != null) {
                session.setCurrentAccount(args[0]);
                ServerTemplateExecutablesResource serverTemplates = new ServerTemplateExecutablesResource(
                        session, args[0]);
                return serverTemplates.indexForServerTemplate(args[1], args[2]);
            } else {
                throw new DashboardError("Unknown where-clause: " + where);
            }
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (RestException e) {
        forgetSession();
        Error err = new DashboardError(e);
        throw err;
    }

    throw new DashboardError("Unknown content URI " + uri);
}