List of usage examples for android.net Uri withAppendedPath
public static Uri withAppendedPath(Uri baseUri, String pathSegment)
From source file:com.kyakujin.android.autoeco.ui.BatteryFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle arg) { switch (id) { case BatteryQuery.LOADER_ID: return new CursorLoader(getActivity(), Uri.withAppendedPath(BatteryTbl.CONTENT_URI, String.valueOf(mCurrentBatteryId)), BatteryQuery.PROJECTION, null, null, null); default://from w w w . java 2 s.c o m break; } return null; }
From source file:net.niyonkuru.koodroid.ui.UsageFragment.java
@Override public void onResume() { super.onResume(); final ContentResolver cr = mContext.getContentResolver(); final Uri billingCycleUri = Uri.withAppendedPath(Settings.CONTENT_URI, Settings.BILLING_CYCLE); cr.registerContentObserver(billingCycleUri, false, mBillingCycleChangeObserver); }
From source file:ca.rmen.android.scrumchatter.member.list.Members.java
/** * Marks a member as deleted.//from w ww .j av a 2s . c om */ public void deleteMember(final long memberId) { Log.v(TAG, "delete member " + memberId); // Delete the member in a background thread Schedulers.io().scheduleDirect(() -> { Uri uri = Uri.withAppendedPath(MemberColumns.CONTENT_URI, String.valueOf(memberId)); ContentValues values = new ContentValues(1); values.put(MemberColumns.DELETED, 1); mActivity.getContentResolver().update(uri, values, null, null); }); }
From source file:org.sufficientlysecure.keychain.util.ContactHelper.java
/** * Retrieves the emails of the primary profile contact * http://developer.android.com/reference/android/provider/ContactsContract.Profile.html *///from w w w .j av a2 s . c om private Set<String> getMainProfileContactEmails() { if (!isContactsPermissionGranted()) { return new HashSet<>(); } Cursor profileCursor = mContentResolver.query( Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI, ContactsContract.Contacts.Data.CONTENT_DIRECTORY), new String[] { ContactsContract.CommonDataKinds.Email.ADDRESS, ContactsContract.CommonDataKinds.Email.IS_PRIMARY }, // Selects only email addresses ContactsContract.Contacts.Data.MIMETYPE + "=?", new String[] { ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE, }, // Show primary rows first. Note that there won't be a primary email address if the // user hasn't specified one. ContactsContract.Contacts.Data.IS_PRIMARY + " DESC"); if (profileCursor == null) { return new HashSet<>(); } Set<String> emails = new HashSet<>(); while (profileCursor.moveToNext()) { String email = profileCursor.getString(0); if (email != null) { emails.add(email); } } profileCursor.close(); return emails; }
From source file:cz.maresmar.sfm.view.menu.day.DayMenuFragment.java
@NonNull @Override/*from w w w . j av a2 s . com*/ public Loader<Cursor> onCreateLoader(int id, @Nullable Bundle args) { switch (id) { case PORTAL_LOADER_ID: { Uri daysUri = Uri.withAppendedPath(mUserUri, ProviderContract.PORTAL_PATH); return new CursorLoader(getContext(), daysUri, new String[] { ProviderContract.Portal._ID, ProviderContract.Portal.NAME }, null, null, null); } case MENU_LOADER_ID: { Uri menuUri = Uri.withAppendedPath(mUserUri, ProviderContract.MENU_ENTRY_PATH); String selection = ProviderContract.MenuEntry.DATE + " = " + mDate; if (mAvailableMenuOnly) { selection += " AND (" + "(" + ProviderContract.MenuEntry.REMAINING_TO_TAKE + " > 0 ) OR " + "(" + ProviderContract.MenuEntry.REMAINING_TO_ORDER + " > 0 ) OR " + "(" + ProviderContract.MenuEntry.SYNCED_RESERVED_AMOUNT + " > 0 ) OR " + "((" + ProviderContract.MenuEntry.STATUS + " & " + ProviderContract.MENU_STATUS_ORDERABLE + ") == " + ProviderContract.MENU_STATUS_ORDERABLE + ")" + ")"; } return new CursorLoader(getContext(), menuUri, MenuViewAdapter.PROJECTION, selection, null, ProviderContract.MenuEntry.PORTAL_ID + " ASC"); } default: throw new UnsupportedOperationException("Unknown loader id: " + id); } }
From source file:com.mutu.gpstracker.breadcrumbs.UploadBreadcrumbsTrackTask.java
/** * Retrieve the OAuth Request Token and present a browser to the user to * authorize the token.//from w ww . ja va 2 s . c om */ @Override protected Uri doInBackground(Void... params) { // Leave room in the progressbar for uploading determineProgressGoal(); mProgressAdmin.setUpload(true); // Build GPX file Uri gpxFile = exportGpx(); if (isCancelled()) { String text = mContext.getString(R.string.ticker_failed) + " \"http://api.gobreadcrumbs.com/v1/tracks\" " + mContext.getString(R.string.error_buildxml); handleError(mContext.getString(R.string.taskerror_breadcrumbs_upload), new IOException("Fail to execute request due to canceling"), text); } // Collect GPX Import option params mActivityId = null; mBundleId = null; mDescription = null; mIsPublic = null; Uri metadataUri = Uri.withAppendedPath(mTrackUri, "metadata"); Cursor cursor = null; try { cursor = mContext.getContentResolver().query(metadataUri, new String[] { MetaData.KEY, MetaData.VALUE }, null, null, null); if (cursor.moveToFirst()) { do { String key = cursor.getString(0); if (BreadcrumbsTracks.ACTIVITY_ID.equals(key)) { mActivityId = cursor.getString(1); } else if (BreadcrumbsTracks.BUNDLE_ID.equals(key)) { mBundleId = cursor.getString(1); } else if (BreadcrumbsTracks.DESCRIPTION.equals(key)) { mDescription = cursor.getString(1); } else if (BreadcrumbsTracks.ISPUBLIC.equals(key)) { mIsPublic = cursor.getString(1); } } while (cursor.moveToNext()); } } finally { if (cursor != null) { cursor.close(); } } if ("-1".equals(mActivityId)) { String text = "Unable to upload without a activity id stored in meta-data table"; IllegalStateException e = new IllegalStateException(text); handleError(mContext.getString(R.string.taskerror_breadcrumbs_upload), e, text); } int statusCode = 0; String responseText = null; Uri trackUri = null; HttpEntity responseEntity = null; try { if ("-1".equals(mBundleId)) { mBundleDescription = "";//mContext.getString(R.string.breadcrumbs_bundledescription); mBundleName = mContext.getString(R.string.app_name); mBundleId = createOpenGpsTrackerBundle(); } String gpxString = XmlCreator .convertStreamToString(mContext.getContentResolver().openInputStream(gpxFile)); HttpPost method = new HttpPost("http://api.gobreadcrumbs.com:80/v1/tracks"); if (isCancelled()) { throw new IOException("Fail to execute request due to canceling"); } // Build the multipart body with the upload data MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); entity.addPart("import_type", new StringBody("GPX")); //entity.addPart("gpx", new FileBody(gpxFile)); entity.addPart("gpx", new StringBody(gpxString)); entity.addPart("bundle_id", new StringBody(mBundleId)); entity.addPart("activity_id", new StringBody(mActivityId)); entity.addPart("description", new StringBody(mDescription)); // entity.addPart("difficulty", new StringBody("3")); // entity.addPart("rating", new StringBody("4")); entity.addPart("public", new StringBody(mIsPublic)); method.setEntity(entity); // Execute the POST to OpenStreetMap mConsumer.sign(method); if (BreadcrumbsAdapter.DEBUG) { Log.d(TAG, "HTTP Method " + method.getMethod()); Log.d(TAG, "URI scheme " + method.getURI().getScheme()); Log.d(TAG, "Host name " + method.getURI().getHost()); Log.d(TAG, "Port " + method.getURI().getPort()); Log.d(TAG, "Request path " + method.getURI().getPath()); Log.d(TAG, "Consumer Key: " + mConsumer.getConsumerKey()); Log.d(TAG, "Consumer Secret: " + mConsumer.getConsumerSecret()); Log.d(TAG, "Token: " + mConsumer.getToken()); Log.d(TAG, "Token Secret: " + mConsumer.getTokenSecret()); Log.d(TAG, "Execute request: " + method.getURI()); for (Header header : method.getAllHeaders()) { Log.d(TAG, " with header: " + header.toString()); } } HttpResponse response = mHttpClient.execute(method); mProgressAdmin.addUploadProgress(); statusCode = response.getStatusLine().getStatusCode(); responseEntity = response.getEntity(); InputStream stream = responseEntity.getContent(); responseText = XmlCreator.convertStreamToString(stream); if (BreadcrumbsAdapter.DEBUG) { Log.d(TAG, "Upload Response: " + responseText); } Pattern p = Pattern.compile(">([0-9]+)</id>"); Matcher m = p.matcher(responseText); if (m.find()) { Integer trackId = Integer.valueOf(m.group(1)); trackUri = Uri.parse("http://api.gobreadcrumbs.com/v1/tracks/" + trackId + "/placemarks.gpx"); for (File photo : mPhotoUploadQueue) { uploadPhoto(photo, trackId); } } } catch (OAuthMessageSignerException e) { mService.removeAuthentication(); handleError(mContext.getString(R.string.taskerror_breadcrumbs_upload), e, "Failed to sign the request with authentication signature"); } catch (OAuthExpectationFailedException e) { mService.removeAuthentication(); handleError(mContext.getString(R.string.taskerror_breadcrumbs_upload), e, "The request did not authenticate"); } catch (OAuthCommunicationException e) { mService.removeAuthentication(); handleError(mContext.getString(R.string.taskerror_breadcrumbs_upload), e, "The authentication communication failed"); } catch (IOException e) { handleError(mContext.getString(R.string.taskerror_breadcrumbs_upload), e, "A problem during communication"); } finally { if (responseEntity != null) { try { //EntityUtils.consume(responseEntity); responseEntity.consumeContent(); } catch (IOException e) { Log.e(TAG, "Failed to close the content stream", e); } } } if (statusCode == 200 || statusCode == 201) { if (trackUri == null) { handleError(mContext.getString(R.string.taskerror_breadcrumbs_upload), new IOException("Unable to retrieve URI from response"), responseText); } } else { //mAdapter.removeAuthentication(); handleError(mContext.getString(R.string.taskerror_breadcrumbs_upload), new IOException("Status code: " + statusCode), responseText); } return trackUri; }
From source file:org.andrico.andrico.facebook.FBBase.java
/** * Create a URL that can be used in a web browser to allow a user to * authorize an app permanently. Success redirects the user to: * https://login.facebook.com/code_gen.php See: * http://wiki.developers.facebook// www . j a v a 2s.com * .com/index.php/Authentication_guide#Creating_Infinite_Sessions * * @return */ public Uri authorizeInfiniteSessionUrl() { // Its really hard to track the mobile url. // return "http://m.facebook.com/code_gen.php?v=1.0&api_key=" + mApiKey; return Uri.withAppendedPath(WWW_URI, "code_gen.php?v=1.0&api_key=" + mApiKey); }
From source file:fr.shywim.antoinedaniel.sync.AppState.java
/** * Load AppState from a JSONObject.// www . j av a 2s . c o m * * @param data json to import. */ void importFromJSON(JSONObject data, Context context, GoogleApiClient apiClient) { Gson gson = new Gson(); try { ContentValues cv = new ContentValues(); Set<String> widgetSounds = gson.fromJson(data.getJSONArray(WIDGET_SOUNDS).toString(), this.widgetSounds.getClass()); for (String soundName : widgetSounds) { synchronized (LOCK) { this.widgetSounds.add(soundName); } Uri uri = Uri.withAppendedPath(ProviderConstants.SOUND_NAME_URI, soundName); cv.clear(); cv.put(ProviderContract.SoundEntry.COLUMN_WIDGET, 1); context.getContentResolver().update(uri, cv, null, null); } Set<String> favSounds = gson.fromJson(data.getJSONArray(FAVORITES_SOUNDS).toString(), this.favSounds.getClass()); for (String soundName : favSounds) { synchronized (LOCK) { this.favSounds.add(soundName); } Uri uri = Uri.withAppendedPath(ProviderConstants.SOUND_NAME_URI, soundName); cv.clear(); cv.put(ProviderContract.SoundEntry.COLUMN_FAVORITE, 1); context.getContentResolver().update(uri, cv, null, null); } Map<String, String> bestScores = gson.fromJson(data.getJSONObject(BEST_SCORES).toString(), this.bestScores.getClass()); for (Map.Entry<String, String> entry : bestScores.entrySet()) { long newLong = Long.parseLong(entry.getValue()); synchronized (LOCK) { if (this.bestScores.containsKey(entry.getKey()) && Long.parseLong(this.bestScores.get(entry.getKey())) <= newLong) this.bestScores.put(entry.getKey(), entry.getValue()); } if (apiClient != null) { Games.Leaderboards.submitScore(apiClient, entry.getKey(), newLong); } } } catch (JSONException e) { e.printStackTrace(); } }
From source file:edu.mit.mobile.android.locast.data.TaggableItem.java
/** * @param cr/*from w ww. ja va 2 s . co m*/ * @param item * @param prefix * @return a list of all the tags attached to a given item */ public static Set<String> getTags(ContentResolver cr, Uri item, String prefix) { final Cursor tags = cr.query(Uri.withAppendedPath(item, Tag.PATH), Tag.DEFAULT_PROJECTION, null, null, null); final Set<String> tagSet = new HashSet<String>(tags.getCount()); final int tagColumn = tags.getColumnIndex(Tag._NAME); final Predicate<String> predicate = getPrefixPredicate(prefix); for (tags.moveToFirst(); !tags.isAfterLast(); tags.moveToNext()) { final String tag = tags.getString(tagColumn); if (predicate.apply(tag)) { final int separatorIndex = tag.indexOf(PREFIX_SEPARATOR); if (separatorIndex == -1) { tagSet.add(tag); } else { tagSet.add(tag.substring(separatorIndex + 1)); } } } tags.close(); return tagSet; }
From source file:edu.nd.darts.cimon.database.CimonDatabaseAdapter.java
/** * Insert new metric into Metrics table, or replace if the id already exist. * //from www .java 2 s . co m * @param id id which identifies individual metric to insert * @param group id of metric group this metric belongs to * @param metric name of metric * @param units units of metric values * @param max maximum potential value * @return rowid of inserted row, -1 on failure * * @see MetricsTable */ public synchronized long insertOrReplaceMetrics(int id, int group, String metric, String units, float max) { if (DebugLog.DEBUG) Log.d(TAG, "CimonDatabaseAdapter.insertOrReplaceMetrics - insert into Metrics table: metric-" + metric); ContentValues values = new ContentValues(); values.put(MetricsTable.COLUMN_ID, id); values.put(MetricsTable.COLUMN_INFO_ID, group); values.put(MetricsTable.COLUMN_METRIC, metric); values.put(MetricsTable.COLUMN_UNITS, units); values.put(MetricsTable.COLUMN_MAX, max); long rowid = database.replace(MetricsTable.TABLE_METRICS, null, values); if (rowid >= 0) { Uri uri = Uri.withAppendedPath(CimonContentProvider.METRICS_URI, String.valueOf(id)); context.getContentResolver().notifyChange(uri, null); } return rowid; }