Weather-Downloader


Source link: https://github.com/CodelightStudios/Weather-Downloader

Weather-Downloader

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

Android Smart Login library

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. 

Resources

Library for Emoji View like Hangouts, Emoji TextView and Emoji EditText.

VisibilityPercentageLayout is a layout (extends RelativeLayout) with a custom listener which gives the visibility percentage of the layout every time it is changed.Pixel visibility listener is also available.

AndroidAppTranslate translates an Android application resource, easy and fast!

SharP wraps your SharedPreferences into a clean, type-safe Java interface. It uses annotation processing to generate the boilerplate code for you.

Android Five Stars Library is a small library that helps developers add a "Rate My App" dialog to their applications.

A simple tool for code generation of android.content.SharedPreferences based on model class described in java with a little help of annotations. Provides an ability to encapsulate data, saves time writing boiler-plate code, goes beyond SharedPreferences usage with easy-to use Serialization & default values evaluation at runtime.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes