2015-07-30 20:14:55 +02:00
|
|
|
package juloo.keyboard2;
|
|
|
|
|
2024-02-10 17:33:42 +01:00
|
|
|
import android.annotation.TargetApi;
|
2021-04-15 23:56:34 +02:00
|
|
|
import android.content.Context;
|
2015-08-08 17:57:25 +02:00
|
|
|
import android.content.Intent;
|
2015-08-08 16:47:22 +02:00
|
|
|
import android.content.SharedPreferences;
|
2015-07-30 20:14:55 +02:00
|
|
|
import android.inputmethodservice.InputMethodService;
|
2021-05-09 00:56:59 +02:00
|
|
|
import android.os.Build.VERSION;
|
2021-04-18 23:31:59 +02:00
|
|
|
import android.os.IBinder;
|
2022-02-07 00:55:32 +01:00
|
|
|
import android.text.InputType;
|
2022-11-11 14:27:02 +01:00
|
|
|
import android.util.Log;
|
|
|
|
import android.util.LogPrinter;
|
2023-05-24 19:23:28 +02:00
|
|
|
import android.view.*;
|
2015-10-11 15:30:39 +02:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2021-12-28 17:47:18 +01:00
|
|
|
import android.view.inputmethod.InputConnection;
|
2021-05-09 00:09:10 +02:00
|
|
|
import android.view.inputmethod.InputMethodInfo;
|
2016-12-11 22:45:58 +01:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2021-04-15 23:56:34 +02:00
|
|
|
import android.view.inputmethod.InputMethodSubtype;
|
2023-06-03 18:35:16 +02:00
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import java.util.AbstractMap.SimpleEntry;
|
2023-08-06 16:49:29 +02:00
|
|
|
import java.util.ArrayList;
|
2022-05-01 00:00:15 +02:00
|
|
|
import java.util.Arrays;
|
2022-03-13 00:14:18 +01:00
|
|
|
import java.util.HashSet;
|
2022-11-11 14:27:02 +01:00
|
|
|
import java.util.List;
|
2022-03-13 00:14:18 +01:00
|
|
|
import java.util.Set;
|
2024-01-13 20:59:05 +01:00
|
|
|
import juloo.keyboard2.prefs.LayoutsPreference;
|
2015-07-30 20:14:55 +02:00
|
|
|
|
|
|
|
public class Keyboard2 extends InputMethodService
|
2022-11-13 16:18:08 +01:00
|
|
|
implements SharedPreferences.OnSharedPreferenceChangeListener
|
2015-07-30 20:14:55 +02:00
|
|
|
{
|
2021-12-19 19:44:27 +01:00
|
|
|
private Keyboard2View _keyboardView;
|
2022-11-13 16:18:08 +01:00
|
|
|
private KeyEventHandler _keyeventhandler;
|
2023-11-19 19:07:54 +01:00
|
|
|
/** If not 'null', the layout to use instead of [_config.current_layout]. */
|
2022-12-11 21:57:40 +01:00
|
|
|
private KeyboardData _currentSpecialLayout;
|
2023-11-19 19:07:54 +01:00
|
|
|
/** Layout associated with the currently selected locale. Not 'null'. */
|
2022-12-11 21:57:40 +01:00
|
|
|
private KeyboardData _localeTextLayout;
|
2021-12-19 19:44:27 +01:00
|
|
|
private ViewGroup _emojiPane = null;
|
2024-01-14 00:50:33 +01:00
|
|
|
private ViewGroup _clipboard_pane = null;
|
2023-06-03 20:06:44 +02:00
|
|
|
public int actionId; // Action performed by the Action key.
|
2015-07-30 20:14:55 +02:00
|
|
|
|
2021-12-19 19:44:27 +01:00
|
|
|
private Config _config;
|
2015-10-29 12:49:40 +01:00
|
|
|
|
2023-09-03 23:38:55 +02:00
|
|
|
/** Layout currently visible before it has been modified. */
|
|
|
|
KeyboardData current_layout_unmodified()
|
2022-12-11 21:57:40 +01:00
|
|
|
{
|
2023-01-15 23:19:09 +01:00
|
|
|
if (_currentSpecialLayout != null)
|
|
|
|
return _currentSpecialLayout;
|
2023-07-29 18:37:06 +02:00
|
|
|
KeyboardData layout = null;
|
2023-11-19 20:10:45 +01:00
|
|
|
int layout_i = _config.get_current_layout();
|
2023-11-19 19:07:54 +01:00
|
|
|
if (layout_i >= _config.layouts.size())
|
|
|
|
layout_i = 0;
|
|
|
|
if (layout_i < _config.layouts.size())
|
|
|
|
layout = _config.layouts.get(layout_i);
|
2023-07-29 18:37:06 +02:00
|
|
|
if (layout == null)
|
2023-01-30 22:33:01 +01:00
|
|
|
layout = _localeTextLayout;
|
2023-09-03 23:38:55 +02:00
|
|
|
return layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Layout currently visible. */
|
|
|
|
KeyboardData current_layout()
|
|
|
|
{
|
2023-12-21 20:59:30 +01:00
|
|
|
if (_currentSpecialLayout != null)
|
|
|
|
return _currentSpecialLayout;
|
2023-09-03 23:38:55 +02:00
|
|
|
return _config.modify_layout(current_layout_unmodified());
|
2023-01-15 23:19:09 +01:00
|
|
|
}
|
|
|
|
|
2023-07-29 18:37:06 +02:00
|
|
|
void setTextLayout(int l)
|
2023-01-15 23:19:09 +01:00
|
|
|
{
|
2023-11-19 19:07:54 +01:00
|
|
|
_config.set_current_layout(l);
|
2023-01-15 23:19:09 +01:00
|
|
|
_currentSpecialLayout = null;
|
|
|
|
_keyboardView.setKeyboard(current_layout());
|
2022-12-11 21:57:40 +01:00
|
|
|
}
|
|
|
|
|
2023-07-29 18:37:06 +02:00
|
|
|
void incrTextLayout(int delta)
|
|
|
|
{
|
|
|
|
int s = _config.layouts.size();
|
2023-11-19 20:10:45 +01:00
|
|
|
setTextLayout((_config.get_current_layout() + delta + s) % s);
|
2023-07-29 18:37:06 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 23:46:02 +01:00
|
|
|
void setSpecialLayout(KeyboardData l)
|
|
|
|
{
|
|
|
|
_currentSpecialLayout = l;
|
|
|
|
_keyboardView.setKeyboard(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyboardData loadLayout(int layout_id)
|
|
|
|
{
|
|
|
|
return KeyboardData.load(getResources(), layout_id);
|
|
|
|
}
|
|
|
|
|
2024-02-14 22:41:35 +01:00
|
|
|
/** Load a layout that contains a numpad. */
|
2023-07-29 17:29:45 +02:00
|
|
|
KeyboardData loadNumpad(int layout_id)
|
|
|
|
{
|
2023-09-03 23:38:55 +02:00
|
|
|
return _config.modify_numpad(KeyboardData.load(getResources(), layout_id),
|
2023-12-26 17:05:51 +01:00
|
|
|
current_layout_unmodified());
|
2023-07-29 17:29:45 +02:00
|
|
|
}
|
|
|
|
|
2024-02-14 22:41:35 +01:00
|
|
|
KeyboardData loadPinentry(int layout_id)
|
|
|
|
{
|
|
|
|
return _config.modify_pinentry(KeyboardData.load(getResources(), layout_id),
|
|
|
|
current_layout_unmodified());
|
|
|
|
}
|
|
|
|
|
2021-12-19 19:44:27 +01:00
|
|
|
@Override
|
|
|
|
public void onCreate()
|
|
|
|
{
|
|
|
|
super.onCreate();
|
2022-11-11 14:27:02 +01:00
|
|
|
SharedPreferences prefs = DirectBootAwarePreferences.get_shared_preferences(this);
|
2022-11-13 16:18:08 +01:00
|
|
|
_keyeventhandler = new KeyEventHandler(getMainLooper(), this.new Receiver());
|
|
|
|
Config.initGlobalConfig(prefs, getResources(), _keyeventhandler);
|
2023-08-15 20:23:33 +02:00
|
|
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
2021-12-28 16:47:19 +01:00
|
|
|
_config = Config.globalConfig();
|
2021-12-30 00:26:05 +01:00
|
|
|
_keyboardView = (Keyboard2View)inflate_view(R.layout.keyboard);
|
2021-12-19 19:44:27 +01:00
|
|
|
_keyboardView.reset();
|
2023-07-19 23:28:33 +02:00
|
|
|
Logs.set_debug_logs(getResources().getBoolean(R.bool.debug_logs));
|
2024-06-16 23:07:58 +02:00
|
|
|
ClipboardHistoryService.on_startup(this, _keyeventhandler);
|
2022-07-24 20:02:48 +02:00
|
|
|
}
|
|
|
|
|
2021-05-09 00:09:10 +02:00
|
|
|
private List<InputMethodSubtype> getEnabledSubtypes(InputMethodManager imm)
|
|
|
|
{
|
|
|
|
String pkg = getPackageName();
|
|
|
|
for (InputMethodInfo imi : imm.getEnabledInputMethodList())
|
|
|
|
if (imi.getPackageName().equals(pkg))
|
|
|
|
return imm.getEnabledInputMethodSubtypeList(imi, true);
|
2022-05-01 00:00:15 +02:00
|
|
|
return Arrays.asList();
|
2021-05-09 00:09:10 +02:00
|
|
|
}
|
|
|
|
|
2024-02-10 17:33:42 +01:00
|
|
|
@TargetApi(12)
|
2023-08-06 16:49:29 +02:00
|
|
|
private ExtraKeys extra_keys_of_subtype(InputMethodSubtype subtype)
|
2021-05-09 00:09:10 +02:00
|
|
|
{
|
2022-01-09 12:47:47 +01:00
|
|
|
String extra_keys = subtype.getExtraValueOf("extra_keys");
|
2023-06-24 23:29:24 +02:00
|
|
|
String script = subtype.getExtraValueOf("script");
|
2023-08-06 01:30:02 +02:00
|
|
|
if (extra_keys != null)
|
2023-08-06 16:49:29 +02:00
|
|
|
return ExtraKeys.parse(script, extra_keys);
|
|
|
|
return ExtraKeys.EMPTY;
|
2021-05-09 00:09:10 +02:00
|
|
|
}
|
|
|
|
|
2024-02-10 17:33:42 +01:00
|
|
|
@TargetApi(12)
|
2021-05-09 00:09:10 +02:00
|
|
|
private void refreshAccentsOption(InputMethodManager imm, InputMethodSubtype subtype)
|
|
|
|
{
|
2022-03-16 13:09:10 +01:00
|
|
|
List<InputMethodSubtype> enabled_subtypes = getEnabledSubtypes(imm);
|
2023-08-06 16:49:29 +02:00
|
|
|
List<ExtraKeys> extra_keys = new ArrayList<ExtraKeys>();
|
2023-08-06 16:58:44 +02:00
|
|
|
// Gather extra keys from all enabled subtypes
|
|
|
|
extra_keys.add(extra_keys_of_subtype(subtype));
|
|
|
|
for (InputMethodSubtype s : enabled_subtypes)
|
|
|
|
extra_keys.add(extra_keys_of_subtype(s));
|
2023-08-06 16:49:29 +02:00
|
|
|
_config.extra_keys_subtype = ExtraKeys.merge(extra_keys);
|
2021-04-28 00:23:52 +02:00
|
|
|
}
|
|
|
|
|
2023-06-03 20:06:44 +02:00
|
|
|
InputMethodManager get_imm()
|
|
|
|
{
|
|
|
|
return (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
|
|
|
|
}
|
|
|
|
|
2021-04-28 00:23:52 +02:00
|
|
|
private void refreshSubtypeImm()
|
|
|
|
{
|
2023-06-03 20:06:44 +02:00
|
|
|
InputMethodManager imm = get_imm();
|
2023-12-30 00:56:55 +01:00
|
|
|
_config.shouldOfferVoiceTyping = true;
|
2023-06-08 21:59:24 +02:00
|
|
|
KeyboardData default_layout = null;
|
2023-06-24 23:29:24 +02:00
|
|
|
_config.extra_keys_subtype = null;
|
|
|
|
if (VERSION.SDK_INT >= 12)
|
2021-05-09 00:56:59 +02:00
|
|
|
{
|
|
|
|
InputMethodSubtype subtype = imm.getCurrentInputMethodSubtype();
|
2023-06-24 23:29:24 +02:00
|
|
|
if (subtype != null)
|
2022-09-24 23:34:50 +02:00
|
|
|
{
|
2023-06-08 21:59:24 +02:00
|
|
|
String s = subtype.getExtraValueOf("default_layout");
|
|
|
|
if (s != null)
|
2023-08-10 12:57:31 +02:00
|
|
|
default_layout = LayoutsPreference.layout_of_string(getResources(), s);
|
2022-09-24 23:34:50 +02:00
|
|
|
refreshAccentsOption(imm, subtype);
|
|
|
|
}
|
2021-05-09 00:56:59 +02:00
|
|
|
}
|
2023-06-08 21:59:24 +02:00
|
|
|
if (default_layout == null)
|
2023-07-29 17:29:45 +02:00
|
|
|
default_layout = loadLayout(R.xml.latn_qwerty_us);
|
2023-06-08 21:59:24 +02:00
|
|
|
_localeTextLayout = default_layout;
|
2021-04-15 23:56:34 +02:00
|
|
|
}
|
|
|
|
|
2022-01-09 20:26:06 +01:00
|
|
|
private String actionLabel_of_imeAction(int action)
|
|
|
|
{
|
2022-01-23 19:19:38 +01:00
|
|
|
int res;
|
2022-01-09 20:26:06 +01:00
|
|
|
switch (action)
|
|
|
|
{
|
2022-01-23 19:19:38 +01:00
|
|
|
case EditorInfo.IME_ACTION_NEXT: res = R.string.key_action_next; break;
|
|
|
|
case EditorInfo.IME_ACTION_DONE: res = R.string.key_action_done; break;
|
|
|
|
case EditorInfo.IME_ACTION_GO: res = R.string.key_action_go; break;
|
|
|
|
case EditorInfo.IME_ACTION_PREVIOUS: res = R.string.key_action_prev; break;
|
|
|
|
case EditorInfo.IME_ACTION_SEARCH: res = R.string.key_action_search; break;
|
|
|
|
case EditorInfo.IME_ACTION_SEND: res = R.string.key_action_send; break;
|
2022-01-30 12:17:31 +01:00
|
|
|
case EditorInfo.IME_ACTION_UNSPECIFIED:
|
2022-01-09 20:26:06 +01:00
|
|
|
case EditorInfo.IME_ACTION_NONE:
|
|
|
|
default: return null;
|
|
|
|
}
|
2022-01-23 19:19:38 +01:00
|
|
|
return getResources().getString(res);
|
2022-01-09 20:26:06 +01:00
|
|
|
}
|
|
|
|
|
2022-07-24 20:02:48 +02:00
|
|
|
private void refresh_action_label(EditorInfo info)
|
2022-01-09 20:26:06 +01:00
|
|
|
{
|
|
|
|
// First try to look at 'info.actionLabel', if it isn't set, look at
|
|
|
|
// 'imeOptions'.
|
|
|
|
if (info.actionLabel != null)
|
|
|
|
{
|
|
|
|
_config.actionLabel = info.actionLabel.toString();
|
2023-06-03 20:06:44 +02:00
|
|
|
actionId = info.actionId;
|
2022-01-10 00:27:22 +01:00
|
|
|
_config.swapEnterActionKey = false;
|
2022-01-09 20:26:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int action = info.imeOptions & EditorInfo.IME_MASK_ACTION;
|
|
|
|
_config.actionLabel = actionLabel_of_imeAction(action); // Might be null
|
2023-06-03 20:06:44 +02:00
|
|
|
actionId = action;
|
2022-01-10 00:27:22 +01:00
|
|
|
_config.swapEnterActionKey =
|
2022-01-30 12:17:31 +01:00
|
|
|
(info.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0;
|
2022-01-09 20:26:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-14 14:49:35 +01:00
|
|
|
/** Might re-create the keyboard view. [_keyboardView.setKeyboard()] and
|
|
|
|
[setInputView()] must be called soon after. */
|
2022-12-11 21:57:40 +01:00
|
|
|
private void refresh_config()
|
2022-01-30 23:29:50 +01:00
|
|
|
{
|
|
|
|
int prev_theme = _config.theme;
|
2022-11-11 14:27:02 +01:00
|
|
|
_config.refresh(getResources());
|
2022-01-30 23:29:50 +01:00
|
|
|
refreshSubtypeImm();
|
|
|
|
// Refreshing the theme config requires re-creating the views
|
|
|
|
if (prev_theme != _config.theme)
|
|
|
|
{
|
|
|
|
_keyboardView = (Keyboard2View)inflate_view(R.layout.keyboard);
|
|
|
|
_emojiPane = null;
|
2024-01-14 00:50:33 +01:00
|
|
|
_clipboard_pane = null;
|
2024-06-16 22:08:07 +02:00
|
|
|
setInputView(_keyboardView);
|
2022-01-30 23:29:50 +01:00
|
|
|
}
|
2022-12-11 21:57:40 +01:00
|
|
|
_keyboardView.reset();
|
2022-01-30 23:29:50 +01:00
|
|
|
}
|
|
|
|
|
2023-07-29 17:29:45 +02:00
|
|
|
private KeyboardData refresh_special_layout(EditorInfo info)
|
2022-10-24 00:17:55 +02:00
|
|
|
{
|
|
|
|
switch (info.inputType & InputType.TYPE_MASK_CLASS)
|
|
|
|
{
|
|
|
|
case InputType.TYPE_CLASS_NUMBER:
|
|
|
|
case InputType.TYPE_CLASS_PHONE:
|
|
|
|
case InputType.TYPE_CLASS_DATETIME:
|
2023-07-29 17:29:45 +02:00
|
|
|
if (_config.pin_entry_enabled)
|
2024-02-14 22:41:35 +01:00
|
|
|
return loadPinentry(R.xml.pin);
|
2023-07-29 17:29:45 +02:00
|
|
|
else
|
|
|
|
return loadNumpad(R.xml.numeric);
|
2022-10-24 00:17:55 +02:00
|
|
|
default:
|
2022-12-14 15:33:44 +01:00
|
|
|
break;
|
2022-10-24 00:17:55 +02:00
|
|
|
}
|
2023-07-29 17:29:45 +02:00
|
|
|
return null;
|
2022-10-24 00:17:55 +02:00
|
|
|
}
|
|
|
|
|
2021-12-19 19:44:27 +01:00
|
|
|
@Override
|
|
|
|
public void onStartInputView(EditorInfo info, boolean restarting)
|
|
|
|
{
|
2022-12-11 21:57:40 +01:00
|
|
|
refresh_config();
|
2022-07-24 20:02:48 +02:00
|
|
|
refresh_action_label(info);
|
2023-07-29 17:29:45 +02:00
|
|
|
_currentSpecialLayout = refresh_special_layout(info);
|
2023-01-15 23:19:09 +01:00
|
|
|
_keyboardView.setKeyboard(current_layout());
|
2022-11-13 16:18:08 +01:00
|
|
|
_keyeventhandler.started(info);
|
2022-12-14 14:49:35 +01:00
|
|
|
setInputView(_keyboardView);
|
2023-07-19 23:28:33 +02:00
|
|
|
Logs.debug_startup_input_view(info, _config);
|
2021-12-19 19:44:27 +01:00
|
|
|
}
|
2015-10-11 15:30:39 +02:00
|
|
|
|
2022-01-20 21:22:09 +01:00
|
|
|
@Override
|
|
|
|
public void setInputView(View v)
|
|
|
|
{
|
|
|
|
ViewParent parent = v.getParent();
|
|
|
|
if (parent != null && parent instanceof ViewGroup)
|
|
|
|
((ViewGroup)parent).removeView(v);
|
|
|
|
super.setInputView(v);
|
2023-05-24 19:23:28 +02:00
|
|
|
updateSoftInputWindowLayoutParams();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateFullscreenMode() {
|
|
|
|
super.updateFullscreenMode();
|
|
|
|
updateSoftInputWindowLayoutParams();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSoftInputWindowLayoutParams() {
|
|
|
|
final Window window = getWindow().getWindow();
|
|
|
|
updateLayoutHeightOf(window, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
|
final View inputArea = window.findViewById(android.R.id.inputArea);
|
|
|
|
|
|
|
|
updateLayoutHeightOf(
|
|
|
|
(View) inputArea.getParent(),
|
|
|
|
isFullscreenMode()
|
|
|
|
? ViewGroup.LayoutParams.MATCH_PARENT
|
|
|
|
: ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
updateLayoutGravityOf((View) inputArea.getParent(), Gravity.BOTTOM);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void updateLayoutHeightOf(final Window window, final int layoutHeight) {
|
|
|
|
final WindowManager.LayoutParams params = window.getAttributes();
|
|
|
|
if (params != null && params.height != layoutHeight) {
|
|
|
|
params.height = layoutHeight;
|
|
|
|
window.setAttributes(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void updateLayoutHeightOf(final View view, final int layoutHeight) {
|
|
|
|
final ViewGroup.LayoutParams params = view.getLayoutParams();
|
|
|
|
if (params != null && params.height != layoutHeight) {
|
|
|
|
params.height = layoutHeight;
|
|
|
|
view.setLayoutParams(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void updateLayoutGravityOf(final View view, final int layoutGravity) {
|
|
|
|
final ViewGroup.LayoutParams lp = view.getLayoutParams();
|
|
|
|
if (lp instanceof LinearLayout.LayoutParams) {
|
|
|
|
final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lp;
|
|
|
|
if (params.gravity != layoutGravity) {
|
|
|
|
params.gravity = layoutGravity;
|
|
|
|
view.setLayoutParams(params);
|
|
|
|
}
|
|
|
|
} else if (lp instanceof FrameLayout.LayoutParams) {
|
|
|
|
final FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lp;
|
|
|
|
if (params.gravity != layoutGravity) {
|
|
|
|
params.gravity = layoutGravity;
|
|
|
|
view.setLayoutParams(params);
|
|
|
|
}
|
|
|
|
}
|
2022-01-20 21:22:09 +01:00
|
|
|
}
|
|
|
|
|
2021-04-15 23:56:34 +02:00
|
|
|
@Override
|
|
|
|
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype)
|
|
|
|
{
|
2021-05-09 00:09:10 +02:00
|
|
|
refreshSubtypeImm();
|
2023-01-15 23:19:09 +01:00
|
|
|
_keyboardView.setKeyboard(current_layout());
|
2021-04-15 23:56:34 +02:00
|
|
|
}
|
|
|
|
|
2022-07-24 20:02:48 +02:00
|
|
|
@Override
|
|
|
|
public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd, int candidatesStart, int candidatesEnd)
|
|
|
|
{
|
|
|
|
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd);
|
2022-11-13 16:18:08 +01:00
|
|
|
_keyeventhandler.selection_updated(oldSelStart, newSelStart);
|
2022-07-24 20:02:48 +02:00
|
|
|
}
|
|
|
|
|
2021-05-01 22:47:22 +02:00
|
|
|
@Override
|
|
|
|
public void onFinishInputView(boolean finishingInput)
|
|
|
|
{
|
|
|
|
super.onFinishInputView(finishingInput);
|
|
|
|
_keyboardView.reset();
|
|
|
|
}
|
|
|
|
|
2021-12-19 19:44:27 +01:00
|
|
|
@Override
|
2022-12-11 21:57:40 +01:00
|
|
|
public void onSharedPreferenceChanged(SharedPreferences _prefs, String _key)
|
2021-12-19 19:44:27 +01:00
|
|
|
{
|
2022-12-11 21:57:40 +01:00
|
|
|
refresh_config();
|
2023-01-15 23:19:09 +01:00
|
|
|
_keyboardView.setKeyboard(current_layout());
|
2021-12-19 19:44:27 +01:00
|
|
|
}
|
2015-10-01 17:11:52 +02:00
|
|
|
|
2022-10-16 00:42:28 +02:00
|
|
|
@Override
|
|
|
|
public boolean onEvaluateFullscreenMode()
|
|
|
|
{
|
|
|
|
/* Entirely disable fullscreen mode. */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-28 17:47:18 +01:00
|
|
|
/** Not static */
|
|
|
|
public class Receiver implements KeyEventHandler.IReceiver
|
2021-12-19 19:44:27 +01:00
|
|
|
{
|
2023-06-03 20:06:44 +02:00
|
|
|
public void handle_event_key(KeyValue.Event ev)
|
2023-02-12 23:20:11 +01:00
|
|
|
{
|
2023-06-03 20:06:44 +02:00
|
|
|
switch (ev)
|
2023-02-12 23:20:11 +01:00
|
|
|
{
|
2023-06-03 20:06:44 +02:00
|
|
|
case CONFIG:
|
|
|
|
Intent intent = new Intent(Keyboard2.this, SettingsActivity.class);
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
startActivity(intent);
|
|
|
|
break;
|
2021-12-28 17:47:18 +01:00
|
|
|
|
2023-06-03 20:06:44 +02:00
|
|
|
case SWITCH_TEXT:
|
|
|
|
_currentSpecialLayout = null;
|
|
|
|
_keyboardView.setKeyboard(current_layout());
|
|
|
|
break;
|
2023-06-03 18:11:42 +02:00
|
|
|
|
2023-06-03 20:06:44 +02:00
|
|
|
case SWITCH_NUMERIC:
|
2023-07-29 17:29:45 +02:00
|
|
|
setSpecialLayout(loadNumpad(R.xml.numeric));
|
2023-06-03 20:06:44 +02:00
|
|
|
break;
|
2021-12-28 17:47:18 +01:00
|
|
|
|
2023-06-03 20:06:44 +02:00
|
|
|
case SWITCH_EMOJI:
|
|
|
|
if (_emojiPane == null)
|
|
|
|
_emojiPane = (ViewGroup)inflate_view(R.layout.emoji_pane);
|
|
|
|
setInputView(_emojiPane);
|
|
|
|
break;
|
2021-12-28 17:47:18 +01:00
|
|
|
|
2024-01-14 00:50:33 +01:00
|
|
|
case SWITCH_CLIPBOARD:
|
|
|
|
if (_clipboard_pane == null)
|
|
|
|
_clipboard_pane = (ViewGroup)inflate_view(R.layout.clipboard_pane);
|
|
|
|
setInputView(_clipboard_pane);
|
|
|
|
break;
|
|
|
|
|
2023-06-03 20:06:44 +02:00
|
|
|
case SWITCH_BACK_EMOJI:
|
2024-01-14 00:50:33 +01:00
|
|
|
case SWITCH_BACK_CLIPBOARD:
|
2023-06-03 20:06:44 +02:00
|
|
|
setInputView(_keyboardView);
|
|
|
|
break;
|
2022-01-09 20:26:06 +01:00
|
|
|
|
2024-01-15 22:09:15 +01:00
|
|
|
case CHANGE_METHOD_PICKER:
|
2023-06-03 20:06:44 +02:00
|
|
|
get_imm().showInputMethodPicker();
|
2023-01-30 23:46:02 +01:00
|
|
|
break;
|
2023-06-03 20:06:44 +02:00
|
|
|
|
2024-01-15 22:09:15 +01:00
|
|
|
case CHANGE_METHOD_AUTO:
|
2023-06-03 20:06:44 +02:00
|
|
|
if (VERSION.SDK_INT < 28)
|
|
|
|
get_imm().switchToLastInputMethod(getConnectionToken());
|
|
|
|
else
|
2024-01-15 22:10:11 +01:00
|
|
|
switchToNextInputMethod(false);
|
2023-06-03 20:06:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION:
|
|
|
|
InputConnection conn = getCurrentInputConnection();
|
|
|
|
if (conn != null)
|
|
|
|
conn.performEditorAction(actionId);
|
2023-01-30 23:46:02 +01:00
|
|
|
break;
|
2023-06-03 20:06:44 +02:00
|
|
|
|
2023-07-29 18:37:06 +02:00
|
|
|
case SWITCH_FORWARD:
|
|
|
|
incrTextLayout(1);
|
2023-01-30 23:46:02 +01:00
|
|
|
break;
|
2023-06-03 20:06:44 +02:00
|
|
|
|
2023-07-29 18:37:06 +02:00
|
|
|
case SWITCH_BACKWARD:
|
|
|
|
incrTextLayout(-1);
|
2023-01-30 23:46:02 +01:00
|
|
|
break;
|
2023-06-03 20:06:44 +02:00
|
|
|
|
|
|
|
case SWITCH_GREEKMATH:
|
2023-07-29 17:29:45 +02:00
|
|
|
setSpecialLayout(loadNumpad(R.xml.greekmath));
|
2023-01-30 23:46:02 +01:00
|
|
|
break;
|
2023-06-03 20:06:44 +02:00
|
|
|
|
|
|
|
case CAPS_LOCK:
|
|
|
|
set_shift_state(true, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SWITCH_VOICE_TYPING:
|
2023-12-30 00:56:55 +01:00
|
|
|
if (!VoiceImeSwitcher.switch_to_voice_ime(Keyboard2.this, get_imm(),
|
|
|
|
Config.globalPrefs()))
|
|
|
|
_config.shouldOfferVoiceTyping = false;
|
2023-06-03 20:06:44 +02:00
|
|
|
break;
|
2023-12-30 01:24:21 +01:00
|
|
|
|
|
|
|
case SWITCH_VOICE_TYPING_CHOOSER:
|
|
|
|
VoiceImeSwitcher.choose_voice_ime(Keyboard2.this, get_imm(),
|
|
|
|
Config.globalPrefs());
|
|
|
|
break;
|
2023-01-30 23:46:02 +01:00
|
|
|
}
|
2021-12-19 19:44:27 +01:00
|
|
|
}
|
2015-08-03 15:58:13 +02:00
|
|
|
|
2023-06-03 20:06:44 +02:00
|
|
|
public void set_shift_state(boolean state, boolean lock)
|
2021-12-28 17:47:18 +01:00
|
|
|
{
|
2023-06-03 20:06:44 +02:00
|
|
|
_keyboardView.set_shift_state(state, lock);
|
2021-12-28 17:47:18 +01:00
|
|
|
}
|
2015-08-03 15:58:13 +02:00
|
|
|
|
2024-02-11 20:46:36 +01:00
|
|
|
public void set_compose_pending(boolean pending)
|
|
|
|
{
|
|
|
|
_keyboardView.set_compose_pending(pending);
|
|
|
|
}
|
|
|
|
|
2022-11-13 16:18:08 +01:00
|
|
|
public InputConnection getCurrentInputConnection()
|
2021-12-28 17:47:18 +01:00
|
|
|
{
|
2022-11-13 16:18:08 +01:00
|
|
|
return Keyboard2.this.getCurrentInputConnection();
|
2021-12-28 17:47:18 +01:00
|
|
|
}
|
2021-12-19 19:44:27 +01:00
|
|
|
}
|
2021-04-18 23:31:59 +02:00
|
|
|
|
|
|
|
private IBinder getConnectionToken()
|
|
|
|
{
|
|
|
|
return getWindow().getWindow().getAttributes().token;
|
|
|
|
}
|
2021-12-30 00:26:05 +01:00
|
|
|
|
|
|
|
private View inflate_view(int layout)
|
|
|
|
{
|
|
|
|
return View.inflate(new ContextThemeWrapper(this, _config.theme), layout, null);
|
|
|
|
}
|
2015-07-30 20:14:55 +02:00
|
|
|
}
|