public int deleteCalendar(JSONObject calendar,
String accountType, String accountName) {
try {
ContentResolver cr = context.getContentResolver();
return cr.delete(
Tools.asSyncAdapter(Calendars.CONTENT_URI, accountType, accountName),
Calendars._ID + " = ? ",
new String[] {String.valueOf(calendar.getLong(Calendars._ID))}
);
} catch (JSONException e) {
Log.w(LOG_TAG, e);
return -1;
}
}
java类android.provider.CalendarContract.Calendars的实例源码
CalendarAccessor.java 文件源码
项目:cordova-plugin-calendarsync
阅读 21
收藏 0
点赞 0
评论 0
EventInfo.java 文件源码
项目:CalendarProvider-Lib
阅读 23
收藏 0
点赞 0
评论 0
/**
* Create a new event starting from the information set into the {@code eventInfo}.
* If the event is correctly added to the Android Calendar Provider then the {@code eventInfo}
* will be updated with the assigned identifier and displayed name of the event.
*
* @param context application's context
* @param eventInfo EventInfo representation of the event to create
* @return true if the event is successfully insert into the Android Calendar Provider
*/
public static boolean insert(Context context, EventInfo eventInfo) {
if (eventInfo.isRecurrentEvent()) { //TODO: manage insertion of recurrent event
return false;
}
final ContentValues contentValues = eventInfo.toInsertContentValues(context);
if (hasMandatoryInsertField(contentValues)) {
final Uri uri = context.getContentResolver().insert(UriBuilder.EVENTS_URI, contentValues);
eventInfo.id = Long.valueOf(uri.getLastPathSegment());
eventInfo.calendarDisplayName = getInformation(context, eventInfo.id,
new String[]{Calendars.CALENDAR_DISPLAY_NAME}).getAsString(Calendars.CALENDAR_DISPLAY_NAME);
return true;
}
return false;
}
CalendarInfo.java 文件源码
项目:CalendarProvider-Lib
阅读 19
收藏 0
点赞 0
评论 0
/**
* Extract a CalendarInfo object from its representation as ContentValues (value extracted querying the Android Content Provider)
*
* @param contentValues information extracted from the content provider
* @return the CalendarInfo representation of the {@code contentValues}
* @throws IllegalArgumentException if the {@code contentValues} cannot be parsed to a CalendarInfo object
*/
public static CalendarInfo fromContentValues(ContentValues contentValues) {
CalendarInfo calendarInfo = new CalendarInfo();
try {
calendarInfo.id = contentValues.getAsLong(Calendars._ID);
calendarInfo.accountName = contentValues.getAsString(Calendars.ACCOUNT_NAME);
calendarInfo.name = contentValues.getAsString(Calendars.NAME);
if (calendarInfo.name == null) {
calendarInfo.name = calendarInfo.accountName;
}
calendarInfo.displayName = contentValues.getAsString(Calendars.CALENDAR_DISPLAY_NAME);
if (calendarInfo.displayName == null) {
calendarInfo.displayName = calendarInfo.name;
}
calendarInfo.ownerAccount = contentValues.getAsString(Calendars.OWNER_ACCOUNT);
calendarInfo.color = contentValues.getAsInteger(Calendars.CALENDAR_COLOR);
calendarInfo.visible = contentValues.getAsInteger(Calendars.VISIBLE) == 1;
calendarInfo.accountType = contentValues.getAsString(Calendars.ACCOUNT_TYPE);
return calendarInfo;
} catch (NullPointerException e) {
StringBuilder errorString = new StringBuilder();
StringBuilder missingColumns = new StringBuilder();
errorString.append("There is NOT all the required parameters in the contentValues\nThe required keys are: ");
for (String col : COLUMNS) {
errorString.append(col).append(", ");
if (!contentValues.containsKey(col)) {
missingColumns.append(col).append(", ");
}
}
errorString.setLength(errorString.length() - 2);
if (missingColumns.length() > 0) {
missingColumns.setLength(missingColumns.length() - 2);
}
errorString.append("\n the following columns are missing: ").append(missingColumns);
throw new IllegalArgumentException(errorString.toString());
}
}
CalendarInfo.java 文件源码
项目:CalendarProvider-Lib
阅读 23
收藏 0
点赞 0
评论 0
/**
* Commodity method to generate the correct filter string and arguments list according to the owners and visibility defined
*
* @param owners filter on the owners, null to not apply the filter
* @param visible filter on the visibility, null to not apply the filter
* @return a {@code Pair} containing as first field the selection string and as second field the selection arguments
*/
private static Pair<String, String[]> filterOnOwnersAndVisible(Collection<String> owners, Boolean visible) {
String selection = null;
String selectionArgs[] = null;
if (owners != null && owners.size() == 0) {
owners = null;
}
if (owners != null || visible != null) {
// selection will look like
// visible=? AND (accountName=? OR accountName=? OR accountName=? OR accountName=?)
StringBuilder builder = new StringBuilder();
List<String> arguments = new ArrayList<>();
if (visible != null) {
builder.append(Calendars.VISIBLE).append("=?");
arguments.add(visible ? "1" : "0");
}
if (owners != null) {
if (visible != null) {
builder.append(" AND (");
}
for (String owner : owners) {
builder.append(Calendars.ACCOUNT_NAME).append("=? OR ");
arguments.add(owner);
}
builder.setLength(builder.length() - 4); //4 is the length of " OR "
if (visible != null) {
builder.append(")");
}
}
selection = builder.toString();
selectionArgs = arguments.toArray(new String[arguments.size()]);
}
return Pair.create(selection, selectionArgs);
}
CalendarInfo.java 文件源码
项目:CalendarProvider-Lib
阅读 23
收藏 0
点赞 0
评论 0
/**
* Commodity method for the building of the ContentValues object starting from the CalendarInfo representation.
* The method will return a ContentValues that will be utilised for a new local calendar
*
* @return ContentValues representation of the CalendarInfo object
*/
private ContentValues toCreateLocalContentValues() {
final ContentValues contentValues = toContentValues();
if (contentValues.containsKey(Calendars._ID)) {
Log.w(getClass().getSimpleName(), "The CalendarInfo to insert shouldn't have id defined, they are automatically removed");
contentValues.remove(Calendars._ID);
id = null;
}
contentValues.put(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
contentValues.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
return contentValues;
}
CalendarInfo.java 文件源码
项目:CalendarProvider-Lib
阅读 22
收藏 0
点赞 0
评论 0
/**
* Commodity method for the building of the ContentValues object starting from the CalendarInfo representation.
* The method will return a ContentValues that will be utilised for the update of the calendar
*
* @return ContentValues representation of the CalendarInfo object
*/
public ContentValues toUpdateContentValues() {
final ContentValues contentValues = toContentValues();
if (contentValues.containsKey(Calendars.ACCOUNT_NAME)) {
contentValues.remove(Calendars.ACCOUNT_NAME);
contentValues.remove(Calendars.ACCOUNT_TYPE);
contentValues.remove(Calendars.OWNER_ACCOUNT);
}
return contentValues;
}
CalendarInfo.java 文件源码
项目:CalendarProvider-Lib
阅读 24
收藏 0
点赞 0
评论 0
/**
* Commodity method to check if the {@code contentValues} has all the required fields to complete successfully the creation
*
* @param contentValues ContentValues to insert
* @return true if the {@code contentValues} has all the needed fields
*/
private static boolean hasMandatoryCreateField(ContentValues contentValues) {
return contentValues.containsKey(Calendars.ACCOUNT_NAME) &&
contentValues.containsKey(Calendars.ACCOUNT_TYPE) &&
contentValues.containsKey(Calendars.NAME) &&
contentValues.containsKey(Calendars.CALENDAR_DISPLAY_NAME) &&
contentValues.containsKey(Calendars.CALENDAR_ACCESS_LEVEL);
}
CalendarInfo.java 文件源码
项目:CalendarProvider-Lib
阅读 21
收藏 0
点赞 0
评论 0
/**
* Create a local calendar starting from the information set into the {@code calendarInfo}.
* If the calendar is correctly added to the Android Calendar Provider then the {@code calendarInfo}
* will be updated with the assigned identifier.
*
* @param context application's context
* @param calendarInfo CalendarInfo representation of the calendar to create
* @return true if the calendar is successfully insert into the Android Calendar Provider
*/
public static boolean createLocal(Context context, CalendarInfo calendarInfo) {
final ContentValues contentValues = calendarInfo.toCreateLocalContentValues();
if (hasMandatoryCreateField(contentValues)) {
final Uri.Builder uriBuilder = UriBuilder.getUri().buildUpon();
uriBuilder.appendQueryParameter(Calendars.ACCOUNT_NAME, calendarInfo.accountName);
uriBuilder.appendQueryParameter(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
uriBuilder.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true");
final Uri uri = context.getContentResolver().insert(uriBuilder.build(), contentValues);
calendarInfo.id = Long.valueOf(uri.getLastPathSegment());
return true;
}
return false;
}
LocalCalendar.java 文件源码
项目:CucumberSync
阅读 27
收藏 0
点赞 0
评论 0
public static LocalCalendar[] findAll(Account account, ContentProviderClient providerClient, AccountSettings accountSettings) throws RemoteException {
@Cleanup Cursor cursor = providerClient.query(calendarsURI(account),
new String[] { Calendars._ID, Calendars.NAME, COLLECTION_COLUMN_CTAG, Calendars.CALENDAR_TIME_ZONE },
Calendars.DELETED + "=0 AND " + Calendars.SYNC_EVENTS + "=1", null, null);
LinkedList<LocalCalendar> calendars = new LinkedList<LocalCalendar>();
while (cursor != null && cursor.moveToNext())
calendars.add(new LocalCalendar(account, providerClient, accountSettings, cursor.getInt(0), cursor.getString(3)));
return calendars.toArray(new LocalCalendar[0]);
}