android.provider.CalendarContract Java Examples

The following examples show how to use android.provider.CalendarContract. 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: CalendarProviderManager.java    From CalendarProviderManager with Apache License 2.0 6 votes vote down vote up
/**
 * 检查是否存在日历账户
 *
 * @return 存在:日历账户ID  不存在:-1
 */
private static long checkCalendarAccount(Context context) {
    try (Cursor cursor = context.getContentResolver().query(CalendarContract.Calendars.CONTENT_URI,
            null, null, null, null)) {
        // 不存在日历账户
        if (null == cursor) {
            return -1;
        }
        int count = cursor.getCount();
        // 存在日历账户,获取第一个账户的ID
        if (count > 0) {
            cursor.moveToFirst();
            return cursor.getInt(cursor.getColumnIndex(CalendarContract.Calendars._ID));
        } else {
            return -1;
        }
    }
}
 
Example #3
Source File: CalendarWrapper.java    From mOrgAnd with GNU General Public License v2.0 6 votes vote down vote up
public int getCalendarID(String calendarName) {
	Cursor cursor = context.getContentResolver().query(
			CalendarContract.Calendars.CONTENT_URI,
			new String[] { CalendarContract.Calendars._ID,
                       CalendarContract.Calendars.CALENDAR_DISPLAY_NAME }, null, null,
			null);
	if (cursor != null && cursor.moveToFirst()) {
		for (int i = 0; i < cursor.getCount(); i++) {
			int calId = cursor.getInt(0);
			String calName = cursor.getString(1);

			if (calName.equals(calendarName)) {
				cursor.close();
				return calId;
			}
			cursor.moveToNext();
		}
		cursor.close();
	}
	return -1;
}
 
Example #4
Source File: CalendarProviderManager.java    From CalendarProviderManager with Apache License 2.0 6 votes vote down vote up
/**
 * 更新指定ID事件的描述
 *
 * @return If successfully returns 1
 */
public static int updateCalendarEventDes(Context context, long eventID, String newEventDes) {
    checkContextNull(context);

    Uri uri = CalendarContract.Events.CONTENT_URI;

    // 新的数据
    ContentValues event = new ContentValues();
    event.put(CalendarContract.Events.DESCRIPTION, newEventDes);


    // 匹配条件
    String selection = "(" + CalendarContract.Events._ID + " = ?)";
    String[] selectionArgs = new String[]{String.valueOf(eventID)};

    return context.getContentResolver().update(uri, event, selection, selectionArgs);
}
 
Example #5
Source File: WizardActivity.java    From haxsync with GNU General Public License v2.0 6 votes vote down vote up
private void readSettings(){
  	Account account = DeviceUtil.getAccount(this);
  	boolean contactSync = true;
  	boolean calendarSync = true;
  	if (account != null){
   	contactSync = ContentResolver.getSyncAutomatically(account, ContactsContract.AUTHORITY);
   	calendarSync = ContentResolver.getSyncAutomatically(account, CalendarContract.AUTHORITY);
  	}
SharedPreferences prefs = getSharedPreferences(getPackageName() + "_preferences", MODE_MULTI_PROCESS);

  	if (!contactSync)
  		contactSpinner.setSelection(0);
  	else if (prefs.getBoolean("phone_only", true))
  		contactSpinner.setSelection(1);
  	else
  		contactSpinner.setSelection(2);
  	
eventSwitch.setChecked(prefs.getBoolean("sync_events", true) && calendarSync);
birthdaySwitch.setChecked(prefs.getBoolean("sync_birthdays", true) && calendarSync);
reminderSwitch.setChecked(prefs.getBoolean("event_reminders", true));
wizardCheck.setChecked(!DeviceUtil.isWizardShown(this));
toggleReminderVisibility();
  }
 
Example #6
Source File: AndroidCalendarManager.java    From ETSMobile-Android2 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the id of the specified calendar
 * @param calendarName
 * @return id
 */
