2 * Copyright (C) 2012 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.hardware.input;
19 import android.os.Parcel;
20 import android.os.Parcelable;
23 * Describes a keyboard layout.
27 public final class KeyboardLayout implements Parcelable,
28 Comparable<KeyboardLayout> {
29 private final String mDescriptor;
30 private final String mLabel;
31 private final String mCollection;
32 private final int mPriority;
34 public static final Parcelable.Creator<KeyboardLayout> CREATOR =
35 new Parcelable.Creator<KeyboardLayout>() {
36 public KeyboardLayout createFromParcel(Parcel source) {
37 return new KeyboardLayout(source);
39 public KeyboardLayout[] newArray(int size) {
40 return new KeyboardLayout[size];
44 public KeyboardLayout(String descriptor, String label, String collection, int priority) {
45 mDescriptor = descriptor;
47 mCollection = collection;
51 private KeyboardLayout(Parcel source) {
52 mDescriptor = source.readString();
53 mLabel = source.readString();
54 mCollection = source.readString();
55 mPriority = source.readInt();
59 * Gets the keyboard layout descriptor, which can be used to retrieve
60 * the keyboard layout again later using
61 * {@link InputManager#getKeyboardLayout(String)}.
63 * @return The keyboard layout descriptor.
65 public String getDescriptor() {
70 * Gets the keyboard layout descriptive label to show in the user interface.
71 * @return The keyboard layout descriptive label.
73 public String getLabel() {
78 * Gets the name of the collection to which the keyboard layout belongs. This is
79 * the label of the broadcast receiver or application that provided the keyboard layout.
80 * @return The keyboard layout collection name.
82 public String getCollection() {
87 public int describeContents() {
92 public void writeToParcel(Parcel dest, int flags) {
93 dest.writeString(mDescriptor);
94 dest.writeString(mLabel);
95 dest.writeString(mCollection);
96 dest.writeInt(mPriority);
100 public int compareTo(KeyboardLayout another) {
101 // Note that these arguments are intentionally flipped since you want higher priority
102 // keyboards to be listed before lower priority keyboards.
103 int result = Integer.compare(another.mPriority, mPriority);
105 result = mLabel.compareToIgnoreCase(another.mLabel);
108 result = mCollection.compareToIgnoreCase(another.mCollection);
114 public String toString() {
115 if (mCollection.isEmpty()) {
118 return mLabel + " - " + mCollection;