(Context context, String[] dictionary)
| 353 | } |
| 354 | |
| 355 | static List<String> getWords(Context context, String[] dictionary) throws IOException, JSONException { |
| 356 | List<String> result = new ArrayList<>(); |
| 357 | |
| 358 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); |
| 359 | String lt_user = prefs.getString("lt_user", null); |
| 360 | String lt_key = prefs.getString("lt_key", null); |
| 361 | String lt_uri = prefs.getString("lt_uri", LT_URI_PLUS); |
| 362 | |
| 363 | if (TextUtils.isEmpty(lt_user) || TextUtils.isEmpty(lt_key)) |
| 364 | return result; |
| 365 | |
| 366 | // https://languagetool.org/http-api/swagger-ui/#!/default/get_words |
| 367 | Uri.Builder builder = Uri.parse(lt_uri).buildUpon() |
| 368 | .appendPath("words") |
| 369 | .appendQueryParameter("offset", "0") |
| 370 | .appendQueryParameter("limit", "500") |
| 371 | .appendQueryParameter("username", lt_user) |
| 372 | .appendQueryParameter("apiKey", lt_key); |
| 373 | |
| 374 | if (dictionary != null && dictionary.length > 0) |
| 375 | builder.appendQueryParameter("dicts", TextUtils.join(",", dictionary)); |
| 376 | |
| 377 | Uri uri = builder.build(); |
| 378 | Log.i("LT uri=" + uri); |
| 379 | |
| 380 | URL url = new URL(uri.toString()); |
| 381 | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| 382 | connection.setRequestMethod("GET"); |
| 383 | connection.setDoOutput(false); |
| 384 | connection.setReadTimeout(LT_TIMEOUT * 1000); |
| 385 | connection.setConnectTimeout(LT_TIMEOUT * 1000); |
| 386 | ConnectionHelper.setUserAgent(context, connection); |
| 387 | connection.setRequestProperty("Accept", "application/json"); |
| 388 | connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); |
| 389 | connection.connect(); |
| 390 | |
| 391 | try { |
| 392 | checkStatus(connection); |
| 393 | |
| 394 | String response = Helper.readStream(connection.getInputStream()); |
| 395 | Log.i("LT response=" + response); |
| 396 | |
| 397 | JSONObject jroot = new JSONObject(response); |
| 398 | JSONArray jwords = jroot.getJSONArray("words"); |
| 399 | for (int i = 0; i < jwords.length(); i++) |
| 400 | result.add(jwords.getString(i)); |
| 401 | |
| 402 | return result; |
| 403 | } finally { |
| 404 | connection.disconnect(); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | static void applySuggestions(EditText etBody, int start, int end, List<Suggestion> suggestions) { |
| 409 | if (etBody == null) |
nothing calls this directly
no test coverage detected