Merge "Move MoreKeySpecParser.getResourceId to Utils"
commit
3eede315dc
|
@ -22,6 +22,7 @@ import android.util.Log;
|
||||||
|
|
||||||
import com.android.inputmethod.keyboard.Keyboard;
|
import com.android.inputmethod.keyboard.Keyboard;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
|
import com.android.inputmethod.latin.Utils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -150,8 +151,9 @@ public class MoreKeySpecParser {
|
||||||
if (indexOfLabelEnd(moreKeySpec, end + 1) >= 0) {
|
if (indexOfLabelEnd(moreKeySpec, end + 1) >= 0) {
|
||||||
throw new MoreKeySpecParserError("Multiple " + LABEL_END + ": " + moreKeySpec);
|
throw new MoreKeySpecParserError("Multiple " + LABEL_END + ": " + moreKeySpec);
|
||||||
}
|
}
|
||||||
final int resId = getResourceId(res,
|
final int resId = Utils.getResourceId(res,
|
||||||
moreKeySpec.substring(end + LABEL_END.length() + PREFIX_AT.length()));
|
moreKeySpec.substring(end + LABEL_END.length() + PREFIX_AT.length()),
|
||||||
|
R.string.english_ime_name);
|
||||||
final int code = res.getInteger(resId);
|
final int code = res.getInteger(resId);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -180,15 +182,6 @@ public class MoreKeySpecParser {
|
||||||
return KeyboardIconsSet.ICON_UNDEFINED;
|
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")
|
@SuppressWarnings("serial")
|
||||||
public static class MoreKeySpecParserError extends RuntimeException {
|
public static class MoreKeySpecParserError extends RuntimeException {
|
||||||
public MoreKeySpecParserError(String message) {
|
public MoreKeySpecParserError(String message) {
|
||||||
|
|
|
@ -16,14 +16,6 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
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.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
@ -41,6 +33,14 @@ import android.text.format.DateUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.inputmethod.EditorInfo;
|
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.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -793,4 +793,13 @@ public class Utils {
|
||||||
LatinImeLogger.logOnAutoCorrectionCancelled();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class MoreKeySpecParserTests extends AndroidTestCase {
|
||||||
assertParser(message, moreKeySpec, expectedLabel, expectedOutputText, expectedIcon,
|
assertParser(message, moreKeySpec, expectedLabel, expectedOutputText, expectedIcon,
|
||||||
expectedCode);
|
expectedCode);
|
||||||
fail(message);
|
fail(message);
|
||||||
} catch (MoreKeySpecParser.MoreKeySpecParserError pcpe) {
|
} catch (Exception pcpe) {
|
||||||
// success.
|
// success.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue