aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDanesh M <daneshm90@gmail.com>2016-02-14 11:54:26 -0800
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-02-15 11:33:05 -0800
commit96f7b8cc03911b5117599457832f1a88a801ff45 (patch)
tree683498e3f3f49b27ca81fd2d37f39bbb55cc25f6 /src
parent70f751feea08cd3bd9ef9b0321e1e63160a8cd75 (diff)
downloadandroid_packages_apps_LockClock-96f7b8cc03911b5117599457832f1a88a801ff45.tar.gz
android_packages_apps_LockClock-96f7b8cc03911b5117599457832f1a88a801ff45.tar.bz2
android_packages_apps_LockClock-96f7b8cc03911b5117599457832f1a88a801ff45.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 Change-Id: Iff949b2e28f1938265dd8074b6e332317e10f0e0
Diffstat (limited to 'src')
-rw-r--r--src/com/cyanogenmod/lockclock/weather/YahooWeatherProvider.java36
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;
}
}