diff --git a/res/layout/clipboard_pin_entry.xml b/res/layout/clipboard_pin_entry.xml index d09a89c..8662c44 100644 --- a/res/layout/clipboard_pin_entry.xml +++ b/res/layout/clipboard_pin_entry.xml @@ -2,6 +2,7 @@ + diff --git a/srcs/juloo.keyboard2/ClipboardHistoryService.java b/srcs/juloo.keyboard2/ClipboardHistoryService.java index 0231d8d..e3f01ba 100644 --- a/srcs/juloo.keyboard2/ClipboardHistoryService.java +++ b/srcs/juloo.keyboard2/ClipboardHistoryService.java @@ -11,9 +11,10 @@ import java.util.List; public final class ClipboardHistoryService { /** Start the service on startup and start listening to clipboard changes. */ - public static void on_startup(Context ctx) + public static void on_startup(Context ctx, ClipboardPasteCallback cb) { get_service(ctx); + _paste_callback = cb; } /** Start the service if it hasn't been started before. Returns [null] if the @@ -40,6 +41,13 @@ public final class ClipboardHistoryService _service.clear_history(); } + /** Send the given string to the editor. */ + public static void paste(String clip) + { + if (_paste_callback != null) + _paste_callback.paste_from_clipboard_pane(clip); + } + /** The maximum size limits the amount of user data stored in memory but also gives a sense to the user that the history is not persisted and can be forgotten as soon as the app stops. */ @@ -48,6 +56,7 @@ public final class ClipboardHistoryService public static final long HISTORY_TTL_MS = 5 * 60 * 1000; static ClipboardHistoryService _service = null; + static ClipboardPasteCallback _paste_callback = null; ClipboardManager _cm; List _history; @@ -163,4 +172,9 @@ public final class ClipboardHistoryService expiry_timestamp = System.currentTimeMillis() + HISTORY_TTL_MS; } } + + public interface ClipboardPasteCallback + { + public void paste_from_clipboard_pane(String content); + } } diff --git a/srcs/juloo.keyboard2/ClipboardPinView.java b/srcs/juloo.keyboard2/ClipboardPinView.java index fd4a4a3..16d57dc 100644 --- a/srcs/juloo.keyboard2/ClipboardPinView.java +++ b/srcs/juloo.keyboard2/ClipboardPinView.java @@ -55,6 +55,12 @@ public final class ClipboardPinView extends NonScrollListView invalidate(); } + /** Send the specified entry to the editor. */ + public void paste_entry(int pos) + { + ClipboardHistoryService.paste(_entries.get(pos)); + } + void persist() { save_to_prefs(_persist_store, _entries); } static void load_from_prefs(SharedPreferences store, List dst) @@ -99,6 +105,12 @@ public final class ClipboardPinView extends NonScrollListView v = View.inflate(getContext(), R.layout.clipboard_pin_entry, null); ((TextView)v.findViewById(R.id.clipboard_pin_text)) .setText(_entries.get(pos)); + v.findViewById(R.id.clipboard_pin_paste).setOnClickListener( + new View.OnClickListener() + { + @Override + public void onClick(View v) { paste_entry(pos); } + }); v.findViewById(R.id.clipboard_pin_remove).setOnClickListener( new View.OnClickListener() { diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java index b6225f1..087ac5b 100644 --- a/srcs/juloo.keyboard2/KeyEventHandler.java +++ b/srcs/juloo.keyboard2/KeyEventHandler.java @@ -10,7 +10,9 @@ import android.view.inputmethod.ExtractedTextRequest; import android.view.inputmethod.InputConnection; import java.util.Iterator; -public final class KeyEventHandler implements Config.IKeyEventHandler +public final class KeyEventHandler + implements Config.IKeyEventHandler, + ClipboardHistoryService.ClipboardPasteCallback { IReceiver _recv; Autocapitalisation _autocap; @@ -105,6 +107,12 @@ public final class KeyEventHandler implements Config.IKeyEventHandler update_meta_state(mods); } + @Override + public void paste_from_clipboard_pane(String content) + { + send_text(content); + } + /** Update [_mods] to be consistent with the [mods], sending key events if needed. */ void update_meta_state(Pointers.Modifiers mods) diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index e51b076..0c82aaf 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -114,7 +114,7 @@ public class Keyboard2 extends InputMethodService _keyboardView = (Keyboard2View)inflate_view(R.layout.keyboard); _keyboardView.reset(); Logs.set_debug_logs(getResources().getBoolean(R.bool.debug_logs)); - ClipboardHistoryService.on_startup(this); + ClipboardHistoryService.on_startup(this, _keyeventhandler); } private List getEnabledSubtypes(InputMethodManager imm)