Skip to content

Instantly share code, notes, and snippets.

@DavidTPate
Created February 13, 2013 04:38
Show Gist options
  • Save DavidTPate/4942311 to your computer and use it in GitHub Desktop.
Save DavidTPate/4942311 to your computer and use it in GitHub Desktop.
public class LoginConfig {
/**
* Whether to hide Login functionality from the user.
*/
private static boolean mShowSaveUsername = false;
public static boolean getShowSaveUsername() {
return mShowSaveUsername;
}
public static void init(Context context) {
Log.v(TAG, "LoginConfig.init()");
loadLoginSettings(context);
}
private static void loadLoginSettings(Context context) {
XmlResourceParser parser = context.getResources().getXml(R.xml.login_config);
try {
beginDocument(parser, "login_config");
while (true) {
nextElement(parser);
String tag = parser.getName();
if (tag == null) {
break;
}
String name = parser.getAttributeName(0);
String value = parser.getAttributeValue(0);
String text = null;
if (parser.next() == XmlPullParser.TEXT) {
text = parser.getText();
}
Log.v(TAG, "tag: " + tag + " value: " + value + " - " + text);
if ("name".equalsIgnoreCase(name)) {
if ("bool".equals(tag)) {
// bool config tags go here
if ("showSaveUsername".equalsIgnoreCase(value)) {
mShowSaveUsername = "true".equalsIgnoreCase(text);
}
}
}
}
} catch (XmlPullParserException e) {
Log.e(TAG, "loadLoginSettings caught ", e);
} catch (NumberFormatException e) {
Log.e(TAG, "loadLoginSettings caught ", e);
} catch (IOException e) {
Log.e(TAG, "loadLoginSettings caught ", e);
} finally {
parser.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment