Example usage for android.provider CalendarContract AUTHORITY

List of usage examples for android.provider CalendarContract AUTHORITY

Introduction

In this page you can find the example usage for android.provider CalendarContract AUTHORITY.

Prototype

String AUTHORITY

To view the source code for android.provider CalendarContract AUTHORITY.

Click Source Link

Document

This authority is used for writing to or querying from the calendar provider.

Usage

From source file:com.granita.contacticloudsync.resource.LocalCalendar.java

@TargetApi(15)
public static Uri create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws CalendarStorageException {
    @Cleanup("release")
    ContentProviderClient provider = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);
    if (provider == null)
        throw new CalendarStorageException(
                "Couldn't acquire ContentProviderClient for " + CalendarContract.AUTHORITY);

    ContentValues values = new ContentValues();
    values.put(Calendars.NAME, info.getUrl());
    values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle());
    values.put(Calendars.CALENDAR_COLOR, info.color != null ? info.color : defaultColor);

    if (info.isReadOnly())
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
    else {//w w  w  . j a v a 2  s .c om
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
        values.put(Calendars.CAN_MODIFY_TIME_ZONE, 1);
        values.put(Calendars.CAN_ORGANIZER_RESPOND, 1);
    }

    values.put(Calendars.OWNER_ACCOUNT, account.name);
    values.put(Calendars.SYNC_EVENTS, 1);
    values.put(Calendars.VISIBLE, 1);
    if (!TextUtils.isEmpty(info.timezone)) {
        VTimeZone timeZone = DateUtils.parseVTimeZone(info.timezone);
        if (timeZone != null && timeZone.getTimeZoneId() != null)
            values.put(Calendars.CALENDAR_TIME_ZONE,
                    DateUtils.findAndroidTimezoneID(timeZone.getTimeZoneId().getValue()));
    }
    values.put(Calendars.ALLOWED_REMINDERS, Reminders.METHOD_ALERT);
    if (Build.VERSION.SDK_INT >= 15) {
        values.put(Calendars.ALLOWED_AVAILABILITY,
                StringUtils.join(new int[] { Reminders.AVAILABILITY_TENTATIVE, Reminders.AVAILABILITY_FREE,
                        Reminders.AVAILABILITY_BUSY }, ","));
        values.put(Calendars.ALLOWED_ATTENDEE_TYPES,
                StringUtils.join(new int[] { CalendarContract.Attendees.TYPE_OPTIONAL,
                        CalendarContract.Attendees.TYPE_REQUIRED, CalendarContract.Attendees.TYPE_RESOURCE },
                        ", "));
    }
    return create(account, provider, values);
}

From source file:liqui.droid.activity.CalendarEvents.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.act_generic_list);
    setUpActionBar();//from   w ww.  j av  a 2  s.  c om

    createBreadcrumb(getResources().getString(R.string.title_explore), (BreadCrumbHolder[]) null);

    String calendarLocation = "content://" + CalendarContract.AUTHORITY + "/";

    Bundle extras = getIntent().getExtras();

    mCalendarId = extras.getString("_id");

    Log.d("XXX", "calendarId " + mCalendarId);

    mEventsUri = Uri.parse(calendarLocation + "events");

    getSupportLoaderManager().initLoader(0, null, this);
    mAdapter = new CalendarEventsCursorAdapter(this, null, true);

    ListView listView = (ListView) findViewById(R.id.list_view);
    listView.setOnItemClickListener(this);
    listView.setAdapter(mAdapter);
    registerForContextMenu(listView);

}

From source file:at.bitfire.ical4android.AndroidCalendar.java

/**
 * Acquires a ContentProviderClient for the Android Calendar Contract.
 * @return A ContentProviderClient, or null if calendar storage is not available/accessible
 *         Caller is responsible for calling release()!
 *//*  w ww . j  av a2  s.c  om*/
public static ContentProviderClient acquireContentProviderClient(ContentResolver resolver) {
    return resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);
}

From source file:at.bitfire.davdroid.mirakel.resource.LocalCalendar.java

