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:com.he5ed.lib.cloudprovider.apis.CloudDriveApi.java

/**
 * Get current user end point url/*from ww  w  .  j  a v  a2  s.  c  om*/
 *
 * @return Uri
 */
public static Uri getEndPointUri() {
    Uri uri = Uri.parse(API_BASE_URL);
    return uri.buildUpon().appendEncodedPath("account/endpoint").build();
}

From source file:com.eincs.athens.android.OlympusFeedActivity.java

private void getTimeline(final String after, final String before) {

    final HttpClient httpClient = new DefaultHttpClient();
    new DefaultAsyncTask<JSONObject>(ProgressDialogs.createDialog(this)) {

        @Override/*from   w  ww  .java  2s. co  m*/
        protected JSONObject doInBackground(Object... params) {
            Uri uri = Uri.parse(OlympusConst.SERVER_HOST + OlympusConst.PATH_TIMELINE);
            Uri.Builder builder = uri.buildUpon();

            if (!StringUtils.isEmptyOrNull(after)) {
                builder.appendQueryParameter("after", after);
            }

            if (!StringUtils.isEmptyOrNull(after)) {
                builder.appendQueryParameter("before", before);
            }

            HttpGet httpGet = new HttpGet(uri.toString());

            try {
                JSONObject result = httpClient.execute(httpGet, new JSONResponseHandler());
                return result;

            } catch (Exception e) {
                Log.e("Olympus", e.getMessage(), e);
                return null;
            }
        }

        protected void onPostExecute(JSONObject result) {
            super.onPostExecute(result);

            if (result == null) {
                Toast.makeText(mContext, "error", Toast.LENGTH_SHORT).show();

            } else if (result.has("error")) {
                try {
                    Toast.makeText(mContext, result.getString("error"), Toast.LENGTH_SHORT).show();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else {
                try {
                    JSONArray jsonList = result.getJSONArray("result");
                    List<Post> postList = Post.createList(jsonList);

                    mData.clear();
                    for (Post post : postList) {
                        mData.put(post.getId(), post);
                    }

                    mDataArray.clear();
                    for (Integer integer : mData.keySet()) {
                        mDataArray.add(mData.get(integer));
                    }
                    mAdapter.notifyDataSetChanged();

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        };
    }.execute();
}

From source file:org.andstatus.app.net.social.ConnectionTwitterGnuSocial.java

@Override
public List<String> getIdsOfUsersFollowedBy(String userId) throws ConnectionException {
    Uri sUri = Uri.parse(getApiPath(ApiRoutineEnum.GET_FRIENDS_IDS));
    Uri.Builder builder = sUri.buildUpon();
    builder.appendQueryParameter("user_id", userId);
    List<String> list = new ArrayList<String>();
    JSONArray jArr = http.getRequestAsArray(builder.build().toString());
    try {/* w ww.j a  v a 2 s  . c om*/
        for (int index = 0; index < jArr.length(); index++) {
            list.add(jArr.getString(index));
        }
    } catch (JSONException e) {
        throw ConnectionException.loggedJsonException(this, "Parsing friendsIds", e, null);
    }
    return list;
}

From source file:net.naonedbus.fragment.impl.LignesFragment.java

@Override
public Loader<Cursor> onCreateLoader(final int loaderId, final Bundle bundle) {
    Uri uri = LigneProvider.CONTENT_URI;
    if (mCurrentFilter == FILTER_FAVORIS) {
        uri = uri.buildUpon().path(LigneProvider.LIGNE_FAVORIS_URI_PATH_QUERY).build();
    }//from ww  w. j  a  v a2 s.c om

    return new CursorLoader(getActivity(), uri, null, null, null, null);
}

From source file:com.owncloud.android.lib.resources.shares.GetRemoteShareesOperation.java

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result = null;
    int status;/*from  www .  java  2  s .  com*/
    GetMethod get = null;

    try {
        Uri requestUri = client.getBaseUri();
        Uri.Builder uriBuilder = requestUri.buildUpon();
        uriBuilder.appendEncodedPath(OCS_ROUTE);
        uriBuilder.appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT);
        uriBuilder.appendQueryParameter(PARAM_ITEM_TYPE, VALUE_ITEM_TYPE);
        uriBuilder.appendQueryParameter(PARAM_SEARCH, mSearchString);
        uriBuilder.appendQueryParameter(PARAM_PAGE, String.valueOf(mPage));
        uriBuilder.appendQueryParameter(PARAM_PER_PAGE, String.valueOf(mPerPage));

        // Get Method
        get = new GetMethod(uriBuilder.build().toString());
        get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);

        status = client.executeMethod(get);

        if (isSuccess(status)) {
            String response = get.getResponseBodyAsString();
            Log_OC.d(TAG, "Successful response: " + response);

            // Parse the response
            JSONObject respJSON = new JSONObject(response);
            JSONObject respOCS = respJSON.getJSONObject(NODE_OCS);
            JSONObject respData = respOCS.getJSONObject(NODE_DATA);
            JSONObject respExact = respData.getJSONObject(NODE_EXACT);
            JSONArray respExactUsers = respExact.getJSONArray(NODE_USERS);
            JSONArray respExactGroups = respExact.getJSONArray(NODE_GROUPS);
            JSONArray respPartialUsers = respData.getJSONArray(NODE_USERS);
            JSONArray respPartialGroups = respData.getJSONArray(NODE_GROUPS);
            JSONArray[] jsonResults = { respExactUsers, respExactGroups, respPartialUsers, respPartialGroups };

            ArrayList<Object> data = new ArrayList<Object>(); // For result data
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < jsonResults[i].length(); j++) {
                    JSONObject jsonResult = jsonResults[i].getJSONObject(j);
                    data.add(jsonResult);
                    Log_OC.d(TAG, "*** Added item: " + jsonResult.getString(PROPERTY_LABEL));
                }
            }

            // Result
            result = new RemoteOperationResult(true, status, get.getResponseHeaders());
            result.setData(data);

            Log_OC.d(TAG, "*** Get Users or groups completed ");

        } else {
            result = new RemoteOperationResult(false, status, get.getResponseHeaders());
            String response = get.getResponseBodyAsString();
            Log_OC.e(TAG, "Failed response while getting users/groups from the server ");
            if (response != null) {
                Log_OC.e(TAG, "*** status code: " + status + "; response message: " + response);
            } else {
                Log_OC.e(TAG, "*** status code: " + status);
            }
        }

    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Exception while getting users/groups", e);

    } finally {
        if (get != null) {
            get.releaseConnection();
        }
    }
    return result;
}

