Files
Jules Aguillon 77c4a27c4c Spell checking (#1137)
This adds dictionary-based spell checking to the keyboard. The keyboard looks at the word being typed and matches it against a dictionary to either complete the rest of the word or find alternative spellings.

The core of this feature is implemented in cdict, which is included as a
submodule in vendor/cidct.

Cdict is developped at https://github.com/Julow/cdict
The dictionaries are hosted at https://github.com/Julow/Unexpected-Keyboard-dictionaries/
The wordlists used to build the dictionaries are the same ones used by
HeliBoard from https://codeberg.org/Helium314/aosp-dictionaries

- Add an activity accessible from the launcher app that lists available
  dictionaries with a download button.
  The DictionaryListView view shows the list of available dictionaries and
  handles downloading and installing them.

- The Dictionaries class manages installed dictionaries. Dictionaries are
  installed as individual files into the app's private directory.

- Available dictionaries are listed in dictionaries.xml, which is generated
  when building Unexpected-Keyboard-dictionaries.
  method.xml mentions the dictionary name for each locales.
2026-02-02 00:20:00 +01:00

65 lines
2.0 KiB
Java

package juloo.keyboard2;
import android.app.AlertDialog;
import android.content.res.Resources;
import android.graphics.Insets;
import android.os.Build.VERSION;
import android.os.IBinder;
import android.view.View;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowManager;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Locale;
public final class Utils
{
/** Turn the first letter of a string uppercase. */
public static String capitalize_string(String s)
{
if (s.length() < 1)
return s;
// Make sure not to cut a code point in half
int i = s.offsetByCodePoints(0, 1);
return s.substring(0, i).toUpperCase(Locale.getDefault()) + s.substring(i);
}
/** Like [dialog.show()] but properly configure layout params when called
from an IME. [token] is the input view's [getWindowToken()]. */
public static void show_dialog_on_ime(AlertDialog dialog, IBinder token)
{
Window win = dialog.getWindow();
WindowManager.LayoutParams lp = win.getAttributes();
lp.token = token;
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
win.setAttributes(lp);
win.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
dialog.show();
}
public static String read_all_utf8(InputStream inp) throws Exception
{
InputStreamReader reader = new InputStreamReader(inp, "UTF-8");
StringBuilder out = new StringBuilder();
int buff_length = 8000;
char[] buff = new char[buff_length];
int l;
while ((l = reader.read(buff, 0, buff_length)) != -1)
out.append(buff, 0, l);
return out.toString();
}
public static byte[] read_all_bytes(InputStream inp) throws IOException
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buff = new byte[128000];
int l;
while ((l = inp.read(buff)) != -1)
out.write(buff, 0, l);
return out.toByteArray();
}
}