]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryActivity.java
Another attempt to fix potential null dereference.
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryActivity.java
index 38c2ac9994c3f02ab6506ba8d1adb9390cc854ab..140de67c2a83bafe8e413871ee9db930242ea4b1 100644 (file)
@@ -389,8 +389,8 @@ public class DictionaryActivity extends ActionBarActivity {
                     for (final Index index : dictionary.indices) {
                         final String searchToken = index.sortedIndexEntries.get(0).token;
                         final IndexEntry entry = index.findExact(searchToken);
-                        if (!searchToken.equals(entry.token)) {
-                            Log.e(LOG, "Couldn't find token: " + searchToken + ", " + entry.token);
+                        if (entry == null || !searchToken.equals(entry.token)) {
+                            Log.e(LOG, "Couldn't find token: " + searchToken + ", " + (entry == null ? "null" : entry.token));
                         }
                     }
                     indexPrepFinished = true;
@@ -475,8 +475,6 @@ public class DictionaryActivity extends ActionBarActivity {
         
         final LinearLayout customSearchView = new LinearLayout(getSupportActionBar().getThemedContext());
         
-        final int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 300,
-                getResources().getDisplayMetrics());
         final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                 ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
         customSearchView.setLayoutParams(layoutParams);
@@ -669,7 +667,7 @@ public class DictionaryActivity extends ActionBarActivity {
         final Locale locale = new Locale(index.sortLanguage.getIsoCode());
         Log.d(LOG, "Setting TTS locale to: " + locale);
         final int ttsResult = textToSpeech.setLanguage(locale);
-        if (ttsResult != TextToSpeech.LANG_AVAILABLE ||
+        if (ttsResult != TextToSpeech.LANG_AVAILABLE &&
                 ttsResult != TextToSpeech.LANG_COUNTRY_AVAILABLE) {
             Log.e(LOG, "TTS not available in this language: ttsResult=" + ttsResult);
         }
@@ -1097,8 +1095,11 @@ public class DictionaryActivity extends ActionBarActivity {
         if (keyCode == KeyEvent.KEYCODE_ENTER) {
             Log.d(LOG, "Trying to hide soft keyboard.");
             final InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
-            inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),
-                    InputMethodManager.HIDE_NOT_ALWAYS);
+            View focus = getCurrentFocus();
+            if (focus != null) {
+                inputManager.hideSoftInputFromWindow(focus.getWindowToken(),
+                        InputMethodManager.HIDE_NOT_ALWAYS);
+            }
             return true;
         }
         return super.onKeyDown(keyCode, event);