Remove GCUtils utility class
Change-Id: Ia666aeb10c155d69763faf7f01ceca113b9b4653
This commit is contained in:
parent
f852891437
commit
1f05cf6dab
3 changed files with 13 additions and 77 deletions
|
@ -21,7 +21,6 @@ import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.InflateException;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
@ -38,7 +37,6 @@ import com.android.inputmethod.latin.LatinImeLogger;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.SettingsValues;
|
import com.android.inputmethod.latin.SettingsValues;
|
||||||
import com.android.inputmethod.latin.SubtypeSwitcher;
|
import com.android.inputmethod.latin.SubtypeSwitcher;
|
||||||
import com.android.inputmethod.latin.Utils;
|
|
||||||
import com.android.inputmethod.latin.WordComposer;
|
import com.android.inputmethod.latin.WordComposer;
|
||||||
|
|
||||||
public class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
public class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
|
@ -47,24 +45,24 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
public static final String PREF_KEYBOARD_LAYOUT = "pref_keyboard_layout_20110916";
|
public static final String PREF_KEYBOARD_LAYOUT = "pref_keyboard_layout_20110916";
|
||||||
|
|
||||||
static class KeyboardTheme {
|
static class KeyboardTheme {
|
||||||
public final String mName;
|
|
||||||
public final int mThemeId;
|
public final int mThemeId;
|
||||||
public final int mStyleId;
|
public final int mStyleId;
|
||||||
|
|
||||||
public KeyboardTheme(String name, int themeId, int styleId) {
|
// Note: The themeId should be aligned with "themeId" attribute of Keyboard style
|
||||||
mName = name;
|
// in values/style.xml.
|
||||||
|
public KeyboardTheme(int themeId, int styleId) {
|
||||||
mThemeId = themeId;
|
mThemeId = themeId;
|
||||||
mStyleId = styleId;
|
mStyleId = styleId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final KeyboardTheme[] KEYBOARD_THEMES = {
|
private static final KeyboardTheme[] KEYBOARD_THEMES = {
|
||||||
new KeyboardTheme("Basic", 0, R.style.KeyboardTheme),
|
new KeyboardTheme(0, R.style.KeyboardTheme),
|
||||||
new KeyboardTheme("HighContrast", 1, R.style.KeyboardTheme_HighContrast),
|
new KeyboardTheme(1, R.style.KeyboardTheme_HighContrast),
|
||||||
new KeyboardTheme("Stone", 6, R.style.KeyboardTheme_Stone),
|
new KeyboardTheme(6, R.style.KeyboardTheme_Stone),
|
||||||
new KeyboardTheme("Stone.Bold", 7, R.style.KeyboardTheme_Stone_Bold),
|
new KeyboardTheme(7, R.style.KeyboardTheme_Stone_Bold),
|
||||||
new KeyboardTheme("GingerBread", 8, R.style.KeyboardTheme_Gingerbread),
|
new KeyboardTheme(8, R.style.KeyboardTheme_Gingerbread),
|
||||||
new KeyboardTheme("IceCreamSandwich", 5, R.style.KeyboardTheme_IceCreamSandwich),
|
new KeyboardTheme(5, R.style.KeyboardTheme_IceCreamSandwich),
|
||||||
};
|
};
|
||||||
|
|
||||||
private SubtypeSwitcher mSubtypeSwitcher;
|
private SubtypeSwitcher mSubtypeSwitcher;
|
||||||
|
@ -355,22 +353,9 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
mKeyboardView.closing();
|
mKeyboardView.closing();
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils.GCUtils.getInstance().reset();
|
|
||||||
boolean tryGC = true;
|
|
||||||
for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
|
|
||||||
try {
|
|
||||||
setContextThemeWrapper(mLatinIME, mKeyboardTheme);
|
setContextThemeWrapper(mLatinIME, mKeyboardTheme);
|
||||||
mCurrentInputView = (InputView)LayoutInflater.from(mThemeContext).inflate(
|
mCurrentInputView = (InputView)LayoutInflater.from(mThemeContext).inflate(
|
||||||
R.layout.input_view, null);
|
R.layout.input_view, null);
|
||||||
tryGC = false;
|
|
||||||
} catch (OutOfMemoryError e) {
|
|
||||||
Log.w(TAG, "load keyboard failed: " + e);
|
|
||||||
tryGC = Utils.GCUtils.getInstance().tryGCOrWait(mKeyboardTheme.mName, e);
|
|
||||||
} catch (InflateException e) {
|
|
||||||
Log.w(TAG, "load keyboard failed: " + e);
|
|
||||||
tryGC = Utils.GCUtils.getInstance().tryGCOrWait(mKeyboardTheme.mName, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mKeyboardView = (MainKeyboardView) mCurrentInputView.findViewById(R.id.keyboard_view);
|
mKeyboardView = (MainKeyboardView) mCurrentInputView.findViewById(R.id.keyboard_view);
|
||||||
if (isHardwareAcceleratedDrawingEnabled) {
|
if (isHardwareAcceleratedDrawingEnabled) {
|
||||||
|
|
|
@ -381,18 +381,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
|
|
||||||
ImfUtils.setAdditionalInputMethodSubtypes(this, mCurrentSettings.getAdditionalSubtypes());
|
ImfUtils.setAdditionalInputMethodSubtypes(this, mCurrentSettings.getAdditionalSubtypes());
|
||||||
|
|
||||||
Utils.GCUtils.getInstance().reset();
|
|
||||||
boolean tryGC = true;
|
|
||||||
// Shouldn't this be removed? I think that from Honeycomb on, the GC is now actually working
|
|
||||||
// as expected and this code is useless.
|
|
||||||
for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
|
|
||||||
try {
|
|
||||||
initSuggest();
|
initSuggest();
|
||||||
tryGC = false;
|
|
||||||
} catch (OutOfMemoryError e) {
|
|
||||||
tryGC = Utils.GCUtils.getInstance().tryGCOrWait("InitSuggest", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mDisplayOrientation = res.getConfiguration().orientation;
|
mDisplayOrientation = res.getConfiguration().orientation;
|
||||||
|
|
||||||
|
|
|
@ -65,44 +65,6 @@ public class Utils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GCUtils {
|
|
||||||
private static final String GC_TAG = GCUtils.class.getSimpleName();
|
|
||||||
public static final int GC_TRY_COUNT = 2;
|
|
||||||
// GC_TRY_LOOP_MAX is used for the hard limit of GC wait,
|
|
||||||
// GC_TRY_LOOP_MAX should be greater than GC_TRY_COUNT.
|
|
||||||
public static final int GC_TRY_LOOP_MAX = 5;
|
|
||||||
private static final long GC_INTERVAL = DateUtils.SECOND_IN_MILLIS;
|
|
||||||
private static GCUtils sInstance = new GCUtils();
|
|
||||||
private int mGCTryCount = 0;
|
|
||||||
|
|
||||||
public static GCUtils getInstance() {
|
|
||||||
return sInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reset() {
|
|
||||||
mGCTryCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean tryGCOrWait(String metaData, Throwable t) {
|
|
||||||
if (mGCTryCount == 0) {
|
|
||||||
System.gc();
|
|
||||||
}
|
|
||||||
if (++mGCTryCount > GC_TRY_COUNT) {
|
|
||||||
LatinImeLogger.logOnException(metaData, t);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
Thread.sleep(GC_INTERVAL);
|
|
||||||
return true;
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Log.e(GC_TAG, "Sleep was interrupted.");
|
|
||||||
LatinImeLogger.logOnException(metaData, t);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* package */ static class RingCharBuffer {
|
/* package */ static class RingCharBuffer {
|
||||||
private static RingCharBuffer sRingCharBuffer = new RingCharBuffer();
|
private static RingCharBuffer sRingCharBuffer = new RingCharBuffer();
|
||||||
private static final char PLACEHOLDER_DELIMITER_CHAR = '\uFFFC';
|
private static final char PLACEHOLDER_DELIMITER_CHAR = '\uFFFC';
|
||||||
|
|
Loading…
Reference in a new issue