Merge "Support IMEs that have no subtype in PhysicalKeyboardFragment." into nyc-dev am: b156761ae8
am: c61d822f6e
* commit 'c61d822f6e781255ad850a0d2eaedfdef6335346':
Support IMEs that have no subtype in PhysicalKeyboardFragment.
Change-Id: I31da307279147ae6c48cbe8bae97b71ad9774ea0
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.inputmethod;
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
|
import android.annotation.Nullable;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.hardware.input.InputDeviceIdentifier;
|
import android.hardware.input.InputDeviceIdentifier;
|
||||||
import android.hardware.input.InputManager;
|
import android.hardware.input.InputManager;
|
||||||
@@ -45,6 +46,7 @@ public final class KeyboardLayoutPickerFragment2 extends SettingsPreferenceFragm
|
|||||||
private int mInputDeviceId = -1;
|
private int mInputDeviceId = -1;
|
||||||
private InputManager mIm;
|
private InputManager mIm;
|
||||||
private InputMethodInfo mImi;
|
private InputMethodInfo mImi;
|
||||||
|
@Nullable
|
||||||
private InputMethodSubtype mSubtype;
|
private InputMethodSubtype mSubtype;
|
||||||
private KeyboardLayout[] mKeyboardLayouts;
|
private KeyboardLayout[] mKeyboardLayouts;
|
||||||
private Map<Preference, KeyboardLayout> mPreferenceMap = new HashMap<>();
|
private Map<Preference, KeyboardLayout> mPreferenceMap = new HashMap<>();
|
||||||
@@ -82,7 +84,7 @@ public final class KeyboardLayoutPickerFragment2 extends SettingsPreferenceFragm
|
|||||||
mImi = activity.getIntent().getParcelableExtra(EXTRA_INPUT_METHOD_INFO);
|
mImi = activity.getIntent().getParcelableExtra(EXTRA_INPUT_METHOD_INFO);
|
||||||
mSubtype = activity.getIntent().getParcelableExtra(EXTRA_INPUT_METHOD_SUBTYPE);
|
mSubtype = activity.getIntent().getParcelableExtra(EXTRA_INPUT_METHOD_SUBTYPE);
|
||||||
|
|
||||||
if (mInputDeviceIdentifier == null || mImi == null || mSubtype == null) {
|
if (mInputDeviceIdentifier == null || mImi == null) {
|
||||||
activity.finish();
|
activity.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -147,7 +147,7 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
|||||||
Preference pref = new Preference(getPrefContext(), null);
|
Preference pref = new Preference(getPrefContext(), null);
|
||||||
final InputMethodInfo imi = info.mImi;
|
final InputMethodInfo imi = info.mImi;
|
||||||
final InputMethodSubtype imSubtype = info.mImSubtype;
|
final InputMethodSubtype imSubtype = info.mImSubtype;
|
||||||
if (imi != null && imSubtype != null) {
|
if (imi != null) {
|
||||||
pref.setTitle(getDisplayName(getContext(), imi, imSubtype));
|
pref.setTitle(getDisplayName(getContext(), imi, imSubtype));
|
||||||
KeyboardLayout layout = info.mLayout;
|
KeyboardLayout layout = info.mLayout;
|
||||||
if (layout != null) {
|
if (layout != null) {
|
||||||
@@ -214,9 +214,9 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showKeyboardLayoutScreen(
|
private void showKeyboardLayoutScreen(
|
||||||
InputDeviceIdentifier inputDeviceIdentifier,
|
@NonNull InputDeviceIdentifier inputDeviceIdentifier,
|
||||||
InputMethodInfo imi,
|
@NonNull InputMethodInfo imi,
|
||||||
InputMethodSubtype imSubtype) {
|
@Nullable InputMethodSubtype imSubtype) {
|
||||||
final Intent intent = new Intent(Intent.ACTION_MAIN);
|
final Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||||
intent.setClass(getActivity(), Settings.KeyboardLayoutPickerActivity.class);
|
intent.setClass(getActivity(), Settings.KeyboardLayoutPickerActivity.class);
|
||||||
intent.putExtra(KeyboardLayoutPickerFragment2.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
intent.putExtra(KeyboardLayoutPickerFragment2.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
||||||
@@ -272,12 +272,15 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
|||||||
};
|
};
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
static String getDisplayName(
|
static CharSequence getDisplayName(
|
||||||
@NonNull Context context, @NonNull InputMethodInfo imi,
|
@NonNull Context context, @NonNull InputMethodInfo imi,
|
||||||
@NonNull InputMethodSubtype imSubtype) {
|
@Nullable InputMethodSubtype imSubtype) {
|
||||||
|
final CharSequence imeName = imi.loadLabel(context.getPackageManager());
|
||||||
|
if (imSubtype == null) {
|
||||||
|
return imeName;
|
||||||
|
}
|
||||||
final CharSequence imSubtypeName = imSubtype.getDisplayName(
|
final CharSequence imSubtypeName = imSubtype.getDisplayName(
|
||||||
context, imi.getPackageName(), imi.getServiceInfo().applicationInfo);
|
context, imi.getPackageName(), imi.getServiceInfo().applicationInfo);
|
||||||
final CharSequence imeName = imi.loadLabel(context.getPackageManager());
|
|
||||||
return String.format(
|
return String.format(
|
||||||
context.getString(R.string.physical_device_title), imSubtypeName, imeName);
|
context.getString(R.string.physical_device_title), imSubtypeName, imeName);
|
||||||
}
|
}
|
||||||
@@ -330,8 +333,21 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
|||||||
final InputManager im = getContext().getSystemService(InputManager.class);
|
final InputManager im = getContext().getSystemService(InputManager.class);
|
||||||
if (imm != null && im != null) {
|
if (imm != null && im != null) {
|
||||||
for (InputMethodInfo imi : imm.getEnabledInputMethodList()) {
|
for (InputMethodInfo imi : imm.getEnabledInputMethodList()) {
|
||||||
for (InputMethodSubtype subtype : imm.getEnabledInputMethodSubtypeList(
|
final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(
|
||||||
imi, true /* allowsImplicitlySelectedSubtypes */)) {
|
imi, true /* allowsImplicitlySelectedSubtypes */);
|
||||||
|
if (subtypes.isEmpty()) {
|
||||||
|
// Here we use null to indicate that this IME has no subtype.
|
||||||
|
final InputMethodSubtype nullSubtype = null;
|
||||||
|
final KeyboardLayout layout = im.getKeyboardLayoutForInputDevice(
|
||||||
|
deviceInfo.mDeviceIdentifier, imi, nullSubtype);
|
||||||
|
keyboardInfoList.add(new Keyboards.KeyboardInfo(imi, nullSubtype, layout));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the IME supports subtypes, we pick up "keyboard" subtypes only.
|
||||||
|
final int N = subtypes.size();
|
||||||
|
for (int i = 0; i < N; ++i) {
|
||||||
|
final InputMethodSubtype subtype = subtypes.get(i);
|
||||||
if (!IM_SUBTYPE_MODE_KEYBOARD.equalsIgnoreCase(subtype.getMode())) {
|
if (!IM_SUBTYPE_MODE_KEYBOARD.equalsIgnoreCase(subtype.getMode())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -421,14 +437,14 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
|||||||
public static final class KeyboardInfo {
|
public static final class KeyboardInfo {
|
||||||
@NonNull
|
@NonNull
|
||||||
public final InputMethodInfo mImi;
|
public final InputMethodInfo mImi;
|
||||||
@NonNull
|
@Nullable
|
||||||
public final InputMethodSubtype mImSubtype;
|
public final InputMethodSubtype mImSubtype;
|
||||||
@NonNull
|
@NonNull
|
||||||
public final KeyboardLayout mLayout;
|
public final KeyboardLayout mLayout;
|
||||||
|
|
||||||
public KeyboardInfo(
|
public KeyboardInfo(
|
||||||
@NonNull final InputMethodInfo imi,
|
@NonNull final InputMethodInfo imi,
|
||||||
@NonNull final InputMethodSubtype imSubtype,
|
@Nullable final InputMethodSubtype imSubtype,
|
||||||
@NonNull final KeyboardLayout layout) {
|
@NonNull final KeyboardLayout layout) {
|
||||||
mImi = imi;
|
mImi = imi;
|
||||||
mImSubtype = imSubtype;
|
mImSubtype = imSubtype;
|
||||||
|
Reference in New Issue
Block a user