Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>gogisha,</p> <p>I had a similar idea. The activity would be a list of text strings to inject into the document the ime was working on. Here's how I did it.</p> <p>In the manifest, I added an activity:</p> <pre><code> &lt;activity android:name="org.this_voice.prakeyboard.KeyboardMacros" android:configChanges="keyboardHidden|orientation|screenSize" android:excludeFromRecents="true" android:label="@string/keyboardmacros" android:screenOrientation="portrait" &gt; &lt;/activity&gt; </code></pre> <p>Then in the ime, I pick up the escape-char code to start the activity:</p> <pre><code> } else if (primaryCode == 27) { Intent i = new Intent(this, KeyboardMacros.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.putExtra("MODE","okay"); startActivity(i); </code></pre> <p>But there was a problem with the ime starting the activity in onCreate. Maybe an Android bug/feature. So I put this in the activity's onCreate:</p> <pre><code> Intent origin = this.getIntent(); String okay = origin.getStringExtra("MODE"); if ((okay == null) || (!okay.matches("okay"))){ finish(); } </code></pre> <p>So, activity only starts when I hit the soft key that sends 27 (Esc). Activity starts, list appears, user chooses an item of text, and the activity loads that into the clipboard:</p> <pre><code> String macro = dbs.get(result); ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(macro); finish(); </code></pre> <p>And so we fall back into the editor with our ime. So in ime.startInput we have:</p> <pre><code> ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard.hasText()){ getCurrentInputConnection().commitText(clipboard.getText(), 1); clipboard.setText(""); </code></pre> <p>Clearing the clipboard is important. I'm using setText so that we are compatible from Android 8+. It changed with 11 to fancier stuff. Oh, and in the ime onCreate, we clear the clipboard as well:</p> <pre><code> ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(""); </code></pre> <p>Hope this helps. Actually, I hope you figured this out already since you asked your question a year ago.... Best fishes.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload