Merge "[ZF2] Read settings for profanity filtering."
diff --git a/java/res/values/config.xml b/java/res/values/config.xml
index f2e76bd..5b11e07 100644
--- a/java/res/values/config.xml
+++ b/java/res/values/config.xml
@@ -75,6 +75,7 @@
     <!-- Showing more keys keyboard, just above the touched point if true, aligned to the key if
          false -->
     <bool name="config_show_more_keys_keyboard_at_touched_point">false</bool>
+    <bool name="config_block_potentially_offensive">true</bool>
     <integer name="config_gesture_floating_preview_text_linger_timeout">200</integer>
     <integer name="config_gesture_preview_trail_fadeout_start_delay">100</integer>
     <integer name="config_gesture_preview_trail_fadeout_duration">800</integer>
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 03f7d1c..c8c7bb4 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -139,6 +139,8 @@
                 inputSize, 0 /* commitPoint */, isGesture, prevWordCodePointArray,
                 mUseFullEditDistance, mOutputCodePoints, mOutputScores, mSpaceIndices,
                 mOutputTypes);
+        final boolean blockPotentiallyOffensive =
+                Settings.getInstance().getBlockPotentiallyOffensive();
         final ArrayList<SuggestedWordInfo> suggestions = CollectionUtils.newArrayList();
         for (int j = 0; j < count; ++j) {
             final int start = j * MAX_WORD_LENGTH;
@@ -148,10 +150,11 @@
             }
             if (len > 0) {
                 final int flags = mOutputTypes[j] & SuggestedWordInfo.KIND_MASK_FLAGS;
-                if (0 != (flags & SuggestedWordInfo.KIND_FLAG_POSSIBLY_OFFENSIVE)
+                if (blockPotentiallyOffensive
+                        && 0 != (flags & SuggestedWordInfo.KIND_FLAG_POSSIBLY_OFFENSIVE)
                         && 0 == (flags & SuggestedWordInfo.KIND_FLAG_EXACT_MATCH)) {
-                    // If the word is possibly offensive, we don't output it unless it's also
-                    // an exact match.
+                    // If we block potentially offensive words, and if the word is possibly
+                    // offensive, then we don't output it unless it's also an exact match.
                     continue;
                 }
                 final int kind = mOutputTypes[j] & SuggestedWordInfo.KIND_MASK_KIND;
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index 22ec015..9fefb58 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -47,6 +47,8 @@
     public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict";
     public static final String PREF_KEY_USE_DOUBLE_SPACE_PERIOD =
             "pref_key_use_double_space_period";
+    public static final String PREF_BLOCK_POTENTIALLY_OFFENSIVE =
+            "pref_key_block_potentially_offensive";
     public static final String PREF_SHOW_LANGUAGE_SWITCH_KEY =
             "pref_show_language_switch_key";
     public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST =
@@ -144,6 +146,10 @@
         return mCurrentLocale;
     }
 
+    public boolean getBlockPotentiallyOffensive() {
+        return mSettingsValues.mBlockPotentiallyOffensive;
+    }
+
     // Accessed from the settings interface, hence public
     public static boolean readKeypressSoundEnabled(final SharedPreferences prefs,
             final Resources res) {
@@ -165,6 +171,12 @@
         return !currentAutoCorrectionSetting.equals(autoCorrectionOff);
     }
 
+    public static boolean readBlockPotentiallyOffensive(final SharedPreferences prefs,
+            final Resources res) {
+        return prefs.getBoolean(Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE,
+                res.getBoolean(R.bool.config_block_potentially_offensive));
+    }
+
     public static boolean readFromBuildConfigIfGestureInputEnabled(final Resources res) {
         return res.getBoolean(R.bool.config_gesture_input_enabled_by_build_config);
     }
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index 838863c..615b2df 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -57,6 +57,7 @@
     public final boolean mShowsLanguageSwitchKey;
     public final boolean mUseContactsDict;
     public final boolean mUseDoubleSpacePeriod;
+    public final boolean mBlockPotentiallyOffensive;
     // Use bigrams to predict the next word when there is no input for it yet
     public final boolean mBigramPredictionEnabled;
     public final boolean mGestureInputEnabled;
@@ -126,6 +127,7 @@
         mShowsLanguageSwitchKey = Settings.readShowsLanguageSwitchKey(prefs);
         mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
         mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true);
+        mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res);
         mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res);
         mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res);