Photo size for KMZ exports is not configurable anymore.

This commit is contained in:
Dennis Guse
2019-08-05 22:12:40 +02:00
parent 28270b202e
commit 972de5f92e
88 changed files with 9 additions and 337 deletions
@@ -18,17 +18,9 @@ package de.dennisguse.opentracks.io.file.exporter;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.util.Log;
import de.dennisguse.opentracks.content.ContentProviderUtils;
import de.dennisguse.opentracks.content.Track;
import de.dennisguse.opentracks.content.Waypoint;
import de.dennisguse.opentracks.util.PreferencesUtils;
import de.dennisguse.opentracks.R;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -36,6 +28,10 @@ import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import de.dennisguse.opentracks.content.ContentProviderUtils;
import de.dennisguse.opentracks.content.Track;
import de.dennisguse.opentracks.content.Waypoint;
/**
* KMZ track exporter.
*
@@ -53,7 +49,6 @@ public class KmzTrackExporter implements TrackExporter {
private final ContentProviderUtils contentProviderUtils;
private final FileTrackExporter fileTrackExporter;
private final Track[] tracks;
private final long photoSize;
/**
* Constructor.
@@ -68,8 +63,6 @@ public class KmzTrackExporter implements TrackExporter {
this.contentProviderUtils = contentProviderUtils;
this.fileTrackExporter = fileTrackExporter;
this.tracks = tracks;
this.photoSize = PreferencesUtils.getInt(
context, R.string.photo_size_key, PreferencesUtils.PHOTO_SIZE_DEFAULT);
}
@Override
@@ -139,40 +132,13 @@ public class KmzTrackExporter implements TrackExporter {
return;
}
ZipEntry zipEntry = new ZipEntry(
KMZ_IMAGES_DIR + File.separatorChar + uri.getLastPathSegment());
ZipEntry zipEntry = new ZipEntry(KMZ_IMAGES_DIR + File.separatorChar + uri.getLastPathSegment());
zipOutputStream.putNextEntry(zipEntry);
int sampleSize;
if (photoSize == -1) {
sampleSize = 1;
} else {
long size = file.length();
// Convert from kilobytes to bytes.
long limit = photoSize * 1024;
sampleSize = size > limit ? (int) Math.ceil(size / limit) : 1;
}
if (sampleSize == 1) {
readFromFile(zipOutputStream, uri);
} else {
readFromScaledBitmap(zipOutputStream, uri, sampleSize);
}
readFromFile(zipOutputStream, uri);
zipOutputStream.closeEntry();
}
private void readFromScaledBitmap(ZipOutputStream zipOutputStream, Uri uri, int sampleSize) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
options.inSampleSize = sampleSize;
Bitmap bitmap = BitmapFactory.decodeFile(uri.getPath(), options);
if (bitmap == null) {
return;
}
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, zipOutputStream);
bitmap.recycle();
}
private void readFromFile(ZipOutputStream zipOutputStream, Uri uri) throws IOException {
try (FileInputStream fileInputStream = new FileInputStream(new File(uri.getPath()))) {
byte[] buffer = new byte[BUFFER_SIZE];
@@ -23,16 +23,15 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.util.Log;
import android.widget.Toast;
import de.dennisguse.opentracks.Constants;
import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.util.DialogUtils;
import de.dennisguse.opentracks.util.PreferencesUtils;
import de.dennisguse.opentracks.R;
/**
* An activity for advanced settings.
@@ -77,14 +76,6 @@ public class AdvancedSettingsActivity extends AbstractSettingsActivity {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.settings_advanced);
ListPreference preference = (ListPreference) findPreference(getString(R.string.photo_size_key));
int value = PreferencesUtils.getInt(this, R.string.photo_size_key, PreferencesUtils.PHOTO_SIZE_DEFAULT);
String[] values = getResources().getStringArray(R.array.photo_size_values);
String[] options = new String[values.length];
String[] summary = new String[values.length];
setPhotoSizeSummaryAndOptions(summary, options, values);
configureListPreference(preference, summary, options, values, String.valueOf(value), null);
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
resetPreference = findPreference(getString(R.string.settings_reset_key));
@@ -128,23 +119,6 @@ public class AdvancedSettingsActivity extends AbstractSettingsActivity {
}
}
private void setPhotoSizeSummaryAndOptions(String[] summary, String[] options, String[] values) {
for (int i = 0; i < values.length; i++) {
int value = Integer.parseInt(values[i]);
if (value == -1) {
options[i] = getString(R.string.settings_advanced_photo_size_original);
summary[i] = getString(R.string.settings_advanced_photo_size_original);
} else if (value < 1024) {
options[i] = getString(R.string.value_integer_kilobyte, value);
summary[i] = getString(R.string.settings_advanced_photo_size_summary, options[i]);
} else {
int megabyte = value / 1024;
options[i] = getString(R.string.value_integer_megabyte, megabyte);
summary[i] = getString(R.string.settings_advanced_photo_size_summary, options[i]);
}
}
}
/**
* Updates the UI based on the recording state.
*/
@@ -171,8 +145,7 @@ public class AdvancedSettingsActivity extends AbstractSettingsActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(
AdvancedSettingsActivity.this, R.string.settings_reset_done, Toast.LENGTH_SHORT)
Toast.makeText(AdvancedSettingsActivity.this, R.string.settings_reset_done, Toast.LENGTH_SHORT)
.show();
// Restart the settings activity so all changes are loaded
Intent intent = getIntent().addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -63,7 +63,6 @@ public class PreferencesUtils {
public static final int MIN_RECORDING_INTERVAL_ADAPT_BATTERY_LIFE = -2;
public static final int MIN_RECORDING_INTERVAL_DEFAULT = 0;
public static final int PHOTO_SIZE_DEFAULT = 1024; // 1024 kB
public static final int RECORDING_DISTANCE_INTERVAL_DEFAULT = 10;
// Values for recording_gps_accuracy