From e508dc25f2d3168f37fe5963fc99b0a034a3a298 Mon Sep 17 00:00:00 2001 From: satok Date: Fri, 11 May 2012 18:37:39 +0900 Subject: [PATCH] Fix the crash during opning the illegal settings of the spell checker Bug: 5591245 Change-Id: I4ff61a59b0622c74b34bc50a00fc9773c04a6395 --- res/values/strings.xml | 2 ++ .../settings/inputmethod/InputMethodPreference.java | 9 +++++++-- .../inputmethod/SingleSpellCheckerPreference.java | 10 +++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index f4e996cddc5..5890afbe613 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2633,6 +2633,8 @@ card numbers. It comes from the app %1$s. Use this spell checker? + + Failed to open settings for %1$s Mouse/trackpad diff --git a/src/com/android/settings/inputmethod/InputMethodPreference.java b/src/com/android/settings/inputmethod/InputMethodPreference.java index 6402dff47b9..c736b2f5d36 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.InputMethodManager; 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 @@ public class InputMethodPreference extends CheckBoxPreference 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 2a62017de42..5b28142e3f1 100644 --- a/src/com/android/settings/inputmethod/SingleSpellCheckerPreference.java +++ b/src/com/android/settings/inputmethod/SingleSpellCheckerPreference.java @@ -19,6 +19,7 @@ package com.android.settings.inputmethod; 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.view.textservice.TextServicesManager; 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 @@ public class SingleSpellCheckerPreference extends Preference { 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(); + } } }