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

View File

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

View File

@ -65,7 +65,10 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
listener = new DirectionDragListener(application) { listener = new DirectionDragListener(application) {
@Override @Override
protected boolean onDrag(@NonNull View view, @NonNull DragEvent event, @NonNull DragDirection direction) { 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); 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) { public void onCreateView(@Nonnull Activity activity, @Nonnull View view) {
cast(activity.getApplication()).getComponent().inject(this); cast(activity.getApplication()).getComponent().inject(this);

View File

@ -246,7 +246,7 @@ public class KeyboardUi extends BaseKeyboardUi {
} }
@Override @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()) { switch (view.getId()) {
case R.id.cpp_button_functions: case R.id.cpp_button_functions:
if (direction == up) { if (direction == up) {

View File

@ -75,13 +75,11 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
} }
@Override @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()) { switch (view.getId()) {
case R.id.cpp_button_right: case R.id.cpp_button_right:
editor.setCursorOnEnd();
return true;
case R.id.cpp_button_left: case R.id.cpp_button_left:
editor.setCursorOnStart(); keyboard.buttonPressed(value);
return true; return true;
case R.id.cpp_button_clear: case R.id.cpp_button_clear:
if(direction == up) { if(direction == up) {

View File

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

View File

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

View File

@ -17,6 +17,8 @@
<string name="cpp_show_greek_keyboard" translatable="false">αβγ</string> <string name="cpp_show_greek_keyboard" translatable="false">αβγ</string>
<string name="cpp_exponent" translatable="false">E</string> <string name="cpp_exponent" translatable="false">E</string>
<string name="cpp_theme_black" translatable="false">%1$s (AMOLED)</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"> <string-array name="cpp_prefs_precisions" translatable="false">
<item>0</item> <item>0</item>
<item>1</item> <item>1</item>