Trying to make Calendar work w/o Google

10 views
Skip to first unread message

Jean-Baptiste Queru

unread,
Oct 19, 2009, 5:43:39 PM10/19/09
to android-...@googlegroups.com
All right, I'm trying to make the AOSP calendar work when the Google
proprietary components aren't there (which is the case in AOSP
builds).

First symptom: calendar exits right away.

I did a quick search for google in the calendar source tree:
find src/ -type f | xargs grep -i google
and found that the interesting stuff lives in LaunchActivity:
http://android.git.kernel.org/?p=platform/packages/apps/Calendar.git;a=blob;f=src/com/android/calendar/LaunchActivity.java;h=1f053d76f73e773389e0839281a59ebd3b6960a2;hb=HEAD
(Check the call to finish() on line 107).

Amusingly, in the call to onAccountsLoaded() on line 103, the accounts
parameter doesn't matter (it's ignored), which means that at that
point Calendar only wants to know that there's an account available
(the details of the account don't matter yet).

Going at it with a big hammer, I locally replaced the call to finish()
by onAccountsLoaded(null). Victory, this is enough to get to the
calendar view.

Second symptom: can't create an entry, "You have no calendars" dialog.

I found the resource in question with
find res/ -type f | xargs grep "You have no calendars"
and tracked it down into the code with
find src/ -type f | xargs grep no_calendars_found
which leads to line 450 of EditEvent
http://android.git.kernel.org/?p=platform/packages/apps/Calendar.git;a=blob;f=src/com/android/calendar/EditEvent.java;h=ce545fa437950bf5c595e031f09b6ad6bf3e422e;hb=HEAD#l450

At this point, it looks like the app is happy to display an "empty"
calendar (probably since the query returns no events), but can't
create any new event (since it has no calendar to create into).

I'd guess that the best approach to resolve this would be to detect
(in LaunchActivity?) that there's no account, therefore no calendar,
and to create a default calendar, or something like that.

Ideas, anyone?

JBQ

--
Jean-Baptiste M. "JBQ" Queru
Software Engineer, Android Open-Source Project, Google.

Questions sent directly to me that have no reason for being private
will likely get ignored or forwarded to a public forum with no further
warning.

Vladimir

unread,
Oct 20, 2009, 4:21:43 AM10/20/09
to android-platform
I think we can (instead of finish() on line 107) insert something like
that:

String defaultCalendar = "Default";
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(Calendars.CONTENT_URI,
ACCOUNTS_PROJECTION,
null, null, Calendars.DEFAULT_SORT_ORDER);
if (cursor == null) {
finish;
} else {
if (cursor.getCount() == 0) {
addCalendar(defaultCalendar);
}
cursor.close();
}
onAccountsLoaded(defaultCalendar);

and add private addDefaultCalendar() function:

private int addDefaultCalendar(final String account) {
final ContentValues cvCal = new ContentValues();

cvCal.put(Calendars.NAME, account);
cvCal.put(Calendars.DISPLAY_NAME, account);
cvCal.put(Calendars.HIDDEN, 0);
cvCal.put(Calendars.COLOR, -14069085);
cvCal.put(Calendars.ACCESS_LEVEL, Integer.toString
(Calendars.OWNER_ACCESS));
cvCal.put(Calendars.SELECTED, 1);
cvCal.put(Calendars.SYNC_EVENTS, 1);
cvCal.put(Calendars.TIMEZONE, TimeZone.getDefault().getID());

final Uri newCalendarUri = getContentResolver().insert
(Calendars.CONTENT_URI, cvCal);
if (newCalendarUri == null) {
return 0;
}
return Integer.parseInt(newCalendarUri.getLastPathSegment());
}

It works fine for me.

BR,
Vladimir


On Oct 20, 1:43 am, Jean-Baptiste Queru <j...@android.com> wrote:
> All right, I'm trying to make the AOSP calendar work when the Google
> proprietary components aren't there (which is the case in AOSP
> builds).
>
> First symptom: calendar exits right away.
>
> I did a quick search for google in the calendar source tree:
> find src/ -type f | xargs grep -i google
> and found that the interesting stuff lives in LaunchActivity:http://android.git.kernel.org/?p=platform/packages/apps/Calendar.git;...
> (Check the call to finish() on line 107).
>
> Amusingly, in the call to onAccountsLoaded() on line 103, the accounts
> parameter doesn't matter (it's ignored), which means that at that
> point Calendar only wants to know that there's an account available
> (the details of the account don't matter yet).
>
> Going at it with a big hammer, I locally replaced the call to finish()
> by onAccountsLoaded(null). Victory, this is enough to get to the
> calendar view.
>
> Second symptom: can't create an entry, "You have no calendars" dialog.
>
> I found the resource in question with
> find res/ -type f | xargs grep "You have no calendars"
> and tracked it down into the code with
> find src/ -type f | xargs grep no_calendars_found
> which leads to line 450 of EditEventhttp://android.git.kernel.org/?p=platform/packages/apps/Calendar.git;...

Jean-Baptiste Queru

unread,
Oct 20, 2009, 9:00:21 AM10/20/09
to android-...@googlegroups.com
Cool, we're getting somewhere.

I think that we need to be a bit more refined, because I guess that
this code path is also used in the situation where a Google account
hasn't been set up yet and the user declines to set one up (but might
set one up later), i.e. we might need to distinguish between the case
where GoogleLoginService is present but the user cancels and the case
where GoogleLoginService is missing.

