Exemplo n.º 1
0
  public static String GetSpeedDisplay(Context context, double metersPerSecond, boolean imperial) {

    DecimalFormat df = new DecimalFormat("#.###");
    String result = df.format(metersPerSecond) + context.getString(R.string.meters_per_second);

    if (imperial) {
      result = df.format(metersPerSecond * 2.23693629) + context.getString(R.string.miles_per_hour);
    } else if (metersPerSecond >= 0.28) {
      result = df.format(metersPerSecond * 3.6) + context.getString(R.string.kilometers_per_hour);
    }

    return result;
  }
Exemplo n.º 2
0
  public static String GetTimeDisplay(Context context, long milliseconds) {

    double ms = (double) milliseconds;
    DecimalFormat df = new DecimalFormat("#.##");

    String result = df.format(ms / 1000) + context.getString(R.string.seconds);

    if (ms > 3600000) {
      result = df.format(ms / 3600000) + context.getString(R.string.hours);
    } else if (ms > 60000) {
      result = df.format(ms / 60000) + context.getString(R.string.minutes);
    }

    return result;
  }
Exemplo n.º 3
0
  public static String GetDistanceDisplay(Context context, double meters, boolean imperial) {
    DecimalFormat df = new DecimalFormat("#.###");
    String result = df.format(meters) + context.getString(R.string.meters);

    if (imperial) {
      if (meters <= 804) {
        result = df.format(meters * 3.2808399) + context.getString(R.string.feet);
      } else {
        result = df.format(meters / 1609.344) + context.getString(R.string.miles);
      }
    } else if (meters >= 1000) {
      result = df.format(meters / 1000) + context.getString(R.string.kilometers);
    }

    return result;
  }
Exemplo n.º 4
0
  /**
   * Converts given bearing degrees into a rough cardinal direction that's more understandable to
   * humans.
   *
   * @param bearingDegrees
   * @return
   */
  public static String GetBearingDescription(float bearingDegrees, Context context) {

    String direction;
    String cardinal;

    if (bearingDegrees > 348.75 || bearingDegrees <= 11.25) {
      cardinal = context.getString(R.string.direction_north);
    } else if (bearingDegrees > 11.25 && bearingDegrees <= 33.75) {
      cardinal = context.getString(R.string.direction_northnortheast);
    } else if (bearingDegrees > 33.75 && bearingDegrees <= 56.25) {
      cardinal = context.getString(R.string.direction_northeast);
    } else if (bearingDegrees > 56.25 && bearingDegrees <= 78.75) {
      cardinal = context.getString(R.string.direction_eastnortheast);
    } else if (bearingDegrees > 78.75 && bearingDegrees <= 101.25) {
      cardinal = context.getString(R.string.direction_east);
    } else if (bearingDegrees > 101.25 && bearingDegrees <= 123.75) {
      cardinal = context.getString(R.string.direction_eastsoutheast);
    } else if (bearingDegrees > 123.75 && bearingDegrees <= 146.26) {
      cardinal = context.getString(R.string.direction_southeast);
    } else if (bearingDegrees > 146.25 && bearingDegrees <= 168.75) {
      cardinal = context.getString(R.string.direction_southsoutheast);
    } else if (bearingDegrees > 168.75 && bearingDegrees <= 191.25) {
      cardinal = context.getString(R.string.direction_south);
    } else if (bearingDegrees > 191.25 && bearingDegrees <= 213.75) {
      cardinal = context.getString(R.string.direction_southsouthwest);
    } else if (bearingDegrees > 213.75 && bearingDegrees <= 236.25) {
      cardinal = context.getString(R.string.direction_southwest);
    } else if (bearingDegrees > 236.25 && bearingDegrees <= 258.75) {
      cardinal = context.getString(R.string.direction_westsouthwest);
    } else if (bearingDegrees > 258.75 && bearingDegrees <= 281.25) {
      cardinal = context.getString(R.string.direction_west);
    } else if (bearingDegrees > 281.25 && bearingDegrees <= 303.75) {
      cardinal = context.getString(R.string.direction_westnorthwest);
    } else if (bearingDegrees > 303.75 && bearingDegrees <= 326.25) {
      cardinal = context.getString(R.string.direction_northwest);
    } else if (bearingDegrees > 326.25 && bearingDegrees <= 348.75) {
      cardinal = context.getString(R.string.direction_northnorthwest);
    } else {
      direction = context.getString(R.string.unknown_direction);
      return direction;
    }

    direction = context.getString(R.string.direction_roughly, cardinal);
    return direction;
  }