public int getCalendarId(String calendarName) throws Exception {

    String selection = "(" + CalendarContract.Calendars.CALENDAR_DISPLAY_NAME+ " = ?)";
    String[] selectionArgs = new String[] {calendarName};
    Cursor calendarCursor = context.getContentResolver().query(CalendarContract.Calendars.CONTENT_URI, new String[] {CalendarContract.Calendars._ID,
            CalendarContract.Calendars.ACCOUNT_NAME,
            CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,
            CalendarContract.Calendars.NAME,
            CalendarContract.Calendars.CALENDAR_COLOR}, selection, selectionArgs, null);

    long id = 0;
    if (calendarCursor.moveToFirst()) {
        id = calendarCursor.getLong(0);
    }

    if(id==0) {
        throw new Exception("Calendar not found");
    }

    calendarCursor.close();
    return (int)id;

}
 
Example #7
Source File: CalendarProviderManager.java    From CalendarProviderManager with Apache License 2.0 6 votes vote down vote up
/**
 * 更新指定ID事件的起始时间
 *
 * @return If successfully returns 1
 */
public static int updateCalendarEventTime(Context context, long eventID, long newBeginTime,
                                          long newEndTime) {
    checkContextNull(context);

    Uri uri = CalendarContract.Events.CONTENT_URI;

    // 新的数据
    ContentValues event = new ContentValues();
    event.put(CalendarContract.Events.DTSTART, newBeginTime);
    event.put(CalendarContract.Events.DTEND, newEndTime);


    // 匹配条件
    String selection = "(" + CalendarContract.Events._ID + " = ?)";
    String[] selectionArgs = new String[]{String.valueOf(eventID)};

    return context.getContentResolver().update(uri, event, selection, selectionArgs);
}
 
Example #8
Source File: EventLoader.java    From RememBirthday with GNU General Public License v3.0 6 votes vote down vote up
public synchronized static void deleteEventsFromContact(Context context, Contact contact) {
    ArrayList<ContentProviderOperation> operations = new ArrayList<>();
    try {
        for (CalendarEvent event : getEventsSavedForEachYear(context, contact)) {
            operations.add(ReminderProvider.deleteAll(context, event.getId()));
            operations.add(EventProvider.delete(event));
        }
        ContentProviderResult[] contentProviderResults =
                context.getContentResolver().applyBatch(CalendarContract.AUTHORITY, operations);
        for(ContentProviderResult contentProviderResult : contentProviderResults) {
            Log.d(TAG, contentProviderResult.toString());
            if (contentProviderResult.uri != null)
                Log.d(TAG, contentProviderResult.uri.toString());
        }
    } catch (RemoteException |OperationApplicationException |EventException e) {
        Log.e(TAG, "Unable to deleteById events : " + e.getMessage());
    }
}
 
Example #9
Source File: CalendarProviderManager.java    From CalendarProviderManager with Apache License 2.0 6 votes vote down vote up
/**
 * 更新指定ID事件的结束时间
 *
 * @return If successfully returns 1
 */
public static int updateCalendarEventEndTime(Context context, long eventID, long newEndTime) {
    checkContextNull(context);

    Uri uri = CalendarContract.Events.CONTENT_URI;

    // 新的数据
    ContentValues event = new ContentValues();
    event.put(CalendarContract.Events.DTEND, newEndTime);


    // 匹配条件
    String selection = "(" + CalendarContract.Events._ID + " = ?)";
    String[] selectionArgs = new String[]{String.valueOf(eventID)};

    return context.getContentResolver().update(uri, event, selection, selectionArgs);
}
 
Example #10
Source File: CalendarProviderManager.java    From CalendarProviderManager with Apache License 2.0 6 votes vote down vote up
/**
 * 更新指定ID事件的常用信息(标题、描述、地点)
 *
 * @return If successfully returns 1
 */
