Example usage for android.net Uri buildUpon

List of usage examples for android.net Uri buildUpon

Introduction

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

Prototype

public abstract Builder buildUpon();

Source Link

Document

Constructs a new builder, copying the attributes from this Uri.

Usage

From source file:Main.java

public static void shiftTableUriIds(HashMap<String, ArrayList<ContentValues>> operationMap, String tableName,
        String idColumnName, String authority, String path, long topTableId) {
    ArrayList<ContentValues> restoreOperations = operationMap.get(tableName);
    if (null == restoreOperations) {
        return;/*w w  w  . j av a  2s.  c  om*/
    }
    for (ContentValues restoreCv : restoreOperations) {
        if (restoreCv.containsKey(idColumnName) && null != restoreCv.getAsString(idColumnName)) {

            Uri uri = Uri.parse(restoreCv.getAsString(idColumnName));
            if ("content".equalsIgnoreCase(uri.getScheme()) && authority.equals(uri.getAuthority())
                    && uri.getPath().substring(0, uri.getPath().lastIndexOf('/')).equals(path)) {
                Uri.Builder newUri = uri.buildUpon()
                        .path(uri.getPath().substring(0, uri.getPath().lastIndexOf('/')))
                        .appendPath(String.valueOf(
                                Long.parseLong(uri.getPath().substring(uri.getPath().lastIndexOf('/') + 1))
                                        + topTableId));

                //               Log.v("URI", uri.getPath().substring(uri.getPath().lastIndexOf('/')+1));
                //               Log.v("URI", String.valueOf(Long.parseLong(uri.getPath().substring(uri.getPath().lastIndexOf('/')+1)) + topTableId));

                restoreCv.put(idColumnName, newUri.build().toString());
            }
        }
    }
}

From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java

public static Uri getAvatarUri(Uri baseUri, long providerId, long accountId) {
    Uri.Builder builder = baseUri.buildUpon();
    ContentUris.appendId(builder, providerId);
    ContentUris.appendId(builder, accountId);
    return builder.build();
}

From source file:physical_web.org.physicalweb.MetadataResolver.java

/**
 * Create the url metadata request,/*from w w  w  .  j a  va2s . co m*/
 * given the json request object
 *
 * @param jsonObj
 * @return
 */
