Home | History | Annotate | Download | only in input
      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 
     33     public static final Parcelable.Creator<KeyboardLayout> CREATOR =
     34             new Parcelable.Creator<KeyboardLayout>() {
     35         public KeyboardLayout createFromParcel(Parcel source) {
     36             return new KeyboardLayout(source);
     37         }
     38         public KeyboardLayout[] newArray(int size) {
     39             return new KeyboardLayout[size];
     40         }
     41     };
     42 
     43     public KeyboardLayout(String descriptor, String label, String collection) {
     44         mDescriptor = descriptor;
     45         mLabel = label;
     46         mCollection = collection;
     47     }
     48 
     49     private KeyboardLayout(Parcel source) {
     50         mDescriptor = source.readString();
     51         mLabel = source.readString();
     52         mCollection = source.readString();
     53     }
     54 
     55     /**
     56      * Gets the keyboard layout descriptor, which can be used to retrieve
     57      * the keyboard layout again later using
     58      * {@link InputManager#getKeyboardLayout(String)}.
     59      *
     60      * @return The keyboard layout descriptor.
     61      */
     62     public String getDescriptor() {
     63         return mDescriptor;
     64     }
     65 
     66     /**
     67      * Gets the keyboard layout descriptive label to show in the user interface.
     68      * @return The keyboard layout descriptive label.
     69      */
     70     public String getLabel() {
     71         return mLabel;
     72     }
     73 
     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 
     83     @Override
     84     public int describeContents() {
     85         return 0;
     86     }
     87 
     88     @Override
     89     public void writeToParcel(Parcel dest, int flags) {
     90         dest.writeString(mDescriptor);
     91         dest.writeString(mLabel);
     92         dest.writeString(mCollection);
     93     }
     94 
     95     @Override
     96     public int compareTo(KeyboardLayout another) {
     97         int result = mLabel.compareToIgnoreCase(another.mLabel);
     98         if (result == 0) {
     99             result = mCollection.compareToIgnoreCase(another.mCollection);
    100         }
    101         return result;
    102     }
    103 
    104     @Override
    105     public String toString() {
    106         if (mCollection.isEmpty()) {
    107             return mLabel;
    108         }
    109         return mLabel + " - " + mCollection;
    110     }
    111 }