Skip to content

Commit b1c55d4

Browse files
committed
Updated README.md
1 parent 80a7811 commit b1c55d4

2 files changed

Lines changed: 143 additions & 161 deletions

File tree

README.md

Lines changed: 138 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,10 @@ compile 'com.github.KwabenBerko:OpenWeatherMap-Android-Library:v1.1.2'
2929

3030
## Usage
3131

32-
#### Instantiate the OpenWeatherMapHelper class
32+
#### //Instantiate Class With Your ApiKey As The Parameter
3333

3434
``` java
35-
OpenWeatherMapHelper helper = new OpenWeatherMapHelper();
36-
```
37-
#### Set your API Key (Required)
38-
39-
``` java
40-
helper.setApiKey(getString(R.string.OPEN_WEATHER_MAP_API_KEY));
35+
OpenWeatherMapHelper helper = new OpenWeatherMapHelper(getString(R.string.OPEN_WEATHER_MAP_API_KEY));
4136
```
4237

4338
#### Set your Units (Optional, Standard by default)
@@ -65,179 +60,166 @@ helper.setLang(Lang.ENGLISH);
6560
#### Get current weather by City Name:
6661

6762
```java
68-
helper.getCurrentWeatherByCityName("Accra", new OpenWeatherMapHelper.CurrentWeatherCallback() {
69-
@Override
70-
public void onSuccess(CurrentWeather currentWeather) {
71-
Log.v(TAG,
72-
"Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon()+"\n"
73-
+"Weather Description: " + currentWeather.getWeatherArray().get(0).getDescription() + "\n"
74-
+"Max Temperature: " + currentWeather.getMain().getTempMax()+"\n"
75-
+"Wind Speed: " + currentWeather.getWind().getSpeed() + "\n"
76-
+"City, Country: " + currentWeather.getName() + ", " + currentWeather.getSys().getCountry()
77-
);
78-
}
79-
80-
@Override
81-
public void onFailure(Throwable throwable) {
82-
Log.v(TAG, throwable.getMessage());
83-
}
84-
});
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+
});
8579
```
8680

8781
#### Get current weather by City ID:
8882
```java
89-
helper.getCurrentWeatherByCityID("524901", new OpenWeatherMapHelper.CurrentWeatherCallback() {
90-
@Override
91-
public void onSuccess(CurrentWeather currentWeather) {
92-
Log.v(TAG,
93-
"Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon() +"\n"
94-
+"Weather Description: " + currentWeather.getWeatherArray().get(0).getDescription() + "\n"
95-
+"Max Temperature: " + currentWeather.getMain().getTempMax()+"\n"
96-
+"Wind Speed: " + currentWeather.getWind().getSpeed() + "\n"
97-
+"City, Country: " + currentWeather.getName() + ", " + currentWeather.getSys().getCountry()
98-
);
99-
}
100-
101-
@Override
102-
public void onFailure(Throwable throwable) {
103-
Log.v(TAG, throwable.getMessage());
104-
}
105-
});
106-
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+
});
10799
```
108100
#### Get current weather by Geographic Coordinates:
109101

