[Physical Keyboard] Null check before using layout descriptor
If descriptor is null, pass null to LayoutSelectedCallback.onSelected to get default layout preview image. Bug: 396006944 Flag: com.android.settings.keyboard.keyboard_and_touchpad_a11y_new_page_enabled Test: atest packages/apps/Settings/tests/robotests/src/com/android/settings/inputmethod/ Change-Id: I6b454a5f0b95c571cac15258977aab5ee12d4327
This commit is contained in:
@@ -26,6 +26,7 @@ import android.os.Bundle;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -58,7 +59,7 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
||||
private PreferenceScreen mScreen;
|
||||
private String mPreviousSelection;
|
||||
private String mFinalSelectedLayoutDescriptor;
|
||||
private String mSelectedLayoutDescriptor;
|
||||
@Nullable private String mSelectedLayoutDescriptor;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private KeyboardLayoutSelectedCallback mKeyboardLayoutSelectedCallback;
|
||||
|
||||
@@ -186,7 +187,8 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
||||
pref = new TickButtonPreference(mScreen.getContext());
|
||||
pref.setTitle(layout.getLabel());
|
||||
|
||||
if (mSelectedLayoutDescriptor.equals(layout.getDescriptor())) {
|
||||
if (mSelectedLayoutDescriptor != null && mSelectedLayoutDescriptor.equals(
|
||||
layout.getDescriptor())) {
|
||||
if (mKeyboardLayoutSelectedCallback != null) {
|
||||
mKeyboardLayoutSelectedCallback.onSelected(layout);
|
||||
}
|
||||
@@ -197,6 +199,12 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
||||
mScreen.addPreference(pref);
|
||||
mPreferenceMap.put(pref, layout);
|
||||
}
|
||||
|
||||
if (mSelectedLayoutDescriptor == null && mKeyboardLayoutSelectedCallback != null) {
|
||||
// Pass null here since getKeyboardLayoutPreview() accept null layout, which will
|
||||
// return default preview image
|
||||
mKeyboardLayoutSelectedCallback.onSelected(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void setLayout(TickButtonPreference preference) {
|
||||
@@ -233,6 +241,6 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
||||
/**
|
||||
* Called when KeyboardLayout been selected.
|
||||
*/
|
||||
void onSelected(KeyboardLayout keyboardLayout);
|
||||
void onSelected(@Nullable KeyboardLayout keyboardLayout);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user