Java Code Examples for android.provider.CalendarContract.Calendars#_ID

The following examples show how to use android.provider.CalendarContract.Calendars#_ID . 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: 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 3
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;
}