├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ ├── Keval_Apache_2_0.xml │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── markdown-navigator.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── _config.yml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images └── sun.png ├── open-weather-wrapper ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── openweatherweapper │ ├── APIService.java │ ├── OpenWeatherApi.java │ ├── RetrofitBuilder.java │ ├── Unit.java │ ├── exception │ ├── InvalidApiKeyException.java │ └── NotInitilizedException.java │ ├── interfaces │ ├── CurrentWeatherListener.java │ ├── ForecastListener.java │ └── MultipleCitiesWeatherListener.java │ └── models │ ├── CurrentWeather.java │ ├── MultipleCitiesWeathers.java │ ├── WeatherForecast.java │ └── params │ ├── City.java │ ├── Clouds.java │ ├── Coord.java │ ├── Forecast.java │ ├── Main.java │ ├── Rain.java │ ├── Snow.java │ ├── Sys.java │ ├── Weather.java │ └── Wind.java ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── openweatherapi │ │ └── sample │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── openweatherapi │ │ │ └── sample │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_moon.png │ │ ├── ic_sun.png │ │ ├── ic_temp.png │ │ ├── ic_temp_heigh.png │ │ ├── ic_temp_low.png │ │ └── ic_wind.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ ├── ic_moon.png │ │ ├── ic_sun.png │ │ ├── ic_temp.png │ │ ├── ic_temp_heigh.png │ │ ├── ic_temp_low.png │ │ └── ic_wind.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── ic_moon.png │ │ ├── ic_sun.png │ │ ├── ic_temp.png │ │ ├── ic_temp_heigh.png │ │ ├── ic_temp_low.png │ │ └── ic_wind.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_moon.png │ │ ├── ic_sun.png │ │ ├── ic_temp.png │ │ ├── ic_temp_heigh.png │ │ ├── ic_temp_low.png │ │ └── ic_wind.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_moon.png │ │ ├── ic_sun.png │ │ ├── ic_temp.png │ │ ├── ic_temp_heigh.png │ │ ├── ic_temp_low.png │ │ └── ic_wind.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── api_key.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── openweatherapi │ └── sample │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | /sample/src/main/res/values/api_key.xml 11 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/Keval_Apache_2_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 33 | 34 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | jdk: oraclejdk8 3 | sudo: false 4 | 5 | notifications: 6 | email: 7 | - kevalpatel2106@gmail.com 8 | 9 | env: 10 | global: 11 | - ADB_INSTALL_TIMEOUT=10 #Time out to 10 mins 12 | 13 | before_cache: 14 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 15 | 16 | cache: 17 | directories: #Cache all dirs under .gradle folder 18 | - $HOME/.gradle/daemon #Cache daemon logs 19 | - $HOME/.gradle/native #Cache library downloaded from the gradle dependency 20 | - $HOME/.gradle/wrapper #Cache the gradle 21 | 22 | android: 23 | update_sdk: true 24 | components: 25 | - platform-tools 26 | - tools 27 | - build-tools-25.0.2 28 | - android-25 29 | 30 | # Additional components 31 | - extra-google-m2repository 32 | - extra-android-m2repository 33 | 34 | #system images 35 | - sys-img-armeabi-v7a-android-22 36 | 37 | licenses: 38 | - 'android-sdk-preview-license-52d11cd2' 39 | - 'android-sdk-license-.+' 40 | - 'google-gdk-license-.+' 41 | 42 | before_script: 43 | - chmod +x gradlew #Grand permissions 44 | - android list targets 45 | - echo no | android create avd --force --name test --target android-21 --abi armeabi-v7a #Create AVD for API 21 46 | - emulator -avd test -no-skin -no-audio -no-window & #Start emulator 47 | 48 | script: 49 | - echo "Travis branch is $TRAVIS_BRANCH" 50 | - echo "Travis branch is in pull request $TRAVIS_PULL+REQUEST" 51 | # - ./gradlew check -PdisablePreDex --continue --stacktrace 52 | - android-wait-for-emulator 53 | - adb devices #Display list of devices 54 | - adb shell input keyevent 82 & 55 | - ./gradlew connectedCheck -PdisablePreDex --stacktrace 56 | 57 | before_install: 58 | - pip install --user codecov #Install codecov 59 | 60 | after_success: 61 | - codecov #Run codecov 62 | 63 | after_failure: "cat $TRAVIS_BUILD_DIR/app/build/outputs/lint-results-debug.xml" 64 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ##How to contribute? 2 | ####Simple 3 step to contribute into this repo: 3 | 4 | 1. Fork the project. 5 | 2. Make required changes and commit. 6 | 3. Generate pull request. Mention all the required description regarding changes you made. -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Open-Weather-API-Wrapper 2 | 3 | [ ![Download](https://api.bintray.com/packages/kevalpatel2106/maven/Open-Weather-API-Wrapper/images/download.svg) ](https://bintray.com/kevalpatel2106/maven/Open-Weather-API-Wrapper/_latestVersion) [![Build Status](https://travis-ci.org/kevalpatel2106/Open-Weather-API-Wrapper.svg?branch=master)](https://travis-ci.org/kevalpatel2106/Open-Weather-API-Wrapper) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Open--Weather--API--Wrapper-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/5251) [![API](https://img.shields.io/badge/API-14%2B-orange.svg?style=flat)](https://android-arsenal.com/api?level=14) 4 | 5 | ![sun.png](/images/sun.png) 6 | 7 | Open Weather API Wrapper is an Android wrapper for the APIs of https://openweathermap.org. This library handles all the network operations and parameter validations on behalf of the developer. 8 | 9 | ## Dependency: 10 | - Add below lines to `app/build.gradle` file of your project. 11 | ``` 12 | dependencies { 13 | compile 'com.kevalpatel2106:open-weather-wrapper:1.0' 14 | } 15 | ``` 16 | 17 | ## How to use this library?: 18 | - **Initialization:** 19 | 20 | Initialize the library in your launch activity by providing the open weather api key and the unit system you want to use throughout the application. 21 | If you don't have the open weather api key, you can generate it from [here](http://openweathermap.org/appid). 22 | ```java 23 | OpenWeatherApi.initialize("YOUR API KEY", Unit.STANDARD); 24 | ``` 25 | 26 | - **Accessing the API:** 27 | 28 | Open weather api provides you functions to access below information: 29 | - _Get current weather for provided city, geo point or postal code._ 30 | - _Get three hourly forecast for city or, geo point._ 31 | - _Get the daily forecast for provided city or geo point._ 32 | 33 | You can get the required information by passing the required parameters. The information will be received in specific listeners. 34 | 35 | Here is the example of getting the three hourly forecast of the weather by city name. 36 | ```java 37 | OpenWeatherApi.getThreeHoursForecast("Landon,uk", new ForecastListener() { 38 | @Override 39 | public void onResponse(WeatherForecast weatherForecasts) { 40 | //Forecast received. 41 | //Do someting 42 | } 43 | 44 | @Override 45 | public void onError(String message) { 46 | //Something went wrong. 47 | //Display the error message to the user. 48 | } 49 | }); 50 | ``` 51 | 52 | Open Weather API Wrapper uses [RxJava](https://github.com/ReactiveX/RxJava) and [Retrofit](https://square.github.io/retrofit/) to handle the network operations. 53 | 54 | ## Demo: 55 | - You can download the sample application from [here](https://github.com/kevalpatel2106/Open-Weather-API-Wrapper/releases/download/1.0/sample.apk). 56 | 57 | ## Contribute: 58 | - Still there are many open weather apis to implement. Any pull request are most welcome. 59 | **Simple 3 step to contribute into this repo:** 60 | 1. Fork the project. 61 | 2. Make required changes and commit. 62 | 3. Generate pull request. Mention all the required description regarding changes you made. 63 | 64 | ## Questions: 65 | Hit me on twitter [![Twitter](https://img.shields.io/badge/Twitter-@kevalpatel2106-blue.svg?style=flat)](https://twitter.com/kevalpatel2106) 66 | 67 | ## License 68 | Copyright 2017 Keval Patel 69 | 70 | Licensed under the Apache License, Version 2.0 (the "License"); 71 | you may not use this file except in compliance with the License. 72 | You may obtain a copy of the License at 73 | 74 | http://www.apache.org/licenses/LICENSE-2.0 75 | 76 | Unless required by applicable law or agreed to in writing, software 77 | distributed under the License is distributed on an "AS IS" BASIS, 78 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 79 | See the License for the specific language governing permissions and 80 | limitations under the License. 81 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 18 | 19 | buildscript { 20 | repositories { 21 | jcenter() 22 | } 23 | dependencies { 24 | classpath 'com.android.tools.build:gradle:2.2.3' 25 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' 26 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7' 27 | // NOTE: Do not place your application dependencies here; they belong 28 | // in the individual module build.gradle files 29 | } 30 | } 31 | 32 | allprojects { 33 | repositories { 34 | jcenter() 35 | } 36 | } 37 | 38 | task clean(type: Delete) { 39 | delete rootProject.buildDir 40 | } 41 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Keval Patel. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | # Project-wide Gradle settings. 18 | 19 | # IDE (e.g. Android Studio) users: 20 | # Gradle settings configured through the IDE *will override* 21 | # any settings specified in this file. 22 | 23 | # For more details on how to configure your build environment visit 24 | # http://www.gradle.org/docs/current/userguide/build_environment.html 25 | 26 | # Specifies the JVM arguments used for the daemon process. 27 | # The setting is particularly useful for tweaking memory settings. 28 | org.gradle.jvmargs=-Xmx1536m 29 | 30 | # When configured, Gradle will run in incubating parallel mode. 31 | # This option should only be used with decoupled projects. More details, visit 32 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 33 | # org.gradle.parallel=true 34 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevalpatel2106/Open-Weather-API-Wrapper/c8a6a3d32c963e0b79b5d1863bcb8d8058255924/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Keval Patel. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | #Mon Dec 28 10:00:20 PST 2015 18 | distributionBase=GRADLE_USER_HOME 19 | distributionPath=wrapper/dists 20 | zipStoreBase=GRADLE_USER_HOME 21 | zipStorePath=wrapper/dists 22 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 23 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /images/sun.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevalpatel2106/Open-Weather-API-Wrapper/c8a6a3d32c963e0b79b5d1863bcb8d8058255924/images/sun.png -------------------------------------------------------------------------------- /open-weather-wrapper/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /open-weather-wrapper/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | android { 5 | compileSdkVersion 25 6 | buildToolsVersion "25.0.2" 7 | 8 | lintOptions { 9 | abortOnError false 10 | } 11 | 12 | defaultConfig { 13 | minSdkVersion 14 14 | targetSdkVersion 25 15 | versionCode 1 16 | versionName "1.0" 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | compile 'com.android.support:support-annotations:25.1.0' 28 | 29 | //Retrofit 30 | compile 'com.squareup.retrofit2:retrofit:2.0.2' 31 | compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2' 32 | compile 'com.squareup.retrofit2:converter-gson:2.0.0' 33 | 34 | //Rx 35 | compile 'io.reactivex:rxandroid:1.2.1' 36 | 37 | //Gson 38 | compile 'com.google.code.gson:gson:2.4' 39 | 40 | compile 'com.squareup.okhttp3:logging-interceptor:3.2.0' 41 | } 42 | 43 | /* 44 | * Copyright 2016 Keval Patel. 45 | * 46 | * Licensed under the Apache License, Version 2.0 (the "License"); 47 | * you may not use this file except in compliance with the License. 48 | * You may obtain a copy of the License at 49 | * 50 | * http://www.apache.org/licenses/LICENSE-2.0 51 | * 52 | * Unless required by applicable law or agreed to in writing, software 53 | * distributed under the License is distributed on an "AS IS" BASIS, 54 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 55 | * See the License for the specific language governing permissions and 56 | * limitations under the License. 57 | */ 58 | 59 | //#################################### Bintray ####################################// 60 | if (project.rootProject.file('local.properties').exists()) { 61 | apply plugin: 'com.jfrog.bintray' 62 | 63 | version = "1.0" // This is the library version used when deploying the artifact 64 | 65 | def siteUrl = 'https://github.com/kevalpatel2106/Open-Weather-API-Wrapper' // Homepage URL of the library 66 | def gitUrl = 'https://github.com/kevalpatel2106/Open-Weather-API-Wrapper.git' // Git repository URL 67 | 68 | group = "com.kevalpatel2106" 69 | 70 | install { 71 | repositories.mavenInstaller { 72 | // This generates POM.xml with proper parameters 73 | pom { 74 | project { 75 | packaging 'aar' 76 | 77 | // Add your description here 78 | name 'Open-Weather-API-Wrapper' 79 | description = 'An Android wrapper for the APIs of https://openweathermap.org.' 80 | url siteUrl 81 | 82 | // Set your license 83 | licenses { 84 | license { 85 | name 'The Apache Software License, Version 2.0' 86 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 87 | } 88 | } 89 | developers { 90 | developer { 91 | id 'kevalpatel2106' 92 | name 'Keval Patel' 93 | email 'kevalpatel2106@gmail.com' 94 | } 95 | } 96 | scm { 97 | connection gitUrl 98 | developerConnection gitUrl 99 | url siteUrl 100 | } 101 | } 102 | } 103 | } 104 | } 105 | 106 | task sourcesJar(type: Jar) { 107 | from android.sourceSets.main.java.srcDirs 108 | classifier = 'sources' 109 | } 110 | 111 | task javadoc(type: Javadoc) { 112 | source = android.sourceSets.main.java.srcDirs 113 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 114 | } 115 | 116 | task javadocJar(type: Jar, dependsOn: javadoc) { 117 | classifier = 'javadoc' 118 | from javadoc.destinationDir 119 | } 120 | artifacts { 121 | // archives javadocJar 122 | archives sourcesJar 123 | } 124 | 125 | Properties properties = new Properties() 126 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 127 | 128 | // https://github.com/bintray/gradle-bintray-plugin 129 | bintray { 130 | user = properties.getProperty("bintray.user") 131 | key = properties.getProperty("bintray.apikey") 132 | 133 | configurations = ['archives'] 134 | pkg { 135 | repo = "maven" 136 | // it is the name that appears in bintray when logged 137 | name = "Open-Weather-API-Wrapper" 138 | websiteUrl = siteUrl 139 | vcsUrl = gitUrl 140 | licenses = ["Apache-2.0"] 141 | publish = true 142 | version { 143 | gpg { 144 | sign = false //Determines whether to GPG sign the files. The default is false 145 | // passphrase = properties.getProperty("bintray.gpg.password") //Optional. The passphrase for GPG signing' 146 | } 147 | } 148 | } 149 | } 150 | } 151 | 152 | -------------------------------------------------------------------------------- /open-weather-wrapper/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Keval\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/APIService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherweapper; 18 | 19 | import com.openweatherweapper.models.CurrentWeather; 20 | import com.openweatherweapper.models.MultipleCitiesWeathers; 21 | import com.openweatherweapper.models.WeatherForecast; 22 | 23 | import retrofit2.http.GET; 24 | import retrofit2.http.Query; 25 | import rx.Observable; 26 | 27 | /** 28 | * Created by Keval on 16-Jan-17. 29 | * 30 | * @author {@link 'https://github.com/kevalpatel2106'} 31 | */ 32 | 33 | interface APIService { 34 | String BASE_URL = "http://api.openweathermap.org/data/2.5/"; 35 | 36 | /*********************************************************************************************** 37 | * CURRENT WEATHER APIS 38 | ***********************************************************************************************/ 39 | 40 | @GET("weather") 41 | Observable getCurrentWeatherByName(@Query("q") String cityAndCountry, 42 | @Query("units") String unit, 43 | @Query("appid") String apikey); 44 | 45 | @GET("weather") 46 | Observable getCurrentWeatherByLatLng(@Query("lat") double latitude, 47 | @Query("lon") double longitude, 48 | @Query("units") String unit, 49 | @Query("appid") String apikey); 50 | 51 | @GET("weather") 52 | Observable getCurrentWeatherById(@Query("id") int cityId, 53 | @Query("units") String unit, 54 | @Query("appid") String apikey); 55 | 56 | @GET("weather") 57 | Observable getCurrentWeatherByZipCode(@Query("zip") String zipCode, 58 | @Query("units") String unit, 59 | @Query("appid") String apikey); 60 | 61 | @GET("group") 62 | Observable getCurrentWeatherMultipleCities(@Query("id") String cityIds, 63 | @Query("units") String unit, 64 | @Query("appid") String apikey); 65 | 66 | /*********************************************************************************************** 67 | * THREE HOURLY FORECAST FOR MAX 5 DAYS FORECAST API 68 | ***********************************************************************************************/ 69 | 70 | @GET("forecast") 71 | Observable getThreeHoursForecast(@Query("q") String cityAndCountry, 72 | @Query("cnt") String limit, 73 | @Query("units") String unit, 74 | @Query("appid") String apikey); 75 | 76 | @GET("forecast") 77 | Observable getThreeHoursForecast(@Query("id") int cityId, 78 | @Query("cnt") String limit, 79 | @Query("units") String unit, 80 | @Query("appid") String apikey); 81 | 82 | @GET("forecast") 83 | Observable getThreeHoursForecast(@Query("lat") double latitude, 84 | @Query("lon") double longitude, 85 | @Query("cnt") String limit, 86 | @Query("units") String unit, 87 | @Query("appid") String apikey); 88 | 89 | /*********************************************************************************************** 90 | * DAILY FORECAST FOR MAX 16 DAYS FORECAST API 91 | ***********************************************************************************************/ 92 | @GET("forecast/daily") 93 | Observable getDailyForecast(@Query("q") String cityAndCountry, 94 | @Query("cnt") String limit, 95 | @Query("units") String unit, 96 | @Query("appid") String apikey); 97 | 98 | @GET("forecast/daily") 99 | Observable getDailyForecast(@Query("id") int cityId, 100 | @Query("cnt") String limit, 101 | @Query("units") String unit, 102 | @Query("appid") String apikey); 103 | 104 | @GET("forecast/daily") 105 | Observable getDailyForecast(@Query("lat") double latitude, 106 | @Query("lon") double longitude, 107 | @Query("cnt") String limit, 108 | @Query("units") String unit, 109 | @Query("appid") String apikey); 110 | 111 | } 112 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/OpenWeatherApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherweapper; 18 | 19 | import android.support.annotation.NonNull; 20 | import android.support.annotation.Nullable; 21 | import android.text.TextUtils; 22 | 23 | import com.openweatherweapper.exception.InvalidApiKeyException; 24 | import com.openweatherweapper.exception.NotInitilizedException; 25 | import com.openweatherweapper.interfaces.CurrentWeatherListener; 26 | import com.openweatherweapper.interfaces.ForecastListener; 27 | import com.openweatherweapper.interfaces.MultipleCitiesWeatherListener; 28 | import com.openweatherweapper.models.CurrentWeather; 29 | import com.openweatherweapper.models.MultipleCitiesWeathers; 30 | import com.openweatherweapper.models.WeatherForecast; 31 | 32 | import java.util.ArrayList; 33 | 34 | import rx.Observable; 35 | import rx.Observer; 36 | import rx.android.schedulers.AndroidSchedulers; 37 | import rx.schedulers.Schedulers; 38 | 39 | /** 40 | * Created by Keval on 16-Jan-17. 41 | * 42 | * @author {@link 'https://github.com/kevalpatel2106'} 43 | */ 44 | public class OpenWeatherApi { 45 | 46 | private static final int NO_LIMIT = -1; 47 | private static final int SUCCESS_CODE = 200; 48 | 49 | @SuppressWarnings("NullableProblems") 50 | @NonNull 51 | private static String sApiKey; 52 | private static String sUnit; 53 | 54 | private OpenWeatherApi() { 55 | throw new RuntimeException("Private constructor cannot be access by another class."); 56 | } 57 | 58 | /** 59 | * Initialize the library before using it. 60 | * 61 | * @param apiKey The api key to get data from openweathermap.org. If you don't have api key yet, 62 | * you can generate from http://openweathermap.org/appid . 63 | * @see 'http://openweathermap.org/appid' 64 | */ 65 | public static void initialize(@NonNull String apiKey, @Unit.Units String unit) { 66 | //noinspection ConstantConditions 67 | if (apiKey == null) throw new InvalidApiKeyException(); 68 | 69 | sApiKey = apiKey; 70 | sUnit = unit; 71 | 72 | if (!Unit.isValidUnit(sUnit)) sUnit = Unit.STANDARD; 73 | } 74 | 75 | @NonNull 76 | static String getApiKey() { 77 | return sApiKey; 78 | } 79 | 80 | @NonNull 81 | @Unit.Units 82 | static String getUnit() { 83 | return sUnit; 84 | } 85 | 86 | private static void checkInitializeOrThrow() { 87 | //noinspection ConstantConditions 88 | if (sApiKey == null) throw new NotInitilizedException(); 89 | } 90 | 91 | /*********************************************************************************************** 92 | * CURRENT WEATHER APIS 93 | ***********************************************************************************************/ 94 | 95 | /** 96 | * Get the current weather condition for the given city name. If the city name does not mach to any location 97 | * error will occur. 98 | * 99 | * @param cityName name of the city. (e.g. Landon) 100 | * @param listener {@link CurrentWeatherListener} to listen the response 101 | */ 102 | @SuppressWarnings("WeakerAccess") 103 | public static void getCurrentWeather(@NonNull String cityName, 104 | @NonNull final CurrentWeatherListener listener) { 105 | getCurrentWeather(cityName, null, listener); 106 | } 107 | 108 | 109 | /** 110 | * Get the current weather condition for the given city name. If the city name does not mach to any location 111 | * error will occur. 112 | * 113 | * @param cityName name of the city. (e.g. Landon) 114 | * @param countryCode ISO 3166 country code. (e.g. uk) 115 | * @param listener {@link CurrentWeatherListener} to listen the response 116 | */ 117 | @SuppressWarnings("WeakerAccess") 118 | public static void getCurrentWeather(@NonNull String cityName, 119 | @Nullable String countryCode, 120 | @NonNull final CurrentWeatherListener listener) { 121 | 122 | //Check if the sdk initialized? 123 | checkInitializeOrThrow(); 124 | 125 | APIService apiService = RetrofitBuilder.getApiService(); 126 | Observable observable = apiService 127 | .getCurrentWeatherByName(countryCode == null ? cityName : (cityName + countryCode), sUnit, sApiKey); 128 | observable.observeOn(AndroidSchedulers.mainThread()) 129 | .subscribeOn(Schedulers.newThread()) 130 | .subscribe(new Observer() { 131 | @Override 132 | public void onCompleted() { 133 | } 134 | 135 | @Override 136 | public void onError(Throwable e) { 137 | listener.onError(e.getMessage()); 138 | } 139 | 140 | @Override 141 | public void onNext(CurrentWeather currentWeather) { 142 | if (currentWeather.getStatusCode() == SUCCESS_CODE) 143 | listener.onResponse(currentWeather); 144 | else listener.onError(currentWeather.statusMessage()); 145 | } 146 | }); 147 | 148 | } 149 | 150 | /** 151 | * Get current weather condition pointed by the geo point. 152 | * 153 | * @param latitude latitude of the point 154 | * @param longitude latitude of the point 155 | * @param listener {@link CurrentWeatherListener} to listen the response 156 | */ 157 | @SuppressWarnings("WeakerAccess") 158 | public static void getCurrentWeather(double latitude, 159 | double longitude, 160 | @NonNull final CurrentWeatherListener listener) { 161 | 162 | //Check if the sdk initialized? 163 | checkInitializeOrThrow(); 164 | 165 | APIService apiService = RetrofitBuilder.getApiService(); 166 | Observable observable = apiService 167 | .getCurrentWeatherByLatLng(latitude, longitude, sUnit, sApiKey); 168 | observable.observeOn(AndroidSchedulers.mainThread()) 169 | .subscribeOn(Schedulers.newThread()) 170 | .subscribe(new Observer() { 171 | @Override 172 | public void onCompleted() { 173 | } 174 | 175 | @Override 176 | public void onError(Throwable e) { 177 | listener.onError(e.getMessage()); 178 | } 179 | 180 | @Override 181 | public void onNext(CurrentWeather currentWeather) { 182 | if (currentWeather.getStatusCode() == SUCCESS_CODE) 183 | listener.onResponse(currentWeather); 184 | else listener.onError(currentWeather.statusMessage()); 185 | } 186 | }); 187 | 188 | } 189 | 190 | /** 191 | * Get current weather of the city provided by the city id. This method is recommended to get the 192 | * accurate result for the give city. If the city id does not exist then, error will occur. 193 | * 194 | * @param cityId city id. 195 | * @param listener {@link CurrentWeatherListener} to listen the response 196 | */ 197 | @SuppressWarnings("WeakerAccess") 198 | public static void getCurrentWeather(int cityId, 199 | @NonNull final CurrentWeatherListener listener) { 200 | 201 | //Check if the sdk initialized? 202 | checkInitializeOrThrow(); 203 | 204 | APIService apiService = RetrofitBuilder.getApiService(); 205 | Observable observable = apiService.getCurrentWeatherById(cityId, sUnit, sApiKey); 206 | observable.observeOn(AndroidSchedulers.mainThread()) 207 | .subscribeOn(Schedulers.newThread()) 208 | .subscribe(new Observer() { 209 | @Override 210 | public void onCompleted() { 211 | } 212 | 213 | @Override 214 | public void onError(Throwable e) { 215 | listener.onError(e.getMessage()); 216 | } 217 | 218 | @Override 219 | public void onNext(CurrentWeather currentWeather) { 220 | if (currentWeather.getStatusCode() == SUCCESS_CODE) 221 | listener.onResponse(currentWeather); 222 | else listener.onError(currentWeather.statusMessage()); 223 | } 224 | }); 225 | 226 | } 227 | 228 | /** 229 | * Get current weather of the city provided by zip/postal code. If the zip/postal code does not 230 | * exist then, error will occur. 231 | * 232 | * @param zipCode Zip code of the area. 233 | * @param countryCode ISO 3166 country code. (e.g. uk) 234 | * @param listener {@link CurrentWeatherListener} to listen the response 235 | */ 236 | @SuppressWarnings("WeakerAccess") 237 | public static void getCurrentWeather(long zipCode, 238 | @NonNull String countryCode, 239 | @NonNull final CurrentWeatherListener listener) { 240 | 241 | //Check if the sdk initialized? 242 | checkInitializeOrThrow(); 243 | 244 | APIService apiService = RetrofitBuilder.getApiService(); 245 | Observable observable = apiService 246 | .getCurrentWeatherByZipCode(zipCode + "," + countryCode, sUnit, sApiKey); 247 | 248 | observable.observeOn(AndroidSchedulers.mainThread()) 249 | .subscribeOn(Schedulers.newThread()) 250 | .subscribe(new Observer() { 251 | @Override 252 | public void onCompleted() { 253 | } 254 | 255 | @Override 256 | public void onError(Throwable e) { 257 | listener.onError(e.getMessage()); 258 | } 259 | 260 | @Override 261 | public void onNext(CurrentWeather currentWeather) { 262 | if (currentWeather.getStatusCode() == SUCCESS_CODE) 263 | listener.onResponse(currentWeather); 264 | else listener.onError(currentWeather.statusMessage()); 265 | } 266 | }); 267 | } 268 | 269 | /** 270 | * Get the current weather condition for more than one city by sending the list of city ids. 271 | * 272 | * @param idsOfCities List of the city ids 273 | * @param listener {@link MultipleCitiesWeatherListener} to listen the response 274 | */ 275 | @SuppressWarnings("WeakerAccess") 276 | public static void getMultipleCitiesCurrentWeather(ArrayList idsOfCities, 277 | @NonNull final MultipleCitiesWeatherListener listener) { 278 | 279 | //Check if the sdk initialized? 280 | checkInitializeOrThrow(); 281 | 282 | APIService apiService = RetrofitBuilder.getApiService(); 283 | Observable observable = apiService 284 | .getCurrentWeatherMultipleCities(TextUtils.join(",", idsOfCities), sUnit, sApiKey); 285 | 286 | observable.observeOn(AndroidSchedulers.mainThread()) 287 | .subscribeOn(Schedulers.newThread()) 288 | .subscribe(new Observer() { 289 | @Override 290 | public void onCompleted() { 291 | } 292 | 293 | @Override 294 | public void onError(Throwable e) { 295 | listener.onError(e.getMessage()); 296 | } 297 | 298 | @Override 299 | public void onNext(MultipleCitiesWeathers citiesWeathers) { 300 | if (citiesWeathers.getStatusCode() == SUCCESS_CODE) 301 | listener.onResponse(citiesWeathers); 302 | else listener.onError(citiesWeathers.statusMessage()); 303 | } 304 | }); 305 | } 306 | 307 | /*********************************************************************************************** 308 | * THREE HOURLY FORECAST FOR MAX 5 DAYS FORECAST API 309 | ***********************************************************************************************/ 310 | 311 | /** 312 | * Get weather forecast for every three hours for given city id. This will return maximum 5 days 313 | * forecast if available. 314 | * 315 | * @param cityId id of the city to get the forecast 316 | * @param listener {@link ForecastListener} to get the forecast data. 317 | */ 318 | @SuppressWarnings("WeakerAccess") 319 | public static void getThreeHoursForecast(int cityId, 320 | @NonNull final ForecastListener listener) { 321 | getThreeHoursForecast(cityId, NO_LIMIT, listener); 322 | } 323 | 324 | /** 325 | * Get weather forecast for every three hours for given city id. 326 | * 327 | * @param cityId id of the city to get the forecast 328 | * @param limit number of forecast result required. The value must be between 1 to 40. 329 | * @param listener {@link ForecastListener} to get the forecast data. 330 | */ 331 | @SuppressWarnings("WeakerAccess") 332 | public static void getThreeHoursForecast(int cityId, 333 | int limit, 334 | @NonNull final ForecastListener listener) { 335 | 336 | //Check if the sdk initialized? 337 | checkInitializeOrThrow(); 338 | 339 | APIService apiService = RetrofitBuilder.getApiService(); 340 | Observable observable = apiService 341 | .getThreeHoursForecast(cityId, (limit < 0 ? limit + "" : ""), sUnit, sApiKey); 342 | 343 | observable.observeOn(AndroidSchedulers.mainThread()) 344 | .subscribeOn(Schedulers.newThread()) 345 | .subscribe(new Observer() { 346 | @Override 347 | public void onCompleted() { 348 | } 349 | 350 | @Override 351 | public void onError(Throwable e) { 352 | listener.onError(e.getMessage()); 353 | } 354 | 355 | @Override 356 | public void onNext(WeatherForecast weatherForecasts) { 357 | if (weatherForecasts.getStatusCode() == SUCCESS_CODE) 358 | listener.onResponse(weatherForecasts); 359 | else listener.onError(weatherForecasts.statusMessage()); 360 | } 361 | }); 362 | } 363 | 364 | /** 365 | * Get weather forecast for every three hours for given city name. If the city name does not mach 366 | * to any location error will occur. This will return maximum 5 days 367 | * forecast if available. 368 | * 369 | * @param cityName name of the city. (e.g. Landon) 370 | * @param listener {@link ForecastListener} to get the forecast data. 371 | */ 372 | @SuppressWarnings("WeakerAccess") 373 | public static void getThreeHoursForecast(@NonNull String cityName, 374 | @NonNull final ForecastListener listener) { 375 | getThreeHoursForecast(cityName, null, NO_LIMIT, listener); 376 | } 377 | 378 | /** 379 | * Get weather forecast for every three hours for given city name. If the city name does not mach 380 | * to any location error will occur. 381 | * 382 | * @param cityName name of the city. (e.g. Landon) 383 | * @param limit number of forecast result required. The value must be between 1 to 40. 384 | * @param listener {@link ForecastListener} to get the forecast data. 385 | */ 386 | @SuppressWarnings("WeakerAccess") 387 | public static void getThreeHoursForecast(@NonNull String cityName, 388 | int limit, 389 | @NonNull final ForecastListener listener) { 390 | getThreeHoursForecast(cityName, null, limit, listener); 391 | } 392 | 393 | /** 394 | * Get weather forecast for every three hours for given city name. If the city name does not mach 395 | * to any location error will occur. This will return maximum 5 days forecast if available. 396 | * 397 | * @param cityName name of the city. (e.g. Landon) 398 | * @param countryCode ISO 3166 country code. (e.g. uk) 399 | * @param listener {@link ForecastListener} to get the forecast data. 400 | */ 401 | @SuppressWarnings("WeakerAccess") 402 | public static void getThreeHoursForecast(@NonNull String cityName, 403 | @Nullable String countryCode, 404 | @NonNull final ForecastListener listener) { 405 | getThreeHoursForecast(cityName, countryCode, NO_LIMIT, listener); 406 | } 407 | 408 | /** 409 | * Get weather forecast for every three hours for given city name. If the city name does not mach 410 | * to any location error will occur. 411 | * 412 | * @param cityName name of the city. (e.g. Landon) 413 | * @param countryCode ISO 3166 country code. (e.g. uk) 414 | * @param limit number of forecast result required. The value must be between 1 to 40. 415 | * @param listener {@link ForecastListener} to get the forecast data. 416 | */ 417 | @SuppressWarnings("WeakerAccess") 418 | public static void getThreeHoursForecast(@NonNull String cityName, 419 | @Nullable String countryCode, 420 | int limit, 421 | @NonNull final ForecastListener listener) { 422 | 423 | //Check if the sdk initialized? 424 | checkInitializeOrThrow(); 425 | 426 | APIService apiService = RetrofitBuilder.getApiService(); 427 | Observable observable = apiService 428 | .getThreeHoursForecast(countryCode == null ? cityName : (cityName + countryCode), 429 | (limit > 0 ? limit + "" : ""), sUnit, sApiKey); 430 | 431 | observable.observeOn(AndroidSchedulers.mainThread()) 432 | .subscribeOn(Schedulers.newThread()) 433 | .subscribe(new Observer() { 434 | @Override 435 | public void onCompleted() { 436 | } 437 | 438 | @Override 439 | public void onError(Throwable e) { 440 | listener.onError(e.getMessage()); 441 | } 442 | 443 | @Override 444 | public void onNext(WeatherForecast weatherForecasts) { 445 | if (weatherForecasts.getStatusCode() == SUCCESS_CODE) 446 | listener.onResponse(weatherForecasts); 447 | else listener.onError(weatherForecasts.statusMessage()); 448 | } 449 | }); 450 | } 451 | 452 | /** 453 | * Get weather forecast for every three hours for given geo point. This will return maximum 5 days forecast 454 | * if available. 455 | * 456 | * @param latitude latitude of the point 457 | * @param longitude latitude of the point 458 | * @param listener {@link ForecastListener} to listen the response 459 | */ 460 | @SuppressWarnings("WeakerAccess") 461 | public static void getThreeHoursForecast(double latitude, 462 | double longitude, 463 | @NonNull final ForecastListener listener) { 464 | getThreeHoursForecast(latitude, longitude, NO_LIMIT, listener); 465 | } 466 | 467 | /** 468 | * Get weather forecast for every three hours for given geo point. 469 | * 470 | * @param latitude latitude of the point 471 | * @param limit number of forecast result required. The value must be between 1 to 40. 472 | * @param longitude latitude of the point 473 | * @param listener {@link CurrentWeatherListener} to listen the response 474 | */ 475 | @SuppressWarnings("WeakerAccess") 476 | public static void getThreeHoursForecast(double latitude, 477 | double longitude, 478 | int limit, 479 | @NonNull final ForecastListener listener) { 480 | 481 | //Check if the sdk initialized? 482 | checkInitializeOrThrow(); 483 | 484 | APIService apiService = RetrofitBuilder.getApiService(); 485 | Observable observable = apiService 486 | .getThreeHoursForecast(latitude, longitude, 487 | (limit > 0 ? limit + "" : ""), 488 | sUnit, sApiKey); 489 | 490 | observable.observeOn(AndroidSchedulers.mainThread()) 491 | .subscribeOn(Schedulers.newThread()) 492 | .subscribe(new Observer() { 493 | @Override 494 | public void onCompleted() { 495 | } 496 | 497 | @Override 498 | public void onError(Throwable e) { 499 | listener.onError(e.getMessage()); 500 | } 501 | 502 | @Override 503 | public void onNext(WeatherForecast weatherForecasts) { 504 | if (weatherForecasts.getStatusCode() == SUCCESS_CODE) 505 | listener.onResponse(weatherForecasts); 506 | else listener.onError(weatherForecasts.statusMessage()); 507 | } 508 | }); 509 | } 510 | 511 | 512 | /*********************************************************************************************** 513 | * DAILY FORECAST FOR MAX 16 DAYS FORECAST API 514 | ***********************************************************************************************/ 515 | /** 516 | * Get daily weather forecast. This will return maximum 16 days forecast if available. 517 | * 518 | * @param cityId id of the city to get the forecast 519 | * @param listener {@link ForecastListener} to get the forecast data. 520 | */ 521 | @SuppressWarnings("WeakerAccess") 522 | public static void getDailyForecast(int cityId, 523 | @NonNull final ForecastListener listener) { 524 | getDailyForecast(cityId, NO_LIMIT, listener); 525 | } 526 | 527 | /** 528 | * Get daily weather forecast. 529 | * 530 | * @param cityId id of the city to get the forecast 531 | * @param limit number of forecast result required. The value must be between 1 to 16. 532 | * @param listener {@link ForecastListener} to get the forecast data. 533 | */ 534 | @SuppressWarnings("WeakerAccess") 535 | public static void getDailyForecast(int cityId, 536 | int limit, 537 | @NonNull final ForecastListener listener) { 538 | 539 | //Check if the sdk initialized? 540 | checkInitializeOrThrow(); 541 | 542 | APIService apiService = RetrofitBuilder.getApiService(); 543 | Observable observable = apiService 544 | .getDailyForecast(cityId, (limit > 0 ? limit + "" : ""), sUnit, sApiKey); 545 | 546 | observable.observeOn(AndroidSchedulers.mainThread()) 547 | .subscribeOn(Schedulers.newThread()) 548 | .subscribe(new Observer() { 549 | @Override 550 | public void onCompleted() { 551 | } 552 | 553 | @Override 554 | public void onError(Throwable e) { 555 | listener.onError(e.getMessage()); 556 | } 557 | 558 | @Override 559 | public void onNext(WeatherForecast weatherForecasts) { 560 | if (weatherForecasts.getStatusCode() == SUCCESS_CODE) 561 | listener.onResponse(weatherForecasts); 562 | else listener.onError(weatherForecasts.statusMessage()); 563 | } 564 | }); 565 | } 566 | 567 | /** 568 | * Get daily weather forecast. If the city name does not match to any location error will occur. 569 | * This will return maximum 16 days forecast if available. 570 | * 571 | * @param cityName name of the city. (e.g. Landon) 572 | * @param listener {@link ForecastListener} to get the forecast data. 573 | */ 574 | @SuppressWarnings("WeakerAccess") 575 | public static void getDailyForecast(@NonNull String cityName, 576 | @NonNull final ForecastListener listener) { 577 | getDailyForecast(cityName, null, NO_LIMIT, listener); 578 | } 579 | 580 | /** 581 | * Get daily weather forecast. If the city name does not match to any location error will occur. 582 | * 583 | * @param cityName name of the city. (e.g. Landon) 584 | * @param limit number of forecast result required. The value must be between 1 to 16. 585 | * @param listener {@link ForecastListener} to get the forecast data. 586 | */ 587 | @SuppressWarnings("WeakerAccess") 588 | public static void getDailyForecast(@NonNull String cityName, 589 | int limit, 590 | @NonNull final ForecastListener listener) { 591 | getDailyForecast(cityName, null, limit, listener); 592 | } 593 | 594 | /** 595 | * Get daily weather forecast. If the city name does not match to any location error will occur. 596 | * This will return maximum 16 days forecast if available. 597 | * 598 | * @param cityName name of the city. (e.g. Landon) 599 | * @param countryCode ISO 3166 country code. (e.g. uk) 600 | * @param listener {@link ForecastListener} to get the forecast data. 601 | */ 602 | @SuppressWarnings("WeakerAccess") 603 | public static void getDailyForecast(@NonNull String cityName, 604 | @Nullable String countryCode, 605 | @NonNull final ForecastListener listener) { 606 | getDailyForecast(cityName, countryCode, NO_LIMIT, listener); 607 | } 608 | 609 | /** 610 | * Get daily weather forecast. If the city name does not match to any location error will occur. 611 | * 612 | * @param cityName name of the city. (e.g. Landon) 613 | * @param countryCode ISO 3166 country code. (e.g. uk) 614 | * @param limit number of forecast result required. The value must be between 1 to 16. 615 | * @param listener {@link ForecastListener} to get the forecast data. 616 | */ 617 | @SuppressWarnings("WeakerAccess") 618 | public static void getDailyForecast(@NonNull String cityName, 619 | @Nullable String countryCode, 620 | int limit, 621 | @NonNull final ForecastListener listener) { 622 | 623 | //Check if the sdk initialized? 624 | checkInitializeOrThrow(); 625 | 626 | APIService apiService = RetrofitBuilder.getApiService(); 627 | Observable observable = apiService 628 | .getDailyForecast(countryCode == null ? cityName : (cityName + countryCode), 629 | (limit > 0 ? limit + "" : ""), sUnit, sApiKey); 630 | 631 | observable.observeOn(AndroidSchedulers.mainThread()) 632 | .subscribeOn(Schedulers.newThread()) 633 | .subscribe(new Observer() { 634 | @Override 635 | public void onCompleted() { 636 | } 637 | 638 | @Override 639 | public void onError(Throwable e) { 640 | listener.onError(e.getMessage()); 641 | } 642 | 643 | @Override 644 | public void onNext(WeatherForecast weatherForecasts) { 645 | if (weatherForecasts.getStatusCode() == SUCCESS_CODE) 646 | listener.onResponse(weatherForecasts); 647 | else listener.onError(weatherForecasts.statusMessage()); 648 | } 649 | }); 650 | } 651 | 652 | /** 653 | * Get daily weather forecast for given geo point. This will return maximum 16 days forecast if 654 | * available. 655 | * 656 | * @param latitude latitude of the point 657 | * @param longitude latitude of the point 658 | * @param listener {@link ForecastListener} to listen the response 659 | */ 660 | @SuppressWarnings("WeakerAccess") 661 | public static void getDailyForecast(double latitude, 662 | double longitude, 663 | @NonNull final ForecastListener listener) { 664 | getDailyForecast(latitude, longitude, NO_LIMIT, listener); 665 | } 666 | 667 | /** 668 | * Get daily weather forecast for given geo point. 669 | * 670 | * @param latitude latitude of the point 671 | * @param limit number of forecast result required. The value must be between 1 to 16. 672 | * @param longitude latitude of the point 673 | * @param listener {@link ForecastListener} to listen the response 674 | */ 675 | @SuppressWarnings("WeakerAccess") 676 | public static void getDailyForecast(double latitude, 677 | double longitude, 678 | int limit, 679 | @NonNull final ForecastListener listener) { 680 | 681 | //Check if the sdk initialized? 682 | checkInitializeOrThrow(); 683 | 684 | APIService apiService = RetrofitBuilder.getApiService(); 685 | Observable observable = apiService 686 | .getDailyForecast(latitude, longitude, 687 | (limit > 0 ? limit + "" : ""), 688 | sUnit, sApiKey); 689 | 690 | observable.observeOn(AndroidSchedulers.mainThread()) 691 | .subscribeOn(Schedulers.newThread()) 692 | .subscribe(new Observer() { 693 | @Override 694 | public void onCompleted() { 695 | } 696 | 697 | @Override 698 | public void onError(Throwable e) { 699 | listener.onError(e.getMessage()); 700 | } 701 | 702 | @Override 703 | public void onNext(WeatherForecast weatherForecasts) { 704 | if (weatherForecasts.getStatusCode() == SUCCESS_CODE) 705 | listener.onResponse(weatherForecasts); 706 | else listener.onError(weatherForecasts.statusMessage()); 707 | } 708 | }); 709 | } 710 | } 711 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/RetrofitBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherweapper; 18 | 19 | import android.os.Build; 20 | 21 | import okhttp3.OkHttpClient; 22 | import okhttp3.logging.HttpLoggingInterceptor; 23 | import retrofit2.Retrofit; 24 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; 25 | import retrofit2.converter.gson.GsonConverterFactory; 26 | 27 | /** 28 | * Created by Keval on 16-Jan-17. 29 | * 30 | * @author {@link 'https://github.com/kevalpatel2106'} 31 | */ 32 | 33 | class RetrofitBuilder { 34 | 35 | static APIService getApiService() { 36 | OkHttpClient client; 37 | 38 | if (BuildConfig.DEBUG) { //In sandbox environment logs will be displayed. 39 | HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); 40 | interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 41 | 42 | client = new OkHttpClient 43 | .Builder() 44 | .addInterceptor(interceptor) 45 | .build(); 46 | } else { //In production environment logs wont be available 47 | HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); 48 | interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 49 | 50 | client = new OkHttpClient.Builder() 51 | .addInterceptor(interceptor) 52 | .build(); 53 | } 54 | 55 | //Building retrofit 56 | final Retrofit retrofit = new Retrofit.Builder() 57 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 58 | .addConverterFactory(GsonConverterFactory.create()) 59 | .baseUrl(APIService.BASE_URL) 60 | .client(client) 61 | .build(); 62 | 63 | return retrofit.create(APIService.class); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/Unit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherweapper; 18 | 19 | import android.support.annotation.StringDef; 20 | 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.security.PublicKey; 24 | 25 | /** 26 | * Created by Keval on 16-Jan-17. 27 | * 28 | * @author {@link 'https://github.com/kevalpatel2106'} 29 | */ 30 | 31 | @SuppressWarnings("WeakerAccess") 32 | public class Unit { 33 | /** 34 | * Matrix units. 35 | *

