am b56f7d8c: Merge "Disable message if personalization is disabled."

* commit 'b56f7d8ca47e5936afe0459928bae49cae6e3615':
  Disable message if personalization is disabled.
This commit is contained in:
Chieu Nguyen 2015-03-18 22:42:23 +00:00 committed by Android Git Automerger
commit 56391ce7c7
5 changed files with 47 additions and 12 deletions

View file

@ -1450,7 +1450,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
final boolean shouldShowImportantNotice = final boolean shouldShowImportantNotice =
ImportantNoticeUtils.shouldShowImportantNotice(this); ImportantNoticeUtils.shouldShowImportantNotice(this, currentSettingsValues);
final boolean shouldShowSuggestionCandidates = final boolean shouldShowSuggestionCandidates =
currentSettingsValues.mInputAttributes.mShouldShowSuggestions currentSettingsValues.mInputAttributes.mShouldShowSuggestions
&& currentSettingsValues.isSuggestionsEnabledPerUserSettings(); && currentSettingsValues.isSuggestionsEnabledPerUserSettings();

View file

@ -237,6 +237,10 @@ public class SettingsValues {
return mSuggestionsEnabledPerUserSettings; return mSuggestionsEnabledPerUserSettings;
} }
public boolean isPersonalizationEnabled() {
return mUsePersonalizedDicts;
}
public boolean isWordSeparator(final int code) { public boolean isWordSeparator(final int code) {
return mSpacingAndPunctuations.isWordSeparator(code); return mSpacingAndPunctuations.isWordSeparator(code);
} }

View file