110102
```java
111-
helper.getCurrentWeatherByGeoCoordinates(5.6037, 0.1870, new OpenWeatherMapHelper.CurrentWeatherCallback() {
112-
@Override
113-
public void onSuccess(CurrentWeather currentWeather) {
114-
Log.v(TAG,
115-
"Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon() +"\n"
116-
+"Weather Description: " + currentWeather.getWeatherArray().get(0).getDescription() + "\n"
117-
+"Max Temperature: " + currentWeather.getMain().getTempMax()+"\n"
118-
+"Wind Speed: " + currentWeather.getWind().getSpeed() + "\n"
119-
+"City, Country: " + currentWeather.getName() + ", " + currentWeather.getSys().getCountry()
120-
);
121-
}
122-
123-
@Override
124-
public void onFailure(Throwable throwable) {
125-
Log.v(TAG, throwable.getMessage());
126-
}
127-
});
128-
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+
});
129119
```
130120
#### Get current weather by Zip Code:
131121
```java
132-
helper.getCurrentWeatherByZipCode("90003", new OpenWeatherMapHelper.CurrentWeatherCallback() {
133-
@Override
134-
public void onSuccess(CurrentWeather currentWeather) {
135-
Log.v(TAG,
136-
"Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon() +"\n"
137-
+"Weather Description: " + currentWeather.getWeatherArray().get(0).getDescription() + "\n"
138-
+"Max Temperature: " + currentWeather.getMain().getTempMax()+"\n"
139-
+"Wind Speed: " + currentWeather.getWind().getSpeed() + "\n"
140-
+"City, Country: " + currentWeather.getName() + ", " + currentWeather.getSys().getCountry()
141-
);
142-
}
143-
144-
@Override
145-
public void onFailure(Throwable throwable) {
146-
Log.v(TAG, throwable.getMessage());
147-
}
148-
});
149-
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+
});
150138
```
151139
### (2) 5 day / 3 hour forecast
152140
#### Get three hour forecast by City Name:
153141
```java
154-
helper.getThreeHourForecastByCityName("Pretoria", new OpenWeatherMapHelper.ThreeHourForecastCallback() {
155-
@Override
156-
public void onSuccess(ThreeHourForecast threeHourForecast) {
157-
Log.v(TAG,
158-
"City/Country: "+ threeHourForecast.getCity().getName() + "/" + threeHourForecast.getCity().getCountry() +"\n"
159-
+"Forecast Array Count: " + threeHourForecast.getCnt() +"\n"
160-
//For this example, we are logging details of only the first forecast object in the forecasts array
161-
+"First Forecast Date Timestamp: " + threeHourForecast.getThreeHourWeatherArray().get(0).getDt() +"\n"
162-
+"First Forecast Weather Description: " + threeHourForecast.getThreeHourWeatherArray().get(0).getWeatherArray().get(0).getDescription()+ "\n"
163-
+"First Forecast Max Temperature: " + threeHourForecast.getThreeHourWeatherArray().get(0).getMain().getTempMax()+"\n"
164-
+"First Forecast Wind Speed: " + threeHourForecast.getThreeHourWeatherArray().get(0).getWind().getSpeed() + "\n"
165-
);
166-
}
167-
168-
@Override
169-
public void onFailure(Throwable throwable) {
170-
Log.v(TAG, throwable.getMessage());
171-
}
172-
});
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).getWeatherArray().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+
});
173160
```
174161
#### Get three hour forecast by City ID:
175162
```java
176-
helper.getThreeHourForecastByCityID("524901", new OpenWeatherMapHelper.ThreeHourForecastCallback() {
177-
@Override
178-
public void onSuccess(ThreeHourForecast threeHourForecast) {
179-
Log.v(TAG,
180-
"City/Country: "+ threeHourForecast.getCity().getName() + "/" + threeHourForecast.getCity().getCountry() +"\n"
181-
+"Forecast Array Count: " + threeHourForecast.getCnt() +"\n"
182-
//For this example, we are logging details of only the first forecast object in the forecasts array
183-
+"First Forecast Date Timestamp: " + threeHourForecast.getThreeHourWeatherArray().get(0).getDt() +"\n"
184-
+"First Forecast Weather Description: " + threeHourForecast.getThreeHourWeatherArray().get(0).getWeatherArray().get(0).getDescription()+ "\n"
185-
+"First Forecast Max Temperature: " + threeHourForecast.getThreeHourWeatherArray().get(0).getMain().getTempMax()+"\n"
186-
+"First Forecast Wind Speed: " + threeHourForecast.getThreeHourWeatherArray().get(0).getWind().getSpeed() + "\n"
187-
);
188-
}
189-
190-
@Override
191-
public void onFailure(Throwable throwable) {
192-
Log.v(TAG, throwable.getMessage());
193-
}
194-
});
195-
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).getWeatherArray().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+
});
196181
```
197182
#### Get three hour forecast by Geographic Coordinates:
198183
```java
199-
helper.getThreeHourForecastByGeoCoordinates(6.5244,3.3792, new OpenWeatherMapHelper.ThreeHourForecastCallback() {
200-
@Override
201-
public void onSuccess(ThreeHourForecast threeHourForecast) {
202-
Log.v(TAG,
203-
"City/Country: "+ threeHourForecast.getCity().getName() + "/" + threeHourForecast.getCity().getCountry() +"\n"
204-
+"Forecast Array Count: " + threeHourForecast.getCnt() +"\n"
205-
//For this example, we are logging details of only the first forecast object in the forecasts array
206-
+"First Forecast Date Timestamp: " + threeHourForecast.getThreeHourWeatherArray().get(0).getDt() +"\n"
207-
+"First Forecast Weather Description: " + threeHourForecast.getThreeHourWeatherArray().get(0).getWeatherArray().get(0).getDescription()+ "\n"
208-
+"First Forecast Max Temperature: " + threeHourForecast.getThreeHourWeatherArray().get(0).getMain().getTempMax()+"\n"
209-
+"First Forecast Wind Speed: " + threeHourForecast.getThreeHourWeatherArray().get(0).getWind().getSpeed() + "\n"
210-
);
211-
}
212-
213-
@Override
214-
public void onFailure(Throwable throwable) {
215-
Log.v(TAG, throwable.getMessage());
216-
}
217-
});
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).getWeatherArray().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+
});
218202
```
219203
#### Get three hour forecast by Zip Code:
220204
```java
221-
helper.getThreeHourForecastByZipCode("94040", new OpenWeatherMapHelper.ThreeHourForecastCallback() {
222-
@Override
223-
public void onSuccess(ThreeHourForecast threeHourForecast) {
224-
Log.v(TAG,
225-
"City/Country: "+ threeHourForecast.getCity().getName() + "/" + threeHourForecast.getCity().getCountry() +"\n"
226-
+"Forecast Array Count: " + threeHourForecast.getCnt() +"\n"
227-
//For this example, we are logging details of only the first forecast object in the forecasts array
228-
+"First Forecast Date Timestamp: " + threeHourForecast.getThreeHourWeatherArray().get(0).getDt() +"\n"
229-
+"First Forecast Weather Description: " + threeHourForecast.getThreeHourWeatherArray().get(0).getWeatherArray().get(0).getDescription()+ "\n"
230-
+"First Forecast Max Temperature: " + threeHourForecast.getThreeHourWeatherArray().get(0).getMain().getTempMax()+"\n"
231-
+"First Forecast Wind Speed: " + threeHourForecast.getThreeHourWeatherArray().get(0).getWind().getSpeed() + "\n"
232-
);
233-
}
234-
235-
@Override
236-
public void onFailure(Throwable throwable) {
237-
Log.v(TAG, throwable.getMessage());
238-
}
239-
});
240-
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).getWeatherArray().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+
});
241223
```
242224

