(EditText etBody, int start, int end, Object... args)
| 1351 | } |
| 1352 | |
| 1353 | static boolean setLink(EditText etBody, int start, int end, Object... args) { |
| 1354 | Log.breadcrumb("style", "action", "link"); |
| 1355 | |
| 1356 | long working = (Long) args[0]; |
| 1357 | int zoom = (Integer) args[1]; |
| 1358 | String url = (String) args[2]; |
| 1359 | boolean image = (Boolean) args[3]; |
| 1360 | String title = (String) args[4]; |
| 1361 | |
| 1362 | Editable edit = etBody.getText(); |
| 1363 | if (image) { |
| 1364 | if (!UriHelper.isHyperLink(url)) |
| 1365 | return false; |
| 1366 | |
| 1367 | SpannableStringBuilder ssb = new SpannableStringBuilderEx(edit); |
| 1368 | |
| 1369 | ssb.insert(start, "\n\uFFFC\n"); // Object replacement character |
| 1370 | |
| 1371 | Drawable img = ImageHelper.decodeImage(etBody.getContext(), |
| 1372 | working, url, true, zoom, 1.0f, etBody); |
| 1373 | |
| 1374 | ImageSpan is = new ImageSpan(img, url); |
| 1375 | ssb.setSpan(is, start + 1, start + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| 1376 | |
| 1377 | etBody.setText(ssb); |
| 1378 | etBody.setSelection(start + 3); |
| 1379 | } else { |
| 1380 | URLSpan[] spans = edit.getSpans(start, end, URLSpan.class); |
| 1381 | for (URLSpan span : spans) |
| 1382 | edit.removeSpan(span); |
| 1383 | |
| 1384 | if (!TextUtils.isEmpty(url)) { |
| 1385 | if (TextUtils.isEmpty(title)) |
| 1386 | title = url; |
| 1387 | |
| 1388 | if (start == end) |
| 1389 | edit.insert(start, title); |
| 1390 | else if (!title.equals(edit.subSequence(start, end).toString())) |
| 1391 | edit.replace(start, end, title); |
| 1392 | |
| 1393 | edit.setSpan(new URLSpan(url), start, start + title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| 1394 | } |
| 1395 | |
| 1396 | etBody.setText(edit); |
| 1397 | etBody.setSelection(start + title.length()); |
| 1398 | } |
| 1399 | |
| 1400 | return true; |
| 1401 | |
| 1402 | } |
| 1403 | |
| 1404 | static boolean clear(EditText etBody, int start, int end, boolean select) { |
| 1405 | Log.breadcrumb("style", "action", "clear"); |
no test coverage detected