コード例 #1
0
  private boolean somethingNew(NearbyPlayer nearbyPlayer) {

    if (lastNotification != null) {
      if (lastNotification.equals(nearbyPlayer)) {
        if (lastNotification.getLocation().equals(nearbyPlayer.getLocation())) {
          return false;
        }
      }
    }

    return true;
  }
コード例 #2
0
  public void nearestPlayer(NearbyPlayer nearbyPlayer) {

    if (nearbyPlayer.getRank() > max_ranking_for_notification) {

      notificationManager.cancelAll();
      if (nearbyPlayer.getRank() < max_ranking_for_vibration) {
        return;
      }
    }

    if (somethingNew(nearbyPlayer)) {
      sendNotification(nearbyPlayer);

      if (nearbyPlayer.getRank() < max_ranking_for_vibration) {
        long[] pattern = {0, 300, 0, 300};
        vibrator.vibrate(pattern, -1);
      }
    }
  }
コード例 #3
0
  private void sendNotification(NearbyPlayer nearbyPlayer) {

    Intent intent = new Intent(context, actionToNotificate);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pIntent =
        PendingIntent.getActivity(context, 2, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Builder builder = new Builder(context);

    switch (nearbyPlayer.getFaction()) {
      case blue:
        builder.setSmallIcon(R.drawable.blue_small);
        break;
      case green:
        builder.setSmallIcon(R.drawable.green_small);
        break;
    }

    builder.setContentIntent(pIntent);
    builder.setContentTitle(nearbyPlayer.getName());
    builder.setContentInfo(
        nearbyPlayer.getHumanReadableDistance()
            + " "
            + nearbyPlayer.getDirection()
            + " "
            + nearbyPlayer.getHumanReadableTime()
            + " ago on "
            + nearbyPlayer.getLocation());

    Notification noti = builder.build();
    noti.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, noti);

    this.lastNotification = nearbyPlayer;
  }