예제 #1
0
 public String[] getTitlesByDistance(double lat, double lon) {
   double[] distances = new double[messages.size()];
   String[] titles = new String[distances.length];
   for (int i = 0; i < distances.length; i++) distances[i] = 0;
   Iterator<Long> keys = messages.keySet().iterator();
   while (keys.hasNext()) {
     MosaicMessage msg = messages.get(keys.next());
     double distance =
         distance(fromE6(msg.getLatitudeE6()), fromE6(msg.getLongitudeE6()), lat, lon);
     for (int i = 0; i < distances.length; i++) {
       if (distance < distances[i]) {
         int n = distances.length - 2;
         while (n >= i) {
           distances[n + 1] = distances[n];
           titles[n + 1] = titles[n];
           n--;
         }
         distances[i] = distance;
         titles[i] = msg.getTitle();
         break;
       } else if (i == (distances.length - 1)) {
         distances[i] = distance;
         titles[i] = msg.getTitle();
       }
     }
   }
   return titles;
 }
예제 #2
0
 @Override
 public void updateMessage(long id, String title, String body, int radius, long expiry)
     throws RemoteException {
   MosaicMessage message = messages.get((Long) id);
   message.setTitle(title);
   message.setBody(body);
   message.setRadius(radius);
   message.setExpiry(expiry);
   new UpdateMessageTask(MosaicService.this, message).execute();
 }
예제 #3
0
 @Override
 public void insertMessage(
     String title, String body, int latE6, int lonE6, int radius, long expiry)
     throws RemoteException {
   MosaicMessage message = new MosaicMessage();
   message.setTitle(title);
   message.setBody(body);
   message.setLatitudeE6(latE6);
   message.setLongitudeE6(lonE6);
   message.setRadius(radius);
   message.setCreated(System.currentTimeMillis());
   message.setUserId(mosaicUser.getId());
   new InsertMessageTask(MosaicService.this, message).execute();
 }
예제 #4
0
 protected void updateMessage(MosaicMessage message) {
   messages.put(message.getId(), message);
   if (iMain != null) {
     try {
       iMain.addMessage(
           message.getId(),
           fromE6(message.getLatitudeE6()),
           fromE6(message.getLongitudeE6()),
           message.getRadius(),
           message.getTitle(),
           message.getBody(),
           message.getUser().getNickname());
     } catch (RemoteException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
 }
예제 #5
0
 @Override
 public void getMessage(long id) throws RemoteException {
   if (messages.containsKey((Long) id)) {
     MosaicMessage message = messages.get((Long) id);
     new ViewMessageTask(MosaicService.this, id).execute();
     if (message.getUserId().equals(mosaicUser.getId()))
       iMain.editMessage(
           message.getId(),
           message.getTitle(),
           message.getBody(),
           message.getRadius(),
           message.getExpiry());
     else
       iMain.viewMessage(
           message.getId(),
           message.getTitle(),
           message.getBody(),
           message.getUser().getNickname());
   } else {
     // TODO error
   }
 }
예제 #6
0
 protected void setMessages(List<MosaicMessage> msgs) {
   if (msgs != null) {
     ArrayList<Long> newIds = new ArrayList<Long>();
     for (MosaicMessage msg : msgs) {
       if (iMain != null) {
         try {
           if (messages.containsKey(msg.getId())
               && (messages.get(msg.getId()).getRadius() == msg.getRadius()))
             iMain.addMessage(
                 msg.getId(),
                 fromE6(msg.getLatitudeE6()),
                 fromE6(msg.getLongitudeE6()),
                 Mosaic.RADIUS_UNCHANGED,
                 msg.getTitle(),
                 msg.getBody(),
                 msg.getUser().getNickname());
           else
             iMain.addMessage(
                 msg.getId(),
                 fromE6(msg.getLatitudeE6()),
                 fromE6(msg.getLongitudeE6()),
                 msg.getRadius(),
                 msg.getTitle(),
                 msg.getBody(),
                 msg.getUser().getNickname());
         } catch (RemoteException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
         }
       }
       messages.put(msg.getId(), msg);
       newIds.add(msg.getId());
     }
     ArrayList<Long> removalIds = new ArrayList<Long>();
     for (Long id : messages.keySet()) {
       if (!newIds.contains(id)) removalIds.add(id);
     }
     for (Long id : removalIds) {
       messages.remove(id);
       if (iMain != null) {
         try {
           iMain.removeMarker(id);
         } catch (RemoteException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
         }
       }
     }
   } else {
     messages.clear();
     if (iMain != null) {
       try {
         iMain.clearMessages();
       } catch (RemoteException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       }
     }
   }
 }