forked from extern/Unexpected-Keyboard
refactoring: safer KeyboardData.load
This commit is contained in:
parent
a1be402638
commit
fb93d841a5
@ -193,21 +193,22 @@ public final class KeyboardData
|
|||||||
/** Load a layout from a resource ID. Returns [null] on error. */
|
/** Load a layout from a resource ID. Returns [null] on error. */
|
||||||
public static KeyboardData load(Resources res, int id)
|
public static KeyboardData load(Resources res, int id)
|
||||||
{
|
{
|
||||||
KeyboardData l = _layoutCache.get(id);
|
if (_layoutCache.containsKey(id))
|
||||||
if (l == null)
|
return _layoutCache.get(id);
|
||||||
|
KeyboardData l = null;
|
||||||
|
XmlResourceParser parser = null;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
parser = res.getXml(id);
|
||||||
{
|
l = parse_keyboard(parser);
|
||||||
XmlResourceParser parser = res.getXml(id);
|
|
||||||
l = parse_keyboard(parser);
|
|
||||||
parser.close();
|
|
||||||
_layoutCache.put(id, l);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logs.exn("Failed to load layout id " + id, e);
|
||||||
|
}
|
||||||
|
if (parser != null)
|
||||||
|
parser.close();
|
||||||
|
_layoutCache.put(id, l);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user