From source file:com.cerema.cloud2.lib.resources.shares.GetRemoteShareesOperation.java

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result = null;
    int status;// w  ww .j  ava 2 s .  com
    GetMethod get = null;

    try {
        Uri requestUri = client.getBaseUri();
        Uri.Builder uriBuilder = requestUri.buildUpon();
        uriBuilder.appendEncodedPath(OCS_ROUTE);
        uriBuilder.appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT);
        uriBuilder.appendQueryParameter(PARAM_ITEM_TYPE, VALUE_ITEM_TYPE);
        uriBuilder.appendQueryParameter(PARAM_SEARCH, mSearchString);
        uriBuilder.appendQueryParameter(PARAM_PAGE, String.valueOf(mPage));
        uriBuilder.appendQueryParameter(PARAM_PER_PAGE, String.valueOf(mPerPage));

        // Get Method
        get = new GetMethod(uriBuilder.build().toString());
        get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);

        status = client.executeMethod(get);

        if (isSuccess(status)) {
            String response = get.getResponseBodyAsString();
            Log_OC.d(TAG, "Successful response: " + response);

            // Parse the response
            JSONObject respJSON = new JSONObject(response);
            JSONObject respOCS = respJSON.getJSONObject(NODE_OCS);
            JSONObject respData = respOCS.getJSONObject(NODE_DATA);
            JSONObject respExact = respData.getJSONObject(NODE_EXACT);
            JSONArray respExactUsers = respExact.getJSONArray(NODE_USERS);
            JSONArray respExactGroups = respExact.getJSONArray(NODE_GROUPS);
            JSONArray respExactRemotes = respExact.getJSONArray(NODE_REMOTES);
            JSONArray respPartialUsers = respData.getJSONArray(NODE_USERS);
            JSONArray respPartialGroups = respData.getJSONArray(NODE_GROUPS);
            JSONArray respPartialRemotes = respData.getJSONArray(NODE_REMOTES);
            JSONArray[] jsonResults = { respExactUsers, respExactGroups, respExactRemotes, respPartialUsers,
                    respPartialGroups, respPartialRemotes };

            ArrayList<Object> data = new ArrayList<Object>(); // For result data
            for (int i = 0; i < 6; i++) {
                for (int j = 0; j < jsonResults[i].length(); j++) {
                    JSONObject jsonResult = jsonResults[i].getJSONObject(j);
                    data.add(jsonResult);
                    Log_OC.d(TAG, "*** Added item: " + jsonResult.getString(PROPERTY_LABEL));
                }
            }

            // Result
            result = new RemoteOperationResult(true, status, get.getResponseHeaders());
            result.setData(data);

            Log_OC.d(TAG, "*** Get Users or groups completed ");

        } else {
            result = new RemoteOperationResult(false, status, get.getResponseHeaders());
            String response = get.getResponseBodyAsString();
            Log_OC.e(TAG, "Failed response while getting users/groups from the server ");
            if (response != null) {
                Log_OC.e(TAG, "*** status code: " + status + "; response message: " + response);
            } else {
                Log_OC.e(TAG, "*** status code: " + status);
            }
        }

    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Exception while getting users/groups", e);

    } finally {
        if (get != null) {
            get.releaseConnection();
        }
    }
    return result;
}

