1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 package android.hardware.input; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * Describes a keyboard layout. 24 * 25 * @hide 26 */ 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; 33 34 public static final Parcelable.Creator<KeyboardLayout> CREATOR = 35 new Parcelable.Creator<KeyboardLayout>() { 36 public KeyboardLayout createFromParcel(Parcel source) { 37 return new KeyboardLayout(source); 38 } 39 public KeyboardLayout[] newArray(int size) { 40 return new KeyboardLayout[size]; 41 } 42 }; 43 44 public KeyboardLayout(String descriptor, String label, String collection, int priority) { 45 mDescriptor = descriptor; 46 mLabel = label; 47 mCollection = collection; 48 mPriority = priority; 49 } 50 51 private KeyboardLayout(Parcel source) { 52 mDescriptor = source.readString(); 53 mLabel = source.readString(); 54 mCollection = source.readString(); 55 mPriority = source.readInt(); 56 } 57 58 /** 59 * Gets the keyboard layout descriptor, which can be used to retrieve 60 * the keyboard layout again later using 61 * {@link InputManager#getKeyboardLayout(String)}. 62 * 63 * @return The keyboard layout descriptor. 64 */ 65 public String getDescriptor() { 66 return mDescriptor; 67 } 68 69 /** 70 * Gets the keyboard layout descriptive label to show in the user interface. 71 * @return The keyboard layout descriptive label. 72 */ 73 public String getLabel() { 74 return mLabel; 75 } 76 77 /** 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. 81 */ 82 public String getCollection() { 83 return mCollection; 84 } 85 86 @Override 87 public int describeContents() { 88 return 0; 89 } 90 91 @Override 92 public void writeToParcel(Parcel dest, int flags) { 93 dest.writeString(mDescriptor); 94 dest.writeString(mLabel); 95 dest.writeString(mCollection); 96 dest.writeInt(mPriority); 97 } 98 99 @Override 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); 104 if (result == 0) { 105 result = mLabel.compareToIgnoreCase(another.mLabel); 106 } 107 if (result == 0) { 108 result = mCollection.compareToIgnoreCase(another.mCollection); 109 } 110 return result; 111 } 112 113 @Override 114 public String toString() { 115 if (mCollection.isEmpty()) { 116 return mLabel; 117 } 118 return mLabel + " - " + mCollection; 119 } 120 } 121