Move MoreKeySpecParser.getResourceId to Utils

Change-Id: I0640dbe76a8ff2dc45b504eca631942811571736
main
Tadashi G. Takaoka 2012-01-20 15:47:22 +09:00
parent 2010130e44
commit 0718590486
3 changed files with 22 additions and 20 deletions

View File

@ -22,6 +22,7 @@ import android.util.Log;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Utils;
import java.util.ArrayList;
@ -150,8 +151,9 @@ public class MoreKeySpecParser {
if (indexOfLabelEnd(moreKeySpec, end + 1) >= 0) {
throw new MoreKeySpecParserError("Multiple " + LABEL_END + ": " + moreKeySpec);
}
final int resId = getResourceId(res,
moreKeySpec.substring(end + LABEL_END.length() + PREFIX_AT.length()));
final int resId = Utils.getResourceId(res,
moreKeySpec.substring(end + LABEL_END.length() + PREFIX_AT.length()),
R.string.english_ime_name);
final int code = res.getInteger(resId);
return code;
}
@ -180,15 +182,6 @@ public class MoreKeySpecParser {
return KeyboardIconsSet.ICON_UNDEFINED;
}
private static int getResourceId(Resources res, String name) {
String packageName = res.getResourcePackageName(R.string.english_ime_name);
int resId = res.getIdentifier(name, null, packageName);
if (resId == 0) {
throw new MoreKeySpecParserError("Unknown resource: " + name);
}
return resId;
}
@SuppressWarnings("serial")
public static class MoreKeySpecParserError extends RuntimeException {
public MoreKeySpecParserError(String message) {

View File

@ -16,14 +16,6 @@
package com.android.inputmethod.latin;
import com.android.inputmethod.compat.InputMethodInfoCompatWrapper;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
import com.android.inputmethod.compat.InputTypeCompatUtils;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.latin.define.JniLibName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@ -41,6 +33,14 @@ import android.text.format.DateUtils;
import android.util.Log;
import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.compat.InputMethodInfoCompatWrapper;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
import com.android.inputmethod.compat.InputTypeCompatUtils;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.latin.define.JniLibName;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@ -793,4 +793,13 @@ public class Utils {
LatinImeLogger.logOnAutoCorrectionCancelled();
}
}
public static int getResourceId(Resources res, String name, int packageNameResId) {
String packageName = res.getResourcePackageName(packageNameResId);
int resId = res.getIdentifier(name, null, packageName);
if (resId == 0) {
throw new RuntimeException("Unknown resource: " + name);
}
return resId;
}
}

View File

@ -66,7 +66,7 @@ public class MoreKeySpecParserTests extends AndroidTestCase {
assertParser(message, moreKeySpec, expectedLabel, expectedOutputText, expectedIcon,
expectedCode);
fail(message);
} catch (MoreKeySpecParser.MoreKeySpecParserError pcpe) {
} catch (Exception pcpe) {
// success.
}
}