Android Open Source - sms-backup-plus Calendar Accessor Pre40






From Project

Back to project page sms-backup-plus.

License

The source code is released under:

Apache License

If you think the Android project sms-backup-plus 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) 2010 Jan Berkel <jan.berkel@gmail.com>
 *// w  w w . j a va  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.zegoggles.smssync.calendar;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.util.Log;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

import static com.zegoggles.smssync.App.LOCAL_LOGV;
import static com.zegoggles.smssync.App.TAG;

public class CalendarAccessorPre40 implements CalendarAccessor {
    private static final Uri CALENDAR_URI = Uri.parse("content://calendar");
    private static final Uri CALENDAR_URI_2_2 = Uri.parse("content://com.android.calendar");
    private static final Uri CALENDAR;

    private ContentResolver resolver;

    public CalendarAccessorPre40(ContentResolver resolver) {
        this.resolver = resolver;
    }

    static {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
            CALENDAR = CALENDAR_URI_2_2;
        } else {
            CALENDAR = CALENDAR_URI;
        }
    }

    /**
     * @noinspection UnusedDeclaration
     */
    interface Consts {
        String TITLE = "title";
        String DESCRIPTION = "description";
        String CALENDAR_ID = "calendar_id";

        String HAS_ALARM = "hasAlarm";

        String VISIBILITY = "visibility";
        int VISIBILITY_DEFAULT = 0;
        int VISIBILITY_CONFIDENTIAL = 1;
        int VISIBILITY_PRIVATE = 2;
        int VISIBILITY_PUBLIC = 3;

        String TRANSPARENCY = "transparency";
        int TRANSPARENCY_OPAQUE = 0;
        int TRANSPARENCY_TRANSPARENT = 1;

        String ALL_DAY = "allDay";
        /* Type: INTEGER (long; millis since epoch) */
        String DTSTART = "dtstart";
        /* Type: INTEGER (long; millis since epoch) */
        String DTEND = "dtend";
        /* Type: TEXT (duration in RFC2445 format) */
        String DURATION = "duration";

        String STATUS = "eventStatus";
        int STATUS_TENTATIVE = 0;
        int STATUS_CONFIRMED = 1;
        int STATUS_CANCELED = 2;
    }

    @Override public boolean enableSync(long calendarId) {
        return false;
    }

    public boolean addEntry(long calendarId, Date when, int duration,
                            String title, String description) {
        if (LOCAL_LOGV) {
            Log.v(TAG, String.format("addEntry(%d, %s, %d, %s, %s)",
                    calendarId, when.toString(), duration, title, description));
        }

        final ContentValues contentValues = new ContentValues();
        contentValues.put(Consts.TITLE, title);
        contentValues.put(Consts.DESCRIPTION, description);
        contentValues.put(Consts.DTSTART, when.getTime());
        contentValues.put(Consts.DTEND, when.getTime() + duration * 1000);
        contentValues.put(Consts.VISIBILITY, Consts.VISIBILITY_DEFAULT);
        contentValues.put(Consts.STATUS, Consts.STATUS_CONFIRMED);
        contentValues.put(Consts.CALENDAR_ID, calendarId);

        try {
            resolver.insert(Uri.withAppendedPath(CALENDAR, "events"), contentValues);
            return true;
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "could not add calendar entry", e);
            return false;
        }
    }

    public Map<String, String> getCalendars() {
        final Map<String, String> map = new LinkedHashMap<String, String>();

        Cursor cursor = null;
        try {
            cursor = resolver.query(Uri.withAppendedPath(CALENDAR, "calendars"),
                    new String[]{"_id", "displayname"},
                    null, null, "displayname ASC");

            while (cursor != null && cursor.moveToNext()) {
                map.put(cursor.getString(0), cursor.getString(1));
            }
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "calendars not available", e);
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
        return map;
    }
}




Java Source Code List