public static int updateCalendarEventCommonInfo(Context context, long eventID, String newEventTitle,
                                                String newEventDes, String newEventLocation) {
    checkContextNull(context);

    Uri uri = CalendarContract.Events.CONTENT_URI;

    // 新的数据
    ContentValues event = new ContentValues();
    event.put(CalendarContract.Events.TITLE, newEventTitle);
    event.put(CalendarContract.Events.DESCRIPTION, newEventDes);
    event.put(CalendarContract.Events.EVENT_LOCATION, newEventLocation);


    // 匹配条件
    String selection = "(" + CalendarContract.Events._ID + " = ?)";
    String[] selectionArgs = new String[]{String.valueOf(eventID)};

    return context.getContentResolver().update(uri, event, selection, selectionArgs);
}
 
Example #11
Source File: CalendarSyncAdapterService.java    From haxsync with GNU General Public License v2.0 6 votes vote down vote up
public static void setCalendarColor(Context context, Account account, String name, int color){
	mContentResolver = context.getContentResolver();
	long calID = getCalendarID(account, name);
	if (calID == -2){
		return;
	}
	ContentValues values = new ContentValues();
	values.put(CalendarContract.Calendars.CALENDAR_COLOR, color);
	Uri calcUri = CalendarContract.Calendars.CONTENT_URI.buildUpon()
			.appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER, "true")
			.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, account.name)
			.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, account.type)
			.build();

	mContentResolver.update(calcUri, values, CalendarContract.Calendars._ID + " = " + calID, null);

	
}
 
Example #12
Source File: AndroidCalendarManager.java    From ETSMobile-Android2 with Apache License 2.0 6 votes vote down vote up
/**
 * Insert an event in the local calendar
 * @param calendarName
 * @param title
 * @param description
 * @param place
 * @param start
 * @param end
 * @throws Exception
 */
public void insertEventInCalendar(String calendarName,String title,String description, String place, Date start, Date end) throws Exception {
    int calendarId = getCalendarId(calendarName);

    Calendar beginTime = Calendar.getInstance();
    beginTime.setTime(start);

    Calendar endTime = Calendar.getInstance();
    endTime.setTime(end);

    ContentValues values = new ContentValues();
    values.put(CalendarContract.Events.DTSTART, beginTime.getTimeInMillis());
    values.put(CalendarContract.Events.DTEND, endTime.getTimeInMillis());
    values.put(CalendarContract.Events.TITLE, title);
    values.put(CalendarContract.Events.DESCRIPTION, description);
    values.put(CalendarContract.Events.EVENT_LOCATION, place);
    values.put(CalendarContract.Events.CALENDAR_ID,calendarId );
    values.put(CalendarContract.Events.EVENT_TIMEZONE, "America/Montreal");

    context.getContentResolver().insert(CalendarContract.Events.CONTENT_URI, values);
}
 
Example #13
Source File: Calendar.java    From intra42 with Apache License 2.0 6 votes vote down vote up
private static void removeEventFromCalendar(Context context, int event) {

        Uri eventsUri = Uri.parse("content://com.android.calendar/events");

        ContentResolver resolver = context.getContentResolver();

        String selection = CalendarContract.Events.CUSTOM_APP_URI + " = ?";
        String[] selectionArgs = {getEventUri(event)};

        Cursor cursor = resolver.query(eventsUri, new String[]{"_id"}, selection, selectionArgs, null);
        while (cursor.moveToNext()) {
            long eventId = cursor.getLong(cursor.getColumnIndex("_id"));
            resolver.delete(ContentUris.withAppendedId(eventsUri, eventId), null, null);
        }
        cursor.close();
    }
 
Example #14
Source File: HoraireFragment.java    From ETSMobile-Android2 with Apache License 2.0 6 votes vote down vote up
protected void onPostExecute(Object result) {

            customProgressDialog.dismiss();
            if (exception != null) {
                Toast.makeText(getActivity(), getString(R.string.toast_Calendar_Update_Error), Toast.LENGTH_SHORT).show();
            } else {

                //Launch native calendar app
                long startMillis = java.lang.System.currentTimeMillis();
                Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
                builder.appendPath("time");
                ContentUris.appendId(builder, startMillis);

                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(builder.build());

                startActivity(intent);

            }
        }
 
Example #15
Source File: CalendarFragment.java    From persian-calendar-view with GNU General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example #16
Source File: EventProvider.java    From RememBirthday with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Utility method for add values in Builder
 * @param builder ContentProviderOperation.Builder
 * @param event Event to add
 */
