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:com.nononsenseapps.feeder.model.RssSyncHelper.java

/**
 * Adds the information contained in the feed to the list of pending
 * operations, to be committed with applyBatch.
 *
 * @param context//from ww  w  .j ava2s  . co m
 * @param operations
 * @param feed
 */
public static void syncFeedBatch(final Context context, final ArrayList<ContentProviderOperation> operations,
        final BackendAPIClient.Feed feed) {

    // This is the index of the feed, if needed for backreferences
    final int feedIndex = operations.size();

    // Create the insert/update feed operation first
    final ContentProviderOperation.Builder feedOp;
    // Might not exist yet
    final long feedId = getFeedSQLId(context, feed);
    if (feedId < 1) {
        feedOp = ContentProviderOperation.newInsert(FeedSQL.URI_FEEDS);
    } else {
        feedOp = ContentProviderOperation
                .newUpdate(Uri.withAppendedPath(FeedSQL.URI_FEEDS, Long.toString(feedId)));
    }
    // Populate with values
    feedOp.withValue(FeedSQL.COL_TITLE, feed.title).withValue(FeedSQL.COL_TAG, feed.tag == null ? "" : feed.tag)
            .withValue(FeedSQL.COL_TIMESTAMP, feed.timestamp).withValue(FeedSQL.COL_URL, feed.link);
    // Add to list of operations
    operations.add(feedOp.build());

    // Now the feeds, might be null
    if (feed.items == null) {
        return;
    }

    for (BackendAPIClient.FeedItem item : feed.items) {
        // Always insert, have on conflict clause
        ContentProviderOperation.Builder itemOp = ContentProviderOperation
                .newInsert(FeedItemSQL.URI_FEED_ITEMS);

        // First, reference feed's id with back ref if insert
        if (feedId < 1) {
            itemOp.withValueBackReference(FeedItemSQL.COL_FEED, feedIndex);
        } else {
            // Use the actual id, because update operation will not return id
            itemOp.withValue(FeedItemSQL.COL_FEED, feedId);
        }
        // Next all the other values. Make sure non null
        itemOp.withValue(FeedItemSQL.COL_GUID, item.guid).withValue(FeedItemSQL.COL_LINK, item.link)
                .withValue(FeedItemSQL.COL_FEEDTITLE, feed.title)
                .withValue(FeedItemSQL.COL_TAG, feed.tag == null ? "" : feed.tag)
                .withValue(FeedItemSQL.COL_IMAGEURL, item.image).withValue(FeedItemSQL.COL_JSON, item.json)
                .withValue(FeedItemSQL.COL_ENCLOSURELINK, item.enclosure)
                .withValue(FeedItemSQL.COL_AUTHOR, item.author)
                .withValue(FeedItemSQL.COL_PUBDATE, FeedItemSQL.getPubDateFromString(item.published))
                // Make sure these are non-null
                .withValue(FeedItemSQL.COL_TITLE, item.title == null ? "" : item.title)
                .withValue(FeedItemSQL.COL_DESCRIPTION, item.description == null ? "" : item.description)
                .withValue(FeedItemSQL.COL_PLAINTITLE, item.title_stripped == null ? "" : item.title_stripped)
                .withValue(FeedItemSQL.COL_PLAINSNIPPET, item.snippet == null ? "" : item.snippet);

        // Add to list of operations
        operations.add(itemOp.build());

        // TODO pre-cache all images
    }
}

From source file:com.winsuk.pebbletype.WatchCommunication.java

