Android Open Source - swap Weather Conditions Utils






From Project

Back to project page swap.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project swap listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.solazo.utils;
/*from www . j  a va2s.  c om*/
import org.solazo.R;

/**
 * Created by Daniel Zhao on 8/21/13.
 */
public final class WeatherConditionsUtils {

    public static final int SNOW_DAY = R.drawable.snow_alt;

    public static final int SNOW_NIGHT = R.drawable.snow_moon_alt;

    public static final int CLOUDY_DAY = R.drawable.cloudy_sun;

    public static final int CLOUDY_NIGHT = R.drawable.cloudy_moon;

    public static final int SUNNY_DAY = R.drawable.sun;

    public static final int CLEAR_NIGHT = R.drawable.cloudy_moon;

    public static final int OVERCAST = R.drawable.cloudy;

    public static final int FOG_DAY = R.drawable.fog_sun_alt;

    public static final int FOG_NIGHT = R.drawable.fog_moon_alt;

    public static final int HAIL_DAY = R.drawable.hail_alt;

    public static final int HAIL_NIGHT = R.drawable.hail_moon_alt;

    public static final int RAIN_DAY = R.drawable.rain;

    public static final int RAIN_NIGHT = R.drawable.rain_moon;

    public static final int DRIZZLE_DAY = R.drawable.drizzle_alt;

    public static final int DRIZZLE_NIGHT = R.drawable.drizzle_moon_alt;

    public static final int THUNDERSTORM_DAY = R.drawable.lightning;

    public static final int THUNDERSTORM_NIGHT = R.drawable.lightning_moon;

    public static final int WINDY = R.drawable.wind_alt;

    public static int getDrawablefromWeatherCondition(String weatherCondition) {
        boolean isDayTime = DateUtils.isDay();

        if (weatherCondition == null) return 0;

        weatherCondition = weatherCondition.toLowerCase();

        if (weatherCondition.contains("mostly cloudy") || weatherCondition.contains("partly cloudy")) {
            if (isDayTime)
                return CLOUDY_DAY;
            return CLOUDY_NIGHT;
        }

        if (weatherCondition.contains("snow")) {
            if (isDayTime)
                return SNOW_DAY;
            return SNOW_NIGHT;
        }

        if (weatherCondition.contains("overcast")) return OVERCAST;

        if (weatherCondition.contains("a few clouds")) {
            if (isDayTime)
                return SUNNY_DAY;
            return CLEAR_NIGHT;
        }

        if (weatherCondition.contains("thunderstorm")) {
            if (isDayTime)
                return THUNDERSTORM_DAY;
            return THUNDERSTORM_NIGHT;
        }

        if (weatherCondition.contains("ice pellets")) {
            if (isDayTime)
                return HAIL_DAY;
            return HAIL_NIGHT;
        }

        if (weatherCondition.contains("drizzle")) {
            if (isDayTime)
                return DRIZZLE_DAY;
            return DRIZZLE_NIGHT;
        }

        if (weatherCondition.contains("rain") || weatherCondition.contains("shower")) {
            if (isDayTime)
                return RAIN_DAY;
            return RAIN_NIGHT;
        }

        if (weatherCondition.contains("windy") || weatherCondition.contains("breezy")) return WINDY;

        if (weatherCondition.contains("fog") || weatherCondition.contains("smoke")) {
            if (isDayTime)
                return FOG_DAY;
            return FOG_NIGHT;
        }
        if (weatherCondition.contains("fair") || weatherCondition.contains("clear")) {
            if (isDayTime)
                return SUNNY_DAY;
            return CLEAR_NIGHT;
        }
        return 0;
    }
}




Java Source Code List

org.solazo.AboutFragment.java
org.solazo.GuessActivity.java
org.solazo.LocationActivity.java
org.solazo.MainActivity.java
org.solazo.Solazo.java
org.solazo.SubmitActivity.java
org.solazo.TabActivity.java
org.solazo.swap.AboutActivity.java
org.solazo.swap.AppState.java
org.solazo.swap.GuessActivity.java
org.solazo.swap.LocationService.java
org.solazo.swap.MainActivity.java
org.solazo.swap.SubmitActivity.java
org.solazo.utils.AppState.java
org.solazo.utils.DateUtils.java
org.solazo.utils.LocationUtils.java
org.solazo.utils.WeatherConditionsUtils.java