From source file:com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation.java

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result = null;
    int status = -1;

    /// prepare array of parameters to update
    List<Pair<String, String>> parametersToUpdate = new ArrayList<Pair<String, String>>();
    if (mPassword != null) {
        parametersToUpdate.add(new Pair<String, String>(PARAM_PASSWORD, mPassword));
    }//from  w  w w. j a v a 2  s.  com
    if (mExpirationDateInMillis < 0) {
        // clear expiration date
        parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, ""));

    } else if (mExpirationDateInMillis > 0) {
        // set expiration date
        DateFormat dateFormat = new SimpleDateFormat(FORMAT_EXPIRATION_DATE);
        Calendar expirationDate = Calendar.getInstance();
        expirationDate.setTimeInMillis(mExpirationDateInMillis);
        String formattedExpirationDate = dateFormat.format(expirationDate.getTime());
        parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, formattedExpirationDate));

    } // else, ignore - no update

    /* TODO complete rest of parameters
    if (mPermissions > 0) {
    parametersToUpdate.add(new Pair("permissions", Integer.toString(mPermissions)));
    }
    if (mPublicUpload != null) {
    parametersToUpdate.add(new Pair("publicUpload", mPublicUpload.toString());
    }
    */

    /// perform required PUT requests
    PutMethod put = null;
    String uriString = null;

    try {
        Uri requestUri = client.getBaseUri();
        Uri.Builder uriBuilder = requestUri.buildUpon();
        uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH.substring(1));
        uriBuilder.appendEncodedPath(Long.toString(mRemoteId));
        uriString = uriBuilder.build().toString();

        for (Pair<String, String> parameter : parametersToUpdate) {
            if (put != null) {
                put.releaseConnection();
            }
            put = new PutMethod(uriString);
            put.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
            put.setRequestEntity(new StringRequestEntity(parameter.first + "=" + parameter.second,
                    ENTITY_CONTENT_TYPE, ENTITY_CHARSET));

            status = client.executeMethod(put);

            if (status == HttpStatus.SC_OK) {
                String response = put.getResponseBodyAsString();

                // Parse xml response
                ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser(
                        new ShareXMLParser());
                parser.setOwnCloudVersion(client.getOwnCloudVersion());
                parser.setServerBaseUri(client.getBaseUri());
                result = parser.parse(response);

            } else {
                result = new RemoteOperationResult(false, status, put.getResponseHeaders());
            }
        }

    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Exception while updating remote share ", e);
        if (put != null) {
            put.releaseConnection();
        }

    } finally {
        if (put != null) {
            put.releaseConnection();
        }
    }
    return result;
}