@ -213,7 +213,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
// it has been shown once already or not, and if in the setup wizard). If applicable, it shows // it has been shown once already or not, and if in the setup wizard). If applicable, it shows
// the notice. In all cases, it returns true if it was shown, false otherwise. // the notice. In all cases, it returns true if it was shown, false otherwise.
public boolean maybeShowImportantNoticeTitle() { public boolean maybeShowImportantNoticeTitle() {
if (!ImportantNoticeUtils.shouldShowImportantNotice(getContext())) { final SettingsValues currentSettingsValues = Settings.getInstance().getCurrent();
if (!ImportantNoticeUtils.shouldShowImportantNotice(getContext(), currentSettingsValues)) {
return false; return false;
} }
if (getWidth() <= 0) { if (getWidth() <= 0) {

View file

@ -25,6 +25,7 @@ import android.util.Log;
import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.settings.SettingsValues;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -105,7 +106,12 @@ public final class ImportantNoticeUtils {
return elapsedTime >= TIMEOUT_OF_IMPORTANT_NOTICE; return elapsedTime >= TIMEOUT_OF_IMPORTANT_NOTICE;
} }
public static boolean shouldShowImportantNotice(final Context context) { public static boolean shouldShowImportantNotice(final Context context,
final SettingsValues settingsValues) {
// Check to see whether personalization is enabled by the user.
if (!settingsValues.isPersonalizationEnabled()) {
return false;
}
if (!hasNewImportantNotice(context)) { if (!hasNewImportantNotice(context)) {
return false; return false;
} }

View file

@ -18,6 +18,7 @@ package com.android.inputmethod.latin.utils;
import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_IMPORTANT_NOTICE_VERSION; import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_IMPORTANT_NOTICE_VERSION;
import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE; import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE;
import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -25,6 +26,11 @@ import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.MediumTest;
import android.text.TextUtils; import android.text.TextUtils;
import com.android.inputmethod.latin.settings.SettingsValues;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@MediumTest @MediumTest
@ -34,6 +40,8 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
private ImportantNoticePreferences mImportantNoticePreferences; private ImportantNoticePreferences mImportantNoticePreferences;
@Mock private SettingsValues mMockSettingsValues;
private static class ImportantNoticePreferences { private static class ImportantNoticePreferences {
private final SharedPreferences mPref; private final SharedPreferences mPref;
@ -97,8 +105,10 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
MockitoAnnotations.initMocks(this);
mImportantNoticePreferences = new ImportantNoticePreferences(getContext()); mImportantNoticePreferences = new ImportantNoticePreferences(getContext());
mImportantNoticePreferences.save(); mImportantNoticePreferences.save();
when(mMockSettingsValues.isPersonalizationEnabled()).thenReturn(true);
} }
@Override @Override
@ -117,9 +127,9 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
// Check internal state of {@link ImportantNoticeUtils.shouldShowImportantNotice(Context)} // Check internal state of {@link ImportantNoticeUtils.shouldShowImportantNotice(Context)}
// after fresh install. // after fresh install.
assertEquals("Has new imortant notice after fresh install", true, assertEquals("Has new important notice after fresh install", true,
ImportantNoticeUtils.hasNewImportantNotice(getContext())); ImportantNoticeUtils.hasNewImportantNotice(getContext()));
assertEquals("Next important norice title after fresh install", false, TextUtils.isEmpty( assertEquals("Next important notice title after fresh install", false, TextUtils.isEmpty(
ImportantNoticeUtils.getNextImportantNoticeTitle(getContext()))); ImportantNoticeUtils.getNextImportantNoticeTitle(getContext())));
assertEquals("Is in system setup wizard after fresh install", false, assertEquals("Is in system setup wizard after fresh install", false,
ImportantNoticeUtils.isInSystemSetupWizard(getContext())); ImportantNoticeUtils.isInSystemSetupWizard(getContext()));
@ -131,14 +141,14 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE)); mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE));
assertEquals("Current boolean before update", true, assertEquals("Current boolean before update", true,
ImportantNoticeUtils.shouldShowImportantNotice(getContext())); ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
} }
public void testUpdateVersion() { public void testUpdateVersion() {
mImportantNoticePreferences.clear(); mImportantNoticePreferences.clear();
assertEquals("Current boolean before update", true, assertEquals("Current boolean before update", true,
ImportantNoticeUtils.shouldShowImportantNotice(getContext())); ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
assertEquals("Last version before update", 0, assertEquals("Last version before update", 0,
ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
assertEquals("Next version before update ", 1, assertEquals("Next version before update ", 1,
@ -151,7 +161,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
ImportantNoticeUtils.updateLastImportantNoticeVersion(getContext()); ImportantNoticeUtils.updateLastImportantNoticeVersion(getContext());
assertEquals("Current boolean after update", false, assertEquals("Current boolean after update", false,
ImportantNoticeUtils.shouldShowImportantNotice(getContext())); ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
assertEquals("Last version after update", 1, assertEquals("Last version after update", 1,
ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
assertEquals("Next version after update", 2, assertEquals("Next version after update", 2,
@ -180,7 +190,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
// Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} before timeout. // Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} before timeout.
assertEquals("Current boolean before timeout 1", true, assertEquals("Current boolean before timeout 1", true,
ImportantNoticeUtils.shouldShowImportantNotice(getContext())); ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
assertEquals("Last version before timeout 1", 0, assertEquals("Last version before timeout 1", 0,
ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
assertEquals("Next version before timeout 1", 1, assertEquals("Next version before timeout 1", 1,
@ -197,7 +207,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
// Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} before timeout // Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} before timeout
// again. // again.
assertEquals("Current boolean before timeout 2", true, assertEquals("Current boolean before timeout 2", true,
ImportantNoticeUtils.shouldShowImportantNotice(getContext())); ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
assertEquals("Last version before timeout 2", 0, assertEquals("Last version before timeout 2", 0,
ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
assertEquals("Next version before timeout 2", 1, assertEquals("Next version before timeout 2", 1,
@ -213,7 +223,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
// Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} after timeout. // Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} after timeout.
assertEquals("Current boolean after timeout 1", false, assertEquals("Current boolean after timeout 1", false,
ImportantNoticeUtils.shouldShowImportantNotice(getContext())); ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
assertEquals("Last version after timeout 1", 1, assertEquals("Last version after timeout 1", 1,
ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
assertEquals("Next version after timeout 1", 2, assertEquals("Next version after timeout 1", 2,
@ -229,7 +239,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
// Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} after timeout again. // Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} after timeout again.
assertEquals("Current boolean after timeout 2", false, assertEquals("Current boolean after timeout 2", false,
ImportantNoticeUtils.shouldShowImportantNotice(getContext())); ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
assertEquals("Last version after timeout 2", 1, assertEquals("Last version after timeout 2", 1,
ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
assertEquals("Next version after timeout 2", 2, assertEquals("Next version after timeout 2", 2,
@ -241,4 +251,18 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
assertEquals("Current contents after timeout 2", true, TextUtils.isEmpty( assertEquals("Current contents after timeout 2", true, TextUtils.isEmpty(
ImportantNoticeUtils.getNextImportantNoticeContents(getContext()))); ImportantNoticeUtils.getNextImportantNoticeContents(getContext())));
} }
public void testPersonalizationSetting() {
mImportantNoticePreferences.clear();
// Personalization enabled.
when(mMockSettingsValues.isPersonalizationEnabled()).thenReturn(true);
assertEquals("Current boolean with personalization enabled", true,
ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
// Personalization disabled.
when(mMockSettingsValues.isPersonalizationEnabled()).thenReturn(false);
assertEquals("Current boolean with personalization disabled", false,
ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
}
} }