Example usage for android.provider CalendarContract ACCOUNT_TYPE_LOCAL

List of usage examples for android.provider CalendarContract ACCOUNT_TYPE_LOCAL

Introduction

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

Prototype

String ACCOUNT_TYPE_LOCAL

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

Click Source Link

Document

A special account type for calendars not associated with any account.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static Uri buildCalUri() {
    return CalendarContract.Calendars.CONTENT_URI.buildUpon()
            .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
            .appendQueryParameter(Calendars.ACCOUNT_NAME, ACCOUNT_NAME)
            .appendQueryParameter(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL).build();
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static ContentValues buildContentValues() {
    int colorCalendar = 0x0066CC;
    String intName = ACCOUNT_NAME + Calendar_Name;
    final ContentValues cv = new ContentValues();
    cv.put(Calendars.ACCOUNT_NAME, ACCOUNT_NAME);
    cv.put(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
    cv.put(Calendars.NAME, intName);//from   w w w  . j a v a  2  s . com
    cv.put(Calendars.CALENDAR_DISPLAY_NAME, Calendar_Name);
    cv.put(Calendars.CALENDAR_COLOR, colorCalendar);
    cv.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
    cv.put(Calendars.OWNER_ACCOUNT, ACCOUNT_NAME);
    cv.put(Calendars.VISIBLE, 1);
    cv.put(Calendars.SYNC_EVENTS, 1);
    return cv;
}

From source file:com.android.calendar.event.CreateEventDialogFragment.java

private void setDefaultCalendarView(Cursor cursor) {
    if (cursor == null || cursor.getCount() == 0) {
        // Create an error message for the user that, when clicked,
        // will exit this activity without saving the event.
        dismiss();//from  w w  w  . j  a  v  a2  s. c o m
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(R.string.no_syncable_calendars).setIconAttribute(android.R.attr.alertDialogIcon)
                .setMessage(R.string.no_calendars_found)
                .setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        final Activity activity = getActivity();
                        if (activity != null) {
                            Intent nextIntent = new Intent(Settings.ACTION_ADD_ACCOUNT);
                            final String[] array = { "com.android.calendar" };
                            nextIntent.putExtra(Settings.EXTRA_AUTHORITIES, array);
                            nextIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                            activity.startActivity(nextIntent);
                        }
                    }
                }).setNegativeButton(android.R.string.no, null);
        builder.show();
        return;
    }

    String defaultCalendar = null;
    final Activity activity = getActivity();
    if (activity != null) {
        defaultCalendar = Utils.getSharedPreference(activity, GeneralPreferences.KEY_DEFAULT_CALENDAR,
                (String) null);
    } else {
        Log.e(TAG, "Activity is null, cannot load default calendar");
    }

    int calendarOwnerIndex = cursor.getColumnIndexOrThrow(Calendars.OWNER_ACCOUNT);
    int accountNameIndex = cursor.getColumnIndexOrThrow(Calendars.ACCOUNT_NAME);
    int accountTypeIndex = cursor.getColumnIndexOrThrow(Calendars.ACCOUNT_TYPE);

    cursor.moveToPosition(-1);
    while (cursor.moveToNext()) {
        String calendarOwner = cursor.getString(calendarOwnerIndex);
        if (defaultCalendar == null) {
            // There is no stored default upon the first time running.  Use a primary
            // calendar in this case.
            if (calendarOwner != null && calendarOwner.equals(cursor.getString(accountNameIndex))
                    && !CalendarContract.ACCOUNT_TYPE_LOCAL.equals(cursor.getString(accountTypeIndex))) {
                setCalendarFields(cursor);
                return;
            }
        } else if (defaultCalendar.equals(calendarOwner)) {
            // Found the default calendar.
            setCalendarFields(cursor);
            return;
        }
    }
    cursor.moveToFirst();
    setCalendarFields(cursor);
}

From source file:com.android.calendar.event.EditEventView.java

private int findDefaultCalendarPosition(Cursor calendarsCursor) {
    if (calendarsCursor.getCount() <= 0) {
        return -1;
    }//w  ww.  ja v  a 2  s .c om

    String defaultCalendar = Utils.getSharedPreference(mActivity, GeneralPreferences.KEY_DEFAULT_CALENDAR,
            (String) null);

    int calendarsOwnerIndex = calendarsCursor.getColumnIndexOrThrow(Calendars.OWNER_ACCOUNT);
    int accountNameIndex = calendarsCursor.getColumnIndexOrThrow(Calendars.ACCOUNT_NAME);
    int accountTypeIndex = calendarsCursor.getColumnIndexOrThrow(Calendars.ACCOUNT_TYPE);
    int position = 0;
    calendarsCursor.moveToPosition(-1);
    while (calendarsCursor.moveToNext()) {
        String calendarOwner = calendarsCursor.getString(calendarsOwnerIndex);
        if (defaultCalendar == null) {
            // There is no stored default upon the first time running. Use a
            // primary
            // calendar in this case.
            if (calendarOwner != null && calendarOwner.equals(calendarsCursor.getString(accountNameIndex))
                    && !CalendarContract.ACCOUNT_TYPE_LOCAL
                            .equals(calendarsCursor.getString(accountTypeIndex))) {
                return position;
            }
        } else if (defaultCalendar.equals(calendarOwner)) {
            // Found the default calendar.
            return position;
        }
        position++;
    }
    return 0;
}