Merge pull request #10771 from osmandapp/master

update test branch
This commit is contained in:
Hardy 2021-02-04 21:37:05 +01:00 committed by GitHub
commit 7b5c8f144f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 35 deletions

View file

@ -23,7 +23,9 @@ public class PlatformUtil {
} }
public static XmlPullParser newXMLPullParser() throws XmlPullParserException{ public static XmlPullParser newXMLPullParser() throws XmlPullParserException{
return new org.kxml2.io.KXmlParser(); org.kxml2.io.KXmlParser xmlParser = new org.kxml2.io.KXmlParser();
xmlParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
return xmlParser;
} }
public static XmlSerializer newSerializer() { public static XmlSerializer newSerializer() {

View file

@ -4,16 +4,13 @@ import android.app.Notification;
import android.app.Service; import android.app.Service;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.location.LocationManager;
import android.os.Binder; import android.os.Binder;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.plus.helpers.LocationServiceHelper; import net.osmand.plus.helpers.LocationServiceHelper;
import net.osmand.plus.helpers.LocationServiceHelper.LocationCallback; import net.osmand.plus.helpers.LocationServiceHelper.LocationCallback;
import net.osmand.plus.notifications.OsmandNotification; import net.osmand.plus.notifications.OsmandNotification;
@ -95,12 +92,6 @@ public class NavigationService extends Service {
@Override @Override
public void onLocationAvailability(boolean locationAvailable) { public void onLocationAvailability(boolean locationAvailable) {
if (!locationAvailable) {
OsmandApplication app = (OsmandApplication) getApplication();
if (app != null) {
app.showToastMessage(getString(R.string.off_router_service_no_gps_available));
}
}
} }
}); });
} catch (SecurityException e) { } catch (SecurityException e) {
@ -137,11 +128,13 @@ public class NavigationService extends Service {
app.setNavigationService(null); app.setNavigationService(null);
usedBy = 0; usedBy = 0;
// remove updates // remove updates
if (locationServiceHelper != null) {
try { try {
locationServiceHelper.removeLocationUpdates(); locationServiceHelper.removeLocationUpdates();
} catch (SecurityException e) { } catch (SecurityException e) {
// Location service permission not granted // Location service permission not granted
} }
}
// remove notification // remove notification
stopForeground(Boolean.TRUE); stopForeground(Boolean.TRUE);
app.getNotificationHelper().updateTopNotification(); app.getNotificationHelper().updateTopNotification();

View file

@ -4,7 +4,6 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener; import android.content.DialogInterface.OnDismissListener;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -102,10 +101,11 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
private boolean handleSelectedImage(final Uri uri) { private boolean handleSelectedImage(final Uri uri) {
boolean success = false; boolean success = false;
InputStream inputStream = null; InputStream inputStream = null;
int[] imageDimensions = null;
try { try {
inputStream = app.getContentResolver().openInputStream(uri); inputStream = app.getContentResolver().openInputStream(uri);
if (inputStream != null) { if (inputStream != null) {
success = uploadImageToPlace(inputStream); imageDimensions = calcImageDimensions(inputStream);
} }
} catch (Exception e) { } catch (Exception e) {
LOG.error(e); LOG.error(e);
@ -113,12 +113,27 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
} finally { } finally {
Algorithms.closeStream(inputStream); Algorithms.closeStream(inputStream);
} }
if (imageDimensions != null && imageDimensions.length == 2) {
try {
inputStream = app.getContentResolver().openInputStream(uri);
if (inputStream != null) {
int width = imageDimensions[0];
int height = imageDimensions[1];
success = uploadImageToPlace(inputStream, width, height);
}
} catch (Exception e) {
LOG.error(e);
app.showToastMessage(R.string.cannot_upload_image);
} finally {
Algorithms.closeStream(inputStream);
}
}
return success; return success;
} }
private boolean uploadImageToPlace(InputStream image) { private boolean uploadImageToPlace(InputStream image, int width, int height) {
boolean success = false; boolean success = false;
InputStream serverData = new ByteArrayInputStream(compressImageToJpeg(image)); InputStream serverData = new ByteArrayInputStream(compressImageToJpeg(image, width, height));
String baseUrl = OPRConstants.getBaseUrl(app); String baseUrl = OPRConstants.getBaseUrl(app);
// all these should be constant // all these should be constant
String url = baseUrl + "api/ipfs/image"; String url = baseUrl + "api/ipfs/image";
@ -178,28 +193,35 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
} }
} }
private byte[] compressImageToJpeg(InputStream image) { private int[] calcImageDimensions(InputStream image) {
BufferedInputStream bufferedInputStream = new BufferedInputStream(image); BufferedInputStream bufferedInputStream = new BufferedInputStream(image);
BitmapFactory.Options opts = new BitmapFactory.Options(); BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = 4; opts.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory.decodeStream(bufferedInputStream, null, opts); BitmapFactory.decodeStream(bufferedInputStream, null, opts);
ByteArrayOutputStream os = new ByteArrayOutputStream(); return new int[] { opts.outWidth, opts.outHeight };
int h = bmp.getHeight(); }
int w = bmp.getWidth();
private byte[] compressImageToJpeg(InputStream image, int width, int height) {
BufferedInputStream bufferedInputStream = new BufferedInputStream(image);
int w = width;
int h = height;
boolean scale = false; boolean scale = false;
int divider = 1;
while (w > MAX_IMAGE_LENGTH || h > MAX_IMAGE_LENGTH) { while (w > MAX_IMAGE_LENGTH || h > MAX_IMAGE_LENGTH) {
w = w / 2; w /= 2;
h = h / 2; h /= 2;
divider *= 2;
scale = true; scale = true;
} }
Bitmap bmp;
if (scale) { if (scale) {
Matrix matrix = new Matrix(); BitmapFactory.Options opts = new BitmapFactory.Options();
matrix.postScale(w, h); opts.inSampleSize = divider;
Bitmap resizedBitmap = Bitmap.createBitmap( bmp = BitmapFactory.decodeStream(bufferedInputStream, null, opts);
bmp, 0, 0, w, h, matrix, false); } else {
bmp.recycle(); bmp = BitmapFactory.decodeStream(bufferedInputStream);
bmp = resizedBitmap;
} }
ByteArrayOutputStream os = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 90, os); bmp.compress(Bitmap.CompressFormat.JPEG, 90, os);
return os.toByteArray(); return os.toByteArray();
} }

View file

@ -90,11 +90,14 @@ public class JSMediaCommandPlayerImpl extends MediaCommandPlayerImpl {
if (voiceDir.getName().contains("tts")) { if (voiceDir.getName().contains("tts")) {
return false; return false;
} }
for (File f : voiceDir.listFiles()) { File[] files = voiceDir.listFiles();
if (files != null) {
for (File f : files) {
if (f.getName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_JS)) { if (f.getName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_JS)) {
return true; return true;
} }
} }
}
return false; return false;
} }