2023-12-30 00:56:55 +01:00
|
|
|
package juloo.keyboard2;
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.os.IBinder;
|
|
|
|
import android.view.Window;
|
|
|
|
import android.view.WindowManager;
|
2024-01-01 21:04:54 +01:00
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStreamReader;
|
2023-12-30 00:56:55 +01:00
|
|
|
|
2024-01-13 20:59:05 +01:00
|
|
|
public final class Utils
|
2023-12-30 00:56:55 +01:00
|
|
|
{
|
|
|
|
/** Turn the first letter of a string uppercase. */
|
|
|
|
public static String capitalize_string(String s)
|
|
|
|
{
|
2024-01-10 00:17:09 +01:00
|
|
|
if (s.length() < 1)
|
|
|
|
return s;
|
2023-12-30 00:56:55 +01:00
|
|
|
// Make sure not to cut a code point in half
|
|
|
|
int i = s.offsetByCodePoints(0, 1);
|
|
|
|
return s.substring(0, i).toUpperCase() + 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();
|
|
|
|
}
|
2024-01-01 21:04:54 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2023-12-30 00:56:55 +01:00
|
|
|
}
|