36 | *

  • Temperature: Celsius
  • 37 | *
  • Speed: meter/sec
  • 38 | */ 39 | public static final String MATRIX = "metric"; 40 | 41 | /** 42 | * Standard international units. 43 | *

    44 | *

  • Temperature: Kelvin
  • 45 | *
  • Speed: meter/sec
  • 46 | */ 47 | public static final String STANDARD = ""; 48 | 49 | /** 50 | * Imperial units. 51 | *

    52 | *

  • Temperature: Fahrenheit
  • 53 | *
  • Speed: miles/hour
  • 54 | */ 55 | public static final String IMPERIAL = "imperial"; 56 | 57 | 58 | static boolean isValidUnit(String unit) { 59 | return unit == null || unit.equals(IMPERIAL) || unit.equals(MATRIX) || unit.equals(STANDARD); 60 | } 61 | 62 | @Retention(RetentionPolicy.SOURCE) 63 | @StringDef({MATRIX, IMPERIAL, STANDARD}) 64 | public @interface Units { 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/exception/InvalidApiKeyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherweapper.exception; 18 | 19 | /** 20 | * Created by Keval on 16-Jan-17. 21 | * 22 | * @author {@link 'https://github.com/kevalpatel2106'} 23 | */ 24 | 25 | public class InvalidApiKeyException extends RuntimeException { 26 | 27 | public InvalidApiKeyException(){ 28 | super("Invalid API key. Go to http://openweathermap.org/appid and generate the API key."); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/exception/NotInitilizedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherweapper.exception; 18 | 19 | /** 20 | * Created by Keval on 16-Jan-17. 21 | * 22 | * @author {@link 'https://github.com/kevalpatel2106'} 23 | */ 24 | 25 | public class NotInitilizedException extends RuntimeException { 26 | 27 | public NotInitilizedException(){ 28 | super("The library is not initialized yet. Use OpenWeatherApi.initialize() at the lunch activity of your application."); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/interfaces/CurrentWeatherListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherweapper.interfaces; 18 | 19 | import com.openweatherweapper.models.CurrentWeather; 20 | 21 | /** 22 | * Created by Keval on 16-Jan-17. 23 | * 24 | * @author {@link 'https://github.com/kevalpatel2106'} 25 | */ 26 | 27 | public interface CurrentWeatherListener { 28 | 29 | void onResponse(CurrentWeather currentWeather); 30 | 31 | void onError(String message); 32 | } 33 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/interfaces/ForecastListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherweapper.interfaces; 18 | 19 | import com.openweatherweapper.models.MultipleCitiesWeathers; 20 | import com.openweatherweapper.models.WeatherForecast; 21 | 22 | /** 23 | * Created by Keval on 16-Jan-17. 24 | * 25 | * @author {@link 'https://github.com/kevalpatel2106'} 26 | */ 27 | 28 | public interface ForecastListener { 29 | 30 | void onResponse(WeatherForecast weatherForecasts); 31 | 32 | void onError(String message); 33 | } 34 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/interfaces/MultipleCitiesWeatherListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherweapper.interfaces; 18 | 19 | import com.openweatherweapper.models.CurrentWeather; 20 | import com.openweatherweapper.models.MultipleCitiesWeathers; 21 | 22 | /** 23 | * Created by Keval on 16-Jan-17. 24 | * 25 | * @author {@link 'https://github.com/kevalpatel2106'} 26 | */ 27 | 28 | public interface MultipleCitiesWeatherListener { 29 | 30 | void onResponse(MultipleCitiesWeathers citiesWeathers); 31 | 32 | void onError(String message); 33 | } 34 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/models/CurrentWeather.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2016 Keval Patel. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.openweatherweapper.models; 19 | 20 | import com.google.gson.annotations.Expose; 21 | import com.google.gson.annotations.SerializedName; 22 | import com.openweatherweapper.models.params.Clouds; 23 | import com.openweatherweapper.models.params.Coord; 24 | import com.openweatherweapper.models.params.Main; 25 | import com.openweatherweapper.models.params.Rain; 26 | import com.openweatherweapper.models.params.Snow; 27 | import com.openweatherweapper.models.params.Sys; 28 | import com.openweatherweapper.models.params.Weather; 29 | import com.openweatherweapper.models.params.Wind; 30 | 31 | import java.util.ArrayList; 32 | import java.util.List; 33 | 34 | public class CurrentWeather { 35 | 36 | @SerializedName("coord") 37 | @Expose 38 | private Coord coordinates; 39 | @SerializedName("weather") 40 | @Expose 41 | private List weather = new ArrayList(); 42 | @SerializedName("main") 43 | @Expose 44 | private Main main; 45 | @SerializedName("visibility") 46 | @Expose 47 | private Integer visibility; 48 | @SerializedName("wind") 49 | @Expose 50 | private Wind windInfo; 51 | @SerializedName("clouds") 52 | @Expose 53 | private Clouds cloudsInfo; 54 | @SerializedName("createdDate") 55 | @Expose 56 | private long createdDate; 57 | @SerializedName("sys") 58 | @Expose 59 | private Sys sys; 60 | @SerializedName("id") 61 | @Expose 62 | private long cityId; 63 | @SerializedName("name") 64 | @Expose 65 | private String cityName; 66 | @SerializedName("rain") 67 | @Expose 68 | private Rain rainInfo; 69 | @SerializedName("snow") 70 | @Expose 71 | private Snow snowInfo; 72 | @Expose 73 | private int code; 74 | @SerializedName("message") 75 | @Expose 76 | private String message; 77 | 78 | 79 | /** 80 | * @return Coordinates 81 | * @see Coord 82 | */ 83 | public Coord getCoordinates() { 84 | return coordinates; 85 | } 86 | 87 | /** 88 | * @return Weather information 89 | * @see Weather 90 | */ 91 | public List getWeather() { 92 | return weather; 93 | } 94 | 95 | /** 96 | * @return {@link Main} 97 | * @see Main 98 | */ 99 | public Main getMain() { 100 | return main; 101 | } 102 | 103 | /** 104 | * @return The visibility 105 | */ 106 | public int getVisibility() { 107 | return visibility; 108 | } 109 | 110 | /** 111 | * @return Wind information 112 | * @see Wind 113 | */ 114 | public Wind getWindInfo() { 115 | return windInfo; 116 | } 117 | 118 | /** 119 | * @return Get cloudiness information 120 | * @see Clouds 121 | */ 122 | public Clouds getCloudsInfo() { 123 | return cloudsInfo; 124 | } 125 | 126 | /** 127 | * @return Time of data calculation, unix, UTC 128 | */ 129 | public long getCreatedDate() { 130 | return createdDate; 131 | } 132 | 133 | /** 134 | * @return System parameters 135 | * @see Sys 136 | */ 137 | public Sys getSys() { 138 | return sys; 139 | } 140 | 141 | /** 142 | * @return City id 143 | */ 144 | public long getCityId() { 145 | return cityId; 146 | } 147 | 148 | /** 149 | * @return City cityName 150 | */ 151 | public String getCityName() { 152 | return cityName; 153 | } 154 | 155 | /** 156 | * @return Rain information 157 | * @see Rain 158 | */ 159 | public Rain getRainInfo() { 160 | return rainInfo; 161 | } 162 | 163 | /** 164 | * @return Snow information 165 | * @see Snow 166 | */ 167 | public Snow getSnowInfo() { 168 | return snowInfo; 169 | } 170 | 171 | public int getStatusCode() { 172 | return code; 173 | } 174 | 175 | public String statusMessage() { 176 | return message; 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/models/MultipleCitiesWeathers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherweapper.models; 18 | 19 | import com.google.gson.annotations.Expose; 20 | import com.google.gson.annotations.SerializedName; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | /** 26 | * Created by Keval on 16-Jan-17. 27 | * 28 | * @author {@link 'https://github.com/kevalpatel2106'} 29 | */ 30 | 31 | public class MultipleCitiesWeathers { 32 | 33 | @SerializedName("cnt") 34 | @Expose 35 | private int noOfResult; 36 | @SerializedName("list") 37 | @Expose 38 | private List weatherInfos = new ArrayList<>(); 39 | @Expose 40 | private int code; 41 | @SerializedName("message") 42 | @Expose 43 | private String message; 44 | 45 | /** 46 | * @return list of {@link CurrentWeather} information for each city 47 | */ 48 | public List getWeatherInfos() { 49 | return weatherInfos; 50 | } 51 | 52 | public int getNoOfResult() { 53 | return noOfResult; 54 | } 55 | 56 | public int getStatusCode() { 57 | return code; 58 | } 59 | 60 | public String statusMessage() { 61 | return message; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/models/WeatherForecast.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherweapper.models; 18 | 19 | import com.google.gson.annotations.Expose; 20 | import com.google.gson.annotations.SerializedName; 21 | import com.openweatherweapper.models.params.City; 22 | import com.openweatherweapper.models.params.Forecast; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Created by Keval on 16-Jan-17. 28 | * 29 | * @author {@link 'https://github.com/kevalpatel2106'} 30 | */ 31 | 32 | public class WeatherForecast { 33 | 34 | @SerializedName("city") 35 | @Expose 36 | private City city; 37 | @SerializedName("cnt") 38 | @Expose 39 | private Long noOfForecastResult; 40 | @SerializedName("list") 41 | @Expose 42 | private List forecast = null; 43 | @SerializedName("cod") 44 | @Expose 45 | private int code; 46 | @SerializedName("message") 47 | @Expose 48 | private String message; 49 | 50 | /** 51 | * @return City information 52 | * @see City 53 | */ 54 | public City getCity() { 55 | return city; 56 | } 57 | 58 | public Long getNoOfForecastResult() { 59 | return noOfForecastResult; 60 | } 61 | 62 | /** 63 | * @return List of weather forecast for timed interval. 64 | * @see Forecast 65 | */ 66 | public List getForecast() { 67 | return forecast; 68 | } 69 | 70 | public int getStatusCode() { 71 | return code; 72 | } 73 | 74 | public String statusMessage() { 75 | return message; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/models/params/City.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2016 Keval Patel. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.openweatherweapper.models.params; 19 | 20 | import com.google.gson.annotations.Expose; 21 | import com.google.gson.annotations.SerializedName; 22 | 23 | public class City { 24 | 25 | @SerializedName("id") 26 | @Expose 27 | private Long id; 28 | @SerializedName("name") 29 | @Expose 30 | private String name; 31 | @SerializedName("coord") 32 | @Expose 33 | private Coord coord; 34 | @SerializedName("country") 35 | @Expose 36 | private String country; 37 | @SerializedName("population") 38 | @Expose 39 | private long population; 40 | 41 | /** 42 | * @return id of the city 43 | */ 44 | public Long getId() { 45 | return id; 46 | } 47 | 48 | /** 49 | * @return nam eof the city 50 | */ 51 | public String getName() { 52 | return name; 53 | } 54 | 55 | /** 56 | * @return Coordinates of the city 57 | * @see Coord 58 | */ 59 | public Coord getCoord() { 60 | return coord; 61 | } 62 | 63 | /** 64 | * @return ISO 3166 country code. 65 | */ 66 | public String getCountry() { 67 | return country; 68 | } 69 | 70 | /** 71 | * @return Population of the city. If not available, value will be 0. 72 | */ 73 | public Long getPopulation() { 74 | return population; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/models/params/Clouds.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2016 Keval Patel. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.openweatherweapper.models.params; 19 | 20 | import com.google.gson.annotations.Expose; 21 | import com.google.gson.annotations.SerializedName; 22 | 23 | public class Clouds { 24 | 25 | @SerializedName("all") 26 | @Expose 27 | private Double cloudiness; 28 | 29 | /** 30 | * @return Cloudiness in % 31 | */ 32 | public Double getCloudiness() { 33 | return cloudiness; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/models/params/Coord.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2016 Keval Patel. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.openweatherweapper.models.params; 19 | 20 | import com.google.gson.annotations.Expose; 21 | import com.google.gson.annotations.SerializedName; 22 | 23 | /** 24 | * Latitude and longitude coordinates for the geo point. 25 | */ 26 | public class Coord { 27 | 28 | @SerializedName("lon") 29 | @Expose 30 | private Double lon; 31 | @SerializedName("lat") 32 | @Expose 33 | private Double lat; 34 | 35 | /** 36 | * @return City geo location, longitude 37 | */ 38 | public Double getLon() { 39 | return lon; 40 | } 41 | 42 | /** 43 | * @return City geo location, latitude 44 | */ 45 | public Double getLat() { 46 | return lat; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/models/params/Forecast.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherweapper.models.params; 18 | 19 | import com.google.gson.annotations.Expose; 20 | import com.google.gson.annotations.SerializedName; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * Created by Keval on 16-Jan-17. 26 | * 27 | * @author {@link 'https://github.com/kevalpatel2106'} 28 | */ 29 | 30 | public class Forecast { 31 | @SerializedName("dt") 32 | @Expose 33 | private Long forecastTime; 34 | @SerializedName("main") 35 | @Expose 36 | private Main main; 37 | @SerializedName("weather") 38 | @Expose 39 | private List weather = null; 40 | @SerializedName("clouds") 41 | @Expose 42 | private Clouds clouds; 43 | @SerializedName("wind") 44 | @Expose 45 | private Wind wind; 46 | @SerializedName("rain") 47 | @Expose 48 | private Rain rain; 49 | 50 | /** 51 | * @return Time of data forecasted, unix, UTC 52 | */ 53 | public Long getForecastTime() { 54 | return forecastTime; 55 | } 56 | 57 | /** 58 | * @return {@link Main} 59 | * @see Main 60 | */ 61 | public Main getMain() { 62 | return main; 63 | } 64 | 65 | /** 66 | * @return Weather information 67 | * @see Weather 68 | */ 69 | public List getWeather() { 70 | return weather; 71 | } 72 | 73 | /** 74 | * @return Get cloudiness information 75 | * @see Clouds 76 | */ 77 | public Clouds getClouds() { 78 | return clouds; 79 | } 80 | 81 | /** 82 | * @return Wind information 83 | * @see Wind 84 | */ 85 | public Wind getWind() { 86 | return wind; 87 | } 88 | 89 | /** 90 | * @return Rain information 91 | * @see Rain 92 | */ 93 | public Rain getRain() { 94 | return rain; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/models/params/Main.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2016 Keval Patel. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.openweatherweapper.models.params; 19 | 20 | import com.google.gson.annotations.Expose; 21 | import com.google.gson.annotations.SerializedName; 22 | 23 | public class Main { 24 | 25 | @SerializedName("temp") 26 | @Expose 27 | private Double temp; 28 | @SerializedName("pressure") 29 | @Expose 30 | private Double pressure; 31 | @SerializedName("humidity") 32 | @Expose 33 | private Double humidity; 34 | @SerializedName("temp_min") 35 | @Expose 36 | private Double tempMin; 37 | @SerializedName("temp_max") 38 | @Expose 39 | private Double tempMax; 40 | @SerializedName("sea_level") 41 | @Expose 42 | private Double seaLevelPressure; 43 | @SerializedName("grnd_level") 44 | @Expose 45 | private Double groundLevelPressure; 46 | 47 | /** 48 | * @return Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit. 49 | */ 50 | public Double getTemp() { 51 | return temp; 52 | } 53 | 54 | /** 55 | * @return Atmospheric pressure (on the sea level, if there is no sea_level or grnd_level data), hPa 56 | */ 57 | public Double getPressure() { 58 | return pressure; 59 | } 60 | 61 | /** 62 | * @return Humidity, % 63 | */ 64 | public Double getHumidity() { 65 | return humidity; 66 | } 67 | 68 | /** 69 | * This is the optional params. 70 | * 71 | * @return Minimum temperature at the moment. This is deviation from current temp that is possible 72 | * for large cities and megalopolises geographically expanded (use these parameter optionally). 73 | * Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit. 74 | */ 75 | public Double getTempMin() { 76 | return tempMin; 77 | } 78 | 79 | /** 80 | * This is the optional params. 81 | * 82 | * @return Maximum temperature at the moment. This is deviation from current temp that is possible 83 | * for large cities and megalopolises geographically expanded (use these parameter optionally). 84 | * Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit. 85 | */ 86 | public Double getTempMax() { 87 | return tempMax; 88 | } 89 | 90 | /** 91 | * @return Atmospheric pressure on the sea level, hPa 92 | */ 93 | public Double getSeaLevelPressure() { 94 | return seaLevelPressure; 95 | } 96 | 97 | /** 98 | * @return Atmospheric pressure on the ground level, hPa 99 | */ 100 | public Double getGroundLevelPressure() { 101 | return groundLevelPressure; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/models/params/Rain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherweapper.models.params; 18 | 19 | import com.google.gson.annotations.Expose; 20 | import com.google.gson.annotations.SerializedName; 21 | 22 | /** 23 | * Created by Keval on 16-Jan-17. 24 | * 25 | * @author {@link 'https://github.com/kevalpatel2106'} 26 | */ 27 | 28 | public class Rain { 29 | 30 | @SerializedName("3h") 31 | @Expose 32 | private Double last3hVolume; 33 | 34 | /** 35 | * @return Rain volume for the last 3 hours 36 | */ 37 | public Double getLast3hVolume() { 38 | return last3hVolume; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/models/params/Snow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherweapper.models.params; 18 | 19 | import com.google.gson.annotations.Expose; 20 | import com.google.gson.annotations.SerializedName; 21 | 22 | /** 23 | * Created by Keval on 16-Jan-17. 24 | * 25 | * @author {@link 'https://github.com/kevalpatel2106'} 26 | */ 27 | 28 | public class Snow { 29 | 30 | @SerializedName("3h") 31 | @Expose 32 | private Double last3hVolume; 33 | 34 | /** 35 | * @return Snow volume for the last 3 hours 36 | */ 37 | public Double getLast3hVolume() { 38 | return last3hVolume; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/models/params/Sys.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2016 Keval Patel. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.openweatherweapper.models.params; 19 | 20 | import com.google.gson.annotations.Expose; 21 | import com.google.gson.annotations.SerializedName; 22 | 23 | public class Sys { 24 | @SerializedName("country") 25 | @Expose 26 | private String country; 27 | @SerializedName("sunrise") 28 | @Expose 29 | private Long sunrise; 30 | @SerializedName("sunset") 31 | @Expose 32 | private Long sunset; 33 | 34 | /** 35 | * @return Country code (GB, JP etc.) 36 | */ 37 | public String getCountry() { 38 | return country; 39 | } 40 | 41 | /** 42 | * @return Sunrise time, unix, UTC 43 | */ 44 | public Long getSunrise() { 45 | return sunrise; 46 | } 47 | 48 | /** 49 | * @return Sunset time, unix, UTC 50 | */ 51 | public Long getSunset() { 52 | return sunset; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/models/params/Weather.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2016 Keval Patel. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.openweatherweapper.models.params; 19 | 20 | import com.google.gson.annotations.Expose; 21 | import com.google.gson.annotations.SerializedName; 22 | 23 | /** 24 | * This class contains more info Weather condition codes. 25 | * 26 | * @author {@link 'https://github.com/kevalpatel2106'}x 27 | */ 28 | public class Weather { 29 | 30 | @SerializedName("id") 31 | @Expose 32 | private long id; 33 | @SerializedName("main") 34 | @Expose 35 | private String main; 36 | @SerializedName("description") 37 | @Expose 38 | private String description; 39 | @SerializedName("icon") 40 | @Expose 41 | private String icon; 42 | 43 | /** 44 | * @return Weather condition id 45 | */ 46 | public long getId() { 47 | return id; 48 | } 49 | 50 | /** 51 | * @return Group of weather parameters (Rain, Snow, Extreme etc.) 52 | */ 53 | public String getMain() { 54 | return main; 55 | } 56 | 57 | /** 58 | * @return Weather condition within the group 59 | */ 60 | public String getDescription() { 61 | return description; 62 | } 63 | 64 | /** 65 | * @return Weather icon id 66 | */ 67 | public String getIcon() { 68 | return icon; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /open-weather-wrapper/src/main/java/com/openweatherweapper/models/params/Wind.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2016 Keval Patel. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.openweatherweapper.models.params; 19 | 20 | import com.google.gson.annotations.Expose; 21 | import com.google.gson.annotations.SerializedName; 22 | 23 | /** 24 | * Wind information. 25 | * 26 | * @author {@link 'https://github.com/kevalpatel2106'} 27 | */ 28 | public class Wind { 29 | 30 | @SerializedName("speed") 31 | @Expose 32 | private Double speed; 33 | @SerializedName("deg") 34 | @Expose 35 | private Double degree; 36 | 37 | /** 38 | * @return Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour. 39 | */ 40 | public Double getSpeed() { 41 | return speed; 42 | } 43 | 44 | /** 45 | * @return Wind direction, degrees (meteorological) 46 | */ 47 | public Double getDegree() { 48 | return degree; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.android.application' 18 | 19 | android { 20 | compileSdkVersion 25 21 | buildToolsVersion "25.0.2" 22 | 23 | lintOptions {//5ae14346421dddcb597ebcf1e3579d83 24 | abortOnError false 25 | } 26 | 27 | defaultConfig { 28 | applicationId "com.openweatherapi.sample" 29 | minSdkVersion 14 30 | targetSdkVersion 25 31 | versionCode 1 32 | versionName "1.0" 33 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 34 | } 35 | buildTypes { 36 | release { 37 | minifyEnabled false 38 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 39 | } 40 | } 41 | } 42 | 43 | dependencies { 44 | compile project(':open-weather-wrapper') 45 | 46 | compile fileTree(dir: 'libs', include: ['*.jar']) 47 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 48 | exclude group: 'com.android.support', module: 'support-annotations' 49 | }) 50 | compile 'com.android.support:appcompat-v7:25.1.0' 51 | testCompile 'junit:junit:4.12' 52 | } -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Keval\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/openweatherapi/sample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.openweatherapi.sample; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.openweatherapi.sample", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 21 | 22 | 23 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /sample/src/main/java/com/openweatherapi/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Keval Patel. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.openweatherapi.sample; 18 | 19 | import android.os.Bundle; 20 | import android.support.v7.app.AppCompatActivity; 21 | import android.util.Log; 22 | import android.view.View; 23 | import android.widget.EditText; 24 | import android.widget.TextView; 25 | import android.widget.Toast; 26 | 27 | import com.openweatherweapper.OpenWeatherApi; 28 | import com.openweatherweapper.Unit; 29 | import com.openweatherweapper.interfaces.CurrentWeatherListener; 30 | import com.openweatherweapper.interfaces.ForecastListener; 31 | import com.openweatherweapper.models.CurrentWeather; 32 | import com.openweatherweapper.models.WeatherForecast; 33 | 34 | import java.text.SimpleDateFormat; 35 | import java.util.Locale; 36 | 37 | public class MainActivity extends AppCompatActivity { 38 | 39 | private TextView sunsetTv; 40 | private TextView sunriseTv; 41 | private TextView windSpeedTv; 42 | private TextView tempLowTv; 43 | private TextView tempHighTv; 44 | private TextView cityTv; 45 | private TextView tempTv; 46 | 47 | private CurrentWeatherListener mCurrentWeatherListener = new CurrentWeatherListener() { 48 | @Override 49 | public void onResponse(CurrentWeather currentWeather) { 50 | cityTv.setText(currentWeather.getCityName()); 51 | 52 | //set the temperature 53 | tempHighTv.setText(currentWeather.getMain().getTempMax() + " " + getString(R.string.degree_fernhight)); 54 | tempLowTv.setText(currentWeather.getMain().getTempMin() + " " + getString(R.string.degree_fernhight)); 55 | tempTv.setText(currentWeather.getMain().getTemp() + " " + getString(R.string.degree_fernhight)); 56 | 57 | windSpeedTv.setText(currentWeather.getWindInfo().getSpeed() + " km/s"); 58 | 59 | SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm a", Locale.getDefault()); 60 | sunriseTv.setText(dateFormat.format(currentWeather.getSys().getSunrise())); 61 | sunsetTv.setText(dateFormat.format(currentWeather.getSys().getSunset())); 62 | } 63 | 64 | @Override 65 | public void onError(String message) { 66 | Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show(); 67 | } 68 | }; 69 | 70 | @Override 71 | protected void onCreate(Bundle savedInstanceState) { 72 | super.onCreate(savedInstanceState); 73 | setContentView(R.layout.activity_main); 74 | 75 | //Initialize the api 76 | OpenWeatherApi.initialize(getString(R.string.your_open_weather_api_key), Unit.STANDARD); 77 | 78 | cityTv = (TextView) findViewById(R.id.city_tv); 79 | tempTv = (TextView) findViewById(R.id.temp_tv); 80 | tempLowTv = (TextView) findViewById(R.id.temp_low_tv); 81 | tempHighTv = (TextView) findViewById(R.id.temp_high_tv); 82 | windSpeedTv = (TextView) findViewById(R.id.wind_speed_tv); 83 | sunriseTv = (TextView) findViewById(R.id.sunrise_tv); 84 | sunsetTv = (TextView) findViewById(R.id.sunset_tv); 85 | 86 | final EditText cityEt = (EditText) findViewById(R.id.city_et); 87 | 88 | findViewById(R.id.go_btn).setOnClickListener(new View.OnClickListener() { 89 | @Override 90 | public void onClick(View view) { 91 | String s = cityEt.getText().toString().trim(); 92 | if (!s.isEmpty()) 93 | OpenWeatherApi.getCurrentWeather(s, mCurrentWeatherListener); 94 | 95 | OpenWeatherApi.getThreeHoursForecast("Landon,uk", new ForecastListener() { 96 | @Override 97 | public void onResponse(WeatherForecast weatherForecasts) { 98 | Log.d("Three hour", "Success"); 99 | } 100 | 101 | @Override 102 | public void onError(String message) { 103 | Log.d("Three hour", message); 104 | } 105 | }); 106 | } 107 | }); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 29 | 30 |