Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3e2d3858 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Restart LatinIME service when keyboard theme is changed

Bug: 6023947
Change-Id: I779da32708fca7333aff74929cc98173246ee685
parent 77541fc9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -388,6 +388,7 @@ public class Keyboard {
        }
    }

    // TODO: Move this method to KeyboardSwitcher.
    public static String toThemeName(int themeId) {
        // This should be aligned with theme-*.xml resource files' themeId attribute.
        switch (themeId) {
+4 −35
Original line number Diff line number Diff line
@@ -39,8 +39,7 @@ import com.android.inputmethod.latin.SettingsValues;
import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.Utils;

public class KeyboardSwitcher implements KeyboardState.SwitchActions,
        SharedPreferences.OnSharedPreferenceChangeListener {
public class KeyboardSwitcher implements KeyboardState.SwitchActions {
    private static final String TAG = KeyboardSwitcher.class.getSimpleName();

    public static final String PREF_KEYBOARD_LAYOUT = "pref_keyboard_layout_20110916";
@@ -94,7 +93,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
        mSubtypeSwitcher = SubtypeSwitcher.getInstance();
        mState = new KeyboardState(this);
        setContextThemeWrapper(ims, getKeyboardThemeIndex(ims, prefs));
        prefs.registerOnSharedPreferenceChangeListener(this);
        mForceNonDistinctMultitouch = prefs.getBoolean(
                DebugSettings.FORCE_NON_DISTINCT_MULTITOUCH_KEY, false);
    }
@@ -341,34 +339,26 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
    }

    public View onCreateInputView() {
        return createInputView(mThemeIndex, true);
    }

    private View createInputView(final int newThemeIndex, final boolean forceRecreate) {
        if (mCurrentInputView != null && mThemeIndex == newThemeIndex && !forceRecreate)
            return mCurrentInputView;

        if (mKeyboardView != null) {
            mKeyboardView.closing();
        }

        final int oldThemeIndex = mThemeIndex;
        Utils.GCUtils.getInstance().reset();
        boolean tryGC = true;
        for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
            try {
                setContextThemeWrapper(mInputMethodService, newThemeIndex);
                setContextThemeWrapper(mInputMethodService, mThemeIndex);
                mCurrentInputView = (InputView)LayoutInflater.from(mThemeContext).inflate(
                        R.layout.input_view, null);
                tryGC = false;
            } catch (OutOfMemoryError e) {
                Log.w(TAG, "load keyboard failed: " + e);
                tryGC = Utils.GCUtils.getInstance().tryGCOrWait(
                        oldThemeIndex + "," + newThemeIndex, e);
                        Keyboard.toThemeName(mThemeIndex), e);
            } catch (InflateException e) {
                Log.w(TAG, "load keyboard failed: " + e);
                tryGC = Utils.GCUtils.getInstance().tryGCOrWait(
                        oldThemeIndex + "," + newThemeIndex, e);
                        Keyboard.toThemeName(mThemeIndex), e);
            }
        }

@@ -385,27 +375,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
        return mCurrentInputView;
    }

    private void postSetInputView(final View newInputView) {
        final LatinIME latinIme = mInputMethodService;
        latinIme.mHandler.post(new Runnable() {
            @Override
            public void run() {
                if (newInputView != null) {
                    latinIme.setInputView(newInputView);
                }
                latinIme.updateInputViewShown();
            }
        });
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        if (PREF_KEYBOARD_LAYOUT.equals(key)) {
            final int themeIndex = getKeyboardThemeIndex(mInputMethodService, sharedPreferences);
            postSetInputView(createInputView(themeIndex, false));
        }
    }

    public void onNetworkStateChanged() {
        if (mKeyboardView != null) {
            mKeyboardView.updateShortcutKey(SubtypeSwitcher.getInstance().isShortcutImeReady());
+4 −1
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.preference.CheckBoxPreference;
import android.preference.PreferenceActivity;
import android.util.Log;

import com.android.inputmethod.keyboard.KeyboardSwitcher;

public class DebugSettings extends PreferenceActivity
        implements SharedPreferences.OnSharedPreferenceChangeListener {

@@ -61,7 +63,8 @@ public class DebugSettings extends PreferenceActivity
                updateDebugMode();
                mServiceNeedsRestart = true;
            }
        } else if (key.equals(FORCE_NON_DISTINCT_MULTITOUCH_KEY)) {
        } else if (key.equals(FORCE_NON_DISTINCT_MULTITOUCH_KEY)
                || key.equals(KeyboardSwitcher.PREF_KEYBOARD_LAYOUT)) {
            mServiceNeedsRestart = true;
        }
    }