diff options
author | Danesh M <daneshm90@gmail.com> | 2016-02-14 11:54:26 -0800 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2016-02-15 11:35:07 -0800 |
commit | decb8e08dbf2a0111ca5153ae556035d02affa47 (patch) | |
tree | afee14195db3e278d170d547175e392a59ebbdda | |
parent | 43899ae6d3375e671730cfce6019ef446fc2a7bc (diff) | |
download | android_packages_apps_LockClock-decb8e08dbf2a0111ca5153ae556035d02affa47.tar.gz android_packages_apps_LockClock-decb8e08dbf2a0111ca5153ae556035d02affa47.tar.bz2 android_packages_apps_LockClock-decb8e08dbf2a0111ca5153ae556035d02affa47.zip |
LockClock : Switch over to new yahoo location api
geo.placefinder is no longer available.
https://developer.yahoo.com/forums/#/discussion/7844/yql-geo-placefinder-is-now-shutdown%3D
CYNGNOS-1756
Change-Id: Iff949b2e28f1938265dd8074b6e332317e10f0e0
(cherry picked from commit 96f7b8cc03911b5117599457832f1a88a801ff45)
(cherry picked from commit b0602ec5221b6114de98e4200702db2ae503c816)
-rw-r--r-- | src/com/cyanogenmod/lockclock/weather/YahooWeatherProvider.java | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/src/com/cyanogenmod/lockclock/weather/YahooWeatherProvider.java b/src/com/cyanogenmod/lockclock/weather/YahooWeatherProvider.java index ff63ddb..21bc9e4 100644 --- a/src/com/cyanogenmod/lockclock/weather/YahooWeatherProvider.java +++ b/src/com/cyanogenmod/lockclock/weather/YahooWeatherProvider.java @@ -57,15 +57,12 @@ public class YahooWeatherProvider implements WeatherProvider { "or placetype = 10 or placetype = 11 or placetype = 20) and text ="); private static final String URL_PLACEFINDER = "https://query.yahooapis.com/v1/public/yql?format=json&q=" + - Uri.encode("select woeid, city, neighborhood, county from geo.placefinder where " + - "gflags=\"R\" and text ="); + Uri.encode("select * from geo.places where " + + "text ="); private static final String[] LOCALITY_NAMES = new String[] { "locality1", "locality2", "admin3", "admin2", "admin1" }; - private static final String[] PLACE_NAMES = new String[] { - "city", "neigborhood", "county" - }; private Context mContext; @@ -212,31 +209,22 @@ public class YahooWeatherProvider implements WeatherProvider { @Override public WeatherInfo getWeatherInfo(Location location, boolean metric) { String language = getLanguage(); - String params = String.format(Locale.US, "\"%f %f\" and locale=\"%s\"", + String params = String.format(Locale.US, "\"(%f,%f)\" and lang=\"%s\"", location.getLatitude(), location.getLongitude(), language); String url = URL_PLACEFINDER + Uri.encode(params); JSONObject results = fetchResults(url); if (results == null) { return null; } - try { - JSONObject result = results.getJSONObject("Result"); - String woeid = result.getString("woeid"); - + JSONObject place = results.getJSONObject("place"); + LocationResult result = parsePlace(place); + String woeid = null; String city = null; - for (String name : PLACE_NAMES) { - if (!result.isNull(name)) { - city = result.getString(name); - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.v(TAG, String.format(Locale.US, "Placefinder for location %f %f " + - "matched %s using %s", location.getLatitude(), - location.getLongitude(), city, name)); - } - break; - } + if (result != null) { + woeid = result.id; + city = result.city; } - // The city name in the placefinder result is HTML encoded :-( if (city != null) { city = Html.fromHtml(city).toString(); @@ -271,7 +259,11 @@ public class YahooWeatherProvider implements WeatherProvider { for (String name : LOCALITY_NAMES) { if (!place.isNull(name)) { - result.city = place.getJSONObject(name).getString("content"); + JSONObject localeObject = place.getJSONObject(name); + result.city = localeObject.getString("content"); + if (localeObject.optString("woeid") != null) { + result.id = localeObject.getString("woeid"); + } break; } } |