├── .gitignore ├── .idea ├── caches │ ├── build_file_checksums.ser │ └── gradle_models.ser ├── codeStyles │ └── Project.xml ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── jarRepositories.xml ├── markdown-navigator.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── openweathermaphelper ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── kwabenaberko │ │ └── openweathermaplib │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── kwabenaberko │ │ │ └── openweathermaplib │ │ │ ├── constant │ │ │ ├── Languages.java │ │ │ └── Units.java │ │ │ ├── implementation │ │ │ ├── OpenWeatherMapHelper.java │ │ │ └── callback │ │ │ │ ├── CurrentWeatherCallback.java │ │ │ │ └── ThreeHourForecastCallback.java │ │ │ ├── model │ │ │ ├── common │ │ │ │ ├── Clouds.java │ │ │ │ ├── Coord.java │ │ │ │ ├── Main.java │ │ │ │ ├── Precipitation.java │ │ │ │ ├── Rain.java │ │ │ │ ├── Snow.java │ │ │ │ ├── Sys.java │ │ │ │ ├── Weather.java │ │ │ │ └── Wind.java │ │ │ ├── currentweather │ │ │ │ └── CurrentWeather.java │ │ │ └── threehourforecast │ │ │ │ ├── City.java │ │ │ │ ├── ThreeHourForecast.java │ │ │ │ └── ThreeHourForecastWeather.java │ │ │ └── network │ │ │ ├── OpenWeatherMapClient.java │ │ │ └── OpenWeatherMapService.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── kwabenaberko │ └── openweathermaplib │ └── ExampleUnitTest.java ├── projectFilesBackup └── .idea │ └── workspace.xml ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── kwabenaberko │ │ └── openweathermap │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── kwabenaberko │ │ │ └── openweathermap │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── kwabenaberko │ └── openweathermap │ └── 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 | /app/src/main/res/values/strings.xml 11 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KwabenBerko/OpenWeatherMap-Android-Library/4f503f8819874b5ce72e4edda4d5002bf6bdbe96/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/caches/gradle_models.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KwabenBerko/OpenWeatherMap-Android-Library/4f503f8819874b5ce72e4edda4d5002bf6bdbe96/.idea/caches/gradle_models.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | xmlns:android 14 | 15 | ^$ 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | xmlns:.* 25 | 26 | ^$ 27 | 28 | 29 | BY_NAME 30 | 31 |
32 |
33 | 34 | 35 | 36 | .*:id 37 | 38 | http://schemas.android.com/apk/res/android 39 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | .*:name 48 | 49 | http://schemas.android.com/apk/res/android 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | name 59 | 60 | ^$ 61 | 62 | 63 | 64 |
65 |
66 | 67 | 68 | 69 | style 70 | 71 | ^$ 72 | 73 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | .* 81 | 82 | ^$ 83 | 84 | 85 | BY_NAME 86 | 87 |
88 |
89 | 90 | 91 | 92 | .* 93 | 94 | http://schemas.android.com/apk/res/android 95 | 96 | 97 | ANDROID_ATTRIBUTE_ORDER 98 | 99 |
100 |
101 | 102 | 103 | 104 | .* 105 | 106 | .* 107 | 108 | 109 | BY_NAME 110 | 111 |
112 |
113 |
114 |
115 |
116 |
-------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 23 | 24 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 57 | 58 | 59 | 60 | 61 | 1.8 62 | 63 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Kwabena Bio Berko 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## OpenWeatherMap-Android-Library 3 | [![](https://jitpack.io/v/KwabenBerko/OpenWeatherMap-Android-Library.svg)](https://jitpack.io/#KwabenBerko/OpenWeatherMap-Android-Library) 4 | 5 | 6 | **You need an API Key to use the OpenWeatherMap API. Head on over to their [website](http://openweathermap.org/) if you don't already have one.** 7 | 8 | 9 | ## Download 10 | 11 | #### Step 1. Add the JitPack repository to your root ```build.gradle``` file. 12 | 13 | ``` java 14 | allprojects { 15 | repositories { 16 | ... 17 | maven { url 'https://jitpack.io' } 18 | } 19 | } 20 | ``` 21 | 22 | #### Step 2 : Download via ```Gradle```: 23 | 24 | ```java 25 | implementation 'com.github.KwabenBerko:OpenWeatherMap-Android-Library:2.1.0' 26 | ``` 27 | 28 | **Note: Remember to include the INTERNET permission to your manifest file** 29 | 30 | ## Usage 31 | 32 | #### Instantiate Class With Your OpenWeatherMap Api Key 33 | 34 | ``` java 35 | OpenWeatherMapHelper helper = new OpenWeatherMapHelper(getString(R.string.OPEN_WEATHER_MAP_API_KEY)); 36 | ``` 37 | 38 | #### Set your Units (Optional, STANDARD by default) 39 | 40 | ``` java 41 | helper.setUnits(Units.IMPERIAL); 42 | ``` 43 | 44 | ##### Unit Options: 45 | 46 | 1. ```Units.IMPERIAL (Fahrenheit)``` 47 | 48 | 2. ```Units.METRIC (Celsius)``` 49 | 50 | #### Set your Language (ENGLISH by default) 51 | 52 | ``` java 53 | helper.setLanguage(Languages.ENGLISH); 54 | ``` 55 | 56 | ## Features 57 | 58 | 59 | ### (1) Current Weather 60 | #### Get current weather by City Name: 61 | 62 | ```java 63 | helper.getCurrentWeatherByCityName("Accra", new CurrentWeatherCallback() { 64 | @Override 65 | public void onSuccess(CurrentWeather currentWeather) { 66 | Log.v(TAG, "Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon() +"\n" 67 | +"Weather Description: " + currentWeather.getWeather().get(0).getDescription() + "\n" 68 | +"Temperature: " + currentWeather.getMain().getTempMax()+"\n" 69 | +"Wind Speed: " + currentWeather.getWind().getSpeed() + "\n" 70 | +"City, Country: " + currentWeather.getName() + ", " + currentWeather.getSys().getCountry() 71 | ); 72 | } 73 | 74 | @Override 75 | public void onFailure(Throwable throwable) { 76 | Log.v(TAG, throwable.getMessage()); 77 | } 78 | }); 79 | ``` 80 | 81 | #### Get current weather by City ID: 82 | ```java 83 | helper.getCurrentWeatherByCityID("524901", new CurrentWeatherCallback() { 84 | @Override 85 | public void onSuccess(CurrentWeather currentWeather) { 86 | Log.v(TAG, "Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon() +"\n" 87 | +"Weather Description: " + currentWeather.getWeather().get(0).getDescription() + "\n" 88 | +"Temperature: " + currentWeather.getMain().getTempMax()+"\n" 89 | +"Wind Speed: " + currentWeather.getWind().getSpeed() + "\n" 90 | +"City, Country: " + currentWeather.getName() + ", " + currentWeather.getSys().getCountry() 91 | ); 92 | } 93 | 94 | @Override 95 | public void onFailure(Throwable throwable) { 96 | Log.v(TAG, throwable.getMessage()); 97 | } 98 | }); 99 | ``` 100 | #### Get current weather by Geographic Coordinates: 101 | 102 | ```java 103 | helper.getCurrentWeatherByGeoCoordinates(5.6037, 0.1870, new CurrentWeatherCallback() { 104 | @Override 105 | public void onSuccess(CurrentWeather currentWeather) { 106 | Log.v(TAG, "Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon() +"\n" 107 | +"Weather Description: " + currentWeather.getWeather().get(0).getDescription() + "\n" 108 | +"Temperature: " + currentWeather.getMain().getTempMax()+"\n" 109 | +"Wind Speed: " + currentWeather.getWind().getSpeed() + "\n" 110 | +"City, Country: " + currentWeather.getName() + ", " + currentWeather.getSys().getCountry() 111 | ); 112 | } 113 | 114 | @Override 115 | public void onFailure(Throwable throwable) { 116 | Log.v(TAG, throwable.getMessage()); 117 | } 118 | }); 119 | ``` 120 | #### Get current weather by Zip Code: 121 | ```java 122 | helper.getCurrentWeatherByZipCode("90003", new CurrentWeatherCallback() { 123 | @Override 124 | public void onSuccess(CurrentWeather currentWeather) { 125 | Log.v(TAG, "Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon() +"\n" 126 | +"Weather Description: " + currentWeather.getWeather().get(0).getDescription() + "\n" 127 | +"Temperature: " + currentWeather.getMain().getTempMax()+"\n" 128 | +"Wind Speed: " + currentWeather.getWind().getSpeed() + "\n" 129 | +"City, Country: " + currentWeather.getName() + ", " + currentWeather.getSys().getCountry() 130 | ); 131 | } 132 | 133 | @Override 134 | public void onFailure(Throwable throwable) { 135 | Log.v(TAG, throwable.getMessage()); 136 | } 137 | }); 138 | ``` 139 | ### (2) 5 day / 3 hour forecast 140 | #### Get three hour forecast by City Name: 141 | ```java 142 | helper.getThreeHourForecastByCityName("Pretoria", new ThreeHourForecastCallback() { 143 | @Override 144 | public void onSuccess(ThreeHourForecast threeHourForecast) { 145 | Log.v(TAG, "City/Country: "+ threeHourForecast.getCity().getName() + "/" + threeHourForecast.getCity().getCountry() +"\n" 146 | +"Forecast Array Count: " + threeHourForecast.getCnt() +"\n" 147 | //For this example, we are logging details of only the first forecast object in the forecasts array 148 | +"First Forecast Date Timestamp: " + threeHourForecast.getList().get(0).getDt() +"\n" 149 | +"First Forecast Weather Description: " + threeHourForecast.getList().get(0).getWeather().get(0).getDescription()+ "\n" 150 | +"First Forecast Max Temperature: " + threeHourForecast.getList().get(0).getMain().getTempMax()+"\n" 151 | +"First Forecast Wind Speed: " + threeHourForecast.getList().get(0).getWind().getSpeed() + "\n" 152 | ); 153 | } 154 | 155 | @Override 156 | public void onFailure(Throwable throwable) { 157 | Log.v(TAG, throwable.getMessage()); 158 | } 159 | }); 160 | ``` 161 | #### Get three hour forecast by City ID: 162 | ```java 163 | helper.getThreeHourForecastByCityID("524901", new ThreeHourForecastCallback() { 164 | @Override 165 | public void onSuccess(ThreeHourForecast threeHourForecast) { 166 | Log.v(TAG, "City/Country: "+ threeHourForecast.getCity().getName() + "/" + threeHourForecast.getCity().getCountry() +"\n" 167 | +"Forecast Array Count: " + threeHourForecast.getCnt() +"\n" 168 | //For this example, we are logging details of only the first forecast object in the forecasts array 169 | +"First Forecast Date Timestamp: " + threeHourForecast.getList().get(0).getDt() +"\n" 170 | +"First Forecast Weather Description: " + threeHourForecast.getList().get(0).getWeather().get(0).getDescription()+ "\n" 171 | +"First Forecast Max Temperature: " + threeHourForecast.getList().get(0).getMain().getTempMax()+"\n" 172 | +"First Forecast Wind Speed: " + threeHourForecast.getList().get(0).getWind().getSpeed() + "\n" 173 | ); 174 | } 175 | 176 | @Override 177 | public void onFailure(Throwable throwable) { 178 | Log.v(TAG, throwable.getMessage()); 179 | } 180 | }); 181 | ``` 182 | #### Get three hour forecast by Geographic Coordinates: 183 | ```java 184 | helper.getThreeHourForecastByGeoCoordinates(6.5244,3.3792, new ThreeHourForecastCallback() { 185 | @Override 186 | public void onSuccess(ThreeHourForecast threeHourForecast) { 187 | Log.v(TAG, "City/Country: "+ threeHourForecast.getCity().getName() + "/" + threeHourForecast.getCity().getCountry() +"\n" 188 | +"Forecast Array Count: " + threeHourForecast.getCnt() +"\n" 189 | //For this example, we are logging details of only the first forecast object in the forecasts array 190 | +"First Forecast Date Timestamp: " + threeHourForecast.getList().get(0).getDt() +"\n" 191 | +"First Forecast Weather Description: " + threeHourForecast.getList().get(0).getWeather().get(0).getDescription()+ "\n" 192 | +"First Forecast Max Temperature: " + threeHourForecast.getList().get(0).getMain().getTempMax()+"\n" 193 | +"First Forecast Wind Speed: " + threeHourForecast.getList().get(0).getWind().getSpeed() + "\n" 194 | ); 195 | } 196 | 197 | @Override 198 | public void onFailure(Throwable throwable) { 199 | Log.v(TAG, throwable.getMessage()); 200 | } 201 | }); 202 | ``` 203 | #### Get three hour forecast by Zip Code: 204 | ```java 205 | helper.getThreeHourForecastByZipCode("94040", new ThreeHourForecastCallback() { 206 | @Override 207 | public void onSuccess(ThreeHourForecast threeHourForecast) { 208 | Log.v(TAG, "City/Country: "+ threeHourForecast.getCity().getName() + "/" + threeHourForecast.getCity().getCountry() +"\n" 209 | +"Forecast Array Count: " + threeHourForecast.getCnt() +"\n" 210 | //For this example, we are logging details of only the first forecast object in the forecasts array 211 | +"First Forecast Date Timestamp: " + threeHourForecast.getList().get(0).getDt() +"\n" 212 | +"First Forecast Weather Description: " + threeHourForecast.getList().get(0).getWeather().get(0).getDescription()+ "\n" 213 | +"First Forecast Max Temperature: " + threeHourForecast.getList().get(0).getMain().getTempMax()+"\n" 214 | +"First Forecast Wind Speed: " + threeHourForecast.getList().get(0).getWind().getSpeed() + "\n" 215 | ); 216 | } 217 | 218 | @Override 219 | public void onFailure(Throwable throwable) { 220 | Log.v(TAG, throwable.getMessage()); 221 | } 222 | }); 223 | ``` 224 | 225 | 226 | 227 | 228 | 229 | ### Upcoming Features 230 | 1. Hourly Forecast 4 days 231 | 2. Daily Forecast 16 days 232 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | google() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.4.0' 10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | jcenter() 20 | google() 21 | maven { url 'https://jitpack.io' } 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | android.enableJetifier=true 13 | android.useAndroidX=true 14 | org.gradle.jvmargs=-Xmx1536m 15 | 16 | # When configured, Gradle will run in incubating parallel mode. 17 | # This option should only be used with decoupled projects. More details, visit 18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 19 | # org.gradle.parallel=true 20 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KwabenBerko/OpenWeatherMap-Android-Library/4f503f8819874b5ce72e4edda4d5002bf6bdbe96/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Apr 25 20:34:19 GMT 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /openweathermaphelper/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /openweathermaphelper/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | group = 'com.github.KwabenBerko' 4 | 5 | 6 | android { 7 | compileSdkVersion 29 8 | 9 | defaultConfig { 10 | minSdkVersion 15 11 | targetSdkVersion 29 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(dir: 'libs', include: ['*.jar']) 28 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { 29 | exclude group: 'com.android.support', module: 'support-annotations' 30 | }) 31 | implementation 'androidx.appcompat:appcompat:1.2.0' 32 | implementation 'com.squareup.retrofit2:retrofit:2.9.0' 33 | implementation 'com.squareup.retrofit2:converter-gson:2.9.0' 34 | testImplementation 'junit:junit:4.13.1' 35 | } 36 | 37 | -------------------------------------------------------------------------------- /openweathermaphelper/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\PAVILION 15\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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /openweathermaphelper/src/androidTest/java/com/kwabenaberko/openweathermaplib/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib; 2 | 3 | import android.content.Context; 4 | import androidx.test.platform.app.InstrumentationRegistry; 5 | import androidx.test.ext.junit.runners.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.kwabenaberko.openweathermaplib.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/constant/Languages.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.constant; 2 | 3 | public class Languages { 4 | 5 | public static final String AFRIKAANS = "af"; 6 | public static final String ALBANIAN = "al"; 7 | public static final String ARABIC = "ar"; 8 | public static final String AZERBAIJANI = "az"; 9 | public static final String BULGARIAN = "bg"; 10 | public static final String CATALAN = "ca"; 11 | public static final String CZECH = "cz"; 12 | public static final String DANISH = "da"; 13 | public static final String GERMAN = "de"; 14 | public static final String GREEK = "el"; 15 | public static final String ENGLISH = "en"; 16 | public static final String BASQUE = "eu"; 17 | public static final String PERSIAN = "fa"; 18 | public static final String FINNISH = "fi"; 19 | public static final String FRENCH = "fr"; 20 | public static final String GALICIAN = "gl"; 21 | public static final String HEBREW = "he"; 22 | public static final String HINDI = "hi"; 23 | public static final String CROATIAN = "hr"; 24 | public static final String HUNGARIAN = "hu"; 25 | public static final String INDONESIAN = "id"; 26 | public static final String ITALIAN = "it"; 27 | public static final String JAPANESE = "ja"; 28 | public static final String KOREAN = "kr"; 29 | public static final String LATVIAN = "la"; 30 | public static final String LITHUANIAN = "lt"; 31 | public static final String MACEDONIAN = "mk"; 32 | public static final String NORWEGIAN = "no"; 33 | public static final String DUTCH = "nl"; 34 | public static final String POLISH = "pl"; 35 | public static final String PORTUGUESE = "pt"; 36 | public static final String PORTUGUES_BRASIL = "pt_br"; 37 | public static final String ROMANIAN = "ro"; 38 | public static final String RUSSIAN = "ru"; 39 | public static final String SWEDISH = "se"; 40 | public static final String SLOVAK = "sk"; 41 | public static final String SLOVENIAN = "sl"; 42 | public static final String SPANISH = "es"; 43 | public static final String SERBIAN = "sr"; 44 | public static final String THAI = "th"; 45 | public static final String TURKISH = "tr"; 46 | public static final String UKRAINIAN = "ua"; 47 | public static final String VIETNAMESE = "vi"; 48 | public static final String CHINESE_SIMPLIFIED = "zh_cn"; 49 | public static final String CHINESE_TRADITIONAL = "zh_tw"; 50 | public static final String ZULU = "zu"; 51 | } 52 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/constant/Units.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.constant; 2 | 3 | /** 4 | * Created by Kwabena Berko on 8/6/2017. 5 | */ 6 | 7 | public class Units { 8 | public static final String METRIC = "metric"; 9 | public static final String IMPERIAL = "imperial"; 10 | } 11 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/implementation/OpenWeatherMapHelper.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.implementation; 2 | 3 | import android.util.Log; 4 | 5 | import androidx.annotation.NonNull; 6 | 7 | import com.kwabenaberko.openweathermaplib.implementation.callback.CurrentWeatherCallback; 8 | import com.kwabenaberko.openweathermaplib.implementation.callback.ThreeHourForecastCallback; 9 | import com.kwabenaberko.openweathermaplib.model.currentweather.CurrentWeather; 10 | import com.kwabenaberko.openweathermaplib.model.threehourforecast.ThreeHourForecast; 11 | import com.kwabenaberko.openweathermaplib.network.OpenWeatherMapClient; 12 | import com.kwabenaberko.openweathermaplib.network.OpenWeatherMapService; 13 | 14 | import org.json.JSONException; 15 | import org.json.JSONObject; 16 | 17 | import java.io.IOException; 18 | import java.net.HttpURLConnection; 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | import retrofit2.Call; 23 | import retrofit2.Callback; 24 | import retrofit2.Response; 25 | 26 | /** 27 | * Created by Kwabena Berko on 7/25/2017. 28 | */ 29 | 30 | public class OpenWeatherMapHelper { 31 | 32 | private static final String APPID = "appId"; 33 | private static final String UNITS = "units"; 34 | private static final String LANGUAGE = "lang"; 35 | private static final String QUERY = "q"; 36 | private static final String CITY_ID = "id"; 37 | private static final String LATITUDE = "lat"; 38 | private static final String LONGITUDE = "lon"; 39 | private static final String ZIP_CODE = "zip"; 40 | 41 | private final OpenWeatherMapService openWeatherMapService; 42 | private final Map options; 43 | 44 | 45 | public OpenWeatherMapHelper(String apiKey){ 46 | openWeatherMapService = OpenWeatherMapClient.getClient().create(OpenWeatherMapService.class); 47 | options = new HashMap<>(); 48 | options.put(APPID, apiKey == null ? "" : apiKey); 49 | } 50 | 51 | 52 | //SETUP METHODS 53 | public void setUnits(String units){ 54 | options.put(UNITS, units); 55 | } 56 | public void setLanguage(String lang) { 57 | options.put(LANGUAGE, lang); 58 | } 59 | 60 | 61 | private Throwable NoAppIdErrMessage() { 62 | return new Throwable("UnAuthorized. Please set a valid OpenWeatherMap API KEY."); 63 | } 64 | 65 | 66 | private Throwable NotFoundErrMsg(String str) { 67 | Throwable throwable = null; 68 | try { 69 | JSONObject obj = new JSONObject(str); 70 | throwable = new Throwable(obj.getString("message")); 71 | } catch (JSONException e) { 72 | e.printStackTrace(); 73 | } 74 | 75 | if (throwable == null){ 76 | throwable = new Throwable("An unexpected error occurred."); 77 | } 78 | 79 | 80 | return throwable; 81 | } 82 | 83 | // CURRENT WEATHER METHODS 84 | // START 85 | 86 | //GET CURRENT WEATHER BY CITY NAME 87 | public void getCurrentWeatherByCityName(String city, final CurrentWeatherCallback callback){ 88 | options.put(QUERY, city); 89 | 90 | openWeatherMapService.getCurrentWeatherByCityName(options).enqueue(new Callback() { 91 | @Override 92 | public void onResponse(@NonNull Call call, @NonNull Response response) { 93 | handleCurrentWeatherResponse(response, callback); 94 | } 95 | 96 | @Override 97 | public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { 98 | callback.onFailure(throwable); 99 | } 100 | }); 101 | } 102 | 103 | //GET CURRENT WEATHER BY CITY ID 104 | public void getCurrentWeatherByCityID(String id, final CurrentWeatherCallback callback){ 105 | options.put(CITY_ID, id); 106 | openWeatherMapService.getCurrentWeatherByCityID(options).enqueue(new Callback() { 107 | @Override 108 | public void onResponse(Call call, Response response) { 109 | handleCurrentWeatherResponse(response, callback); 110 | } 111 | 112 | @Override 113 | public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { 114 | callback.onFailure(throwable); 115 | } 116 | }); 117 | 118 | } 119 | 120 | //GET CURRENT WEATHER BY GEOGRAPHIC COORDINATES 121 | public void getCurrentWeatherByGeoCoordinates(double latitude, double longitude, final CurrentWeatherCallback callback){ 122 | options.put(LATITUDE, String.valueOf(latitude)); 123 | options.put(LONGITUDE, String.valueOf(longitude)); 124 | openWeatherMapService.getCurrentWeatherByGeoCoordinates(options).enqueue(new Callback() { 125 | @Override 126 | public void onResponse(Call call, Response response) { 127 | handleCurrentWeatherResponse(response, callback); 128 | } 129 | 130 | @Override 131 | public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { 132 | callback.onFailure(throwable); 133 | } 134 | }); 135 | } 136 | 137 | //GET CURRENT WEATHER BY ZIP CODE 138 | 139 | public void getCurrentWeatherByZipCode(String zipCode, final CurrentWeatherCallback callback){ 140 | options.put(ZIP_CODE, zipCode); 141 | openWeatherMapService.getCurrentWeatherByZipCode(options).enqueue(new Callback() { 142 | @Override 143 | public void onResponse(Call call, Response response) { 144 | handleCurrentWeatherResponse(response, callback); 145 | } 146 | 147 | @Override 148 | public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { 149 | callback.onFailure(throwable); 150 | } 151 | }); 152 | } 153 | 154 | private void handleCurrentWeatherResponse(Response response, CurrentWeatherCallback callback){ 155 | if (response.code() == HttpURLConnection.HTTP_OK){ 156 | callback.onSuccess(response.body()); 157 | } 158 | else if (response.code() == HttpURLConnection.HTTP_FORBIDDEN || response.code() == HttpURLConnection.HTTP_UNAUTHORIZED){ 159 | callback.onFailure(NoAppIdErrMessage()); 160 | } 161 | else{ 162 | try { 163 | callback.onFailure(NotFoundErrMsg(response.errorBody().string())); 164 | } catch (IOException e) { 165 | e.printStackTrace(); 166 | } 167 | } 168 | } 169 | 170 | 171 | // CURRENT WEATHER METHODS 172 | // END 173 | 174 | 175 | 176 | 177 | // THREE HOUR FORECAST METHODS 178 | // START 179 | 180 | //GET THREE HOUR FORECAST BY CITY NAME 181 | public void getThreeHourForecastByCityName(String city, final ThreeHourForecastCallback callback){ 182 | options.put(QUERY, city); 183 | openWeatherMapService.getThreeHourForecastByCityName(options) 184 | .enqueue(new Callback() { 185 | @Override 186 | public void onResponse(@NonNull Call call, @NonNull Response response) { 187 | handleThreeHourForecastResponse(response, callback); 188 | } 189 | 190 | @Override 191 | public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { 192 | callback.onFailure(throwable); 193 | } 194 | }); 195 | 196 | } 197 | 198 | //GET THREE HOUR FORECAST BY CITY ID 199 | public void getThreeHourForecastByCityID(String id, final ThreeHourForecastCallback callback){ 200 | options.put(CITY_ID, id); 201 | openWeatherMapService.getThreeHourForecastByCityID(options) 202 | .enqueue(new Callback() { 203 | @Override 204 | public void onResponse(@NonNull Call call, @NonNull Response response) { 205 | handleThreeHourForecastResponse(response, callback); 206 | } 207 | 208 | @Override 209 | public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { 210 | callback.onFailure(throwable); 211 | } 212 | }); 213 | 214 | } 215 | 216 | //GET THREE HOUR FORECAST BY GEO C0ORDINATES 217 | public void getThreeHourForecastByGeoCoordinates(double latitude, double longitude, final ThreeHourForecastCallback callback){ 218 | options.put(LATITUDE, String.valueOf(latitude)); 219 | options.put(LONGITUDE, String.valueOf(longitude)); 220 | openWeatherMapService.getThreeHourForecastByGeoCoordinates(options) 221 | .enqueue(new Callback() { 222 | @Override 223 | public void onResponse(@NonNull Call call, @NonNull Response response) { 224 | handleThreeHourForecastResponse(response, callback); 225 | } 226 | 227 | @Override 228 | public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { 229 | callback.onFailure(throwable); 230 | } 231 | }); 232 | 233 | } 234 | 235 | //GET THREE HOUR FORECAST BY ZIP CODE 236 | public void getThreeHourForecastByZipCode(String zipCode, final ThreeHourForecastCallback callback){ 237 | options.put(ZIP_CODE, zipCode); 238 | openWeatherMapService.getThreeHourForecastByZipCode(options) 239 | .enqueue(new Callback() { 240 | @Override 241 | public void onResponse(@NonNull Call call, @NonNull Response response) { 242 | handleThreeHourForecastResponse(response, callback); 243 | } 244 | 245 | @Override 246 | public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { 247 | callback.onFailure(throwable); 248 | } 249 | }); 250 | 251 | } 252 | 253 | private void handleThreeHourForecastResponse(Response response, ThreeHourForecastCallback callback){ 254 | if (response.code() == HttpURLConnection.HTTP_OK){ 255 | callback.onSuccess(response.body()); 256 | } 257 | else if (response.code() == HttpURLConnection.HTTP_FORBIDDEN || response.code() == HttpURLConnection.HTTP_UNAUTHORIZED){ 258 | callback.onFailure(NoAppIdErrMessage()); 259 | } 260 | else{ 261 | try { 262 | callback.onFailure(NotFoundErrMsg(response.errorBody().string())); 263 | } catch (IOException e) { 264 | e.printStackTrace(); 265 | } 266 | } 267 | } 268 | 269 | 270 | } 271 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/implementation/callback/CurrentWeatherCallback.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.implementation.callback; 2 | 3 | import com.kwabenaberko.openweathermaplib.model.currentweather.CurrentWeather; 4 | 5 | public interface CurrentWeatherCallback{ 6 | void onSuccess(CurrentWeather currentWeather); 7 | void onFailure(Throwable throwable); 8 | } 9 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/implementation/callback/ThreeHourForecastCallback.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.implementation.callback; 2 | 3 | import com.kwabenaberko.openweathermaplib.model.threehourforecast.ThreeHourForecast; 4 | 5 | public interface ThreeHourForecastCallback{ 6 | void onSuccess(ThreeHourForecast threeHourForecast); 7 | void onFailure(Throwable throwable); 8 | } -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/model/common/Clouds.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.model.common; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Created by Kwabena Berko on 7/25/2017. 7 | */ 8 | 9 | public class Clouds { 10 | 11 | @SerializedName("all") 12 | private double all; 13 | 14 | public double getAll() { 15 | return all; 16 | } 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/model/common/Coord.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.model.common; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Created by Kwabena Berko on 7/25/2017. 7 | */ 8 | 9 | public class Coord { 10 | 11 | @SerializedName("lon") 12 | private double lon; 13 | 14 | @SerializedName("lat") 15 | private double lat; 16 | 17 | public double getLon() { 18 | return lon; 19 | } 20 | 21 | public double getLat() { 22 | return lat; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/model/common/Main.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.model.common; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Created by Kwabena Berko on 7/25/2017. 7 | */ 8 | 9 | public class Main { 10 | @SerializedName("temp") 11 | private double temp; 12 | 13 | @SerializedName("feels_like") 14 | private double feelsLike; 15 | 16 | @SerializedName("temp_min") 17 | private double tempMin; 18 | 19 | @SerializedName("temp_max") 20 | private double tempMax; 21 | 22 | @SerializedName("pressure") 23 | private double pressure; 24 | 25 | @SerializedName("humidity") 26 | private double humidity; 27 | 28 | @SerializedName("sea_level") 29 | private Double seaLevel; 30 | 31 | @SerializedName("grnd_level") 32 | private Double grndLevel; 33 | 34 | @SerializedName("temp_kf") 35 | private Double tempKf; 36 | 37 | 38 | public double getTemp() { 39 | return temp; 40 | } 41 | 42 | public double getFeelsLike() { 43 | return feelsLike; 44 | } 45 | 46 | public double getTempMin() { 47 | return tempMin; 48 | } 49 | 50 | public double getTempMax() { 51 | return tempMax; 52 | } 53 | 54 | public double getPressure() { 55 | return pressure; 56 | } 57 | 58 | public double getHumidity() { 59 | return humidity; 60 | } 61 | 62 | public Double getSeaLevel() { 63 | return seaLevel; 64 | } 65 | 66 | public Double getGrndLevel() { 67 | return grndLevel; 68 | } 69 | 70 | public Double getTempKf() { 71 | return tempKf; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/model/common/Precipitation.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.model.common; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | public class Precipitation { 6 | 7 | @SerializedName("1h") 8 | private Double oneHour; 9 | 10 | @SerializedName("3h") 11 | private Double threeHour; 12 | 13 | public Double getOneHour() { 14 | return oneHour; 15 | } 16 | 17 | public Double getThreeHour() { 18 | return threeHour; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/model/common/Rain.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.model.common; 2 | 3 | 4 | public class Rain extends Precipitation {} 5 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/model/common/Snow.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.model.common; 2 | 3 | 4 | public class Snow extends Precipitation { } 5 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/model/common/Sys.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.model.common; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Created by Kwabena Berko on 7/25/2017. 7 | */ 8 | 9 | public class Sys { 10 | 11 | @SerializedName("type") 12 | private double type; 13 | 14 | @SerializedName("id") 15 | private Long id; 16 | 17 | @SerializedName("message") 18 | private Double message; 19 | 20 | @SerializedName("country") 21 | private String country; 22 | 23 | @SerializedName("sunrise") 24 | private Long sunrise; 25 | 26 | @SerializedName("sunset") 27 | private Long sunset; 28 | 29 | @SerializedName("pod") 30 | private Character pod; 31 | 32 | public double getType() { 33 | return type; 34 | } 35 | 36 | public Long getId() { 37 | return id; 38 | } 39 | 40 | public Double getMessage() { 41 | return message; 42 | } 43 | 44 | public String getCountry() { 45 | return country; 46 | } 47 | 48 | public Long getSunrise() { 49 | return sunrise; 50 | } 51 | 52 | public Long getSunset() { 53 | return sunset; 54 | } 55 | 56 | public Character getPod() { 57 | return pod; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/model/common/Weather.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.model.common; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Created by Kwabena Berko on 7/25/2017. 7 | */ 8 | 9 | public class Weather { 10 | 11 | @SerializedName("id") 12 | private Long id; 13 | 14 | @SerializedName("main") 15 | private String main; 16 | 17 | @SerializedName("description") 18 | private String description; 19 | 20 | @SerializedName("icon") 21 | private String icon; 22 | 23 | public Long getId() { 24 | return id; 25 | } 26 | 27 | public String getMain() { 28 | return main; 29 | } 30 | 31 | public String getDescription() { 32 | return description; 33 | } 34 | 35 | public String getIcon() { 36 | return icon; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/model/common/Wind.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.model.common; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Created by Kwabena Berko on 7/25/2017. 7 | */ 8 | 9 | public class Wind { 10 | @SerializedName("speed") 11 | private double speed; 12 | 13 | @SerializedName("deg") 14 | private double deg; 15 | 16 | @SerializedName("gust") 17 | private Double gust; 18 | 19 | public double getSpeed() { 20 | return speed; 21 | } 22 | 23 | public double getDeg() { 24 | return deg; 25 | } 26 | 27 | public Double getGust() { 28 | return gust; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/model/currentweather/CurrentWeather.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.model.currentweather; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import com.kwabenaberko.openweathermaplib.model.common.Clouds; 5 | import com.kwabenaberko.openweathermaplib.model.common.Main; 6 | import com.kwabenaberko.openweathermaplib.model.common.Rain; 7 | import com.kwabenaberko.openweathermaplib.model.common.Snow; 8 | import com.kwabenaberko.openweathermaplib.model.common.Weather; 9 | import com.kwabenaberko.openweathermaplib.model.common.Wind; 10 | import com.kwabenaberko.openweathermaplib.model.common.Coord; 11 | import com.kwabenaberko.openweathermaplib.model.common.Sys; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Created by Kwabena Berko on 7/25/2017. 17 | */ 18 | 19 | public class CurrentWeather { 20 | 21 | @SerializedName("coord") 22 | private Coord coord; 23 | 24 | @SerializedName("weather") 25 | private List weather; 26 | 27 | @SerializedName("base") 28 | private String base; 29 | 30 | @SerializedName("main") 31 | private Main main; 32 | 33 | @SerializedName("visibility") 34 | private Long visibility; 35 | 36 | @SerializedName("wind") 37 | private Wind wind; 38 | 39 | @SerializedName("clouds") 40 | private Clouds clouds; 41 | 42 | @SerializedName("rain") 43 | private Rain rain; 44 | 45 | @SerializedName("snow") 46 | private Snow snow; 47 | 48 | @SerializedName("dt") 49 | private Long dt; 50 | 51 | @SerializedName("sys") 52 | private Sys sys; 53 | 54 | @SerializedName("timezone") 55 | private Long timezone; 56 | 57 | @SerializedName("id") 58 | private Long id; 59 | 60 | @SerializedName("name") 61 | private String name; 62 | 63 | @SerializedName("cod") 64 | private Integer cod; 65 | 66 | public Coord getCoord() { 67 | return coord; 68 | } 69 | 70 | public List getWeather() { 71 | return weather; 72 | } 73 | 74 | public String getBase() { 75 | return base; 76 | } 77 | 78 | public Main getMain() { 79 | return main; 80 | } 81 | 82 | public Long getVisibility() { 83 | return visibility; 84 | } 85 | 86 | public Wind getWind() { 87 | return wind; 88 | } 89 | 90 | public Clouds getClouds() { 91 | return clouds; 92 | } 93 | 94 | public Rain getRain() { 95 | return rain; 96 | } 97 | 98 | public Snow getSnow() { 99 | return snow; 100 | } 101 | 102 | public Long getDt() { 103 | return dt; 104 | } 105 | 106 | public Sys getSys() { 107 | return sys; 108 | } 109 | 110 | public Long getTimezone() { 111 | return timezone; 112 | } 113 | 114 | public Long getId() { 115 | return id; 116 | } 117 | 118 | public String getName() { 119 | return name; 120 | } 121 | 122 | public Integer getCod() { 123 | return cod; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/model/threehourforecast/City.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.model.threehourforecast; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import com.kwabenaberko.openweathermaplib.model.common.Coord; 5 | 6 | /** 7 | * Created by Kwabena Berko on 8/6/2017. 8 | */ 9 | 10 | public class City { 11 | 12 | @SerializedName("id") 13 | private long id; 14 | 15 | @SerializedName("name") 16 | private String name; 17 | 18 | @SerializedName("coord") 19 | private Coord coord; 20 | 21 | @SerializedName("country") 22 | private String country; 23 | 24 | @SerializedName("timezone") 25 | private Long timezone; 26 | 27 | @SerializedName("population") 28 | private Long population; 29 | 30 | @SerializedName("sunrise") 31 | private Long sunrise; 32 | 33 | @SerializedName("sunset") 34 | private Long sunset; 35 | 36 | public long getId() { 37 | return id; 38 | } 39 | 40 | public String getName() { 41 | return name; 42 | } 43 | 44 | public Coord getCoord() { 45 | return coord; 46 | } 47 | 48 | public String getCountry() { 49 | return country; 50 | } 51 | 52 | public Long getTimezone() { 53 | return timezone; 54 | } 55 | 56 | public Long getPopulation() { 57 | return population; 58 | } 59 | 60 | public Long getSunrise() { 61 | return sunrise; 62 | } 63 | 64 | public Long getSunset() { 65 | return sunset; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/model/threehourforecast/ThreeHourForecast.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.model.threehourforecast; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created by Kwabena Berko on 8/6/2017. 9 | */ 10 | 11 | public class ThreeHourForecast { 12 | 13 | @SerializedName("cod") 14 | private String cod; 15 | 16 | @SerializedName("message") 17 | private double message; 18 | 19 | @SerializedName("cnt") 20 | private int cnt; 21 | 22 | @SerializedName("list") 23 | private List list; 24 | 25 | @SerializedName("city") 26 | private City city; 27 | 28 | 29 | public String getCod() { 30 | return cod; 31 | } 32 | 33 | public double getMessage() { 34 | return message; 35 | } 36 | 37 | public int getCnt() { 38 | return cnt; 39 | } 40 | 41 | public List getList() { 42 | return list; 43 | } 44 | 45 | public City getCity() { 46 | return city; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/model/threehourforecast/ThreeHourForecastWeather.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.model.threehourforecast; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import com.kwabenaberko.openweathermaplib.model.common.Clouds; 5 | import com.kwabenaberko.openweathermaplib.model.common.Main; 6 | import com.kwabenaberko.openweathermaplib.model.common.Rain; 7 | import com.kwabenaberko.openweathermaplib.model.common.Snow; 8 | import com.kwabenaberko.openweathermaplib.model.common.Sys; 9 | import com.kwabenaberko.openweathermaplib.model.common.Weather; 10 | import com.kwabenaberko.openweathermaplib.model.common.Wind; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Created by Kwabena Berko on 8/6/2017. 16 | */ 17 | 18 | public class ThreeHourForecastWeather { 19 | 20 | @SerializedName("dt") 21 | private Long dt; 22 | 23 | @SerializedName("main") 24 | private Main main; 25 | 26 | @SerializedName("weather") 27 | private List weather; 28 | 29 | @SerializedName("clouds") 30 | private Clouds clouds; 31 | 32 | @SerializedName("wind") 33 | private Wind wind; 34 | 35 | @SerializedName("visibility") 36 | private Long visibility; 37 | 38 | @SerializedName("pop") 39 | private Double pop; 40 | 41 | @SerializedName("rain") 42 | private Rain rain; 43 | 44 | @SerializedName("snow") 45 | private Snow snow; 46 | 47 | @SerializedName("sys") 48 | private Sys mSys; 49 | 50 | @SerializedName("dt_txt") 51 | private String dtTxt; 52 | 53 | public Long getDt() { 54 | return dt; 55 | } 56 | 57 | public void setDt(Long dt) { 58 | this.dt = dt; 59 | } 60 | 61 | public Main getMain() { 62 | return main; 63 | } 64 | 65 | public void setMain(Main main) { 66 | this.main = main; 67 | } 68 | 69 | public List getWeather() { 70 | return weather; 71 | } 72 | 73 | public void setWeather(List weather) { 74 | this.weather = weather; 75 | } 76 | 77 | public Clouds getClouds() { 78 | return clouds; 79 | } 80 | 81 | public void setClouds(Clouds clouds) { 82 | this.clouds = clouds; 83 | } 84 | 85 | public Wind getWind() { 86 | return wind; 87 | } 88 | 89 | public Long getVisibility() { 90 | return visibility; 91 | } 92 | 93 | public Double getPop() { 94 | return pop; 95 | } 96 | 97 | public void setWind(Wind wind) { 98 | this.wind = wind; 99 | } 100 | 101 | public Rain getRain() { 102 | return rain; 103 | } 104 | 105 | public void setRain(Rain rain) { 106 | this.rain = rain; 107 | } 108 | 109 | public Snow getSnow() { 110 | return snow; 111 | } 112 | 113 | public void setSnow(Snow snow) { 114 | this.snow = snow; 115 | } 116 | 117 | public Sys getmSys() { 118 | return mSys; 119 | } 120 | 121 | public void setmSys(Sys mSys) { 122 | this.mSys = mSys; 123 | } 124 | 125 | public String getDtTxt() { 126 | return dtTxt; 127 | } 128 | 129 | public void setDtTxt(String dtTxt) { 130 | this.dtTxt = dtTxt; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/network/OpenWeatherMapClient.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.network; 2 | 3 | import retrofit2.Retrofit; 4 | import retrofit2.converter.gson.GsonConverterFactory; 5 | 6 | /** 7 | * Created by Kwabena Berko on 7/25/2017. 8 | */ 9 | 10 | public class OpenWeatherMapClient { 11 | private static final String BASE_URL = "https://api.openweathermap.org"; 12 | private static Retrofit retrofit = null; 13 | public static Retrofit getClient(){ 14 | if (retrofit == null){ 15 | retrofit = new Retrofit.Builder() 16 | .baseUrl(BASE_URL) 17 | .addConverterFactory(GsonConverterFactory.create()) 18 | .build(); 19 | } 20 | return retrofit; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/java/com/kwabenaberko/openweathermaplib/network/OpenWeatherMapService.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib.network; 2 | 3 | import com.kwabenaberko.openweathermaplib.model.currentweather.CurrentWeather; 4 | import com.kwabenaberko.openweathermaplib.model.threehourforecast.ThreeHourForecast; 5 | 6 | import java.util.Map; 7 | 8 | import retrofit2.Call; 9 | import retrofit2.http.GET; 10 | import retrofit2.http.QueryMap; 11 | 12 | /** 13 | * Created by Kwabena Berko on 7/25/2017. 14 | */ 15 | 16 | public interface OpenWeatherMapService { 17 | 18 | String CURRENT = "/data/2.5/weather"; 19 | String FORECAST = "/data/2.5/forecast"; 20 | 21 | //Current Weather Endpoints start 22 | @GET(CURRENT) 23 | Call getCurrentWeatherByCityName(@QueryMap Map options); 24 | 25 | @GET(CURRENT) 26 | Call getCurrentWeatherByCityID(@QueryMap Map options); 27 | 28 | @GET(CURRENT) 29 | Call getCurrentWeatherByGeoCoordinates(@QueryMap Map options); 30 | 31 | @GET(CURRENT) 32 | Call getCurrentWeatherByZipCode(@QueryMap Map options); 33 | 34 | //Current Weather Endpoints end 35 | 36 | //Three hour forecast endpoints start 37 | @GET(FORECAST) 38 | Call getThreeHourForecastByCityName(@QueryMap Map options); 39 | 40 | @GET(FORECAST) 41 | Call getThreeHourForecastByCityID(@QueryMap Map options); 42 | 43 | @GET(FORECAST) 44 | Call getThreeHourForecastByGeoCoordinates(@QueryMap Map options); 45 | 46 | @GET(FORECAST) 47 | Call getThreeHourForecastByZipCode(@QueryMap Map options); 48 | } 49 | -------------------------------------------------------------------------------- /openweathermaphelper/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | OpenWeatherMapLib 3 | 4 | -------------------------------------------------------------------------------- /openweathermaphelper/src/test/java/com/kwabenaberko/openweathermaplib/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermaplib; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | 6 | defaultConfig { 7 | applicationId "com.kwabenaberko.openweathermap" 8 | minSdkVersion 15 9 | targetSdkVersion 29 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | 21 | compileOptions { 22 | sourceCompatibility JavaVersion.VERSION_1_8 23 | targetCompatibility JavaVersion.VERSION_1_8 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: 'libs', include: ['*.jar']) 29 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { 30 | exclude group: 'com.android.support', module: 'support-annotations' 31 | }) 32 | implementation 'androidx.appcompat:appcompat:1.2.0' 33 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 34 | implementation 'com.github.KwabenBerko:OpenWeatherMap-Android-Library:2.1.0' 35 | testImplementation 'junit:junit:4.13.1' 36 | } 37 | -------------------------------------------------------------------------------- /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\PAVILION 15\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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/kwabenaberko/openweathermap/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermap; 2 | 3 | import android.content.Context; 4 | import androidx.test.platform.app.InstrumentationRegistry; 5 | import androidx.test.ext.junit.runners.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.kwabenaberko.openweathermap", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /sample/src/main/java/com/kwabenaberko/openweathermap/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermap; 2 | 3 | import android.os.Bundle; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import android.util.Log; 6 | 7 | import com.kwabenaberko.openweathermaplib.constant.Languages; 8 | import com.kwabenaberko.openweathermaplib.constant.Units; 9 | import com.kwabenaberko.openweathermaplib.implementation.OpenWeatherMapHelper; 10 | import com.kwabenaberko.openweathermaplib.implementation.callback.CurrentWeatherCallback; 11 | import com.kwabenaberko.openweathermaplib.implementation.callback.ThreeHourForecastCallback; 12 | import com.kwabenaberko.openweathermaplib.model.currentweather.CurrentWeather; 13 | import com.kwabenaberko.openweathermaplib.model.threehourforecast.ThreeHourForecast; 14 | 15 | 16 | public class MainActivity extends AppCompatActivity { 17 | 18 | public static final String TAG = MainActivity.class.getSimpleName(); 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_main); 24 | 25 | //Instantiate Class With Your ApiKey As The Parameter 26 | OpenWeatherMapHelper helper = new OpenWeatherMapHelper(getString(R.string.OPEN_WEATHER_MAP_API_KEY)); 27 | 28 | //Set Units 29 | helper.setUnits(Units.IMPERIAL); 30 | 31 | //Set Languages 32 | helper.setLanguage(Languages.ENGLISH); 33 | 34 | /* 35 | This Example Only Shows how to get current weather by city name 36 | Check the docs for more methods [https://github.com/KwabenBerko/OpenWeatherMap-Android-Library/] 37 | */ 38 | 39 | helper.getCurrentWeatherByCityName("Accra", new CurrentWeatherCallback() { 40 | @Override 41 | public void onSuccess(CurrentWeather currentWeather) { 42 | Log.v(TAG, 43 | "Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon() +"\n" 44 | +"Weather Description: " + currentWeather.getWeather().get(0).getDescription() + "\n" 45 | +"Temperature: " + currentWeather.getMain().getTempMax()+"\n" 46 | +"Wind Speed: " + currentWeather.getWind().getSpeed() + "\n" 47 | +"City, Country: " + currentWeather.getName() + ", " + currentWeather.getSys().getCountry() 48 | ); 49 | } 50 | 51 | @Override 52 | public void onFailure(Throwable throwable) { 53 | Log.v(TAG, throwable.getMessage()); 54 | } 55 | }); 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KwabenBerko/OpenWeatherMap-Android-Library/4f503f8819874b5ce72e4edda4d5002bf6bdbe96/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KwabenBerko/OpenWeatherMap-Android-Library/4f503f8819874b5ce72e4edda4d5002bf6bdbe96/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KwabenBerko/OpenWeatherMap-Android-Library/4f503f8819874b5ce72e4edda4d5002bf6bdbe96/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KwabenBerko/OpenWeatherMap-Android-Library/4f503f8819874b5ce72e4edda4d5002bf6bdbe96/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KwabenBerko/OpenWeatherMap-Android-Library/4f503f8819874b5ce72e4edda4d5002bf6bdbe96/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KwabenBerko/OpenWeatherMap-Android-Library/4f503f8819874b5ce72e4edda4d5002bf6bdbe96/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KwabenBerko/OpenWeatherMap-Android-Library/4f503f8819874b5ce72e4edda4d5002bf6bdbe96/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KwabenBerko/OpenWeatherMap-Android-Library/4f503f8819874b5ce72e4edda4d5002bf6bdbe96/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KwabenBerko/OpenWeatherMap-Android-Library/4f503f8819874b5ce72e4edda4d5002bf6bdbe96/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KwabenBerko/OpenWeatherMap-Android-Library/4f503f8819874b5ce72e4edda4d5002bf6bdbe96/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | OpenWeatherMap 3 | YOUR_API_KEY_GOES_HERE 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/test/java/com/kwabenaberko/openweathermap/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.kwabenaberko.openweathermap; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':openweathermaphelper' 2 | --------------------------------------------------------------------------------