Skip to content

Get the weather data you need right into your android app in an easy and efficient way.

License

Notifications You must be signed in to change notification settings

CodelightStudios/Weather-Downloader

Repository files navigation

Weather-Downloader Android Arsenal Download MethodCount

Want to show the weather information in your app, here is a simple and efficient solution for you. Now show the weather information you need in your app without deviating away from your app's core idea. This is a helper library to get basic weather information into your app (not into a weather app of course). It uses the openweathermap api to get the weather data. Please note that this is still in beta phase and is limited to get the current weather conditions only. Forecast and Historical data will be added in future releases.

Include in your project

Using Gradle

Add this in dependencies of your app's build.gradle file.

compile 'codelight.studios.android:weather-downloader:0.2'

How to use

1. Implement the WeatherDataDownloadListener in your Activity

WeatherDataDownloadListener implements the callback functions to be called after the weather info is loaded.

    
    public class MainActivity extends AppCompatActivity implements WeatherDownloader.WeatherDataDownloadListener {
    
        ...
        
        @Override
        public void onWeatherDownloadComplete(WeatherData data, WeatherDownloader.Mode mode) {
            
        }
    
        @Override
        public void onWeatherDownloadFailed(Exception e) {
            
        }
    }

2. Invoke the getCurrentWeatherData to get the current weather conditions

Invoke the getCurrentWeatherData method by passing your Api Key and the Query (location name/zipcode/id/coordinates) strings.

    //Get data by city name
    WeatherDownloader downloader = new WeatherDownloader(MainActivity.this, WeatherDownloader.Mode.CITYNAME);
    downloader.getCurrentWeatherData(getResources().getString(R.string.weather_api_key), locationQuery);
    
    //Get data by city ID
    WeatherDownloader downloader = new WeatherDownloader(MainActivity.this, WeatherDownloader.Mode.CITYID);
    downloader.getCurrentWeatherData(getResources().getString(R.string.weather_api_key), cityIdQuery);
    
    //Get data by zip code
    WeatherDownloader downloader = new WeatherDownloader(MainActivity.this, WeatherDownloader.Mode.ZIPCODE);
    downloader.getCurrentWeatherData(getResources().getString(R.string.weather_api_key), zipCodeQuery);
    
    //Get data by coordinates.
    //In this method, the coordinatesQuery should be in the form of latitude:longitude format only.
    WeatherDownloader downloader = new WeatherDownloader(MainActivity.this, WeatherDownloader.Mode.COORDINATES);
    downloader.getCurrentWeatherData(getResources().getString(R.string.weather_api_key), coordinatesQuery);
    

That's it! Once the weather is downloaded in the background thread, you will be notified via the above mentioned onWeatherDownloadComplete or onWeatherDownloadFailed listeners.

Other features

By default the weather data is downloaded in KELVIN units. You can easily convert it into CELSIUS or FAHRENHEIT by using WeatherUnits class. For example, take a look into the sample app in repo.

    @Override
    public void onWeatherDownloadComplete(WeatherData data, WeatherDownloader.Mode mode) {
        if (mode == WeatherDownloader.Mode.CITYNAME) {
            cityNameTextView.
                    setText(String.format("%.2f", WeatherUnits.convertToCelsius(data.getMain().getTemp())));
        } else if (mode == WeatherDownloader.Mode.CITYID) {
            cityIdProgress.setVisibility(View.GONE);
            cityIdTextView.
                    setText(String.format("%.2f", WeatherUnits.convertToFahrenheit(data.getMain().getTemp())));
        }
    }

Contribution

I would love to welcome everyone of you to contribute to this project and make it better. Currently we are focusing on the current weather data only, but other forecast and historical data features would be a great addition. Encounter any issue? Don't hesitate to open an issue.

Convention I would like to follow: Master branch would be the development branch. So feel free to fork from the Master branch. Release branch will be merged with master branch after every major release.

Our other libraries

An easy and efficient way to add login functionality into your app.

License

The MIT License (MIT)

Copyright (c) 2017 Codelight Studios

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

Get the weather data you need right into your android app in an easy and efficient way.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages