forked from extern/Unexpected-Keyboard
clipboard: Pasting
The paste button send the content of the pinned clip to the editor the same way as a string key.
This commit is contained in:
parent
59d2d05c50
commit
700b7e9d19
@ -2,6 +2,7 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content">
|
||||
<TextView android:id="@+id/clipboard_pin_text" style="@style/clipboardEntry" android:maxLines="3"/>
|
||||
<LinearLayout style="@style/clipboardEntryButtons">
|
||||
<View android:id="@+id/clipboard_pin_paste" style="@style/clipboardEntryButton" android:background="@drawable/ic_clipboard_paste"/>
|
||||
<View android:id="@+id/clipboard_pin_remove" style="@style/clipboardEntryButton" android:background="@drawable/ic_clipboard_unsafe"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
@ -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<HistoryEntry> _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);
|
||||
}
|
||||
}
|
||||
|
@ -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<String> 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()
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -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<InputMethodSubtype> getEnabledSubtypes(InputMethodManager imm)
|
||||
|
Loading…
Reference in New Issue
Block a user