android.provider.CalendarContract.Calendars Java Examples

The following examples show how to use android.provider.CalendarContract.Calendars. 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: BrewTimerStepFragment.java    From biermacht with Apache License 2.0 8 votes vote down vote up
private long getCalendarId() {
  String[] projection = new String[]{Calendars._ID};
  //String selection = Calendars.ACCOUNT_NAME + "=Biermacht AND" + Calendars.ACCOUNT_TYPE + "=" + CalendarContract.ACCOUNT_TYPE_LOCAL;

  String selection = "(" + Calendars.ACCOUNT_NAME + " = ?) AND (" + Calendars.ACCOUNT_TYPE + " = ?)";
  String[] selectionArgs = new String[]{"Biermacht", CalendarContract.ACCOUNT_TYPE_LOCAL};

  // use the same values as above:
  //String[] selArgs = new String[]{"Biermacht", CalendarContract.ACCOUNT_TYPE_LOCAL};
  Cursor cursor = c.getContentResolver().query(Calendars.CONTENT_URI,
                                               projection,
                                               selection,
                                               selectionArgs,
                                               null);
  if (cursor.moveToFirst()) {
    return cursor.getLong(0);
  }
  return - 1;
}
 
Example #2
Source File: MyCalendarActivity.java    From codeexamples-android with Eclipse Public License 1.0 7 votes vote down vote up
public void queryCalendar(View view) {
	// Run query
	Cursor cur = null;
	ContentResolver cr = getContentResolver();
	Uri uri = Calendars.CONTENT_URI;
	String selection = "((" + Calendars.ACCOUNT_NAME + " = ?) AND ("
			+ Calendars.ACCOUNT_TYPE + " = ?))";

	// Replace this with your own user and account type
	String[] selectionArgs = new String[] { "[email protected]",
			"com.google" };
	// Submit the query and get a Cursor object back.
	cur = cr.query(uri, EVENT_PROJECTION, selection, selectionArgs, null);
	Toast.makeText(this, String.valueOf(cur.getCount()), Toast.LENGTH_LONG)
			.show();
	// Use the cursor to step through the returned records
	while (cur.moveToNext()) {
		long calID = 0;
		String displayName = null;
		String accountName = null;

		// Get the field values
		calID = cur.getLong(PROJECTION_ID_INDEX);
		displayName = cur.getString(PROJECTION_DISPLAY_NAME_INDEX);
		accountName = cur.getString(PROJECTION_ACCOUNT_NAME_INDEX);

		// Do something with the values...
		Toast.makeText(this, "Calendar " + displayName, Toast.LENGTH_SHORT)
				.show();
	}
}
 
