mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-19 16:30:19 +00:00
Add copy functionality
Current functionality is short-press to copy, long-press to paste.
This commit is contained in:
parent
de924ce3a5
commit
31b4a28471
5 changed files with 31 additions and 12 deletions
|
@ -1117,6 +1117,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
}
|
||||
}
|
||||
|
||||
public CharSequence getSelection() {
|
||||
return mInputLogic.mConnection.getSelectedText(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the user has clicked on the extracted text view,
|
||||
* when running in fullscreen mode. The default implementation hides
|
||||
|
|
|
@ -62,6 +62,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
void pickSuggestionManually(SuggestedWordInfo word);
|
||||
void onCodeInput(int primaryCode, int x, int y, boolean isKeyRepeat);
|
||||
void onTextInput(final String rawText);
|
||||
CharSequence getSelection();
|
||||
}
|
||||
|
||||
static final boolean DBG = DebugFlags.DEBUG_ENABLED;
|
||||
|
@ -172,6 +173,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
mVoiceKey.setOnClickListener(this);
|
||||
mPasteKey.setImageDrawable(iconPaste);
|
||||
mPasteKey.setOnClickListener(this);
|
||||
mPasteKey.setOnLongClickListener(this);
|
||||
|
||||
mOtherKey.setImageDrawable(iconIncognito);
|
||||
}
|
||||
|
@ -265,6 +267,23 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
|
||||
@Override
|
||||
public boolean onLongClick(final View view) {
|
||||
if (view == mPasteKey) {
|
||||
ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clipData = clipboardManager.getPrimaryClip();
|
||||
if (clipData != null && clipData.getItemCount() > 0 && clipData.getItemAt(0) != null) {
|
||||
String clipString = clipData.getItemAt(0).coerceToText(getContext()).toString();
|
||||
if (clipString.length() == 1) {
|
||||
mListener.onTextInput(clipString);
|
||||
} else if (clipString.length() > 1) {
|
||||
//awkward workaround
|
||||
mListener.onTextInput(clipString.substring(0, clipString.length() - 1));
|
||||
mListener.onTextInput(clipString.substring(clipString.length() - 1));
|
||||
}
|
||||
}
|
||||
AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback(
|
||||
Constants.NOT_A_CODE, this);
|
||||
return true;
|
||||
}
|
||||
AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback(
|
||||
Constants.NOT_A_CODE, this);
|
||||
return showMoreSuggestions();
|
||||
|
@ -423,17 +442,10 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
return;
|
||||
}
|
||||
if (view == mPasteKey) {
|
||||
ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clipData = clipboardManager.getPrimaryClip();
|
||||
if (clipData != null && clipData.getItemCount() > 0 && clipData.getItemAt(0) != null) {
|
||||
String clipString = clipData.getItemAt(0).coerceToText(getContext()).toString();
|
||||
if (clipString.length() == 1) {
|
||||
mListener.onTextInput(clipString);
|
||||
} else if (clipString.length() > 1) {
|
||||
//awkward workaround
|
||||
mListener.onTextInput(clipString.substring(0, clipString.length() - 1));
|
||||
mListener.onTextInput(clipString.substring(clipString.length() - 1));
|
||||
}
|
||||
CharSequence selectionSequence = mListener.getSelection();
|
||||
if (selectionSequence != null && selectionSequence.length() > 0) {
|
||||
ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipboardManager.setPrimaryClip(ClipData.newPlainText(selectionSequence, selectionSequence));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,8 @@
|
|||
<LinearLayout
|
||||
android:id="@+id/suggestions_strip"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:maxWidth="100dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:hapticFeedbackEnabled="false"
|
||||
|
|
|
@ -181,6 +181,7 @@
|
|||
|
||||
<!-- Preferences item for enabling pasting from keyboard -->
|
||||
<string name="show_paste_key">Clipboard paste key</string>
|
||||
<string name="show_paste_key_summary">Press to copy, long-press to paste.</string>
|
||||
|
||||
<!-- Title for configuring input method settings [CHAR LIMIT=35] -->
|
||||
<string name="configure_input_method">Configure input methods</string>
|
||||
|
|
|
@ -74,6 +74,7 @@
|
|||
<CheckBoxPreference
|
||||
android:key="pref_show_paste_key"
|
||||
android:title="@string/show_paste_key"
|
||||
android:summary="@string/show_paste_key_summary"
|
||||
android:defaultValue="false"
|
||||
android:persistent="true" />
|
||||
</PreferenceScreen>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue