Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc9445ba authored by Jeff Brown's avatar Jeff Brown Committed by Android (Google) Code Review
Browse files

Merge "Add support for grouping keyboard layouts by collection." into jb-dev

parents 9de61ae0 d9fec5d3
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -77,7 +77,8 @@ public final class InputManager {
     * The meta-data specifies a resource that contains a description of each keyboard
     * layout that is provided by the application.
     * <pre><code>
     * &lt;receiver android:name=".InputDeviceReceiver">
     * &lt;receiver android:name=".InputDeviceReceiver"
     *         android:label="@string/keyboard_layouts_label">
     *     &lt;intent-filter>
     *         &lt;action android:name="android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS" />
     *     &lt;/intent-filter>
@@ -90,7 +91,9 @@ public final class InputManager {
     * an XML resource whose root element is <code>&lt;keyboard-layouts></code> that
     * contains zero or more <code>&lt;keyboard-layout></code> elements.
     * Each <code>&lt;keyboard-layout></code> element specifies the name, label, and location
     * of a key character map for a particular keyboard layout.
     * of a key character map for a particular keyboard layout.  The label on the receiver
     * is used to name the collection of keyboard layouts provided by this receiver in the
     * keyboard layout settings.
     * <pre></code>
     * &lt;?xml version="1.0" encoding="utf-8"?>
     * &lt;keyboard-layouts xmlns:android="http://schemas.android.com/apk/res/android">
+23 −3
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ public final class KeyboardLayout implements Parcelable,
        Comparable<KeyboardLayout> {
    private final String mDescriptor;
    private final String mLabel;
    private final String mCollection;

    public static final Parcelable.Creator<KeyboardLayout> CREATOR =
            new Parcelable.Creator<KeyboardLayout>() {
@@ -39,14 +40,16 @@ public final class KeyboardLayout implements Parcelable,
        }
    };

    public KeyboardLayout(String descriptor, String label) {
    public KeyboardLayout(String descriptor, String label, String collection) {
        mDescriptor = descriptor;
        mLabel = label;
        mCollection = collection;
    }

    private KeyboardLayout(Parcel source) {
        mDescriptor = source.readString();
        mLabel = source.readString();
        mCollection = source.readString();
    }

    /**
@@ -68,6 +71,15 @@ public final class KeyboardLayout implements Parcelable,
        return mLabel;
    }

    /**
     * Gets the name of the collection to which the keyboard layout belongs.  This is
     * the label of the broadcast receiver or application that provided the keyboard layout.
     * @return The keyboard layout collection name.
     */
    public String getCollection() {
        return mCollection;
    }

    @Override
    public int describeContents() {
        return 0;
@@ -77,15 +89,23 @@ public final class KeyboardLayout implements Parcelable,
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mDescriptor);
        dest.writeString(mLabel);
        dest.writeString(mCollection);
    }

    @Override
    public int compareTo(KeyboardLayout another) {
        return mLabel.compareToIgnoreCase(another.mLabel);
        int result = mLabel.compareToIgnoreCase(another.mLabel);
        if (result == 0) {
            result = mCollection.compareToIgnoreCase(another.mCollection);
        }
        return result;
    }

    @Override
    public String toString() {
        if (mCollection.isEmpty()) {
            return mLabel;
        }
        return mLabel + " - " + mCollection;
    }
}
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -8,7 +8,8 @@
            android:label="@string/app_label"
            android:process="system">

        <receiver android:name=".InputDeviceReceiver">
        <receiver android:name=".InputDeviceReceiver"
                android:label="@string/keyboard_layouts_label">
            <intent-filter>
                <action android:name="android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS" />
            </intent-filter>
+3 −0
Original line number Diff line number Diff line
@@ -3,6 +3,9 @@
    <!-- Name of the application. [CHAR LIMIT=35] -->
    <string name="app_label">Input Devices</string>

    <!-- Keyboard layouts label, used to describe the set of all built-in layouts in the UI. [CHAR LIMIT=35] -->
    <string name="keyboard_layouts_label">Android keyboard</string>

    <!-- US English keyboard layout label. [CHAR LIMIT=35] -->
    <string name="keyboard_layout_english_us_label">English (US)</string>

+10 −8
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.content.res.TypedArray;
@@ -597,8 +596,8 @@ public class InputManagerService extends IInputManager.Stub implements Watchdog.
        visitAllKeyboardLayouts(new KeyboardLayoutVisitor() {
            @Override
            public void visitKeyboardLayout(Resources resources,
                    String descriptor, String label, int keyboardLayoutResId) {
                list.add(new KeyboardLayout(descriptor, label));
                    String descriptor, String label, String collection, int keyboardLayoutResId) {
                list.add(new KeyboardLayout(descriptor, label, collection));
            }
        });
        return list.toArray(new KeyboardLayout[list.size()]);
@@ -614,8 +613,8 @@ public class InputManagerService extends IInputManager.Stub implements Watchdog.
        visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
            @Override
            public void visitKeyboardLayout(Resources resources,
                    String descriptor, String label, int keyboardLayoutResId) {
                result[0] = new KeyboardLayout(descriptor, label);
                    String descriptor, String label, String collection, int keyboardLayoutResId) {
                result[0] = new KeyboardLayout(descriptor, label, collection);
            }
        });
        if (result[0] == null) {
@@ -663,6 +662,9 @@ public class InputManagerService extends IInputManager.Stub implements Watchdog.
            return;
        }

        CharSequence receiverLabel = receiver.loadLabel(pm);
        String collection = receiverLabel != null ? receiverLabel.toString() : "";

        try {
            Resources resources = pm.getResourcesForApplication(receiver.applicationInfo);
            XmlResourceParser parser = resources.getXml(configResId);
@@ -696,7 +698,7 @@ public class InputManagerService extends IInputManager.Stub implements Watchdog.
                                        receiver.packageName, receiver.name, name);
                                if (keyboardName == null || name.equals(keyboardName)) {
                                    visitor.visitKeyboardLayout(resources, descriptor,
                                            label, keyboardLayoutResId);
                                            label, collection, keyboardLayoutResId);
                                }
                            }
                        } finally {
@@ -1139,7 +1141,7 @@ public class InputManagerService extends IInputManager.Stub implements Watchdog.
        visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
            @Override
            public void visitKeyboardLayout(Resources resources,
                    String descriptor, String label, int keyboardLayoutResId) {
                    String descriptor, String label, String collection, int keyboardLayoutResId) {
                try {
                    result[0] = descriptor;
                    result[1] = Streams.readFully(new InputStreamReader(
@@ -1262,7 +1264,7 @@ public class InputManagerService extends IInputManager.Stub implements Watchdog.

    private interface KeyboardLayoutVisitor {
        void visitKeyboardLayout(Resources resources,
                String descriptor, String label, int keyboardLayoutResId);
                String descriptor, String label, String collection, int keyboardLayoutResId);
    }

    private final class InputDevicesChangedListenerRecord implements DeathRecipient {