mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-26 09:47:13 +00:00
Added select text block
This commit is contained in:
parent
ea84f158aa
commit
37a36dddbf
3 changed files with 38 additions and 6 deletions
|
@ -71,6 +71,7 @@ import android.text.TextUtils;
|
|||
import android.text.format.DateUtils;
|
||||
import android.text.format.Time;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Pair;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ActionMode;
|
||||
import android.view.KeyEvent;
|
||||
|
@ -2093,11 +2094,28 @@ public class Helper {
|
|||
return new ActionMode.Callback() {
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
try {
|
||||
int order = 1000;
|
||||
menu.add(Menu.CATEGORY_SECONDARY, R.string.title_select_block, order++,
|
||||
view.getContext().getString(R.string.title_select_block));
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||
try {
|
||||
Pair<Integer, Integer> block = StyleHelper.getParagraph(view, true);
|
||||
boolean ablock = (block != null &&
|
||||
block.first == view.getSelectionStart() &&
|
||||
block.second == view.getSelectionEnd());
|
||||
menu.findItem(R.string.title_select_block).setVisible(!ablock);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
||||
for (int i = 0; i < menu.size(); i++) {
|
||||
MenuItem item = menu.getItem(i);
|
||||
Intent intent = item.getIntent();
|
||||
|
@ -2158,6 +2176,18 @@ public class Helper {
|
|||
|
||||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
if (item.getGroupId() == Menu.CATEGORY_SECONDARY)
|
||||
try {
|
||||
int id = item.getItemId();
|
||||
if (id == R.string.title_select_block) {
|
||||
Pair<Integer, Integer> block = StyleHelper.getParagraph(view, true);
|
||||
if (block != null)
|
||||
android.text.Selection.setSelection((Spannable) view.getText(), block.first, block.second);
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ import android.view.MenuItem;
|
|||
import android.view.SubMenu;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
|
@ -889,14 +890,14 @@ public class StyleHelper {
|
|||
return new Pair<>(start, end);
|
||||
}
|
||||
|
||||
public static Pair<Integer, Integer> getParagraph(EditText etBody) {
|
||||
return getParagraph(etBody, false);
|
||||
public static Pair<Integer, Integer> getParagraph(TextView tvBody) {
|
||||
return getParagraph(tvBody, false);
|
||||
}
|
||||
|
||||
public static Pair<Integer, Integer> getParagraph(EditText etBody, boolean block) {
|
||||
int start = etBody.getSelectionStart();
|
||||
int end = etBody.getSelectionEnd();
|
||||
Editable edit = etBody.getText();
|
||||
public static Pair<Integer, Integer> getParagraph(TextView tvBody, boolean block) {
|
||||
int start = tvBody.getSelectionStart();
|
||||
int end = tvBody.getSelectionEnd();
|
||||
Spannable edit = (Spannable) tvBody.getText();
|
||||
|
||||
if (start < 0 || end < 0)
|
||||
return null;
|
||||
|
|
|
@ -1946,6 +1946,7 @@
|
|||
<string name="title_undo">Undo</string>
|
||||
<string name="title_redo">Redo</string>
|
||||
<string name="title_insert_line">Insert line</string>
|
||||
<string name="title_select_block">Select block</string>
|
||||
<string name="title_add">Add</string>
|
||||
<string name="title_browse">Open with</string>
|
||||
<string name="title_info">Info</string>
|
||||
|
|
Loading…
Reference in a new issue