forked from upstream-mirrors/OpenTracks
Add activity icon next to calorie in stats page
This commit is contained in:
@@ -24,7 +24,7 @@ limitations under the License.
|
||||
layout="@layout/stats_large_item" />
|
||||
<include
|
||||
android:id="@+id/stats_calorie"
|
||||
layout="@layout/stats_large_item" />
|
||||
layout="@layout/stats_calorie" />
|
||||
<View
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="1dp"
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2013 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
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.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
style="@style/StatsLargeItemContainer" >
|
||||
<!-- Label -->
|
||||
<TextView
|
||||
android:id="@+id/stats_label"
|
||||
style="@style/StatsLargeLabel" />
|
||||
<!-- Value container -->
|
||||
<LinearLayout style="@style/StatsLargeValueContainer" >
|
||||
<!-- Value -->
|
||||
<TextView
|
||||
android:id="@+id/stats_value"
|
||||
style="@style/StatsLargeValue" />
|
||||
<!-- Unit -->
|
||||
<TextView
|
||||
android:id="@+id/stats_unit"
|
||||
style="@style/StatsUnit" />
|
||||
<!-- Activity type -->
|
||||
<Spinner
|
||||
android:id="@+id/stats_activity_type_icon"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginTop="-6dp"
|
||||
android:layout_width="wrap_content" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
@@ -24,7 +24,7 @@ limitations under the License.
|
||||
layout="@layout/stats_large_item" />
|
||||
<include
|
||||
android:id="@+id/stats_calorie"
|
||||
layout="@layout/stats_large_item" />
|
||||
layout="@layout/stats_calorie" />
|
||||
</LinearLayout>
|
||||
<!-- Total time and moving time -->
|
||||
<LinearLayout
|
||||
|
||||
@@ -15,17 +15,18 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/stats_large_item_id"
|
||||
style="@style/StatsLargeItemContainer" >
|
||||
<!-- Distance label -->
|
||||
<!-- Label -->
|
||||
<TextView
|
||||
android:id="@+id/stats_label"
|
||||
style="@style/StatsLargeLabel" />
|
||||
<!-- Distance value -->
|
||||
<!-- Value container -->
|
||||
<LinearLayout style="@style/StatsLargeValueContainer" >
|
||||
<!-- Value -->
|
||||
<TextView
|
||||
android:id="@+id/stats_value"
|
||||
style="@style/StatsLargeValue" />
|
||||
<!-- Unit -->
|
||||
<TextView
|
||||
android:id="@+id/stats_unit"
|
||||
style="@style/StatsUnit" />
|
||||
|
||||
@@ -17,22 +17,24 @@ limitations under the License.
|
||||
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" >
|
||||
<RelativeLayout
|
||||
<!-- Value container -->
|
||||
<LinearLayout
|
||||
android:layout_gravity="right|bottom"
|
||||
style="@style/StatsSmallValueContainer" >
|
||||
<!-- Value -->
|
||||
<TextView
|
||||
android:id="@+id/stats_value"
|
||||
android:layout_alignParentBottom="true"
|
||||
style="@style/StatsSmallValue" />
|
||||
<!-- Unit -->
|
||||
<TextView
|
||||
android:id="@+id/stats_unit"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_toRightOf="@id/stats_value"
|
||||
style="@style/StatsUnit" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
<!-- Label container -->
|
||||
<LinearLayout
|
||||
android:layout_gravity="left|bottom"
|
||||
style="@style/StatsSmallValueContainer" >
|
||||
<!-- Label -->
|
||||
<TextView
|
||||
android:id="@+id/stats_label"
|
||||
android:paddingLeft="8dp"
|
||||
|
||||
@@ -15,16 +15,18 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/stats_small_item_id"
|
||||
style="@style/StatsSmallItemContainer" >
|
||||
<!-- Label -->
|
||||
<TextView
|
||||
android:id="@+id/stats_label"
|
||||
style="@style/StatsSmallLabel" />
|
||||
<!-- Distance value -->
|
||||
<!-- Value container -->
|
||||
<LinearLayout style="@style/StatsSmallValueContainer" >
|
||||
<!-- Value -->
|
||||
<TextView
|
||||
android:id="@+id/stats_value"
|
||||
style="@style/StatsSmallValue" />
|
||||
<!-- Unit -->
|
||||
<TextView
|
||||
android:id="@+id/stats_unit"
|
||||
style="@style/StatsUnit" />
|
||||
|
||||
@@ -2157,11 +2157,11 @@ limitations under the License.
|
||||
Character limit: ~23 (1 line)">
|
||||
Calories
|
||||
</string>
|
||||
<string name="stats_calorie_setup"
|
||||
translation_description="In the 'Stats' page, the button to setup calorie.
|
||||
<string name="stats_calorie_no_calculation"
|
||||
translation_description="In the 'Stats' page, the message when calories cannot be calculated.
|
||||
|
||||
Character limit: ~23 (1 line)">
|
||||
Setup Activity Type
|
||||
%1$s activity type. E.g., 'driving'.">
|
||||
Calories can\'t be calculated with %1$s.
|
||||
</string>
|
||||
<string name="stats_fastest_pace"
|
||||
translation_description="In the 'Stats' page, the fastest pace.">
|
||||
|
||||
@@ -36,7 +36,7 @@ public class AggregatedStatsActivity extends AbstractMyTracksActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
StatsUtils.setTripStatisticsValues(this, this, null, getTripStatistics());
|
||||
StatsUtils.setTripStatisticsValues(this, this, null, getTripStatistics(), null);
|
||||
StatsUtils.setLocationValues(this, this, null, null, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
|
||||
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
||||
import com.google.android.apps.mytracks.fragments.ChartFragment;
|
||||
import com.google.android.apps.mytracks.fragments.ChooseActivityTypeDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.ChooseActivityTypeDialogFragment.ChooseActivityTypeCaller;
|
||||
import com.google.android.apps.mytracks.fragments.ConfirmDeleteDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.ExportDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.ExportDialogFragment.ExportCaller;
|
||||
@@ -37,11 +39,15 @@ import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection
|
||||
import com.google.android.apps.mytracks.settings.SettingsActivity;
|
||||
import com.google.android.apps.mytracks.util.AnalyticsUtils;
|
||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||
import com.google.android.apps.mytracks.util.CalorieUtils;
|
||||
import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType;
|
||||
import com.google.android.apps.mytracks.util.FileUtils;
|
||||
import com.google.android.apps.mytracks.util.GoogleFeedbackUtils;
|
||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackIconUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -74,7 +80,8 @@ import java.util.Date;
|
||||
* @author Leif Hendrik Wilden
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class TrackDetailActivity extends AbstractSendToGoogleActivity implements ExportCaller {
|
||||
public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
||||
implements ChooseActivityTypeCaller, ExportCaller {
|
||||
|
||||
public static final String EXTRA_TRACK_ID = "track_id";
|
||||
public static final String EXTRA_MARKER_ID = "marker_id";
|
||||
@@ -612,4 +619,23 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity implements
|
||||
}
|
||||
setTitle(title);
|
||||
}
|
||||
|
||||
public void chooseActivityType() {
|
||||
new ChooseActivityTypeDialogFragment().show(getSupportFragmentManager(),
|
||||
ChooseActivityTypeDialogFragment.CHOOSE_ACTIVITY_TYPE_DIALOG_TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChooseActivityTypeDone(String iconValue) {
|
||||
Track track = myTracksProviderUtils.getTrack(trackId);
|
||||
String category = getString(TrackIconUtils.getIconActivityType(iconValue));
|
||||
TrackUtils.updateTrack(
|
||||
this, track, null, category, null, myTracksProviderUtils, trackRecordingServiceConnection);
|
||||
|
||||
// Add toast if cannot calculate calorie
|
||||
if (CalorieUtils.getActivityType(this, category) == ActivityType.INVALID) {
|
||||
String message = getString(R.string.stats_calorie_no_calculation, category);
|
||||
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,17 +21,12 @@ import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.fragments.ChooseActivityTypeDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.ChooseActivityTypeDialogFragment.ChooseActivityTypeCaller;
|
||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||
import com.google.android.apps.mytracks.util.CalorieUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackIconUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackNameUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.BitmapFactory.Options;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
@@ -42,7 +37,6 @@ import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
|
||||
/**
|
||||
@@ -101,14 +95,14 @@ public class TrackEditActivity extends AbstractMyTracksActivity
|
||||
this, R.array.activity_types, android.R.layout.simple_dropdown_item_1line);
|
||||
activityType.setAdapter(adapter);
|
||||
activityType.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
setActivityTypeIcon(TrackIconUtils.getIconValue(
|
||||
TrackEditActivity.this, (String) activityType.getAdapter().getItem(position)));
|
||||
}
|
||||
});
|
||||
activityType.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
if (!hasFocus) {
|
||||
setActivityTypeIcon(TrackIconUtils.getIconValue(
|
||||
@@ -125,37 +119,10 @@ public class TrackEditActivity extends AbstractMyTracksActivity
|
||||
iconValue = track.getIcon();
|
||||
}
|
||||
|
||||
// Add a border around the icon
|
||||
Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeResource(getResources(), R.drawable.ic_track_airplane, options);
|
||||
final int padding = 4;
|
||||
final int width = options.outWidth + 2 * padding;
|
||||
final int height = options.outHeight + 2 * padding;
|
||||
|
||||
activityTypeIcon = (Spinner) findViewById(R.id.track_edit_activity_type_icon);
|
||||
ArrayAdapter<StringBuilder> activityTypeIconAdapter = new ArrayAdapter<StringBuilder>(
|
||||
this, android.R.layout.simple_spinner_item,
|
||||
new StringBuilder[] {new StringBuilder(iconValue)}) {
|
||||
@Override
|
||||
public View getView(int position, View convertView, android.view.ViewGroup parent) {
|
||||
ImageView imageView =
|
||||
convertView != null ? (ImageView) convertView : new ImageView(getContext());
|
||||
Bitmap source = BitmapFactory.decodeResource(
|
||||
getResources(), TrackIconUtils.getIconDrawable(getItem(position).toString()));
|
||||
if (ApiAdapterFactory.getApiAdapter().isSpinnerBackgroundLight()) {
|
||||
source = TrackIconUtils.invertBitmap(source);
|
||||
}
|
||||
imageView.setImageBitmap(source);
|
||||
imageView.setMinimumHeight(height);
|
||||
imageView.setMinimumWidth(width);
|
||||
imageView.setPadding(padding, padding, padding, padding);
|
||||
return imageView;
|
||||
}
|
||||
};
|
||||
activityTypeIcon.setAdapter(activityTypeIconAdapter);
|
||||
activityTypeIcon.setAdapter(TrackIconUtils.getIconSpinnerAdapter(this, iconValue));
|
||||
activityTypeIcon.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
new ChooseActivityTypeDialogFragment().show(getSupportFragmentManager(),
|
||||
@@ -165,15 +132,13 @@ public class TrackEditActivity extends AbstractMyTracksActivity
|
||||
}
|
||||
});
|
||||
activityTypeIcon.setOnKeyListener(new View.OnKeyListener() {
|
||||
@Override
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
|
||||
new ChooseActivityTypeDialogFragment().show(getSupportFragmentManager(),
|
||||
ChooseActivityTypeDialogFragment.CHOOSE_ACTIVITY_TYPE_DIALOG_TAG);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -184,36 +149,9 @@ public class TrackEditActivity extends AbstractMyTracksActivity
|
||||
save.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
track.setName(name.getText().toString());
|
||||
|
||||
String category = activityType.getText().toString();
|
||||
boolean newCategory = !category.equals(track.getCategory());
|
||||
boolean isRecording = trackId
|
||||
== PreferencesUtils.getLong(TrackEditActivity.this, R.string.recording_track_id_key);
|
||||
|
||||
if (newCategory && !isRecording) {
|
||||
// Update calorie
|
||||
double calorie = CalorieUtils.getTrackCalorie(TrackEditActivity.this, track, -1L);
|
||||
track.getTripStatistics().setCalorie(calorie);
|
||||
}
|
||||
|
||||
track.setCategory(category);
|
||||
track.setIcon(TrackIconUtils.getIconValue(TrackEditActivity.this, category));
|
||||
track.setDescription(description.getText().toString());
|
||||
track.setModifiedTime(System.currentTimeMillis());
|
||||
myTracksProviderUtils.updateTrack(track);
|
||||
|
||||
if (newCategory && isRecording) {
|
||||
// Update calorie through track recording service
|
||||
TrackRecordingServiceConnectionUtils.updateCalorie(trackRecordingServiceConnection);
|
||||
}
|
||||
|
||||
boolean driveSync = PreferencesUtils.getBoolean(
|
||||
TrackEditActivity.this, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
|
||||
if (driveSync) {
|
||||
PreferencesUtils.addToList(TrackEditActivity.this, R.string.drive_edited_list_key,
|
||||
PreferencesUtils.DRIVE_EDITED_LIST_DEFAULT, String.valueOf(track.getId()));
|
||||
}
|
||||
TrackUtils.updateTrack(TrackEditActivity.this, track, name.getText().toString(),
|
||||
activityType.getText().toString(), description.getText().toString(),
|
||||
myTracksProviderUtils, trackRecordingServiceConnection);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
@@ -261,26 +199,15 @@ public class TrackEditActivity extends AbstractMyTracksActivity
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.track_edit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the activity type icon.
|
||||
*
|
||||
* @param value the icon value
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
private void setActivityTypeIcon(String value) {
|
||||
iconValue = value;
|
||||
ArrayAdapter<StringBuilder> adapter =
|
||||
(ArrayAdapter<StringBuilder>) activityTypeIcon.getAdapter();
|
||||
StringBuilder stringBuilder = adapter.getItem(0);
|
||||
stringBuilder.delete(0, stringBuilder.length());
|
||||
stringBuilder.append(value);
|
||||
adapter.notifyDataSetChanged();
|
||||
TrackIconUtils.setIconSpinner(activityTypeIcon, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChooseActivityTypeDone(String value) {
|
||||
activityType.setText(getString(TrackIconUtils.getIconActivityType(value)));
|
||||
setActivityTypeIcon(value);
|
||||
activityType.setText(getString(TrackIconUtils.getIconActivityType(value)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ public class MarkerDetailFragment extends Fragment {
|
||||
setTextView(name, waypoint.getName());
|
||||
|
||||
StatsUtils.setTripStatisticsValues(
|
||||
getActivity(), null, getView(), waypoint.getTripStatistics());
|
||||
getActivity(), null, getView(), waypoint.getTripStatistics(), null);
|
||||
StatsUtils.setLocationValues(getActivity(), null, getView(), waypoint.getLocation(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.StatsUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackIconUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.location.Location;
|
||||
@@ -33,9 +34,12 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
@@ -56,6 +60,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
|
||||
private Location lastLocation = null;
|
||||
private TripStatistics lastTripStatistics = null;
|
||||
private String category = "";
|
||||
private int recordingGpsAccuracy = PreferencesUtils.RECORDING_GPS_ACCURACY_DEFAULT;
|
||||
|
||||
// A runnable to update the total time field.
|
||||
@@ -81,6 +86,27 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
handler = new Handler();
|
||||
|
||||
Spinner activityTypeIcon = (Spinner) getView().findViewById(R.id.stats_activity_type_icon);
|
||||
activityTypeIcon.setAdapter(TrackIconUtils.getIconSpinnerAdapter(getActivity(), ""));
|
||||
activityTypeIcon.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
((TrackDetailActivity) getActivity()).chooseActivityType();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
activityTypeIcon.setOnKeyListener(new View.OnKeyListener() {
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
|
||||
((TrackDetailActivity) getActivity()).chooseActivityType();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,8 +132,9 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isResumed()) {
|
||||
if (isResumed()) {
|
||||
lastTripStatistics = track != null ? track.getTripStatistics() : null;
|
||||
category = track != null ? track.getCategory() : "";
|
||||
updateUi(getActivity());
|
||||
}
|
||||
}
|
||||
@@ -260,7 +287,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
* Updates the UI.
|
||||
*/
|
||||
private void updateUi(FragmentActivity activity) {
|
||||
StatsUtils.setTripStatisticsValues(activity, activity, null, lastTripStatistics);
|
||||
StatsUtils.setTripStatisticsValues(activity, activity, null, lastTripStatistics, category);
|
||||
StatsUtils.setLocationValues(
|
||||
activity, activity, null, lastLocation, isSelectedTrackRecording());
|
||||
}
|
||||
|
||||
@@ -86,6 +86,9 @@ public class CalorieUtils {
|
||||
* @param activityType the activity type
|
||||
*/
|
||||
public static ActivityType getActivityType(Context context, String activityType) {
|
||||
if (activityType == null || activityType.equals("")) {
|
||||
return ActivityType.INVALID;
|
||||
}
|
||||
if (TrackIconUtils.getIconValue(context, activityType).equals(TrackIconUtils.WALK)
|
||||
|| TrackIconUtils.getIconValue(context, activityType).equals(TrackIconUtils.RUN)) {
|
||||
return ActivityType.FOOT;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -26,6 +27,7 @@ import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.SuperscriptSpan;
|
||||
import android.view.View;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Locale;
|
||||
@@ -129,7 +131,7 @@ public class StatsUtils {
|
||||
* @param tripStatistics the trip statistics
|
||||
*/
|
||||
public static void setTripStatisticsValues(
|
||||
Context context, Activity activity, View view, TripStatistics tripStatistics) {
|
||||
Context context, Activity activity, View view, TripStatistics tripStatistics, String category) {
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
boolean reportSpeed = PreferencesUtils.isReportSpeed(context);
|
||||
|
||||
@@ -139,9 +141,17 @@ public class StatsUtils {
|
||||
context, getView(activity, view, R.id.stats_distance), totalDistance, metricUnits);
|
||||
|
||||
// Set calorie
|
||||
double calorie = tripStatistics == null ? Double.NaN : tripStatistics.getCalorie();
|
||||
ActivityType activityType = CalorieUtils.getActivityType(context, category);
|
||||
double calorie = tripStatistics == null || activityType == ActivityType.INVALID ? Double.NaN
|
||||
: tripStatistics.getCalorie();
|
||||
setCalorie(context, getView(activity, view, R.id.stats_calorie), calorie);
|
||||
|
||||
Spinner spinner = (Spinner) getView(activity, view, R.id.stats_activity_type_icon);
|
||||
spinner.setVisibility(category != null ? View.VISIBLE : View.GONE);
|
||||
if (category != null) {
|
||||
TrackIconUtils.setIconSpinner(spinner, TrackIconUtils.getIconValue(context, category));
|
||||
}
|
||||
|
||||
// Set total time
|
||||
setTimeValue(context, getView(activity, view, R.id.stats_total_time), R.string.stats_total_time,
|
||||
tripStatistics != null ? tripStatistics.getTotalTime() : -1L);
|
||||
@@ -226,7 +236,7 @@ public class StatsUtils {
|
||||
* @param calorie the value of calorie
|
||||
*/
|
||||
private static void setCalorie(Context context, View view, double calorie) {
|
||||
String value = calorie == Double.NaN ? null
|
||||
String value = Double.isNaN(calorie) ? null
|
||||
: String.format(Locale.getDefault(), CALORIES_FORMAT, calorie);
|
||||
setItem(context, view, R.string.stats_calorie, value, context.getString(R.string.unit_calorie));
|
||||
}
|
||||
|
||||
@@ -21,8 +21,13 @@ import com.google.android.maps.mytracks.R;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -196,6 +201,35 @@ public class TrackIconUtils {
|
||||
return output;
|
||||
}
|
||||
|
||||
public static void setIconSpinner(Spinner spinner, String iconValue) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ArrayAdapter<StringBuilder> adapter = (ArrayAdapter<StringBuilder>) spinner.getAdapter();
|
||||
StringBuilder stringBuilder = adapter.getItem(0);
|
||||
stringBuilder.delete(0, stringBuilder.length());
|
||||
stringBuilder.append(iconValue);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public static ArrayAdapter<StringBuilder> getIconSpinnerAdapter(
|
||||
final Context context, String iconValue) {
|
||||
return new ArrayAdapter<StringBuilder>(context, android.R.layout.simple_spinner_item,
|
||||
new StringBuilder[] { new StringBuilder(iconValue) }) {
|
||||
@Override
|
||||
public View getView(int position, View convertView, android.view.ViewGroup parent) {
|
||||
ImageView imageView = convertView != null ? (ImageView) convertView
|
||||
: new ImageView(getContext());
|
||||
Bitmap source = BitmapFactory.decodeResource(
|
||||
context.getResources(), TrackIconUtils.getIconDrawable(getItem(position).toString()));
|
||||
if (ApiAdapterFactory.getApiAdapter().isSpinnerBackgroundLight()) {
|
||||
source = TrackIconUtils.invertBitmap(source);
|
||||
}
|
||||
imageView.setImageBitmap(source);
|
||||
imageView.setPadding(4, 4, -4, -4);
|
||||
return imageView;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the activity type is in the list.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2013 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, 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.
|
||||
*/
|
||||
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* Utilities for updating track.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class TrackUtils {
|
||||
|
||||
private TrackUtils() {}
|
||||
|
||||
public static void updateTrack(Context context, Track track, String name, String category,
|
||||
String description, MyTracksProviderUtils myTracksProviderUtils,
|
||||
TrackRecordingServiceConnection trackRecordingServiceConnection) {
|
||||
if (name != null) {
|
||||
track.setName(name);
|
||||
}
|
||||
boolean newCategory = false;
|
||||
boolean isRecording = false;
|
||||
if (category != null) {
|
||||
newCategory = !category.equals(track.getCategory());
|
||||
track.setCategory(category);
|
||||
track.setIcon(TrackIconUtils.getIconValue(context, category));
|
||||
if (newCategory) {
|
||||
isRecording = track.getId()
|
||||
== PreferencesUtils.getLong(context, R.string.recording_track_id_key);
|
||||
if (!isRecording) {
|
||||
// Update calorie
|
||||
double calorie = CalorieUtils.getTrackCalorie(context, track, -1L);
|
||||
track.getTripStatistics().setCalorie(calorie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (description != null) {
|
||||
track.setDescription(description);
|
||||
}
|
||||
track.setModifiedTime(System.currentTimeMillis());
|
||||
myTracksProviderUtils.updateTrack(track);
|
||||
|
||||
if (newCategory && isRecording) {
|
||||
// Update calorie through track recording service
|
||||
TrackRecordingServiceConnectionUtils.updateCalorie(trackRecordingServiceConnection);
|
||||
}
|
||||
|
||||
boolean driveSync = PreferencesUtils.getBoolean(
|
||||
context, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
|
||||
if (driveSync) {
|
||||
PreferencesUtils.addToList(context, R.string.drive_edited_list_key,
|
||||
PreferencesUtils.DRIVE_EDITED_LIST_DEFAULT, String.valueOf(track.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user