Home | History | Annotate | Download | only in display
      1 /*
      2  * Copyright (C) 2012 Google Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
      5  * use this file except in compliance with the License. You may obtain a copy of
      6  * 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, WITHOUT
     12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     13  * License for the specific language governing permissions and limitations under
     14  * the License.
     15  */
     16 
     17 package com.googlecode.eyesfree.braille.display;
     18 
     19 import android.os.Parcel;
     20 import android.os.Parcelable;
     21 
     22 import java.util.Collections;
     23 import java.util.HashMap;
     24 import java.util.Map;
     25 
     26 /**
     27  * Properties of a braille display such as dimensions and keyboard
     28  * configuration.
     29  */
     30 public class BrailleDisplayProperties implements Parcelable {
     31     private final int mNumTextCells;
     32     private final int mNumStatusCells;
     33     private final BrailleKeyBinding[] mKeyBindings;
     34     private final Map<String, String> mFriendlyKeyNames;
     35 
     36     public BrailleDisplayProperties(int numTextCells, int numStatusCells,
     37             BrailleKeyBinding[] keyBindings,
     38             Map<String, String> friendlyKeyNames) {
     39         mNumTextCells = numTextCells;
     40         mNumStatusCells = numStatusCells;
     41         mKeyBindings = keyBindings;
     42         mFriendlyKeyNames = friendlyKeyNames;
     43     }
     44 
     45     /**
     46      * Returns the number of cells on the main display intended for display of
     47      * text or other content.
     48      */
     49     public int getNumTextCells() {
     50         return mNumTextCells;
     51     }
     52 
     53     /**
     54      * Returns the number of status cells that are separated from the main
     55      * display.  This value will be {@code 0} for displays without any separate
     56      * status cells.
     57      */
     58     public int getNumStatusCells() {
     59         return mNumStatusCells;
     60     }
     61 
     62     /**
     63      * Returns the list of key bindings for this display.
     64      */
     65     public BrailleKeyBinding[] getKeyBindings() {
     66         return mKeyBindings;
     67     }
     68 
     69     /**
     70      * Returns an unmodifiable map mapping key names in {@link BrailleKeyBinding}
     71      * objects to localized user-friendly key names.
     72      */
     73     public Map<String, String> getFriendlyKeyNames() {
     74         return mFriendlyKeyNames;
     75     }
     76 
     77     @Override
     78     public String toString() {
     79         return String.format(
     80             "BrailleDisplayProperties [numTextCells: %d, numStatusCells: %d, "
     81             + "keyBindings: %d]",
     82             mNumTextCells, mNumStatusCells, mKeyBindings.length);
     83     }
     84 
     85     // For Parcelable support.
     86 
     87     public static final Parcelable.Creator<BrailleDisplayProperties> CREATOR =
     88         new Parcelable.Creator<BrailleDisplayProperties>() {
     89             @Override
     90             public BrailleDisplayProperties createFromParcel(Parcel in) {
     91                 return new BrailleDisplayProperties(in);
     92             }
     93 
     94             @Override
     95             public BrailleDisplayProperties[] newArray(int size) {
     96                 return new BrailleDisplayProperties[size];
     97             }
     98         };
     99 
    100     @Override
    101     public int describeContents() {
    102         return 0;
    103     }
    104 
    105     @Override
    106     public void writeToParcel(Parcel out, int flags) {
    107         out.writeInt(mNumTextCells);
    108         out.writeInt(mNumStatusCells);
    109         out.writeTypedArray(mKeyBindings, flags);
    110         out.writeInt(mFriendlyKeyNames.size());
    111         for (Map.Entry<String, String> entry : mFriendlyKeyNames.entrySet()) {
    112             out.writeString(entry.getKey());
    113             out.writeString(entry.getValue());
    114         }
    115     }
    116 
    117     private BrailleDisplayProperties(Parcel in) {
    118         mNumTextCells = in.readInt();
    119         mNumStatusCells = in.readInt();
    120         mKeyBindings = in.createTypedArray(BrailleKeyBinding.CREATOR);
    121         int size = in.readInt();
    122         Map<String, String> names = new HashMap<String, String>(size);
    123         for (int i = 0; i < size; ++i) {
    124             names.put(in.readString(), in.readString());
    125         }
    126         mFriendlyKeyNames = Collections.unmodifiableMap(names);
    127     }
    128 }
    129