Fix the crash during opning the illegal settings of the spell checker

Bug: 5591245
Change-Id: I4ff61a59b0622c74b34bc50a00fc9773c04a6395
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f4e996c..5890afb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2633,6 +2633,8 @@
     card numbers.  It comes from the app
     <xliff:g id="spellchecker_application_name">%1$s</xliff:g>.
     Use this spell checker?</string>
+    <!-- Toast that settings for an application is failed to open. -->
+    <string name="failed_to_open_app_settings_toast">Failed to open settings for <xliff:g id="spell_application_name">%1$s</xliff:g></string>
 
     <!-- On Language & input settings screen, heading. Inside the "Language & input settings" screen, this is the header for settings that relate to mouse and trackpad devices. [CHAR LIMIT=40] -->
     <string name="pointer_settings_category">Mouse/trackpad</string>
diff --git a/src/com/android/settings/inputmethod/InputMethodPreference.java b/src/com/android/settings/inputmethod/InputMethodPreference.java
index 6402dff..c736b2f5 100644
--- a/src/com/android/settings/inputmethod/InputMethodPreference.java
+++ b/src/com/android/settings/inputmethod/InputMethodPreference.java
@@ -39,6 +39,7 @@
 import android.view.inputmethod.InputMethodSubtype;
 import android.widget.ImageView;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import java.util.Comparator;
 import java.util.List;
@@ -126,8 +127,12 @@
                                 mFragment.startActivity(mSettingsIntent);
                             } catch (ActivityNotFoundException e) {
                                 Log.d(TAG, "IME's Settings Activity Not Found: " + e);
-                                // If the IME's settings activity does not exist, we can just
-                                // do nothing...
+                                final String msg = mFragment.getString(
+                                        R.string.failed_to_open_app_settings_toast,
+                                        mImi.loadLabel(
+                                                mFragment.getActivity().getPackageManager()));
+                                Toast.makeText(
+                                        mFragment.getActivity(), msg, Toast.LENGTH_LONG).show();
                             }
                         }
                     });
diff --git a/src/com/android/settings/inputmethod/SingleSpellCheckerPreference.java b/src/com/android/settings/inputmethod/SingleSpellCheckerPreference.java
index 2a62017..5b28142 100644
--- a/src/com/android/settings/inputmethod/SingleSpellCheckerPreference.java
+++ b/src/com/android/settings/inputmethod/SingleSpellCheckerPreference.java
@@ -19,6 +19,7 @@
 import com.android.settings.R;
 
 import android.app.AlertDialog;
+import android.content.ActivityNotFoundException;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.res.Resources;
@@ -33,6 +34,7 @@
 import android.widget.ImageView;
 import android.widget.RadioButton;
 import android.widget.TextView;
+import android.widget.Toast;
 
 public class SingleSpellCheckerPreference extends Preference {
     private static final float DISABLED_ALPHA = 0.4f;
@@ -177,7 +179,13 @@
 
     private void onSettingsButtonClicked(View arg0) {
         if (mFragment != null && mSettingsIntent != null) {
-            mFragment.startActivity(mSettingsIntent);
+            try {
+                mFragment.startActivity(mSettingsIntent);
+            } catch (ActivityNotFoundException e) {
+                final String msg = mFragment.getString(R.string.failed_to_open_app_settings_toast,
+                        mSpellCheckerInfo.loadLabel(mFragment.getActivity().getPackageManager()));
+                Toast.makeText(mFragment.getActivity(), msg, Toast.LENGTH_LONG).show();
+            }
         }
     }