Support versioned important notice

This change must be checked in together with If38a754d00.

Bug: 10587358
Change-Id: I91580f9468bc5ee7ed1694d7852a60dc6793dac0
diff --git a/java/res/values/strings-config-important-notice.xml b/java/res/values/strings-config-important-notice.xml
index 3be95d3..f2229be 100644
--- a/java/res/values/strings-config-important-notice.xml
+++ b/java/res/values/strings-config-important-notice.xml
@@ -20,11 +20,14 @@
 
 <resources>
     <integer name="config_important_notice_version">0</integer>
-    <!-- TODO: Make title and contents resource to string array indexed by version. -->
-    <!-- The text of the important notice displayed on the suggestion strip. -->
-    <string name="important_notice_title"></string>
-    <!-- The contents of the important notice. -->
-    <string name="important_notice_contents"></string>
+    <!-- The array of the text of the important notices displayed on the suggestion strip. -->
+    <string-array name="important_notice_title_array">
+        <!-- empty -->
+    </string-array>
+    <!-- The array of the contents of the important notices. -->
+    <string-array name="important_notice_contents_array">
+        <!-- empty -->
+    </string-array>
     <!-- Description for option enabling the use by the keyboards of sent/received messages, e-mail and typing history to improve suggestion accuracy [CHAR LIMIT=68] -->
     <string name="use_personalized_dicts_summary">Learn from your communications and typed data to improve suggestions</string>
 </resources>
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 47137e7..f2fa329 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1190,15 +1190,28 @@
                 new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_DARK);
         builder.setMessage(ImportantNoticeUtils.getNextImportantNoticeContents(context));
         builder.setPositiveButton(android.R.string.ok, null /* listener */);
+        final int nextVersion = ImportantNoticeUtils.getNextImportantNoticeVersion(context);
         final OnClickListener onClickListener = new OnClickListener() {
             @Override
             public void onClick(final DialogInterface dialog, final int position) {
-                if (position == DialogInterface.BUTTON_NEGATIVE) {
-                    launchSettings();
+                switch (nextVersion) {
+                case ImportantNoticeUtils.VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS:
+                    if (position == DialogInterface.BUTTON_NEGATIVE) {
+                        launchSettings();
+                    }
+                    break;
+                default:
+                    break;
                 }
             }
         };
-        builder.setNegativeButton(R.string.go_to_settings, onClickListener);
+        switch (nextVersion) {
+        case ImportantNoticeUtils.VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS:
+            builder.setNegativeButton(R.string.go_to_settings, onClickListener);
+            break;
+        default:
+            break;
+        }
         final AlertDialog importantNoticeDialog = builder.create();
         importantNoticeDialog.setOnShowListener(new OnShowListener() {
             @Override
diff --git a/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java b/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java
index 6b0bb86..ca8bef3 100644
--- a/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java
@@ -60,7 +60,7 @@
         return context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
     }
 
-    public static int getCurrentImportantNoticeVersion(final Context context) {
+    private static int getCurrentImportantNoticeVersion(final Context context) {
         return context.getResources().getInteger(R.integer.config_important_notice_version);
     }
 
@@ -68,7 +68,7 @@
         return getImportantNoticePreferences(context).getInt(KEY_IMPORTANT_NOTICE_VERSION, 0);
     }
 
-    private static int getNextImportantNoticeVersion(final Context context) {
+    public static int getNextImportantNoticeVersion(final Context context) {
         return getLastImportantNoticeVersion(context) + 1;
     }
 
@@ -92,23 +92,23 @@
                 .apply();
     }
 
-    // TODO: Make title resource to string array indexed by version.
     public static String getNextImportantNoticeTitle(final Context context) {
-        switch (getNextImportantNoticeVersion(context)) {
-        case VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS:
-            return context.getString(R.string.important_notice_title);
-        default:
-            return null;
+        final int nextVersion = getCurrentImportantNoticeVersion(context);
+        final String[] importantNoticeTitleArray = context.getResources().getStringArray(
+                R.array.important_notice_title_array);
+        if (nextVersion > 0 && nextVersion < importantNoticeTitleArray.length) {
+            return importantNoticeTitleArray[nextVersion];
         }
+        return null;
     }
 
-    // TODO: Make content resource to string array indexed by version.
     public static String getNextImportantNoticeContents(final Context context) {
-        switch (getNextImportantNoticeVersion(context)) {
-        case VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS:
-            return context.getString(R.string.important_notice_contents);
-        default:
-            return null;
+        final int nextVersion = getNextImportantNoticeVersion(context);
+        final String[] importantNoticeContentsArray = context.getResources().getStringArray(
+                R.array.important_notice_contents_array);
+        if (nextVersion > 0 && nextVersion < importantNoticeContentsArray.length) {
+            return importantNoticeContentsArray[nextVersion];
         }
+        return null;
     }
 }