(int itemId, EditText etBody, int start, int end, boolean select)
| 968 | } |
| 969 | |
| 970 | static boolean setList(int itemId, EditText etBody, int start, int end, boolean select) { |
| 971 | Log.breadcrumb("style", "action", "list"); |
| 972 | |
| 973 | Context context = etBody.getContext(); |
| 974 | Editable edit = etBody.getText(); |
| 975 | |
| 976 | int colorAccent = Helper.resolveColor(context, androidx.appcompat.R.attr.colorAccent); |
| 977 | int bulletGap = context.getResources().getDimensionPixelSize(R.dimen.bullet_gap_size); |
| 978 | int bulletRadius = context.getResources().getDimensionPixelSize(R.dimen.bullet_radius_size); |
| 979 | int bulletIndent = context.getResources().getDimensionPixelSize(R.dimen.bullet_indent_size); |
| 980 | |
| 981 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); |
| 982 | int message_zoom = prefs.getInt("message_zoom", 100); |
| 983 | float textSize = Helper.getTextSize(context, 0) * message_zoom / 100f; |
| 984 | |
| 985 | Pair<Integer, Integer> paragraph = ensureParagraph(edit, start, end); |
| 986 | if (paragraph == null) |
| 987 | return false; |
| 988 | |
| 989 | int s = paragraph.first; |
| 990 | int e = paragraph.second; |
| 991 | |
| 992 | // Remove existing bullets |
| 993 | BulletSpan[] spans = edit.getSpans(s, e, BulletSpan.class); |
| 994 | for (BulletSpan span : spans) |
| 995 | edit.removeSpan(span); |
| 996 | |
| 997 | int i = s; |
| 998 | int j = s + 1; |
| 999 | int index = 1; |
| 1000 | while (j < e) { |
| 1001 | if (i > 0 && edit.charAt(i - 1) == '\n' && edit.charAt(j) == '\n') { |
| 1002 | Log.i("Insert " + i + "..." + (j + 1) + " size=" + e); |
| 1003 | if (itemId == R.id.menu_style_list_bullets) |
| 1004 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) |
| 1005 | edit.setSpan(new BulletSpanEx(bulletIndent, bulletGap, colorAccent, 0), i, j + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_PARAGRAPH); |
| 1006 | else |
| 1007 | edit.setSpan(new BulletSpanEx(bulletIndent, bulletGap, colorAccent, bulletRadius, 0), i, j + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_PARAGRAPH); |
| 1008 | else |
| 1009 | edit.setSpan(new NumberSpan(bulletIndent, bulletGap, colorAccent, textSize, 0, index++), i, j + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_PARAGRAPH); |
| 1010 | |
| 1011 | i = j + 1; |
| 1012 | } |
| 1013 | j++; |
| 1014 | } |
| 1015 | |
| 1016 | renumber(edit, false, context); |
| 1017 | |
| 1018 | etBody.setText(edit); |
| 1019 | etBody.setSelection(select ? s : e - 1, e - 1); |
| 1020 | |
| 1021 | return true; |
| 1022 | } |
| 1023 | |
| 1024 | static boolean selectIndentation(LifecycleOwner owner, View anchor, EditText etBody, int start, int end) { |
| 1025 | Log.breadcrumb("style", "action", "selectIndentation"); |
no test coverage detected