mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-16 15:02:48 +00:00
add copy key, fixes #253
This commit is contained in:
parent
5d173d0981
commit
245ee27053
11 changed files with 64 additions and 5 deletions
|
@ -6,6 +6,9 @@
|
|||
|
||||
package org.dslul.openboard.inputmethod.latin;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
|
@ -635,6 +638,21 @@ public final class RichInputConnection implements PrivateCommandPerformer {
|
|||
// the rest is done via LatinIME.onUpdateSelection
|
||||
}
|
||||
|
||||
public void copyText() {
|
||||
// copy selected text, and if nothing is selected copy the whole text
|
||||
CharSequence text = getSelectedText(InputConnection.GET_TEXT_WITH_STYLES);
|
||||
if (text == null || text.length() == 0) {
|
||||
// we have no selection, get the whole text
|
||||
ExtractedTextRequest etr = new ExtractedTextRequest();
|
||||
etr.flags = InputConnection.GET_TEXT_WITH_STYLES;
|
||||
etr.hintMaxChars = Integer.MAX_VALUE;
|
||||
text = mIC.getExtractedText(etr, 0).text;
|
||||
}
|
||||
if (text == null) return;
|
||||
final ClipboardManager cm = (ClipboardManager) mParent.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cm.setPrimaryClip(ClipData.newPlainText("copied text", text));
|
||||
}
|
||||
|
||||
public void commitCorrection(final CorrectionInfo correctionInfo) {
|
||||
if (DEBUG_BATCH_NESTING) checkBatchEdit();
|
||||
if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
|
||||
|
|
|
@ -233,12 +233,13 @@ public final class Constants {
|
|||
public static final int CODE_ALPHA_FROM_NUMPAD = -21;
|
||||
public static final int CODE_SYMBOL_FROM_NUMPAD = -22;
|
||||
public static final int CODE_SELECT_ALL = -23;
|
||||
public static final int CODE_LEFT = -24;
|
||||
public static final int CODE_RIGHT = -25;
|
||||
public static final int CODE_UP = -26;
|
||||
public static final int CODE_DOWN = -27;
|
||||
public static final int CODE_COPY = -24;
|
||||
public static final int CODE_LEFT = -25;
|
||||
public static final int CODE_RIGHT = -26;
|
||||
public static final int CODE_UP = -27;
|
||||
public static final int CODE_DOWN = -28;
|
||||
// Code value representing the code is not specified.
|
||||
public static final int CODE_UNSPECIFIED = -28;
|
||||
public static final int CODE_UNSPECIFIED = -29;
|
||||
|
||||
public static boolean isLetterCode(final int code) {
|
||||
return code >= CODE_SPACE;
|
||||
|
|
|
@ -763,6 +763,9 @@ public final class InputLogic {
|
|||
case Constants.CODE_SELECT_ALL:
|
||||
mConnection.selectAll();
|
||||
break;
|
||||
case Constants.CODE_COPY:
|
||||
mConnection.copyText();
|
||||
break;
|
||||
case Constants.CODE_LEFT:
|
||||
sendDownUpKeyEvent(KeyEvent.KEYCODE_DPAD_LEFT);
|
||||
break;
|
||||
|
|
|
@ -78,6 +78,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
private static final String CLIPBOARD_KEY_TAG = "clipboard_key";
|
||||
private static final String SETTINGS_KEY_TAG = "settings_key";
|
||||
private static final String SELECT_ALL_KEY_TAG = "select_all_key";
|
||||
private static final String COPY_KEY_TAG = "copy_key";
|
||||
private static final String ONE_HANDED_KEY_TAG = "one_handed_key";
|
||||
private static final String LEFT_KEY_TAG = "left_key";
|
||||
private static final String RIGHT_KEY_TAG = "right_key";
|
||||
|
@ -160,6 +161,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
final ImageButton voiceKey = findViewById(R.id.suggestions_strip_voice_key);
|
||||
final ImageButton clipboardKey = findViewById(R.id.suggestions_strip_clipboard_key);
|
||||
final ImageButton selectAllKey = findViewById(R.id.suggestions_strip_select_all_key);
|
||||
final ImageButton copyKey = findViewById(R.id.suggestions_strip_copy_key);
|
||||
final ImageButton settingsKey = findViewById(R.id.suggestions_strip_settings_key);
|
||||
final ImageButton oneHandedKey = findViewById(R.id.suggestions_strip_one_handed_key);
|
||||
final ImageButton arrowLeft = findViewById(R.id.suggestions_strip_left_key);
|
||||
|
@ -201,6 +203,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
clipboardKey.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconClipboardNormalKey));
|
||||
settingsKey.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconSettingsKey));
|
||||
selectAllKey.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconSelectAll));
|
||||
copyKey.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconCopyKey));
|
||||
arrowLeft.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconArrowLeft));
|
||||
arrowRight.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconArrowRight));
|
||||
arrowUp.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconArrowUp));
|
||||
|
@ -627,6 +630,9 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
case SELECT_ALL_KEY_TAG:
|
||||
mListener.onCodeInput(Constants.CODE_SELECT_ALL, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
|
||||
return;
|
||||
case COPY_KEY_TAG:
|
||||
mListener.onCodeInput(Constants.CODE_COPY, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
|
||||
return;
|
||||
case ONE_HANDED_KEY_TAG:
|
||||
final boolean oneHandedEnabled = Settings.getInstance().getCurrent().mOneHandedModeEnabled;
|
||||
mListener.onCodeInput(oneHandedEnabled ? Constants.CODE_STOP_ONE_HANDED_MODE : Constants.CODE_START_ONE_HANDED_MODE,
|
||||
|
@ -719,6 +725,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
return R.layout.suggestions_strip_clipboard_key;
|
||||
case SELECT_ALL_KEY_TAG:
|
||||
return R.layout.suggestions_strip_select_all_key;
|
||||
case COPY_KEY_TAG:
|
||||
return R.layout.suggestions_strip_copy_key;
|
||||
case ONE_HANDED_KEY_TAG:
|
||||
return R.layout.suggestions_strip_one_handed_key;
|
||||
case LEFT_KEY_TAG:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue