use of android.hardware.input.KeyboardLayout in project android_frameworks_base by crdroidandroid.
the class InputManagerService method getKeyboardLayoutOverlay.
// Native callback.
private String[] getKeyboardLayoutOverlay(InputDeviceIdentifier identifier) {
if (!mSystemReady) {
return null;
}
String keyboardLayoutDescriptor = getCurrentKeyboardLayoutForInputDevice(identifier);
if (keyboardLayoutDescriptor == null) {
return null;
}
final String[] result = new String[2];
visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
@Override
public void visitKeyboardLayout(Resources resources, int keyboardLayoutResId, KeyboardLayout layout) {
try {
result[0] = layout.getDescriptor();
result[1] = Streams.readFully(new InputStreamReader(resources.openRawResource(keyboardLayoutResId)));
} catch (IOException ex) {
} catch (NotFoundException ex) {
}
}
});
if (result[0] == null) {
Slog.w(TAG, "Could not get keyboard layout with descriptor '" + keyboardLayoutDescriptor + "'.");
return null;
}
return result;
}
use of android.hardware.input.KeyboardLayout in project android_frameworks_base by crdroidandroid.
the class InputManagerService method getKeyboardLayoutForInputDevice.
// Binder call
@Override
@Nullable
public KeyboardLayout getKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier, InputMethodInfo imeInfo, InputMethodSubtype imeSubtype) {
InputMethodSubtypeHandle handle = new InputMethodSubtypeHandle(imeInfo, imeSubtype);
String key = getLayoutDescriptor(identifier);
final String keyboardLayoutDescriptor;
synchronized (mDataStore) {
keyboardLayoutDescriptor = mDataStore.getKeyboardLayout(key, handle);
}
if (keyboardLayoutDescriptor == null) {
return null;
}
final KeyboardLayout[] result = new KeyboardLayout[1];
visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
@Override
public void visitKeyboardLayout(Resources resources, int keyboardLayoutResId, KeyboardLayout layout) {
result[0] = layout;
}
});
if (result[0] == null) {
Slog.w(TAG, "Could not get keyboard layout with descriptor '" + keyboardLayoutDescriptor + "'.");
}
return result[0];
}
use of android.hardware.input.KeyboardLayout in project platform_frameworks_base by android.
the class InputManagerService method visitKeyboardLayoutsInPackage.
private void visitKeyboardLayoutsInPackage(PackageManager pm, ActivityInfo receiver, String keyboardName, int requestedPriority, KeyboardLayoutVisitor visitor) {
Bundle metaData = receiver.metaData;
if (metaData == null) {
return;
}
int configResId = metaData.getInt(InputManager.META_DATA_KEYBOARD_LAYOUTS);
if (configResId == 0) {
Slog.w(TAG, "Missing meta-data '" + InputManager.META_DATA_KEYBOARD_LAYOUTS + "' on receiver " + receiver.packageName + "/" + receiver.name);
return;
}
CharSequence receiverLabel = receiver.loadLabel(pm);
String collection = receiverLabel != null ? receiverLabel.toString() : "";
int priority;
if ((receiver.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
priority = requestedPriority;
} else {
priority = 0;
}
try {
Resources resources = pm.getResourcesForApplication(receiver.applicationInfo);
XmlResourceParser parser = resources.getXml(configResId);
try {
XmlUtils.beginDocument(parser, "keyboard-layouts");
for (; ; ) {
XmlUtils.nextElement(parser);
String element = parser.getName();
if (element == null) {
break;
}
if (element.equals("keyboard-layout")) {
TypedArray a = resources.obtainAttributes(parser, com.android.internal.R.styleable.KeyboardLayout);
try {
String name = a.getString(com.android.internal.R.styleable.KeyboardLayout_name);
String label = a.getString(com.android.internal.R.styleable.KeyboardLayout_label);
int keyboardLayoutResId = a.getResourceId(com.android.internal.R.styleable.KeyboardLayout_keyboardLayout, 0);
String languageTags = a.getString(com.android.internal.R.styleable.KeyboardLayout_locale);
LocaleList locales = getLocalesFromLanguageTags(languageTags);
int vid = a.getInt(com.android.internal.R.styleable.KeyboardLayout_vendorId, -1);
int pid = a.getInt(com.android.internal.R.styleable.KeyboardLayout_productId, -1);
if (name == null || label == null || keyboardLayoutResId == 0) {
Slog.w(TAG, "Missing required 'name', 'label' or 'keyboardLayout' " + "attributes in keyboard layout " + "resource from receiver " + receiver.packageName + "/" + receiver.name);
} else {
String descriptor = KeyboardLayoutDescriptor.format(receiver.packageName, receiver.name, name);
if (keyboardName == null || name.equals(keyboardName)) {
KeyboardLayout layout = new KeyboardLayout(descriptor, label, collection, priority, locales, vid, pid);
visitor.visitKeyboardLayout(resources, keyboardLayoutResId, layout);
}
}
} finally {
a.recycle();
}
} else {
Slog.w(TAG, "Skipping unrecognized element '" + element + "' in keyboard layout resource from receiver " + receiver.packageName + "/" + receiver.name);
}
}
} finally {
parser.close();
}
} catch (Exception ex) {
Slog.w(TAG, "Could not parse keyboard layout resource from receiver " + receiver.packageName + "/" + receiver.name, ex);
}
}
use of android.hardware.input.KeyboardLayout in project platform_frameworks_base by android.
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();
}
use of android.hardware.input.KeyboardLayout in project android_frameworks_base by crdroidandroid.
the class InputManagerService method visitKeyboardLayoutsInPackage.
private void visitKeyboardLayoutsInPackage(PackageManager pm, ActivityInfo receiver, String keyboardName, int requestedPriority, KeyboardLayoutVisitor visitor) {
Bundle metaData = receiver.metaData;
if (metaData == null) {
return;
}
int configResId = metaData.getInt(InputManager.META_DATA_KEYBOARD_LAYOUTS);
if (configResId == 0) {
Slog.w(TAG, "Missing meta-data '" + InputManager.META_DATA_KEYBOARD_LAYOUTS + "' on receiver " + receiver.packageName + "/" + receiver.name);
return;
}
CharSequence receiverLabel = receiver.loadLabel(pm);
String collection = receiverLabel != null ? receiverLabel.toString() : "";
int priority;
if ((receiver.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
priority = requestedPriority;
} else {
priority = 0;
}
try {
Resources resources = pm.getResourcesForApplication(receiver.applicationInfo);
XmlResourceParser parser = resources.getXml(configResId);
try {
XmlUtils.beginDocument(parser, "keyboard-layouts");
for (; ; ) {
XmlUtils.nextElement(parser);
String element = parser.getName();
if (element == null) {
break;
}
if (element.equals("keyboard-layout")) {
TypedArray a = resources.obtainAttributes(parser, com.android.internal.R.styleable.KeyboardLayout);
try {
String name = a.getString(com.android.internal.R.styleable.KeyboardLayout_name);
String label = a.getString(com.android.internal.R.styleable.KeyboardLayout_label);
int keyboardLayoutResId = a.getResourceId(com.android.internal.R.styleable.KeyboardLayout_keyboardLayout, 0);
String languageTags = a.getString(com.android.internal.R.styleable.KeyboardLayout_locale);
LocaleList locales = getLocalesFromLanguageTags(languageTags);
int vid = a.getInt(com.android.internal.R.styleable.KeyboardLayout_vendorId, -1);
int pid = a.getInt(com.android.internal.R.styleable.KeyboardLayout_productId, -1);
if (name == null || label == null || keyboardLayoutResId == 0) {
Slog.w(TAG, "Missing required 'name', 'label' or 'keyboardLayout' " + "attributes in keyboard layout " + "resource from receiver " + receiver.packageName + "/" + receiver.name);
} else {
String descriptor = KeyboardLayoutDescriptor.format(receiver.packageName, receiver.name, name);
if (keyboardName == null || name.equals(keyboardName)) {
KeyboardLayout layout = new KeyboardLayout(descriptor, label, collection, priority, locales, vid, pid);
visitor.visitKeyboardLayout(resources, keyboardLayoutResId, layout);
}
}
} finally {
a.recycle();
}
} else {
Slog.w(TAG, "Skipping unrecognized element '" + element + "' in keyboard layout resource from receiver " + receiver.packageName + "/" + receiver.name);
}
}
} finally {
parser.close();
}
} catch (Exception ex) {
Slog.w(TAG, "Could not parse keyboard layout resource from receiver " + receiver.packageName + "/" + receiver.name, ex);
}
}
Aggregations