/** * This is the method of the AsyncTaskLoader that will load and parse the JSON data * from OpenWeatherMap in the background. * * @return Weather data from OpenWeatherMap as an array of Strings. * null if an error occurs */ @Override public String[] loadInBackground() { URL weatherRequestUrl = NetworkUtils.getUrl(MainActivity.this); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } }
/** * Retrieves the proper URL to query for the weather data. The reason for both this method as * well as {@link #buildUrlWithLocationQuery(String)} is two fold. * <p> * 1) You should be able to just use one method when you need to create the URL within the * app instead of calling both methods. * 2) Later in Sunshine, you are going to add an alternate method of allowing the user * to select their preferred location. Once you do so, there will be another way to form * the URL using a latitude and longitude rather than just a location String. This method * will "decide" which URL to build and return it. * * @param context used to access other Utility methods * @return URL to query weather service */ public static URL getUrl(Context context) { if (SunshinePreferences.isLocationLatLonAvailable(context)) { double[] preferredCoordinates = SunshinePreferences.getLocationCoordinates(context); double latitude = preferredCoordinates[0]; double longitude = preferredCoordinates[1]; return buildUrlWithLatitudeLongitude(latitude, longitude); } else { String locationQuery = SunshinePreferences.getPreferredWeatherLocation(context); return buildUrlWithLocationQuery(locationQuery); } }
@Override protected String[] doInBackground(String... params) { /* If there's no zip code, there's nothing to look up. */ if (params.length == 0) { return null; } String location = params[0]; URL weatherRequestUrl = NetworkUtils.buildUrl(location); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } }
/** * This is the method of the AsyncTaskLoader that will load and parse the JSON data * from OpenWeatherMap in the background. * * @return Weather data from OpenWeatherMap as an array of Strings. * null if an error occurs */ @Override public String[] loadInBackground() { URL weatherRequestUrl = NetworkUtils.getUrl(MainActivity.this); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } }
/** * Retrieves the proper URL to query for the weather data. The reason for both this method as * well as {@link #buildUrlWithLocationQuery(String)} is two fold. * <p> * 1) You should be able to just use one method when you need to create the URL within the * app instead of calling both methods. * 2) Later in Sunshine, you are going to add an alternate method of allowing the user * to select their preferred location. Once you do so, there will be another way to form * the URL using a latitude and longitude rather than just a location String. This method * will "decide" which URL to build and return it. * * @param context used to access other Utility methods * @return URL to query weather service */ public static URL getUrl(Context context) { if (SunshinePreferences.isLocationLatLonAvailable(context)) { double[] preferredCoordinates = SunshinePreferences.getLocationCoordinates(context); double latitude = preferredCoordinates[0]; double longitude = preferredCoordinates[1]; return buildUrlWithLatitudeLongitude(latitude, longitude); } else { String locationQuery = SunshinePreferences.getPreferredWeatherLocation(context); return buildUrlWithLocationQuery(locationQuery); } }
@Override protected String[] doInBackground(String... params) { /* If there's no zip code, there's nothing to look up. */ if (params.length == 0) { return null; } String location = params[0]; URL weatherRequestUrl = NetworkUtils.buildUrl(location); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } }
/** * This is the method of the AsyncTaskLoader that will load and parse the JSON data * from OpenWeatherMap in the background. * * @return Weather data from OpenWeatherMap as an array of Strings. * null if an error occurs */ @Override public String[] loadInBackground() { URL weatherRequestUrl = NetworkUtils.getUrl(MainActivity.this); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } }
/** * Retrieves the proper URL to query for the weather data. The reason for both this method as * well as {@link #buildUrlWithLocationQuery(String)} is two fold. * <p> * 1) You should be able to just use one method when you need to create the URL within the * app instead of calling both methods. * 2) Later in Sunshine, you are going to add an alternate method of allowing the user * to select their preferred location. Once you do so, there will be another way to form * the URL using a latitude and longitude rather than just a location String. This method * will "decide" which URL to build and return it. * * @param context used to access other Utility methods * @return URL to query weather service */ public static URL getUrl(Context context) { if (SunshinePreferences.isLocationLatLonAvailable(context)) { double[] preferredCoordinates = SunshinePreferences.getLocationCoordinates(context); double latitude = preferredCoordinates[0]; double longitude = preferredCoordinates[1]; return buildUrlWithLatitudeLongitude(latitude, longitude); } else { String locationQuery = SunshinePreferences.getPreferredWeatherLocation(context); return buildUrlWithLocationQuery(locationQuery); } }
@Override protected String[] doInBackground(String... params) { /* If there's no zip code, there's nothing to look up. */ if (params.length == 0) { return null; } String location = params[0]; URL weatherRequestUrl = NetworkUtils.buildUrl(location); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } }
/** * This is the method of the AsyncTaskLoader that will load and parse the JSON data * from OpenWeatherMap in the background. * * @return Weather data from OpenWeatherMap as an array of Strings. * null if an error occurs */ @Override public String[] loadInBackground() { URL weatherRequestUrl = NetworkUtils.getUrl(MainActivity.this); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } }
/** * Retrieves the proper URL to query for the weather data. The reason for both this method as * well as {@link #buildUrlWithLocationQuery(String)} is two fold. * <p> * 1) You should be able to just use one method when you need to create the URL within the * app instead of calling both methods. * 2) Later in Sunshine, you are going to add an alternate method of allowing the user * to select their preferred location. Once you do so, there will be another way to form * the URL using a latitude and longitude rather than just a location String. This method * will "decide" which URL to build and return it. * * @param context used to access other Utility methods * @return URL to query weather service */ public static URL getUrl(Context context) { if (SunshinePreferences.isLocationLatLonAvailable(context)) { double[] preferredCoordinates = SunshinePreferences.getLocationCoordinates(context); double latitude = preferredCoordinates[0]; double longitude = preferredCoordinates[1]; return buildUrlWithLatitudeLongitude(latitude, longitude); } else { String locationQuery = SunshinePreferences.getPreferredWeatherLocation(context); return buildUrlWithLocationQuery(locationQuery); } }
@Override protected String[] doInBackground(String... params) { /* If there's no zip code, there's nothing to look up. */ if (params.length == 0) { return null; } String location = params[0]; URL weatherRequestUrl = NetworkUtils.buildUrl(location); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } }
/** * This is the method of the AsyncTaskLoader that will load and parse the JSON data * from OpenWeatherMap in the background. * * @return Weather data from OpenWeatherMap as an array of Strings. * null if an error occurs */ @Override public String[] loadInBackground() { URL weatherRequestUrl = NetworkUtils.getUrl(MainActivity.this); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } }
/** * Retrieves the proper URL to query for the weather data. The reason for both this method as * well as {@link #buildUrlWithLocationQuery(String)} is two fold. * <p> * 1) You should be able to just use one method when you need to create the URL within the * app instead of calling both methods. * 2) Later in Sunshine, you are going to add an alternate method of allowing the user * to select their preferred location. Once you do so, there will be another way to form * the URL using a latitude and longitude rather than just a location String. This method * will "decide" which URL to build and return it. * * @param context used to access other Utility methods * @return URL to query weather service */ public static URL getUrl(Context context) { if (SunshinePreferences.isLocationLatLonAvailable(context)) { double[] preferredCoordinates = SunshinePreferences.getLocationCoordinates(context); double latitude = preferredCoordinates[0]; double longitude = preferredCoordinates[1]; return buildUrlWithLatitudeLongitude(latitude, longitude); } else { String locationQuery = SunshinePreferences.getPreferredWeatherLocation(context); return buildUrlWithLocationQuery(locationQuery); } }
@Override protected String[] doInBackground(String... params) { /* If there's no zip code, there's nothing to look up. */ if (params.length == 0) { return null; } String location = params[0]; URL weatherRequestUrl = NetworkUtils.buildUrl(location); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } }
/** * This is the method of the AsyncTaskLoader that will load and parse the JSON data * from OpenWeatherMap in the background. * * @return Weather data from OpenWeatherMap as an array of Strings. * null if an error occurs */ @Override public String[] loadInBackground() { URL weatherRequestUrl = NetworkUtils.getUrl(MainActivity.this); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } }
/** * Retrieves the proper URL to query for the weather data. The reason for both this method as * well as {@link #buildUrlWithLocationQuery(String)} is two fold. * <p> * 1) You should be able to just use one method when you need to create the URL within the * app instead of calling both methods. * 2) Later in Sunshine, you are going to add an alternate method of allowing the user * to select their preferred location. Once you do so, there will be another way to form * the URL using a latitude and longitude rather than just a location String. This method * will "decide" which URL to build and return it. * * @param context used to access other Utility methods * @return URL to query weather service */ public static URL getUrl(Context context) { if (SunshinePreferences.isLocationLatLonAvailable(context)) { double[] preferredCoordinates = SunshinePreferences.getLocationCoordinates(context); double latitude = preferredCoordinates[0]; double longitude = preferredCoordinates[1]; return buildUrlWithLatitudeLongitude(latitude, longitude); } else { String locationQuery = SunshinePreferences.getPreferredWeatherLocation(context); return buildUrlWithLocationQuery(locationQuery); } }
@Override protected String[] doInBackground(String... params) { /* If there's no zip code, there's nothing to look up. */ if (params.length == 0) { return null; } String location = params[0]; URL weatherRequestUrl = NetworkUtils.buildUrl(location); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } }
/** * This is the method of the AsyncTaskLoader that will load and parse the JSON data * from OpenWeatherMap in the background. * * @return Weather data from OpenWeatherMap as an array of Strings. * null if an error occurs */ @Override public String[] loadInBackground() { URL weatherRequestUrl = NetworkUtils.getUrl(MainActivity.this); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } }
/** * Retrieves the proper URL to query for the weather data. The reason for both this method as * well as {@link #buildUrlWithLocationQuery(String)} is two fold. * <p> * 1) You should be able to just use one method when you need to create the URL within the * app instead of calling both methods. * 2) Later in Sunshine, you are going to add an alternate method of allowing the user * to select their preferred location. Once you do so, there will be another way to form * the URL using a latitude and longitude rather than just a location String. This method * will "decide" which URL to build and return it. * * @param context used to access other Utility methods * @return URL to query weather service */ public static URL getUrl(Context context) { if (SunshinePreferences.isLocationLatLonAvailable(context)) { double[] preferredCoordinates = SunshinePreferences.getLocationCoordinates(context); double latitude = preferredCoordinates[0]; double longitude = preferredCoordinates[1]; return buildUrlWithLatitudeLongitude(latitude, longitude); } else { String locationQuery = SunshinePreferences.getPreferredWeatherLocation(context); return buildUrlWithLocationQuery(locationQuery); } }