private static synchronized void assignValuesInBuilder(ContentProviderOperation.Builder builder, CalendarEvent event) {
    if(event.isAllDay()) {
        // ALL_DAY events must be UTC
        DateTime dateTimeStartUTC = new DateTime(event.getDateStart()).withZoneRetainFields(DateTimeZone.UTC);
        DateTime dateTimeStopUTC = new DateTime(event.getDateStop()).withZoneRetainFields(DateTimeZone.UTC);
        builder.withValue(CalendarContract.Events.DTSTART, dateTimeStartUTC.toDate().getTime());
        builder.withValue(CalendarContract.Events.DTEND, dateTimeStopUTC.toDate().getTime());
        builder.withValue(CalendarContract.Events.EVENT_TIMEZONE, "UTC");
        builder.withValue(CalendarContract.Events.ALL_DAY, 1);
    } else {
        builder.withValue(CalendarContract.Events.DTSTART, event.getDateStart().getTime());
        builder.withValue(CalendarContract.Events.DTEND, event.getDateStop().getTime());
        builder.withValue(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
    }
    builder.withValue(CalendarContract.Events.TITLE, event.getTitle());
}
 
Example #17
Source File: MainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
private void listing10_26() {
  // Listing 10-26: Inserting a new calendar event using an Intent

  // Create a new insertion Intent.
  Intent intent = new Intent(Intent.ACTION_INSERT, CalendarContract.Events.CONTENT_URI);

  // Add the calendar event details
  intent.putExtra(CalendarContract.Events.TITLE, "Book Launch!");
  intent.putExtra(CalendarContract.Events.DESCRIPTION, "Professional Android Release!");
  intent.putExtra(CalendarContract.Events.EVENT_LOCATION, "Wrox.com");

  Calendar startTime = Calendar.getInstance();
  startTime.set(2018, 6, 19, 0, 30);
  intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startTime.getTimeInMillis());

  // Use the Calendar app to add the new event.
  startActivity(intent);
}
 
Example #18
Source File: MainActivity.java    From ToDay with MIT License 6 votes vote down vote up
private void createLocalCalendar() {
    String name = getString(R.string.default_calendar_name);
    ContentValues cv = new ContentValues();
    cv.put(CalendarContract.Calendars.ACCOUNT_NAME, BuildConfig.APPLICATION_ID);
    cv.put(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
    cv.put(CalendarContract.Calendars.NAME, name);
    cv.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, name);
    cv.put(CalendarContract.Calendars.CALENDAR_COLOR, 0);
    cv.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL,
            CalendarContract.Calendars.CAL_ACCESS_OWNER);
    cv.put(CalendarContract.Calendars.OWNER_ACCOUNT, BuildConfig.APPLICATION_ID);
    new CalendarQueryHandler(getContentResolver())
            .startInsert(0, null, CalendarContract.Calendars.CONTENT_URI
                            .buildUpon()
                            .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "1")
                            .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME,
                                    BuildConfig.APPLICATION_ID)
                            .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE,
                                    CalendarContract.ACCOUNT_TYPE_LOCAL)
                            .build()
                    , cv);
}
 
Example #19
Source File: AndroidCalendarManager.java    From ETSMobile-Android2 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a string containing all user's calendars
 * @return
 */
public String selectAllCalendars() {
    Cursor calendarCursor = context.getContentResolver().query(CalendarContract.Calendars.CONTENT_URI, projection, null, null, null);
    String response = "";

    if (calendarCursor.moveToFirst()) {
        do {
            long id = calendarCursor.getLong(0);
            String accountName = calendarCursor.getString(1);
            String calendarDisplayName = calendarCursor.getString(2);
            String name = calendarCursor.getString(3);
            String calendarColor = calendarCursor.getString(4);

            response += id+"-"+accountName+"-"+calendarDisplayName+"-"+name+"-"+calendarColor+"\n";

        } while (calendarCursor.moveToNext());
    }
    calendarCursor.close();
    return response;
}
 
