List of usage examples for android.content ContentUris appendId
public static Uri.Builder appendId(Uri.Builder builder, long id)
From source file:com.android.calendar.alerts.AlarmScheduler.java
/** * Queries events starting within a fixed interval from now. *//*w w w. java 2s . c om*/ private static Cursor queryUpcomingEvents(Context context, ContentResolver contentResolver, long currentMillis) { Time time = new Time(); time.normalize(false); long localOffset = time.gmtoff * 1000; final long localStartMin = currentMillis; final long localStartMax = localStartMin + EVENT_LOOKAHEAD_WINDOW_MS; final long utcStartMin = localStartMin - localOffset; final long utcStartMax = utcStartMin + EVENT_LOOKAHEAD_WINDOW_MS; if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) { //If permission is not granted then just return. Log.d(TAG, "Manifest.permission.READ_CALENDAR is not granted"); return null; } // Expand Instances table range by a day on either end to account for // all-day events. Uri.Builder uriBuilder = Instances.CONTENT_URI.buildUpon(); ContentUris.appendId(uriBuilder, localStartMin - DateUtils.DAY_IN_MILLIS); ContentUris.appendId(uriBuilder, localStartMax + DateUtils.DAY_IN_MILLIS); // Build query for all events starting within the fixed interval. StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("("); queryBuilder.append(INSTANCES_WHERE); queryBuilder.append(") OR ("); queryBuilder.append(INSTANCES_WHERE); queryBuilder.append(")"); String[] queryArgs = new String[] { // allday selection "1", /* visible = ? */ String.valueOf(utcStartMin), /* begin >= ? */ String.valueOf(utcStartMax), /* begin <= ? */ "1", /* allDay = ? */ // non-allday selection "1", /* visible = ? */ String.valueOf(localStartMin), /* begin >= ? */ String.valueOf(localStartMax), /* begin <= ? */ "0" /* allDay = ? */ }; Cursor cursor = contentResolver.query(uriBuilder.build(), INSTANCES_PROJECTION, queryBuilder.toString(), queryArgs, null); return cursor; }
From source file:com.grandilo.stanthony.MainActivity.java
private void setupDrawerContent(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override/*from w w w. j av a 2 s . c om*/ public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); mDrawerLayout.closeDrawers(); switch (menuItem.getItemId()) { case android.R.id.home: mDrawerLayout.openDrawer(GravityCompat.START); return true; case R.id.nav_reminder: // A date-time specified in milliseconds since the epoch. long startMillis = 0; 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); return true; case R.id.nav_feedback: startActivity(new Intent(MainActivity.this, FeedBack.class)); return true; case R.id.nav_about: startActivity(new Intent(MainActivity.this, About.class)); return true; } return true; } }); }
From source file:com.pindroid.platform.BookmarkManager.java
public static Bookmark GetById(int id, Context context) throws ContentNotFoundException { final String[] projection = new String[] { Bookmark.Account, Bookmark.Url, Bookmark.Description, Bookmark.Notes, Bookmark.Time, Bookmark.Tags, Bookmark.Hash, Bookmark.Meta, Bookmark.ToRead, Bookmark.Shared, Bookmark.Synced, Bookmark.Deleted }; String selection = Bookmark.Deleted + "=0"; Uri uri = ContentUris.appendId(Bookmark.CONTENT_URI.buildUpon(), id).build(); Cursor c = context.getContentResolver().query(uri, projection, selection, null, null); if (c.moveToFirst()) { final int accountColumn = c.getColumnIndex(Bookmark.Account); final int urlColumn = c.getColumnIndex(Bookmark.Url); final int descriptionColumn = c.getColumnIndex(Bookmark.Description); final int notesColumn = c.getColumnIndex(Bookmark.Notes); final int tagsColumn = c.getColumnIndex(Bookmark.Tags); final int hashColumn = c.getColumnIndex(Bookmark.Hash); final int metaColumn = c.getColumnIndex(Bookmark.Meta); final int timeColumn = c.getColumnIndex(Bookmark.Time); final int readColumn = c.getColumnIndex(Bookmark.ToRead); final int shareColumn = c.getColumnIndex(Bookmark.Shared); final int syncedColumn = c.getColumnIndex(Bookmark.Synced); final int deletedColumn = c.getColumnIndex(Bookmark.Deleted); final boolean read = c.getInt(readColumn) == 0 ? false : true; final boolean share = c.getInt(shareColumn) == 0 ? false : true; final int synced = c.getInt(syncedColumn); final boolean deleted = c.getInt(deletedColumn) == 0 ? false : true; Bookmark b = new Bookmark(id, c.getString(accountColumn), c.getString(urlColumn), c.getString(descriptionColumn), c.getString(notesColumn), c.getString(tagsColumn), c.getString(hashColumn), c.getString(metaColumn), c.getLong(timeColumn), read, share, synced, deleted);//from w ww.ja v a2 s .co m c.close(); return b; } else { c.close(); throw new ContentNotFoundException(); } }
From source file:com.xandy.calendar.month.MonthByWeekFragment.java
/** * Updates the uri used by the loader according to the current position of * the listview./*from w w w.ja v a 2 s . c o m*/ * * @return The new Uri to use */ private Uri updateUri() { SimpleWeekView child = (SimpleWeekView) mListView.getChildAt(0); if (child != null) { int julianDay = child.getFirstJulianDay(); mFirstLoadedJulianDay = julianDay; } // -1 to ensure we get all day events from any time zone mTempTime.setJulianDay(mFirstLoadedJulianDay - 1); long start = mTempTime.toMillis(true); mLastLoadedJulianDay = mFirstLoadedJulianDay + (mNumWeeks + 2 * WEEKS_BUFFER) * 7; // +1 to ensure we get all day events from any time zone mTempTime.setJulianDay(mLastLoadedJulianDay + 1); long end = mTempTime.toMillis(true); // Create a new uri with the updated times Uri.Builder builder = Instances.CONTENT_URI.buildUpon(); ContentUris.appendId(builder, start); ContentUris.appendId(builder, end); return builder.build(); }
From source file:com.android.calendar.month.MonthByWeekFragment.java
/** * Updates the uri used by the loader according to the current position of * the listview./*from w w w . j a v a 2 s .c om*/ * * @return The new Uri to use */ private Uri updateUri() { SimpleWeekView child = (SimpleWeekView) mListView.getChildAt(0); if (child != null) { int julianDay = child.getFirstJulianDay(); mFirstLoadedJulianDay = julianDay; } // -1 to ensure we get all day events from any time zone long milis = DateTimeUtils.fromJulianDay(mFirstLoadedJulianDay - 1); mTempTime.set(milis); long start = mTempTime.toMillis(true); mLastLoadedJulianDay = mFirstLoadedJulianDay + (mNumWeeks + 2 * WEEKS_BUFFER) * 7; // +1 to ensure we get all day events from any time zone milis = DateTimeUtils.fromJulianDay(mLastLoadedJulianDay + 1); mTempTime.set(milis); long end = mTempTime.toMillis(true); // Create a new uri with the updated times Uri.Builder builder = Instances.CONTENT_URI.buildUpon(); ContentUris.appendId(builder, start); ContentUris.appendId(builder, end); return builder.build(); }
From source file:com.wit.android.support.content.intent.CalendarIntent.java
/** *//*from w w w . java2 s .c o m*/ @Nullable @Override public Intent buildIntent() { switch (mType) { case TYPE_VIEW: if (checkTime(mBeginTime, "Time isn't valid.")) { final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); builder.appendPath("time"); ContentUris.appendId(builder, mBeginTime); /** * Build the intent. */ return new Intent(Intent.ACTION_VIEW).setData(builder.build()); } break; case TYPE_INSERT_EVENT: if (!checkTime(mBeginTime, "Begin time(" + mBeginTime + ") isn't valid.")) { return null; } if (!checkTime(mEndTime, "End time(" + mEndTime + ") isn't valid.")) { return null; } if (mEndTime <= mBeginTime) { this.logMessage( "End time(" + mEndTime + ") is wrong specified before/at begin time(" + mBeginTime + ")."); return null; } /** * Build the intent. */ final Intent intent = new Intent(Intent.ACTION_INSERT).setData(CalendarContract.Events.CONTENT_URI) .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, mBeginTime) .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, mEndTime) .putExtra(CalendarContract.Events.TITLE, mTitle) .putExtra(CalendarContract.Events.DESCRIPTION, mDescription) .putExtra(CalendarContract.Events.EVENT_LOCATION, mLocation) .putExtra(CalendarContract.Events.AVAILABILITY, mAvailability); // todo: add extra emails. // intent.putExtra(Intent.EXTRA_EMAIL, "rowan@example.com,trevor@example.com"); return intent; case TYPE_EDIT_EVENT: if (checkEventId()) { /** * Build the intent. */ final Intent eventIntent = new Intent(Intent.ACTION_EDIT); eventIntent.setData(ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, mEventId)); if (!TextUtils.isEmpty(mTitle)) { eventIntent.putExtra(CalendarContract.Events.TITLE, mTitle); } return eventIntent; } break; case TYPE_VIEW_EVENT: if (checkEventId()) { /** * Build the intent. */ return new Intent(Intent.ACTION_VIEW) .setData(ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, mEventId)); } break; } return null; }
From source file:com.granita.contacticloudsync.syncadapter.AccountSettings.java
@SuppressWarnings("Recycle") private void update_0_1() throws URISyntaxException { String v0_principalURL = accountManager.getUserData(account, "principal_url"), v0_addressBookPath = accountManager.getUserData(account, "addressbook_path"); Constants.log.debug("Old principal URL = " + v0_principalURL); Constants.log.debug("Old address book path = " + v0_addressBookPath); URI principalURI = new URI(v0_principalURL); // update address book if (v0_addressBookPath != null) { String addressBookURL = principalURI.resolve(v0_addressBookPath).toASCIIString(); Constants.log.debug("New address book URL = " + addressBookURL); accountManager.setUserData(account, "addressbook_url", addressBookURL); }/*from w ww .jav a 2s .c o m*/ // update calendars ContentResolver resolver = context.getContentResolver(); Uri calendars = Calendars.CONTENT_URI.buildUpon().appendQueryParameter(Calendars.ACCOUNT_NAME, account.name) .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type) .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true").build(); @Cleanup Cursor cursor = resolver.query(calendars, new String[] { Calendars._ID, Calendars.NAME }, null, null, null); while (cursor != null && cursor.moveToNext()) { int id = cursor.getInt(0); String v0_path = cursor.getString(1), v1_url = principalURI.resolve(v0_path).toASCIIString(); Constants.log.debug("Updating calendar #" + id + " name: " + v0_path + " -> " + v1_url); Uri calendar = ContentUris.appendId( Calendars.CONTENT_URI.buildUpon().appendQueryParameter(Calendars.ACCOUNT_NAME, account.name) .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type) .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true"), id).build(); ContentValues newValues = new ContentValues(1); newValues.put(Calendars.NAME, v1_url); if (resolver.update(calendar, newValues, null, null) != 1) Constants.log.debug("Number of modified calendars != 1"); } accountManager.setUserData(account, "principal_url", null); accountManager.setUserData(account, "addressbook_path", null); accountManager.setUserData(account, KEY_SETTINGS_VERSION, "1"); }
From source file:org.totschnig.myexpenses.fragment.PlanList.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle bundle) { switch (id) { case TEMPLATES_CURSOR: return new CursorLoader(getActivity(), TransactionProvider.TEMPLATES_URI, null, KEY_PLANID + " is not null", null, null); case PLANS_CURSOR: return new CursorLoader(getActivity(), Events.CONTENT_URI, new String[] { Events._ID, Events.DTSTART, Events.RRULE, }, Events._ID + " IN (" + TextUtils.join(",", (ArrayList<Long>) bundle.getSerializable("plans")) + ")", null, null);// ww w . jav a 2s.c o m default: if (id % 2 == 0) { // The ID of the recurring event whose instances you are searching // for in the Instances table String selection = Instances.EVENT_ID + " = " + bundle.getLong("plan_id"); // Construct the query with the desired date range. Uri.Builder builder = Instances.CONTENT_URI.buildUpon(); long now = System.currentTimeMillis(); ContentUris.appendId(builder, now); ContentUris.appendId(builder, now + 7776000000L); //90 days return new CursorLoader(getActivity(), builder.build(), new String[] { Instances._ID, Instances.BEGIN }, selection, null, null); } else { return new CursorLoader(getActivity(), TransactionProvider.PLAN_INSTANCE_STATUS_URI, new String[] { KEY_TEMPLATEID, KEY_INSTANCEID, KEY_TRANSACTIONID }, KEY_TEMPLATEID + " = ?", new String[] { String.valueOf(bundle.getLong("template_id")) }, null); } } }
From source file:com.android.calendar.Event.java
/** * Performs a query to return all visible instances in the given range * that match the given selection. 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.// ww w . j av a 2s. c o m * * @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 selection Filter on the query as an SQL WHERE statement * @param selectionArgs Args to replace any '?'s in the selection * @param orderBy How to order the rows as an SQL ORDER BY statement * @return A Cursor of instances matching the selection */ private static final Cursor instancesQuery(ContentResolver cr, String[] projection, int startDay, int endDay, String selection, String[] selectionArgs, String orderBy) { String WHERE_CALENDARS_SELECTED = Calendars.VISIBLE + "=?"; String[] WHERE_CALENDARS_ARGS = { "1" }; String DEFAULT_SORT_ORDER = "begin ASC"; Uri.Builder builder = Instances.CONTENT_BY_DAY_URI.buildUpon(); ContentUris.appendId(builder, startDay); ContentUris.appendId(builder, endDay); if (TextUtils.isEmpty(selection)) { selection = WHERE_CALENDARS_SELECTED; selectionArgs = WHERE_CALENDARS_ARGS; } else { selection = "(" + selection + ") AND " + WHERE_CALENDARS_SELECTED; if (selectionArgs != null && selectionArgs.length > 0) { selectionArgs = Arrays.copyOf(selectionArgs, selectionArgs.length + 1); selectionArgs[selectionArgs.length - 1] = WHERE_CALENDARS_ARGS[0]; } else { selectionArgs = WHERE_CALENDARS_ARGS; } } return cr.query(builder.build(), projection, selection, selectionArgs, orderBy == null ? DEFAULT_SORT_ORDER : orderBy); }
From source file:com.albedinsky.android.support.intent.CalendarIntent.java
/** *//*from ww w.j a v a 2 s . c o m*/ @NonNull @Override @SuppressWarnings("ConstantConditions") protected Intent onBuild() { switch (mType) { case TYPE_VIEW: final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); builder.appendPath("time"); ContentUris.appendId(builder, mBeginTime); return new Intent(Intent.ACTION_VIEW).setData(builder.build()); case TYPE_INSERT_EVENT: return new Intent(Intent.ACTION_INSERT).setData(CalendarContract.Events.CONTENT_URI) .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, mBeginTime) .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, mEndTime) .putExtra(CalendarContract.Events.TITLE, mTitle) .putExtra(CalendarContract.Events.DESCRIPTION, mDescription) .putExtra(CalendarContract.Events.EVENT_LOCATION, mLocation) .putExtra(CalendarContract.Events.AVAILABILITY, mAvailability); case TYPE_EDIT_EVENT: final Intent intent = new Intent(Intent.ACTION_EDIT); intent.setData(ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, mEventId)); if (!TextUtils.isEmpty(mTitle)) { intent.putExtra(CalendarContract.Events.TITLE, mTitle); } return intent; default: return new Intent(Intent.ACTION_VIEW) .setData(ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, mEventId)); } }