List of usage examples for android.net Uri withAppendedPath
public static Uri withAppendedPath(Uri baseUri, String pathSegment)
From source file:com.dsdar.thosearoundme.util.ContactsListFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { // If this is the loader for finding contacts in the Contacts Provider // (the only one supported) if (id == ContactsQuery.QUERY_ID) { Uri contentUri;/*from w ww .j av a 2s. c o m*/ // There are two types of searches, one which displays all contacts // and // one which filters contacts by a search query. If mSearchTerm is // set // then a search query has been entered and the latter should be // used. if (mSearchTerm == null) { // Since there's no search string, use the content URI that // searches the entire // Contacts table contentUri = ContactsQuery.CONTENT_URI; } else { // Since there's a search string, use the special content Uri // that searches the // Contacts table. The URI consists of a base Uri and the search // string. contentUri = Uri.withAppendedPath(ContactsQuery.FILTER_URI, Uri.encode(mSearchTerm)); } // Returns a new CursorLoader for querying the Contacts table. No // arguments are used // for the selection clause. The search string is either encoded // onto the content URI, // or no contacts search string is used. The other search criteria // are constants. See // the ContactsQuery interface. return new CursorLoader(getActivity(), contentUri, ContactsQuery.PROJECTION, ContactsQuery.SELECTION, null, ContactsQuery.SORT_ORDER); } Log.e(TAG, "onCreateLoader - incorrect ID provided (" + id + ")"); return null; }
From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // android.os.Debug.waitForDebugger(); mPropertyManager = new PropertyManager(this); // must be at the beginning of any activity that can be called from an // external intent setAppName("survey"); Uri uri = getIntent().getData();/*from w w w . j a v a 2s . c om*/ Uri formUri = null; if (uri != null) { // initialize to the URI, then we will customize further based upon the // savedInstanceState... final Uri uriFormsProvider = FormsProviderAPI.CONTENT_URI; final Uri uriWebView = UrlUtils.getWebViewContentUri(this); if (uri.getScheme().equalsIgnoreCase(uriFormsProvider.getScheme()) && uri.getAuthority().equalsIgnoreCase(uriFormsProvider.getAuthority())) { List<String> segments = uri.getPathSegments(); if (segments != null && segments.size() == 1) { String appName = segments.get(0); setAppName(appName); } else if (segments != null && segments.size() >= 2) { String appName = segments.get(0); setAppName(appName); formUri = Uri.withAppendedPath(Uri.withAppendedPath(uriFormsProvider, appName), segments.get(1)); } else { assignContentView(); createErrorDialog(getString(R.string.invalid_uri_expecting_n_segments, uri.toString(), 2), EXIT); return; } } else if (uri.getScheme().equals(uriWebView.getScheme()) && uri.getAuthority().equals(uriWebView.getAuthority()) && uri.getPort() == uriWebView.getPort()) { List<String> segments = uri.getPathSegments(); if (segments != null && segments.size() == 1) { String appName = segments.get(0); setAppName(appName); } else { assignContentView(); createErrorDialog(getString(R.string.invalid_uri_expecting_one_segment, uri.toString()), EXIT); return; } } else { assignContentView(); createErrorDialog(getString(R.string.unrecognized_uri, uri.toString(), uriWebView.toString(), uriFormsProvider.toString()), EXIT); return; } } if (savedInstanceState != null) { // if appName is explicitly set, use it... setAppName(savedInstanceState.containsKey(APP_NAME) ? savedInstanceState.getString(APP_NAME) : getAppName()); if (savedInstanceState.containsKey(CONFLICT_TABLES)) { mConflictTables = savedInstanceState.getBundle(CONFLICT_TABLES); } } WebLogger.getLogger(getAppName()).i(t, "Starting up, creating directories"); try { String appName = getAppName(); if (appName != null && appName.length() != 0) { ODKFileUtils.verifyExternalStorageAvailability(); ODKFileUtils.assertDirectoryStructure(appName); } } catch (RuntimeException e) { assignContentView(); createErrorDialog(e.getMessage(), EXIT); return; } if (savedInstanceState != null) { // if we are restoring, assume that initialization has already occurred. pageWaitingForData = savedInstanceState.containsKey(PAGE_WAITING_FOR_DATA) ? savedInstanceState.getString(PAGE_WAITING_FOR_DATA) : null; pathWaitingForData = savedInstanceState.containsKey(PATH_WAITING_FOR_DATA) ? savedInstanceState.getString(PATH_WAITING_FOR_DATA) : null; actionWaitingForData = savedInstanceState.containsKey(ACTION_WAITING_FOR_DATA) ? savedInstanceState.getString(ACTION_WAITING_FOR_DATA) : null; currentFragment = ScreenList.valueOf(savedInstanceState.containsKey(CURRENT_FRAGMENT) ? savedInstanceState.getString(CURRENT_FRAGMENT) : currentFragment.name()); if (savedInstanceState.containsKey(FORM_URI)) { FormIdStruct newForm = FormIdStruct.retrieveFormIdStruct(getContentResolver(), Uri.parse(savedInstanceState.getString(FORM_URI))); if (newForm != null) { setAppName(newForm.appName); setCurrentForm(newForm); } } setInstanceId(savedInstanceState.containsKey(INSTANCE_ID) ? savedInstanceState.getString(INSTANCE_ID) : getInstanceId()); setUploadTableId( savedInstanceState.containsKey(UPLOAD_TABLE_ID) ? savedInstanceState.getString(UPLOAD_TABLE_ID) : getUploadTableId()); String tmpScreenPath = savedInstanceState.containsKey(SCREEN_PATH) ? savedInstanceState.getString(SCREEN_PATH) : getScreenPath(); String tmpControllerState = savedInstanceState.containsKey(CONTROLLER_STATE) ? savedInstanceState.getString(CONTROLLER_STATE) : getControllerState(); setSectionScreenState(tmpScreenPath, tmpControllerState); setAuxillaryHash( savedInstanceState.containsKey(AUXILLARY_HASH) ? savedInstanceState.getString(AUXILLARY_HASH) : getAuxillaryHash()); if (savedInstanceState.containsKey(SESSION_VARIABLES)) { sessionVariables = savedInstanceState.getBundle(SESSION_VARIABLES); } if (savedInstanceState.containsKey(SECTION_STATE_SCREEN_HISTORY)) { sectionStateScreenHistory = savedInstanceState.getParcelableArrayList(SECTION_STATE_SCREEN_HISTORY); } } else if (formUri != null) { // request specifies a specific formUri -- try to open that FormIdStruct newForm = FormIdStruct.retrieveFormIdStruct(getContentResolver(), formUri); if (newForm == null) { // can't find it -- launch the initialization dialog to hopefully // discover it. WebLogger.getLogger(getAppName()).i(t, "onCreate -- calling setRunInitializationTask"); Survey.getInstance().setRunInitializationTask(getAppName()); currentFragment = ScreenList.WEBKIT; } else { transitionToFormHelper(uri, newForm); } } assignContentView(); }
From source file:org.spontaneous.trackservice.RemoteService.java
/** * Trigged by events that start a new segment *///from ww w .j a v a2 s . c om private void startNewSegment() { this.mDistance = 0; this.mPreviousLocation = null; Uri newSegment = getContentResolver().insert( Uri.withAppendedPath(Tracks.CONTENT_URI, this.mTrackId + "/segments"), new ContentValues(0)); this.mSegmentId = Long.valueOf(newSegment.getLastPathSegment()).longValue(); // crashProtectState(); }
From source file:org.spontaneous.trackservice.RemoteService.java
private void updateSegment() { if (this.mSegmentId > 0L) { ContentValues args = new ContentValues(); args.put(SegmentsColumns.END_TIME, System.currentTimeMillis()); Uri segmentUpdateUri = Uri.withAppendedPath(Tracks.CONTENT_URI, this.mTrackId + "/segments/" + this.mSegmentId); getContentResolver().update(segmentUpdateUri, args, null, null); }// ww w .j av a2 s .c o m }
From source file:com.dsdar.thosearoundme.util.ContactsListFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // This swaps the new cursor into the adapter. if (loader.getId() == ContactsQuery.QUERY_ID) { mAdapter.swapCursor(data);//from www.j a va 2 s .c o m // If this is a two-pane layout and there is a search query then // there is some additional work to do around default selected // search item. if (mIsTwoPaneLayout && !TextUtils.isEmpty(mSearchTerm) && mSearchQueryChanged) { // Selects the first item in results, unless this fragment has // been restored from a saved state (like orientation change) // in which case it selects the previously selected search item. if (data != null && data.moveToPosition(mPreviouslySelectedSearchItem)) { // Creates the content Uri for the previously selected // contact by appending the // contact's ID to the Contacts table content Uri final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_URI, String.valueOf(data.getLong(ContactsQuery.ID))); mOnContactSelectedListener.onContactSelected(uri); getListView().setItemChecked(mPreviouslySelectedSearchItem, true); } else { // No results, clear selection. onSelectionCleared(); } // Only restore from saved state one time. Next time fall back // to selecting first item. If the fragment state is saved again // then the currently selected item will once again be saved. mPreviouslySelectedSearchItem = 0; mSearchQueryChanged = false; } } }
From source file:org.spontaneous.trackservice.RemoteService.java
public TrackModel readTrackAndSegmentsById(Long trackId) { TrackModel trackModel = null;/*w w w . j ava2s .c o m*/ if (trackId != null) { String[] mTrackColumns = { Tracks._ID, Tracks.NAME, Tracks.TOTAL_DISTANCE, Tracks.TOTAL_DURATION, Tracks.USER_ID, Tracks.CREATION_TIME }; // Read track Uri trackReadUri = Uri.withAppendedPath(Tracks.CONTENT_URI, String.valueOf(trackId)); Cursor mCursor = getContentResolver().query(trackReadUri, mTrackColumns, null, null, Tracks.CREATION_TIME); if (mCursor != null && mCursor.moveToNext()) { trackModel = new TrackModel(Long.valueOf(mCursor.getString(mCursor.getColumnIndex(Tracks._ID))), mCursor.getString(mCursor.getColumnIndex(Tracks.NAME)), mCursor.getFloat(mCursor.getColumnIndex(Tracks.TOTAL_DISTANCE)), mCursor.getLong(mCursor.getColumnIndex(Tracks.TOTAL_DURATION)), mCursor.getLong(mCursor.getColumnIndex(Tracks.CREATION_TIME)), Integer.valueOf(mCursor.getColumnIndex(Tracks.USER_ID))); // Read Segments and wayPoints String[] mSegmentsColumns = { BaseColumns._ID, SegmentsColumns.TRACK, SegmentsColumns.START_TIME, SegmentsColumns.END_TIME }; Uri segmentReadUri = Uri.withAppendedPath(Tracks.CONTENT_URI, String.valueOf(trackId) + "/segments/"); Cursor mSegmentsCursor = getContentResolver().query(segmentReadUri, mSegmentsColumns, null, null, Segments._ID); if (mSegmentsCursor != null) { SegmentModel segmentModel = null; while (mSegmentsCursor.moveToNext()) { segmentModel = new SegmentModel(); segmentModel.setId(Long .valueOf(mSegmentsCursor.getString(mSegmentsCursor.getColumnIndex(Segments._ID)))); segmentModel.setTrackId(Long.valueOf( mSegmentsCursor.getString(mSegmentsCursor.getColumnIndex(Segments.TRACK)))); segmentModel.setStartTimeInMillis( mSegmentsCursor.getLong(mSegmentsCursor.getColumnIndex(Segments.START_TIME))); segmentModel.setEndTimeInMillis( mSegmentsCursor.getLong(mSegmentsCursor.getColumnIndex(Segments.END_TIME))); trackModel.addSegment(segmentModel); } } } } return trackModel; }
From source file:com.android.gallery3d.filtershow.FilterShowActivity.java
public void completeSaveImage(Uri saveUri) { if (mSharingImage && mSharedOutputFile != null) { // Image saved, we unblock the content provider Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI, Uri.encode(mSharedOutputFile.getAbsolutePath())); ContentValues values = new ContentValues(); values.put(SharedImageProvider.PREPARE, false); getContentResolver().insert(uri, values); }//from w w w . j a v a2 s . com setResult(RESULT_OK, new Intent().setData(saveUri)); hideSavingProgress(); finish(); }
From source file:com.raibow.yamahaspk.filtershow.FilterShowActivity.java
public void completeSaveImage(Uri saveUri) { if (saveUri == null) { hideSavingProgress();// www .ja v a 2 s.c o m CharSequence text = getString(R.string.save_image_failed); Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT); toast.show(); finish(); } else { if (mSharingImage && mSharedOutputFile != null) { // Image saved, we unblock the content provider Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI, Uri.encode(mSharedOutputFile.getAbsolutePath())); ContentValues values = new ContentValues(); values.put(SharedImageProvider.PREPARE, false); getContentResolver().insert(uri, values); } setResult(RESULT_OK, new Intent().setData(saveUri)); hideSavingProgress(); finish(); } }
From source file:org.path.episample.android.activities.MainMenuActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // android.os.Debug.waitForDebugger(); mPropertyManager = new PropertyManager(this); mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); // must be at the beginning of any activity that can be called from an // external intent setAppName("survey"); Uri uri = getIntent().getData();//from w w w . j a v a 2s. c om Uri formUri = null; if (uri != null) { // initialize to the URI, then we will customize further based upon the // savedInstanceState... final Uri uriFormsProvider = FormsProviderAPI.CONTENT_URI; final Uri uriWebView = UrlUtils.getWebViewContentUri(this); if (uri.getScheme().equalsIgnoreCase(uriFormsProvider.getScheme()) && uri.getAuthority().equalsIgnoreCase(uriFormsProvider.getAuthority())) { List<String> segments = uri.getPathSegments(); if (segments != null && segments.size() == 1) { String appName = segments.get(0); setAppName(appName); } else if (segments != null && segments.size() >= 2) { String appName = segments.get(0); setAppName(appName); formUri = Uri.withAppendedPath(Uri.withAppendedPath(uriFormsProvider, appName), segments.get(1)); } else { assignContentView(); createErrorDialog(getString(R.string.invalid_uri_expecting_n_segments, uri.toString(), 2), EXIT); return; } } else if (uri.getScheme().equals(uriWebView.getScheme()) && uri.getAuthority().equals(uriWebView.getAuthority()) && uri.getPort() == uriWebView.getPort()) { List<String> segments = uri.getPathSegments(); if (segments != null && segments.size() == 1) { String appName = segments.get(0); setAppName(appName); } else { assignContentView(); createErrorDialog(getString(R.string.invalid_uri_expecting_one_segment, uri.toString()), EXIT); return; } } else { assignContentView(); createErrorDialog(getString(R.string.unrecognized_uri, uri.toString(), uriWebView.toString(), uriFormsProvider.toString()), EXIT); return; } } if (savedInstanceState != null) { // if appName is explicitly set, use it... setAppName(savedInstanceState.containsKey(APP_NAME) ? savedInstanceState.getString(APP_NAME) : getAppName()); if (savedInstanceState.containsKey(CONFLICT_TABLES)) { mConflictTables = savedInstanceState.getBundle(CONFLICT_TABLES); } } WebLogger.getLogger(getAppName()).i(t, "Starting up, creating directories"); try { String appName = getAppName(); if (appName != null && appName.length() != 0) { ODKFileUtils.verifyExternalStorageAvailability(); ODKFileUtils.assertDirectoryStructure(appName); } } catch (RuntimeException e) { assignContentView(); createErrorDialog(e.getMessage(), EXIT); return; } if (savedInstanceState != null) { // if we are restoring, assume that initialization has already occurred. pageWaitingForData = savedInstanceState.containsKey(PAGE_WAITING_FOR_DATA) ? savedInstanceState.getString(PAGE_WAITING_FOR_DATA) : null; pathWaitingForData = savedInstanceState.containsKey(PATH_WAITING_FOR_DATA) ? savedInstanceState.getString(PATH_WAITING_FOR_DATA) : null; actionWaitingForData = savedInstanceState.containsKey(ACTION_WAITING_FOR_DATA) ? savedInstanceState.getString(ACTION_WAITING_FOR_DATA) : null; currentFragment = ScreenList.valueOf(savedInstanceState.containsKey(CURRENT_FRAGMENT) ? savedInstanceState.getString(CURRENT_FRAGMENT) : currentFragment.name()); if (savedInstanceState.containsKey(FORM_URI)) { FormIdStruct newForm = FormIdStruct.retrieveFormIdStruct(getContentResolver(), Uri.parse(savedInstanceState.getString(FORM_URI))); if (newForm != null) { setAppName(newForm.appName); setCurrentForm(newForm); } } setInstanceId(savedInstanceState.containsKey(INSTANCE_ID) ? savedInstanceState.getString(INSTANCE_ID) : getInstanceId()); setUploadTableId( savedInstanceState.containsKey(UPLOAD_TABLE_ID) ? savedInstanceState.getString(UPLOAD_TABLE_ID) : getUploadTableId()); String tmpScreenPath = savedInstanceState.containsKey(SCREEN_PATH) ? savedInstanceState.getString(SCREEN_PATH) : getScreenPath(); String tmpControllerState = savedInstanceState.containsKey(CONTROLLER_STATE) ? savedInstanceState.getString(CONTROLLER_STATE) : getControllerState(); setSectionScreenState(tmpScreenPath, tmpControllerState); setAuxillaryHash( savedInstanceState.containsKey(AUXILLARY_HASH) ? savedInstanceState.getString(AUXILLARY_HASH) : getAuxillaryHash()); if (savedInstanceState.containsKey(SESSION_VARIABLES)) { sessionVariables = savedInstanceState.getBundle(SESSION_VARIABLES); } if (savedInstanceState.containsKey(SECTION_STATE_SCREEN_HISTORY)) { sectionStateScreenHistory = savedInstanceState.getParcelableArrayList(SECTION_STATE_SCREEN_HISTORY); } } else if (formUri != null) { // request specifies a specific formUri -- try to open that FormIdStruct newForm = FormIdStruct.retrieveFormIdStruct(getContentResolver(), formUri); if (newForm == null) { // can't find it -- launch the initialization dialog to hopefully // discover it. WebLogger.getLogger(getAppName()).i(t, "onCreate -- calling setRunInitializationTask"); Survey.getInstance().setRunInitializationTask(getAppName()); currentFragment = ScreenList.WEBKIT; } else { transitionToFormHelper(uri, newForm); } } assignContentView(); }
From source file:com.android.gallery3d.filtershow.FilterShowActivity.java
@Override public boolean onShareTargetSelected(ShareActionProvider arg0, Intent arg1) { // First, let's tell the SharedImageProvider that it will need to wait // for the image Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI, Uri.encode(mSharedOutputFile.getAbsolutePath())); ContentValues values = new ContentValues(); values.put(SharedImageProvider.PREPARE, true); getContentResolver().insert(uri, values); mSharingImage = true;/* w w w . j a va 2 s . com*/ // Process and save the image in the background. showSavingProgress(null); mImageShow.saveImage(this, mSharedOutputFile); return true; }