From 9d13f5ae5957348059328bbd019b133ac24c4a79 Mon Sep 17 00:00:00 2001 From: Nikolay Demyankov Date: Fri, 4 Mar 2016 10:45:05 +0100 Subject: [PATCH] Added handling for native-interface preference from config.xml. --- .../chcp/main/config/ChcpXmlConfig.java | 22 +++++++- .../chcp/main/config/ChcpXmlConfigParser.java | 53 ++++++++++++------- .../nordnetab/chcp/main/config/XmlTags.java | 4 ++ 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/src/android/src/com/nordnetab/chcp/main/config/ChcpXmlConfig.java b/src/android/src/com/nordnetab/chcp/main/config/ChcpXmlConfig.java index 2f0da740..7fff6659 100644 --- a/src/android/src/com/nordnetab/chcp/main/config/ChcpXmlConfig.java +++ b/src/android/src/com/nordnetab/chcp/main/config/ChcpXmlConfig.java @@ -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; } /** @@ -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); diff --git a/src/android/src/com/nordnetab/chcp/main/config/ChcpXmlConfigParser.java b/src/android/src/com/nordnetab/chcp/main/config/ChcpXmlConfigParser.java index c0e4eb0c..8c486778 100644 --- a/src/android/src/com/nordnetab/chcp/main/config/ChcpXmlConfigParser.java +++ b/src/android/src/com/nordnetab/chcp/main/config/ChcpXmlConfigParser.java @@ -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; @@ -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; } @@ -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); } } diff --git a/src/android/src/com/nordnetab/chcp/main/config/XmlTags.java b/src/android/src/com/nordnetab/chcp/main/config/XmlTags.java index d2dc5c65..9791aa57 100644 --- a/src/android/src/com/nordnetab/chcp/main/config/XmlTags.java +++ b/src/android/src/com/nordnetab/chcp/main/config/XmlTags.java @@ -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"; + }