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 com.android.inputmethod.keyboard.internal; 18 19 import android.content.res.TypedArray; 20 21 import javax.annotation.Nonnull; 22 import javax.annotation.Nullable; 23 24 public abstract class KeyStyle { 25 private final KeyboardTextsSet mTextsSet; 26 getStringArray(TypedArray a, int index)27 public abstract @Nullable String[] getStringArray(TypedArray a, int index); getString(TypedArray a, int index)28 public abstract @Nullable String getString(TypedArray a, int index); getInt(TypedArray a, int index, int defaultValue)29 public abstract int getInt(TypedArray a, int index, int defaultValue); getFlags(TypedArray a, int index)30 public abstract int getFlags(TypedArray a, int index); 31 KeyStyle(@onnull final KeyboardTextsSet textsSet)32 protected KeyStyle(@Nonnull final KeyboardTextsSet textsSet) { 33 mTextsSet = textsSet; 34 } 35 36 @Nullable parseString(final TypedArray a, final int index)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 parseStringArray(final TypedArray a, final int index)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