Back to project page android-bossweather.
The source code is released under:
Apache License
If you think the Android project android-bossweather listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.michael.feng.tools; /*from www .j a v a2 s . co m*/ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import com.michael.feng.bossweather.R; public class ConvertUtil { public static String dateToLocal() { // SimpleDateFormat sdfCST = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm a z"); SimpleDateFormat sdfDST = new SimpleDateFormat("EEE? MMM.dd.yyyy"); String destStr = ""; destStr = sdfDST.format(new Date()); // Convert Day to Chinese destStr = destStr.replace("Mon", "???"); destStr = destStr.replace("Tue", "???"); destStr = destStr.replace("Wed", "???"); destStr = destStr.replace("Thu", "???"); destStr = destStr.replace("Fri", "???"); destStr = destStr.replace("Sat", "???"); destStr = destStr.replace("Sun", "???"); // Convert Month to number destStr = destStr.replace("Jan", "1"); destStr = destStr.replace("Feb", "2"); destStr = destStr.replace("Mar", "3"); destStr = destStr.replace("Apr", "4"); destStr = destStr.replace("May", "5"); destStr = destStr.replace("Jun", "6"); destStr = destStr.replace("Jul", "7"); destStr = destStr.replace("Aug", "8"); destStr = destStr.replace("Sep", "9"); destStr = destStr.replace("Oct", "10"); destStr = destStr.replace("Nov", "11"); destStr = destStr.replace("Dec", "12"); return destStr; } public static String weatherToLocal(String weather) { weather = weather.toLowerCase(); weather = weather.replace("tornado", "?????"); weather = weather.replace("tropical storm", "????"); weather = weather.replace("hurricane", "??"); // Thunderstorm weather = weather.replace("severe thunderstorms", "???"); weather = weather.replace("thunderstorms", "??"); // Rain and snow weather = weather.replace("mixed rain and snow", "???"); weather = weather.replace("mixed rain and sleet", "???"); weather = weather.replace("mixed snow and sleet", "???"); weather = weather.replace("freezing drizzle", "??"); weather = weather.replace("drizzle", "???"); weather = weather.replace("freezing rain", "??"); weather = weather.replace("showers", "??"); weather = weather.replace("snow flurries", "??"); weather = weather.replace("light snow showers", "??"); weather = weather.replace("blowing snow", "?"); weather = weather.replace("snow", "?"); weather = weather.replace("hail", "??"); weather = weather.replace("sleet", "???"); weather = weather.replace("dust", "??"); weather = weather.replace("foggy", "?"); weather = weather.replace("haze", "??"); weather = weather.replace("smoky", "??"); weather = weather.replace("blustery", "?"); weather = weather.replace("windy", "??"); // Cold weather = weather.replace("cold", "?"); // Cloud weather = weather.replace("cloudy", "??"); weather = weather.replace("partly cloudy", "??"); weather = weather.replace("mostly cloudy (night)", "????"); weather = weather.replace("mostly cloudy (day)", "????"); weather = weather.replace("partly cloudy (night)", "????"); // Sunny weather = weather.replace("partly cloudy (day)", "?"); weather = weather.replace("clear", "?"); weather = weather.replace("clear (night)", "?"); weather = weather.replace("sunny", "?"); weather = weather.replace("fair", "?"); weather = weather.replace("fair (night)", "?"); weather = weather.replace("fair (day)", "?"); weather = weather.replace("mixed rain and hail", "????"); weather = weather.replace("hot", "?"); // Thunderstorm weather = weather.replace("isolated thunderstorms", "????"); weather = weather.replace("scattered thunderstorms", "????"); weather = weather.replace("scattered showers", "????"); weather = weather.replace("heavy snow", "??"); weather = weather.replace("scattered snow showers", "????"); weather = weather.replace("partly cloudy", "??"); weather = weather.replace("thundershowers", "???"); weather = weather.replace("snow showers", "??"); weather = weather.replace("isolated thundershowers", "???"); weather = weather.replace("not available", "??"); weather = weather.replace("mostly", ""); weather = weather.replace("isolated", ""); weather = weather.replace("partly", "??"); weather = weather.replace("mist", "?"); weather = weather.replace("rain shower", "??"); weather = weather.replace("scattered", "??"); weather = weather.replace(" ", ""); return weather; } public static int getIconByWeather(String weather) { int icon = R.drawable.sunny; if(weather.equals("????")) { icon = R.drawable.partly_sunny; } else if(weather.equals("?") || weather.equals("??") || weather.equals("??")) { icon = R.drawable.foggy; } else if(weather.equals("??") || weather.equals("?") || weather.equals("????")) { icon = R.drawable.cloud; } else if(weather.equals("?") || weather.equals("??")) { icon = R.drawable.cold; } else if(weather.equals("???") || weather.equals("??") || weather.equals("???") || weather.equals("????")) { icon = R.drawable.thunderstorm; } else if(weather.equals("?") || weather.equals("??") || weather.equals("??")) { icon = R.drawable.snow; } else if(weather.equals("??") || weather.equals("????") || weather.equals("??")) { icon = R.drawable.small_snow; } else if(weather.equals("??") || weather.equals("????")) { icon = R.drawable.little_rain; } else if(weather.equals("???") || weather.equals("??") || weather.equals("??") || weather.equals("??")) { icon = R.drawable.rain; } else if(weather.equals("???") || weather.equals("????")) { icon = R.drawable.rain_and_snow; } return icon; } }