Exemplo n.º 5
0
  /**
   * Converts seconds into friendly, understandable description of time.
   *
   * @param numberOfSeconds
   * @return
   */
  public static String GetDescriptiveTimeString(int numberOfSeconds, Context context) {

    String descriptive;
    int hours;
    int minutes;
    int seconds;

    int remainingSeconds;

    // Special cases
    if (numberOfSeconds == 1) {
      return context.getString(R.string.time_onesecond);
    }

    if (numberOfSeconds == 30) {
      return context.getString(R.string.time_halfminute);
    }

    if (numberOfSeconds == 60) {
      return context.getString(R.string.time_oneminute);
    }

    if (numberOfSeconds == 900) {
      return context.getString(R.string.time_quarterhour);
    }

    if (numberOfSeconds == 1800) {
      return context.getString(R.string.time_halfhour);
    }

    if (numberOfSeconds == 3600) {
      return context.getString(R.string.time_onehour);
    }

    if (numberOfSeconds == 4800) {
      return context.getString(R.string.time_oneandhalfhours);
    }

    if (numberOfSeconds == 9000) {
      return context.getString(R.string.time_twoandhalfhours);
    }

    // For all other cases, calculate

    hours = numberOfSeconds / 3600;
    remainingSeconds = numberOfSeconds % 3600;
    minutes = remainingSeconds / 60;
    seconds = remainingSeconds % 60;

    // Every 5 hours and 2 minutes
    // XYZ-5*2*20*

    descriptive =
        context.getString(
            R.string.time_hms_format,
            String.valueOf(hours),
            String.valueOf(minutes),
            String.valueOf(seconds));

    return descriptive;
  }
Exemplo n.º 6
0
  private void start(final Context context) {

    /** Producer properties * */
    Properties props = new Properties();
    props.put("metadata.broker.list", context.getString(BROKER_LIST));
    props.put("serializer.class", context.getString(SERIALIZER));
    props.put("request.required.acks", context.getString(REQUIRED_ACKS));

    ProducerConfig config = new ProducerConfig(props);
    final Producer<String, String> producer = new Producer<String, String>(config);

    /** Twitter properties * */
    consumerKey = context.getString(CONSUMER_KEY_KEY);
    consumerSecret = context.getString(CONSUMER_SECRET_KEY);
    accessToken = context.getString(ACCESS_TOKEN_KEY);
    accessTokenSecret = context.getString(ACCESS_TOKEN_SECRET_KEY);

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(consumerKey);
    cb.setOAuthConsumerSecret(consumerSecret);
    cb.setOAuthAccessToken(accessToken);
    cb.setOAuthAccessTokenSecret(accessTokenSecret);
    cb.setJSONStoreEnabled(true);
    cb.setIncludeEntitiesEnabled(true);

    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    final boolean shouldPrintTweetsOnScreen =
        Boolean.parseBoolean(context.getString(printTweetsOnScreen));
    final boolean shouldSendTweetsToKafka =
        Boolean.parseBoolean(context.getString(sendTweetsToKafka));

    final StatusListener listener =
        new StatusListener() {
          // The onStatus method is executed every time a new tweet comes
          // in.
          public void onStatus(Status status) {
            // The EventBuilder is used to build an event using the
            // the raw JSON of a tweet
            if (shouldPrintTweetsOnScreen) {
              logger.info(status.getUser().getScreenName() + ": " + status.getText());
            }

            if (shouldSendTweetsToKafka) {
              KeyedMessage<String, String> data =
                  new KeyedMessage<String, String>(
                      context.getString(KAFKA_TOPIC), TwitterObjectFactory.getRawJSON(status));
              producer.send(data);
            }
          }

          public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {}

          public void onTrackLimitationNotice(int numberOfLimitedStatuses) {}

          public void onScrubGeo(long userId, long upToStatusId) {}

          public void onException(Exception ex) {
            logger.info("Shutting down Twitter sample stream...");
            twitterStream.shutdown();
          }

          public void onStallWarning(StallWarning warning) {}
        };

    twitterStream.addListener(listener);

    twitterStream.filter(new FilterQuery().track(context.getString(keywords).split(",")));
  }