2012-04-05 06:59:55 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* 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
|
2012-04-05 06:59:55 +01:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-04-05 06:59:55 +01:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-01-21 12:52:57 +00:00
|
|
|
* 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.
|
2012-04-05 06:59:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.keyboard.internal;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
|
2012-10-26 07:29:52 +01:00
|
|
|
import com.android.inputmethod.annotations.UsedForTesting;
|
2013-07-03 11:05:32 +01:00
|
|
|
import com.android.inputmethod.latin.utils.CollectionUtils;
|
2012-04-05 06:59:55 +01:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* !!!!! DO NOT EDIT THIS FILE !!!!!
|
2012-04-24 04:13:16 +01:00
|
|
|
*
|
|
|
|
* This file is generated by tools/maketext. The base template file is
|
|
|
|
* tools/maketext/res/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.tmpl
|
|
|
|
*
|
|
|
|
* This file must be updated when any text resources in keyboard layout files have been changed.
|
|
|
|
* These text resources are referred as "!text/<resource_name>" in keyboard XML definitions,
|
|
|
|
* and should be defined in
|
|
|
|
* tools/maketext/res/values-<locale>/donottranslate-more-keys.xml
|
|
|
|
*
|
|
|
|
* To update this file, please run the following commands.
|
|
|
|
* $ cd $ANDROID_BUILD_TOP
|
|
|
|
* $ mmm packages/inputmethods/LatinIME/tools/maketext
|
|
|
|
* $ maketext -java packages/inputmethods/LatinIME/java/src
|
|
|
|
*
|
|
|
|
* The updated source file will be generated to the following path (this file).
|
|
|
|
* packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/internal/
|
|
|
|
* KeyboardTextsSet.java
|
2012-04-05 06:59:55 +01:00
|
|
|
*/
|
2012-04-20 00:39:11 +01:00
|
|
|
public final class KeyboardTextsSet {
|
|
|
|
// Language to texts map.
|
2012-08-21 08:34:55 +01:00
|
|
|
private static final HashMap<String, String[]> sLocaleToTextsMap = CollectionUtils.newHashMap();
|
|
|
|
private static final HashMap<String, Integer> sNameToIdsMap = CollectionUtils.newHashMap();
|
2012-04-05 06:59:55 +01:00
|
|
|
|
2012-04-20 00:39:11 +01:00
|
|
|
private String[] mTexts;
|
|
|
|
// Resource name to text map.
|
2012-08-21 08:34:55 +01:00
|
|
|
private HashMap<String, String> mResourceNameToTextsMap = CollectionUtils.newHashMap();
|
2012-04-05 06:59:55 +01:00
|
|
|
|
|
|
|
public void setLanguage(final String language) {
|
2012-04-20 00:39:11 +01:00
|
|
|
mTexts = sLocaleToTextsMap.get(language);
|
|
|
|
if (mTexts == null) {
|
|
|
|
mTexts = LANGUAGE_DEFAULT;
|
2012-04-05 06:59:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 04:52:52 +00:00
|
|
|
public void loadStringResources(final Context context) {
|
|
|
|
final int referenceId = context.getApplicationInfo().labelRes;
|
|
|
|
loadStringResourcesInternal(context, RESOURCE_NAMES, referenceId);
|
2012-04-05 06:59:55 +01:00
|
|
|
}
|
|
|
|
|
2012-10-26 07:29:52 +01:00
|
|
|
@UsedForTesting
|
2013-03-22 04:52:52 +00:00
|
|
|
void loadStringResourcesInternal(final Context context, final String[] resourceNames,
|
|
|
|
final int referenceId) {
|
2012-04-05 06:59:55 +01:00
|
|
|
final Resources res = context.getResources();
|
|
|
|
final String packageName = res.getResourcePackageName(referenceId);
|
|
|
|
for (final String resName : resourceNames) {
|
|
|
|
final int resId = res.getIdentifier(resName, "string", packageName);
|
2012-04-20 00:39:11 +01:00
|
|
|
mResourceNameToTextsMap.put(resName, res.getString(resId));
|
2012-04-05 06:59:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-20 00:39:11 +01:00
|
|
|
public String getText(final String name) {
|
|
|
|
String text = mResourceNameToTextsMap.get(name);
|
|
|
|
if (text != null) {
|
|
|
|
return text;
|
2012-04-19 20:35:04 +01:00
|
|
|
}
|
2012-05-28 04:27:18 +01:00
|
|
|
final Integer id = sNameToIdsMap.get(name);
|
2012-04-05 06:59:55 +01:00
|
|
|
if (id == null) throw new RuntimeException("Unknown label: " + name);
|
2012-04-20 00:39:11 +01:00
|
|
|
text = (id < mTexts.length) ? mTexts[id] : null;
|
|
|
|
return (text == null) ? LANGUAGE_DEFAULT[id] : text;
|
2012-04-05 06:59:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static final String[] RESOURCE_NAMES = {
|
2012-04-20 00:39:11 +01:00
|
|
|
// These texts' name should be aligned with the @string/<name> in values/strings.xml.
|
2012-04-05 06:59:55 +01:00
|
|
|
// Labels for action.
|
|
|
|
"label_go_key",
|
|
|
|
// "label_search_key",
|
|
|
|
"label_send_key",
|
|
|
|
"label_next_key",
|
|
|
|
"label_done_key",
|
|
|
|
"label_previous_key",
|
|
|
|
// Other labels.
|
|
|
|
"label_pause_key",
|
|
|
|
"label_wait_key",
|
|
|
|
};
|
|
|
|
|
|
|
|
private static final String[] NAMES = {
|
|
|
|
/* @NAMES@ */
|
|
|
|
};
|
|
|
|
|
|
|
|
private static final String EMPTY = "";
|
|
|
|
|
2012-04-20 00:39:11 +01:00
|
|
|
/* Default texts */
|
2012-04-05 06:59:55 +01:00
|
|
|
private static final String[] LANGUAGE_DEFAULT = {
|
2012-04-20 00:39:11 +01:00
|
|
|
/* @DEFAULT_TEXTS@ */
|
2012-04-05 06:59:55 +01:00
|
|
|
};
|
|
|
|
|
2012-04-20 00:39:11 +01:00
|
|
|
/* @TEXTS@ */
|
|
|
|
private static final Object[] LANGUAGES_AND_TEXTS = {
|
|
|
|
/* @LANGUAGES_AND_TEXTS@ */
|
2012-04-05 06:59:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static {
|
|
|
|
int id = 0;
|
|
|
|
for (final String name : NAMES) {
|
2012-05-28 04:27:18 +01:00
|
|
|
sNameToIdsMap.put(name, id++);
|
2012-04-05 06:59:55 +01:00
|
|
|
}
|
|
|
|
|
2012-04-20 00:39:11 +01:00
|
|
|
for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) {
|
|
|
|
final String language = (String)LANGUAGES_AND_TEXTS[i];
|
|
|
|
final String[] texts = (String[])LANGUAGES_AND_TEXTS[i + 1];
|
|
|
|
sLocaleToTextsMap.put(language, texts);
|
2012-04-05 06:59:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|