Integrate UI with APIs for physical keyboard settgins.
Integrate UI with these APIs. 1. getKeyboardLayoutListForInputDevice 2. getKeyboardLayoutForInputDevice 3. setKeyboardLayoutForInputDevice Demo: go/pk_with_final_api_demo Bug: 247079681 Test: local test Change-Id: I5478e2c344a47e692e7c524f8c1e96d9dda52796
This commit is contained in:
@@ -3713,6 +3713,8 @@
|
|||||||
<string name="language_and_input_for_work_category_title">Work profile keyboards & tools</string>
|
<string name="language_and_input_for_work_category_title">Work profile keyboards & tools</string>
|
||||||
<!-- Title for the 'Virtual keyboards for work' preference. [CHAR LIMIT=45] -->
|
<!-- Title for the 'Virtual keyboards for work' preference. [CHAR LIMIT=45] -->
|
||||||
<string name="virtual_keyboards_for_work_title">On-screen keyboard for work</string>
|
<string name="virtual_keyboards_for_work_title">On-screen keyboard for work</string>
|
||||||
|
<!-- Summary text for none selected keyboard default layout -->
|
||||||
|
<string name="keyboard_default_layout">Default</string>
|
||||||
|
|
||||||
<!-- Title for the button to trigger the 'trackpad settings' page if only connect with a touchpad. [CHAR LIMIT=35] -->
|
<!-- Title for the button to trigger the 'trackpad settings' page if only connect with a touchpad. [CHAR LIMIT=35] -->
|
||||||
<string name="trackpad_settings">Touchpad</string>
|
<string name="trackpad_settings">Touchpad</string>
|
||||||
|
@@ -16,8 +16,5 @@
|
|||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:title="@string/physical_keyboard_title">
|
android:title="@string/physical_keyboard_title">
|
||||||
<PreferenceCategory
|
|
||||||
android:key="enabled_locales_keyboard_layout"
|
|
||||||
android:title="@string/enabled_locales_keyboard_layout">
|
|
||||||
</PreferenceCategory>
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
@@ -20,64 +20,124 @@ import android.app.settings.SettingsEnums;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.hardware.input.InputDeviceIdentifier;
|
import android.hardware.input.InputDeviceIdentifier;
|
||||||
import android.hardware.input.InputManager;
|
import android.hardware.input.InputManager;
|
||||||
|
import android.hardware.input.KeyboardLayout;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.inputmethod.NewKeyboardSettingsUtils.KeyboardInfo;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
||||||
implements InputManager.InputDeviceListener {
|
implements InputManager.InputDeviceListener {
|
||||||
|
|
||||||
private static final String TAG = "NewKeyboardLayoutEnabledLocalesFragment";
|
private static final String TAG = "NewKeyboardLayoutEnabledLocalesFragment";
|
||||||
private static final String PREF_KEY_ENABLED_LOCALES = "enabled_locales_keyboard_layout";
|
|
||||||
|
|
||||||
static final String EXTRA_KEYBOARD_DEVICE_NAME = "extra_keyboard_device_name";
|
|
||||||
|
|
||||||
private InputManager mIm;
|
private InputManager mIm;
|
||||||
|
private InputMethodManager mImm;
|
||||||
private InputDeviceIdentifier mInputDeviceIdentifier;
|
private InputDeviceIdentifier mInputDeviceIdentifier;
|
||||||
|
private int mUserId;
|
||||||
private int mInputDeviceId;
|
private int mInputDeviceId;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private Map<String, KeyboardInfo> mKeyboardLanguageLayouts = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(final Bundle icicle) {
|
public void onActivityCreated(final Bundle icicle) {
|
||||||
super.onActivityCreated(icicle);
|
super.onActivityCreated(icicle);
|
||||||
|
|
||||||
Bundle arguments = getArguments();
|
Bundle arguments = getArguments();
|
||||||
final String title = arguments.getString(EXTRA_KEYBOARD_DEVICE_NAME);
|
final String title =
|
||||||
mInputDeviceIdentifier = arguments.getParcelable(
|
arguments.getString(NewKeyboardSettingsUtils.EXTRA_KEYBOARD_DEVICE_NAME);
|
||||||
KeyboardLayoutPickerFragment.EXTRA_INPUT_DEVICE_IDENTIFIER);
|
mInputDeviceIdentifier =
|
||||||
|
arguments.getParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_DEVICE_IDENTIFIER);
|
||||||
getActivity().setTitle(title);
|
getActivity().setTitle(title);
|
||||||
final PreferenceCategory category = findPreference(PREF_KEY_ENABLED_LOCALES);
|
updateCheckedState();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(b/252816846): Need APIs to get the available keyboards from Inputmanager.
|
private void updateCheckedState() {
|
||||||
// For example: InputMethodManager.getEnabledInputMethodLocales()
|
PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||||
// InputManager.getKeyboardLayoutForLocale()
|
preferenceScreen.removeAll();
|
||||||
// Hardcode the default value for demo purpose
|
List<InputMethodInfo> infoList = mImm.getEnabledInputMethodListAsUser(mUserId);
|
||||||
String[] keyboardLanguages = {"English (US)", "German (Germany)", "Spanish (Spain)"};
|
for (InputMethodInfo info : infoList) {
|
||||||
String[] keyboardLayouts = {"English (US)", "German", "Spanish"};
|
mKeyboardLanguageLayouts.clear();
|
||||||
for (int i = 0; i < keyboardLanguages.length; i++) {
|
List<InputMethodSubtype> subtypes =
|
||||||
|
mImm.getEnabledInputMethodSubtypeList(info, true);
|
||||||
|
for (InputMethodSubtype subtype : subtypes) {
|
||||||
|
if (subtype.isSuitableForPhysicalKeyboardLayoutMapping()) {
|
||||||
|
mapLanguageWithLayout(info, subtype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updatePreferenceLayout(preferenceScreen, info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mapLanguageWithLayout(InputMethodInfo info, InputMethodSubtype subtype) {
|
||||||
|
KeyboardLayout[] keyboardLayouts = getKeyboardLayouts(info, subtype);
|
||||||
|
String layout = getKeyboardLayout(info, subtype);
|
||||||
|
String language = getLanguage(info, subtype);
|
||||||
|
if (layout != null) {
|
||||||
|
for (int i = 0; i < keyboardLayouts.length; i++) {
|
||||||
|
if (keyboardLayouts[i].getDescriptor().equals(layout)) {
|
||||||
|
KeyboardInfo keyboardInfo = new KeyboardInfo(
|
||||||
|
language,
|
||||||
|
keyboardLayouts[i].getLabel(),
|
||||||
|
info,
|
||||||
|
subtype);
|
||||||
|
mKeyboardLanguageLayouts.put(subtype.getLanguageTag(), keyboardInfo);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if there is no auto-selected layout, we should show "Default"
|
||||||
|
KeyboardInfo keyboardInfo = new KeyboardInfo(
|
||||||
|
language,
|
||||||
|
mContext.getString(R.string.keyboard_default_layout),
|
||||||
|
info,
|
||||||
|
subtype);
|
||||||
|
mKeyboardLanguageLayouts.put(subtype.getLanguageTag(), keyboardInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePreferenceLayout(PreferenceScreen preferenceScreen, InputMethodInfo info) {
|
||||||
|
if (mKeyboardLanguageLayouts.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PreferenceCategory preferenceCategory = new PreferenceCategory(mContext);
|
||||||
|
preferenceCategory.setTitle(info.loadLabel(mContext.getPackageManager()).toString());
|
||||||
|
preferenceCategory.setKey(info.getPackageName());
|
||||||
|
preferenceScreen.addPreference(preferenceCategory);
|
||||||
|
for (Map.Entry<String, KeyboardInfo> entry : mKeyboardLanguageLayouts.entrySet()) {
|
||||||
final Preference pref = new Preference(mContext);
|
final Preference pref = new Preference(mContext);
|
||||||
String key = "keyboard_language_label_" + String.valueOf(i);
|
String key = "keyboard_language_" + entry.getKey();
|
||||||
String keyboardLanguageTitle = keyboardLanguages[i];
|
NewKeyboardSettingsUtils.KeyboardInfo keyboardInfo = entry.getValue();
|
||||||
String keyboardLanguageSummary = keyboardLayouts[i];
|
|
||||||
// TODO: Waiting for new API to use a prefix with special number to setKey
|
|
||||||
pref.setKey(key);
|
pref.setKey(key);
|
||||||
pref.setTitle(keyboardLanguageTitle);
|
pref.setTitle(keyboardInfo.getLanguage());
|
||||||
pref.setSummary(keyboardLanguageSummary);
|
pref.setSummary(keyboardInfo.getLayout());
|
||||||
pref.setOnPreferenceClickListener(
|
pref.setOnPreferenceClickListener(
|
||||||
preference -> {
|
preference -> {
|
||||||
showKeyboardLayoutPicker(
|
showKeyboardLayoutPicker(
|
||||||
keyboardLanguageTitle,
|
keyboardInfo.getLanguage(),
|
||||||
keyboardLanguageSummary,
|
keyboardInfo.getLayout(),
|
||||||
mInputDeviceIdentifier);
|
mInputDeviceIdentifier,
|
||||||
|
mUserId,
|
||||||
|
keyboardInfo.getInputMethodInfo(),
|
||||||
|
keyboardInfo.getInputMethodSubtype());
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
category.addPreference(pref);
|
preferenceCategory.addPreference(pref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +156,7 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onInputDeviceChanged(int deviceId) {
|
public void onInputDeviceChanged(int deviceId) {
|
||||||
if (mInputDeviceId >= 0 && deviceId == mInputDeviceId) {
|
if (mInputDeviceId >= 0 && deviceId == mInputDeviceId) {
|
||||||
// TODO(b/252816846): Need APIs to update the available keyboards.
|
updateCheckedState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +165,9 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mContext = getContext();
|
mContext = getContext();
|
||||||
mIm = mContext.getSystemService(InputManager.class);
|
mIm = mContext.getSystemService(InputManager.class);
|
||||||
|
mImm = mContext.getSystemService(InputMethodManager.class);
|
||||||
mInputDeviceId = -1;
|
mInputDeviceId = -1;
|
||||||
|
mUserId = UserHandle.myUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -131,7 +193,7 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
// TODO(b/252816846): Need APIs to get the available keyboards from Inputmanager.
|
updateCheckedState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -149,17 +211,50 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
|||||||
return R.xml.keyboard_settings_enabled_locales_list;
|
return R.xml.keyboard_settings_enabled_locales_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showKeyboardLayoutPicker(String language, String layout,
|
private void showKeyboardLayoutPicker(
|
||||||
InputDeviceIdentifier inputDeviceIdentifier) {
|
String language,
|
||||||
|
String layout,
|
||||||
|
InputDeviceIdentifier inputDeviceIdentifier,
|
||||||
|
int userId,
|
||||||
|
InputMethodInfo inputMethodInfo,
|
||||||
|
InputMethodSubtype inputMethodSubtype) {
|
||||||
Bundle arguments = new Bundle();
|
Bundle arguments = new Bundle();
|
||||||
arguments.putParcelable(KeyboardLayoutPickerFragment.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
arguments.putParcelable(
|
||||||
inputDeviceIdentifier);
|
NewKeyboardSettingsUtils.EXTRA_INPUT_DEVICE_IDENTIFIER, inputDeviceIdentifier);
|
||||||
arguments.putString(NewKeyboardLayoutPickerFragment.EXTRA_TITLE, language);
|
arguments.putParcelable(
|
||||||
arguments.putString(NewKeyboardLayoutPickerFragment.EXTRA_KEYBOARD_LAYOUT, layout);
|
NewKeyboardSettingsUtils.EXTRA_INPUT_METHOD_INFO, inputMethodInfo);
|
||||||
|
arguments.putParcelable(
|
||||||
|
NewKeyboardSettingsUtils.EXTRA_INPUT_METHOD_SUBTYPE, inputMethodSubtype);
|
||||||
|
arguments.putInt(NewKeyboardSettingsUtils.EXTRA_USER_ID, userId);
|
||||||
|
arguments.putString(NewKeyboardSettingsUtils.EXTRA_TITLE, language);
|
||||||
|
arguments.putString(NewKeyboardSettingsUtils.EXTRA_KEYBOARD_LAYOUT, layout);
|
||||||
new SubSettingLauncher(mContext)
|
new SubSettingLauncher(mContext)
|
||||||
.setSourceMetricsCategory(getMetricsCategory())
|
.setSourceMetricsCategory(getMetricsCategory())
|
||||||
.setDestination(NewKeyboardLayoutPickerFragment.class.getName())
|
.setDestination(NewKeyboardLayoutPickerFragment.class.getName())
|
||||||
.setArguments(arguments)
|
.setArguments(arguments)
|
||||||
.launch();
|
.launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private KeyboardLayout[] getKeyboardLayouts(InputMethodInfo info, InputMethodSubtype subtype) {
|
||||||
|
return mIm.getKeyboardLayoutListForInputDevice(
|
||||||
|
mInputDeviceIdentifier, mUserId, info, subtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getKeyboardLayout(InputMethodInfo info, InputMethodSubtype subtype) {
|
||||||
|
return mIm.getKeyboardLayoutForInputDevice(
|
||||||
|
mInputDeviceIdentifier, mUserId, info, subtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getLanguage(InputMethodInfo info, InputMethodSubtype subtype) {
|
||||||
|
String language;
|
||||||
|
if (subtype.getLanguageTag().isEmpty()) {
|
||||||
|
language = subtype.getDisplayName(
|
||||||
|
mContext,
|
||||||
|
info.getPackageName(),
|
||||||
|
info.getServiceInfo().applicationInfo).toString();
|
||||||
|
} else {
|
||||||
|
language = Locale.forLanguageTag(subtype.getLanguageTag()).getDisplayName();
|
||||||
|
}
|
||||||
|
return language;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,8 @@ import android.app.settings.SettingsEnums;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.hardware.input.InputDeviceIdentifier;
|
import android.hardware.input.InputDeviceIdentifier;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
@@ -28,31 +30,28 @@ public class NewKeyboardLayoutPickerContent extends DashboardFragment {
|
|||||||
|
|
||||||
private static final String TAG = "KeyboardLayoutPicker";
|
private static final String TAG = "KeyboardLayoutPicker";
|
||||||
|
|
||||||
static final String EXTRA_TITLE = "keyboard_layout_picker_title";
|
|
||||||
static final String EXTRA_KEYBOARD_LAYOUT = "keyboard_layout";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Intent extra: The input device descriptor of the keyboard whose keyboard
|
|
||||||
* layout is to be changed.
|
|
||||||
*/
|
|
||||||
public static final String EXTRA_INPUT_DEVICE_IDENTIFIER = "input_device_identifier";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
|
|
||||||
Bundle arguments = getArguments();
|
Bundle arguments = getArguments();
|
||||||
final String title = arguments.getString(EXTRA_TITLE);
|
final String title = arguments.getString(NewKeyboardSettingsUtils.EXTRA_TITLE);
|
||||||
final String layout = arguments.getString(EXTRA_KEYBOARD_LAYOUT);
|
final String layout = arguments.getString(NewKeyboardSettingsUtils.EXTRA_KEYBOARD_LAYOUT);
|
||||||
|
final int userId = arguments.getInt(NewKeyboardSettingsUtils.EXTRA_USER_ID);
|
||||||
final InputDeviceIdentifier inputDeviceIdentifier =
|
final InputDeviceIdentifier inputDeviceIdentifier =
|
||||||
arguments.getParcelable(EXTRA_INPUT_DEVICE_IDENTIFIER);
|
arguments.getParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_DEVICE_IDENTIFIER);
|
||||||
|
final InputMethodInfo inputMethodInfo =
|
||||||
|
arguments.getParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_METHOD_INFO);
|
||||||
|
final InputMethodSubtype inputMethodSubtype =
|
||||||
|
arguments.getParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_METHOD_SUBTYPE);
|
||||||
|
|
||||||
|
|
||||||
if (inputDeviceIdentifier == null) {
|
if (inputDeviceIdentifier == null) {
|
||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
}
|
}
|
||||||
getActivity().setTitle(title);
|
getActivity().setTitle(title);
|
||||||
use(NewKeyboardLayoutPickerController.class).initialize(this /*parent*/,
|
use(NewKeyboardLayoutPickerController.class).initialize(this /*parent*/, userId,
|
||||||
inputDeviceIdentifier, layout);
|
inputDeviceIdentifier, inputMethodInfo, inputMethodSubtype, layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -21,6 +21,8 @@ import android.hardware.input.InputDeviceIdentifier;
|
|||||||
import android.hardware.input.InputManager;
|
import android.hardware.input.InputManager;
|
||||||
import android.hardware.input.KeyboardLayout;
|
import android.hardware.input.KeyboardLayout;
|
||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -31,7 +33,6 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
|||||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -42,7 +43,11 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
|||||||
|
|
||||||
private Fragment mParent;
|
private Fragment mParent;
|
||||||
private int mInputDeviceId;
|
private int mInputDeviceId;
|
||||||
|
private int mUserId;
|
||||||
private InputDeviceIdentifier mInputDeviceIdentifier;
|
private InputDeviceIdentifier mInputDeviceIdentifier;
|
||||||
|
private InputMethodInfo mInputMethodInfo;
|
||||||
|
private InputMethodSubtype mInputMethodSubtype;
|
||||||
|
|
||||||
private KeyboardLayout[] mKeyboardLayouts;
|
private KeyboardLayout[] mKeyboardLayouts;
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
private String mPreviousSelection;
|
private String mPreviousSelection;
|
||||||
@@ -55,13 +60,16 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
|||||||
mPreferenceMap = new HashMap<>();
|
mPreferenceMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(Fragment parent, InputDeviceIdentifier inputDeviceIdentifier,
|
public void initialize(Fragment parent, int userId, InputDeviceIdentifier inputDeviceIdentifier,
|
||||||
String layout) {
|
InputMethodInfo imeInfo, InputMethodSubtype imeSubtype, String layout) {
|
||||||
mLayout = layout;
|
|
||||||
mParent = parent;
|
mParent = parent;
|
||||||
|
mUserId = userId;
|
||||||
mInputDeviceIdentifier = inputDeviceIdentifier;
|
mInputDeviceIdentifier = inputDeviceIdentifier;
|
||||||
mKeyboardLayouts = mIm.getKeyboardLayoutsForInputDevice(mInputDeviceIdentifier);
|
mInputMethodInfo = imeInfo;
|
||||||
Arrays.sort(mKeyboardLayouts);
|
mInputMethodSubtype = imeSubtype;
|
||||||
|
mLayout = layout;
|
||||||
|
mKeyboardLayouts = mIm.getKeyboardLayoutListForInputDevice(
|
||||||
|
inputDeviceIdentifier, userId, imeInfo, imeSubtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -102,15 +110,12 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
final KeyboardLayoutPreference pref = (KeyboardLayoutPreference) preference;
|
final KeyboardLayoutPreference pref = (KeyboardLayoutPreference) preference;
|
||||||
// TODO(b/259530132): Need APIs to update the available keyboards for input device.
|
pref.setCheckMark(true);
|
||||||
// For example:
|
|
||||||
// inputManager.setCurrentKeyboardLayoutForInputDevice(
|
|
||||||
// InputDevice..., Userid..., ImeSubType ..., String keyboardLayoutDescriptor)
|
|
||||||
if (mPreviousSelection != null && !mPreviousSelection.equals(preference.getKey())) {
|
if (mPreviousSelection != null && !mPreviousSelection.equals(preference.getKey())) {
|
||||||
KeyboardLayoutPreference preSelectedPref = mScreen.findPreference(mPreviousSelection);
|
KeyboardLayoutPreference preSelectedPref = mScreen.findPreference(mPreviousSelection);
|
||||||
pref.setCheckMark(true);
|
|
||||||
preSelectedPref.setCheckMark(false);
|
preSelectedPref.setCheckMark(false);
|
||||||
}
|
}
|
||||||
|
setLayout(pref);
|
||||||
mPreviousSelection = preference.getKey();
|
mPreviousSelection = preference.getKey();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -129,13 +134,7 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInputDeviceChanged(int deviceId) {
|
public void onInputDeviceChanged(int deviceId) {
|
||||||
if (mInputDeviceId >= 0 && deviceId == mInputDeviceId) {
|
// Do nothing.
|
||||||
updateCheckedState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateCheckedState() {
|
|
||||||
// TODO(b/259530132): Need API to update the keyboard language layout list.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createPreferenceHierarchy() {
|
private void createPreferenceHierarchy() {
|
||||||
@@ -143,14 +142,22 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
|
|||||||
final KeyboardLayoutPreference pref;
|
final KeyboardLayoutPreference pref;
|
||||||
if (mLayout.equals(layout.getLabel())) {
|
if (mLayout.equals(layout.getLabel())) {
|
||||||
pref = new KeyboardLayoutPreference(mScreen.getContext(), layout.getLabel(), true);
|
pref = new KeyboardLayoutPreference(mScreen.getContext(), layout.getLabel(), true);
|
||||||
mPreviousSelection = layout.getLabel();
|
mPreviousSelection = layout.getDescriptor();
|
||||||
} else {
|
} else {
|
||||||
pref = new KeyboardLayoutPreference(mScreen.getContext(), layout.getLabel(), false);
|
pref = new KeyboardLayoutPreference(mScreen.getContext(), layout.getLabel(), false);
|
||||||
}
|
}
|
||||||
// TODO: Waiting for new API to use a prefix with special number to setKey
|
pref.setKey(layout.getDescriptor());
|
||||||
pref.setKey(layout.getLabel());
|
|
||||||
mScreen.addPreference(pref);
|
mScreen.addPreference(pref);
|
||||||
mPreferenceMap.put(pref, layout);
|
mPreferenceMap.put(pref, layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setLayout(KeyboardLayoutPreference preference) {
|
||||||
|
mIm.setKeyboardLayoutForInputDevice(
|
||||||
|
mInputDeviceIdentifier,
|
||||||
|
mUserId,
|
||||||
|
mInputMethodInfo,
|
||||||
|
mInputMethodSubtype,
|
||||||
|
mPreferenceMap.get(preference).getDescriptor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,15 +27,6 @@ import com.android.settings.R;
|
|||||||
|
|
||||||
public class NewKeyboardLayoutPickerFragment extends Fragment {
|
public class NewKeyboardLayoutPickerFragment extends Fragment {
|
||||||
|
|
||||||
static final String EXTRA_TITLE = "keyboard_layout_picker_title";
|
|
||||||
static final String EXTRA_KEYBOARD_LAYOUT = "keyboard_layout";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Intent extra: The input device descriptor of the keyboard whose keyboard
|
|
||||||
* layout is to be changed.
|
|
||||||
*/
|
|
||||||
public static final String EXTRA_INPUT_DEVICE_IDENTIFIER = "input_device_identifier";
|
|
||||||
|
|
||||||
private ViewGroup mFragmentView;
|
private ViewGroup mFragmentView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilities of keyboard settings
|
||||||
|
*/
|
||||||
|
public class NewKeyboardSettingsUtils {
|
||||||
|
|
||||||
|
static final String EXTRA_KEYBOARD_DEVICE_NAME = "extra_keyboard_device_name";
|
||||||
|
static final String EXTRA_TITLE = "keyboard_layout_picker_title";
|
||||||
|
static final String EXTRA_KEYBOARD_LAYOUT = "keyboard_layout";
|
||||||
|
static final String EXTRA_USER_ID = "user_id";
|
||||||
|
static final String EXTRA_INPUT_DEVICE_IDENTIFIER = "input_device_identifier";
|
||||||
|
static final String EXTRA_INPUT_METHOD_INFO = "input_method_info";
|
||||||
|
static final String EXTRA_INPUT_METHOD_SUBTYPE = "input_method_subtype";
|
||||||
|
|
||||||
|
static InputMethodInfo getActiveIme(Context context, InputMethodManager imm) {
|
||||||
|
InputMethodInfo activeIme = null;
|
||||||
|
List<InputMethodInfo> infoList = imm.getEnabledInputMethodList();
|
||||||
|
String imeId = Settings.Secure.getStringForUser(context.getContentResolver(),
|
||||||
|
Settings.Secure.DEFAULT_INPUT_METHOD, context.getUserId());
|
||||||
|
for (InputMethodInfo method : infoList) {
|
||||||
|
if (method.getId().equals(imeId)) {
|
||||||
|
activeIme = method;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return activeIme;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<String> getSuitableImeLabels(Context context, InputMethodManager imm, int userId) {
|
||||||
|
List<String> suitableInputMethodInfoLabels = new ArrayList<>();
|
||||||
|
List<InputMethodInfo> infoList = imm.getEnabledInputMethodListAsUser(userId);
|
||||||
|
for (InputMethodInfo info : infoList) {
|
||||||
|
List<InputMethodSubtype> subtypes =
|
||||||
|
imm.getEnabledInputMethodSubtypeList(info, true);
|
||||||
|
for (InputMethodSubtype subtype : subtypes) {
|
||||||
|
if (subtype.isSuitableForPhysicalKeyboardLayoutMapping()) {
|
||||||
|
suitableInputMethodInfoLabels.add(
|
||||||
|
info.loadLabel(context.getPackageManager()).toString());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return suitableInputMethodInfoLabels;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class KeyboardInfo {
|
||||||
|
String mLanguage;
|
||||||
|
String mLayout;
|
||||||
|
InputMethodInfo mInputMethodInfo;
|
||||||
|
InputMethodSubtype mInputMethodSubtype;
|
||||||
|
|
||||||
|
KeyboardInfo(
|
||||||
|
String language,
|
||||||
|
String layout,
|
||||||
|
InputMethodInfo inputMethodInfo,
|
||||||
|
InputMethodSubtype inputMethodSubtype) {
|
||||||
|
mLanguage = language;
|
||||||
|
mLayout = layout;
|
||||||
|
mInputMethodInfo = inputMethodInfo;
|
||||||
|
mInputMethodSubtype = inputMethodSubtype;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getLanguage() {
|
||||||
|
return mLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getLayout() {
|
||||||
|
return mLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
InputMethodInfo getInputMethodInfo() {
|
||||||
|
return mInputMethodInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
InputMethodSubtype getInputMethodSubtype() {
|
||||||
|
return mInputMethodSubtype;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -35,6 +35,7 @@ import android.provider.Settings.Secure;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.FeatureFlagUtils;
|
import android.util.FeatureFlagUtils;
|
||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||||
@@ -54,9 +55,7 @@ import com.android.settingslib.utils.ThreadUtils;
|
|||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@SearchIndexable
|
@SearchIndexable
|
||||||
@@ -73,6 +72,7 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
|||||||
private final ArrayList<HardKeyboardDeviceInfo> mLastHardKeyboards = new ArrayList<>();
|
private final ArrayList<HardKeyboardDeviceInfo> mLastHardKeyboards = new ArrayList<>();
|
||||||
|
|
||||||
private InputManager mIm;
|
private InputManager mIm;
|
||||||
|
private InputMethodManager mImm;
|
||||||
@NonNull
|
@NonNull
|
||||||
private PreferenceCategory mKeyboardAssistanceCategory;
|
private PreferenceCategory mKeyboardAssistanceCategory;
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -90,6 +90,7 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
|||||||
mBluetoothAddress = activity.getIntent().getStringExtra(EXTRA_BT_ADDRESS);
|
mBluetoothAddress = activity.getIntent().getStringExtra(EXTRA_BT_ADDRESS);
|
||||||
addPreferencesFromResource(R.xml.physical_keyboard_settings);
|
addPreferencesFromResource(R.xml.physical_keyboard_settings);
|
||||||
mIm = Preconditions.checkNotNull(activity.getSystemService(InputManager.class));
|
mIm = Preconditions.checkNotNull(activity.getSystemService(InputManager.class));
|
||||||
|
mImm = Preconditions.checkNotNull(activity.getSystemService(InputMethodManager.class));
|
||||||
mKeyboardAssistanceCategory = Preconditions.checkNotNull(
|
mKeyboardAssistanceCategory = Preconditions.checkNotNull(
|
||||||
(PreferenceCategory) findPreference(KEYBOARD_OPTIONS_CATEGORY));
|
(PreferenceCategory) findPreference(KEYBOARD_OPTIONS_CATEGORY));
|
||||||
mShowVirtualKeyboardSwitch = Preconditions.checkNotNull(
|
mShowVirtualKeyboardSwitch = Preconditions.checkNotNull(
|
||||||
@@ -194,21 +195,15 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
|||||||
final Preference pref = new Preference(getPrefContext());
|
final Preference pref = new Preference(getPrefContext());
|
||||||
pref.setTitle(hardKeyboardDeviceInfo.mDeviceName);
|
pref.setTitle(hardKeyboardDeviceInfo.mDeviceName);
|
||||||
if (mIsNewKeyboardSettings) {
|
if (mIsNewKeyboardSettings) {
|
||||||
// TODO(b/252816846): Need InputMethodManager to provide the enabled locales.
|
List<String> suitableImes = new ArrayList<>();
|
||||||
// Hardcode Languages for demo until inputMethodManager provides the latest API.
|
suitableImes.addAll(
|
||||||
// For example: InputMethodManager.getEnabledInputMethodLocales();
|
NewKeyboardSettingsUtils.getSuitableImeLabels(
|
||||||
String[] keyboardLanguages =
|
getContext(), mImm, UserHandle.myUserId()));
|
||||||
{"English (US)", "German (Germany)", "Spanish (Spain)"};
|
if (!suitableImes.isEmpty()) {
|
||||||
String[] keyboardLayouts = {"English (US)", "German", "Spanish"};
|
String summary = suitableImes.get(0);
|
||||||
Map<String, String> keyboardMap = new HashMap<>();
|
|
||||||
for (int i = 0; i < keyboardLanguages.length; i++) {
|
|
||||||
keyboardMap.put(keyboardLanguages[i], keyboardLayouts[i]);
|
|
||||||
}
|
|
||||||
if (!keyboardMap.isEmpty()) {
|
|
||||||
String summary = keyboardMap.get(keyboardLanguages[0]);
|
|
||||||
StringBuilder result = new StringBuilder(summary);
|
StringBuilder result = new StringBuilder(summary);
|
||||||
for (int i = 1; i < keyboardLanguages.length; i++) {
|
for (int i = 1; i < suitableImes.size(); i++) {
|
||||||
result.append(", ").append(keyboardMap.get(keyboardLanguages[i]));
|
result.append(", ").append(suitableImes.get(i));
|
||||||
}
|
}
|
||||||
pref.setSummary(result.toString());
|
pref.setSummary(result.toString());
|
||||||
} else {
|
} else {
|
||||||
@@ -245,12 +240,10 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private void showEnabledLocalesKeyboardLayoutList(String keyboardName,
|
private void showEnabledLocalesKeyboardLayoutList(String keyboardName,
|
||||||
InputDeviceIdentifier inputDeviceIdentifier) {
|
InputDeviceIdentifier inputDeviceIdentifier) {
|
||||||
// TODO(b/252816846: Need to get enabled locales.
|
|
||||||
Bundle arguments = new Bundle();
|
Bundle arguments = new Bundle();
|
||||||
arguments.putParcelable(KeyboardLayoutPickerFragment.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
arguments.putParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
||||||
inputDeviceIdentifier);
|
inputDeviceIdentifier);
|
||||||
arguments.putString(NewKeyboardLayoutEnabledLocalesFragment.EXTRA_KEYBOARD_DEVICE_NAME,
|
arguments.putString(NewKeyboardSettingsUtils.EXTRA_KEYBOARD_DEVICE_NAME, keyboardName);
|
||||||
keyboardName);
|
|
||||||
new SubSettingLauncher(getContext())
|
new SubSettingLauncher(getContext())
|
||||||
.setSourceMetricsCategory(getMetricsCategory())
|
.setSourceMetricsCategory(getMetricsCategory())
|
||||||
.setDestination(NewKeyboardLayoutEnabledLocalesFragment.class.getName())
|
.setDestination(NewKeyboardLayoutEnabledLocalesFragment.class.getName())
|
||||||
|
Reference in New Issue
Block a user