Is there any chance that you could just stick that change in a file
somewhere and upload it to the review server (I don't care if it
doesn't compile, and I'll take it from there, but I need the legal
safeguards set by the review process)

JBQ

Michael Trimarchi

unread,
Oct 20, 2009, 12:38:43 PM10/20/09
to android-...@googlegroups.com
Vladimir wrote:
> I think we can (instead of finish() on line 107) insert something like
> that:
>
> String defaultCalendar = "Default";
> ContentResolver cr = getContentResolver();
> Cursor cursor = cr.query(Calendars.CONTENT_URI,
> ACCOUNTS_PROJECTION,
> null, null, Calendars.DEFAULT_SORT_ORDER);
> if (cursor == null) {
> finish;
> } else {
> if (cursor.getCount() == 0) {
> addCalendar(defaultCalendar);
>
Sorry but where is defined the addCalendar function?
Michael

Jean-Baptiste Queru

unread,
Oct 20, 2009, 12:56:36 PM10/20/09
to android-...@googlegroups.com
It's there in Vladimir's email, just with the wrong name.

JBQ

Michael Trimarchi

unread,
Oct 20, 2009, 12:57:57 PM10/20/09
to android-...@googlegroups.com
Hi,

Jean-Baptiste Queru wrote:
> It's there in Vladimir's email, just with the wrong name.
>
> JBQ
>
> On Tue, Oct 20, 2009 at 9:38 AM, Michael Trimarchi
> <trim...@gandalf.sssup.it> wrote:
>
>> Vladimir wrote:
>>
>>> I think we can (instead of finish() on line 107) insert something like
>>> that:
>>>
>>> String defaultCalendar = "Default";
>>> ContentResolver cr = getContentResolver();
>>> Cursor cursor = cr.query(Calendars.CONTENT_URI,
>>> ACCOUNTS_PROJECTION,
>>> null, null, Calendars.DEFAULT_SORT_ORDER);
>>> if (cursor == null) {
>>> finish;
>>> } else {
>>> if (cursor.getCount() == 0) {
>>> addCalendar(defaultCalendar);
>>>
>>>
>> Sorry but where is defined the addCalendar function?
>> Michael
>>
>>
>
>
>

Sorry I didn't see the other peace of code. You are right

Thanks

Michael Trimarchi

unread,
Oct 20, 2009, 1:33:09 PM10/20/09
to android-...@googlegroups.com
Hi,


I tested it on the freerunnner and the calendar is show

Michael

calendar.patch

Jean-Baptiste Queru

unread,
Oct 20, 2009, 2:05:39 PM10/20/09
to android-...@googlegroups.com
I'd really really like to take those changes in, but I can't do it
without a contributor agreement. Please upload it through the regular
review system, as described at http://source.android.com/

Thanks thanks thanks,
JBQ

Michael Trimarchi

unread,
Oct 21, 2009, 7:08:00 AM10/21/09
to android-...@googlegroups.com
Jean-Baptiste Queru wrote:
> I'd really really like to take those changes in, but I can't do it
> without a contributor agreement. Please upload it through the regular
> review system, as described at http://source.android.com/
>
> Thanks thanks thanks,
> JBQ
>
Ok,I will try :)

Michael

Reply all
Reply to author
Forward
0 new messages