243225

sample/src/main/java/com/kwabenaberko/openweathermap/MainActivity.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ protected void onCreate(Bundle savedInstanceState) {
1919
super.onCreate(savedInstanceState);
2020
setContentView(R.layout.activity_main);
2121

22-
//Instantiate class
23-
OpenWeatherMapHelper helper = new OpenWeatherMapHelper();
22+
//Instantiate Class With Your ApiKey As The Parameter
23+
OpenWeatherMapHelper helper = new OpenWeatherMapHelper(getString(R.string.OPEN_WEATHER_MAP_API_KEY));
2424

25-
//Set API KEY
26-
helper.setApiKey(getString(R.string.OPEN_WEATHER_MAP_API_KEY));
2725
//Set Units
2826
helper.setUnits(Units.IMPERIAL);
27+
2928
//Set lang
3029
helper.setLang(Lang.ENGLISH);
3130

@@ -37,7 +36,8 @@ protected void onCreate(Bundle savedInstanceState) {
3736
helper.getCurrentWeatherByCityName("Accra", new CurrentWeatherCallback() {
3837
@Override
3938
public void onSuccess(CurrentWeather currentWeather) {
40-
Log.v(TAG, "Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon() +"\n"
39+
Log.v(TAG,
40+
"Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon() +"\n"
4141
+"Weather Description: " + currentWeather.getWeather().get(0).getDescription() + "\n"
4242
+"Temperature: " + currentWeather.getMain().getTempMax()+"\n"
4343
+"Wind Speed: " + currentWeather.getWind().getSpeed() + "\n"

0 commit comments

Comments
 (0)