1313import android .view .*;
1414import android .view .inputmethod .EditorInfo ;
1515import android .view .inputmethod .InputConnection ;
16- import android .view .inputmethod .InputMethodInfo ;
1716import android .view .inputmethod .InputMethodManager ;
1817import android .view .inputmethod .InputMethodSubtype ;
1918import android .widget .FrameLayout ;
@@ -38,6 +37,8 @@ public class Keyboard2 extends InputMethodService
3837 private KeyboardData _currentSpecialLayout ;
3938 /** Layout associated with the currently selected locale. Not 'null'. */
4039 private KeyboardData _localeTextLayout ;
40+ /** Installed and current locales. */
41+ private DeviceLocales _device_locales ;
4142 private ViewGroup _emojiPane = null ;
4243 private ViewGroup _clipboard_pane = null ;
4344 private Handler _handler ;
@@ -119,6 +120,7 @@ public void onCreate()
119120 prefs .registerOnSharedPreferenceChangeListener (this );
120121 _config = Config .globalConfig ();
121122 Logs .set_debug_logs (getResources ().getBoolean (R .bool .debug_logs ));
123+ refreshSubtypeImm ();
122124 create_keyboard_view ();
123125 ClipboardHistoryService .on_startup (this , _keyeventhandler );
124126 _foldStateTracker .setChangedCallback (() -> { refresh_config (); });
@@ -138,79 +140,31 @@ private void create_keyboard_view()
138140 _candidates_view = (CandidatesView )_container_view .findViewById (R .id .candidates_view );
139141 }
140142
141- private List <InputMethodSubtype > getEnabledSubtypes (InputMethodManager imm )
142- {
143- String pkg = getPackageName ();
144- for (InputMethodInfo imi : imm .getEnabledInputMethodList ())
145- if (imi .getPackageName ().equals (pkg ))
146- return imm .getEnabledInputMethodSubtypeList (imi , true );
147- return Arrays .asList ();
148- }
149-
150- private ExtraKeys extra_keys_of_subtype (InputMethodSubtype subtype )
151- {
152- String extra_keys = subtype .getExtraValueOf ("extra_keys" );
153- String script = subtype .getExtraValueOf ("script" );
154- if (extra_keys != null )
155- return ExtraKeys .parse (script , extra_keys );
156- return ExtraKeys .EMPTY ;
157- }
158-
159- private void refreshAccentsOption (InputMethodManager imm , List <InputMethodSubtype > enabled_subtypes )
160- {
161- List <ExtraKeys > extra_keys = new ArrayList <ExtraKeys >();
162- for (InputMethodSubtype s : enabled_subtypes )
163- extra_keys .add (extra_keys_of_subtype (s ));
164- _config .extra_keys_subtype = ExtraKeys .merge (extra_keys );
165- }
166-
167143 InputMethodManager get_imm ()
168144 {
169145 return (InputMethodManager )getSystemService (INPUT_METHOD_SERVICE );
170146 }
171147
172- private InputMethodSubtype defaultSubtypes (InputMethodManager imm , List <InputMethodSubtype > enabled_subtypes )
173- {
174- if (VERSION .SDK_INT < 24 )
175- return imm .getCurrentInputMethodSubtype ();
176- // Android might return a random subtype, for example, the first in the
177- // list alphabetically.
178- InputMethodSubtype current_subtype = imm .getCurrentInputMethodSubtype ();
179- if (current_subtype == null )
180- return null ;
181- for (InputMethodSubtype s : enabled_subtypes )
182- if (s .getLanguageTag ().equals (current_subtype .getLanguageTag ()))
183- return s ;
184- return null ;
185- }
186-
187148 private void refreshSubtypeImm ()
188149 {
189- InputMethodManager imm = get_imm ();
190150 _config .shouldOfferVoiceTyping = true ;
191151 KeyboardData default_layout = null ;
192- _config . extra_keys_subtype = null ;
193- if (VERSION . SDK_INT >= 12 )
152+ _device_locales = DeviceLocales . load ( this ) ;
153+ if (_device_locales . default_ != null )
194154 {
195- List <InputMethodSubtype > enabled_subtypes = getEnabledSubtypes (imm );
196- InputMethodSubtype subtype = defaultSubtypes (imm , enabled_subtypes );
197- if (subtype != null )
198- {
199- String s = subtype .getExtraValueOf ("default_layout" );
200- if (s != null )
201- default_layout = LayoutsPreference .layout_of_string (getResources (), s );
202- refreshAccentsOption (imm , enabled_subtypes );
203- }
155+ String layout_name = _device_locales .default_ .default_layout ;
156+ if (layout_name != null )
157+ default_layout = LayoutsPreference .layout_of_string (getResources (), layout_name );
204158 }
159+ _config .extra_keys_subtype = _device_locales .extra_keys ();
205160 if (default_layout == null )
206161 default_layout = loadLayout (R .xml .latn_qwerty_us );
207162 _localeTextLayout = default_layout ;
208163 }
209164
210- private void refresh_candidates_view (EditorInfo info )
165+ private void refresh_candidates_view ()
211166 {
212- boolean should_show = CandidatesView .should_show (info );
213- _config .should_show_candidates_view = should_show ;
167+ boolean should_show = _config .editor_config .should_show_candidates_view ;
214168 _candidates_view .setVisibility (should_show ? View .VISIBLE : View .GONE );
215169 }
216170
@@ -220,7 +174,6 @@ private void refresh_config()
220174 {
221175 int prev_theme = _config .theme ;
222176 _config .refresh (getResources (), _foldStateTracker .isUnfolded ());
223- refreshSubtypeImm ();
224177 // Refreshing the theme config requires re-creating the views
225178 if (prev_theme != _config .theme )
226179 {
@@ -252,7 +205,7 @@ public void onStartInputView(EditorInfo info, boolean restarting)
252205 {
253206 _config .editor_config .refresh (info , getResources ());
254207 refresh_config ();
255- refresh_candidates_view (info );
208+ refresh_candidates_view ();
256209 _currentSpecialLayout = refresh_special_layout ();
257210 _keyboardView .setKeyboard (current_layout ());
258211 _keyeventhandler .started (_config );
@@ -339,6 +292,7 @@ private static void updateLayoutGravityOf(final View view, final int layoutGravi
339292 public void onCurrentInputMethodSubtypeChanged (InputMethodSubtype subtype )
340293 {
341294 refreshSubtypeImm ();
295+ refresh_candidates_view ();
342296 _keyboardView .setKeyboard (current_layout ());
343297 }
344298
0 commit comments