added support for draw tools file export on Android < 4.4
This commit is contained in:
parent
816b3d355f
commit
903fa4f904
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -285,7 +285,7 @@ window.plugin.drawTools.manualOpt = function() {
|
||||
+ '<a onclick="window.plugin.drawTools.optPaste();return false;">Paste Drawn Items</a>'
|
||||
+ (window.requestFile != undefined
|
||||
? '<a onclick="window.plugin.drawTools.optImport();return false;">Import Drawn Items</a>' : '')
|
||||
+ ((typeof android !== 'undefined' && android && android.saveFile) // saveFile only exists on Kitkat+!
|
||||
+ ((typeof android !== 'undefined' && android && android.saveFile)
|
||||
? '<a onclick="window.plugin.drawTools.optExport();return false;">Export Drawn Items</a>' : '')
|
||||
+ '<a onclick="window.plugin.drawTools.optReset();return false;">Reset Drawn Items</a>'
|
||||
+ '</div>';
|
||||
@ -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']);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user