mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
77dbd3dbc7
commit
ae960092bd
|
@ -106,6 +106,58 @@ public class EditTextCompose extends FixedEditText {
|
||||||
boolean undo_manager = prefs.getBoolean("undo_manager", false);
|
boolean undo_manager = prefs.getBoolean("undo_manager", false);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
setCustomSelectionActionModeCallback(new ActionMode.Callback() {
|
||||||
|
@Override
|
||||||
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||||
|
try {
|
||||||
|
int order = 1000;
|
||||||
|
menu.add(Menu.CATEGORY_SECONDARY, R.string.title_insert_parenthesis, order++, context.getString(R.string.title_insert_parenthesis));
|
||||||
|
menu.add(Menu.CATEGORY_SECONDARY, R.string.title_insert_quotes, order++, context.getString(R.string.title_insert_quotes));
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
Log.e(ex);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||||
|
int start = getSelectionStart();
|
||||||
|
int end = getSelectionEnd();
|
||||||
|
boolean selection = (BuildConfig.DEBUG && start >= 0 && start < end);
|
||||||
|
menu.findItem(R.string.title_insert_parenthesis).setVisible(selection);
|
||||||
|
menu.findItem(R.string.title_insert_quotes).setVisible(selection);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||||
|
if (item.getGroupId() == Menu.CATEGORY_SECONDARY) {
|
||||||
|
int id = item.getItemId();
|
||||||
|
if (id == R.string.title_insert_parenthesis)
|
||||||
|
return surround("(", ")");
|
||||||
|
else if (id == R.string.title_insert_quotes)
|
||||||
|
return surround("\"", "\"");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyActionMode(ActionMode mode) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean surround(String before, String after) {
|
||||||
|
int start = getSelectionStart();
|
||||||
|
int end = getSelectionEnd();
|
||||||
|
boolean selection = (start >= 0 && start < end);
|
||||||
|
if (selection) {
|
||||||
|
getText().insert(end, after);
|
||||||
|
getText().insert(start, before);
|
||||||
|
}
|
||||||
|
return selection;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
setCustomInsertionActionModeCallback(new ActionMode.Callback() {
|
setCustomInsertionActionModeCallback(new ActionMode.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||||
|
|
|
@ -213,8 +213,6 @@ public class StyleHelper {
|
||||||
popupMenu.getMenu().findItem(R.id.menu_style_indentation_increase).setEnabled(maxLevel == null);
|
popupMenu.getMenu().findItem(R.id.menu_style_indentation_increase).setEnabled(maxLevel == null);
|
||||||
popupMenu.getMenu().findItem(R.id.menu_style_indentation_decrease).setEnabled(indents.length > 0);
|
popupMenu.getMenu().findItem(R.id.menu_style_indentation_decrease).setEnabled(indents.length > 0);
|
||||||
|
|
||||||
popupMenu.getMenu().findItem(R.id.menu_style_parenthesis).setEnabled(BuildConfig.DEBUG);
|
|
||||||
popupMenu.getMenu().findItem(R.id.menu_style_quotes).setEnabled(BuildConfig.DEBUG);
|
|
||||||
popupMenu.getMenu().findItem(R.id.menu_style_code).setEnabled(BuildConfig.DEBUG);
|
popupMenu.getMenu().findItem(R.id.menu_style_code).setEnabled(BuildConfig.DEBUG);
|
||||||
|
|
||||||
popupMenu.insertIcons(context);
|
popupMenu.insertIcons(context);
|
||||||
|
@ -250,10 +248,6 @@ public class StyleHelper {
|
||||||
return setMark(item);
|
return setMark(item);
|
||||||
} else if (groupId == R.id.group_style_strikethrough) {
|
} else if (groupId == R.id.group_style_strikethrough) {
|
||||||
return setStrikeThrough(item);
|
return setStrikeThrough(item);
|
||||||
} else if (groupId == R.id.group_style_parenthesis) {
|
|
||||||
return surround(item, "(", ")");
|
|
||||||
} else if (groupId == R.id.group_style_quotes) {
|
|
||||||
return surround(item, "\"", "\"");
|
|
||||||
} else if (groupId == R.id.group_style_code) {
|
} else if (groupId == R.id.group_style_code) {
|
||||||
return setCode(item);
|
return setCode(item);
|
||||||
} else if (groupId == R.id.group_style_clear) {
|
} else if (groupId == R.id.group_style_clear) {
|
||||||
|
@ -495,13 +489,6 @@ public class StyleHelper {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean surround(MenuItem item, String before, String after) {
|
|
||||||
Log.breadcrumb("style", "action", "parenthesis");
|
|
||||||
edit.insert(end, after);
|
|
||||||
edit.insert(start, before);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean setCode(MenuItem item) {
|
private boolean setCode(MenuItem item) {
|
||||||
Log.breadcrumb("style", "action", "code");
|
Log.breadcrumb("style", "action", "code");
|
||||||
_setSize(HtmlHelper.FONT_SMALL);
|
_setSize(HtmlHelper.FONT_SMALL);
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="24dp"
|
|
||||||
android:height="24dp"
|
|
||||||
android:viewportWidth="24"
|
|
||||||
android:viewportHeight="24"
|
|
||||||
android:tint="?attr/colorControlNormal">
|
|
||||||
<path
|
|
||||||
android:fillColor="@android:color/white"
|
|
||||||
android:pathData="M4,22H2V2h2V22zM22,2h-2v20h2V2zM13.5,7h-3v10h3V7z"/>
|
|
||||||
</vector>
|
|
|
@ -159,27 +159,9 @@
|
||||||
android:title="@string/title_style_strikethrough" />
|
android:title="@string/title_style_strikethrough" />
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
<group
|
|
||||||
android:id="@+id/group_style_parenthesis"
|
|
||||||
android:orderInCategory="11">
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_style_parenthesis"
|
|
||||||
android:icon="@drawable/twotone_data_object_24"
|
|
||||||
android:title="@string/title_style_parenthesis" />
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<group
|
|
||||||
android:id="@+id/group_style_quotes"
|
|
||||||
android:orderInCategory="12">
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_style_quotes"
|
|
||||||
android:icon="@drawable/twotone_horizontal_distribute_24"
|
|
||||||
android:title="@string/title_style_quotes" />
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<group
|
<group
|
||||||
android:id="@+id/group_style_code"
|
android:id="@+id/group_style_code"
|
||||||
android:orderInCategory="13">
|
android:orderInCategory="11">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_style_code"
|
android:id="@+id/menu_style_code"
|
||||||
android:icon="@drawable/twotone_code_24"
|
android:icon="@drawable/twotone_code_24"
|
||||||
|
@ -188,7 +170,7 @@
|
||||||
|
|
||||||
<group
|
<group
|
||||||
android:id="@+id/group_style_clear"
|
android:id="@+id/group_style_clear"
|
||||||
android:orderInCategory="14">
|
android:orderInCategory="12">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_style_clear"
|
android:id="@+id/menu_style_clear"
|
||||||
android:icon="@drawable/twotone_format_clear_24"
|
android:icon="@drawable/twotone_format_clear_24"
|
||||||
|
|
|
@ -1444,8 +1444,6 @@
|
||||||
<string name="title_style_indentation">Indentation</string>
|
<string name="title_style_indentation">Indentation</string>
|
||||||
<string name="title_style_mark">Highlight</string>
|
<string name="title_style_mark">Highlight</string>
|
||||||
<string name="title_style_strikethrough">Strikethrough</string>
|
<string name="title_style_strikethrough">Strikethrough</string>
|
||||||
<string name="title_style_parenthesis" translatable="false">Parenthesis</string>
|
|
||||||
<string name="title_style_quotes" translatable="false">Quotes</string>
|
|
||||||
<string name="title_style_code" translatable="false">Code</string>
|
<string name="title_style_code" translatable="false">Code</string>
|
||||||
<string name="title_style_clear">Clear formatting</string>
|
<string name="title_style_clear">Clear formatting</string>
|
||||||
<string name="title_style_link">Insert link</string>
|
<string name="title_style_link">Insert link</string>
|
||||||
|
@ -1951,6 +1949,8 @@
|
||||||
<string name="title_redo">Redo</string>
|
<string name="title_redo">Redo</string>
|
||||||
<string name="title_insert_line">Insert line</string>
|
<string name="title_insert_line">Insert line</string>
|
||||||
<string name="title_select_block">Select block</string>
|
<string name="title_select_block">Select block</string>
|
||||||
|
<string name="title_insert_parenthesis">Parenthesis</string>
|
||||||
|
<string name="title_insert_quotes">Quote</string>
|
||||||
<string name="title_add">Add</string>
|
<string name="title_add">Add</string>
|
||||||
<string name="title_browse">Open with</string>
|
<string name="title_browse">Open with</string>
|
||||||
<string name="title_info">Info</string>
|
<string name="title_info">Info</string>
|
||||||
|
|
Loading…
Reference in New Issue