fix potential NullPointerExceptions

This commit is contained in:
Philipp Crocoll
2018-08-28 05:39:28 +02:00
parent d13b2d236b
commit 5429876cde

View File

@@ -1395,6 +1395,8 @@ public class KP2AKeyboard extends InputMethodService
} }
private void updateKp2aKeyLabels() { private void updateKp2aKeyLabels() {
if ((mKeyboardSwitcher.getInputView() != null)
&& (mKeyboardSwitcher.getInputView().getKeyboard() != null))
for (Keyboard.Key key : mKeyboardSwitcher.getInputView().getKeyboard().getKeys()) { for (Keyboard.Key key : mKeyboardSwitcher.getInputView().getKeyboard().getKeys()) {
boolean isFirstKey = false; boolean isFirstKey = false;
@@ -1417,11 +1419,16 @@ public class KP2AKeyboard extends InputMethodService
} }
if (fieldIndex >= 0) if (fieldIndex >= 0)
{ {
String displayName = KeyboardData.availableFields.get(fieldIndex).displayName; String displayName = "";
if ("Password".equals(KeyboardData.availableFields.get(fieldIndex).key)) StringForTyping fieldData = KeyboardData.availableFields.get(fieldIndex);
displayName = getString(R.string.kp2a_password); //might be a shorter variant if (fieldData != null)
if ("UserName".equals(KeyboardData.availableFields.get(fieldIndex).key )) {
displayName = getString(R.string.kp2a_user); //might be a shorter variant displayName = fieldData.displayName;
if ("Password".equals(fieldData.key))
displayName = getString(R.string.kp2a_password); //might be a shorter variant
if ("UserName".equals(fieldData.key))
displayName = getString(R.string.kp2a_user); //might be a shorter variant
}
key.label = displayName; key.label = displayName;
} }
mKeyboardSwitcher.getInputView().invalidateAllKeys(); mKeyboardSwitcher.getInputView().invalidateAllKeys();