本文整理匯總了Java中android.provider.CalendarContract類的典型用法代碼示例。如果您正苦於以下問題:Java CalendarContract類的具體用法?Java CalendarContract怎麽用?Java CalendarContract使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CalendarContract類屬於android.provider包,在下文中一共展示了CalendarContract類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addEventToCalendar
import android.provider.CalendarContract; //導入依賴的package包/類
private void addEventToCalendar(ColegiElectoral colegiElectoral) {
Calendar calendar = Calendar.getInstance(Locale.getDefault());
calendar.set(2017, Calendar.OCTOBER, 1, 9, 0);
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(CalendarContract.Events.TITLE, StringsManager.getString("notification_title"));
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calendar.getTimeInMillis());
intent.putExtra(CalendarContract.Events.ALL_DAY, true);
String location = colegiElectoral.getLocal() + ": " + colegiElectoral.getAdresa() + ", " + colegiElectoral.getMunicipi();
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, location);
startActivity(intent);
}
示例2: addEventOnCalendar
import android.provider.CalendarContract; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void addEventOnCalendar(PersianDate persianDate) {
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setData(CalendarContract.Events.CONTENT_URI);
CivilDate civil = DateConverter.persianToCivil(persianDate);
intent.putExtra(CalendarContract.Events.DESCRIPTION,
mPersianCalendarHandler.dayTitleSummary(persianDate));
Calendar time = Calendar.getInstance();
time.set(civil.getYear(), civil.getMonth() - 1, civil.getDayOfMonth());
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
time.getTimeInMillis());
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
time.getTimeInMillis());
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
startActivity(intent);
}
示例3: findLocalCalendar
import android.provider.CalendarContract; //導入依賴的package包/類
private long findLocalCalendar() throws android.os.RemoteException,
android.database.sqlite.SQLiteException {
Cursor cur = mContext.getContentProviderClient().query(
CalendarContract.Calendars.CONTENT_URI,
new String[]{ CalendarContract.Calendars._ID },
String.format("((%s = ?) AND (%s = ?) AND (%s = ?) AND (%s = ?))",
CalendarContract.Calendars.ACCOUNT_NAME,
CalendarContract.Calendars.ACCOUNT_TYPE,
CalendarContract.Calendars.OWNER_ACCOUNT,
CalendarContract.Calendars.NAME),
new String[]{
mContext.getAccount().name,
mContext.getContext().getString(R.string.account_type),
mContext.getAccount().name,
mType.id()},
null);
long result = -1;
if (cur != null) {
if (cur.moveToNext()) {
result = cur.getLong(0);
}
cur.close();
}
return result;
}
示例4: fetchLocalEvents
import android.provider.CalendarContract; //導入依賴的package包/類
private HashMap<String /* FBID */, Long /* local ID */ > fetchLocalEvents(
String selectorQuery, String[] selectorValues)
throws android.os.RemoteException,
android.database.sqlite.SQLiteException
{
HashMap<String, Long> localIds = new HashMap<>();
// HACK: Only select future events: Facebook will remove the events from the listing once
// they pass, but it's desirable that we keep them in the calendar. The only way to achieve
// so is to ignore them
Cursor cur = mContext.getContentProviderClient().query(
CalendarContract.Events.CONTENT_URI,
new String[]{
CalendarContract.Events.UID_2445,
CalendarContract.Events._ID },
selectorQuery, selectorValues,
null);
if (cur != null) {
while (cur.moveToNext()) {
localIds.put(cur.getString(0), cur.getLong(1));
}
cur.close();
}
return localIds;
}
示例5: getLocalReminders
import android.provider.CalendarContract; //導入依賴的package包/類
private HashMap<Integer /* minutes */, Long /* reminder ID */> getLocalReminders(SyncContext context, long localEventId)
throws android.os.RemoteException,
android.database.sqlite.SQLiteException
{
Cursor cur = context.getContentProviderClient().query(
CalendarContract.Reminders.CONTENT_URI,
new String[]{
CalendarContract.Reminders._ID,
CalendarContract.Reminders.MINUTES },
String.format("(%s = ?)", CalendarContract.Reminders.EVENT_ID),
new String[]{ String.valueOf(localEventId) },
null);
@SuppressLint("UseSparseArrays")
HashMap<Integer /* minutes */, Long /* reminder ID */> localReminders = new HashMap<>();
if (cur != null) {
while (cur.moveToNext()) {
localReminders.put(cur.getInt(1), cur.getLong(0));
}
cur.close();
}
return localReminders;
}
示例6: createReminders
import android.provider.CalendarContract; //導入依賴的package包/類
private void createReminders(SyncContext context, long localEventId, Set<Integer> reminders)
throws android.os.RemoteException,
android.database.sqlite.SQLiteException
{
ArrayList<ContentValues> reminderValues = new ArrayList<>();
for (int reminder : reminders) {
ContentValues values = new ContentValues();
values.put(CalendarContract.Reminders.EVENT_ID, localEventId);
values.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);
values.put(CalendarContract.Reminders.MINUTES, reminder);
reminderValues.add(values);
}
Uri uri = CalendarContract.Reminders.CONTENT_URI.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, context.getAccount().name)
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, context.getContext().getString(R.string.account_type))
.build();
context.getContentProviderClient().bulkInsert(
uri,
reminderValues.toArray(new ContentValues[0]));
}
示例7: openCalendar
import android.provider.CalendarContract; //導入依賴的package包/類
@TargetApi(14)
private void openCalendar(JSONArray args) {
try {
final Long millis = args.getJSONObject(0).optLong("date");
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon().appendPath("time");
ContentUris.appendId(builder, millis);
final Intent intent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
Calendar.this.cordova.startActivityForResult(Calendar.this, intent, RESULT_CODE_OPENCAL);
callback.success();
}
});
} catch (JSONException e) {
System.err.println("Exception: " + e.getMessage());
callback.error(e.getMessage());
}
}
示例8: deleteCalendar
import android.provider.CalendarContract; //導入依賴的package包/類
@SuppressWarnings("MissingPermission") // already requested in calling method
public void deleteCalendar(String calendarName) {
try {
Uri evuri = CalendarContract.Calendars.CONTENT_URI;
final ContentResolver contentResolver = cordova.getActivity().getContentResolver();
Cursor result = contentResolver.query(evuri, new String[]{CalendarContract.Calendars._ID, CalendarContract.Calendars.NAME, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME}, null, null, null);
if (result != null) {
while (result.moveToNext()) {
if (result.getString(1).equals(calendarName) || result.getString(2).equals(calendarName)) {
long calid = result.getLong(0);
Uri deleteUri = ContentUris.withAppendedId(evuri, calid);
contentResolver.delete(deleteUri, null, null);
}
}
result.close();
}
// also delete previously crashing calendars, see https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin/issues/241
deleteCrashingCalendars(contentResolver);
} catch (Throwable t) {
System.err.println(t.getMessage());
t.printStackTrace();
}
}
示例9: buildEvent
import android.provider.CalendarContract; //導入依賴的package包/類
@Override
protected void buildEvent(Event recurrence, ContentProviderOperation.Builder builder) {
super.buildEvent(recurrence, builder);
boolean buildException = recurrence != null;
Event eventToBuild = buildException ? recurrence : event;
builder.withValue(COLUMN_UID, event.uid)
.withValue(COLUMN_SEQUENCE, eventToBuild.sequence)
.withValue(CalendarContract.Events.DIRTY, 0)
.withValue(CalendarContract.Events.DELETED, 0);
if (buildException) {
builder.withValue(CalendarContract.Events.ORIGINAL_SYNC_ID, fileName);
} else {
builder.withValue(CalendarContract.Events._SYNC_ID, fileName)
.withValue(COLUMN_ETAG, eTag);
}
}
示例10: getCalendars
import android.provider.CalendarContract; //導入依賴的package包/類
/**
* fetching all calendars from local android calendar db
*
* @return a set of all calendars
*/
public Set<String> getCalendars() {
// Fetch a list of all calendars sync'd with the device and their display names
Cursor cursor = contentResolver.query(CALENDAR_URI, FIELDS, null, null, null);
try {
if (cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String name = cursor.getString(0);
String displayName = cursor.getString(1);
// This is actually a better pattern:
String color = cursor.getString(cursor.getColumnIndex(CalendarContract.Calendars.CALENDAR_COLOR));
Boolean selected = !cursor.getString(3).equals("0");
calendars.add(displayName);
}
}
} catch (AssertionError ex) { /*TODO: log exception and bail*/ }
return calendars;
}
示例11: getCalendarIdForName
import android.provider.CalendarContract; //導入依賴的package包/類
public String getCalendarIdForName(String calendarName) {
String selection = "(" + CalendarContract.Calendars.NAME + " = ?)";
String[] selectionArgs = new String[] {calendarName};
Cursor cursor = contentResolver.query(CALENDAR_URI, FIELDS, selection, selectionArgs, null);
try {
if (cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String id = cursor.getString(0);
return id;
}
}
} catch (AssertionError ex) { /*TODO: log exception and bail*/ }
return "";
}
示例12: ensureCalendarPermissions
import android.provider.CalendarContract; //導入依賴的package包/類
private boolean ensureCalendarPermissions()
{
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this,
Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_CALENDAR, Manifest.permission.WRITE_CALENDAR }, 0);
return false;
}
if (mCalendarsClient == null)
{
mCalendarsClient = getContentResolver().acquireContentProviderClient(CalendarContract.AUTHORITY);
mCalendarQueue = new BasicOperationsQueue(mCalendarsClient);
}
return true;
}
示例13: create
import android.provider.CalendarContract; //導入依賴的package包/類
public static Uri create(@NonNull Account account, @NonNull ContentProviderClient provider, @NonNull
CollectionInfo info) throws
CalendarStorageException {
ContentValues values = valuesFromCollectionInfo(info, true);
// ACCOUNT_NAME and ACCOUNT_TYPE are required (see docs)! If it's missing, other apps will crash.
values.put(CalendarContract.Calendars.ACCOUNT_NAME, account.name);
values.put(CalendarContract.Calendars.ACCOUNT_TYPE, account.type);
values.put(CalendarContract.Calendars.OWNER_ACCOUNT, account.name);
// flag as visible & synchronizable at creation, might be changed by user at any time
values.put(CalendarContract.Calendars.VISIBLE, 0);
values.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
return create(account, provider, values);
}
示例14: getDirty
import android.provider.CalendarContract; //導入依賴的package包/類
@Override
public LocalResource[] getDirty() throws CalendarStorageException, FileNotFoundException {
List<LocalResource> dirty = new LinkedList<>();
// get dirty events which are required to have an increased SEQUENCE value
for (LocalEvent event : (LocalEvent[]) queryEvents(
CalendarContract.Events.DIRTY + "!=0 AND " + CalendarContract.Events.ORIGINAL_ID + " IS NULL",
null)) {
if (event.getEvent().sequence ==
null) // sequence has not been assigned yet (i.e. this event was just locally created)
{
event.getEvent().sequence = 0;
} else if (event.weAreOrganizer) {
event.getEvent().sequence++;
}
dirty.add(event);
}
return dirty.toArray(new LocalResource[dirty.size()]);
}
示例15: testSelection
import android.provider.CalendarContract; //導入依賴的package包/類
@Test
public void testSelection() throws Exception
{
TransactionContext mockTc = failingMock(TransactionContext.class);
SoftRowReference<CalendarContract.Calendars> dummyReference = dummy(SoftRowReference.class);
RowSnapshot<CalendarContract.Calendars> mockCalendarRow = failingMock(RowSnapshot.class);
doReturn(dummyReference).when(mockCalendarRow).reference();
doReturn(new BackReference<>(dummy(Uri.class), 12)).when(mockTc).resolved(dummyReference);
assertThat(new CalendarScoped(mockCalendarRow, new EqArg("x", "y")),
predicateWith(
selection(mockTc, "( x = ? ) and ( calendar_id = ? )"),
argumentValues(mockTc, "y", "-1"),
backReferences(mockTc, AbsentMatcher.<Integer>isAbsent(), isPresent(12))
));
}