distriqt / airnativeextensions

DEPRECATED: Original repository of the distriqt native extensions and is no longer maintained. Please see our site for the latest ANEs
https://airnativeextensions.com
2 stars 0 forks source link

Unable to get calendar extension to run off a View #291

Closed aaharoni closed 8 years ago

aaharoni commented 9 years ago

Hi, I've added the calendar ANE into a simple application with 1 view and tried to get it running on my Galaxy Note 3. Basically I took your sample app that seems to work as is and added it to a view based app. But when I click on the "request access" button (see below) the whole thing just freezes. Does the ANE not work in View based apps?

I am running android v4.4.2 here is the view: <?xml version="1.0" encoding="utf-8"?> <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" title="Calendar View">

  <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
  </fx:Declarations>

  <fx:Script>
        <![CDATA[
               import com.distriqt.extension.calendar.Calendar;
               import com.distriqt.extension.calendar.Recurrence;
               import com.distriqt.extension.calendar.events.CalendarStatusEvent;
               import com.distriqt.extension.calendar.objects.CalendarObject;
               import com.distriqt.extension.calendar.objects.EventAlarmObject;
               import com.distriqt.extension.calendar.objects.EventObject;

               import mx.events.FlexEvent;

               private function init( ):void
               {
                      try
                      {
                            Calendar.init( "I DID cut and paste my developer key here :-) ");

                            Calendar.service.addEventListener( CalendarStatusEvent.ACCESS_GRANTED, calendar_accessGrantedHandler, false, 0, true );
                            Calendar.service.addEventListener( CalendarStatusEvent.ACCESS_DENIED,  calendar_accessDeniedHandler, false, 0, true );

                             Calendar.service.addEventListener( CalendarStatusEvent.UI_SAVE,    calendar_uiHandler, false, 0, true );
                            Calendar.service.addEventListener( CalendarStatusEvent.UI_CANCEL,  calendar_uiHandler, false, 0, true );
                            Calendar.service.addEventListener( CalendarStatusEvent.UI_DELETE,  calendar_uiHandler, false, 0, true );

                            message("Calendar supported: "+String(Calendar.isSupported));
                            message("Service version: "+Calendar.service.version);

                      }
                      catch (e:Error)
                      {
                            message(e.message);
                      }
               }

               private function calendar_accessDeniedHandler( event:CalendarStatusEvent ):void
               {
                      message( "DENIED" );

                      //
                      //     See what happens if you add an event with a denied calendar access under iOS
                      //     You should see a message along the lines of "This app does not have access to your calendars"
                      //     and the user will be forced to press "Cancel"
               }

               private function calendar_uiHandler( event:CalendarStatusEvent ):void
               {
                      switch (event.type)
                      {
                            //                         case CalendarStatusEvent.UI_SAVE:
                            //                         case CalendarStatusEvent.UI_CANCEL:
                            //                         case CalendarStatusEvent.UI_DELETE:
                            //                               break;

                            default:
                                   message( event.type );
                      }
               }

               private function calendar_accessGrantedHandler( event:CalendarStatusEvent ):void
               {
                      message( "GRANTED" );
                      TestCalendar();                         

               }

               private function TestCalendar():void {
                      var calendarId:String = "";
                      var calendars:Array = Calendar.service.getCalendars();

                      for each (var cal:CalendarObject in calendars)
                      {

                      if (cal.displayName.toLowerCase() == "test")
                      {
                            calendarId = cal.id;
                            message( "USING : "+calendarId );
                      }
               } 

                      //
                      //     CREATE AN EVENT
                      var e:EventObject = new EventObject();
                      e.title = "Test title now";
                      e.startDate = new Date() ;
                      e.endDate = new Date();
                      e.startDate.minutes = e.startDate.minutes + 6;
                      e.endDate.hours = e.endDate.hours+1;
                      //                  e.allDay = true;
                      //                  e.calendarId = calendarId;

                      var a:EventAlarmObject = new EventAlarmObject();
                      a.offset = -1;
                      e.alarms.push( a );

                      //                  var r:Recurrence = new Recurrence();
                      //                  r.endCount = 5;
                      //                  r.interval = 1;
                      //                  r.frequency = Recurrence.FREQUENCY_DAILY;
                      //                  
                      //                  e.recurrenceRules.push( r );

                      //
                      //     ADD EVENT
                      message( "ADDING: "+e.startDateString + " :: " + e.title );
                      Calendar.service.addEventWithUI( e );
                      //                  Calendar.service.addEvent( e );

                      //
                      //     GET EVENTS
                      var startDate:Date = new Date();
                      startDate.date -= 1;
                      var endDate:Date = new Date();
                      endDate.date += 1;

                      var events:Array = Calendar.service.getEvents( startDate, endDate  );

                      for each (var evt:EventObject in events)
                      {

                            message( "["+evt.id+"] in "+evt.calendarId+" @ "+ evt.startDateString + " :: " + evt.title );

                            for each (var alarm:EventAlarmObject in evt.alarms)
                            {
                                   //                               message( "\tALARM: "+alarm.offset );
                            }
                            for each (var rule:Recurrence in evt.recurrenceRules)
                            {
                                   //                               message( "\tRRULE: "+rule.notes );
                            }

                            if (evt.title == "Test title now")
                            {
                                   message( "REMOVING" );
                                   Calendar.service.removeEvent( evt );
                            }
                      }
               }

               private function message(st:String):void {

                      trace(st);
                      log.text += "\n"+st;
               }

               protected function btnAccess_clickHandler(event:MouseEvent):void
               {
                      init();                          
               }

               protected function btnCalendar_clickHandler(event:MouseEvent):void
               {
                      Calendar.service.requestAccess();
               }

        ]]>
  </fx:Script>

  <s:VGroup width="100%" height="100%">

        <s:Button id="btnAccess" width="100%" label="Click to request access" click="btnAccess_clickHandler(event)"/>
        <s:Button id="btnCalendar"  width="100%" label="Click to set a meeting" click="btnCalendar_clickHandler(event)" />
        <s:TextArea id="log" width="100%" height="100%" />          
  </s:VGroup>

