mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 05:52:47 +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:
|
||||
|
|
12
app/src/main/res/drawable/sym_keyboard_copy.xml
Normal file
12
app/src/main/res/drawable/sym_keyboard_copy.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!--
|
||||
icon available in Android Studio
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24" >
|
||||
<path android:fillColor="#FFF"
|
||||
android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z"/>
|
||||
</vector>
|
|
@ -46,6 +46,9 @@
|
|||
<include
|
||||
android:id="@+id/suggestions_strip_select_all_key"
|
||||
layout="@layout/suggestions_strip_select_all_key" />
|
||||
<include
|
||||
android:id="@+id/suggestions_strip_copy_key"
|
||||
layout="@layout/suggestions_strip_copy_key" />
|
||||
<include
|
||||
android:id="@+id/suggestions_strip_one_handed_key"
|
||||
layout="@layout/suggestions_strip_one_handed_key" />
|
||||
|
|
10
app/src/main/res/layout/suggestions_strip_copy_key.xml
Normal file
10
app/src/main/res/layout/suggestions_strip_copy_key.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
-->
|
||||
<ImageButton
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="@dimen/config_suggestions_strip_edge_key_width"
|
||||
android:layout_height="fill_parent"
|
||||
android:tag="copy_key"
|
||||
style="?attr/suggestionWordStyle" />
|
|
@ -266,6 +266,7 @@
|
|||
<attr name="iconEmojiNormalKey" format="reference" />
|
||||
<attr name="iconClipboardActionKey" format="reference" />
|
||||
<attr name="iconClipboardNormalKey" format="reference" />
|
||||
<attr name="iconCopyKey" format="reference" />
|
||||
<attr name="iconClearClipboardKey" format="reference" />
|
||||
<attr name="iconStartOneHandedMode" format="reference" />
|
||||
<attr name="iconStopOneHandedMode" format="reference" />
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
<item name="iconEmojiNormalKey">@drawable/sym_keyboard_smiley_holo</item>
|
||||
<item name="iconClipboardActionKey">@drawable/sym_keyboard_clipboard_holo</item>
|
||||
<item name="iconClipboardNormalKey">@drawable/sym_keyboard_clipboard_holo</item>
|
||||
<item name="iconCopyKey">@drawable/sym_keyboard_copy</item>
|
||||
<item name="iconClearClipboardKey">@drawable/sym_keyboard_clear_clipboard_holo</item>
|
||||
<item name="iconStartOneHandedMode">@drawable/sym_keyboard_start_onehanded_holo</item>
|
||||
<item name="iconStopOneHandedMode">@drawable/sym_keyboard_stop_onehanded_holo</item>
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
<item name="iconEmojiNormalKey">@drawable/sym_keyboard_smiley_lxx</item>
|
||||
<item name="iconClipboardActionKey">@drawable/sym_keyboard_clipboard_lxx</item>
|
||||
<item name="iconClipboardNormalKey">@drawable/sym_keyboard_clipboard_lxx</item>
|
||||
<item name="iconCopyKey">@drawable/sym_keyboard_copy</item>
|
||||
<item name="iconClearClipboardKey">@drawable/sym_keyboard_clear_clipboard_lxx</item>
|
||||
<item name="iconStartOneHandedMode">@drawable/sym_keyboard_start_onehanded_lxx</item>
|
||||
<item name="iconStopOneHandedMode">@drawable/sym_keyboard_stop_onehanded_lxx</item>
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
<item name="iconEmojiNormalKey">@drawable/sym_keyboard_smiley_rounded</item>
|
||||
<item name="iconClipboardActionKey">@drawable/sym_keyboard_clipboard_rounded</item>
|
||||
<item name="iconClipboardNormalKey">@drawable/sym_keyboard_clipboard_rounded</item>
|
||||
<item name="iconCopyKey">@drawable/sym_keyboard_copy</item>
|
||||
<item name="iconClearClipboardKey">@drawable/sym_keyboard_clear_clipboard_rounded</item>
|
||||
<item name="iconStartOneHandedMode">@drawable/sym_keyboard_start_onehanded_rounded</item>
|
||||
<item name="iconStopOneHandedMode">@drawable/sym_keyboard_stop_onehanded_rounded</item>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue