mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
2f16fd40fa
Change-Id: I76c3e9179dd8777d3cf3138ad76513d83672debf
128 lines
4.2 KiB
Cheetah
128 lines
4.2 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> sLowerCaseNameToIdsMap =
|
|
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) {
|
|
String lowerCaseName = null;
|
|
String label = mResourceNameToLabelsMap.get(name);
|
|
if (label == null) {
|
|
lowerCaseName = name.toLowerCase();
|
|
label = mResourceNameToLabelsMap.get(lowerCaseName);
|
|
}
|
|
if (label != null) {
|
|
return label;
|
|
}
|
|
Integer id = sLowerCaseNameToIdsMap.get(name);
|
|
if (id == null) {
|
|
id = sLowerCaseNameToIdsMap.get(lowerCaseName); // lowerCaseName != null
|
|
}
|
|
if (id == null) throw new RuntimeException("Unknown label: " + name);
|
|
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) {
|
|
sLowerCaseNameToIdsMap.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);
|
|
}
|
|
}
|
|
}
|