Skip to content

Commit d9fec5d

Browse files
author
Jeff Brown
committed
Add support for grouping keyboard layouts by collection.
Bug: 6405203 Change-Id: Id818b27ec09928150795d594a96df186a6e39168
1 parent ab624c2 commit d9fec5d

File tree

5 files changed

+43
-14
lines changed

5 files changed

+43
-14
lines changed

core/java/android/hardware/input/InputManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public final class InputManager {
7777
* The meta-data specifies a resource that contains a description of each keyboard
7878
* layout that is provided by the application.
7979
* <pre><code>
80-
* &lt;receiver android:name=".InputDeviceReceiver">
80+
* &lt;receiver android:name=".InputDeviceReceiver"
81+
* android:label="@string/keyboard_layouts_label">
8182
* &lt;intent-filter>
8283
* &lt;action android:name="android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS" />
8384
* &lt;/intent-filter>
@@ -90,7 +91,9 @@ public final class InputManager {
9091
* an XML resource whose root element is <code>&lt;keyboard-layouts></code> that
9192
* contains zero or more <code>&lt;keyboard-layout></code> elements.
9293
* Each <code>&lt;keyboard-layout></code> element specifies the name, label, and location
93-
* of a key character map for a particular keyboard layout.
94+
* of a key character map for a particular keyboard layout. The label on the receiver
95+
* is used to name the collection of keyboard layouts provided by this receiver in the
96+
* keyboard layout settings.
9497
* <pre></code>
9598
* &lt;?xml version="1.0" encoding="utf-8"?>
9699
* &lt;keyboard-layouts xmlns:android="http://schemas.android.com/apk/res/android">

core/java/android/hardware/input/KeyboardLayout.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public final class KeyboardLayout implements Parcelable,
2828
Comparable<KeyboardLayout> {
2929
private final String mDescriptor;
3030
private final String mLabel;
31+
private final String mCollection;
3132

3233
public static final Parcelable.Creator<KeyboardLayout> CREATOR =
3334
new Parcelable.Creator<KeyboardLayout>() {
@@ -39,14 +40,16 @@ public KeyboardLayout[] newArray(int size) {
3940
}
4041
};
4142

42-
public KeyboardLayout(String descriptor, String label) {
43+
public KeyboardLayout(String descriptor, String label, String collection) {
4344
mDescriptor = descriptor;
4445
mLabel = label;
46+
mCollection = collection;
4547
}
4648

4749
private KeyboardLayout(Parcel source) {
4850
mDescriptor = source.readString();
4951
mLabel = source.readString();
52+
mCollection = source.readString();
5053
}
5154

5255
/**
@@ -68,6 +71,15 @@ public String getLabel() {
6871
return mLabel;
6972
}
7073

74+
/**
75+
* Gets the name of the collection to which the keyboard layout belongs. This is
76+
* the label of the broadcast receiver or application that provided the keyboard layout.
77+
* @return The keyboard layout collection name.
78+
*/
79+
public String getCollection() {
80+
return mCollection;
81+
}
82+
7183
@Override
7284
public int describeContents() {
7385
return 0;
@@ -77,15 +89,23 @@ public int describeContents() {
7789
public void writeToParcel(Parcel dest, int flags) {
7890
dest.writeString(mDescriptor);
7991
dest.writeString(mLabel);
92+
dest.writeString(mCollection);
8093
}
8194

8295
@Override
8396
public int compareTo(KeyboardLayout another) {
84-
return mLabel.compareToIgnoreCase(another.mLabel);
97+
int result = mLabel.compareToIgnoreCase(another.mLabel);
98+
if (result == 0) {
99+
result = mCollection.compareToIgnoreCase(another.mCollection);
100+
}
101+
return result;
85102
}
86103

87104
@Override
88105
public String toString() {
89-
return mLabel;
106+
if (mCollection.isEmpty()) {
107+
return mLabel;
108+
}
109+
return mLabel + " - " + mCollection;
90110
}
91111
}

packages/InputDevices/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
android:label="@string/app_label"
99
android:process="system">
1010

11-
<receiver android:name=".InputDeviceReceiver">
11+
<receiver android:name=".InputDeviceReceiver"
12+
android:label="@string/keyboard_layouts_label">
1213
<intent-filter>
1314
<action android:name="android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS" />
1415
</intent-filter>

packages/InputDevices/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<!-- Name of the application. [CHAR LIMIT=35] -->
44
<string name="app_label">Input Devices</string>
55

6+
<!-- Keyboard layouts label, used to describe the set of all built-in layouts in the UI. [CHAR LIMIT=35] -->
7+
<string name="keyboard_layouts_label">Android keyboard</string>
8+
69
<!-- US English keyboard layout label. [CHAR LIMIT=35] -->
710
<string name="keyboard_layout_english_us_label">English (US)</string>
811

services/java/com/android/server/input/InputManagerService.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import android.content.pm.PackageManager;
3838
import android.content.pm.ResolveInfo;
3939
import android.content.pm.PackageManager.NameNotFoundException;
40-
import android.content.res.Configuration;
4140
import android.content.res.Resources;
4241
import android.content.res.Resources.NotFoundException;
4342
import android.content.res.TypedArray;
@@ -597,8 +596,8 @@ public KeyboardLayout[] getKeyboardLayouts() {
597596
visitAllKeyboardLayouts(new KeyboardLayoutVisitor() {
598597
@Override
599598
public void visitKeyboardLayout(Resources resources,
600-
String descriptor, String label, int keyboardLayoutResId) {
601-
list.add(new KeyboardLayout(descriptor, label));
599+
String descriptor, String label, String collection, int keyboardLayoutResId) {
600+
list.add(new KeyboardLayout(descriptor, label, collection));
602601
}
603602
});
604603
return list.toArray(new KeyboardLayout[list.size()]);
@@ -614,8 +613,8 @@ public KeyboardLayout getKeyboardLayout(String keyboardLayoutDescriptor) {
614613
visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
615614
@Override
616615
public void visitKeyboardLayout(Resources resources,
617-
String descriptor, String label, int keyboardLayoutResId) {
618-
result[0] = new KeyboardLayout(descriptor, label);
616+
String descriptor, String label, String collection, int keyboardLayoutResId) {
617+
result[0] = new KeyboardLayout(descriptor, label, collection);
619618
}
620619
});
621620
if (result[0] == null) {
@@ -663,6 +662,9 @@ private void visitKeyboardLayoutsInPackage(PackageManager pm, ActivityInfo recei
663662
return;
664663
}
665664

665+
CharSequence receiverLabel = receiver.loadLabel(pm);
666+
String collection = receiverLabel != null ? receiverLabel.toString() : "";
667+
666668
try {
667669
Resources resources = pm.getResourcesForApplication(receiver.applicationInfo);
668670
XmlResourceParser parser = resources.getXml(configResId);
@@ -696,7 +698,7 @@ private void visitKeyboardLayoutsInPackage(PackageManager pm, ActivityInfo recei
696698
receiver.packageName, receiver.name, name);
697699
if (keyboardName == null || name.equals(keyboardName)) {
698700
visitor.visitKeyboardLayout(resources, descriptor,
699-
label, keyboardLayoutResId);
701+
label, collection, keyboardLayoutResId);
700702
}
701703
}
702704
} finally {
@@ -1139,7 +1141,7 @@ private String[] getKeyboardLayoutOverlay(String inputDeviceDescriptor) {
11391141
visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
11401142
@Override
11411143
public void visitKeyboardLayout(Resources resources,
1142-
String descriptor, String label, int keyboardLayoutResId) {
1144+
String descriptor, String label, String collection, int keyboardLayoutResId) {
11431145
try {
11441146
result[0] = descriptor;
11451147
result[1] = Streams.readFully(new InputStreamReader(
@@ -1262,7 +1264,7 @@ public static KeyboardLayoutDescriptor parse(String descriptor) {
12621264

12631265
private interface KeyboardLayoutVisitor {
12641266
void visitKeyboardLayout(Resources resources,
1265-
String descriptor, String label, int keyboardLayoutResId);
1267+
String descriptor, String label, String collection, int keyboardLayoutResId);
12661268
}
12671269

12681270
private final class InputDevicesChangedListenerRecord implements DeathRecipient {

0 commit comments

Comments
 (0)