Example #20
Source File: CalendarProviderManager.java    From CalendarProviderManager with Apache License 2.0 6 votes vote down vote up
/**
 * 通过Intent启动系统日历新建事件界面插入新的事件
 * <p>
 * TIP: 这将不再需要声明读写日历数据的权限
 *
 * @param beginTime 事件开始时间
 * @param endTime   事件结束时间
 * @param title     事件标题
 * @param des       事件描述
 * @param location  事件地点
 * @param isAllDay  事件是否全天
 */
public static void startCalendarForIntentToInsert(Context context, long beginTime, long endTime,
                                                  String title, String des, String location,
                                                  boolean isAllDay) {
    checkCalendarAccount(context);


    // FIXME: 2019/3/6 VIVO手机无法打开界面,找不到对应的Activity  com.bbk.calendar
    Intent intent = new Intent(Intent.ACTION_INSERT)
            .setData(CalendarContract.Events.CONTENT_URI)
            .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime)
            .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime)
            .putExtra(CalendarContract.Events.ALL_DAY, isAllDay)
            .putExtra(CalendarContract.Events.TITLE, title)
            .putExtra(CalendarContract.Events.DESCRIPTION, des)
            .putExtra(CalendarContract.Events.EVENT_LOCATION, location);

    if (null != intent.resolveActivity(context.getPackageManager())) {
        context.startActivity(intent);
    }
}
 
Example #21
Source File: PickCalendarDialogFragment.java    From utexas-utilities with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    parentAct = getActivity();
    ArrayList<String> calendars = getArguments().getStringArrayList("calendars");
    return new AlertDialog.Builder(getActivity())
            .setAdapter(new CalendarAdapter(getActivity(), calendars), (dialog, which) -> {
                CalendarInsertHandler cih = new CalendarInsertHandler(getActivity()
                        .getContentResolver());
                ArrayList<ContentValues> cvList = getArguments().getParcelableArrayList(
                        "valuesList");
                ArrayList<Integer> indices = getArguments().getIntegerArrayList("indices");
                int selection = indices.get(which);

                for (int i = 0; i < cvList.size(); i++) {
                    cvList.get(i).put(CalendarContract.Events.CALENDAR_ID, selection);
                    cih.startInsert(i, null, CalendarContract.Events.CONTENT_URI, cvList.get(i));
                }
            })
            .setTitle("Select calendar")
            .create();
}
 
Example #22
Source File: CalendarWriteTest.java    From AndPermission with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test() throws Throwable {
    try {
        TimeZone timeZone = TimeZone.getDefault();
        ContentValues value = new ContentValues();
        value.put(CalendarContract.Calendars.NAME, NAME);
        value.put(CalendarContract.Calendars.ACCOUNT_NAME, ACCOUNT);
        value.put(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
        value.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, NAME);
        value.put(CalendarContract.Calendars.VISIBLE, 1);
        value.put(CalendarContract.Calendars.CALENDAR_COLOR, Color.BLUE);
        value.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER);
        value.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
        value.put(CalendarContract.Calendars.CALENDAR_TIME_ZONE, timeZone.getID());
        value.put(CalendarContract.Calendars.OWNER_ACCOUNT, NAME);
        value.put(CalendarContract.Calendars.CAN_ORGANIZER_RESPOND, 0);

        Uri insertUri = CalendarContract.Calendars.CONTENT_URI.buildUpon()
            .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
            .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, NAME)
            .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL)
            .build();
        Uri resourceUri = mResolver.insert(insertUri, value);
        return ContentUris.parseId(resourceUri) > 0;
    } finally {
        Uri deleteUri = CalendarContract.Calendars.CONTENT_URI.buildUpon().build();
        mResolver.delete(deleteUri, CalendarContract.Calendars.ACCOUNT_NAME + "=?", new String[]{ACCOUNT});
    }
}
 
Example #23
Source File: ActivityUtils.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
public ActivityUtils startCalendarApp() {
    Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
    builder.appendPath("time");
    builder.appendPath(Long.toString(System.currentTimeMillis()));
    Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
    _activity.startActivity(intent);
    return this;
}
 
