Permalink
Browse files

Android SVG cache folder option, closes #914

  • Loading branch information...
1 parent f9b9569 commit 284472475f038092443c6e6b246a3bc7779fc978 @devemux86 devemux86 committed Dec 31, 2016
View
@@ -3,6 +3,7 @@
## New since 0.7.0
- Android tile cache folder option [#913](https://github.com/mapsforge/mapsforge/issues/913)
+- Android SVG cache folder option [#914](https://github.com/mapsforge/mapsforge/issues/914)
- Desktop tile cache creation utility [#915](https://github.com/mapsforge/mapsforge/issues/915)
- Many other minor improvements and bug fixes
- [Solved issues](https://github.com/mapsforge/mapsforge/issues?q=is%3Aissue+is%3Aclosed+milestone%3A0.8.0)
@@ -1,7 +1,7 @@
/*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014 Ludwig M Brinckmann
- * Copyright 2014-2016 devemux86
+ * Copyright 2014-2017 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -42,6 +42,7 @@
import org.mapsforge.core.model.Point;
import org.mapsforge.map.model.DisplayModel;
+import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -165,6 +166,7 @@ static int getColor(Color color) {
}
private final Application application;
+ private File svgCacheDir;
private AndroidGraphicFactory(Application app) {
this.application = app;
@@ -257,27 +259,39 @@ public TileBitmap createTileBitmap(int tileSize, boolean isTransparent) {
* Android method accessible only via Context.
*/
public boolean deleteFile(String name) {
+ if (this.svgCacheDir != null) {
+ return new File(this.svgCacheDir, name).delete();
+ }
return this.application.deleteFile(name);
}
/*
* Android method accessible only via Context.
*/
public String[] fileList() {
+ if (this.svgCacheDir != null) {
+ return this.svgCacheDir.list();
+ }
return this.application.fileList();
}
/*
* Android method accessible only via Context.
*/
public FileInputStream openFileInput(String name) throws FileNotFoundException {
+ if (this.svgCacheDir != null) {
+ return new FileInputStream(new File(this.svgCacheDir, name));
+ }
return this.application.openFileInput(name);
}
/*
* Android method accessible only via Context.
*/
public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException {
+ if (this.svgCacheDir != null) {
+ return new FileOutputStream(new File(this.svgCacheDir, name), mode == Context.MODE_APPEND);
+ }
return this.application.openFileOutput(name, mode);
}
@@ -297,4 +311,7 @@ public ResourceBitmap renderSvg(InputStream inputStream, float scaleFactor, int
return new AndroidSvgBitmap(inputStream, hash, scaleFactor, width, height, percent);
}
+ public void setSvgCacheDir(File svgCacheDir) {
+ this.svgCacheDir = svgCacheDir;
+ }
}
@@ -1,6 +1,6 @@
/*
* Copyright 2013-2015 Ludwig M Brinckmann
- * Copyright 2014-2016 devemux86
+ * Copyright 2014-2017 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -34,6 +34,8 @@
import android.widget.LinearLayout;
import android.widget.TextView;
+import org.mapsforge.map.android.graphics.AndroidGraphicFactory;
+
/**
* Start screen for the sample activities.
*/
@@ -187,6 +189,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
startActivity(intent);
return true;
+ case R.id.menu_svgclear:
+ AndroidGraphicFactory.clearResourceFileCache();
+ break;
}
return false;
}
@@ -204,7 +209,7 @@ public void onResume() {
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- preferences.edit().putBoolean(accepted, true).commit();
+ preferences.edit().putBoolean(accepted, true).apply();
}
});
builder.setMessage(R.string.startup_message);
@@ -225,7 +230,7 @@ private void startupDialog(String prefs, int message, final Class clazz) {
builder.setPositiveButton(R.string.startup_dontshowagain, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- preferences.edit().putBoolean(accepted, true).commit();
+ preferences.edit().putBoolean(accepted, true).apply();
startActivity(new Intent(Samples.this, clazz));
}
});

0 comments on commit 2844724

Please sign in to comment.