Merge heads

This commit is contained in:
youtaol
2013-10-28 20:36:36 +08:00
19 changed files with 339 additions and 215 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"
+60 -74
View File
@@ -14,92 +14,78 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingBottom="12dp"
android:paddingRight="12dp"
android:paddingTop="8dp"
android:shrinkColumns="1"
android:stretchColumns="1"
style="@style/ListItem" >
<!-- First row -->
<TableRow>
<!-- First column -->
<ImageView
android:contentDescription="@string/icon_track"
android:id="@+id/list_item_icon"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_width="wrap_content" />
<!-- Second column -->
<LinearLayout
android:baselineAligned="false"
android:layout_height="wrap_content"
android:layout_width="match_parent" >
<LinearLayout
android:layout_width="match_parent" >
<ImageView
android:contentDescription="@string/icon_marker"
android:id="@+id/list_item_background"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:scaleType="centerCrop" />
<TableLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingBottom="12dp"
android:paddingRight="12dp"
android:paddingTop="8dp"
android:shrinkColumns="1"
android:stretchColumns="1"
style="@style/ListItem" >
<!-- First row -->
<TableRow>
<!-- First column -->
<ImageView
android:contentDescription="@string/icon_track"
android:id="@+id/list_item_icon"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_width="0dp" >
<TableLayout
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow>
<TextView
android:ellipsize="end"
android:id="@+id/list_item_name"
android:singleLine="true"
style="@style/TextMedium" />
</TableRow>
<TableRow>
<!-- Need to match the style set in ListItemUtils.setListItem -->
<TextView
android:ellipsize="end"
android:id="@+id/list_item_time_distance"
android:singleLine="true"
style="@style/TextSmall" />
</TableRow>
</TableLayout>
<ImageView
android:id="@+id/list_item_photo"
android:adjustViewBounds="true"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:layout_width="0dp"
android:scaleType="fitCenter" />
</LinearLayout>
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_width="wrap_content" />
<!-- Second column -->
<TableLayout
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp"
android:shrinkColumns="*"
android:stretchColumns="*" >
android:layout_width="match_parent"
android:shrinkColumns="0"
android:stretchColumns="0" >
<TableRow>
<TextView
android:ellipsize="end"
android:id="@+id/list_item_name"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:singleLine="true"
style="@style/TextMedium" />
<TextView
android:id="@+id/list_item_date"
style="@style/ListItemDate" />
</TableRow>
<TableRow>
<!-- Need to match the style set in ListItemUtils.setListItem -->
<TextView
android:ellipsize="end"
android:id="@+id/list_item_time_distance"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:singleLine="true"
style="@style/TextSmall" />
<TextView
android:id="@+id/list_item_time"
style="@style/ListItemDate" />
</TableRow>
</TableLayout>
</LinearLayout>
</TableRow>
<!-- Second row -->
<TableRow>
<TextView
android:id="@+id/list_item_description"
android:layout_column="1"
android:singleLine="false"
style="@style/TextSmall" />
</TableRow>
</TableLayout>
</TableRow>
<!-- Second row -->
<TableRow>
<TextView
android:ellipsize="end"
android:id="@+id/list_item_description"
android:layout_column="1"
android:maxLines="2"
android:singleLine="false"
style="@style/TextSmall" />
</TableRow>
</TableLayout>
</FrameLayout>
@@ -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>
@@ -101,7 +101,7 @@ public class MarkerDetailFragment extends Fragment {
inflater.inflate(R.menu.marker_detail, menu);
updateWaypoint(false);
Track track = myTracksProviderUtils.getTrack(waypoint.getTrackId());
boolean isSharedWithMe = track != null ? track.isSharedWithMe() : true;
@@ -114,7 +114,7 @@ public class MarkerDetailFragment extends Fragment {
long markerId = getArguments().getLong(KEY_MARKER_ID);
FragmentActivity fragmentActivity = getActivity();
Intent intent;
switch (item.getItemId()) {
case R.id.marker_detail_show_on_map:
intent = IntentUtils.newIntent(fragmentActivity, TrackDetailActivity.class)
@@ -153,6 +153,7 @@ public class MarkerDetailFragment extends Fragment {
/**
* Updates the UI.
*/
@SuppressWarnings("deprecation")
private void update() {
View waypointSection = getView().findViewById(R.id.marker_detail_waypoint_section);
View statisticsSection = getView().findViewById(R.id.marker_detail_statistics_section);
@@ -168,11 +169,8 @@ public class MarkerDetailFragment extends Fragment {
} else {
imageView.setVisibility(View.VISIBLE);
Display defaultDisplay = getActivity().getWindowManager().getDefaultDisplay();
@SuppressWarnings("deprecation")
int displayWidth = defaultDisplay.getWidth();
@SuppressWarnings("deprecation")
int displayHeight = defaultDisplay.getHeight();
PhotoUtils.setImageVew(imageView, Uri.parse(photoUrl), displayWidth, displayHeight);
PhotoUtils.setImageVew(imageView, Uri.parse(photoUrl), defaultDisplay.getWidth(),
defaultDisplay.getHeight(), true);
}
TextView name = (TextView) getView().findViewById(R.id.marker_detail_waypoint_name);
@@ -193,8 +191,8 @@ public class MarkerDetailFragment extends Fragment {
TextView name = (TextView) getView().findViewById(R.id.marker_detail_statistics_name);
name.setText(getString(R.string.generic_name_line, waypoint.getName()));
StatsUtils.setTripStatisticsValues(getActivity(), waypoint.getTripStatistics(),
PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
StatsUtils.setTripStatisticsValues(
getActivity(), waypoint.getTripStatistics(), PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
StatsUtils.setLocationValues(getActivity(), waypoint.getLocation(), false);
}
}
@@ -19,14 +19,18 @@ 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;
import android.net.Uri;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
@@ -38,7 +42,7 @@ 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";
@@ -49,6 +53,7 @@ public class KmzTrackExporter implements TrackExporter {
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);
}
}
}
@@ -132,10 +140,47 @@ public class KmzTrackExporter implements TrackExporter {
private void addImage(ZipOutputStream zipOutputStream, String photoUrl) throws IOException {
Uri uri = Uri.parse(photoUrl);
File file = new File(uri.getPath());
if (!file.exists()) {
Log.e(TAG, "file not found " + photoUrl);
return;
}
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);
}
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 {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(new File(uri.getPath()));
@@ -143,14 +188,11 @@ public class KmzTrackExporter implements TrackExporter {
int byteCount = 0;
while ((byteCount = fileInputStream.read(buffer)) != -1) {
zipOutputStream.write(buffer, 0, byteCount);
}
} catch (FileNotFoundException e) {
Log.e(TAG, "Unable to add image", e);
}
} finally {
if (fileInputStream != null) {
fileInputStream.close();
}
}
zipOutputStream.closeEntry();
}
}
@@ -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;
@@ -40,16 +40,19 @@ public class BitmapLoader extends AsyncTask<Void, Void, Bitmap> {
private final WeakReference<ImageView> imageViewReference;
private final Uri uri;
private final int displayWidth;
private final int displayHeight;
private final int targetWidth;
private final int targetHeight;
private final boolean fitWithin;
public BitmapLoader(ImageView imageView, Uri uri, int displayWidth, int displayHeight) {
public BitmapLoader(
ImageView imageView, Uri uri, int targetWidth, int targetHeight, boolean fitWithin) {
// Use a WeakReference to ensure the ImageView can be garbage collected
imageViewReference = new WeakReference<ImageView>(imageView);
this.uri = uri;
this.displayWidth = displayWidth;
this.displayHeight = displayHeight;
this.targetWidth = targetWidth;
this.targetHeight = targetHeight;
this.fitWithin = fitWithin;
}
public Uri getUri() {
@@ -64,12 +67,9 @@ public class BitmapLoader extends AsyncTask<Void, Void, Bitmap> {
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(uri.getPath(), options);
// Set targetWidth and targetHeight
int targetWidth = displayWidth;
int targetHeight = displayHeight;
if (targetHeight == 0) {
targetHeight = (int) (targetWidth * ((float) options.outHeight / (float) options.outWidth));
if (options.outWidth == 0 || options.outHeight == 0) {
return null;
}
// Set imageWidth and imageHeight based on image rotation
@@ -87,20 +87,29 @@ public class BitmapLoader extends AsyncTask<Void, Void, Bitmap> {
// Get a scaled down version of the image
options.inJustDecodeBounds = false;
options.inSampleSize = getInSampleSize(imageWidth, imageHeight, targetWidth, targetHeight);
options.inSampleSize = getInSampleSize(imageWidth, imageHeight);
options.inPurgeable = true;
Bitmap scaledBitmap = BitmapFactory.decodeFile(uri.getPath(), options);
if (scaledBitmap == null) {
return null;
}
// Get the final bitmap after rotating the scaled down image
Bitmap bitmap;
if (rotation == 0) {
if (rotation == 0 && fitWithin) {
bitmap = scaledBitmap;
} else {
Matrix matrix = new Matrix();
matrix.postRotate(rotation);
int offset = 0;
int height = scaledBitmap.getHeight();
if (!fitWithin && height > targetHeight) {
offset = (height - targetHeight) / 2;
height = targetHeight;
}
bitmap = Bitmap.createBitmap(
scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix, true);
scaledBitmap, 0, offset, scaledBitmap.getWidth(), height, matrix, true);
scaledBitmap.recycle();
}
return bitmap;
@@ -148,10 +157,8 @@ public class BitmapLoader extends AsyncTask<Void, Void, Bitmap> {
*
* @param imageWidth the image width
* @param imageHeight the image height
* @param targetWidth the target width
* @param targetHeight the target height
*/
private int getInSampleSize(int imageWidth, int imageHeight, int targetWidth, int targetHeight) {
private int getInSampleSize(int imageWidth, int imageHeight) {
float widthRatio = 1;
if (imageWidth > targetWidth) {
widthRatio = (float) imageWidth / (float) targetWidth;
@@ -162,11 +169,21 @@ public class BitmapLoader extends AsyncTask<Void, Void, Bitmap> {
heightRatio = (float) imageHeight / (float) targetHeight;
}
/*
* To fit within the target area, return the larger sample ratio so the
* image will not be larger than the target dimensions. Use Math.floor to
* not under sample.
*/
return (int) Math.floor(Math.max(widthRatio, heightRatio));
double size;
if (fitWithin) {
/*
* To fit within the target area, return the larger sample ratio so the
* image will not be larger than the target dimensions.
*/
size = Math.max(widthRatio, heightRatio);
} else {
/*
* To fill the target area, return the smaller ratio so the image will
* cover both dimensions.
*/
size = Math.min(widthRatio, heightRatio);
}
// Use Math.floor to not under-sample.
return (int) Math.floor(size);
}
}
@@ -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);
}
/**
@@ -20,6 +20,7 @@ import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.net.Uri;
import android.text.format.DateUtils;
import android.view.Display;
@@ -36,6 +37,8 @@ import java.util.Calendar;
*/
public class ListItemUtils {
private static final int LIST_PREFERRED_ITEM_HEIGHT_DEFAULT = 128;
private ListItemUtils() {}
/**
@@ -56,6 +59,7 @@ public class ListItemUtils {
* @param category the category value
* @param description the description value
*/
@SuppressWarnings("deprecation")
public static void setListItem(Activity activity, View view, boolean isRecording,
boolean isPaused, int iconId, int iconContentDescriptionId, String name, String sharedOwner,
String totalTime, String totalDistance, String photoUrl, long startTime, String category,
@@ -87,17 +91,14 @@ public class ListItemUtils {
setTextView(timeDistanceTextView,
getTimeDistance(activity, isRecording, isPaused, sharedOwner, totalTime, totalDistance));
// Set photoUrl
ImageView photo = (ImageView) view.findViewById(R.id.list_item_photo);
ImageView photo = (ImageView) view.findViewById(R.id.list_item_background);
if (photoUrl == null || photoUrl.equals("")) {
photo.setVisibility(View.GONE);
} else {
photo.setVisibility(View.VISIBLE);
Display defaultDisplay = activity.getWindowManager().getDefaultDisplay();
// Set the initial width to 33% of the display width.
int width = (int) (defaultDisplay.getWidth() * .33);
int height = 0;
PhotoUtils.setImageVew(photo, Uri.parse(photoUrl), width, height);
PhotoUtils.setImageVew(
photo, Uri.parse(photoUrl), defaultDisplay.getWidth(), getPhotoHeight(activity), false);
}
// Set date/time
@@ -108,6 +109,15 @@ public class ListItemUtils {
TextView timeTextView = (TextView) view.findViewById(R.id.list_item_time);
setTextView(timeTextView, startTimeDisplay[1]);
/*
* If column0 is GONE, change to INVISIBLE so column1 is placed at the
* correct position.
*/
if (timeTextView.getVisibility() == View.VISIBLE
&& timeDistanceTextView.getVisibility() == View.GONE) {
timeDistanceTextView.setVisibility(View.INVISIBLE);
}
// Set category/description
TextView descriptionTextView = (TextView) view.findViewById(R.id.list_item_description);
setTextView(descriptionTextView,
@@ -201,4 +211,17 @@ public class ListItemUtils {
textView.setText(value);
}
}
/**
* Gets the photo height.
*
* @param context the context
*/
private static int getPhotoHeight(Context context) {
int[] attrs = new int[] { android.R.attr.listPreferredItemHeight };
TypedArray typeArray = context.obtainStyledAttributes(attrs);
int height = typeArray.getDimensionPixelSize(0, LIST_PREFERRED_ITEM_HEIGHT_DEFAULT);
typeArray.recycle();
return 2 * height;
}
}
@@ -37,13 +37,17 @@ public class PhotoUtils {
*
* @param imageView the image view
* @param uri the image uri
* @param displayWidth the display width
* @param displayHeight the display height
* @param targetWidth the target width
* @param targetHeight the target height
* @param fitWithin true to fit within the target area in order to display the
* entire image (no cropping). False to fill the entire target area.
* (allow cropping).
*/
public static void setImageVew(
ImageView imageView, Uri uri, int displayWidth, int displayHeight) {
ImageView imageView, Uri uri, int targetWidth, int targetHeight, boolean fitWithin) {
if (cancelBitmapLoader(imageView, uri)) {
BitmapLoader bitmapLoader = new BitmapLoader(imageView, uri, displayWidth, displayHeight);
BitmapLoader bitmapLoader = new BitmapLoader(
imageView, uri, targetWidth, targetHeight, fitWithin);
WeakReference<BitmapLoader> bitmapLoaderReference = new WeakReference<BitmapLoader>(
bitmapLoader);
imageView.setTag(bitmapLoaderReference);
@@ -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
@@ -28,7 +28,7 @@ import android.test.AndroidTestCase;
/**
* Tests {@link ChartFragment}.
*
*
* @author Youtao Liu
*/
public class ChartFragmentTest extends AndroidTestCase {
@@ -45,12 +45,12 @@ public class ChartFragmentTest extends AndroidTestCase {
}
/**
* Tests the logic to get the incorrect values of sensor in
* {@link ChartFragment#fillDataPoint(Location, double[])}
* Tests the logic to get the incorrect values of sensor in {@link ChartFragment#fillDataPoint(Location,
* double[], android.content.Context)}
*/
public void testFillDataPoint_sensorIncorrect() {
MyTracksLocation myTracksLocation = TrackStubUtils.createMyTracksLocation();
// No input.
double[] point = fillDataPointTestHelper(myTracksLocation);
assertEquals(Double.NaN, point[ChartView.HEART_RATE_SERIES + 1]);
@@ -69,10 +69,7 @@ public class ChartFragmentTest extends AndroidTestCase {
// Creates SensorDataSet.
SensorDataSet sensorDataSet = myTracksLocation.getSensorDataSet();
sensorDataSet = sensorDataSet.toBuilder()
.setHeartRate(heartRateData)
.setCadence(cadenceData)
.setPower(powerData)
.build();
.setHeartRate(heartRateData).setCadence(cadenceData).setPower(powerData).build();
myTracksLocation.setSensorDataSet(sensorDataSet);
// Test.
point = fillDataPointTestHelper(myTracksLocation);
@@ -82,8 +79,8 @@ public class ChartFragmentTest extends AndroidTestCase {
}
/**
* Tests the logic to get the correct values of sensor in
* {@link ChartFragment#fillDataPoint(Location, double[])}.
* Tests the logic to get the correct values of sensor in {@link ChartFragment#fillDataPoint(Location,
* double[], android.content.Context)}.
*/
public void testFillDataPoint_sensorCorrect() {
MyTracksLocation myTracksLocation = TrackStubUtils.createMyTracksLocation();
@@ -100,14 +97,11 @@ public class ChartFragmentTest extends AndroidTestCase {
.setValue(101).setState(Sensor.SensorState.SENDING);
Sensor.SensorData.Builder powerData = Sensor.SensorData.newBuilder()
.setValue(102).setState(Sensor.SensorState.SENDING);
// Creates SensorDataSet.
SensorDataSet sensorDataSet = myTracksLocation.getSensorDataSet();
sensorDataSet = sensorDataSet.toBuilder()
.setHeartRate(heartRateData)
.setCadence(cadenceData)
.setPower(powerData)
.build();
.setHeartRate(heartRateData).setCadence(cadenceData).setPower(powerData).build();
myTracksLocation.setSensorDataSet(sensorDataSet);
// Test.
point = fillDataPointTestHelper(myTracksLocation);
@@ -117,8 +111,8 @@ public class ChartFragmentTest extends AndroidTestCase {
}
/**
* Tests the logic to get the value of metric Distance in
* {@link ChartFragment#fillDataPoint(Location, double[])}.
* Tests the logic to get the value of metric Distance in {@link ChartFragment#fillDataPoint(Location,
* double[], android.content.Context)}.
*/
public void testFillDataPoint_distanceMetric() {
// By distance.
@@ -137,7 +131,7 @@ public class ChartFragmentTest extends AndroidTestCase {
MyTracksLocation myTracksLocation3 = TrackStubUtils.createMyTracksLocation();
myTracksLocation3.setLatitude(23);
point = fillDataPointTestHelper(myTracksLocation3);
// Computes the distance between Latitude 22 and 23.
float[] results = new float[4];
Location.distanceBetween(myTracksLocation2.getLatitude(), myTracksLocation2.getLongitude(),
@@ -149,7 +143,7 @@ public class ChartFragmentTest extends AndroidTestCase {
MyTracksLocation myTracksLocation4 = TrackStubUtils.createMyTracksLocation();
myTracksLocation4.setLatitude(24);
point = fillDataPointTestHelper(myTracksLocation4);
// Computes the distance between Latitude 23 and 24.
Location.distanceBetween(myTracksLocation3.getLatitude(), myTracksLocation3.getLongitude(),
myTracksLocation4.getLatitude(), myTracksLocation4.getLongitude(), results);
@@ -158,8 +152,8 @@ public class ChartFragmentTest extends AndroidTestCase {
}
/**
* Tests the logic to get the value of imperial Distance in
* {@link ChartFragment#fillDataPoint(Location, double[])}.
* Tests the logic to get the value of imperial Distance in {@link ChartFragment#fillDataPoint(Location,
* double[], android.content.Context)}.
*/
public void testFillDataPoint_distanceImperial() {
// By distance.
@@ -203,8 +197,8 @@ public class ChartFragmentTest extends AndroidTestCase {
}
/**
* Tests the logic to get the values of time in
* {@link ChartFragment#fillDataPoint(Location, double[])}.
* Tests the logic to get the values of time in {@link ChartFragment#fillDataPoint(Location,
* double[], android.content.Context)}.
*/
public void testFillDataPoint_time() {
// By time
@@ -220,9 +214,8 @@ public class ChartFragmentTest extends AndroidTestCase {
}
/**
* Tests the logic to get the value of elevation in
* {@link ChartFragment#fillDataPoint(Location, double[])} by one and two
* points.
* Tests the logic to get the value of elevation in {@link ChartFragment#fillDataPoint(Location,
* double[], android.content.Context)} by one and two points.
*/
public void testFillDataPoint_elevation() {
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation();
@@ -246,10 +239,10 @@ public class ChartFragmentTest extends AndroidTestCase {
}
/**
* Tests the logic to get the value of speed in
* {@link ChartFragment#fillDataPoint(Location, double[])}. In this test,
* firstly remove all points in memory, and then fill in two points one by
* one. The speed values of these points are 129, 130.
* Tests the logic to get the value of speed in {@link ChartFragment#fillDataPoint(Location,
* double[], android.content.Context)}. In this test, firstly remove all
* points in memory, and then fill in two points one by one. The speed values
* of these points are 129, 130.
*/
public void testFillDataPoint_speed() {
/*
@@ -283,22 +276,19 @@ public class ChartFragmentTest extends AndroidTestCase {
public void testFillDataPoint_speedImperial() {
// Setups to use imperial.
chartFragment.setMetricUnits(false);
// First data point is not added to the speed buffer
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation();
myTracksLocation1.setSpeed(100.0f);
double[] point = fillDataPointTestHelper(myTracksLocation1);
assertEquals(0.0, point[ChartView.SPEED_SERIES + 1]);
MyTracksLocation myTracksLocation2 = TrackStubUtils.createMyTracksLocation();
/*
* Add a time span here to make sure the second point is valid and the speed is valid.
*
* Speed is valid if:
* speedDifference > Constants.MAX_ACCELERATION * timeDifference
* speedDifference = 102 -100
* timeDifference = 222
* Add a time span here to make sure the second point is valid and the speed
* is valid. Speed is valid if: speedDifference > Constants.MAX_ACCELERATION
* * timeDifference speedDifference = 102 -100 timeDifference = 222
*/
myTracksLocation2.setTime(myTracksLocation2.getTime() + 222);
myTracksLocation2.setSpeed(102);
@@ -313,22 +303,19 @@ public class ChartFragmentTest extends AndroidTestCase {
public void testFillDataPoint_pace_nonZeroSpeed() {
// Setups reportSpeed to false.
chartFragment.setReportSpeed(false);
// First data point is not added to the speed buffer
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation();
myTracksLocation1.setSpeed(100.0f);
double[] point = fillDataPointTestHelper(myTracksLocation1);
assertEquals(0.0, point[ChartView.SPEED_SERIES + 1]);
MyTracksLocation myTracksLocation2 = TrackStubUtils.createMyTracksLocation();
/*
* Add a time span here to make sure the second point is valid and the speed is valid.
*
* Speed is valid if:
* speedDifference > Constants.MAX_ACCELERATION * timeDifference
* speedDifference = 102 -100
* timeDifference = 222
* Add a time span here to make sure the second point is valid and the speed
* is valid. Speed is valid if: speedDifference > Constants.MAX_ACCELERATION
* * timeDifference speedDifference = 102 -100 timeDifference = 222
*/
myTracksLocation2.setTime(myTracksLocation2.getTime() + 222);
myTracksLocation2.setSpeed(102);
@@ -352,7 +339,7 @@ public class ChartFragmentTest extends AndroidTestCase {
/**
* Helper method to test fillDataPoint.
*
*
* @param location location to fill
* @return data of this location
*/
@@ -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);