com.zegoggles.smssync.App.java
com.zegoggles.smssync.Consts.java
com.zegoggles.smssync.MmsConsts.java
com.zegoggles.smssync.SmsConsts.java
com.zegoggles.smssync.activity.Dialogs.java
com.zegoggles.smssync.activity.MainActivity.java
com.zegoggles.smssync.activity.StatusPreference.java
com.zegoggles.smssync.activity.auth.AccountManagerAuthActivity.java
com.zegoggles.smssync.activity.auth.WebAuthActivity.java
com.zegoggles.smssync.activity.donation.DonationActivity.java
com.zegoggles.smssync.auth.TokenRefreshException.java
com.zegoggles.smssync.auth.TokenRefresher.java
com.zegoggles.smssync.auth.XOAuthConsumer.java
com.zegoggles.smssync.calendar.CalendarAccessorPost40.java
com.zegoggles.smssync.calendar.CalendarAccessorPre40.java
com.zegoggles.smssync.calendar.CalendarAccessor.java
com.zegoggles.smssync.compat.ComposeSmsActivity.java
com.zegoggles.smssync.compat.HeadlessSmsSendService.java
com.zegoggles.smssync.compat.MmsReceiver.java
com.zegoggles.smssync.compat.SmsReceiver.java
com.zegoggles.smssync.compat.package-info.java
com.zegoggles.smssync.contacts.ContactAccessorPost20.java
com.zegoggles.smssync.contacts.ContactAccessorPre20.java
com.zegoggles.smssync.contacts.ContactAccessor.java
com.zegoggles.smssync.contacts.ContactGroupIds.java
com.zegoggles.smssync.contacts.ContactGroup.java
com.zegoggles.smssync.contacts.Group.java
com.zegoggles.smssync.mail.AllTrustedSocketFactory.java
com.zegoggles.smssync.mail.Attachment.java
com.zegoggles.smssync.mail.BackupImapStore.java
com.zegoggles.smssync.mail.BackupStoreConfig.java
com.zegoggles.smssync.mail.CallFormatter.java
com.zegoggles.smssync.mail.ConversionResult.java
com.zegoggles.smssync.mail.DataType.java
com.zegoggles.smssync.mail.HeaderGenerator.java
com.zegoggles.smssync.mail.Headers.java
com.zegoggles.smssync.mail.MessageConverter.java
com.zegoggles.smssync.mail.MessageGenerator.java
com.zegoggles.smssync.mail.MmsSupport.java
com.zegoggles.smssync.mail.PersonLookup.java
com.zegoggles.smssync.mail.PersonRecord.java
com.zegoggles.smssync.preferences.AddressStyle.java
com.zegoggles.smssync.preferences.AuthMode.java
com.zegoggles.smssync.preferences.AuthPreferences.java
com.zegoggles.smssync.preferences.BackupManagerWrapper.java
com.zegoggles.smssync.preferences.CalendarPreferences.java
com.zegoggles.smssync.preferences.CallLogTypes.java
com.zegoggles.smssync.preferences.Defaults.java
com.zegoggles.smssync.preferences.MarkAsReadTypes.java
com.zegoggles.smssync.preferences.PreferenceBackupAgent.java
com.zegoggles.smssync.preferences.Preferences.java
com.zegoggles.smssync.preferences.ServerPreferences.java
com.zegoggles.smssync.receiver.BackupBroadcastReceiver.java
com.zegoggles.smssync.receiver.SmsBroadcastReceiver.java
com.zegoggles.smssync.service.Alarms.java
com.zegoggles.smssync.service.BackupConfig.java
com.zegoggles.smssync.service.BackupCursors.java
com.zegoggles.smssync.service.BackupItemsFetcher.java
com.zegoggles.smssync.service.BackupQueryBuilder.java
com.zegoggles.smssync.service.BackupTask.java
com.zegoggles.smssync.service.BackupType.java
com.zegoggles.smssync.service.BulkFetcher.java
com.zegoggles.smssync.service.CalendarSyncer.java
com.zegoggles.smssync.service.RestoreConfig.java
com.zegoggles.smssync.service.RestoreTask.java
com.zegoggles.smssync.service.ServiceBase.java
com.zegoggles.smssync.service.SmsBackupService.java
com.zegoggles.smssync.service.SmsRestoreService.java
com.zegoggles.smssync.service.UserCanceled.java
com.zegoggles.smssync.service.WhatsAppItemsFetcher.java
com.zegoggles.smssync.service.exception.BackupDisabledException.java
com.zegoggles.smssync.service.exception.ConnectivityException.java
com.zegoggles.smssync.service.exception.LocalizableException.java
com.zegoggles.smssync.service.exception.NoConnectionException.java
com.zegoggles.smssync.service.exception.RequiresBackgroundDataException.java
com.zegoggles.smssync.service.exception.RequiresLoginException.java
com.zegoggles.smssync.service.exception.RequiresWifiException.java
com.zegoggles.smssync.service.exception.SmsProviderNotWritableException.java
com.zegoggles.smssync.service.state.BackupState.java
com.zegoggles.smssync.service.state.RestoreState.java
com.zegoggles.smssync.service.state.SmsSyncState.java
com.zegoggles.smssync.service.state.State.java
com.zegoggles.smssync.tasks.OAuthCallbackTask.java
com.zegoggles.smssync.tasks.RequestTokenTask.java
com.zegoggles.smssync.utils.AppLog.java
com.zegoggles.smssync.utils.ListPreferenceHelper.java
com.zegoggles.smssync.utils.Sanitizer.java
com.zegoggles.smssync.utils.ThreadHelper.java