Merge "[Physical Keyboard] Null check before using layout descriptor" into main
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);
|
||||
}
|
||||
}
|
||||
|
@@ -31,6 +31,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -48,10 +49,10 @@ public class NewKeyboardLayoutPickerFragment extends Fragment {
|
||||
mKeyboardLayoutSelectedCallback =
|
||||
new NewKeyboardLayoutPickerController.KeyboardLayoutSelectedCallback() {
|
||||
@Override
|
||||
public void onSelected(KeyboardLayout keyboardLayout) {
|
||||
public void onSelected(@Nullable KeyboardLayout keyboardLayout) {
|
||||
if (mInputManager != null
|
||||
&& mKeyboardLayoutPreview != null
|
||||
&& mKeyboardLayoutPreviewText != null && keyboardLayout != null) {
|
||||
&& mKeyboardLayoutPreviewText != null) {
|
||||
Drawable previewDrawable = mInputManager.getKeyboardLayoutPreview(
|
||||
keyboardLayout,
|
||||
DEFAULT_KEYBOARD_PREVIEW_WIDTH, DEFAULT_KEYBOARD_PREVIEW_HEIGHT);
|
||||
@@ -60,9 +61,12 @@ public class NewKeyboardLayoutPickerFragment extends Fragment {
|
||||
mKeyboardLayoutPreviewText.setVisibility(
|
||||
previewDrawable == null ? GONE : VISIBLE);
|
||||
if (previewDrawable != null) {
|
||||
mKeyboardLayoutPreviewText.setText(keyboardLayout.getLabel());
|
||||
mKeyboardLayoutPreview.setImageDrawable(previewDrawable);
|
||||
}
|
||||
mKeyboardLayoutPreviewText.setText(
|
||||
keyboardLayout != null ? keyboardLayout.getLabel()
|
||||
: requireContext().getString(
|
||||
R.string.keyboard_default_layout));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user