summaryrefslogtreecommitdiff
path: root/display/BrailleDisplayProperties.java
blob: 606476f68dffe754cecf258c9bc37e61ff24f93c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright (C) 2012 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.googlecode.eyesfree.braille.display;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Properties of a braille display such as dimensions and keyboard
 * configuration.
 */
public class BrailleDisplayProperties implements Parcelable {
    private final int mNumTextCells;
    private final int mNumStatusCells;
    private final BrailleKeyBinding[] mKeyBindings;
    private final Map<String, String> mFriendlyKeyNames;

    public BrailleDisplayProperties(int numTextCells, int numStatusCells,
            BrailleKeyBinding[] keyBindings,
            Map<String, String> friendlyKeyNames) {
        mNumTextCells = numTextCells;
        mNumStatusCells = numStatusCells;
        mKeyBindings = keyBindings;
        mFriendlyKeyNames = friendlyKeyNames;
    }

    /**
     * Returns the number of cells on the main display intended for display of
     * text or other content.
     */
    public int getNumTextCells() {
        return mNumTextCells;
    }

    /**
     * Returns the number of status cells that are separated from the main
     * display.  This value will be {@code 0} for displays without any separate
     * status cells.
     */
    public int getNumStatusCells() {
        return mNumStatusCells;
    }

    /**
     * Returns the list of key bindings for this display.
     */
    public BrailleKeyBinding[] getKeyBindings() {
        return mKeyBindings;
    }

    /**
     * Returns an unmodifiable map mapping key names in {@link BrailleKeyBinding}
     * objects to localized user-friendly key names.
     */
    public Map<String, String> getFriendlyKeyNames() {
        return mFriendlyKeyNames;
    }

    @Override
    public String toString() {
        return String.format(
            "BrailleDisplayProperties [numTextCells: %d, numStatusCells: %d, "
            + "keyBindings: %d]",
            mNumTextCells, mNumStatusCells, mKeyBindings.length);
    }

    // For Parcelable support.

    public static final Parcelable.Creator<BrailleDisplayProperties> CREATOR =
        new Parcelable.Creator<BrailleDisplayProperties>() {
            @Override
            public BrailleDisplayProperties createFromParcel(Parcel in) {
                return new BrailleDisplayProperties(in);
            }

            @Override
            public BrailleDisplayProperties[] newArray(int size) {
                return new BrailleDisplayProperties[size];
            }
        };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(mNumTextCells);
        out.writeInt(mNumStatusCells);
        out.writeTypedArray(mKeyBindings, flags);
        out.writeInt(mFriendlyKeyNames.size());
        for (Map.Entry<String, String> entry : mFriendlyKeyNames.entrySet()) {
            out.writeString(entry.getKey());
            out.writeString(entry.getValue());
        }
    }

    private BrailleDisplayProperties(Parcel in) {
        mNumTextCells = in.readInt();
        mNumStatusCells = in.readInt();
        mKeyBindings = in.createTypedArray(BrailleKeyBinding.CREATOR);
        int size = in.readInt();
        Map<String, String> names = new HashMap<String, String>(size);
        for (int i = 0; i < size; ++i) {
            names.put(in.readString(), in.readString());
        }
        mFriendlyKeyNames = Collections.unmodifiableMap(names);
    }
}