Search in sources :

Example 21 with KeyboardLayout

use of android.hardware.input.KeyboardLayout in project android_frameworks_base by ResurrectionRemix.

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) SettingNotFoundException(android.provider.Settings.SettingNotFoundException) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Resources(android.content.res.Resources) KeyboardLayout(android.hardware.input.KeyboardLayout) IOException(java.io.IOException)

Example 22 with KeyboardLayout

use of android.hardware.input.KeyboardLayout in project android_frameworks_base by ResurrectionRemix.

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);
    }
}
Also used : LocaleList(android.os.LocaleList) XmlResourceParser(android.content.res.XmlResourceParser) Bundle(android.os.Bundle) TypedArray(android.content.res.TypedArray) Resources(android.content.res.Resources) KeyboardLayout(android.hardware.input.KeyboardLayout) SettingNotFoundException(android.provider.Settings.SettingNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 23 with KeyboardLayout

use of android.hardware.input.KeyboardLayout in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class KeyboardLayoutPickerFragment method onPreferenceTreeClick.

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    if (preference instanceof CheckBoxPreference) {
        CheckBoxPreference checkboxPref = (CheckBoxPreference) preference;
        KeyboardLayout layout = mPreferenceMap.get(checkboxPref);
        if (layout != null) {
            boolean checked = checkboxPref.isChecked();
            if (checked) {
                mIm.addKeyboardLayoutForInputDevice(mInputDeviceIdentifier, layout.getDescriptor());
            } else {
                mIm.removeKeyboardLayoutForInputDevice(mInputDeviceIdentifier, layout.getDescriptor());
            }
            return true;
        }
    }
    return super.onPreferenceTreeClick(preference);
}
Also used : CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) KeyboardLayout(android.hardware.input.KeyboardLayout)

Example 24 with KeyboardLayout

use of android.hardware.input.KeyboardLayout in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class KeyboardLayoutPickerFragment2 method createPreferenceHierarchy.

private PreferenceScreen createPreferenceHierarchy() {
    PreferenceScreen root = getPreferenceManager().createPreferenceScreen(getActivity());
    for (KeyboardLayout layout : mKeyboardLayouts) {
        Preference pref = new Preference(getPrefContext());
        pref.setTitle(layout.getLabel());
        pref.setSummary(layout.getCollection());
        root.addPreference(pref);
        mPreferenceMap.put(pref, layout);
    }
    root.setTitle(KeyboardInfoPreference.getDisplayName(getContext(), mImi, mSubtype));
    return root;
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) KeyboardInfoPreference(com.android.settings.inputmethod.PhysicalKeyboardFragment.KeyboardInfoPreference) KeyboardLayout(android.hardware.input.KeyboardLayout)

Example 25 with KeyboardLayout

use of android.hardware.input.KeyboardLayout in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class KeyboardLayoutDialogFragment method onKeyboardLayoutClicked.

private void onKeyboardLayoutClicked(int which) {
    if (which >= 0 && which < mAdapter.getCount()) {
        KeyboardLayout keyboardLayout = mAdapter.getItem(which);
        if (keyboardLayout != null) {
            mIm.setCurrentKeyboardLayoutForInputDevice(mInputDeviceIdentifier, keyboardLayout.getDescriptor());
        }
        dismiss();
    }
}
Also used : KeyboardLayout(android.hardware.input.KeyboardLayout)

Aggregations

KeyboardLayout (android.hardware.input.KeyboardLayout)27 Resources (android.content.res.Resources)20 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)10 NotFoundException (android.content.res.Resources.NotFoundException)10 LocaleList (android.os.LocaleList)10 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)10 FileNotFoundException (java.io.FileNotFoundException)10 IOException (java.io.IOException)10 Nullable (android.annotation.Nullable)5 TypedArray (android.content.res.TypedArray)5 XmlResourceParser (android.content.res.XmlResourceParser)5 Bundle (android.os.Bundle)5 RemoteException (android.os.RemoteException)5 InputMethodSubtypeHandle (com.android.internal.inputmethod.InputMethodSubtypeHandle)5 InputStreamReader (java.io.InputStreamReader)5 ArrayList (java.util.ArrayList)5 Locale (java.util.Locale)5 PreferenceScreen (android.support.v7.preference.PreferenceScreen)3 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)2 Preference (android.support.v7.preference.Preference)2