mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2024-11-21 23:03:11 +01:00
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. */
|
||||
public static KeyboardData load(Resources res, int id)
|
||||
{
|
||||
KeyboardData l = _layoutCache.get(id);
|
||||
if (l == null)
|
||||
{
|
||||
if (_layoutCache.containsKey(id))
|
||||
return _layoutCache.get(id);
|
||||
KeyboardData l = null;
|
||||
XmlResourceParser parser = null;
|
||||
try
|
||||
{
|
||||
XmlResourceParser parser = res.getXml(id);
|
||||
parser = res.getXml(id);
|
||||
l = parse_keyboard(parser);
|
||||
parser.close();
|
||||
_layoutCache.put(id, l);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
Logs.exn("Failed to load layout id " + id, e);
|
||||
}
|
||||
if (parser != null)
|
||||
parser.close();
|
||||
_layoutCache.put(id, l);
|
||||
return l;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user