List of usage examples for android.net Uri buildUpon
public abstract Builder buildUpon();
From source file:com.he5ed.lib.cloudprovider.apis.CloudDriveApi.java
@Override public CFile moveFile(@NonNull CFile file, @Nullable CFolder folder) throws RequestFailException { if (TextUtils.isEmpty(mAccessToken)) { throw new RequestFailException("Access token not available"); }//from ww w . j a v a2 s . com // create parameter as json final JSONObject params = new JSONObject(); try { ArrayList<String> parentList = new ArrayList<>(); parentList.add(folder != null ? folder.getId() : getRoot().getId()); params.put("parents", new JSONArray(parentList)); } catch (JSONException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } RequestBody body = new RequestBody() { @Override public MediaType contentType() { return JSON; } @Override public void writeTo(BufferedSink sink) throws IOException { sink.writeUtf8(params.toString()); } }; Uri uri = Uri.parse(mMetadataUrl); String url = uri.buildUpon().appendEncodedPath("nodes/" + file.getId()).build().toString(); Request request = new Request.Builder().url(url) .header("Authorization", String.format("Bearer %s", mAccessToken)).patch(body).build(); try { Response response = mHttpClient.newCall(request).execute(); if (response.isSuccessful()) { // return file object return buildFile(new JSONObject(response.body().string())); } else { throw new RequestFailException(response.message(), response.code()); } } catch (JSONException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } catch (IOException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } }
From source file:com.he5ed.lib.cloudprovider.apis.CloudDriveApi.java
@Override public CFolder createFolder(@NonNull String name, @Nullable CFolder parent) throws RequestFailException { if (TextUtils.isEmpty(mAccessToken)) { throw new RequestFailException("Access token not available"); }/* w w w. j av a 2s.c o m*/ Uri uri = Uri.parse(mMetadataUrl); String url = uri.buildUpon().appendEncodedPath("nodes/").build().toString(); // create parameter as json final JSONObject params = new JSONObject(); try { params.put("name", name); params.put("kind", "FOLDER"); ArrayList<String> parentList = new ArrayList<>(); parentList.add(parent != null ? parent.getId() : getRoot().getId()); params.put("parents", new JSONArray(parentList)); } catch (JSONException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } RequestBody body = new RequestBody() { @Override public MediaType contentType() { return JSON; } @Override public void writeTo(BufferedSink sink) throws IOException { sink.writeUtf8(params.toString()); } }; Request request = new Request.Builder().url(url) .header("Authorization", String.format("Bearer %s", mAccessToken)).post(body).build(); try { Response response = mHttpClient.newCall(request).execute(); if (response.isSuccessful()) { JSONObject jsonObject = new JSONObject(response.body().string()); return buildFolder(jsonObject); } else { throw new RequestFailException(response.message(), response.code()); } } catch (JSONException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } catch (IOException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } }
From source file:com.he5ed.lib.cloudprovider.apis.CloudDriveApi.java
@Override public CFolder renameFolder(@NonNull CFolder folder, String name) throws RequestFailException { if (TextUtils.isEmpty(mAccessToken)) { throw new RequestFailException("Access token not available"); }/*from www .jav a2 s.com*/ // exit if root or same name if (folder.isRoot() || folder.getName().equals(name)) return folder; // create parameter as json final JSONObject params = new JSONObject(); try { params.put("name", name); } catch (JSONException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } RequestBody body = new RequestBody() { @Override public MediaType contentType() { return JSON; } @Override public void writeTo(BufferedSink sink) throws IOException { sink.writeUtf8(params.toString()); } }; Uri uri = Uri.parse(mMetadataUrl); String url = uri.buildUpon().appendEncodedPath("nodes/" + folder.getId()).build().toString(); Request request = new Request.Builder().url(url) .header("Authorization", String.format("Bearer %s", mAccessToken)).patch(body).build(); try { Response response = mHttpClient.newCall(request).execute(); if (response.isSuccessful()) { // return folder object return buildFolder(new JSONObject(response.body().string())); } else { throw new RequestFailException(response.message(), response.code()); } } catch (JSONException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } catch (IOException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } }
From source file:com.he5ed.lib.cloudprovider.apis.CloudDriveApi.java
@Override public CFile renameFile(@NonNull CFile file, String name) throws RequestFailException { if (TextUtils.isEmpty(mAccessToken)) { throw new RequestFailException("Access token not available"); }//from ww w . j ava 2 s .c o m // exist if same filename if (file.getName().equals(name)) return file; // create parameter as json final JSONObject params = new JSONObject(); try { params.put("name", name); } catch (JSONException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } RequestBody body = new RequestBody() { @Override public MediaType contentType() { return JSON; } @Override public void writeTo(BufferedSink sink) throws IOException { sink.writeUtf8(params.toString()); } }; Uri uri = Uri.parse(mMetadataUrl); String url = uri.buildUpon().appendEncodedPath("nodes/" + file.getId()).build().toString(); Request request = new Request.Builder().url(url) .header("Authorization", String.format("Bearer %s", mAccessToken)).patch(body).build(); try { Response response = mHttpClient.newCall(request).execute(); if (response.isSuccessful()) { // return file object return buildFile(new JSONObject(response.body().string())); } else { throw new RequestFailException(response.message(), response.code()); } } catch (JSONException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } catch (IOException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } }
From source file:com.he5ed.lib.cloudprovider.apis.CloudDriveApi.java
@Override public CFolder moveFolder(@NonNull CFolder folder, @Nullable CFolder parent) throws RequestFailException { if (TextUtils.isEmpty(mAccessToken)) { throw new RequestFailException("Access token not available"); }/* w w w . ja v a 2s .c o m*/ // exit if root or same name if (folder.isRoot() || parent != null && folder.getId().equals(parent.getId())) return folder; // create parameter as json final JSONObject params = new JSONObject(); try { ArrayList<String> parentList = new ArrayList<>(); parentList.add(parent != null ? parent.getId() : getRoot().getId()); params.put("parents", new JSONArray(parentList)); } catch (JSONException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } RequestBody body = new RequestBody() { @Override public MediaType contentType() { return JSON; } @Override public void writeTo(BufferedSink sink) throws IOException { sink.writeUtf8(params.toString()); } }; Uri uri = Uri.parse(mMetadataUrl); String url = uri.buildUpon().appendEncodedPath("nodes/" + folder.getId()).build().toString(); Request request = new Request.Builder().url(url) .header("Authorization", String.format("Bearer %s", mAccessToken)).patch(body).build(); try { Response response = mHttpClient.newCall(request).execute(); if (response.isSuccessful()) { // return folder object return buildFolder(new JSONObject(response.body().string())); } else { throw new RequestFailException(response.message(), response.code()); } } catch (JSONException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } catch (IOException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } }
From source file:com.he5ed.lib.cloudprovider.apis.CloudDriveApi.java
@Override public synchronized List<Object> exploreFolder(@NonNull CFolder folder, int offset) throws RequestFailException { if (TextUtils.isEmpty(mAccessToken)) { throw new RequestFailException("Access token not available"); }//w w w . j a v a 2 s . co m // if folder id is empty set it to root id if (TextUtils.isEmpty(folder.getId())) folder.setId(getRootId()); List<Object> list = new ArrayList<>(); String folderId = folder.getId(); Uri uri = Uri.parse(mMetadataUrl); String url = uri.buildUpon().appendEncodedPath("nodes/" + folderId + "/children").build().toString(); Request request = new Request.Builder().url(url) .header("Authorization", String.format("Bearer %s", mAccessToken)).get().build(); try { Response response = mHttpClient.newCall(request).execute(); if (response.isSuccessful()) { JSONObject jsonObject = new JSONObject(response.body().string()); int total = jsonObject.getInt("count"); // return null if no item found if (total == 0) return null; JSONArray entries = jsonObject.getJSONArray("data"); list.addAll(createItemList(entries)); // pagination available if (jsonObject.has("nextToken")) { list.addAll(exploreFolderContinue(folderId, jsonObject.getString("nextToken"))); } return list; } else { switch (response.code()) { case 404: // no item found throw new RequestFailException("No item found"); case 401: // unauthorized throw new RequestFailException("Unauthorized request"); default: break; } } } catch (JSONException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } catch (IOException e) { e.printStackTrace(); throw new RequestFailException(e.getMessage()); } return null; }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public int delete(Uri uri, boolean notifyChange) { uri = uri.buildUpon() .appendQueryParameter(MechanoidContentProvider.PARAM_NOTIFY, String.valueOf(notifyChange)).build(); ContentResolver resolver = Mechanoid.getContentResolver(); return resolver.delete(uri, toString(), getArgsArray()); }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public int update(Uri uri, ContentValues values, boolean notifyChange) { uri = uri.buildUpon() .appendQueryParameter(MechanoidContentProvider.PARAM_NOTIFY, String.valueOf(notifyChange)).build(); ContentResolver resolver = Mechanoid.getContentResolver(); return resolver.update(uri, values, toString(), getArgsArray()); }
From source file:de.vanita5.twittnuker.fragment.support.UserProfileFragment.java
@Override public void onLinkClick(final String link, final String orig, final long account_id, final int type, final boolean sensitive) { final ParcelableUser user = mUser; if (user == null) return;//from w w w . j a v a 2 s . c o m switch (type) { case TwidereLinkify.LINK_TYPE_MENTION: { openUserProfile(getActivity(), user.account_id, -1, link); break; } case TwidereLinkify.LINK_TYPE_HASHTAG: { openTweetSearch(getActivity(), user.account_id, link); break; } case TwidereLinkify.LINK_TYPE_LINK: { final Uri uri = Uri.parse(link); final Intent intent; if (uri.getScheme() != null) { intent = new Intent(Intent.ACTION_VIEW, uri); } else { intent = new Intent(Intent.ACTION_VIEW, uri.buildUpon().scheme("http").build()); } startActivity(intent); break; } case TwidereLinkify.LINK_TYPE_LIST: { final String[] mention_list = link.split("\\/"); if (mention_list == null || mention_list.length != 2) { break; } break; } case TwidereLinkify.LINK_TYPE_STATUS: { openStatus(getActivity(), account_id, parseLong(link)); break; } } }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public android.support.v4.content.CursorLoader createSupportLoader(Uri uri, String[] projection, boolean enableNotifications) { uri = uri.buildUpon() .appendQueryParameter(MechanoidContentProvider.PARAM_NOTIFY, String.valueOf(enableNotifications)) .build();/* w w w . j ava 2s. c om*/ return new android.support.v4.content.CursorLoader(Mechanoid.getApplicationContext(), uri, projection, toString(), getArgsArray(), null); }