コード例 #1
0
 public void fetch() {
   ChumbyLog.i(TAG + ".fetch()");
   if (!XAPI.hasNetwork()) {
     ChumbyLog.i(TAG + ".fetch(): no network, skipping");
   }
   String[] pathItems = {"notify", "list"};
   Properties params = new Properties();
   if (lastTimeStamp != null) {
     // ChumbyLog.i(TAG+".fetch(): sending timeStamp "+lastTimeStamp);
     params.put("timestamp", lastTimeStamp);
   }
   Handler xmlHandler =
       new Handler() {
         public void handleMessage(Message message) {
           // ChumbyLog.i("NotificationEvents(): "+message);
           switch (message.what) {
             case XMLHelper.DID_SUCCEED:
               {
                 Document document = (Document) message.obj;
                 parseResponse(document);
                 break;
               }
             case XMLHelper.DID_ERROR:
               {
                 Exception e = (Exception) message.obj;
                 e.printStackTrace();
                 break;
               }
           }
         }
       };
   XAPI.request(pathItems, params, XAPI.GET, true, xmlHandler);
 }
コード例 #2
0
 private void parseResponse(Document document) {
   // ChumbyLog.i(TAG+".parseResponse()");
   // ChumbyLog.i(XMLHelper.nodeToString(document));
   Element notificationsNode = XMLUtil.firstChildOfType(document, "notifications");
   if (notificationsNode != null) {
     lastTimeStamp = notificationsNode.getAttribute("timestamp");
     // ChumbyLog.i(TAG+".parseResponse(): new lastTimeStamp: "+lastTimeStamp);
     ArrayList<Element> notificationNodes =
         XMLUtil.childrenOfType(notificationsNode, "notification");
     for (int i = 0; i < notificationNodes.size(); i++) {
       Element notificationNode = notificationNodes.get(i);
       NotificationType type = NotificationType.parse(notificationNode.getAttribute("type"));
       ChumbyLog.i(TAG + ".parseResponse(): processing notification " + type.toString());
       if (type == NotificationType.PROFILE) {
         ChannelNotification notification = new ChannelNotification();
         notification.parse(notificationNode);
         NotificationAction action = notification.action;
         if (action == NotificationAction.CREATE) {
           dispatchEvent(new Event(PROFILE_CREATED, notification));
         } else if (action == NotificationAction.DELETE) {
           dispatchEvent(new Event(PROFILE_DELETED, notification));
         } else if (action == NotificationAction.UPDATE) {
           dispatchEvent(new Event(PROFILE_UPDATED, notification));
         } else {
           ChumbyLog.w(
               TAG
                   + ".parseResponse() unknown action "
                   + action.toString()
                   + " for "
                   + type.toString());
         }
       } else if (type == NotificationType.CHUM) {
         ChumNotification notification = new ChumNotification();
         notification.parse(notificationNode);
         NotificationAction action = notification.action;
         if (action == NotificationAction.CREATE) {
           dispatchEvent(new Event(CHUM_CREATED, notification));
         } else if (action == NotificationAction.DELETE) {
           dispatchEvent(new Event(CHUM_DELETED, notification));
         } else if (action == NotificationAction.UPDATE) {
           dispatchEvent(new Event(CHUM_UPDATED, notification));
         } else {
           ChumbyLog.w(
               TAG
                   + ".parseResponse() unknown action "
                   + action.toString()
                   + " for "
                   + type.toString());
         }
       } else if (type == NotificationType.DEVICE) {
         DeviceNotification notification = new DeviceNotification();
         notification.parse(notificationNode);
         NotificationAction action = notification.action;
         if (notification.id.equals(Chumby.getInstance().guid)) {
           if (action == NotificationAction.CREATE) {
             dispatchEvent(new Event(DEVICE_CREATED, notification));
           } else if (action == NotificationAction.DELETE) {
             dispatchEvent(new Event(DEVICE_DELETED, notification));
           } else if (action == NotificationAction.UPDATE) {
             dispatchEvent(new Event(DEVICE_UPDATED, notification));
           } else {
             ChumbyLog.w(
                 TAG
                     + ".parseResponse() unknown action "
                     + action.toString()
                     + " for "
                     + type.toString());
           }
         } else {
           ChumbyLog.w(TAG + ".parseResponse(): device id mismatch:" + notification.id);
         }
       } else if (type == NotificationType.MESSAGE) {
         MessageNotification notification = new MessageNotification();
         notification.parse(notificationNode);
         NotificationAction action = notification.action;
         if (action == NotificationAction.CREATE) {
           dispatchEvent(new Event(MESSAGE_CREATED, notification));
         } else if (action == NotificationAction.DELETE) {
           dispatchEvent(new Event(MESSAGE_DELETED, notification));
         } else {
           ChumbyLog.w(
               TAG
                   + ".parseResponse() unknown action "
                   + action.toString()
                   + " for "
                   + type.toString());
         }
       } else if (type == NotificationType.WIDGET_INSTANCE) {
         WidgetNotification notification = new WidgetNotification();
         notification.parse(notificationNode);
         NotificationAction action = notification.action;
         if (action == NotificationAction.CREATE) {
           dispatchEvent(new Event(WIDGET_CREATED, notification));
         } else if (action == NotificationAction.DELETE) {
           dispatchEvent(new Event(WIDGET_DELETED, notification));
         } else if (action == NotificationAction.UPDATE) {
           dispatchEvent(new Event(WIDGET_UPDATED, notification));
         } else {
           ChumbyLog.w(
               TAG
                   + ".parseResponse() unknown action "
                   + action.toString()
                   + " for "
                   + type.toString());
         }
       } else {
         ChumbyLog.w("NotificationEvents.parseResponse(): unhandled type " + type.toString());
       }
     }
   }
 }