use of android.hardware.input.KeyboardLayout in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class InputMethodAndLanguageSettings method updateHardKeyboards.
private void updateHardKeyboards() {
if (mHardKeyboardCategory == null) {
return;
}
mHardKeyboardPreferenceList.clear();
final int[] devices = InputDevice.getDeviceIds();
for (int i = 0; i < devices.length; i++) {
InputDevice device = InputDevice.getDevice(devices[i]);
if (device != null && !device.isVirtual() && device.isFullKeyboard()) {
final InputDeviceIdentifier identifier = device.getIdentifier();
final String keyboardLayoutDescriptor = mIm.getCurrentKeyboardLayoutForInputDevice(identifier);
final KeyboardLayout keyboardLayout = keyboardLayoutDescriptor != null ? mIm.getKeyboardLayout(keyboardLayoutDescriptor) : null;
final PreferenceScreen pref = new PreferenceScreen(getPrefContext(), null);
pref.setTitle(device.getName());
if (keyboardLayout != null) {
pref.setSummary(keyboardLayout.toString());
} else {
pref.setSummary(R.string.keyboard_layout_default_label);
}
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
showKeyboardLayoutDialog(identifier);
return true;
}
});
mHardKeyboardPreferenceList.add(pref);
}
}
if (!mHardKeyboardPreferenceList.isEmpty()) {
for (int i = mHardKeyboardCategory.getPreferenceCount(); i-- > 0; ) {
final Preference pref = mHardKeyboardCategory.getPreference(i);
if (pref.getOrder() < 1000) {
mHardKeyboardCategory.removePreference(pref);
}
}
Collections.sort(mHardKeyboardPreferenceList);
final int count = mHardKeyboardPreferenceList.size();
for (int i = 0; i < count; i++) {
final Preference pref = mHardKeyboardPreferenceList.get(i);
pref.setOrder(i);
mHardKeyboardCategory.addPreference(pref);
}
getPreferenceScreen().addPreference(mHardKeyboardCategory);
} else {
getPreferenceScreen().removePreference(mHardKeyboardCategory);
}
}
use of android.hardware.input.KeyboardLayout in project android_frameworks_base by crdroidandroid.
the class InputManagerService method getDefaultKeyboardLayout.
private String getDefaultKeyboardLayout(final InputDevice d) {
final Locale systemLocale = mContext.getResources().getConfiguration().locale;
// reasonable default.
if (TextUtils.isEmpty(systemLocale.getLanguage())) {
return null;
}
final List<KeyboardLayout> layouts = new ArrayList<>();
visitAllKeyboardLayouts(new KeyboardLayoutVisitor() {
@Override
public void visitKeyboardLayout(Resources resources, int keyboardLayoutResId, KeyboardLayout layout) {
// means its a custom layout for a specific keyboard.
if (layout.getVendorId() != d.getVendorId() || layout.getProductId() != d.getProductId()) {
return;
}
final LocaleList locales = layout.getLocales();
final int numLocales = locales.size();
for (int localeIndex = 0; localeIndex < numLocales; ++localeIndex) {
if (isCompatibleLocale(systemLocale, locales.get(localeIndex))) {
layouts.add(layout);
break;
}
}
}
});
if (layouts.isEmpty()) {
return null;
}
// First sort so that ones with higher priority are listed at the top
Collections.sort(layouts);
// Next we want to try to find an exact match of language, country and variant.
final int N = layouts.size();
for (int i = 0; i < N; i++) {
KeyboardLayout layout = layouts.get(i);
final LocaleList locales = layout.getLocales();
final int numLocales = locales.size();
for (int localeIndex = 0; localeIndex < numLocales; ++localeIndex) {
final Locale locale = locales.get(localeIndex);
if (locale.getCountry().equals(systemLocale.getCountry()) && locale.getVariant().equals(systemLocale.getVariant())) {
return layout.getDescriptor();
}
}
}
// Then try an exact match of language and country
for (int i = 0; i < N; i++) {
KeyboardLayout layout = layouts.get(i);
final LocaleList locales = layout.getLocales();
final int numLocales = locales.size();
for (int localeIndex = 0; localeIndex < numLocales; ++localeIndex) {
final Locale locale = locales.get(localeIndex);
if (locale.getCountry().equals(systemLocale.getCountry())) {
return layout.getDescriptor();
}
}
}
// Give up and just use the highest priority layout with matching language
return layouts.get(0).getDescriptor();
}
Aggregations