Clear keyboard cache when system locale is changed
Bug: 17310080 Change-Id: I2b388772f269f1e7610a5bd32de80793da2df16emain
parent
6bd267f4f7
commit
f2eadbb497
|
@ -82,6 +82,7 @@
|
||||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
<action android:name="android.intent.action.USER_INITIALIZE" />
|
<action android:name="android.intent.action.USER_INITIALIZE" />
|
||||||
|
<action android:name="android.intent.action.LOCALE_CHANGED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,15 @@ public final class KeyboardLayoutSet {
|
||||||
new SparseArray<>();
|
new SparseArray<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearKeyboardCache() {
|
public static void onSystemLocaleChanged() {
|
||||||
|
clearKeyboardCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onKeyboardThemeChanged() {
|
||||||
|
clearKeyboardCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void clearKeyboardCache() {
|
||||||
sKeyboardCache.clear();
|
sKeyboardCache.clear();
|
||||||
sKeysCache.clear();
|
sKeysCache.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
if (mThemeContext == null || !keyboardTheme.equals(mKeyboardTheme)) {
|
if (mThemeContext == null || !keyboardTheme.equals(mKeyboardTheme)) {
|
||||||
mKeyboardTheme = keyboardTheme;
|
mKeyboardTheme = keyboardTheme;
|
||||||
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
|
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
|
||||||
KeyboardLayoutSet.clearKeyboardCache();
|
KeyboardLayoutSet.onKeyboardThemeChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -17,21 +17,16 @@
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import com.android.inputmethod.compat.IntentCompatUtils;
|
import com.android.inputmethod.compat.IntentCompatUtils;
|
||||||
import com.android.inputmethod.latin.settings.Settings;
|
import com.android.inputmethod.keyboard.KeyboardLayoutSet;
|
||||||
import com.android.inputmethod.latin.setup.LauncherIconVisibilityManager;
|
import com.android.inputmethod.latin.setup.LauncherIconVisibilityManager;
|
||||||
import com.android.inputmethod.latin.setup.SetupActivity;
|
|
||||||
import com.android.inputmethod.latin.utils.UncachedInputMethodManagerUtils;
|
import com.android.inputmethod.latin.utils.UncachedInputMethodManagerUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,6 +53,9 @@ import com.android.inputmethod.latin.utils.UncachedInputMethodManagerUtils;
|
||||||
* When a multiuser account has been created, {@link Intent#ACTION_USER_INITIALIZE} is received
|
* When a multiuser account has been created, {@link Intent#ACTION_USER_INITIALIZE} is received
|
||||||
* by this receiver and it checks the whether the setup wizard's icon should be appeared or not on
|
* by this receiver and it checks the whether the setup wizard's icon should be appeared or not on
|
||||||
* the launcher depending on which partition this IME is installed.
|
* the launcher depending on which partition this IME is installed.
|
||||||
|
*
|
||||||
|
* When the system locale has been changed, {@link Intent#ACTION_LOCALE_CHANGED} is received by
|
||||||
|
* this receiver and the {@link KeyboardLayoutSet}'s cache is cleared.
|
||||||
*/
|
*/
|
||||||
public final class SystemBroadcastReceiver extends BroadcastReceiver {
|
public final class SystemBroadcastReceiver extends BroadcastReceiver {
|
||||||
private static final String TAG = SystemBroadcastReceiver.class.getSimpleName();
|
private static final String TAG = SystemBroadcastReceiver.class.getSimpleName();
|
||||||
|
@ -67,21 +65,22 @@ public final class SystemBroadcastReceiver extends BroadcastReceiver {
|
||||||
final String intentAction = intent.getAction();
|
final String intentAction = intent.getAction();
|
||||||
if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intentAction)) {
|
if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intentAction)) {
|
||||||
Log.i(TAG, "Package has been replaced: " + context.getPackageName());
|
Log.i(TAG, "Package has been replaced: " + context.getPackageName());
|
||||||
} else if (Intent.ACTION_BOOT_COMPLETED.equals(intentAction)) {
|
|
||||||
Log.i(TAG, "Boot has been completed");
|
|
||||||
} else if (IntentCompatUtils.is_ACTION_USER_INITIALIZE(intentAction)) {
|
|
||||||
Log.i(TAG, "User initialize");
|
|
||||||
}
|
|
||||||
|
|
||||||
LauncherIconVisibilityManager.onReceiveGlobalIntent(intentAction, context);
|
|
||||||
|
|
||||||
if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intentAction)) {
|
|
||||||
// Need to restore additional subtypes because system always clears additional
|
// Need to restore additional subtypes because system always clears additional
|
||||||
// subtypes when the package is replaced.
|
// subtypes when the package is replaced.
|
||||||
RichInputMethodManager.init(context);
|
RichInputMethodManager.init(context);
|
||||||
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
||||||
final InputMethodSubtype[] additionalSubtypes = richImm.getAdditionalSubtypes(context);
|
final InputMethodSubtype[] additionalSubtypes = richImm.getAdditionalSubtypes(context);
|
||||||
richImm.setAdditionalInputMethodSubtypes(additionalSubtypes);
|
richImm.setAdditionalInputMethodSubtypes(additionalSubtypes);
|
||||||
|
LauncherIconVisibilityManager.updateSetupWizardIconVisibility(context);
|
||||||
|
} else if (Intent.ACTION_BOOT_COMPLETED.equals(intentAction)) {
|
||||||
|
Log.i(TAG, "Boot has been completed");
|
||||||
|
LauncherIconVisibilityManager.updateSetupWizardIconVisibility(context);
|
||||||
|
} else if (IntentCompatUtils.is_ACTION_USER_INITIALIZE(intentAction)) {
|
||||||
|
Log.i(TAG, "User initialize");
|
||||||
|
LauncherIconVisibilityManager.updateSetupWizardIconVisibility(context);
|
||||||
|
} else if (Intent.ACTION_LOCALE_CHANGED.equals(intentAction)) {
|
||||||
|
Log.i(TAG, "System locale changed");
|
||||||
|
KeyboardLayoutSet.onSystemLocaleChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
// The process that hosts this broadcast receiver is invoked and remains alive even after
|
// The process that hosts this broadcast receiver is invoked and remains alive even after
|
||||||
|
|
|
@ -24,7 +24,6 @@ import android.content.pm.PackageManager;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.inputmethod.compat.IntentCompatUtils;
|
|
||||||
import com.android.inputmethod.latin.settings.Settings;
|
import com.android.inputmethod.latin.settings.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,14 +54,6 @@ import com.android.inputmethod.latin.settings.Settings;
|
||||||
public final class LauncherIconVisibilityManager {
|
public final class LauncherIconVisibilityManager {
|
||||||
private static final String TAG = LauncherIconVisibilityManager.class.getSimpleName();
|
private static final String TAG = LauncherIconVisibilityManager.class.getSimpleName();
|
||||||
|
|
||||||
public static void onReceiveGlobalIntent(final String action, final Context context) {
|
|
||||||
if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(action) ||
|
|
||||||
Intent.ACTION_BOOT_COMPLETED.equals(action) ||
|
|
||||||
IntentCompatUtils.is_ACTION_USER_INITIALIZE(action)) {
|
|
||||||
updateSetupWizardIconVisibility(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateSetupWizardIconVisibility(final Context context) {
|
public static void updateSetupWizardIconVisibility(final Context context) {
|
||||||
final ComponentName setupWizardActivity = new ComponentName(context, SetupActivity.class);
|
final ComponentName setupWizardActivity = new ComponentName(context, SetupActivity.class);
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
|
@ -118,8 +118,16 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio
|
||||||
super.testActionCustom();
|
super.testActionCustom();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Working variable to simulate system locale changing.
|
||||||
|
private Locale mSystemLocale = Locale.getDefault();
|
||||||
|
|
||||||
private void doTestActionLabelInLocale(final InputMethodSubtype subtype,
|
private void doTestActionLabelInLocale(final InputMethodSubtype subtype,
|
||||||
final Locale labelLocale, final Locale systemLocale) {
|
final Locale labelLocale, final Locale systemLocale) {
|
||||||
|
// Simulate system locale changing, see {@link SystemBroadcastReceiver}.
|
||||||
|
if (!systemLocale.equals(mSystemLocale)) {
|
||||||
|
KeyboardLayoutSet.onSystemLocaleChanged();
|
||||||
|
mSystemLocale = systemLocale;
|
||||||
|
}
|
||||||
final String tag = "label=" + labelLocale + " system=" + systemLocale
|
final String tag = "label=" + labelLocale + " system=" + systemLocale
|
||||||
+ " " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
|
+ " " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
|
||||||
final RunInLocale<Void> job = new RunInLocale<Void>() {
|
final RunInLocale<Void> job = new RunInLocale<Void>() {
|
||||||
|
@ -164,9 +172,8 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio
|
||||||
SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.QWERTY);
|
SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.QWERTY);
|
||||||
// An action label of no language keyboard should be displayed in the system locale.
|
// An action label of no language keyboard should be displayed in the system locale.
|
||||||
doTestActionLabelInLocale(noLanguage, Locale.US, Locale.US);
|
doTestActionLabelInLocale(noLanguage, Locale.US, Locale.US);
|
||||||
// TODO: Uncomment the following test once a bug is fixed.
|
doTestActionLabelInLocale(noLanguage, Locale.FRENCH, Locale.FRENCH);
|
||||||
// doTestActionLabelInLocale(noLanguage, Locale.FRENCH, Locale.FRENCH);
|
doTestActionLabelInLocale(noLanguage, Locale.ITALIAN, Locale.ITALIAN);
|
||||||
// doTestActionLabelInLocale(noLanguage, Locale.ITALIAN, Locale.ITALIAN);
|
doTestActionLabelInLocale(noLanguage, Locale.JAPANESE, Locale.JAPANESE);
|
||||||
// doTestActionLabelInLocale(noLanguage, Locale.JAPANESE, Locale.JAPANESE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue