Add support for multiple languages in search suggestions

This commit is contained in:
Anthony Restaino 2015-11-01 17:25:40 -05:00
parent 23dc83fb6a
commit 9a9a06fe7b

View File

@ -63,6 +63,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
private final boolean mIncognito; private final boolean mIncognito;
private static final String CACHE_FILE_TYPE = ".sgg"; private static final String CACHE_FILE_TYPE = ".sgg";
private static final String ENCODING = "ISO-8859-1"; private static final String ENCODING = "ISO-8859-1";
private static final String DEFAULT_LANGUAGE = "en";
private static final long INTERVAL_DAY = 86400000; private static final long INTERVAL_DAY = 86400000;
private static final int MAX_SUGGESTIONS = 5; private static final int MAX_SUGGESTIONS = 5;
private static final SuggestionsComparator mComparator = new SuggestionsComparator(); private static final SuggestionsComparator mComparator = new SuggestionsComparator();
@ -374,9 +375,13 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
} }
InputStream in = null; InputStream in = null;
FileOutputStream fos = null; FileOutputStream fos = null;
String language = Locale.getDefault().getLanguage();
if (language.isEmpty()) {
language = DEFAULT_LANGUAGE;
}
try { try {
URL url = new URL("http://google.com/complete/search?q=" + query URL url = new URL("http://google.com/complete/search?q=" + query
+ "&output=toolbar&hl=en"); + "&output=toolbar&hl=" + language);
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true); connection.setDoInput(true);
connection.connect(); connection.connect();