@SuppressLint("InlinedApi")
public static void create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws LocalStorageException {
    ContentProviderClient client = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);
    if (client == null)
        throw new LocalStorageException("No Calendar Provider found (Calendar app disabled?)");

    int color = 0xFFC3EA6E; // fallback: "DAVdroid green"
    if (info.getColor() != null) {
        Pattern p = Pattern.compile("#(\\p{XDigit}{6})(\\p{XDigit}{2})?");
        Matcher m = p.matcher(info.getColor());
        if (m.find()) {
            int color_rgb = Integer.parseInt(m.group(1), 16);
            int color_alpha = m.group(2) != null ? (Integer.parseInt(m.group(2), 16) & 0xFF) : 0xFF;
            color = (color_alpha << 24) | color_rgb;
        }/*  ww w.  j a  v  a2  s . co m*/
    }

    ContentValues values = new ContentValues();
    values.put(Calendars.ACCOUNT_NAME, account.name);
    values.put(Calendars.ACCOUNT_TYPE, account.type);
    values.put(Calendars.NAME, info.getURL());
    values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle());
    values.put(Calendars.CALENDAR_COLOR, color);
    values.put(Calendars.OWNER_ACCOUNT, account.name);
    values.put(Calendars.SYNC_EVENTS, 1);
    values.put(Calendars.VISIBLE, 1);
    values.put(Calendars.ALLOWED_REMINDERS, Reminders.METHOD_ALERT);

    if (info.isReadOnly())
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
    else {
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
        values.put(Calendars.CAN_ORGANIZER_RESPOND, 1);
        values.put(Calendars.CAN_MODIFY_TIME_ZONE, 1);
    }

    if (android.os.Build.VERSION.SDK_INT >= 15) {
        values.put(Calendars.ALLOWED_AVAILABILITY, Events.AVAILABILITY_BUSY + "," + Events.AVAILABILITY_FREE
                + "," + Events.AVAILABILITY_TENTATIVE);
        values.put(Calendars.ALLOWED_ATTENDEE_TYPES, Attendees.TYPE_NONE + "," + Attendees.TYPE_OPTIONAL + ","
                + Attendees.TYPE_REQUIRED + "," + Attendees.TYPE_RESOURCE);
    }

    if (info.getTimezone() != null)
        values.put(Calendars.CALENDAR_TIME_ZONE, info.getTimezone());

    Log.i(TAG, "Inserting calendar: " + values.toString() + " -> " + calendarsURI(account).toString());
    try {
        client.insert(calendarsURI(account), values);
    } catch (RemoteException e) {
        throw new LocalStorageException(e);
    }
}

From source file:com.granita.icloudcalsync.resource.LocalCalendar.java

@SuppressLint("InlinedApi")
public static Uri create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws LocalStorageException {
    final ContentProviderClient client = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);
    if (client == null)
        throw new LocalStorageException("No Calendar Provider found (Calendar app disabled?)");

    ContentValues values = new ContentValues();
    values.put(Calendars.ACCOUNT_NAME, account.name);
    values.put(Calendars.ACCOUNT_TYPE, account.type);
    values.put(Calendars.NAME, info.getURL());
    values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle());
    values.put(Calendars.CALENDAR_COLOR, DAVUtils.CalDAVtoARGBColor(info.getColor()));
    values.put(Calendars.OWNER_ACCOUNT, account.name);
    values.put(Calendars.SYNC_EVENTS, 1);
    values.put(Calendars.VISIBLE, 1);//from w w  w  .  j  ava 2s .  c om
    values.put(Calendars.ALLOWED_REMINDERS, Reminders.METHOD_ALERT);

    if (info.isReadOnly())
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
    else {
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
        values.put(Calendars.CAN_ORGANIZER_RESPOND, 1);
        values.put(Calendars.CAN_MODIFY_TIME_ZONE, 1);
    }

    if (android.os.Build.VERSION.SDK_INT >= 15) {
        values.put(Calendars.ALLOWED_AVAILABILITY, Events.AVAILABILITY_BUSY + "," + Events.AVAILABILITY_FREE
                + "," + Events.AVAILABILITY_TENTATIVE);
        values.put(Calendars.ALLOWED_ATTENDEE_TYPES, Attendees.TYPE_NONE + "," + Attendees.TYPE_OPTIONAL + ","
                + Attendees.TYPE_REQUIRED + "," + Attendees.TYPE_RESOURCE);
    }

    if (info.getTimezone() != null)
        values.put(Calendars.CALENDAR_TIME_ZONE, info.getTimezone());

    Log.i(TAG, "Inserting calendar: " + values.toString());
    try {
        return client.insert(calendarsURI(account), values);
    } catch (RemoteException e) {
        throw new LocalStorageException(e);
    }
}

