diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java
index ae3babfd..1ea70ca3 100644
--- a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java
+++ b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java
@@ -6,12 +6,18 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
+import android.os.Environment;
import android.webkit.JavascriptInterface;
import android.widget.Toast;
import com.cradle.iitc_mobile.IITC_NavigationHelper.Pane;
import com.cradle.iitc_mobile.share.ShareActivity;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
// provide communication between IITC script and android app
public class IITC_JSInterface {
// context of main activity
@@ -232,4 +238,18 @@ public class IITC_JSInterface {
public void setPermalink(final String href) {
mIitc.setPermalink(href);
}
+
+ @JavascriptInterface
+ public void saveFile(final String filename, final String type, final String content) {
+ try {
+ final File outFile = new File(Environment.getExternalStorageDirectory().getPath() +
+ "/IITC_Mobile/drawn_items/" + filename);
+ outFile.getParentFile().mkdirs();
+ final FileOutputStream outStream = new FileOutputStream(outFile);
+ IITC_FileManager.copyStream(new ByteArrayInputStream(content.getBytes("UTF-8")), outStream, true);
+ Toast.makeText(mIitc, "Drawn items exported to " + outFile.getPath(), Toast.LENGTH_SHORT).show();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterfaceKitkat.java b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterfaceKitkat.java
index 4e8256b6..6adf1a84 100644
--- a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterfaceKitkat.java
+++ b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterfaceKitkat.java
@@ -10,6 +10,7 @@ public class IITC_JSInterfaceKitkat extends IITC_JSInterface {
}
@JavascriptInterface
+ @Override
public void saveFile(final String filename, final String type, final String content) {
mIitc.getFileManager().new FileSaveRequest(filename, type, content);
diff --git a/plugins/draw-tools.user.js b/plugins/draw-tools.user.js
index 64a1aa1c..865a71e8 100644
--- a/plugins/draw-tools.user.js
+++ b/plugins/draw-tools.user.js
@@ -285,7 +285,7 @@ window.plugin.drawTools.manualOpt = function() {
+ 'Paste Drawn Items'
+ (window.requestFile != undefined
? 'Import Drawn Items' : '')
- + ((typeof android !== 'undefined' && android && android.saveFile) // saveFile only exists on Kitkat+!
+ + ((typeof android !== 'undefined' && android && android.saveFile)
? 'Export Drawn Items' : '')
+ 'Reset Drawn Items'
+ '';
@@ -332,7 +332,7 @@ window.plugin.drawTools.optCopy = function() {
}
window.plugin.drawTools.optExport = function() {
- if(typeof android !== 'undefined' && android && android.saveFile) { // saveFile only exists on Kitkat+!
+ if(typeof android !== 'undefined' && android && android.saveFile) {
android.saveFile('IITC-drawn-items.json', 'application/json', localStorage['plugin-draw-tools-layer']);
}
}