Example #24
Source File: CalendarResolver.java    From mCalendar with Apache License 2.0 5 votes vote down vote up
public TaskBean getTaskById(long id){
    TaskBean ret = null;
    Cursor cursor = contentResolver.query(EVENTS_URI,
            EVENTS_FIELDS,
            new StringBuilder().append(CalendarContract.Events._ID).append("=?").toString(),
            new String[]{"" + id},
            null);
    if (cursor.getCount() > 0){
        while (cursor.moveToNext()){
            ret = new TaskBean().populate(cursor);
        }
    }
    return ret;
}
 
Example #25
Source File: CalendarReadTest.java    From AndPermission with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test() throws Throwable {
    String[] projection = new String[] {CalendarContract.Calendars._ID, CalendarContract.Calendars.NAME};
    Cursor cursor = mResolver.query(CalendarContract.Calendars.CONTENT_URI, projection, null, null, null);
    if (cursor != null) {
        try {
            CursorTest.read(cursor);
        } finally {
            cursor.close();
        }
        return true;
    } else {
        return false;
    }
}
 
Example #26
Source File: CalendarSelectionView.java    From ToDay with MIT License 5 votes vote down vote up
public CalendarCursorAdapter(Context context) {
    super(context,
            R.layout.list_item_calendar,
            null,
            new String[]{CalendarContract.Calendars.CALENDAR_DISPLAY_NAME},
            new int[]{R.id.text_view_title},
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
}
 
Example #27
Source File: ReminderProvider.java    From RememBirthday with GNU General Public License v3.0 5 votes vote down vote up
public static ContentProviderOperation update(Context context, long eventId, Reminder reminder) {
    ContentProviderOperation.Builder builder = ContentProviderOperation
            .newUpdate(CalendarLoader.getBirthdayAdapterUri(context, CalendarContract.Reminders.CONTENT_URI))
        .withSelection(CalendarContract.Reminders._ID + " =?"
                + " AND " + CalendarContract.Reminders.EVENT_ID + " =?"
            , new String[]{String.valueOf(reminder.getId()),
                String.valueOf(eventId)})
        .withValue(CalendarContract.Reminders.MINUTES, reminder.getMinutesBeforeEvent());
    return  builder.build();
}
 
Example #28
Source File: EventEditView.java    From ToDay with MIT License 5 votes vote down vote up
private void showCalendarPicker() {
    new AlertDialog.Builder(getContext())
            .setCursor(mCursor, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    changeCalendar(which);
                }
            }, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME)
            .setNegativeButton(android.R.string.cancel, null)
            .create()
            .show();
}
 
Example #29
Source File: MainActivity.java    From ToDay with MIT License 5 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    String selection = null;
    String[] selectionArgs = null;
    if (id == LOADER_LOCAL_CALENDAR) {
        selection = CalendarContract.Calendars.ACCOUNT_TYPE + "=?";
        selectionArgs = new String[]{String.valueOf(CalendarContract.ACCOUNT_TYPE_LOCAL)};
    }
    return new CursorLoader(this,
            CalendarContract.Calendars.CONTENT_URI,
            CalendarCursor.PROJECTION, selection, selectionArgs,
            CalendarContract.Calendars.DEFAULT_SORT_ORDER);
}
 
Example #30
Source File: CalendarListFragment.java    From offline-calendar with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Define Adapter and Loader on create of Activity
 */
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    getListView().setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            // edit calendar
            Intent intent = new Intent(getActivity(), EditActivity.class);
            intent.setData(ContentUris.withAppendedId(CalendarContract.Calendars.CONTENT_URI, id));
            startActivity(intent);
        }
    });

    // Give some text to display if there is no data.
    setEmptyText(getString(R.string.main_activity_empty_list));

    mAdapter = new CalendarListViewAdapter(getActivity(), null, true);

    setListAdapter(mAdapter);

    // Start out with a progress indicator.
    setListShown(false);

    // Prepare the loader. Either re-connect with an existing one,
    // or start a new one.
    getLoaderManager().initLoader(0, null, this);
}