private void sendThreadList(Context context) {
    Cursor msgCursor = context.getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null,
            null);/*from   www . j  a  v  a2  s  .c  om*/
    Activity act = new Activity();
    act.startManagingCursor(msgCursor);
    ArrayList<SMSThread> threads = new ArrayList<SMSThread>();

    if (msgCursor.moveToFirst()) {
        for (int i = 0; i < msgCursor.getCount(); i++) {
            int thread_id = msgCursor.getInt(msgCursor.getColumnIndexOrThrow("thread_id"));
            SMSThread th = null;
            for (int t = 0; t < threads.size(); t++) {
                SMSThread existingTh = threads.get(t);
                if (existingTh.thread_id == thread_id) {
                    th = existingTh;
                }
            }

            if (th == null) {
                String address = msgCursor.getString(msgCursor.getColumnIndexOrThrow("address")).toString();
                String name = "";

                Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, address);
                Cursor contactCursor = context.getContentResolver().query(uri,
                        new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null);
                if (contactCursor.moveToFirst()) {
                    name = contactCursor.getString(contactCursor.getColumnIndex(PhoneLookup.DISPLAY_NAME));
                    contactCursor.close();
                }

                th = new SMSThread();
                th.thread_id = thread_id;
                th.address = address;
                th.name = name;
                //th.messages = new ArrayList<String>();
                threads.add(th);
            }

            /* TODO: this line is causing crashes on select few devices
            String body = msgCursor.getString(msgCursor.getColumnIndexOrThrow("body")).toString();
            if (th.messages.size() < 5) {
               th.messages.add(body);
            }
            */

            msgCursor.moveToNext();
        }
    }
    msgCursor.close();

    int limit = (threads.size() <= THREAD_LIMIT ? threads.size() : THREAD_LIMIT);
    String output = "";

    if (limit > 0) {
        // Calculate how many characters names can take up
        int availibleCharacters = 120;
        for (int i = 0; i < limit; i++) {
            availibleCharacters -= threads.get(i).address.length();
            availibleCharacters -= 2; //for ; and \n
        }
        int maxNameLength = availibleCharacters / limit - 3;

        for (int i = 0; i < limit; i++) {
            SMSThread thread = threads.get(i);

            String name = "";
            if (thread.name.length() < maxNameLength) {
                name = thread.name;
            } else {
                name = thread.name.substring(0, maxNameLength - 1);
                name += "";
            }

            output = output + thread.address + ";" + name + "\n";

            /* List messages
            for (int ii = 0; ii < thread.messages.size(); ii++) {
               output = output + thread.messages.get(ii) + "\n";
            }*/
        }
    }
    PebbleDictionary data = new PebbleDictionary();
    data.addString(KEY_THREAD_LIST, output);
    PebbleKit.sendDataToPebble(context, PEBBLE_APP_UUID, data);
}

From source file:com.twolinessoftware.smarterlist.fragment.MasterListViewSearchFragment.java

private Cursor buildQueryCursor(String queryText) {
    return getBaseActivity().getContentResolver().query(
            Uri.withAppendedPath(m_masterListItemDAO.getProvider().getBaseContentUri(), "search"), null,
            "masterListName = ? and name MATCH ?",
            new String[] { Constants.DEFAULT_MASTERLIST_NAME, queryText }, "categoryId desc");

}

From source file:com.sublimis.urgentcallfilter.Magic.java

private boolean isCallerEligible() {
    boolean retVal = true;

    if (MyPreference.isContactsOnly()) {
        if (!strValidAndNotEmpty(mNumber)) {
            retVal = false;/* ww w  . j  av a  2 s .co  m*/
        } else {
            try {
                Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(mNumber));

                if (mContext != null) {
                    ContentResolver contentResolver = mContext.getContentResolver();

                    if (contentResolver != null) {
                        Cursor cur = contentResolver.query(uri, new String[] { PhoneLookup._ID }, null, null,
                                null);

                        if (cur == null || cur.getCount() <= 0) {
                            retVal = false;
                        }

                        if (cur != null) {
                            cur.close();
                        }
                    }
                }
            } catch (Exception e) {
            }
        }
    }

    return retVal;
}

From source file:org.openbmap.activities.CellsListContainer.java

@Override
public final Loader<Cursor> onCreateLoader(final int arg0, final Bundle arg1) {
    final DataHelper dataHelper = new DataHelper(getActivity());

    final String[] projection = { Schema.COL_ID, Schema.COL_ACTUAL_CELLID, Schema.COL_OPERATORNAME,
            Schema.COL_NETWORKTYPE, "MAX(" + Schema.COL_STRENGTHDBM + ")" };

    final int session = dataHelper.getActiveSessionId();

    // TODO: mSelection and mSelectionArgs are yet ignored
    final CursorLoader cursorLoader = new CursorLoader(getActivity().getBaseContext(),
            ContentUris.withAppendedId(Uri.withAppendedPath(RadioBeaconContentProvider.CONTENT_URI_CELL,
                    RadioBeaconContentProvider.CONTENT_URI_OVERVIEW_SUFFIX), session),
            projection, mSelection, mSelectionArgs, null);
    return cursorLoader;
}

