2021-01-17 13:47:24 +00:00
|
|
|
package eu.faircode.email;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This file is part of FairEmail.
|
|
|
|
|
|
|
|
FairEmail is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
FairEmail is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2022-01-01 08:46:36 +00:00
|
|
|
Copyright 2018-2022 by Marcel Bokhorst (M66B)
|
2021-01-17 13:47:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import android.content.Context;
|
2022-02-21 12:14:51 +00:00
|
|
|
import android.content.SharedPreferences;
|
2022-02-22 11:36:30 +00:00
|
|
|
import android.content.res.ColorStateList;
|
2022-02-24 14:10:39 +00:00
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
2021-12-15 16:51:06 +00:00
|
|
|
import android.graphics.Canvas;
|
2022-02-23 08:48:26 +00:00
|
|
|
import android.graphics.Rect;
|
2022-02-24 14:10:39 +00:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
2022-02-20 21:07:10 +00:00
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.net.Uri;
|
2022-02-24 18:15:21 +00:00
|
|
|
import android.os.Build;
|
2022-02-20 21:07:10 +00:00
|
|
|
import android.provider.ContactsContract;
|
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.Spanned;
|
2022-02-24 18:15:21 +00:00
|
|
|
import android.text.TextDirectionHeuristics;
|
2022-02-20 21:07:10 +00:00
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.text.style.DynamicDrawableSpan;
|
|
|
|
import android.text.style.ImageSpan;
|
2021-01-17 13:47:24 +00:00
|
|
|
import android.util.AttributeSet;
|
2022-02-20 21:07:10 +00:00
|
|
|
import android.view.ContextThemeWrapper;
|
2021-12-15 16:51:06 +00:00
|
|
|
import android.view.MotionEvent;
|
2022-02-24 18:15:21 +00:00
|
|
|
import android.view.View;
|
2021-01-17 13:47:24 +00:00
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.widget.AppCompatMultiAutoCompleteTextView;
|
2022-02-22 11:36:30 +00:00
|
|
|
import androidx.core.graphics.ColorUtils;
|
2022-02-21 12:14:51 +00:00
|
|
|
import androidx.preference.PreferenceManager;
|
2021-01-17 13:47:24 +00:00
|
|
|
|
2022-02-20 21:07:10 +00:00
|
|
|
import com.google.android.material.chip.ChipDrawable;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2022-03-04 12:41:39 +00:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
2022-02-20 21:07:10 +00:00
|
|
|
|
2022-03-04 12:41:39 +00:00
|
|
|
import javax.mail.Address;
|
2022-02-20 21:07:10 +00:00
|
|
|
import javax.mail.internet.AddressException;
|
|
|
|
import javax.mail.internet.InternetAddress;
|
|
|
|
|
2021-01-17 13:47:24 +00:00
|
|
|
public class EditTextMultiAutoComplete extends AppCompatMultiAutoCompleteTextView {
|
2022-02-22 22:44:52 +00:00
|
|
|
private SharedPreferences prefs;
|
|
|
|
private boolean dark;
|
|
|
|
private int colorAccent;
|
|
|
|
private ContextThemeWrapper ctx;
|
2022-02-23 19:01:35 +00:00
|
|
|
private Tokenizer tokenizer;
|
2022-03-04 17:58:02 +00:00
|
|
|
private Map<String, Integer> encryption = new ConcurrentHashMap<>();
|
2022-03-04 12:41:39 +00:00
|
|
|
|
|
|
|
private static ExecutorService executor = Helper.getBackgroundExecutor(1, "chips");
|
2022-02-22 22:44:52 +00:00
|
|
|
|
2022-03-04 17:58:02 +00:00
|
|
|
private static int[] icons = new int[]{
|
2022-03-05 07:44:05 +00:00
|
|
|
R.drawable.twotone_vpn_key_24_p,
|
|
|
|
R.drawable.twotone_vpn_key_24_s,
|
2022-03-04 17:58:02 +00:00
|
|
|
R.drawable.twotone_vpn_key_24_b
|
|
|
|
};
|
|
|
|
|
2021-01-17 13:47:24 +00:00
|
|
|
public EditTextMultiAutoComplete(@NonNull Context context) {
|
|
|
|
super(context);
|
2022-02-20 21:07:10 +00:00
|
|
|
init(context);
|
2021-01-17 13:47:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public EditTextMultiAutoComplete(@NonNull Context context, @Nullable AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
2022-02-20 21:07:10 +00:00
|
|
|
init(context);
|
2021-01-17 13:47:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public EditTextMultiAutoComplete(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
|
|
super(context, attrs, defStyleAttr);
|
2022-02-20 21:07:10 +00:00
|
|
|
init(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void init(Context context) {
|
2021-01-17 13:47:24 +00:00
|
|
|
Helper.setKeyboardIncognitoMode(this, context);
|
2022-02-20 21:07:10 +00:00
|
|
|
|
2022-02-23 19:01:35 +00:00
|
|
|
tokenizer = new CommaTokenizer();
|
|
|
|
setTokenizer(tokenizer);
|
|
|
|
|
2022-02-22 22:44:52 +00:00
|
|
|
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
dark = Helper.isDarkTheme(context);
|
|
|
|
colorAccent = Helper.resolveColor(context, R.attr.colorAccent);
|
|
|
|
colorAccent = ColorUtils.setAlphaComponent(colorAccent, 5 * 255 / 100);
|
|
|
|
ctx = new ContextThemeWrapper(context, dark ? R.style.ChipDark : R.style.ChipLight);
|
2022-02-22 07:29:06 +00:00
|
|
|
|
|
|
|
addTextChangedListener(new TextWatcher() {
|
2022-02-22 22:44:52 +00:00
|
|
|
private Integer backspace = null;
|
2022-02-22 18:50:11 +00:00
|
|
|
|
2022-02-22 07:29:06 +00:00
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
2022-02-22 18:50:11 +00:00
|
|
|
backspace = (count - after == 1 ? start : null);
|
2022-02-22 07:29:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable edit) {
|
2022-06-16 10:08:21 +00:00
|
|
|
if (backspace != null)
|
|
|
|
post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
2022-07-02 06:51:32 +00:00
|
|
|
if (edit == null)
|
|
|
|
return;
|
2022-06-16 10:08:21 +00:00
|
|
|
ClipImageSpan[] spans = edit.getSpans(backspace, backspace, ClipImageSpan.class);
|
|
|
|
if (spans.length == 1) {
|
|
|
|
int start = edit.getSpanStart(spans[0]);
|
|
|
|
int end = edit.getSpanEnd(spans[0]);
|
2022-06-19 05:54:41 +00:00
|
|
|
if (backspace > start)
|
|
|
|
edit.delete(start, end);
|
2022-06-16 10:08:21 +00:00
|
|
|
}
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-02-22 18:50:11 +00:00
|
|
|
|
2022-03-28 19:34:40 +00:00
|
|
|
post(update);
|
2022-02-22 07:29:06 +00:00
|
|
|
}
|
|
|
|
});
|
2021-01-17 13:47:24 +00:00
|
|
|
}
|
2021-12-15 16:51:06 +00:00
|
|
|
|
2022-02-22 22:44:52 +00:00
|
|
|
@Override
|
2022-02-23 08:48:26 +00:00
|
|
|
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
|
|
|
|
super.onFocusChanged(focused, direction, previouslyFocusedRect);
|
|
|
|
post(update);
|
|
|
|
}
|
2022-02-22 22:44:52 +00:00
|
|
|
|
2022-02-23 08:48:26 +00:00
|
|
|
@Override
|
|
|
|
protected void onSelectionChanged(int selStart, int selEnd) {
|
|
|
|
super.onSelectionChanged(selStart, selEnd);
|
2022-02-22 22:44:52 +00:00
|
|
|
post(update);
|
2022-02-21 11:07:13 +00:00
|
|
|
}
|
|
|
|
|
2022-02-26 15:16:46 +00:00
|
|
|
@Override
|
|
|
|
public void setEnabled(boolean enabled) {
|
|
|
|
super.setEnabled(enabled);
|
|
|
|
setAlpha(enabled ? 1.0f : Helper.LOW_LIGHT);
|
|
|
|
}
|
|
|
|
|
2021-12-15 16:51:06 +00:00
|
|
|
@Override
|
|
|
|
public boolean onPreDraw() {
|
|
|
|
try {
|
|
|
|
return super.onPreDraw();
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.w(ex);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
try {
|
|
|
|
super.onDraw(canvas);
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.w(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent event) {
|
|
|
|
try {
|
|
|
|
return super.dispatchTouchEvent(event);
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.w(ex);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
try {
|
2022-02-24 09:13:37 +00:00
|
|
|
return super.onTouchEvent(event);
|
2021-12-15 16:51:06 +00:00
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.w(ex);
|
2022-02-24 09:13:37 +00:00
|
|
|
return true;
|
2021-12-15 16:51:06 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-22 22:44:52 +00:00
|
|
|
|
2022-02-23 19:01:35 +00:00
|
|
|
@Override
|
|
|
|
protected void replaceText(CharSequence text) {
|
|
|
|
clearComposingText();
|
|
|
|
|
|
|
|
Editable edit = getText();
|
|
|
|
int _end = getSelectionEnd();
|
|
|
|
int start = tokenizer.findTokenStart(edit, _end);
|
|
|
|
int end = tokenizer.findTokenEnd(edit, _end);
|
|
|
|
if (end < edit.length() && edit.charAt(end) == ',') {
|
|
|
|
end++;
|
|
|
|
while (end < edit.length() && edit.charAt(end) == ' ')
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
|
|
|
|
edit.replace(start, end, tokenizer.terminateToken(text));
|
|
|
|
|
|
|
|
setSelection(edit.length());
|
|
|
|
}
|
|
|
|
|
2022-02-23 12:26:32 +00:00
|
|
|
private final Runnable update = new Runnable() {
|
2022-02-22 22:44:52 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
final Context context = getContext();
|
2022-02-24 14:10:39 +00:00
|
|
|
final Resources res = getResources();
|
2022-02-22 22:44:52 +00:00
|
|
|
final Editable edit = getText();
|
2022-02-24 14:20:40 +00:00
|
|
|
final int dp3 = Helper.dp2pixels(context, 3);
|
2022-02-24 14:10:39 +00:00
|
|
|
final int dp24 = Helper.dp2pixels(context, 24);
|
2022-02-24 10:00:01 +00:00
|
|
|
final boolean send_chips = prefs.getBoolean("send_chips", true);
|
2022-02-24 14:10:39 +00:00
|
|
|
boolean generated = prefs.getBoolean("generated_icons", true);
|
|
|
|
boolean identicons = prefs.getBoolean("identicons", false);
|
2022-02-24 14:20:40 +00:00
|
|
|
boolean circular = prefs.getBoolean("circular", true);
|
2022-02-22 22:44:52 +00:00
|
|
|
|
2022-02-23 08:48:26 +00:00
|
|
|
final boolean focus = hasFocus();
|
|
|
|
final int selStart = getSelectionStart();
|
|
|
|
final int selEnd = getSelectionEnd();
|
|
|
|
|
2022-02-22 22:44:52 +00:00
|
|
|
boolean added = false;
|
2022-02-23 08:48:26 +00:00
|
|
|
List<ClipImageSpan> tbd = new ArrayList<>();
|
2022-02-23 14:03:24 +00:00
|
|
|
tbd.addAll(Arrays.asList(edit.getSpans(0, edit.length(), ClipImageSpan.class)));
|
2022-02-22 22:44:52 +00:00
|
|
|
|
|
|
|
if (send_chips) {
|
|
|
|
int start = 0;
|
2022-02-23 08:48:26 +00:00
|
|
|
boolean space = true;
|
|
|
|
boolean quote = false;
|
2022-02-23 14:03:24 +00:00
|
|
|
for (int i = 0; i < edit.length(); i++) {
|
2022-02-22 22:44:52 +00:00
|
|
|
char kar = edit.charAt(i);
|
2022-02-23 08:48:26 +00:00
|
|
|
|
|
|
|
if (space && kar == ' ') {
|
|
|
|
start++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
space = false;
|
|
|
|
|
2022-02-22 22:44:52 +00:00
|
|
|
if (kar == '"')
|
|
|
|
quote = !quote;
|
2022-02-23 14:03:24 +00:00
|
|
|
else if (!quote && (kar == ',' || (!focus && i + 1 == edit.length()))) {
|
2022-02-22 22:44:52 +00:00
|
|
|
boolean found = false;
|
2022-02-23 08:48:26 +00:00
|
|
|
for (ClipImageSpan span : new ArrayList<>(tbd)) {
|
2022-02-22 22:44:52 +00:00
|
|
|
int s = edit.getSpanStart(span);
|
|
|
|
int e = edit.getSpanEnd(span);
|
|
|
|
if (s == start && e == i + 1) {
|
2022-03-04 12:41:39 +00:00
|
|
|
found = !span.needsUpdate();
|
|
|
|
if (found && !(focus && overlap(start, i, selStart, selEnd)))
|
2022-02-23 08:48:26 +00:00
|
|
|
tbd.remove(span);
|
2022-02-22 22:44:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found && start < i + 1 &&
|
2022-02-23 08:48:26 +00:00
|
|
|
!(focus && overlap(start, i, selStart, selEnd))) {
|
2022-02-24 18:27:34 +00:00
|
|
|
String address = edit.subSequence(start, i + 1).toString();
|
2022-02-22 22:44:52 +00:00
|
|
|
InternetAddress[] parsed;
|
|
|
|
try {
|
2022-02-24 18:27:34 +00:00
|
|
|
parsed = MessageHelper.parseAddresses(context, address);
|
2022-02-22 22:44:52 +00:00
|
|
|
if (parsed != null)
|
|
|
|
for (InternetAddress a : parsed)
|
|
|
|
a.validate();
|
|
|
|
} catch (AddressException ex) {
|
|
|
|
parsed = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parsed != null && parsed.length == 1) {
|
2022-02-23 14:03:24 +00:00
|
|
|
if (kar == ' ')
|
|
|
|
edit.insert(i++, ",");
|
|
|
|
else if (kar != ',')
|
2022-02-23 12:26:32 +00:00
|
|
|
edit.insert(++i, ",");
|
|
|
|
|
2022-02-24 18:27:34 +00:00
|
|
|
String email = parsed[0].getAddress();
|
|
|
|
String personal = parsed[0].getPersonal();
|
2022-02-24 14:10:39 +00:00
|
|
|
|
|
|
|
Bitmap bm = null;
|
2022-02-22 22:44:52 +00:00
|
|
|
Uri lookupUri = ContactInfo.getLookupUri(parsed);
|
2022-02-24 12:30:45 +00:00
|
|
|
if (lookupUri != null)
|
|
|
|
try (InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(
|
|
|
|
context.getContentResolver(), lookupUri, false)) {
|
2022-02-24 14:10:39 +00:00
|
|
|
bm = BitmapFactory.decodeStream(is);
|
2022-02-24 12:30:45 +00:00
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(ex);
|
|
|
|
}
|
2022-02-22 22:44:52 +00:00
|
|
|
|
2022-02-24 18:27:34 +00:00
|
|
|
if (bm == null && generated && !TextUtils.isEmpty(address))
|
2022-02-24 14:10:39 +00:00
|
|
|
if (identicons)
|
2022-02-24 18:27:34 +00:00
|
|
|
bm = ImageHelper.generateIdenticon(email, dp24, 5, context);
|
2022-02-24 14:10:39 +00:00
|
|
|
else
|
2022-02-24 18:27:34 +00:00
|
|
|
bm = ImageHelper.generateLetterIcon(email, personal, dp24, context);
|
2022-02-24 14:10:39 +00:00
|
|
|
|
2022-02-24 14:20:40 +00:00
|
|
|
if (bm != null && circular && !identicons)
|
|
|
|
bm = ImageHelper.makeCircular(bm, dp3);
|
|
|
|
|
2022-02-24 14:10:39 +00:00
|
|
|
Drawable avatar = (bm == null ? null : new BitmapDrawable(res, bm));
|
|
|
|
|
2022-02-24 18:27:34 +00:00
|
|
|
String text = (TextUtils.isEmpty(personal) ? email : personal);
|
2022-02-22 22:44:52 +00:00
|
|
|
|
|
|
|
// https://github.com/material-components/material-components-android/blob/master/docs/components/Chip.md
|
|
|
|
ChipDrawable cd = ChipDrawable.createFromResource(ctx, R.xml.chip);
|
|
|
|
cd.setChipIcon(avatar);
|
2022-02-24 18:15:21 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
|
|
|
try {
|
|
|
|
if (TextDirectionHeuristics.FIRSTSTRONG_LTR.isRtl(text, 0, text.length()))
|
|
|
|
cd.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(ex);
|
|
|
|
}
|
2022-02-22 22:44:52 +00:00
|
|
|
cd.setText(text);
|
|
|
|
cd.setChipBackgroundColor(ColorStateList.valueOf(colorAccent));
|
|
|
|
|
|
|
|
ClipImageSpan is = new ClipImageSpan(cd);
|
2022-02-24 18:27:34 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
|
|
|
is.setContentDescription(email);
|
2022-03-04 12:41:39 +00:00
|
|
|
|
2022-03-04 17:58:02 +00:00
|
|
|
Integer has = encryption.get(email);
|
2022-03-04 12:41:39 +00:00
|
|
|
if (has == null) {
|
|
|
|
final List<Address> recipient = Arrays.asList(new Address[]{parsed[0]});
|
|
|
|
executor.submit(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
2022-03-04 17:58:02 +00:00
|
|
|
int has = 0;
|
|
|
|
if (PgpHelper.hasPgpKey(context, recipient))
|
|
|
|
has |= 1;
|
|
|
|
if (SmimeHelper.hasSmimeKey(context, recipient))
|
|
|
|
has |= 2;
|
2022-03-04 12:41:39 +00:00
|
|
|
encryption.put(email, has);
|
2022-03-04 17:58:02 +00:00
|
|
|
|
|
|
|
if (has != 0) {
|
2022-03-04 12:41:39 +00:00
|
|
|
is.invalidate();
|
|
|
|
post(update);
|
|
|
|
}
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.w(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-03-04 17:58:02 +00:00
|
|
|
} else if (has != 0) {
|
|
|
|
cd.setCloseIcon(context.getDrawable(icons[has - 1]));
|
2022-03-04 12:41:39 +00:00
|
|
|
cd.setCloseIconVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
cd.setMaxWidth(getWidth());
|
|
|
|
cd.setBounds(0, 0, cd.getIntrinsicWidth(), cd.getIntrinsicHeight());
|
|
|
|
|
2022-02-22 22:44:52 +00:00
|
|
|
edit.setSpan(is, start, i + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
2022-02-23 12:26:32 +00:00
|
|
|
|
2022-02-23 14:03:24 +00:00
|
|
|
if (kar == ',' &&
|
|
|
|
(i + 1 == edit.length() || edit.charAt(i + 1) != ' '))
|
2022-02-23 12:26:32 +00:00
|
|
|
edit.insert(++i, " ");
|
2022-07-15 15:27:05 +00:00
|
|
|
|
|
|
|
// Workaround Android bug
|
|
|
|
/*
|
|
|
|
java.lang.IndexOutOfBoundsException: 2, 0
|
|
|
|
at android.text.PackedIntVector.getValue(PackedIntVector.java:75)
|
|
|
|
at android.text.DynamicLayout.getLineStart(DynamicLayout.java:1028)
|
|
|
|
at android.text.Layout.getLineEnd(Layout.java:1676)
|
|
|
|
at android.text.Layout.getOffsetForHorizontal(Layout.java:1545)
|
|
|
|
at android.text.Layout.getOffsetForHorizontal(Layout.java:1530)
|
|
|
|
at android.widget.TextView.getOffsetAtCoordinate(TextView.java:13250)
|
|
|
|
at android.widget.Editor$HandleView.getOffsetAtCoordinate(Editor.java:5037)
|
|
|
|
at android.widget.Editor$InsertionHandleView.updatePosition(Editor.java:5828)
|
|
|
|
at android.widget.Editor$HandleView.onTouchEvent(Editor.java:5494)
|
|
|
|
at android.widget.Editor$InsertionHandleView.onTouchEvent(Editor.java:5657)
|
|
|
|
at android.view.View.dispatchTouchEvent(View.java:14625)
|
|
|
|
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3153)
|
|
|
|
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2829)
|
|
|
|
at android.widget.PopupWindow$PopupDecorView.dispatchTouchEvent(PopupWindow.java:2566)
|
|
|
|
at android.view.View.dispatchPointerEvent(View.java:14892)
|
|
|
|
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:6674)
|
|
|
|
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:6448)
|
|
|
|
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5917)
|
|
|
|
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5979)
|
|
|
|
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5940)
|
|
|
|
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:6114)
|
|
|
|
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5948)
|
|
|
|
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:6171)
|
|
|
|
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5921)
|
|
|
|
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5979)
|
|
|
|
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5940)
|
|
|
|
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5948)
|
|
|
|
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5921)
|
|
|
|
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:8914)
|
|
|
|
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:8865)
|
|
|
|
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:8826)
|
|
|
|
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:9057)
|
|
|
|
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:260)
|
|
|
|
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
|
|
|
|
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:240)
|
|
|
|
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:9002)
|
|
|
|
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:9143)
|
|
|
|
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1205)
|
|
|
|
at android.view.Choreographer.doCallbacks(Choreographer.java:1002)
|
|
|
|
at android.view.Choreographer.doFrame(Choreographer.java:908)
|
|
|
|
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1190)
|
|
|
|
at android.os.Handler.handleCallback(Handler.java:938)
|
|
|
|
*/
|
|
|
|
edit.append("\n\n");
|
|
|
|
post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
Editable e = getText();
|
|
|
|
int len = e.length();
|
|
|
|
while (len > 0 && e.charAt(len - 1) == '\n') {
|
|
|
|
e.delete(len - 1, len);
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-02-22 22:44:52 +00:00
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-23 08:48:26 +00:00
|
|
|
start = i + 1;
|
|
|
|
space = true;
|
2022-02-22 22:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-23 08:48:26 +00:00
|
|
|
for (ClipImageSpan span : tbd)
|
2022-02-22 22:44:52 +00:00
|
|
|
edit.removeSpan(span);
|
|
|
|
|
2022-02-23 08:48:26 +00:00
|
|
|
if (tbd.size() > 0 || added)
|
2022-02-22 22:44:52 +00:00
|
|
|
invalidate();
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-02-23 08:48:26 +00:00
|
|
|
private static boolean overlap(int start, int end, int selStart, int selEnd) {
|
|
|
|
return Math.max(start, selStart) <= Math.min(end, selEnd);
|
|
|
|
}
|
|
|
|
|
2022-02-22 22:44:52 +00:00
|
|
|
private static class ClipImageSpan extends ImageSpan {
|
2022-03-04 12:41:39 +00:00
|
|
|
private boolean update;
|
|
|
|
|
2022-02-22 22:44:52 +00:00
|
|
|
public ClipImageSpan(@NonNull Drawable drawable) {
|
|
|
|
super(drawable, DynamicDrawableSpan.ALIGN_BOTTOM);
|
|
|
|
}
|
2022-03-04 12:41:39 +00:00
|
|
|
|
|
|
|
void invalidate() {
|
|
|
|
update = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean needsUpdate() {
|
|
|
|
return update;
|
|
|
|
}
|
2022-02-22 22:44:52 +00:00
|
|
|
}
|
2021-12-15 16:51:06 +00:00
|
|
|
}
|