From source file:at.bitfire.davdroid.resource.LocalCalendar.java

@SuppressLint("InlinedApi")
public static Uri create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws LocalStorageException {
    @Cleanup("release")
    final ContentProviderClient client = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);
    if (client == null)
        throw new LocalStorageException("No Calendar Provider found (Calendar app disabled?)");

    ContentValues values = new ContentValues();
    values.put(Calendars.ACCOUNT_NAME, account.name);
    values.put(Calendars.ACCOUNT_TYPE, account.type);
    values.put(Calendars.NAME, info.getURL());
    values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle());
    values.put(Calendars.CALENDAR_COLOR, info.getColor() != null ? info.getColor() : DAVUtils.calendarGreen);
    values.put(Calendars.OWNER_ACCOUNT, account.name);
    values.put(Calendars.SYNC_EVENTS, 1);
    values.put(Calendars.VISIBLE, 1);//w  w w.j  a v  a  2 s.  c om
    values.put(Calendars.ALLOWED_REMINDERS, Reminders.METHOD_ALERT);

    if (info.isReadOnly())
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
    else {
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
        values.put(Calendars.CAN_ORGANIZER_RESPOND, 1);
        values.put(Calendars.CAN_MODIFY_TIME_ZONE, 1);
    }

    if (android.os.Build.VERSION.SDK_INT >= 15) {
        values.put(Calendars.ALLOWED_AVAILABILITY, Events.AVAILABILITY_BUSY + "," + Events.AVAILABILITY_FREE
                + "," + Events.AVAILABILITY_TENTATIVE);
        values.put(Calendars.ALLOWED_ATTENDEE_TYPES, Attendees.TYPE_NONE + "," + Attendees.TYPE_OPTIONAL + ","
                + Attendees.TYPE_REQUIRED + "," + Attendees.TYPE_RESOURCE);
    }

    if (info.getTimezone() != null)
        values.put(Calendars.CALENDAR_TIME_ZONE, DateUtils.findAndroidTimezoneID(info.getTimezone()));

    Log.i(TAG, "Inserting calendar: " + values.toString());
    try {
        return client.insert(calendarsURI(account), values);
    } catch (RemoteException e) {
        throw new LocalStorageException(e);
    }
}

From source file:com.xandy.calendar.selectcalendars.SelectCalendarsSyncFragment.java

@Override
public void onResume() {
    super.onResume();
    if (!ContentResolver.getMasterSyncAutomatically()
            || !ContentResolver.getSyncAutomatically(mAccount, CalendarContract.AUTHORITY)) {
        Resources res = getActivity().getResources();
        mSyncStatus.setText(res.getString(R.string.acct_not_synced));
        mSyncStatus.setVisibility(View.VISIBLE);
        mAccountsButton.setText(res.getString(R.string.accounts));
        mAccountsButton.setVisibility(View.VISIBLE);
    } else {/*  w  w w  .  j  av  a2 s  . com*/
        mSyncStatus.setVisibility(View.GONE);
        mAccountsButton.setVisibility(View.GONE);

        // Start a background sync to get the list of calendars from the server.
        Utils.startCalendarMetafeedSync(mAccount);
        getActivity().getContentResolver().registerContentObserver(Calendars.CONTENT_URI, true,
                mCalendarsObserver);
    }
}

From source file:org.exfio.csyncdroid.resource.LocalCalendar.java