private static JsonObjectRequest createUrlMetadataRequest(JSONObject jsonObj) {
    return new JsonObjectRequest(METADATA_URL, jsonObj, new Response.Listener<JSONObject>() {
        // Called when the server returns a response
        @Override
        public void onResponse(JSONObject jsonResponse) {

            // Build the metadata from the response
            try {
                JSONArray foundMetaData = jsonResponse.getJSONArray("metadata");

                if (foundMetaData.length() > 0) {

                    JSONObject jsonUrlMetadata = foundMetaData.getJSONObject(0);

                    String title = "Unknown name";
                    String url = "Unknown url";
                    String description = "Unknown description";
                    String iconUrl = "/favicon.ico";
                    String id = jsonUrlMetadata.getString("id");

                    if (jsonUrlMetadata.has("title")) {
                        title = jsonUrlMetadata.getString("title");
                    }
                    if (jsonUrlMetadata.has("url")) {
                        url = jsonUrlMetadata.getString("url");
                    }
                    if (jsonUrlMetadata.has("description")) {
                        description = jsonUrlMetadata.getString("description");
                    }
                    if (jsonUrlMetadata.has("icon")) {
                        // We might need to do some magic here.
                        iconUrl = jsonUrlMetadata.getString("icon");
                    }

                    // TODO: Eliminate this fallback since we expect the server to always return an icon.
                    // Provisions for a favicon specified as a relative URL.
                    if (!iconUrl.startsWith("http")) {
                        // Lets just assume we are dealing with a relative path.
                        Uri fullUri = Uri.parse(url);
                        Uri.Builder builder = fullUri.buildUpon();
                        // Append the default favicon path to the URL.
                        builder.path(iconUrl);
                        iconUrl = builder.toString();
                    }

                    UrlMetadata urlMetadata = new UrlMetadata();
                    urlMetadata.title = title;
                    urlMetadata.description = description;
                    urlMetadata.siteUrl = url;
                    urlMetadata.iconUrl = iconUrl;
                    downloadIcon(urlMetadata, url);

                    onUrlMetadataReceived(id, urlMetadata);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            Log.i(TAG, "VolleyError: " + volleyError.toString());
        }
    });
}

From source file:Main.java

public static Cursor query(final Context context, Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder, final int limit) {
    try {/* w w  w . j  a  v a2s.co m*/
        final ContentResolver resolver = context.getContentResolver();
        if (resolver == null) {
            return null;
        }
        if (limit > 0) {
            uri = uri.buildUpon().appendQueryParameter("limit", "" + limit).build();
        }
        return resolver.query(uri, projection, selection, selectionArgs, sortOrder);
    } catch (final UnsupportedOperationException ex) {
        return null;
    }

}

From source file:Main.java

@Nullable
public static Cursor query(Context context, Uri uri, String[] projection, String selection,
        String[] selectionArgs, String sortOrder, int limit) {
    try {/*from  www.  ja v  a 2  s  . co m*/
        ContentResolver resolver = context.getContentResolver();
        if (resolver == null) {
            return null;
        }
        if (limit > 0) {
            uri = uri.buildUpon().appendQueryParameter("limit", "" + limit).build();
        }
        return resolver.query(uri, projection, selection, selectionArgs, sortOrder);
    } catch (UnsupportedOperationException ex) {
        return null;
    }
}

From source file:org.mobisocial.corral.CorralClient.java

private static Uri uriForContent(String host, SignedObj obj) {
    try {/*from w w  w.  j  a  va  2s .c o  m*/
        String localContent = obj.getJson().getString(OBJ_LOCAL_URI);
        Uri baseUri = Uri.parse("http://" + host + ":" + ContentCorral.SERVER_PORT);
        return baseUri.buildUpon().appendQueryParameter("content", localContent)
                .appendQueryParameter("hash", "" + obj.getHash()).build();
    } catch (Exception e) {
        Log.d(TAG, "No uri for content " + obj.getHash() + "; " + obj.getJson());
        return null;
    }
}

From source file:Main.java

public static Cursor query(Context context, Uri uri, String[] projection, String selection,
        String[] selectionArgs, String sortOrder, int limit) {
    try {/*from  w  ww.j  ava2s.  com*/
        ContentResolver resolver = context.getContentResolver();
        if (resolver == null) {
            return null;
        }
        if (limit > 0) {
            uri = uri.buildUpon().appendQueryParameter("limit", "" + limit).build();
        }
        return resolver.query(uri, projection, selection, selectionArgs, sortOrder);
    } catch (UnsupportedOperationException ex) {
        return null;
    }

}

From source file:com.appdynamics.demo.gasp.service.RESTIntentService.java

private static void attachUriWithQuery(HttpRequestBase request, Uri uri, Bundle params) {
    try {//from   www .  jav a  2  s.co m
        if (params == null) {
            request.setURI(new URI(uri.toString()));
        } else {
            Uri.Builder uriBuilder = uri.buildUpon();

            // Loop through our params and append them to the Uri.
            for (BasicNameValuePair param : paramsToList(params)) {
                uriBuilder.appendQueryParameter(param.getName(), param.getValue());
            }

            uri = uriBuilder.build();
            request.setURI(new URI(uri.toString()));
        }
    } catch (URISyntaxException e) {
        Log.e(TAG, "URI syntax was incorrect: " + uri.toString(), e);
    }
}

From source file:can.yrt.onebusaway.QueryUtils.java

static protected CursorLoader newRecentQuery(final Context context, final Uri uri, final String[] projection,
        final String accessTime, final String useCount) {
    // "Recently" means seven days in the past
    final long last = System.currentTimeMillis() - 7 * DateUtils.DAY_IN_MILLIS;
    Uri limit = uri.buildUpon().appendQueryParameter("limit", "20").build();

    String regionWhere = "";
    if (Application.get().getCurrentRegion() != null) {
        if (projection.equals(QueryUtils.StopList.Columns.PROJECTION)) {
            regionWhere = " AND " + StopList.getRegionWhere();
        } else if (projection.equals(QueryUtils.RouteList.Columns.PROJECTION)) {
            regionWhere = " AND " + RouteList.getRegionWhere();
        }//from   w w  w .ja v  a2 s  .c  om
    }

    return new CursorLoader(
            context, limit, projection, "((" + accessTime + " IS NOT NULL AND " + accessTime + " > " + last
                    + ") OR (" + useCount + " > 0))" + regionWhere,
            null, accessTime + " desc, " + useCount + " desc");
}

From source file:com.example.jumpnote.android.SyncAdapter.java

private static Uri addCallerIsSyncAdapterParameter(Uri uri) {
    return uri.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
}