Android Open Source - Android-Calendar-Sync Utility






From Project

Back to project page Android-Calendar-Sync.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Defi...

If you think the Android project Android-Calendar-Sync listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 Mukesh Y authors//from  w  w w.j  a v a  2s .  c  o  m
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.examples.android.calendar;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

/**
 * @author Mukesh Y
 */
public class Utility {
  public static ArrayList<String> nameOfEvent = new ArrayList<String>();
  public static ArrayList<String> startDates = new ArrayList<String>();
  public static ArrayList<String> endDates = new ArrayList<String>();
  public static ArrayList<String> descriptions = new ArrayList<String>();

  public static ArrayList<String> readCalendarEvent(Context context) {
    Cursor cursor = context.getContentResolver()
        .query(Uri.parse("content://com.android.calendar/events"),
            new String[] { "calendar_id", "title", "description",
                "dtstart", "dtend", "eventLocation" }, null,
            null, null);
    cursor.moveToFirst();
    // fetching calendars name
    String CNames[] = new String[cursor.getCount()];

    // fetching calendars id
    nameOfEvent.clear();
    startDates.clear();
    endDates.clear();
    descriptions.clear();
    for (int i = 0; i < CNames.length; i++) {

      nameOfEvent.add(cursor.getString(1));
      startDates.add(getDate(Long.parseLong(cursor.getString(3))));
      endDates.add(getDate(Long.parseLong(cursor.getString(4))));
      descriptions.add(cursor.getString(2));
      CNames[i] = cursor.getString(1);
      cursor.moveToNext();

    }
    return nameOfEvent;
  }

  public static String getDate(long milliSeconds) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(milliSeconds);
    return formatter.format(calendar.getTime());
  }
}




Java Source Code List

com.examples.android.calendar.CalendarAdapter.java
com.examples.android.calendar.CalendarView.java
com.examples.android.calendar.Utility.java