fixed nullability crash in keyboard shortcut settings

This commit is contained in:
Mariotaku Lee 2017-08-13 16:19:31 +08:00
parent 54fcde9270
commit 6da2717a3b
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
2 changed files with 5 additions and 4 deletions

View File

@ -307,11 +307,12 @@ public class KeyboardShortcutsHandler implements KeyboardShortcutConstants {
public static final class KeyboardShortcutSpec {
private String action;
@Nullable
private String contextTag;
private int keyMeta;
private String keyName;
public KeyboardShortcutSpec(String contextTag, int keyMeta, String keyName, String action) {
public KeyboardShortcutSpec(@Nullable String contextTag, int keyMeta, String keyName, String action) {
this.contextTag = contextTag;
this.keyMeta = keyMeta;
this.keyName = keyName;
@ -340,11 +341,12 @@ public class KeyboardShortcutsHandler implements KeyboardShortcutConstants {
return action;
}
@Nullable
public String getContextTag() {
return contextTag;
}
public void setContextTag(String contextTag) {
public void setContextTag(@Nullable String contextTag) {
this.contextTag = contextTag;
}

View File

@ -31,7 +31,7 @@ class KeyboardShortcutPreference(context: Context, attrs: AttributeSet? = null)
private val preferencesChangeListener: SharedPreferences.OnSharedPreferenceChangeListener
val contextTag: String
val contextTag: String?
val action: String
@Inject
@ -42,7 +42,6 @@ class KeyboardShortcutPreference(context: Context, attrs: AttributeSet? = null)
val a = context.obtainStyledAttributes(attrs, R.styleable.KeyboardShortcutPreference)
contextTag = a.getString(R.styleable.KeyboardShortcutPreference_android_tag)
action = a.getString(R.styleable.KeyboardShortcutPreference_android_action)
.takeUnless(String::isNullOrEmpty) ?: throw IllegalArgumentException("android:action required")
a.recycle()
key = action