/**
* get the Element
* @param context 上下文
* @param resId the id
* @return the Element
*/
public static Element getElement(Context context, int resId) {
Element element = ElementScatter.getInstance(context).parse(resId);
return element;
}
获取Color
/**
* get the color
*
* @param context the context
* @param id the id
* @return the color
*/
public static int getColor(Context context, int id) {
Log.info(TAG, "Entering getColor");
int result = 0;
if (context == null) {
Log.info(TAG, "getColor -> get null context");
return result;
}
ResourceManager manager = context.getResourceManager();
if (manager == null) {
Log.info(TAG, "getColor -> get null ResourceManager");
return result;
}
try {
result = manager.getElement(id).getColor();
} catch (IOException e) {
Log.info(TAG, "getColor -> IOException");
} catch (NotExistException e) {
Log.info(TAG, "getColor -> NotExistException");
} catch (WrongTypeException e) {
Log.info(TAG, "getColor -> WrongTypeException");
}
return result;
}
获取Dimen
/**
* get the dimen value
*
* @param context the context
* @param id the id
* @return get the float dimen value
*/
public static float getDimen(Context context, int id) {
Log.info(TAG, "Entering getDimen");
float result = 0;
if (context == null) {
Log.info(TAG, "getDimen -> get null context");
return result;
}
ResourceManager manager = context.getResourceManager();
if (manager == null) {
Log.info(TAG, "getDimen -> get null ResourceManager");
return result;
}
try {
result = manager.getElement(id).getFloat();
} catch (IOException e) {
Log.info(TAG, "getDimen -> IOException");
} catch (NotExistException e) {
Log.info(TAG, "getDimen -> NotExistException");
} catch (WrongTypeException e) {
Log.info(TAG, "getDimen -> WrongTypeException");
}
return result;
}
获取String
/**
* get string
*
* @param context the context
* @param id the string id
* @return string of the given id
*/
public static String getString(Context context, int id) {
Log.info(TAG, "Entering getString");
String result = "";
if (context == null) {
Log.info(TAG, "getString -> get null context");
return result;
}
ResourceManager manager = context.getResourceManager();
if (manager == null) {
Log.info(TAG, "getString -> get null ResourceManager");
return result;
}
try {
result = manager.getElement(id).getString();
} catch (IOException e) {
Log.info(TAG, "getString -> IOException");
} catch (NotExistException e) {
Log.info(TAG, "getString -> NotExistException");
} catch (WrongTypeException e) {
Log.info(TAG, "getString -> WrongTypeException");
}
return result;
}
获取StringArray
/**
* get the string array
*
* @param context the context
* @param id the string array id
* @return the string array
*/
public static String[] getStringArray(Context context, int id) {
Log.info(TAG, "Entering getStringArray");
String[] result = null;
if (context == null) {
Log.info(TAG, "getStringArray -> get null context");
return result;
}
ResourceManager manager = context.getResourceManager();
if (manager == null) {
Log.info(TAG, "getStringArray -> get null ResourceManager");
return result;
}
try {
result = manager.getElement(id).getStringArray();
} catch (IOException e) {
Log.info(TAG, "getStringArray -> IOException");
} catch (NotExistException e) {
Log.info(TAG, "getStringArray -> NotExistException");
} catch (WrongTypeException e) {
Log.info(TAG, "getStringArray -> WrongTypeException");
}
return result;
}
获取IntArray
/**
* get the int array
*
* @param context the context
* @param id the int array
* @return the int array
*/
public static int[] getIntArray(Context context, int id) {
Log.info(TAG, "Entering getIntArray");
int[] result = null;
if (context == null) {
Log.info(TAG, "getIntArray -> get null context");
return result;
}
ResourceManager manager = context.getResourceManager();
if (manager == null) {
Log.info(TAG, "getIntArray -> get null ResourceManager");
return result;
}
try {
result = manager.getElement(id).getIntArray();
} catch (IOException e) {
Log.info(TAG, "getIntArray -> IOException");
} catch (NotExistException e) {
Log.info(TAG, "getIntArray -> NotExistException");
} catch (WrongTypeException e) {
Log.info(TAG, "getIntArray -> WrongTypeException");
}
return result;
}
获取Boolean
/**
* get boolean
*
* @param context the context
* @param id the boolean id
* @return boolean of the given id
*/
public static boolean getBoolean(Context context, int id) {
Log.info(TAG, "Entering getBoolean");
boolean result = false;
if (context == null) {
Log.info(TAG, "getBoolean -> get null context");
return result;
}
ResourceManager manager = context.getResourceManager();
if (manager == null) {
Log.info(TAG, "getBoolean -> get null ResourceManager");
return result;
}
try {
result = manager.getElement(id).getBoolean();
} catch (IOException e) {
Log.info(TAG, "getBoolean -> IOException");
} catch (NotExistException e) {
Log.info(TAG, "getBoolean -> NotExistException");
} catch (WrongTypeException e) {
Log.info(TAG, "getBoolean -> WrongTypeException");
}
return result;
}