Java Code Examples for android.content.ContentUris#appendId()

The following examples show how to use android.content.ContentUris#appendId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContactListManagerAdapter.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
void insertBlockedContactToDataBase(Contact contact) {
    // Remove the blocked contact if it already exists, to avoid duplicates and
    // handle the odd case where a blocked contact's nickname has changed
    removeBlockedContactFromDataBase(contact);

    Uri.Builder builder = Imps.BlockedList.CONTENT_URI.buildUpon();
    ContentUris.appendId(builder,  mConn.getProviderId());
    ContentUris.appendId(builder, mConn.getAccountId());
    Uri uri = builder.build();

    String username = mAdaptee.normalizeAddress(contact.getAddress().getAddress());
    ContentValues values = new ContentValues(2);
    values.put(Imps.BlockedList.USERNAME, username);
    values.put(Imps.BlockedList.NICKNAME, contact.getName());

    mResolver.insert(uri, values);

    mValidatedBlockedContacts.add(username);
}
 
Example 2
Source File: ContactListManagerAdapter.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
private void removeObsoleteContactsAndLists() {
    // remove all contacts for this provider & account which have not been
    // added since login, yet still exist in db from a prior login
    Exclusion exclusion = new Exclusion(Imps.Contacts.USERNAME, mValidatedContacts);
    mResolver.delete(mContactUrl, exclusion.getSelection(), exclusion.getSelectionArgs());

    // remove all blocked contacts for this provider & account which have not been
    // added since login, yet still exist in db from a prior login
    exclusion = new Exclusion(Imps.BlockedList.USERNAME, mValidatedBlockedContacts);
    Uri.Builder builder = Imps.BlockedList.CONTENT_URI.buildUpon();
    ContentUris.appendId(builder, mConn.getProviderId());
    ContentUris.appendId(builder, mConn.getAccountId());
    Uri uri = builder.build();
    mResolver.delete(uri, exclusion.getSelection(), exclusion.getSelectionArgs());

    // remove all contact lists for this provider & account which have not been
    // added since login, yet still exist in db from a prior login
    exclusion = new Exclusion(Imps.ContactList.NAME, mValidatedContactLists);
    builder = Imps.ContactList.CONTENT_URI.buildUpon();
    ContentUris.appendId(builder, mConn.getProviderId());
    ContentUris.appendId(builder, mConn.getAccountId());
    uri = builder.build();
    mResolver.delete(uri, exclusion.getSelection(), exclusion.getSelectionArgs());

}
 
Example 3
Source File: HoraireFragment.java    From ETSMobile-Android2 with Apache License 2.0 6 votes vote down vote up
protected void onPostExecute(Object result) {

            customProgressDialog.dismiss();
            if (exception != null) {
                Toast.makeText(getActivity(), getString(R.string.toast_Calendar_Update_Error), Toast.LENGTH_SHORT).show();
            } else {

                //Launch native calendar app
                long startMillis = java.lang.System.currentTimeMillis();
                Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
                builder.appendPath("time");
                ContentUris.appendId(builder, startMillis);

                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(builder.build());

                startActivity(intent);

            }
        }
 
Example 4
Source File: SuntimesActivity.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void showCalendar(boolean tomorrow)
{
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    {
        long startMillis = (tomorrow ? dataset.otherCalendar().getTimeInMillis() : dataset.calendar().getTimeInMillis());
        Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
        builder.appendPath("time");
        ContentUris.appendId(builder, startMillis);
        Intent intent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
        startActivity(intent);
    }
}
 
Example 5
Source File: ContactListManagerAdapter.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
void removeBlockedContactFromDataBase(Contact contact) {
    String address = mAdaptee.normalizeAddress(contact.getAddress().getAddress());

    Uri.Builder builder = Imps.BlockedList.CONTENT_URI.buildUpon();
    ContentUris.appendId(builder,  mConn.getProviderId());
    ContentUris.appendId(builder, mConn.getAccountId());

    Uri uri = builder.build();
    mResolver.delete(uri, Imps.BlockedList.USERNAME + "=?", new String[] { address });

    //int type = isTemporary(address) ? Imps.Contacts.TYPE_TEMPORARY : Imps.Contacts.TYPE_NORMAL;

    updateContactType(address, Imps.Contacts.TYPE_NORMAL);
}
 
