Add a Photo Size option in Advanced settings

This commit is contained in:
Jimmy Shih
2013-10-22 17:32:38 -07:00
parent 44ea7dbfab
commit f1ce31cfeb
13 changed files with 155 additions and 50 deletions
+1 -1
View File
@@ -219,6 +219,7 @@ limitations under the License.
<activity android:name="com.google.android.apps.mytracks.io.maps.SendMapsActivity" />
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity" />
<activity android:name="com.google.android.apps.mytracks.io.spreadsheets.SendSpreadsheetsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.AdvancedSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.BackupResetSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.ChartSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.GoogleSettingsActivity" />
@@ -226,7 +227,6 @@ limitations under the License.
<activity android:name="com.google.android.apps.mytracks.settings.RecordingSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.SensorSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.SettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.SharingSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.StatsSettingsActivity" />
<activity
android:label="@string/track_widget_config_title"
@@ -15,7 +15,6 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<!-- Do not translate any arrays in this file. -->
<string-array name="activity_types">
<item>@string/activity_type_airplane</item>
@@ -142,6 +141,12 @@ limitations under the License.
<item>900</item>
<item>1800</item>
</string-array>
<string-array name="photo_size_values">
<item>500</item>
<item>1024</item>
<item>2048</item>
<item>-1</item>
</string-array>
<string-array name="recording_distance_interval_values">
<item>1</item>
<item>2</item>
@@ -172,7 +177,7 @@ limitations under the License.
<item>@string/sensor_type_value_polar</item>
<item>@string/sensor_type_value_zephyr</item>
<item>@string/sensor_type_value_ant</item>
<item>@string/sensor_type_value_none</item>
<item>@string/sensor_type_value_none</item>
</string-array>
<string-array name="sensor_type_bluetooth_options">
<item>@string/settings_sensor_type_polar</item>
@@ -195,7 +200,7 @@ limitations under the License.
<string-array name="stats_rate_values">
<item>@string/stats_rate_speed</item>
<item>@string/stats_rate_pace</item>
</string-array>
</string-array>
<string-array name="stats_units_options">
<item>@string/settings_stats_units_metric</item>
<item>@string/settings_stats_units_imperial</item>
@@ -203,7 +208,7 @@ limitations under the License.
<string-array name="stats_units_values">
<item>@string/stats_units_metric</item>
<item>@string/stats_units_imperial</item>
</string-array>
</string-array>
<string-array name="track_color_mode_options">
<item>@string/settings_map_track_color_mode_single</item>
<item>@string/settings_map_track_color_mode_fixed</item>
@@ -284,5 +289,4 @@ limitations under the License.
<item>@string/waypoint_type_water_fountain</item>
<item>@string/waypoint_type_waypoint</item>
</string-array>
</resources>
+4 -3
View File
@@ -27,18 +27,19 @@ limitations under the License.
<string name="default_activity_key">defaultActivity</string>
<string name="export_external_storage_format_key">exportExternalStorageFormat</string>
<string name="export_google_fusion_tables_public_key">exportGoogleFusionTablesPublic</string>
<string name="export_google_maps_public_key">exportGoogleMapsPublic</string>
<string name="export_google_maps_public_key">exportGoogleMapsPublic</string>
<string name="export_type_key">exportType</string>
<string name="map_type_key">mapType</string>
<string name="max_recording_distance_key">maxRecordingDistance</string>
<string name="min_recording_interval_key">minRecordingInterval</string>
<string name="photo_size_key">photoSize</string>
<string name="recording_distance_interval_key">recordingDistanceInterval</string>
<string name="recording_gps_accuracy_key">recordingGpsAccuracy</string>
<string name="sensor_type_key">sensorType</string>
<string name="share_track_invite_key">shareTrackInvite</string>
<string name="share_track_public_key">shareTrackPublic</string>
<string name="split_frequency_key">splitFrequency</string>
<string name="stats_rate_key">statsRate</string>
<string name="stats_rate_key">statsRate</string>
<string name="stats_show_coordinate_key">statsShowCoordinate</string>
<string name="stats_show_grade_elevation_key">statsShowGradeElevation</string>
<string name="stats_show_calorie_key">statsShowCalorie</string>
@@ -70,6 +71,7 @@ limitations under the License.
<string name="recording_track_id_key">recordingTrackId</string>
<string name="recording_track_paused_key">recordingTrackPaused</string>
<!-- Keys for non-persisted preferences. Sorted alphabetically. DO NOT TRANSLATE. -->
<string name="settings_advanced_key">settingsAdvanced</string>
<string name="settings_backup_key">settingsBackup</string>
<string name="settings_backup_reset_key">settingsBackupReset</string>
<string name="settings_chart_key">settingsChart</string>
@@ -90,6 +92,5 @@ limitations under the License.
<string name="settings_sensor_bluetooth_key">settingsSensorBluetooth</string>
<string name="settings_sensor_bluetooth_pairing_key">settingsSensorBluetoothPairing</string>
<string name="settings_sensor_root_key">settingsSensorRoot</string>
<string name="settings_sharing_key">settingsSharing</string>
<string name="settings_stats_key">settingsStats</string>
</resources>
+46 -18
View File
@@ -777,7 +777,7 @@ limitations under the License.
<string name="generic_delete_selected_confirm_title"
translation_description="When deleting selected items, the title of the confirmation dialog.">
Delete selected?
</string>
</string>
<string name="generic_description"
translation_description="The text label for entering a description.">
Description
@@ -1002,7 +1002,7 @@ limitations under the License.
</string>
<string name="marker_delete_one_confirm_title"
translation_description="When deleting one marker, the title of the confirmation dialog.">
Delete marker?
Delete marker?
</string>
<string name="marker_delete_multiple_confirm_message"
translation_description="When deleting multiple markers, the confirmation message.">
@@ -1475,6 +1475,29 @@ limitations under the License.
Show
</string>
<!-- Settings Advanced -->
<string name="settings_advanced"
translation_description="In the 'Settings' page, the 'Advanced' options.
Character limit: ~26 (1 line)">
Advanced
</string>
<string name="settings_advanced_photo_size_original"
translation_description="In the 'Advanced' settings, under the 'Photo size' option, the value to
use the original photo size.">
Original size
</string>
<string name="settings_advanced_photo_size_summary"
translation_description="In the 'Advanced' settings, the summary for the 'Photo size' option.
%1$s value. E.g., '1 MB'.">
Scale photo to %1$s for export.
</string>
<string name="settings_advanced_photo_size_title"
translation_description="In the 'Advanced' settings, the option to set the photo size.">
Photo size
</string>
<!-- Settings Backup Reset -->
<string name="settings_backup_reset"
translation_description="In the 'Settings' page, the option backup and reset.
@@ -1494,7 +1517,7 @@ limitations under the License.
<string name="settings_backup_confirm_message"
translation_description="In the 'Backup and reset' settings, after pressing the 'Backup' option,
the confirmation message.
%1$s the directory. E.g., '/MyTracks/backups'.">
This will write a full copy of all your tracks and settings to &#8216;%1$s&#8217; on the
external storage.
@@ -1955,13 +1978,6 @@ limitations under the License.
</string>
<!-- Settings Sharing -->
<string name="settings_sharing"
translation_description="In the 'Settings' page, the option to change the track sharing related
settings.
Character limit: ~26 (1 line)">
Sharing
</string>
<string name="settings_sharing_allow_access"
translation_description="In the 'Sharing' settings, the checkbox option to allow third party
apps access to the My Tracks data.
@@ -2137,13 +2153,13 @@ limitations under the License.
</string>
<string name="stats_calorie"
translation_description="In the 'Stats' page, the calorie burned.
Character limit: ~23 (1 line)">
Calories
</string>
<string name="stats_calorie_setup"
translation_description="In the 'Stats' page, the button to setup calorie.
Character limit: ~23 (1 line)">
Setup Activity Type
</string>
@@ -2238,11 +2254,11 @@ limitations under the License.
</string>
<string name="track_markers"
translation_description="Title indicating a particular track's markers.
%1$s track name. E.g., 'Grand Canyon trail'.">
%1$s Markers
</string>
<!-- Track Delete -->
<string name="track_delete_all_confirm_message"
translation_description="When deleting all the tracks, the confirmation message.">
@@ -2492,12 +2508,11 @@ limitations under the License.
%1$d an integer value. E.g., '2'.">
%1$d ft (recommended)
</string>
<string name="value_integer_kilometer"
translation_description="In a setting picker, the string format to display an integer value in
kilometers (km).
<string name="value_integer_kilobyte"
translation_description="Display an integer value in kilobyte (kB).
%1$d an integer value. E.g., '2'.">
%1$d km
%1$d kB
</string>
<string name="value_integer_kilogram"
translation_description="Display an integer value in kilogram (kg).
@@ -2505,12 +2520,25 @@ limitations under the License.
%1$d an integer value. E.g., '2'.">
%1$d kg
</string>
<string name="value_integer_kilometer"
translation_description="In a setting picker, the string format to display an integer value in
kilometers (km).
%1$d an integer value. E.g., '2'.">
%1$d km
</string>
<string name="value_integer_kilometer_hour"
translation_description="Display an integer value in kilometers per hour (km/h).
%1$d an integer value. E.g., '2'.">
%1$d km/h
</string>
<string name="value_integer_megabyte"
translation_description="Display an integer value in megabyte (MB).
%1$d an integer value. E.g., '2'.">
%1$d MB
</string>
<string name="value_integer_meter"
translation_description="In a setting picker, the string format to display an integer value in
meters (m).
@@ -15,11 +15,15 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/settings_sharing" >
android:title="@string/settings_advanced" >
<com.google.android.apps.mytracks.IntegerListPreference
android:defaultValue="1024"
android:key="@string/photo_size_key"
android:title="@string/settings_advanced_photo_size_title" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/allow_access_key"
android:summaryOff="@string/settings_sharing_allow_access_summary_off"
android:summaryOn="@string/settings_sharing_allow_access_summary_on"
android:title="@string/settings_sharing_allow_access" />
android:title="@string/settings_sharing_allow_access" />
</PreferenceScreen>
+4 -4
View File
@@ -36,10 +36,6 @@ limitations under the License.
android:key="@string/settings_recording_key"
android:persistent="false"
android:title="@string/settings_recording" />
<Preference
android:key="@string/settings_sharing_key"
android:persistent="false"
android:title="@string/settings_sharing" />
<Preference
android:key="@string/settings_sensor_key"
android:persistent="false"
@@ -48,4 +44,8 @@ limitations under the License.
android:key="@string/settings_backup_reset_key"
android:persistent="false"
android:title="@string/settings_backup_reset" />
<Preference
android:key="@string/settings_advanced_key"
android:persistent="false"
android:title="@string/settings_advanced" />
</PreferenceScreen>
@@ -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;
@@ -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
@@ -80,7 +80,7 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
EndToEndTestUtils.SOLO.goBack();
// Change a setting of sharing.
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sharing));
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_advanced));
assertTrue(EndToEndTestUtils.SOLO.waitForText(
activityMyTracks.getString(R.string.settings_sharing_allow_access), 1,
EndToEndTestUtils.NORMAL_WAIT_TIME));
@@ -121,7 +121,7 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
assertEquals(useMetric, displayCheckBoxs.get(0).isChecked());
EndToEndTestUtils.SOLO.goBack();
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sharing));
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_advanced));
EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.settings_sharing_allow_access));
sharingCheckBoxs = EndToEndTestUtils.SOLO.getCurrentViews(CheckBox.class);