From source file:com.he5ed.lib.cloudprovider.apis.DropboxApi.java

/**
 * Get current user information uri//from w w  w.j  av  a2  s .c  om
 *
 * @return Uri
 */
public static Uri getUserInfoUri() {
    Uri uri = Uri.parse(API_BASE_URL);
    return uri.buildUpon().appendEncodedPath("users/get_current_account").build();
}

From source file:com.delaroystudios.todolist.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Set the RecyclerView to its corresponding view
    mRecyclerView = (RecyclerView) findViewById(R.id.recyclerViewTasks);

    // Set the layout for the RecyclerView to be a linear layout, which measures and
    // positions items within a RecyclerView into a linear list
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    // Initialize the adapter and attach it to the RecyclerView
    mAdapter = new CustomCursorAdapter(this);
    mRecyclerView.setAdapter(mAdapter);/* www . j  a va  2  s .c o  m*/

    /*
     Add a touch helper to the RecyclerView to recognize when a user swipes to delete an item.
     An ItemTouchHelper enables touch behavior (like swipe and move) on each ViewHolder,
     and uses callbacks to signal when a user is performing these actions.
     */
    new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                RecyclerView.ViewHolder target) {
            return false;
        }

        // Called when a user swipes left or right on a ViewHolder
        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
            // Here is where you'll implement swipe to delete

            // COMPLETED (1) Construct the URI for the item to delete
            //[Hint] Use getTag (from the adapter code) to get the id of the swiped item
            // Retrieve the id of the task to delete
            int id = (int) viewHolder.itemView.getTag();

            // Build appropriate uri with String row id appended
            String stringId = Integer.toString(id);
            Uri uri = TaskContract.TaskEntry.CONTENT_URI;
            uri = uri.buildUpon().appendPath(stringId).build();

            // COMPLETED (2) Delete a single row of data using a ContentResolver
            getContentResolver().delete(uri, null, null);

            // COMPLETED (3) Restart the loader to re-query for all tasks after a deletion
            getSupportLoaderManager().restartLoader(TASK_LOADER_ID, null, MainActivity.this);

        }
    }).attachToRecyclerView(mRecyclerView);

    /*
     Set the Floating Action Button (FAB) to its corresponding View.
     Attach an OnClickListener to it, so that when it's clicked, a new intent will be created
     to launch the AddTaskActivity.
     */
    FloatingActionButton fabButton = (FloatingActionButton) findViewById(R.id.fab);

    fabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Create a new intent to start an AddTaskActivity
            Intent addTaskIntent = new Intent(MainActivity.this, AddTaskActivity.class);
            startActivity(addTaskIntent);
        }
    });

    /*
     Ensure a loader is initialized and active. If the loader doesn't already exist, one is
     created, otherwise the last created loader is re-used.
     */
    getSupportLoaderManager().initLoader(TASK_LOADER_ID, null, this);
}

From source file:edu.stanford.mobisocial.dungbeetle.obj.action.RelatedObjAction.java

@Override
public void onAct(Context context, DbEntryHandler objType, DbObj obj) {
    Uri feedUri = obj.getContainingFeed().getUri();
    long hash = obj.getHash();
    // TODO:/*from www .j  a v a 2  s  .c o  m*/
    /*Intent viewComments = new Intent(Intent.ACTION_VIEW);
    viewComments.setDataAndType(objUri, DbObject.MIME_TYPE);
    mmContext.startActivity(viewComments);*/
    Uri objUri = feedUri.buildUpon().encodedPath(feedUri.getPath() + ":" + hash).build();

    Intent objViewActivity = new Intent(Intent.ACTION_VIEW);
    objViewActivity.setDataAndType(objUri, Feed.MIME_TYPE);
    context.startActivity(objViewActivity);
}