Example 6
Source File: ContactListManagerAdapter.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
private void init ()
{
    mContactListListenerAdapter = new ContactListListenerAdapter();
    mSubscriptionListenerAdapter = new SubscriptionRequestListenerAdapter();
    mContactLists = new HashMap<String, ContactListAdapter>();
    mTemporaryContacts = new HashMap<String, Contact>();
   // mOfflineContacts = new HashMap<String, Contact>();

    mValidatedContacts = new HashSet<String>();
    mValidatedContactLists = new HashSet<String>();
    mValidatedBlockedContacts = new HashSet<String>();

    mAdaptee.addContactListListener(mContactListListenerAdapter);
    mAdaptee.setSubscriptionRequestListener(mSubscriptionListenerAdapter);

    Uri.Builder builder = Imps.Avatars.CONTENT_URI_AVATARS_BY.buildUpon();
    ContentUris.appendId(builder,  mConn.getProviderId());
    ContentUris.appendId(builder, mConn.getAccountId());

    mAvatarUrl = builder.build();

    builder = Imps.Contacts.CONTENT_URI_CONTACTS_BY.buildUpon();
    ContentUris.appendId(builder,  mConn.getProviderId());
    ContentUris.appendId(builder, mConn.getAccountId());

    mContactUrl = builder.build();

    if (mConn.getAccountId() != -1)
        seedInitialPresences();

}
 
Example 7
Source File: IntentCall.java    From RememBirthday with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Open calendar application at specific time
 * @param context Context to call
 * @param date Date to show in calendar
 */
public static void openCalendarAt(android.content.Context context, java.util.Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
    builder.appendPath("time");
    ContentUris.appendId(builder, calendar.getTimeInMillis());
    Intent intent = new Intent(Intent.ACTION_VIEW)
            .setData(builder.build());
    try {
        context.startActivity(intent);
    } catch(ActivityNotFoundException e) {
        Log.e(context.getClass().getSimpleName(), e.toString());
    }
}
 
Example 8
Source File: EventListActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
private ArrayList<EventPojo> getCalenderEvents() {
    Uri.Builder eventsUriBuilder = CalendarContract.Instances.CONTENT_URI.buildUpon();

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.SECOND, 0);
    ContentUris.appendId(eventsUriBuilder, calendar.getTimeInMillis());
    ContentUris.appendId(eventsUriBuilder, calendar.getTimeInMillis() + 86400000);
    Uri eventsUri = eventsUriBuilder.build();
    Log.d("events uri",eventsUri + "");
    final String[] columns = new String[]{
            CalendarContract.Events.TITLE,
            CalendarContract.Events.DESCRIPTION
    };
    Cursor calCursor = getContentResolver().query(eventsUri, columns, null, null, CalendarContract.Instances.DTSTART + " ASC");

    ArrayList<EventPojo> eventPojos = new ArrayList<>();
    if (calCursor != null) {
        if (calCursor.moveToFirst()) {
            do {
                EventPojo calenderPojo = new EventPojo();
                calenderPojo.setTitle(calCursor.getString(0));
                calenderPojo.setDescription(calCursor.getString(1));
                eventPojos.add(calenderPojo);

            } while (calCursor.moveToNext());
        }
        calCursor.close();
    }
    return eventPojos;
}
 