@SuppressLint("InlinedApi")
public static void create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws RemoteException {
    ContentProviderClient client = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);

    //FIXME - change default colour
    int color = 0xFFC3EA6E; // fallback: "DAVdroid green"
    if (info.getColor() != null) {
        Pattern p = Pattern.compile("#(\\p{XDigit}{6})(\\p{XDigit}{2})?");
        Matcher m = p.matcher(info.getColor());
        if (m.find()) {
            int color_rgb = Integer.parseInt(m.group(1), 16);
            int color_alpha = m.group(2) != null ? (Integer.parseInt(m.group(2), 16) & 0xFF) : 0xFF;
            color = (color_alpha << 24) | color_rgb;
        }//from   w  w  w  .  j  a v  a 2 s. c  o m
    }

    ContentValues values = new ContentValues();
    values.put(Calendars.ACCOUNT_NAME, account.name);
    values.put(Calendars.ACCOUNT_TYPE, account.type);
    values.put(Calendars.NAME, info.getCollection());
    values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle());
    values.put(Calendars.CALENDAR_COLOR, color);
    values.put(Calendars.OWNER_ACCOUNT, account.name);
    values.put(Calendars.SYNC_EVENTS, 1);
    values.put(Calendars.VISIBLE, 1);
    values.put(Calendars.ALLOWED_REMINDERS, Reminders.METHOD_ALERT);

    if (info.isReadOnly())
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
    else {
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
        values.put(Calendars.CAN_ORGANIZER_RESPOND, 1);
        values.put(Calendars.CAN_MODIFY_TIME_ZONE, 1);
    }

    if (android.os.Build.VERSION.SDK_INT >= 15) {
        values.put(Calendars.ALLOWED_AVAILABILITY, Events.AVAILABILITY_BUSY + "," + Events.AVAILABILITY_FREE
                + "," + Events.AVAILABILITY_TENTATIVE);
        values.put(Calendars.ALLOWED_ATTENDEE_TYPES, Attendees.TYPE_NONE + "," + Attendees.TYPE_OPTIONAL + ","
                + Attendees.TYPE_REQUIRED + "," + Attendees.TYPE_RESOURCE);
    }

    if (info.getTimezone() != null)
        values.put(Calendars.CALENDAR_TIME_ZONE, info.getTimezone());

    Log.i(TAG, "Inserting calendar: " + values.toString() + " -> " + calendarsURI(account).toString());
    client.insert(calendarsURI(account), values);
}

From source file:com.google.samples.apps.iosched.service.SessionCalendarService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (!permissionsAlreadyGranted()) {
        LOGW(TAG, "Calendar permission not granted.");
        return;//from  ww  w . jav  a 2  s .  c  o m
    }

    final String action = intent.getAction();
    LOGD(TAG, "Received intent: " + action);

    final ContentResolver resolver = getContentResolver();

    boolean isAddEvent = false;

    if (ACTION_ADD_SESSION_CALENDAR.equals(action)) {
        isAddEvent = true;

    } else if (ACTION_REMOVE_SESSION_CALENDAR.equals(action)) {
        isAddEvent = false;

    } else if (ACTION_UPDATE_ALL_SESSIONS_CALENDAR.equals(action) && SettingsUtils.shouldSyncCalendar(this)) {
        try {
            getContentResolver().applyBatch(CalendarContract.AUTHORITY,
                    processAllSessionsCalendar(resolver, getCalendarId(intent)));
            sendBroadcast(new Intent(SessionCalendarService.ACTION_UPDATE_ALL_SESSIONS_CALENDAR_COMPLETED));
        } catch (RemoteException | OperationApplicationException e) {
            LOGE(TAG, "Error adding all sessions to Google Calendar", e);
        }

    } else if (ACTION_CLEAR_ALL_SESSIONS_CALENDAR.equals(action)) {
        try {
            getContentResolver().applyBatch(CalendarContract.AUTHORITY,
                    processClearAllSessions(resolver, getCalendarId(intent)));
        } catch (RemoteException | OperationApplicationException e) {
            LOGE(TAG, "Error clearing all sessions from Google Calendar", e);
        }

    } else {
        return;
    }

    final Uri uri = intent.getData();
    final Bundle extras = intent.getExtras();
    if (uri == null || extras == null || !SettingsUtils.shouldSyncCalendar(this)) {
        return;
    }

    try {
        resolver.applyBatch(CalendarContract.AUTHORITY,
                processSessionCalendar(resolver, getCalendarId(intent), isAddEvent, uri,
                        extras.getLong(EXTRA_SESSION_START), extras.getLong(EXTRA_SESSION_END),
                        extras.getString(EXTRA_SESSION_TITLE), extras.getString(EXTRA_SESSION_ROOM)));
    } catch (RemoteException | OperationApplicationException e) {
        LOGE(TAG, "Error adding session to Google Calendar", e);
    }
}

