Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. public class WeatherClass {
  2.  
  3. static double temp;
  4.  
  5. private static String OPEN_WEATHER_MAP_API = "97e202a04a512514be6c36668fb2a5e3";
  6.  
  7.  
  8. public static double setWeatherCity(final double latitude, double longitude, final Context context){
  9. new WeatherManager("97e202a04a512514be6c36668fb2a5e3").getFiveDayForecastByCoordinates(latitude,longitude,
  10. new WeatherManager.ForecastHandler() {
  11. @Override
  12. public void onReceivedForecast(WeatherManager manager, Forecast forecast) {
  13. // Handle forecast
  14.  
  15. List<Double> list = new ArrayList<>();
  16. for (int i = 0; i < 5; i++) {
  17. long timestamp = forecast.getTimestampByIndex(i+3);
  18. Weather weatherForTimestamp = forecast.getWeatherForTimestamp(timestamp);
  19. Temperature tempMini = weatherForTimestamp.getTemperature().getMinimum();
  20. double temperatureInCelcius = tempMini.getValue(TemperatureUnit.CELCIUS);
  21. list.add(temperatureInCelcius);
  22. Log.v("Weather", "" +weatherForTimestamp.getWind().getSpeed());
  23. Log.v("Weather", "Température mini : " + " "+ list.get(i));
  24. }
  25. int minIndex = list.indexOf(Collections.min(list));
  26. Log.v("Weather MINI", "Température mini : " + list.get(minIndex));
  27. //Toast.makeText(context, "Température mini: " + list.get(minIndex), Toast.LENGTH_LONG).show();
  28. temp = list.get(minIndex);
  29. Log.v("WeatherClass", temp + "");
  30.  
  31.  
  32.  
  33. /*for (int timestampIndex = 0; timestampIndex < numberOfAvailableTimestamps; timestampIndex++) {
  34. long timestamp = forecast.getTimestampByIndex(timestampIndex);
  35. Weather weatherForTimestamp = forecast.getWeatherForTimestamp(timestamp);
  36. Temperature tempMin = weatherForTimestamp.getTemperature().getMinimum();
  37. double temperatureInCelcius = tempMin.getValue(TemperatureUnit.CELCIUS); // 0.0 degrees
  38. }*/
  39. }
  40.  
  41. @Override
  42. public void onFailedToReceiveForecast(WeatherManager manager) {
  43. Log.v("TAG", " ERREUR");
  44. temp = -1000000;
  45.  
  46. }
  47. }
  48. );
  49. return temp;
  50. }
  51.  
  52.  
  53.  
  54. }
  55.  
  56. temp = WeatherClass.setWeatherCity(latitude, longitude, getApplicationContext());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement