diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/ui/HomeActivity.java b/onebusaway-android/src/main/java/org/onebusaway/android/ui/HomeActivity.java index 3dc071c77..9e13964ea 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/ui/HomeActivity.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/ui/HomeActivity.java @@ -2014,7 +2014,7 @@ private void setWeatherData() { double weatherTemp = weatherResponse.getCurrent_forecast().getTemperature(); if (weatherIcon != null && !weatherIcon.isEmpty()) { - WeatherUtils.setWeatherImage(weatherImageView, weatherIcon, this); + WeatherUtils.setWeatherImage(weatherImageView, weatherIcon); }else{ weatherImageView.setVisibility(View.GONE); } diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/ui/weather/WeatherUtils.java b/onebusaway-android/src/main/java/org/onebusaway/android/ui/weather/WeatherUtils.java index d391bdb94..ae28356f7 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/ui/weather/WeatherUtils.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/ui/weather/WeatherUtils.java @@ -1,6 +1,5 @@ package org.onebusaway.android.ui.weather; -import android.content.Context; import android.content.SharedPreferences; import android.widget.ImageView; import android.widget.TextView; @@ -12,25 +11,15 @@ public class WeatherUtils { - public static void setWeatherImage(ImageView imageView, String weatherCondition, Context context) { - // TODO FIXME: This is temporarily commented out because it was causing a large number - // of crashes in 2.13.0. - // See https://github.com/OneBusAway/onebusaway-android/issues/1196 - -// String resName = weatherCondition.replace("-", "_"); -// -// int resId = context.getResources().getIdentifier(resName, "drawable", context.getPackageName()); -// -// if (resId != 0) { -// // Adjusting scale for fog and wind icons. -// if(weatherCondition.equals("fog") || weatherCondition.equals("wind")){ -// imageView.setScaleType(ImageView.ScaleType.CENTER); -// } -// imageView.setImageResource(resId); -// } else { -// // Default -// imageView.setImageResource(R.drawable.clear_day); -// } + public static void setWeatherImage(ImageView imageView, String weatherCondition) { + String resName = weatherCondition.replaceAll("-", "_"); + // Adjusting scale for fog and wind icons. + if (weatherCondition.equals("fog") || weatherCondition.equals("wind")) { + imageView.setScaleType(ImageView.ScaleType.CENTER); + }else{ + imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + } + imageView.setImageResource(getWeatherDrawableRes(resName)); } public static void setWeatherTemp(TextView weatherTempTxtView, double temp) { @@ -51,6 +40,32 @@ public static void setWeatherTemp(TextView weatherTempTxtView, double temp) { } + private static int getWeatherDrawableRes(String condition) { + switch (condition) { + case "clear_night": + return R.drawable.clear_night; + case "rain": + return R.drawable.rain; + case "snow": + return R.drawable.snow; + case "sleet": + return R.drawable.sleet; + case "wind": + return R.drawable.wind; + case "fog": + return R.drawable.fog; + case "cloudy": + return R.drawable.cloudy; + case "partly_cloudy_day": + return R.drawable.partly_cloudy_day; + case "partly_cloudy_night": + return R.drawable.partly_cloudy_night; + default: + return R.drawable.clear_day; + } + } + + public static String getDefaultUserTemp() { Locale locale = Locale.getDefault(); String countryCode = locale.getCountry(); diff --git a/onebusaway-android/src/main/res/layout/main.xml b/onebusaway-android/src/main/res/layout/main.xml index 02c0e88c8..d301dcf5e 100644 --- a/onebusaway-android/src/main/res/layout/main.xml +++ b/onebusaway-android/src/main/res/layout/main.xml @@ -109,7 +109,6 @@