From source file:at.bitfire.davdroid.ui.setup.AccountDetailsFragment.java

protected boolean createAccount(String accountName, DavResourceFinder.Configuration config) {
    Account account = new Account(accountName, Constants.ACCOUNT_TYPE);

    // create Android account
    Bundle userData = AccountSettings.initialUserData(config.userName);
    App.log.log(Level.INFO, "Creating Android account with initial config", new Object[] { account, userData });

    AccountManager accountManager = AccountManager.get(getContext());
    if (!accountManager.addAccountExplicitly(account, config.password, userData))
        return false;

    // add entries for account to service DB
    App.log.log(Level.INFO, "Writing account configuration to database", config);
    @Cleanup//from w w  w  . java  2  s.c om
    OpenHelper dbHelper = new OpenHelper(getContext());
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    try {
        AccountSettings settings = new AccountSettings(getContext(), account);

        Intent refreshIntent = new Intent(getActivity(), DavService.class);
        refreshIntent.setAction(DavService.ACTION_REFRESH_COLLECTIONS);

        if (config.cardDAV != null) {
            // insert CardDAV service
            long id = insertService(db, accountName, Services.SERVICE_CARDDAV, config.cardDAV);

            // start CardDAV service detection (refresh collections)
            refreshIntent.putExtra(DavService.EXTRA_DAV_SERVICE_ID, id);
            getActivity().startService(refreshIntent);

            // initial CardDAV account settings
            int idx = spnrGroupMethod.getSelectedItemPosition();
            String groupMethodName = getResources()
                    .getStringArray(R.array.settings_contact_group_method_values)[idx];
            settings.setGroupMethod(GroupMethod.valueOf(groupMethodName));

            // enable contact sync
            ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
            settings.setSyncInterval(ContactsContract.AUTHORITY, DEFAULT_SYNC_INTERVAL);
        } else
            // disable contact sync when CardDAV is not available
            ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 0);

        if (config.calDAV != null) {
            // insert CalDAV service
            long id = insertService(db, accountName, Services.SERVICE_CALDAV, config.calDAV);

            // start CalDAV service detection (refresh collections)
            refreshIntent.putExtra(DavService.EXTRA_DAV_SERVICE_ID, id);
            getActivity().startService(refreshIntent);

            // enable calendar sync
            ContentResolver.setIsSyncable(account, CalendarContract.AUTHORITY, 1);
            settings.setSyncInterval(CalendarContract.AUTHORITY, DEFAULT_SYNC_INTERVAL);

            // enable task sync, if possible
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                /* Android >=6, it's possible to gain OpenTasks permissions dynamically, so
                 * OpenTasks sync will be enabled by default. Setting the sync interval to "manually"
                 * if OpenTasks is not installed avoids the "sync error" in Android settings / Accounts. */
                ContentResolver.setIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority, 1);
                settings.setSyncInterval(TaskProvider.ProviderName.OpenTasks.authority,
                        LocalTaskList.tasksProviderAvailable(getContext()) ? DEFAULT_SYNC_INTERVAL
                                : AccountSettings.SYNC_INTERVAL_MANUALLY);
            } else {
                // Android <6: enable task sync according to whether OpenTasks is accessible
                if (LocalTaskList.tasksProviderAvailable(getContext())) {
                    ContentResolver.setIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority, 1);
                    settings.setSyncInterval(TaskProvider.ProviderName.OpenTasks.authority,
                            DEFAULT_SYNC_INTERVAL);
                } else
                    // Android <6 only: disable OpenTasks sync forever when OpenTasks is not installed
                    // because otherwise, there will be a non-catchable SecurityException as soon as OpenTasks is installed
                    ContentResolver.setIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority, 0);
            }
        } else {
            // disable calendar and task sync when CalDAV is not available
            ContentResolver.setIsSyncable(account, CalendarContract.AUTHORITY, 0);
            ContentResolver.setIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority, 0);
        }

    } catch (InvalidAccountException e) {
        App.log.log(Level.SEVERE, "Couldn't access account settings", e);
    }

    return true;
}