Example usage for android.net Uri withAppendedPath

List of usage examples for android.net Uri withAppendedPath

Introduction

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

Prototype

public static Uri withAppendedPath(Uri baseUri, String pathSegment) 

Source Link

Document

Creates a new Uri by appending an already-encoded path segment to a base Uri.

Usage

From source file:cx.ring.fragments.CallListFragment.java

private void startConversation(CallContact c) {
    Intent intent = new Intent().setClass(getActivity(), ConversationActivity.class)
            .setAction(Intent.ACTION_VIEW)
            .setData(Uri.withAppendedPath(ConversationActivity.CONTENT_URI, c.getIds().get(0)));
    intent.putExtra("resuming", true);
    startActivityForResult(intent, HomeActivity.REQUEST_CODE_CONVERSATION);
}

From source file:at.flack.MainActivity.java

public static String getContactName(Context context, String phoneNumber) {
    if (phoneNumber == null || phoneNumber.length() == 0)
        return phoneNumber;
    ContentResolver cr = context.getContentResolver();
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
    Cursor cursor = cr.query(uri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null);
    if (cursor == null) {
        return null;
    }//from  w  w w . j  a v  a2s  .  c  om
    String contactName = null;
    if (cursor.moveToFirst()) {
        contactName = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME));
    }

    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }

    return contactName;
}

From source file:cx.ring.fragments.SmartListFragment.java

private void startConversation(CallContact c) {
    if (mSearchMenuItem != null) {
        mSearchMenuItem.collapseActionView();
    }/*w ww  .j a va  2s.  c  o m*/

    Intent intent = new Intent().setClass(getActivity(), ConversationActivity.class)
            .setAction(Intent.ACTION_VIEW)
            .setData(Uri.withAppendedPath(ConversationActivity.CONTENT_URI, c.getIds().get(0)));
    startActivityForResult(intent, HomeActivity.REQUEST_CODE_CONVERSATION);
}

From source file:com.mutu.gpstracker.breadcrumbs.UploadBreadcrumbsTrackTask.java

private String createOpenGpsTrackerBundle() throws OAuthMessageSignerException, OAuthExpectationFailedException,
        OAuthCommunicationException, IOException {
    HttpPost method = new HttpPost("http://api.gobreadcrumbs.com/v1/bundles.xml");
    if (isCancelled()) {
        throw new IOException("Fail to execute request due to canceling");
    }// w w w  .  jav  a 2s. c om

    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    entity.addPart("name", new StringBody(mBundleName));
    entity.addPart("activity_id", new StringBody(mActivityId));
    entity.addPart("description", new StringBody(mBundleDescription));
    method.setEntity(entity);

    mConsumer.sign(method);
    HttpResponse response = mHttpClient.execute(method);
    HttpEntity responseEntity = response.getEntity();
    InputStream stream = responseEntity.getContent();
    String responseText = XmlCreator.convertStreamToString(stream);
    Pattern p = Pattern.compile(">([0-9]+)</id>");
    Matcher m = p.matcher(responseText);
    String bundleId = null;
    if (m.find()) {
        bundleId = m.group(1);

        ContentValues values = new ContentValues();
        values.put(MetaData.KEY, BreadcrumbsTracks.BUNDLE_ID);
        values.put(MetaData.VALUE, bundleId);
        Uri metadataUri = Uri.withAppendedPath(mTrackUri, "metadata");

        mContext.getContentResolver().insert(metadataUri, values);
        mIsBundleCreated = true;
    } else {
        String text = "Unable to upload (yet) without a bunld id stored in meta-data table";
        IllegalStateException e = new IllegalStateException(text);
        handleError(mContext.getString(R.string.taskerror_breadcrumbs_upload), e, text);
    }
    return bundleId;
}

From source file:name.gumartinm.weather.information.widget.WidgetIntentService.java

private RemoteViews makeErrorView(final int appWidgetId) {
    final RemoteViews remoteView = new RemoteViews(this.getApplicationContext().getPackageName(),
            R.layout.appwidget_error);//w  w  w .j  a  v  a2s . c o m

    // 6. Activity launcher.
    final Intent resultIntent = new Intent(this.getApplicationContext(), WidgetConfigure.class);
    resultIntent.putExtra("actionFromUser", true);
    resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    // From: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget
    final Uri data = Uri.withAppendedPath(Uri.parse("PAIN" + "://widget/id/"), String.valueOf(appWidgetId));
    resultIntent.setData(data);

    final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext());
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(WidgetConfigure.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteView.setOnClickPendingIntent(R.id.weather_appwidget_error, resultPendingIntent);

    return remoteView;
}

From source file:edu.umbc.cs.ebiquity.mithril.parserapp.contentparsers.contacts.ContactsListFragment.java