Example 9
Source File: CalendarTracker.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public CheckEventResult checkEvent(EventInfo filter, long time) {
    final Uri.Builder uriBuilder = Instances.CONTENT_URI.buildUpon();
    ContentUris.appendId(uriBuilder, time);
    ContentUris.appendId(uriBuilder, time + EVENT_CHECK_LOOKAHEAD);
    final Uri uri = uriBuilder.build();
    final Cursor cursor = mUserContext.getContentResolver().query(uri, INSTANCE_PROJECTION,
            null, null, INSTANCE_ORDER_BY);
    final CheckEventResult result = new CheckEventResult();
    result.recheckAt = time + EVENT_CHECK_LOOKAHEAD;
    try {
        final ArraySet<Long> primaryCalendars = getPrimaryCalendars();
        while (cursor != null && cursor.moveToNext()) {
            final long begin = cursor.getLong(0);
            final long end = cursor.getLong(1);
            final String title = cursor.getString(2);
            final boolean calendarVisible = cursor.getInt(3) == 1;
            final int eventId = cursor.getInt(4);
            final String name = cursor.getString(5);
            final String owner = cursor.getString(6);
            final long calendarId = cursor.getLong(7);
            final int availability = cursor.getInt(8);
            final boolean calendarPrimary = primaryCalendars.contains(calendarId);
            if (DEBUG) Log.d(TAG, String.format(
                    "%s %s-%s v=%s a=%s eid=%s n=%s o=%s cid=%s p=%s",
                    title,
                    new Date(begin), new Date(end), calendarVisible,
                    availabilityToString(availability), eventId, name, owner, calendarId,
                    calendarPrimary));
            final boolean meetsTime = time >= begin && time < end;
            final boolean meetsCalendar = calendarVisible && calendarPrimary
                    && (filter.calendar == null || Objects.equals(filter.calendar, owner)
                    || Objects.equals(filter.calendar, name));
            final boolean meetsAvailability = availability != Instances.AVAILABILITY_FREE;
            if (meetsCalendar && meetsAvailability) {
                if (DEBUG) Log.d(TAG, "  MEETS CALENDAR & AVAILABILITY");
                final boolean meetsAttendee = meetsAttendee(filter, eventId, owner);
                if (meetsAttendee) {
                    if (DEBUG) Log.d(TAG, "    MEETS ATTENDEE");
                    if (meetsTime) {
                        if (DEBUG) Log.d(TAG, "      MEETS TIME");
                        result.inEvent = true;
                    }
                    if (begin > time && begin < result.recheckAt) {
                        result.recheckAt = begin;
                    } else if (end > time && end < result.recheckAt) {
                        result.recheckAt = end;
                    }
                }
            }
        }
    } catch (Exception e) {
        Slog.w(TAG, "error reading calendar", e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return result;
}
 
Example 10
Source File: ContactListManagerAdapter.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
private void seedInitialPresences() {
    Builder builder = Imps.Presence.SEED_PRESENCE_BY_ACCOUNT_CONTENT_URI.buildUpon();
    ContentUris.appendId(builder, mConn.getAccountId());
    mResolver.insert(builder.build(), new ContentValues(0));
}
 
Example 11
Source File: DatabaseUtils.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
public static Uri getAvatarUri(Uri baseUri, long providerId, long accountId) {
    Uri.Builder builder = baseUri.buildUpon();
    ContentUris.appendId(builder, providerId);
    ContentUris.appendId(builder, accountId);
    return builder.build();
}
 
Example 12
Source File: Imps.java    From Zom-Android-XMPP with GNU General Public License v3.0 3 votes vote down vote up
/**
 * @deprecated
 *
 *             Gets the Uri to query off the record messages by account
 *             and contact.
 *
 * @param accountId the account id of the contact.
 * @param username the user name of the contact.
 * @return the Uri
 */
public static final Uri getOtrMessagesContentUriByContact(long accountId, String username) {
    Uri.Builder builder = OTR_MESSAGES_CONTENT_URI_BY_ACCOUNT_AND_CONTACT.buildUpon();
    ContentUris.appendId(builder, accountId);
    builder.appendPath(username);
    return builder.build();
}
 
Example 13
Source File: CalendarContract.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Retrieves the days with events for the Julian days starting at
 * "startDay" for "numDays". It returns a cursor containing startday and
 * endday representing the max range of days for all events beginning on
 * each startday.This is a blocking function and should not be done on
 * the UI thread.
 *
 * @param cr the ContentResolver
 * @param startDay the first Julian day in the range
 * @param numDays the number of days to load (must be at least 1)
 * @param projection the columns to return in the cursor
 * @return a database cursor containing a list of start and end days for
 *         events
 */
public static final Cursor query(ContentResolver cr, int startDay, int numDays,
        String[] projection) {
    if (numDays < 1) {
        return null;
    }
    int endDay = startDay + numDays - 1;
    Uri.Builder builder = CONTENT_URI.buildUpon();
    ContentUris.appendId(builder, startDay);
    ContentUris.appendId(builder, endDay);
    return cr.query(builder.build(), projection, SELECTION,
            null /* selection args */, STARTDAY);
}
 
Example 14
Source File: CalendarContract.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Performs a query to return all visible instances in the given range
 * that match the given query. This is a blocking function and should
 * not be done on the UI thread. This will cause an expansion of
 * recurring events to fill this time range if they are not already
 * expanded and will slow down for larger time ranges with many
 * recurring events.
 *
 * @param cr The ContentResolver to use for the query
 * @param projection The columns to return
 * @param begin The start of the time range to query in UTC millis since
 *            epoch
 * @param end The end of the time range to query in UTC millis since
 *            epoch
 * @param searchQuery A string of space separated search terms. Segments
 *            enclosed by double quotes will be treated as a single
 *            term.
 * @return A Cursor of instances matching the search terms in the given
 *         time range
 */
public static final Cursor query(ContentResolver cr, String[] projection,
                                 long begin, long end, String searchQuery) {
    Uri.Builder builder = CONTENT_SEARCH_URI.buildUpon();
    ContentUris.appendId(builder, begin);
    ContentUris.appendId(builder, end);
    builder = builder.appendPath(searchQuery);
    return cr.query(builder.build(), projection, WHERE_CALENDARS_SELECTED,
            WHERE_CALENDARS_ARGS, DEFAULT_SORT_ORDER);
}
 
Example 15
Source File: CalendarContract.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Performs a query to return all visible instances in the given range.
 * This is a blocking function and should not be done on the UI thread.
 * This will cause an expansion of recurring events to fill this time
 * range if they are not already expanded and will slow down for larger
 * time ranges with many recurring events.
 *
 * @param cr The ContentResolver to use for the query
 * @param projection The columns to return
 * @param begin The start of the time range to query in UTC millis since
 *            epoch
 * @param end The end of the time range to query in UTC millis since
 *            epoch
 * @return A Cursor containing all instances in the given range
 */
public static final Cursor query(ContentResolver cr, String[] projection,
                                 long begin, long end) {
    Uri.Builder builder = CONTENT_URI.buildUpon();
    ContentUris.appendId(builder, begin);
    ContentUris.appendId(builder, end);
    return cr.query(builder.build(), projection, WHERE_CALENDARS_SELECTED,
            WHERE_CALENDARS_ARGS, DEFAULT_SORT_ORDER);
}
 
Example 16
Source File: Imps.java    From Zom-Android-XMPP with GNU General Public License v3.0 3 votes vote down vote up
/**
 * @deprecated
 *
 *             Gets the Uri to query messages by account and contact.
 *
 * @param accountId the account id of the contact.
 * @param username the user name of the contact.
 * @return the Uri
 */
public static final Uri getContentUriByContact(long accountId, String username) {
    Uri.Builder builder = CONTENT_URI_MESSAGES_BY_ACCOUNT_AND_CONTACT.buildUpon();
    ContentUris.appendId(builder, accountId);
    builder.appendPath(username);
    return builder.build();
}
 
Example 17
Source File: Imps.java    From Zom-Android-XMPP with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the Uri to query off the record messages by account.
 *
 * @param accountId the account id.
 * @return the Uri
 */
public static final Uri getOtrMessagesContentUriByAccount(long accountId) {
    Uri.Builder builder = OTR_MESSAGES_CONTENT_URI_BY_ACCOUNT.buildUpon();
    ContentUris.appendId(builder, accountId);
    return builder.build();
}
 
Example 18
Source File: Imps.java    From Zom-Android-XMPP with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the Uri to query off the record messages by thread id.
 *
 * @param threadId the thread id of the message.
 * @return the Uri
 */
public static final Uri getOtrMessagesContentUriByThreadId(long threadId) {
    Uri.Builder builder = OTR_MESSAGES_CONTENT_URI_BY_THREAD_ID.buildUpon();
    ContentUris.appendId(builder, threadId);
    return builder.build();
}
 
Example 19
Source File: Imps.java    From Zom-Android-XMPP with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the Uri to query messages by provider.
 *
 * @param providerId the service provider id.
 * @return the Uri
 */
public static final Uri getContentUriByProvider(long providerId) {
    Uri.Builder builder = CONTENT_URI_MESSAGES_BY_PROVIDER.buildUpon();
    ContentUris.appendId(builder, providerId);
    return builder.build();
}
 
Example 20
Source File: Imps.java    From Zom-Android-XMPP with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the Uri to query messages by thread id.
 *
 * @param threadId the thread id of the message.
 * @return the Uri
 */
public static final Uri getContentUriByThreadId(long threadId) {
    Uri.Builder builder = CONTENT_URI_MESSAGES_BY_THREAD_ID.buildUpon();
    ContentUris.appendId(builder, threadId);
    return builder.build();
}