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

Bug: 5591245
Change-Id: I4ff61a59b0622c74b34bc50a00fc9773c04a6395
This commit is contained in:
satok
2012-05-11 18:37:39 +09:00
parent ee10ceccde
commit e508dc25f2
3 changed files with 18 additions and 3 deletions

View File

@@ -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>

View File

@@ -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();
}
}
});

View File

@@ -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();
}
}
}