aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2013-01-07 18:40:59 +0900
committerTadashi G. Takaoka <takaoka@google.com>2013-01-07 19:05:31 +0900
commitf90fc105ab1159f43f536bcacdd1224c2c05bacb (patch)
tree4a7af2845d4d431f946e33eb8c179aa786e010e8 /java/src
parentb6ca354431367b625daf9fff5fbe4b1f5ef996ab (diff)
downloadlatinime-f90fc105ab1159f43f536bcacdd1224c2c05bacb.tar.gz
latinime-f90fc105ab1159f43f536bcacdd1224c2c05bacb.tar.xz
latinime-f90fc105ab1159f43f536bcacdd1224c2c05bacb.zip
Simplify singleton class initialization
Change-Id: I16a27f2ed6ea66184bfdc9903180372cd7ea2fd1
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java31
-rw-r--r--java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java2
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java8
-rw-r--r--java/src/com/android/inputmethod/latin/LatinImeLogger.java2
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputMethodManager.java4
-rw-r--r--java/src/com/android/inputmethod/research/ResearchLogger.java4
6 files changed, 29 insertions, 22 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index c1c105e8d..51517823a 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
+import android.preference.PreferenceManager;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
@@ -50,7 +51,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
// Note: The themeId should be aligned with "themeId" attribute of Keyboard style
// in values/style.xml.
- public KeyboardTheme(int themeId, int styleId) {
+ public KeyboardTheme(final int themeId, final int styleId) {
mThemeId = themeId;
mStyleId = styleId;
}
@@ -95,11 +96,12 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
// Intentional empty constructor for singleton.
}
- public static void init(LatinIME latinIme, SharedPreferences prefs) {
+ public static void init(final LatinIME latinIme) {
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(latinIme);
sInstance.initInternal(latinIme, prefs);
}
- private void initInternal(LatinIME latinIme, SharedPreferences prefs) {
+ private void initInternal(final LatinIME latinIme, final SharedPreferences prefs) {
mLatinIME = latinIme;
mResources = latinIme.getResources();
mFeedbackManager = new AudioAndHapticFeedbackManager(latinIme);
@@ -109,7 +111,8 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
setContextThemeWrapper(latinIme, getKeyboardTheme(latinIme, prefs));
}
- private static KeyboardTheme getKeyboardTheme(Context context, SharedPreferences prefs) {
+ private static KeyboardTheme getKeyboardTheme(final Context context,
+ final SharedPreferences prefs) {
final String defaultIndex = context.getString(R.string.config_default_keyboard_theme_index);
final String themeIndex = prefs.getString(PREF_KEYBOARD_LAYOUT, defaultIndex);
try {
@@ -124,7 +127,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
return KEYBOARD_THEMES[0];
}
- private void setContextThemeWrapper(Context context, KeyboardTheme keyboardTheme) {
+ private void setContextThemeWrapper(final Context context, final KeyboardTheme keyboardTheme) {
if (mThemeContext == null || mKeyboardTheme.mThemeId != keyboardTheme.mThemeId) {
mKeyboardTheme = keyboardTheme;
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
@@ -132,7 +135,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
}
}
- public void loadKeyboard(EditorInfo editorInfo, SettingsValues settingsValues) {
+ public void loadKeyboard(final EditorInfo editorInfo, final SettingsValues settingsValues) {
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(
mThemeContext, editorInfo);
final Resources res = mThemeContext.getResources();
@@ -210,14 +213,14 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
mState.onResetKeyboardStateToAlphabet();
}
- public void onPressKey(int code) {
+ public void onPressKey(final int code) {
if (isVibrateAndSoundFeedbackRequired()) {
mFeedbackManager.hapticAndAudioFeedback(code, mKeyboardView);
}
mState.onPressKey(code, isSinglePointer(), mLatinIME.getCurrentAutoCapsState());
}
- public void onReleaseKey(int code, boolean withSliding) {
+ public void onReleaseKey(final int code, final boolean withSliding) {
mState.onReleaseKey(code, withSliding);
}
@@ -303,7 +306,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
// Implements {@link KeyboardState.SwitchActions}.
@Override
- public void startLongPressTimer(int code) {
+ public void startLongPressTimer(final int code) {
final MainKeyboardView keyboardView = getMainKeyboardView();
if (keyboardView != null) {
final TimerProxy timer = keyboardView.getTimerProxy();
@@ -323,11 +326,11 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
// Implements {@link KeyboardState.SwitchActions}.
@Override
- public void hapticAndAudioFeedback(int code) {
+ public void hapticAndAudioFeedback(final int code) {
mFeedbackManager.hapticAndAudioFeedback(code, mKeyboardView);
}
- public void onLongPressTimeout(int code) {
+ public void onLongPressTimeout(final int code) {
mState.onLongPressTimeout(code);
}
@@ -346,7 +349,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
/**
* Updates state machine to figure out when to automatically switch back to the previous mode.
*/
- public void onCodeInput(int code) {
+ public void onCodeInput(final int code) {
mState.onCodeInput(code, isSinglePointer(), mLatinIME.getCurrentAutoCapsState());
}
@@ -354,7 +357,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
return mKeyboardView;
}
- public View onCreateInputView(boolean isHardwareAcceleratedDrawingEnabled) {
+ public View onCreateInputView(final boolean isHardwareAcceleratedDrawingEnabled) {
if (mKeyboardView != null) {
mKeyboardView.closing();
}
@@ -383,7 +386,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
}
}
- public void onAutoCorrectionStateChanged(boolean isAutoCorrection) {
+ public void onAutoCorrectionStateChanged(final boolean isAutoCorrection) {
if (mIsAutoCorrectionActive != isAutoCorrection) {
mIsAutoCorrectionActive = isAutoCorrection;
if (mKeyboardView != null) {
diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
index 08f08d24e..6ac5a9b94 100644
--- a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
+++ b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
@@ -387,7 +387,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
super.onCreate(savedInstanceState);
mPrefs = getPreferenceManager().getSharedPreferences();
- RichInputMethodManager.init(getActivity(), mPrefs);
+ RichInputMethodManager.init(getActivity());
mRichImm = RichInputMethodManager.getInstance();
addPreferencesFromResource(R.xml.additional_subtype_settings);
setHasOptionsMenu(true);
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 1061859df..9d16eb7c5 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -413,14 +413,14 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mResources = getResources();
- LatinImeLogger.init(this, mPrefs);
+ LatinImeLogger.init(this);
if (ProductionFlag.IS_EXPERIMENTAL) {
- ResearchLogger.getInstance().init(this, mPrefs);
+ ResearchLogger.getInstance().init(this);
}
- RichInputMethodManager.init(this, mPrefs);
+ RichInputMethodManager.init(this);
mRichImm = RichInputMethodManager.getInstance();
SubtypeSwitcher.init(this);
- KeyboardSwitcher.init(this, mPrefs);
+ KeyboardSwitcher.init(this);
AccessibilityUtils.init(this);
super.onCreate();
diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java
index 394a9c7aa..e4e8b94b2 100644
--- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java
+++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java
@@ -31,7 +31,7 @@ public final class LatinImeLogger implements SharedPreferences.OnSharedPreferenc
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
}
- public static void init(LatinIME context, SharedPreferences prefs) {
+ public static void init(LatinIME context) {
}
public static void commit() {
diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
index af0d61cc7..637916f76 100644
--- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
+++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
@@ -21,6 +21,7 @@ import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.IBinder;
+import android.preference.PreferenceManager;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
@@ -50,7 +51,8 @@ public final class RichInputMethodManager {
return sInstance;
}
- public static void init(final Context context, final SharedPreferences prefs) {
+ public static void init(final Context context) {
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
sInstance.initInternal(context, prefs);
}
diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java
index cde100a5f..709746ee3 100644
--- a/java/src/com/android/inputmethod/research/ResearchLogger.java
+++ b/java/src/com/android/inputmethod/research/ResearchLogger.java
@@ -38,6 +38,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.IBinder;
import android.os.SystemClock;
+import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
@@ -161,7 +162,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
return sInstance;
}
- public void init(final LatinIME latinIME, final SharedPreferences prefs) {
+ public void init(final LatinIME latinIME) {
assert latinIME != null;
if (latinIME == null) {
Log.w(TAG, "IMS is null; logging is off");
@@ -171,6 +172,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
Log.w(TAG, "IME storage directory does not exist.");
}
}
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(latinIME);
if (prefs != null) {
mUUIDString = getUUID(prefs);
if (!prefs.contains(PREF_USABILITY_STUDY_MODE)) {