Copy/paste actions

This commit is contained in:
serso 2016-04-16 23:32:05 +02:00
parent 85b9cdc56a
commit a0c45a383c
9 changed files with 40 additions and 36 deletions

View File

@ -43,6 +43,10 @@ public class Keyboard implements SharedPreferences.OnSharedPreferenceChangeListe
@Nonnull
private final MathType.Result mathType = new MathType.Result();
@Nonnull
private static final String GLYPH_PASTE = "\uE000";
@Nonnull
private static final String GLYPH_COPY = "\uE001";
@Inject
Editor editor;
@ -74,10 +78,17 @@ public class Keyboard implements SharedPreferences.OnSharedPreferenceChangeListe
return vibrateOnKeypress;
}
public boolean buttonPressed(@Nullable final String text) {
public boolean buttonPressed(@Nullable String text) {
if (TextUtils.isEmpty(text)) {
return false;
}
if (text.equals(GLYPH_COPY)) {
text = CppSpecialButton.copy.action;
} else if (text.equals(GLYPH_PASTE)) {
text = CppSpecialButton.paste.action;
}
ga.onButtonPressed(text);
if (!processSpecialAction(text)) {
processText(prepareText(text));
@ -137,10 +148,16 @@ public class Keyboard implements SharedPreferences.OnSharedPreferenceChangeListe
launcher.showHistory();
break;
case cursor_right:
moveCursorRight();
editor.moveCursorRight();
break;
case cursor_to_end:
editor.setCursorOnEnd();
break;
case cursor_left:
moveCursorLeft();
editor.moveCursorLeft();
break;
case cursor_to_start:
editor.setCursorOnStart();
break;
case settings:
launcher.showSettings();
@ -158,16 +175,19 @@ public class Keyboard implements SharedPreferences.OnSharedPreferenceChangeListe
editor.erase();
break;
case paste:
pasteButtonPressed();
final String text = clipboard.get().getText();
if (!TextUtils.isEmpty(text)) {
editor.insert(text);
}
break;
case copy:
copyButtonPressed();
bus.get().post(new Display.CopyOperation());
break;
case equals:
equalsButtonPressed();
break;
case clear:
clearButtonPressed();
editor.clear();
break;
case functions:
launcher.showFunctions();
@ -209,29 +229,6 @@ public class Keyboard implements SharedPreferences.OnSharedPreferenceChangeListe
editor.setText("(" + oldText.subSequence(0, cursorPosition) + ")" + oldText.subSequence(cursorPosition, oldText.length()), cursorPosition + 2);
}
public void pasteButtonPressed() {
final String text = clipboard.get().getText();
if (!TextUtils.isEmpty(text)) {
editor.insert(text);
}
}
public void clearButtonPressed() {
editor.clear();
}
public void copyButtonPressed() {
bus.get().post(new Display.CopyOperation());
}
public void moveCursorLeft() {
editor.moveCursorLeft();
}
public void moveCursorRight() {
editor.moveCursorRight();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (Preferences.Gui.vibrateOnKeypress.isSameKey(key)) {

View File

@ -33,7 +33,9 @@ public enum CppSpecialButton {
history("history"),
cursor_right(""),
cursor_to_end(">>"),
cursor_left(""),
cursor_to_start("<<"),
settings("settings"),
settings_widget("settings_widget"),
like("like"),

View File

@ -65,7 +65,10 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
listener = new DirectionDragListener(application) {
@Override
protected boolean onDrag(@NonNull View view, @NonNull DragEvent event, @NonNull DragDirection direction) {
return Drag.hasDirectionText(view, direction) && BaseKeyboardUi.this.onDrag(view, direction);
if (!Drag.hasDirectionText(view, direction)) {
return false;
}
return BaseKeyboardUi.this.onDrag(view, direction, ((DirectionDragView) view).getText(direction).getValue());
}
};
textScale = getTextScale(application);
@ -82,7 +85,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
}
}
protected abstract boolean onDrag(@NonNull View view, @NonNull DragDirection direction);
protected abstract boolean onDrag(@NonNull View view, @NonNull DragDirection direction, @Nonnull String value);
public void onCreateView(@Nonnull Activity activity, @Nonnull View view) {
cast(activity.getApplication()).getComponent().inject(this);

View File

@ -246,7 +246,7 @@ public class KeyboardUi extends BaseKeyboardUi {
}
@Override
protected boolean onDrag(@NonNull View view, @NonNull DragDirection direction) {
protected boolean onDrag(@NonNull View view, @NonNull DragDirection direction, @Nonnull String value) {
switch (view.getId()) {
case R.id.cpp_button_functions:
if (direction == up) {

View File

@ -75,13 +75,11 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
}
@Override
protected boolean onDrag(@NonNull View view, @NonNull DragDirection direction) {
protected boolean onDrag(@NonNull View view, @NonNull DragDirection direction, @Nonnull String value) {
switch (view.getId()) {
case R.id.cpp_button_right:
editor.setCursorOnEnd();
return true;
case R.id.cpp_button_left:
editor.setCursorOnStart();
keyboard.buttonPressed(value);
return true;
case R.id.cpp_button_clear:
if(direction == up) {

View File

@ -29,4 +29,5 @@
xmlns:tools="http://schemas.android.com/tools"
a:src="@drawable/ic_keyboard_arrow_left_white_48dp"
c:directionTextUp="&lt;&lt;"
c:directionTextDown="@string/cpp_glyph_copy"
tools:ignore="HardcodedText" />

View File

@ -29,4 +29,5 @@
xmlns:tools="http://schemas.android.com/tools"
a:src="@drawable/ic_keyboard_arrow_right_white_48dp"
c:directionTextUp="&gt;&gt;"
c:directionTextDown="@string/cpp_glyph_paste"
tools:ignore="HardcodedText" />

View File

@ -17,6 +17,8 @@
<string name="cpp_show_greek_keyboard" translatable="false">αβγ</string>
<string name="cpp_exponent" translatable="false">E</string>
<string name="cpp_theme_black" translatable="false">%1$s (AMOLED)</string>
<string name="cpp_glyph_paste">"\ue000"</string>
<string name="cpp_glyph_copy">"\ue001"</string>
<string-array name="cpp_prefs_precisions" translatable="false">
<item>0</item>
<item>1</item>