Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Added handling for native-interface preference from config.xml.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikDemyankov committed Mar 4, 2016
1 parent d5cecf4 commit 9d13f5a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ public class ChcpXmlConfig {
private String configUrl;
private boolean allowUpdatesAutoDownload;
private boolean allowUpdatesAutoInstall;
private int nativeInterfaceVersion;

private ChcpXmlConfig() {
configUrl = "";
allowUpdatesAutoDownload = true;
allowUpdatesAutoInstall = true;
nativeInterfaceVersion = 1;
}

/**
Expand Down Expand Up @@ -80,13 +82,31 @@ public boolean isAutoInstallIsAllowed() {
return allowUpdatesAutoInstall;
}

/**
* Getter for current native interface version of the application.
*
* @return native version
* */
public int getNativeInterfaceVersion() {
return nativeInterfaceVersion;
}

/**
* Setter for current native interface version of the application.
*
* @param version version to set
* */
void setNativeInterfaceVersion(int version) {
nativeInterfaceVersion = version > 0 ? version : 1;
}

/**
* Load plugins specific preferences from Cordova's config.xml.
*
* @param context current context of the activity
* @return hot-code-push plugin preferences
*/
public static ChcpXmlConfig loadFromCordovaConfig(Context context) {
public static ChcpXmlConfig loadFromCordovaConfig(final Context context) {
ChcpXmlConfig chcpConfig = new ChcpXmlConfig();

new ChcpXmlConfigParser().parse(context, chcpConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ChcpXmlConfigParser extends ConfigXmlParser {
* @param chcpConfig config instance to which we will set preferences from config.xml
* @see ChcpXmlConfig
*/
public void parse(Context context, ChcpXmlConfig chcpConfig) {
public void parse(final Context context, final ChcpXmlConfig chcpConfig) {
this.chcpConfig = chcpConfig;

isInsideChcpBlock = false;
Expand All @@ -38,13 +38,13 @@ public void parse(Context context, ChcpXmlConfig chcpConfig) {
}

@Override
public void handleStartTag(XmlPullParser xml) {
public void handleStartTag(final XmlPullParser xml) {
if (didParseChcpBlock) {
return;
return;
}

final String name = xml.getName();
if (name.equals(XmlTags.MAIN_TAG)) {
if (XmlTags.MAIN_TAG.equals(name)) {
isInsideChcpBlock = true;
return;
}
Expand All @@ -55,49 +55,62 @@ public void handleStartTag(XmlPullParser xml) {
}

// parse configuration file preference
if (name.equals(XmlTags.CONFIG_FILE_TAG)) {
if (XmlTags.CONFIG_FILE_TAG.equals(name)) {
processConfigFileBlock(xml);
return;
}

// parse auto download preference
if (name.equals(XmlTags.AUTO_DOWNLOAD_TAG)) {
if (XmlTags.AUTO_DOWNLOAD_TAG.equals(name)) {
processAutoDownloadBlock(xml);
return;
}

// parse auto installation preference
if (name.equals(XmlTags.AUTO_INSTALLATION_TAG)) {
if (XmlTags.AUTO_INSTALLATION_TAG.equals(name)) {
processAutoInstallationBlock(xml);
return;
}

// parse native navigation interface version
if (XmlTags.NATIVE_INTERFACE_TAG.equals(name)) {
processNativeInterfaceBlock(xml);
}
}

@Override
public void handleEndTag(final XmlPullParser xml) {
if (didParseChcpBlock) {
return;
}

final String name = xml.getName();
if (XmlTags.MAIN_TAG.equals(name)) {
didParseChcpBlock = true;
isInsideChcpBlock = false;
}
}

private void processConfigFileBlock(XmlPullParser xml) {
private void processConfigFileBlock(final XmlPullParser xml) {
String configUrl = xml.getAttributeValue(null, XmlTags.CONFIG_FILE_URL_ATTRIBUTE);

chcpConfig.setConfigUrl(configUrl);
}

private void processAutoDownloadBlock(XmlPullParser xml) {
private void processAutoDownloadBlock(final XmlPullParser xml) {
boolean isEnabled = xml.getAttributeValue(null, XmlTags.AUTO_DOWNLOAD_ENABLED_ATTRIBUTE).equals("true");
chcpConfig.allowUpdatesAutoDownload(isEnabled);
}

private void processAutoInstallationBlock(XmlPullParser xml) {
private void processAutoInstallationBlock(final XmlPullParser xml) {
boolean isEnabled = xml.getAttributeValue(null, XmlTags.AUTO_INSTALLATION_ENABLED_ATTRIBUTE).equals("true");
chcpConfig.allowUpdatesAutoInstall(isEnabled);
}

@Override
public void handleEndTag(XmlPullParser xml) {
if (didParseChcpBlock) {
return;
}
private void processNativeInterfaceBlock(final XmlPullParser xml) {
final String nativeVersionStr = xml.getAttributeValue(null, XmlTags.NATIVE_INTERFACE_VERSION_ATTRIBUTE);
final int nativeVersion = Integer.parseInt(nativeVersionStr);

String name = xml.getName();
if (name.equals(XmlTags.MAIN_TAG)) {
didParseChcpBlock = true;
isInsideChcpBlock = false;
}
chcpConfig.setNativeInterfaceVersion(nativeVersion);
}
}
4 changes: 4 additions & 0 deletions src/android/src/com/nordnetab/chcp/main/config/XmlTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ private XmlTags() {
public static final String AUTO_INSTALLATION_TAG = "auto-install";
public static final String AUTO_INSTALLATION_ENABLED_ATTRIBUTE = "enabled";

// keys for native interface version
public static final String NATIVE_INTERFACE_TAG = "native-interface";
public static final String NATIVE_INTERFACE_VERSION_ATTRIBUTE = "version";

}

0 comments on commit 9d13f5a

Please sign in to comment.