From source file:com.android.contacts.common.model.ContactLoaderTest.java

public void testLoadContactWithOldStyleUri() {
    // Use content Uris that only contain the ID but use the format used in Donut
    final Uri legacyUri = ContentUris.withAppendedId(Uri.parse("content://contacts"), RAW_CONTACT_ID);
    final Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, RAW_CONTACT_ID);
    final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
    final Uri lookupUri = ContentUris
            .withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY), CONTACT_ID);
    final Uri entityUri = Uri.withAppendedPath(lookupUri, Contacts.Entity.CONTENT_DIRECTORY);

    ContactQueries queries = new ContactQueries();
    queries.fetchContactIdAndLookupFromRawContactUri(rawContactUri, CONTACT_ID, LOOKUP_KEY);
    queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);

    Contact contact = assertLoadContact(legacyUri);

    assertEquals(CONTACT_ID, contact.getId());
    assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
    assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
    assertEquals(LOOKUP_KEY, contact.getLookupKey());
    assertEquals(lookupUri, contact.getLookupUri());
    assertEquals(1, contact.getRawContacts().size());
    assertEquals(1, contact.getStatuses().size());
    mContactsProvider.verify();//from   ww  w.  ja  v  a  2  s  .co m
}

From source file:org.trakhound.www.trakhound.device_list.GetDevices.java

public static ListItem[] get(String id, String password, boolean remember) {

    if (id != null && password != null) {

        String url = Uri.withAppendedPath(ApiConfiguration.apiHost, "data/get/index.php").toString();

        PostData[] postDatas = new PostData[6];
        postDatas[0] = new PostData("id", id);
        postDatas[1] = new PostData("password", password);
        postDatas[2] = new PostData("sender_id", UserManagement.getSenderId());
        postDatas[3] = new PostData("command", "1101"); // Get Description, Status, and Oee tables
        if (remember)
            postDatas[4] = new PostData("remember", "1");
        else//ww w  .ja  v  a 2 s .  co m
            postDatas[4] = new PostData("remember", "0");
        postDatas[5] = new PostData("note", "TrakHound Mobile Android App - Get Devices Login");

        String response = Requests.post(url, postDatas);
        return processResponse(response);
    }

    return null;
}

From source file:com.securecomcode.text.contacts.ContactAccessor.java

public String getNameForNumber(Context context, String number) {
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);

    try {/*from  w w  w  .  jav a 2 s  .  c o m*/
        if (cursor != null && cursor.moveToFirst())
            return cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));
    } finally {
        if (cursor != null)
            cursor.close();
    }

    return null;
}

From source file:com.bydavy.card.receipts.activities.ReceiptPagerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home: {
        final Intent intent = new Intent(this, ReceiptListActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);/*from  ww w  .  j  a  v  a 2 s  .c o m*/
        return true;
    }
    case R.id.menu_edit: {
        final Intent intent = new Intent(this, ReceiptEditActivity.class);
        intent.putExtra(ReceiptEditActivity.INTENT_BUNDLE_RECEIPT_ID, mReceiptPagerFragment.getPageReceiptId());
        startActivity(intent);
        return true;
    }
    case R.id.menu_delete: {
        final long id = mReceiptPagerFragment.getPageReceiptId();
        final Uri uri = Uri.withAppendedPath(Receipts.CONTENT_URI, String.valueOf(id));
        final int rows = getContentResolver().delete(uri, null, null);
        if (rows != 1) {
            LogHelper.e(ErrorID.CONTENT_PROVIDER,
                    "Error when deleting a receipt (id:" + id + ", delete count: " + rows, null);
        }
        finish();
        return true;
    }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.vedant.hereami.chatfolder.MyFirebaseMessagingService.java

public String getContactDisplayNameByNumber(String number) {
    Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    String name = "?";

    ContentResolver contentResolver = getContentResolver();
    Cursor contactLookup = contentResolver.query(uri,
            new String[] { BaseColumns._ID, ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null);

    try {//w w w.  j a va  2 s  .com
        if (contactLookup != null && contactLookup.getCount() > 0) {
            contactLookup.moveToNext();
            name = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
            //String contactId = contactLookup.getString(contactLookup.getColumnIndex(BaseColumns._ID));
            hashMap.put(name, number);
        }
    } finally {
        if (contactLookup != null) {
            contactLookup.close();
        }
    }

    return name;
}