private void getData() {
    Cursor data = getContacts();//  ww w.j av  a 2s.c  o m
    mAdapter.swapCursor(data);

    // 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:ut.ee.mh.WebServer.java

/**
 * Added by Carlos//www. java2s  .  c  o  m
 * 
 * @param serverConnection
 * @param request
 * @param requestLine
 * @throws IOException
 * @throws HttpException
 * @throws UnsupportedEncodingException
 */
private void handlePostRequest(DefaultHttpServerConnection serverConnection, HttpRequest request,
        RequestLine requestLine) throws IOException, HttpException, UnsupportedEncodingException {
    HttpResponse response = new BasicHttpResponse(new HttpVersion(1, 1), 200, "OK");
    String folderId = getFolderId(requestLine.getUri());
    processUpload(folderId, request, serverConnection);
    String header = getHTMLHeader();
    String form = getUploadForm(folderId);
    String footer = getHTMLFooter();
    String listing = getFileListing(Uri.withAppendedPath(FileSharingProvider.Folders.CONTENT_URI, folderId));
    response.setEntity(new StringEntity(header + listing + form + footer));
    serverConnection.sendResponseHeader(response);
    serverConnection.sendResponseEntity(response);
}

From source file:org.fdroid.enigtext.contacts.ContactAccessor.java

/***
 * If the code below looks shitty to you, that's because it was taken
 * directly from the Android source, where shitty code is all you get.
 */// ww  w  .  j av a2  s  .com

public Cursor getCursorForRecipientFilter(CharSequence constraint, ContentResolver mContentResolver) {
    final String SORT_ORDER = Contacts.TIMES_CONTACTED + " DESC," + Contacts.DISPLAY_NAME + "," + Phone.TYPE;

    final String[] PROJECTION_PHONE = { Phone._ID, // 0
            Phone.CONTACT_ID, // 1
            Phone.TYPE, // 2
            Phone.NUMBER, // 3
            Phone.LABEL, // 4
            Phone.DISPLAY_NAME, // 5
    };

    String phone = "";
    String cons = null;

    if (constraint != null) {
        cons = constraint.toString();

        if (RecipientsAdapter.usefulAsDigits(cons)) {
            phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons);
            if (phone.equals(cons)) {
                phone = "";
            } else {
                phone = phone.trim();
            }
        }
    }

    Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(cons));
    String selection = String.format("%s=%s OR %s=%s OR %s=%s", Phone.TYPE, Phone.TYPE_MOBILE, Phone.TYPE,
            Phone.TYPE_WORK_MOBILE, Phone.TYPE, Phone.TYPE_MMS);

    Cursor phoneCursor = mContentResolver.query(uri, PROJECTION_PHONE, null, null, SORT_ORDER);

    if (phone.length() > 0) {
        ArrayList result = new ArrayList();
        result.add(Integer.valueOf(-1)); // ID
        result.add(Long.valueOf(-1)); // CONTACT_ID
        result.add(Integer.valueOf(Phone.TYPE_CUSTOM)); // TYPE
        result.add(phone); // NUMBER

        /*
        * The "\u00A0" keeps Phone.getDisplayLabel() from deciding
        * to display the default label ("Home") next to the transformation
        * of the letters into numbers.
        */
        result.add("\u00A0"); // LABEL
        result.add(cons); // NAME

        ArrayList<ArrayList> wrap = new ArrayList<ArrayList>();
        wrap.add(result);

        ArrayListCursor translated = new ArrayListCursor(PROJECTION_PHONE, wrap);

        return new MergeCursor(new Cursor[] { translated, phoneCursor });
    } else {
        return phoneCursor;
    }
}

From source file:com.mstoyanov.music_lessons.ScheduleFragment.java

@Override
public Loader<Cursor> onCreateLoader(int loaderID, Bundle bundle) {
    switch (loaderID) {
    case LESSONS_LOADER:
        String innerJoin = " INNER JOIN " + Students.TABLE_NAME + " ON " + "schedule."
                + Schedule.COLUMN_NAME_STUDENT_ID + " = " + "students." + Students.COLUMN_NAME_STUDENT_ID;
        Uri uri = Uri.withAppendedPath(SchoolContract.SCHEDULE_TABLE_CONTENTURI, innerJoin);
        return new CursorLoader(getActivity(), // context
                uri, // uri
                projection_lessons, // projection
                selection_lessons, // selection
                selectionArgs_lessons, // selectionArgs
                sortOrder // timeFrom, timeTo
        );/*  www.jav  a  2 s  .  c  o  m*/
    case ACTIONS_LOADER:
        return new CursorLoader(getActivity(), // context
                SchoolContract.STUDENTS_TABLE_CONTENTURI, // table
                projection_actions, // projection
                selection_actions, // selection
                selectionArgs_actions, // selectionArgs
                null // sortOrder
        );
    default:
        throw new IllegalArgumentException("Invalid loaderID: " + loaderID);
    }
}

From source file:com.haedrian.curo.HomeScreen.Contacts.ContactDetailFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    switch (id) {
    // Two main queries to load the required information
    case ContactDetailQuery.QUERY_ID:
        // This query loads main contact details, see
        // ContactDetailQuery for more information.
        return new CursorLoader(getActivity(), mContactUri, ContactDetailQuery.PROJECTION, null, null, null);
    case ContactEmailQuery.QUERY_ID:
        final Uri emailUri = Uri.withAppendedPath(mContactUri, Contacts.Data.CONTENT_DIRECTORY);

        ContactEmailQuery.mSelectionArgs[0] = mContactUri.getLastPathSegment();

        return new CursorLoader(getActivity(), emailUri, ContactEmailQuery.PROJECTION,
                ContactEmailQuery.SELECTION, ContactEmailQuery.mSelectionArgs, null);
    }/*from w w w. j  av  a  2s .  co m*/
    return null;
}