RexWeather


Source link: https://github.com/vyshane/rex-weather

RexWeather

RexWeather is a sample Android Studio project demonstrating the use of Retrofit and RxJava to interact with web services. Link to the blog post.

Retrofit, by Square

Retrofit is a REST client for Android and Java. It allows you to turn a REST API into a Java interface by using annotations to describe the HTTP requests. It can then generate an implementation of the interface for you. This means that you can go from GET /users/{ userId } /posts to webService.fetchUserPosts(userId) in a few lines of code. Retrofit is very easy to use and it integrates well with RxJava.

RxJava, by Netflix

RxJava is a Java implementation of Rx, the Reactive Extensions library from the .NET world. It allows you to compose asynchronous and event-based programs in a declarative manner. Let's say that you want to implement something like this:

  • Start observing our current location. When a location change happens, in parallel,
    • Send a web service request A
    • Send a web service request B
      • Using the result from B, send a web service request C
  • When the results for both A and C are back, update the UI

RxJava allows you to write out your program pretty much as above. It abstracts out concerns about things like threading, synchronization, thread-safety, concurrent data structures, and non-blocking I/O. You can tell RxJava to observe the location changes and perform the web service requests in a background thread, and pass you the final results in the UI thread. If any exceptions are thrown at any point in the chain of events, you get told about it in one convenient place. You're not drowning in a spaghetti of onSuccess and onError callbacks. You're building pipelines.

Web Service Calls

The app uses OpenWeatherMap to fetch the current weather as well as the seven day forecast.

Because of the new policy of OpenWeatherMap, we need to provide API key to the requests we made. You can see the detailed information in here. Please insert your API key that you get after register from OpenWeatherMap to WeatherService.java

Current Weather

The current weather can be obtained by making a call similar to the following:

http://api.openweathermap.org/data/2.5/weather?lat=-31.9522&lon=115.8589&units=metric 

The returned JSON looks like this:

{

"coord": {

  "lon": 115.86,
  "lat": -31.95

}
,
"sys": {

  "message": 0.1843,
  "country": "AU",
  "sunrise": 1404602233,
  "sunset": 1404638729

}
,
"weather": [
  {

 "id": 802,

 "main": "Clouds",

 "description": "scattered clouds",

 "icon": "03n"
  
}

],
"base": "cmc stations",
"main": {

  "temp": 13,
  "pressure": 1015,
  "humidity": 71,
  "temp_min": 13,
  "temp_max": 13

}
,
"wind": {

  "speed": 3.1,
  "deg": 300

}
,
"rain": {

  "3h": 0

}
,
"clouds": {

  "all": 40

}
,
"dt": 1404657000,
"id": 6692202,
"name": "South Perth",
"cod": 200 
}

7 Day Forecast

The 7 day forecast can be obtained like so:

http://api.openweathermap.org/data/2.5/forecast/daily?lat=-31.9522&lon=115.8589&mode=json&units=metric&cnt=7 

And the returned JSON looks like this:

{

"cod": "200",
"message": 0.0094,
"city": {

  "id": 2063523,
  "name": "South Perth",
  "coord": {

 "lon": 115.833328,

 "lat": -31.933331
  
}
,
  "country": "AU",
  "population": 0

}
,
"cnt": 7,
"list": [
  {

 "dt": 1404619200,

 "temp": {

"day": 13,

"min": 13,

"max": 13.31,

"night": 13.31,

"eve": 13,

"morn": 13

 
}
,

 "pressure": 1016.99,

 "humidity": 100,

 "weather": [

{

  "id": 501,

  "main": "Rain",

  "description": "moderate rain",

  "icon": "10d"

}

 ],

 "speed": 7.25,

 "deg": 225,

 "clouds": 92,

 "rain": 4
  
}
,
]
 // Six more entries ...  
}

Resources

A sample android starter project to demonstrate the integration of the following tools:

  • Automation: Gradle
  • Testing: Android Testing Framework, Robotium, Roboelectric (JUnit, Android)
  • Continuous Integration: TravisCI

Sample Tasks:

  • Adding testing-only project dependencies
  • Using square spoon to run integraton tests
  • Writing android tests with robotium
  • Writing junit tests with robolectric
  • Android tests can be run with only Robotium use "gradle connectedAndroidTest"
  • Android tests can be run with Robotium and Spoon "gradle spoon"
  • Robolectric junit tests can be run with "gradle clean test"

RxBinding is an easy one-way binding support for Android, which is based on RxJava.

A wave view of android, can be used as progress bar.

This library is inspired from Chris Banes' Done Discard bar. It has material design already.

WebRTC Live Streaming

An Android client for ProjectRTC.

It is designed to demonstrate WebRTC video calls between androids and/or desktop browsers, but WebRtcClient could be used in other scenarios.

reflection-no-reflection is a proof on concept to create an API that is 100% compatible reflection API, but without any reflection. Performance stuff for Android and Java.

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