Fix NPE in AppearanceSettingsFragment
Bug: 18147440 Change-Id: I7a7a47b3484e54146d34d11b5bd9c1305421d829main
parent
d5455fea4a
commit
395009c03e
|
@ -305,6 +305,16 @@ public final class Constants {
|
||||||
public static final int SCREEN_METRICS_LARGE_TABLET = 2;
|
public static final int SCREEN_METRICS_LARGE_TABLET = 2;
|
||||||
public static final int SCREEN_METRICS_SMALL_TABLET = 3;
|
public static final int SCREEN_METRICS_SMALL_TABLET = 3;
|
||||||
|
|
||||||
|
public static boolean isPhone(final int screenMetrics) {
|
||||||
|
return screenMetrics == SCREEN_METRICS_SMALL_PHONE
|
||||||
|
|| screenMetrics == SCREEN_METRICS_LARGE_PHONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isTablet(final int screenMetrics) {
|
||||||
|
return screenMetrics == SCREEN_METRICS_SMALL_TABLET
|
||||||
|
|| screenMetrics == SCREEN_METRICS_LARGE_TABLET;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default capacity of gesture points container.
|
* Default capacity of gesture points container.
|
||||||
* This constant is used by {@link com.android.inputmethod.keyboard.internal.BatchInputArbiter}
|
* This constant is used by {@link com.android.inputmethod.keyboard.internal.BatchInputArbiter}
|
||||||
|
|
|
@ -19,9 +19,9 @@ package com.android.inputmethod.latin.settings;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
|
import com.android.inputmethod.latin.common.Constants;
|
||||||
import com.android.inputmethod.latin.define.ProductionFlags;
|
import com.android.inputmethod.latin.define.ProductionFlags;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Appearance" settings sub screen.
|
* "Appearance" settings sub screen.
|
||||||
*/
|
*/
|
||||||
|
@ -30,8 +30,8 @@ public final class AppearanceSettingsFragment extends SubScreenFragment {
|
||||||
public void onCreate(final Bundle icicle) {
|
public void onCreate(final Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
addPreferencesFromResource(R.xml.prefs_screen_appearance);
|
addPreferencesFromResource(R.xml.prefs_screen_appearance);
|
||||||
if (!ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED
|
if (!ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED ||
|
||||||
|| !Settings.getInstance().getCurrent().isTablet()) {
|
Constants.isPhone(Settings.readScreenMetrics(getResources()))) {
|
||||||
removePreference(Settings.PREF_ENABLE_SPLIT_KEYBOARD);
|
removePreference(Settings.PREF_ENABLE_SPLIT_KEYBOARD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,6 +213,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||||
return mSettingsValues.mBlockPotentiallyOffensive;
|
return mSettingsValues.mBlockPotentiallyOffensive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int readScreenMetrics(final Resources res) {
|
||||||
|
return res.getInteger(R.integer.config_screen_metrics);
|
||||||
|
}
|
||||||
|
|
||||||
// Accessed from the settings interface, hence public
|
// Accessed from the settings interface, hence public
|
||||||
public static boolean readKeypressSoundEnabled(final SharedPreferences prefs,
|
public static boolean readKeypressSoundEnabled(final SharedPreferences prefs,
|
||||||
final Resources res) {
|
final Resources res) {
|
||||||
|
|
|
@ -29,7 +29,6 @@ import com.android.inputmethod.latin.InputAttributes;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.RichInputMethodManager;
|
import com.android.inputmethod.latin.RichInputMethodManager;
|
||||||
import com.android.inputmethod.latin.SubtypeSwitcher;
|
import com.android.inputmethod.latin.SubtypeSwitcher;
|
||||||
import com.android.inputmethod.latin.common.Constants;
|
|
||||||
import com.android.inputmethod.latin.utils.AsyncResultHolder;
|
import com.android.inputmethod.latin.utils.AsyncResultHolder;
|
||||||
import com.android.inputmethod.latin.utils.ResourceUtils;
|
import com.android.inputmethod.latin.utils.ResourceUtils;
|
||||||
import com.android.inputmethod.latin.utils.TargetPackageInfoGetterTask;
|
import com.android.inputmethod.latin.utils.TargetPackageInfoGetterTask;
|
||||||
|
@ -158,7 +157,7 @@ public class SettingsValues {
|
||||||
mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration());
|
mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration());
|
||||||
mEnableMetricsLogging = prefs.getBoolean(Settings.PREF_ENABLE_METRICS_LOGGING, true);
|
mEnableMetricsLogging = prefs.getBoolean(Settings.PREF_ENABLE_METRICS_LOGGING, true);
|
||||||
mIsSplitKeyboardEnabled = prefs.getBoolean(Settings.PREF_ENABLE_SPLIT_KEYBOARD, false);
|
mIsSplitKeyboardEnabled = prefs.getBoolean(Settings.PREF_ENABLE_SPLIT_KEYBOARD, false);
|
||||||
mScreenMetrics = res.getInteger(R.integer.config_screen_metrics);
|
mScreenMetrics = Settings.readScreenMetrics(res);
|
||||||
|
|
||||||
mShouldShowLxxSuggestionUi = Settings.SHOULD_SHOW_LXX_SUGGESTION_UI
|
mShouldShowLxxSuggestionUi = Settings.SHOULD_SHOW_LXX_SUGGESTION_UI
|
||||||
&& prefs.getBoolean(DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI, true);
|
&& prefs.getBoolean(DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI, true);
|
||||||
|
@ -224,11 +223,6 @@ public class SettingsValues {
|
||||||
return mEnableMetricsLogging;
|
return mEnableMetricsLogging;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTablet() {
|
|
||||||
return mScreenMetrics == Constants.SCREEN_METRICS_SMALL_TABLET
|
|
||||||
|| mScreenMetrics == Constants.SCREEN_METRICS_LARGE_TABLET;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isApplicationSpecifiedCompletionsOn() {
|
public boolean isApplicationSpecifiedCompletionsOn() {
|
||||||
return mInputAttributes.mApplicationSpecifiedCompletionOn;
|
return mInputAttributes.mApplicationSpecifiedCompletionOn;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
||||||
setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId));
|
setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId));
|
||||||
KeyboardLayoutSet.onKeyboardThemeChanged();
|
KeyboardLayoutSet.onKeyboardThemeChanged();
|
||||||
|
|
||||||
mScreenMetrics = res.getInteger(R.integer.config_screen_metrics);
|
mScreenMetrics = Settings.readScreenMetrics(res);
|
||||||
RichInputMethodManager.init(context);
|
RichInputMethodManager.init(context);
|
||||||
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
||||||
|
|
||||||
|
@ -121,8 +121,7 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean isPhone() {
|
protected final boolean isPhone() {
|
||||||
return mScreenMetrics == Constants.SCREEN_METRICS_SMALL_PHONE
|
return Constants.isPhone(mScreenMetrics);
|
||||||
|| mScreenMetrics == Constants.SCREEN_METRICS_LARGE_PHONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final InputMethodSubtype getSubtype(final Locale locale,
|
protected final InputMethodSubtype getSubtype(final Locale locale,
|
||||||
|
|
|
@ -20,7 +20,6 @@ import android.content.res.Resources;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.R;
|
|
||||||
import com.android.inputmethod.latin.SuggestedWords;
|
import com.android.inputmethod.latin.SuggestedWords;
|
||||||
import com.android.inputmethod.latin.common.Constants;
|
import com.android.inputmethod.latin.common.Constants;
|
||||||
import com.android.inputmethod.latin.utils.RunInLocale;
|
import com.android.inputmethod.latin.utils.RunInLocale;
|
||||||
|
@ -37,13 +36,11 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
|
||||||
private int mScreenMetrics;
|
private int mScreenMetrics;
|
||||||
|
|
||||||
private boolean isPhone() {
|
private boolean isPhone() {
|
||||||
return mScreenMetrics == Constants.SCREEN_METRICS_SMALL_PHONE
|
return Constants.isPhone(mScreenMetrics);
|
||||||
|| mScreenMetrics == Constants.SCREEN_METRICS_LARGE_PHONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isTablet() {
|
private boolean isTablet() {
|
||||||
return mScreenMetrics == Constants.SCREEN_METRICS_SMALL_TABLET
|
return Constants.isTablet(mScreenMetrics);
|
||||||
|| mScreenMetrics == Constants.SCREEN_METRICS_LARGE_TABLET;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private SpacingAndPunctuations ENGLISH;
|
private SpacingAndPunctuations ENGLISH;
|
||||||
|
@ -70,7 +67,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
mScreenMetrics = mContext.getResources().getInteger(R.integer.config_screen_metrics);
|
mScreenMetrics = Settings.readScreenMetrics(getContext().getResources());
|
||||||
|
|
||||||
// Language only
|
// Language only
|
||||||
ENGLISH = getSpacingAndPunctuations(Locale.ENGLISH);
|
ENGLISH = getSpacingAndPunctuations(Locale.ENGLISH);
|
||||||
|
|
Loading…
Reference in New Issue