Example #3
Source File: CalendarTracker.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private ArraySet<Long> getPrimaryCalendars() {
    final long start = System.currentTimeMillis();
    final ArraySet<Long> rt = new ArraySet<>();
    final String primary = "\"primary\"";
    final String[] projection = { Calendars._ID,
            "(" + Calendars.ACCOUNT_NAME + "=" + Calendars.OWNER_ACCOUNT + ") AS " + primary };
    final String selection = primary + " = 1";
    Cursor cursor = null;
    try {
        cursor = mUserContext.getContentResolver().query(Calendars.CONTENT_URI, projection,
                selection, null, null);
        while (cursor != null && cursor.moveToNext()) {
            rt.add(cursor.getLong(0));
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    if (DEBUG) Log.d(TAG, "getPrimaryCalendars took " + (System.currentTimeMillis() - start));
    return rt;
}
 
Example #4
Source File: CalendarTracker.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void setRegistered(boolean registered) {
    if (mRegistered == registered) return;
    final ContentResolver cr = mSystemContext.getContentResolver();
    final int userId = mUserContext.getUserId();
    if (mRegistered) {
        if (DEBUG) Log.d(TAG, "unregister content observer u=" + userId);
        cr.unregisterContentObserver(mObserver);
    }
    mRegistered = registered;
    if (DEBUG) Log.d(TAG, "mRegistered = " + registered + " u=" + userId);
    if (mRegistered) {
        if (DEBUG) Log.d(TAG, "register content observer u=" + userId);
        cr.registerContentObserver(Instances.CONTENT_URI, true, mObserver, userId);
        cr.registerContentObserver(Events.CONTENT_URI, true, mObserver, userId);
        cr.registerContentObserver(Calendars.CONTENT_URI, true, mObserver, userId);
    }
}
 
Example #5
Source File: BrewTimerStepFragment.java    From biermacht with Apache License 2.0 6 votes vote down vote up
private void createCalendar() {
  ContentValues values = new ContentValues();
  values.put(Calendars.ACCOUNT_NAME, "Biermacht");
  values.put(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
  values.put(Calendars.NAME, "Biermacht Calendar");
  values.put(Calendars.CALENDAR_DISPLAY_NAME, "Biermacht Calendar");
  values.put(Calendars.CALENDAR_COLOR, 0xE6A627);
  values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
  values.put(Calendars.OWNER_ACCOUNT, "[email protected]");
  values.put(Calendars.CALENDAR_TIME_ZONE, "Europe/Berlin");

  Uri.Builder builder = CalendarContract.Calendars.CONTENT_URI.buildUpon();
  builder.appendQueryParameter(Calendars.ACCOUNT_NAME, "com.biermacht.brews");
  builder.appendQueryParameter(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
  builder.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true");
  Uri uri = c.getContentResolver().insert(builder.build(), values);
}
 
Example #6
Source File: CalendarsMultiSelectDialogPreferenceX.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@SuppressLint("MissingPermission")
static String getSummary(String value, Context context) {
    String summary = context.getString(R.string.calendars_multiselect_summary_text_not_selected);
    if (Permissions.checkCalendar(context)) {
        if (!value.isEmpty()) {
            String[] splits = value.split("\\|");
            if (splits.length == 1) {
                boolean found = false;
                Cursor cur;
                ContentResolver cr = context.getContentResolver();
                Uri uri = Calendars.CONTENT_URI;
                String selection = Calendars._ID + "=" + splits[0];
                // permission is already checked in Permissions.checkCalendar()
                //noinspection MissingPermission
                cur = cr.query(uri, CalendarsMultiSelectDialogPreferenceFragmentX.CALENDAR_PROJECTION, selection, null, null);
                if (cur != null) {
                    //while (cur.moveToNext()) {
                    if (cur.moveToFirst()) {
                        found = true;
                        summary = cur.getString(CalendarsMultiSelectDialogPreferenceFragmentX.PROJECTION_DISPLAY_NAME_INDEX);
                        //break;
                    }
                    cur.close();
                }
                if (!found)
                    summary = context.getString(R.string.calendars_multiselect_summary_text_selected) + ": " + splits.length;
            } else
                summary = context.getString(R.string.calendars_multiselect_summary_text_selected) + ": " + splits.length;
        }
    }
    return summary;
}
 
Example #7
Source File: Utils.java    From Android-RecurrencePicker with Apache License 2.0 3 votes vote down vote up
/**
 * Checks the server for an updated list of Calendars (in the background).
 * <p/>
 * If a Calendar is added on the web (and it is selected and not
 * hidden) then it will be added to the list of calendars on the phone
 * (when this finishes).  When a new calendar from the
 * web is added to the phone, then the events for that calendar are also
 * downloaded from the web.
 * <p/>
 * This sync is done automatically in the background when the
 * SelectCalendars activity and fragment are started.
 *
 * @param account - The account to sync. May be null to sync all accounts.
 */
public static void startCalendarMetafeedSync(Account account) {
    Bundle extras = new Bundle();
    extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    extras.putBoolean("metafeedonly", true);
    ContentResolver.requestSync(account, Calendars.CONTENT_URI.getAuthority(), extras);
}