/s:View

marchbold commented 9 years ago

Hi, There's no reason it shouldn't work in a Flex application.

Can you post the device logs when you experience the freeze?

adb logcat

Also have you correctly added the activity to your manifest additions?

<android>
    <manifestAdditions><![CDATA[
        <manifest android:installLocation="auto">
            <uses-permission android:name="android.permission.INTERNET"/>
            <uses-permission android:name="android.permission.READ_CALENDAR"/>
            <uses-permission android:name="android.permission.WRITE_CALENDAR"/>
            <application>
                <activity android:name="com.distriqt.extension.calendar.activities.CalendarAddEventWithUIActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"></activity>
            </application>
        </manifest>
    ]]></manifestAdditions>
</android>
aaharoni commented 9 years ago

Hi,

Did you get a chance to look into this? Can you send me a sample view based app that contains a working version of the extension. I need to know if this works or not.

Thanks,

Avinoam.

מאת: Michael [mailto:notifications@github.com] נשלח: יום ב 17 נובמבר 2014 06:48 אל: distriqt/airnativeextensions עותק: aaharoni נושא: Re: [airnativeextensions] Unable to get calendar extension to run off a View (#291)

Hi, There's no reason it shouldn't work in a Flex application.

Can you post the device logs when you experience the freeze?

adb logcat

— Reply to this email directly or view it on GitHub https://github.com/distriqt/airnativeextensions/issues/291#issuecomment-63259411 . https://github.com/notifications/beacon/ABnjVTaGTaAUi-pPkM3k8DV5D86QT6Krks5nOXVogaJpZM4C8NWe.gif

marchbold commented 9 years ago

See questions above?

aaharoni commented 9 years ago

Unfortunately no. The device is not connected to the computer so I can't debug it on the device. But if you can send me a simple view based project that runs on your phone then that would help a lot. Thanks.

מאת: Michael [mailto:notifications@github.com] נשלח: יום ג 18 נובמבר 2014 01:19 אל: distriqt/airnativeextensions עותק: aaharoni נושא: Re: [airnativeextensions] Unable to get calendar extension to run off a View (#291)

See questions above?

— Reply to this email directly or view it on GitHub https://github.com/distriqt/airnativeextensions/issues/291#issuecomment-63395468 . https://github.com/notifications/beacon/ABnjVb4lXiopgAvQIOMxzGK11dn2D9WSks5nOnoBgaJpZM4C8NWe.gif

marchbold commented 9 years ago

What about the manifest additions?

aaharoni commented 9 years ago

Of course i have added. On Nov 18, 2014 3:31 AM, "Michael" notifications@github.com wrote:

What about the manifest additions?

Reply to this email directly or view it on GitHub https://github.com/distriqt/airnativeextensions/issues/291#issuecomment-63408459 .

aaharoni commented 9 years ago

Hello Michael,

Everything is fine now. It works. Can't really say what was the problem. I started a new project and it just workd. So thanks :-)

3 more questions:

  1. When I create a new event with UI, Android displays a list of calendars that I can select from. However - unlike in other applications where I have an option to use the selected application once or always, here I have to select one every time. Can this be solved?
  2. What do I need to do in order to just bring up the calendar in the default calendar view and not in creating a new event?
  3. How can I detect that the calendar has been closed and my application regains focus?

Thanks,

Avi

מאת: Michael [mailto:notifications@github.com] נשלח: יום ג 18 נובמבר 2014 03:31 אל: distriqt/airnativeextensions עותק: aaharoni נושא: Re: [airnativeextensions] Unable to get calendar extension to run off a View (#291)

What about the manifest additions?

— Reply to this email directly or view it on GitHub https://github.com/distriqt/airnativeextensions/issues/291#issuecomment-63408459 . https://github.com/notifications/beacon/ABnjVQN1238BqhrJmNZVLxQrHtFM14uZks5nOpjhgaJpZM4C8NWe.gif