コード例 #1
0
ファイル: MosaicService.java プロジェクト: piusvelte/Mosaic
 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
ファイル: MosaicService.java プロジェクト: piusvelte/Mosaic
 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();
       }
     }
   }
 }
コード例 #3
0
ファイル: MosaicService.java プロジェクト: piusvelte/Mosaic
 @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
   }
 }
コード例 #4
0
ファイル: MosaicService.java プロジェクト: piusvelte/Mosaic
 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();
     }
   }
 }