Search in sources :

Example 1 with KeyboardLayout

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

the class InputManagerService method handleSwitchKeyboardLayout.

// Must be called on handler.
private void handleSwitchKeyboardLayout(int deviceId, int direction) {
    final InputDevice device = getInputDevice(deviceId);
    if (device != null) {
        final String inputDeviceDescriptor = device.getDescriptor();
        final boolean changed;
        final String keyboardLayoutDescriptor;
        synchronized (mDataStore) {
            try {
                changed = mDataStore.switchKeyboardLayout(inputDeviceDescriptor, direction);
                keyboardLayoutDescriptor = mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor);
            } finally {
                mDataStore.saveIfNeeded();
            }
        }
        if (changed) {
            if (mSwitchedKeyboardLayoutToast != null) {
                mSwitchedKeyboardLayoutToast.cancel();
                mSwitchedKeyboardLayoutToast = null;
            }
            if (keyboardLayoutDescriptor != null) {
                KeyboardLayout keyboardLayout = getKeyboardLayout(keyboardLayoutDescriptor);
                if (keyboardLayout != null) {
                    mSwitchedKeyboardLayoutToast = Toast.makeText(mContext, keyboardLayout.getLabel(), Toast.LENGTH_SHORT);
                    mSwitchedKeyboardLayoutToast.show();
                }
            }
            reloadKeyboardLayouts();
        }
    }
}
Also used : InputDevice(android.view.InputDevice) KeyboardLayout(android.hardware.input.KeyboardLayout)

Example 2 with KeyboardLayout

use of android.hardware.input.KeyboardLayout in project platform_frameworks_base by android.

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 3 with KeyboardLayout

use of android.hardware.input.KeyboardLayout in project platform_frameworks_base by android.

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];
}
Also used : InputMethodSubtypeHandle(com.android.internal.inputmethod.InputMethodSubtypeHandle) KeyboardLayout(android.hardware.input.KeyboardLayout) Resources(android.content.res.Resources) Nullable(android.annotation.Nullable)

Example 4 with KeyboardLayout

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

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();
}
Also used : Locale(java.util.Locale) LocaleList(android.os.LocaleList) ArrayList(java.util.ArrayList) KeyboardLayout(android.hardware.input.KeyboardLayout) Resources(android.content.res.Resources)

Example 5 with KeyboardLayout

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

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];
}
Also used : InputMethodSubtypeHandle(com.android.internal.inputmethod.InputMethodSubtypeHandle) KeyboardLayout(android.hardware.input.KeyboardLayout) Resources(android.content.res.Resources) Nullable(android.annotation.Nullable)

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