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
17package com.android.inputmethod.keyboard.internal;
18
19import android.content.res.TypedArray;
20
21import javax.annotation.Nonnull;
22import javax.annotation.Nullable;
23
24public abstract class KeyStyle {
25    private final KeyboardTextsSet mTextsSet;
26
27    public abstract @Nullable String[] getStringArray(TypedArray a, int index);
28    public abstract @Nullable String getString(TypedArray a, int index);
29    public abstract int getInt(TypedArray a, int index, int defaultValue);
30    public abstract int getFlags(TypedArray a, int index);
31
32    protected KeyStyle(@Nonnull final KeyboardTextsSet textsSet) {
33        mTextsSet = textsSet;
34    }
35
36    @Nullable
37    protected String parseString(final TypedArray a, final int index) {
38        if (a.hasValue(index)) {
39            return mTextsSet.resolveTextReference(a.getString(index));
40        }
41        return null;
42    }
43
44    @Nullable
45    protected String[] parseStringArray(final TypedArray a, final int index) {
46        if (a.hasValue(index)) {
47            final String text = mTextsSet.resolveTextReference(a.getString(index));
48            return MoreKeySpec.splitKeySpecs(text);
49        }
50        return null;
51    }
52}
53