forked from upstream-mirrors/OpenTracks
Add a Photo Size option in Advanced settings
This commit is contained in:
+47
-9
@@ -19,7 +19,10 @@ package com.google.android.apps.mytracks.io.file.exporter;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
@@ -27,6 +30,7 @@ import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
@@ -38,17 +42,18 @@ import java.util.zip.ZipOutputStream;
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class KmzTrackExporter implements TrackExporter {
|
||||
|
||||
|
||||
public static final String KMZ_EXTENSION = "kmz";
|
||||
public static final String KMZ_IMAGES_DIR = "images";
|
||||
public static final String KMZ_KML_FILE = "doc.kml";
|
||||
|
||||
private static final String TAG = KmzTrackExporter.class.getSimpleName();
|
||||
private static final int MEGA_BYTE = 1000000;
|
||||
private static final int BUFFER_SIZE = 4096;
|
||||
|
||||
private final MyTracksProviderUtils myTracksProviderUtils;
|
||||
private final FileTrackExporter fileTrackExporter;
|
||||
private final Track[] tracks;
|
||||
private final long photoSize;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -56,12 +61,15 @@ public class KmzTrackExporter implements TrackExporter {
|
||||
* @param myTracksProviderUtils the my tracks provider utils
|
||||
* @param fileTrackExporter the file track exporter
|
||||
* @param tracks the tracks to export
|
||||
* @param context the context
|
||||
*/
|
||||
public KmzTrackExporter(MyTracksProviderUtils myTracksProviderUtils,
|
||||
FileTrackExporter fileTrackExporter, Track[] tracks) {
|
||||
FileTrackExporter fileTrackExporter, Track[] tracks, Context context) {
|
||||
this.myTracksProviderUtils = myTracksProviderUtils;
|
||||
this.fileTrackExporter = fileTrackExporter;
|
||||
this.tracks = tracks;
|
||||
this.photoSize = PreferencesUtils.getInt(
|
||||
context, R.string.photo_size_key, PreferencesUtils.PHOTO_SIZE_DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,7 +86,7 @@ public class KmzTrackExporter implements TrackExporter {
|
||||
zipOutputStream.closeEntry();
|
||||
if (!success) {
|
||||
Log.e(TAG, "Unable to write kml in kmz");
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add photos
|
||||
@@ -95,7 +103,7 @@ public class KmzTrackExporter implements TrackExporter {
|
||||
try {
|
||||
zipOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Unable to close zip input stream", e);;
|
||||
Log.e(TAG, "Unable to close zip input stream", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,8 +150,24 @@ public class KmzTrackExporter implements TrackExporter {
|
||||
KMZ_IMAGES_DIR + File.separatorChar + uri.getLastPathSegment());
|
||||
zipOutputStream.putNextEntry(zipEntry);
|
||||
|
||||
long size = file.length();
|
||||
int sampleSize = size > MEGA_BYTE ? (int) Math.ceil(size / MEGA_BYTE) : 1;
|
||||
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);
|
||||
}
|
||||
zipOutputStream.closeEntry();
|
||||
}
|
||||
|
||||
private void readFromScaledBitmap(ZipOutputStream zipOutputStream, Uri uri, int sampleSize) {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = false;
|
||||
options.inSampleSize = sampleSize;
|
||||
@@ -154,7 +178,21 @@ public class KmzTrackExporter implements TrackExporter {
|
||||
}
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, zipOutputStream);
|
||||
bitmap.recycle();
|
||||
|
||||
zipOutputStream.closeEntry();
|
||||
}
|
||||
|
||||
private void readFromFile(ZipOutputStream zipOutputStream, Uri uri) throws IOException {
|
||||
FileInputStream fileInputStream = null;
|
||||
try {
|
||||
fileInputStream = new FileInputStream(new File(uri.getPath()));
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int byteCount = 0;
|
||||
while ((byteCount = fileInputStream.read(buffer)) != -1) {
|
||||
zipOutputStream.write(buffer, 0, byteCount);
|
||||
}
|
||||
} finally {
|
||||
if (fileInputStream != null) {
|
||||
fileInputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,7 +202,8 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
}
|
||||
});
|
||||
|
||||
trackExporter = useKmz ? new KmzTrackExporter(myTracksProviderUtils, fileTrackExporter, tracks)
|
||||
trackExporter = useKmz ? new KmzTrackExporter(
|
||||
myTracksProviderUtils, fileTrackExporter, tracks, context)
|
||||
: fileTrackExporter;
|
||||
|
||||
String fileName = FileUtils.buildUniqueFileName(directory, track.getName(), extension);
|
||||
|
||||
@@ -469,7 +469,7 @@ public class SyncUtils {
|
||||
FileTrackExporter fileTrackExporter = new FileTrackExporter(
|
||||
myTracksProviderUtils, tracks, TrackFileFormat.KML.newTrackWriter(context, false), null);
|
||||
TrackExporter trackExporter = useKmz ? new KmzTrackExporter(
|
||||
myTracksProviderUtils, fileTrackExporter, tracks)
|
||||
myTracksProviderUtils, fileTrackExporter, tracks, context)
|
||||
: fileTrackExporter;
|
||||
|
||||
FileOutputStream fileOutputStream = null;
|
||||
|
||||
+31
-3
@@ -17,21 +17,23 @@
|
||||
package com.google.android.apps.mytracks.settings;
|
||||
|
||||
import com.google.android.apps.mytracks.util.DialogUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
|
||||
/**
|
||||
* An activity for accessing the sharing settings.
|
||||
* An activity for advanced settings.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class SharingSettingsActivity extends AbstractSettingsActivity {
|
||||
public class AdvancedSettingsActivity extends AbstractSettingsActivity {
|
||||
|
||||
private static final int DIALOG_CONFIRM_ALLOW_ACCESS_ID = 0;
|
||||
|
||||
@@ -41,7 +43,7 @@ public class SharingSettingsActivity extends AbstractSettingsActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(R.xml.sharing_settings);
|
||||
addPreferencesFromResource(R.xml.advanced_settings);
|
||||
|
||||
allowAccessCheckBoxPreference = (CheckBoxPreference) findPreference(
|
||||
getString(R.string.allow_access_key));
|
||||
@@ -56,6 +58,15 @@ public class SharingSettingsActivity extends AbstractSettingsActivity {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,4 +84,21 @@ public class SharingSettingsActivity 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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,9 +43,9 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
||||
configPreference(R.string.settings_chart_key, ChartSettingsActivity.class);
|
||||
configPreference(R.string.settings_stats_key, StatsSettingsActivity.class);
|
||||
configPreference(R.string.settings_recording_key, RecordingSettingsActivity.class);
|
||||
configPreference(R.string.settings_sharing_key, SharingSettingsActivity.class);
|
||||
configPreference(R.string.settings_sensor_key, SensorSettingsActivity.class);
|
||||
configPreference(R.string.settings_backup_reset_key, BackupResetSettingsActivity.class);
|
||||
configPreference(R.string.settings_advanced_key, AdvancedSettingsActivity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -82,6 +82,7 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user