mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-19 08:20:15 +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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue