LatinIME/tools/makelabel/res/com/android/inputmethod/keyboard/internal/KeyboardLabelsSet.tmpl

118 lines
3.8 KiB
Cheetah

/*
* Copyright (C) 2012 The Android Open Source Project
*
* 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.android.inputmethod.keyboard.internal;
import android.content.Context;
import android.content.res.Resources;
import com.android.inputmethod.latin.R;
import java.util.HashMap;
/**
* !!!!! DO NOT EDIT THIS FILE !!!!!
* This file is generated by tools/makelabel.
*/
public final class KeyboardLabelsSet {
// Language to labels map.
private static final HashMap<String, String[]> sLocaleToLabelsMap =
new HashMap<String, String[]>();
private static final HashMap<String, Integer> sNameToIdMap = new HashMap<String, Integer>();
private String[] mLabels;
// Resource name to label map.
private HashMap<String, String> mResourceNameToLabelsMap = new HashMap<String, String>();
public void setLanguage(final String language) {
mLabels = sLocaleToLabelsMap.get(language);
if (mLabels == null) {
mLabels = LANGUAGE_DEFAULT;
}
}
public void loadStringResources(Context context) {
loadStringResourcesInternal(context, RESOURCE_NAMES, R.string.english_ime_name);
}
/* package for test */
void loadStringResourcesInternal(Context context, final String[] resourceNames,
int referenceId) {
final Resources res = context.getResources();
final String packageName = res.getResourcePackageName(referenceId);
for (final String resName : resourceNames) {
final int resId = res.getIdentifier(resName, "string", packageName);
mResourceNameToLabelsMap.put(resName, res.getString(resId));
}
}
public String getLabel(final String name) {
if (mResourceNameToLabelsMap.containsKey(name)) {
return mResourceNameToLabelsMap.get(name);
}
final Integer id = sNameToIdMap.get(name);
if (id == null) throw new RuntimeException("Unknown label: " + name);
final String label = (id < mLabels.length) ? mLabels[id] : null;
return (label == null) ? LANGUAGE_DEFAULT[id] : label;
}
private static final String[] RESOURCE_NAMES = {
// These labels' name should be aligned with the @string/<name> in values/strings.xml.
// Labels for action.
"label_go_key",
// "label_search_key",
"label_send_key",
"label_next_key",
"label_done_key",
"label_previous_key",
// Other labels.
"label_to_alpha_key",
"label_to_symbol_key",
"label_to_symbol_with_microphone_key",
"label_pause_key",
"label_wait_key",
};
private static final String[] NAMES = {
/* @NAMES@ */
};
private static final String EMPTY = "";
/* Default labels */
private static final String[] LANGUAGE_DEFAULT = {
/* @DEFAULT_LABELS@ */
};
/* @LABELS@ */
private static final Object[] LANGUAGES_AND_LABELS = {
/* @LANGUAGES_AND_LABELS@ */
};
static {
int id = 0;
for (final String name : NAMES) {
sNameToIdMap.put(name, id++);
}
for (int i = 0; i < LANGUAGES_AND_LABELS.length; i += 2) {
final String language = (String)LANGUAGES_AND_LABELS[i];
final String[] labels = (String[])LANGUAGES_AND_LABELS[i + 1];
sLocaleToLabelsMap.put(language, labels);
}
}
}