Drop beanshell for android 9+. Replaced by rnd pattern.
This commit is contained in:
parent
2ecb2a556a
commit
df68cc70b3
1 changed files with 46 additions and 18 deletions
|
@ -3,6 +3,7 @@ package net.osmand.plus;
|
|||
import android.database.sqlite.SQLiteDiskIOException;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Build;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
|
@ -24,6 +25,8 @@ import java.nio.ByteBuffer;
|
|||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import bsh.Interpreter;
|
||||
|
||||
|
@ -53,6 +56,8 @@ public class SQLiteTileSource implements ITileSource {
|
|||
private OsmandApplication ctx;
|
||||
private boolean onlyReadonlyAvailable = false;
|
||||
|
||||
private static final Pattern RND_PATTERN =
|
||||
Pattern.compile(".*(\\{rnd:([0-9a-zA-Z-_~:\\/?#\\[\\]@!$&'\\(\\)*+,;=]+)\\}).*");
|
||||
|
||||
|
||||
public SQLiteTileSource(OsmandApplication ctx, File f, List<TileSourceTemplate> toFindUrl){
|
||||
|
@ -116,7 +121,27 @@ public class SQLiteTileSource implements ITileSource {
|
|||
return null;
|
||||
}
|
||||
|
||||
if(TileSourceManager.RULE_BEANSHELL.equalsIgnoreCase(rule)){
|
||||
String urlTemplate = this.urlTemplate;
|
||||
try {
|
||||
Matcher matcher = RND_PATTERN.matcher(urlTemplate);
|
||||
if (matcher.matches()) {
|
||||
int i = 0;
|
||||
String rndString = matcher.group(1);
|
||||
String valuesString = matcher.group(2);
|
||||
if (!Algorithms.isEmpty(valuesString)) {
|
||||
String[] valuesArray = valuesString.split(",");
|
||||
if (valuesArray.length > 0) {
|
||||
i = ((x + y) % valuesArray.length);
|
||||
}
|
||||
}
|
||||
urlTemplate = urlTemplate.replace(rndString, i + "");
|
||||
return MessageFormat.format(urlTemplate, zoom + "", x + "", y + "");
|
||||
|
||||
} else if (TileSourceManager.RULE_BEANSHELL.equalsIgnoreCase(rule)) {
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
Toast.makeText(ctx, "Beanshell is not supported on Android 9+ anymore. Use {rnd:1,2,3,a,b,c} pattern instead.", Toast.LENGTH_LONG).show();
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
if (bshInterpreter == null) {
|
||||
bshInterpreter = new Interpreter();
|
||||
|
@ -129,9 +154,12 @@ public class SQLiteTileSource implements ITileSource {
|
|||
LOG.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return MessageFormat.format(urlTemplate, zoom + "", x + "", y + "");
|
||||
}
|
||||
else {
|
||||
return MessageFormat.format(urlTemplate, zoom+"", x+"", y+""); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOG.error("Cannot build url for template: " + urlTemplate, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue