Move chart settings to ChartSettingsActivity.

This commit is contained in:
Jimmy Shih
2012-05-08 11:45:46 -07:00
parent 7d09348abc
commit 1de9fe67a3
21 changed files with 234 additions and 288 deletions
+1
View File
@@ -208,6 +208,7 @@ limitations under the License.
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity" />
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadServiceChooserActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.BackupSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.ChartSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.MapSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.RecordingSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.SensorSettingsActivity" />
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 275 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

-66
View File
@@ -1,66 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2009 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.
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/ScrollView" >
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:padding="8dp" >
<TextView
android:drawableLeft="@drawable/x_axis"
android:text="@string/chart_settings_x_axis"
style="@style/TextLarge.WithIcon" />
<RadioGroup
android:id="@+id/chart_settings_x"
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<RadioButton
android:id="@+id/chart_settings_by_distance"
android:text="@string/chart_settings_by_distance"
style="@style/TextMedium" />
<RadioButton
android:id="@+id/chart_settings_by_time"
android:text="@string/chart_settings_by_time"
style="@style/TextMedium" />
</RadioGroup>
<TextView
android:drawableLeft="@drawable/y_axis"
android:text="@string/chart_settings_y_axis"
style="@style/TextLarge.WithIcon" />
<CheckBox
android:id="@+id/chart_settings_elevation"
android:text="@string/stats_elevation"
style="@style/TextMedium" />
<CheckBox
android:id="@+id/chart_settings_speed"
android:text="@string/stats_speed"
style="@style/TextMedium" />
<CheckBox
android:id="@+id/chart_settings_power"
android:text="@string/sensor_state_power"
style="@style/TextMedium" />
<CheckBox
android:id="@+id/chart_settings_cadence"
android:text="@string/sensor_state_cadence"
style="@style/TextMedium" />
<CheckBox
android:id="@+id/chart_settings_heart_rate"
android:text="@string/sensor_state_heart_rate"
style="@style/TextMedium" />
</LinearLayout>
</ScrollView>
-4
View File
@@ -84,10 +84,6 @@ limitations under the License.
android:icon="@drawable/menu_sensor_state"
android:id="@+id/track_detail_sensor_state"
android:title="@string/menu_sensor_state"/>
<item
android:icon="@drawable/menu_chart_settings"
android:id="@+id/track_detail_chart_settings"
android:title="@string/menu_chart_settings"/>
<item
android:icon="@drawable/menu_settings"
android:id="@+id/track_detail_settings"
+7 -1
View File
@@ -25,6 +25,12 @@ limitations under the License.
<string name="auto_resume_track_current_retry_key">autoResumeTrackCurrentRetry</string>
<string name="auto_resume_track_timeout_key">autoResumeTrackTimeout</string>
<string name="bluetooth_sensor_key">bluetoothSensor</string>
<string name="chart_by_distance_key">chartByDistance</string>
<string name="chart_show_cadence_key">chartShowCadence</string>
<string name="chart_show_elevation_key">chartShowElevation</string>
<string name="chart_show_heart_rate_key">chartShowHeartRate</string>
<string name="chart_show_power_key">chartShowPower</string>
<string name="chart_show_speed_key">chartShowSpeed</string>
<string name="default_activity_key">defaultActivity</string>
<string name="default_map_public_key">defaultMapPublic</string>
<string name="max_recording_distance_key">maxRecordingDistance</string>
@@ -55,11 +61,11 @@ limitations under the License.
<string name="track_color_mode_slow_key">trackColorModeSlow</string>
<string name="track_color_mode_key">trackColorMode</string>
<string name="track_name_key">trackName</string>
<!-- Keys for non-persisted preferences. Sorted alphabetically. DO NOT TRANSLATE. -->
<string name="backup_to_sd_key">backupToSd</string>
<string name="restore_from_sd_key">restoreFromSd</string>
<string name="settings_backup_key">settingsBackup</string>
<string name="settings_chart_key">settingsChart</string>
<string name="settings_map_key">settingsMap</string>
<string name="settings_map_medium_display_key">settingsMapMediumDisplay</string>
<string name="settings_map_percentage_display_key">settingsMapPercentageDisplay</string>
+20 -32
View File
@@ -416,30 +416,6 @@ limitations under the License.
Record and share your GPS tracks with My Tracks.
</string>
<!-- Chart Settings -->
<string name="chart_settings_by_distance"
translation_description="In the 'Chart settings' dialog, under the 'X axis' section, the radio
option to show the charts by distance. The other radio option is to show by time. User can
only choose one of the options.">
By distance
</string>
<string name="chart_settings_by_time"
translation_description="In the 'Chart settings' dialog, under the 'X axis' section, the radio
option to show the charts by time. The other radio option is to show by distance. User can
only choose one of the options.">
By time
</string>
<string name="chart_settings_x_axis"
translation_description="In the 'Chart settings' dialog, the section label for configuring the X
axis.">
X axis
</string>
<string name="chart_settings_y_axis"
translation_description="In the 'Chart settings' dialog, the section label for configuring the Y
axis.">
Y axis
</string>
<!-- Description -->
<string name="description_activity_type"
translation_description="Activity type description.
@@ -1034,10 +1010,6 @@ limitations under the License.
translation_description="In the menu, to go to the aggregated statistics page.">
Aggregated statistics
</string>
<string name="menu_chart_settings"
translation_description="In the menu, to change the chart settings.">
Chart settings
</string>
<string name="menu_delete_all"
translation_description="In the menu, to delete all the tracks.">
Delete all
@@ -1521,6 +1493,22 @@ limitations under the License.
Restore all tracks and settings from the SD card.
</string>
<!-- Settings Chart -->
<string name="settings_chart_by_distance"
translation_description="In the 'Chart' settings, the option to display the x axis by
distance.">
By distance
</string>
<string name="settings_chart_by_time"
translation_description="In the 'Chart' settings, the option to display the x axis by time.">
By time
</string>
<string name="settings_chart_x_axis"
translation_description="In the 'Chart' setttings, the option to change the x axis display,
either by distance or by time.">
X axis
</string>
<!-- Settings Map -->
<string name="settings_map_medium"
translation_description="In the 'Map' settings, under the 'Fixed thresholds' configurations, the
@@ -1574,6 +1562,10 @@ limitations under the License.
</string>
<!-- Settings Others -->
<string name="settings_show"
translation_description="In settings, the section label to show additional values.">
Show
</string>
<string name="settings_not_while_recording"
translation_description="In settings, the summary for an option that is not available during a
track recording.">
@@ -1986,10 +1978,6 @@ limitations under the License.
either speed (mi/hr) or pace (hr/mi).">
Preferred Rate
</string>
<string name="settings_stats_show"
translation_description="In the 'Stats' settings, the section label to show additional stats.">
Show
</string>
<string name="settings_stats_time_title"
translation_description="In the 'Stats' settings, the option to change the time measurement,
either total time or moving time.">
+46
View File
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2012 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.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/track_detail_chart_tab" >
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/chart_by_distance_key"
android:summaryOff="@string/settings_chart_by_time"
android:summaryOn="@string/settings_chart_by_distance"
android:title="@string/settings_chart_x_axis" />
<PreferenceCategory android:title="@string/settings_show" >
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/chart_show_elevation_key"
android:title="@string/stats_elevation" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/chart_show_speed_key" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/chart_show_heart_rate_key"
android:title="@string/sensor_state_heart_rate" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/chart_show_cadence_key"
android:title="@string/sensor_state_cadence" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/chart_show_power_key"
android:title="@string/sensor_state_power" />
</PreferenceCategory>
</PreferenceScreen>
+4
View File
@@ -20,6 +20,10 @@ limitations under the License.
android:key="@string/settings_map_key"
android:persistent="false"
android:title="@string/track_detail_map_tab" />
<Preference
android:key="@string/settings_chart_key"
android:persistent="false"
android:title="@string/track_detail_chart_tab" />
<Preference
android:key="@string/settings_stats_key"
android:persistent="false"
+1 -1
View File
@@ -32,7 +32,7 @@ limitations under the License.
android:summaryOff="@string/stats_total_time"
android:summaryOn="@string/stats_moving_time"
android:title="@string/settings_stats_time_title" />
<PreferenceCategory android:title="@string/settings_stats_show" >
<PreferenceCategory android:title="@string/settings_show" >
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/stats_show_elevation_key"
@@ -156,12 +156,7 @@ public class ChartView extends View {
private boolean metricUnits = true;
private boolean showPointer = false;
/** Display chart versus distance or time */
public enum Mode {
BY_DISTANCE, BY_TIME
}
private Mode mode = Mode.BY_DISTANCE;
private boolean chartByDistance = true;
public ChartView(Context context) {
super(context);
@@ -394,22 +389,17 @@ public class ChartView extends View {
}
/**
* @return the current display mode (by distance, by time)
* Sets chart by distance value. It is expected that after changing this
* value, data will be reloaded.
*
* @param value true for by distance, false for by time.
*/
public Mode getMode() {
return mode;
}
/**
* Sets the display mode (by distance, by time).
* It is expected that after the mode change, data will be reloaded.
*/
public void setMode(Mode mode) {
this.mode = mode;
public void setChartByDistance(boolean value) {
this.chartByDistance = value;
}
private int getWaypointX(Waypoint waypoint) {
if (mode == Mode.BY_DISTANCE) {
if (chartByDistance) {
double lenghtInKm = waypoint.getLength() * UnitConversions.M_TO_KM;
return getX(metricUnits ? lenghtInKm : lenghtInKm * UnitConversions.KM_TO_MI);
} else {
@@ -813,8 +803,7 @@ public class ChartView extends View {
if (x < 0) {
return;
}
String s =
(mode == Mode.BY_DISTANCE)
String s = chartByDistance
? (shortFormat ? X_SHORT_FORMAT.format(x) : X_FORMAT.format(x))
: StringUtils.formatElapsedTime((long) x);
c.drawText(s,
@@ -841,7 +830,7 @@ public class ChartView extends View {
final int y = effectiveHeight + topBorder;
canvas.drawLine(leftBorder, y, rightEdge, y, borderPaint);
Context c = getContext();
String s = mode == Mode.BY_DISTANCE
String s = chartByDistance
? (metricUnits ? c.getString(R.string.unit_kilometer) : c.getString(R.string.unit_mile))
: c.getString(R.string.unit_minute);
canvas.drawText(s, rightEdge, effectiveHeight + .2f * UNIT_BORDER + topBorder, labelPaint);
@@ -875,17 +864,6 @@ public class ChartView extends View {
}
}
/**
* Returns whether a given time series is enabled for drawing.
*
* @param index the time series, one of {@link #ELEVATION_SERIES},
* {@link #SPEED_SERIES}, {@link #POWER_SERIES}, etc.
* @return true if drawn, false otherwise
*/
public boolean isChartValueSeriesEnabled(int index) {
return series[index].isEnabled();
}
/**
* Sets whether a given time series will be enabled for drawing.
*
@@ -21,7 +21,6 @@ import com.google.android.apps.mytracks.content.TrackDataHub;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
import com.google.android.apps.mytracks.fragments.ChartFragment;
import com.google.android.apps.mytracks.fragments.ChartSettingsDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment;
import com.google.android.apps.mytracks.fragments.InstallEarthDialogFragment;
import com.google.android.apps.mytracks.fragments.MapFragment;
@@ -231,8 +230,6 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
String currentTabTag = tabHost.getCurrentTabTag();
menu.findItem(R.id.track_detail_chart_settings).setVisible(
ChartFragment.CHART_FRAGMENT_TAG.equals(currentTabTag));
MenuItem satelliteMode = menu.findItem(R.id.track_detail_satellite_mode)
.setVisible(MapFragment.MAP_FRAGMENT_TAG.equals(currentTabTag));
@@ -347,10 +344,6 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
intent = IntentUtils.newIntent(this, SensorStateActivity.class);
startActivity(intent);
return true;
case R.id.track_detail_chart_settings:
new ChartSettingsDialogFragment().show(
getSupportFragmentManager(), ChartSettingsDialogFragment.CHART_SETTINGS_DIALOG_TAG);
return true;
case R.id.track_detail_settings:
intent = IntentUtils.newIntent(this, SettingsActivity.class);
startActivity(intent);
@@ -17,7 +17,6 @@
package com.google.android.apps.mytracks.fragments;
import com.google.android.apps.mytracks.ChartView;
import com.google.android.apps.mytracks.ChartView.Mode;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.MyTracksApplication;
import com.google.android.apps.mytracks.content.MyTracksLocation;
@@ -31,6 +30,7 @@ import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.stats.DoubleBuffer;
import com.google.android.apps.mytracks.stats.TripStatisticsBuilder;
import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.UnitConversions;
import com.google.android.maps.mytracks.R;
import com.google.common.annotations.VisibleForTesting;
@@ -76,6 +76,9 @@ public class ChartFragment extends Fragment implements TrackDataListener {
private boolean metricUnits = true;
private boolean reportSpeed = true;
private boolean chartByDistance = true;
private boolean[] chartShow = new boolean[] {true, true, true, true, true};
// UI elements
private ChartView chartView;
private ZoomControls zoomControls;
@@ -143,6 +146,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
public void onResume() {
super.onResume();
resumeTrackDataHub();
checkChartSettings();
getActivity().runOnUiThread(updateChart);
}
@@ -158,58 +162,6 @@ public class ChartFragment extends Fragment implements TrackDataListener {
ViewGroup layout = (ViewGroup) getActivity().findViewById(R.id.chart_view_layout);
layout.removeView(chartView);
}
/**
* Sets the chart view mode.
*
* @param mode the chart view mode
*/
public void setMode(Mode mode) {
if (chartView.getMode() != mode) {
chartView.setMode(mode);
reloadTrackDataHub();
}
}
/**
* Gets the chart view mode.
*/
public Mode getMode() {
return chartView.getMode();
}
/**
* Enables or disables the chart value series.
*
* @param index the index of the series
* @param enabled true to enable, false to disable
*/
public void setChartValueSeriesEnabled(int index, boolean enabled) {
chartView.setChartValueSeriesEnabled(index, enabled);
}
/**
* Returns true if the chart value series is enabled.
*
* @param index the index of the series
*/
public boolean isChartValueSeriesEnabled(int index) {
return chartView.isChartValueSeriesEnabled(index);
}
/**
* Returns true to report speed instead of pace.
*/
public boolean isReportSpeed() {
return reportSpeed;
}
/**
* Updates the chart.
*/
public void update() {
chartView.postInvalidate();
}
@Override
public void onProviderStateChange(ProviderState state) {
@@ -338,6 +290,60 @@ public class ChartFragment extends Fragment implements TrackDataListener {
return true;
}
/**
* Checks the chart settings.
*/
private void checkChartSettings() {
boolean needUpdate = false;
if (chartByDistance != PreferencesUtils.getBoolean(getActivity(),
R.string.chart_by_distance_key, PreferencesUtils.CHART_BY_DISTANCE_DEFAULT)) {
chartByDistance = !chartByDistance;
chartView.setChartByDistance(chartByDistance);
reloadTrackDataHub();
needUpdate = true;
}
if (setSeriesEnabled(ChartView.ELEVATION_SERIES, PreferencesUtils.getBoolean(getActivity(),
R.string.chart_show_elevation_key, PreferencesUtils.CHART_SHOW_ELEVATION_DEFAULT))) {
needUpdate = true;
}
if (setSeriesEnabled(ChartView.SPEED_SERIES, PreferencesUtils.getBoolean(
getActivity(), R.string.chart_show_speed_key, PreferencesUtils.CHART_SHOW_SPEED_DEFAULT))) {
needUpdate = true;
}
if (setSeriesEnabled(ChartView.POWER_SERIES, PreferencesUtils.getBoolean(
getActivity(), R.string.chart_show_power_key, PreferencesUtils.CHART_SHOW_POWER_DEFAULT))) {
needUpdate = true;
}
if (setSeriesEnabled(ChartView.CADENCE_SERIES, PreferencesUtils.getBoolean(getActivity(),
R.string.chart_show_cadence_key, PreferencesUtils.CHART_SHOW_CADENCE_DEFAULT))) {
needUpdate = true;
}
if (setSeriesEnabled(ChartView.HEART_RATE_SERIES, PreferencesUtils.getBoolean(getActivity(),
R.string.chart_show_heart_rate_key, PreferencesUtils.CHART_SHOW_HEART_RATE_DEFAULT))) {
needUpdate = true;
}
if (needUpdate) {
chartView.postInvalidate();
}
}
/**
* Sets the series enabled value.
*
* @param index the series index
* @param value the value
* @return true if changed
*/
private boolean setSeriesEnabled(int index, boolean value) {
if (chartShow[index] != value) {
chartShow[index] = value;
chartView.setChartValueSeriesEnabled(index, value);
return true;
} else {
return false;
}
}
/**
* Resumes the trackDataHub. Needs to be synchronized because trackDataHub can be
* accessed by multiple threads.
@@ -352,16 +358,16 @@ public class ChartFragment extends Fragment implements TrackDataListener {
ListenerDataType.SAMPLED_OUT_POINT_UPDATES,
ListenerDataType.DISPLAY_PREFERENCES));
}
/**
* Pauses the trackDataHub. Needs to be synchronized because trackDataHub can be
* accessed by multiple threads.
* Pauses the trackDataHub. Needs to be synchronized because trackDataHub can
* be accessed by multiple threads.
*/
private synchronized void pauseTrackDataHub() {
trackDataHub.unregisterTrackDataListener(this);
trackDataHub = null;
}
/**
* Returns true if recording. Needs to be synchronized because trackDataHub
* can be accessed by multiple threads.
@@ -369,7 +375,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
private synchronized boolean isRecording() {
return trackDataHub != null && trackDataHub.isRecordingSelected();
}
/**
* Reloads the trackDataHub. Needs to be synchronized because trackDataHub can be
* accessed by multiple threads.
@@ -420,7 +426,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
double heartRate = Double.NaN;
// TODO: Use TripStatisticsBuilder
if (chartView.getMode() == Mode.BY_DISTANCE) {
if (chartByDistance) {
if (lastLocation != null) {
double distance = lastLocation.distanceTo(location) * UnitConversions.M_TO_KM;
if (metricUnits) {
@@ -512,4 +518,8 @@ public class ChartFragment extends Fragment implements TrackDataListener {
void setReportSpeed(boolean value) {
reportSpeed = value;
}
@VisibleForTesting
void setChartByDistance(boolean value) {
chartByDistance = value;
}
}
@@ -1,84 +0,0 @@
/*
* Copyright 2012 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.fragments;
import com.google.android.apps.mytracks.ChartView;
import com.google.android.maps.mytracks.R;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioGroup;
/**
* A DialogFragment to show chart settings.
*
* @author Jimmy Shih
*/
public class ChartSettingsDialogFragment extends DialogFragment {
public static final String CHART_SETTINGS_DIALOG_TAG = "chartSettingsDialog";
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final ChartFragment chartFragment = (ChartFragment) getActivity()
.getSupportFragmentManager().findFragmentByTag(ChartFragment.CHART_FRAGMENT_TAG);
View view = getActivity().getLayoutInflater().inflate(R.layout.chart_settings, null);
final RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.chart_settings_x);
radioGroup.check(chartFragment.getMode() == ChartView.Mode.BY_DISTANCE
? R.id.chart_settings_by_distance : R.id.chart_settings_by_time);
final CheckBox[] checkBoxes = new CheckBox[ChartView.NUM_SERIES];
checkBoxes[ChartView.ELEVATION_SERIES] = (CheckBox) view.findViewById(
R.id.chart_settings_elevation);
checkBoxes[ChartView.SPEED_SERIES] = (CheckBox) view.findViewById(R.id.chart_settings_speed);
checkBoxes[ChartView.POWER_SERIES] = (CheckBox) view.findViewById(R.id.chart_settings_power);
checkBoxes[ChartView.CADENCE_SERIES] = (CheckBox) view.findViewById(
R.id.chart_settings_cadence);
checkBoxes[ChartView.HEART_RATE_SERIES] = (CheckBox) view.findViewById(
R.id.chart_settings_heart_rate);
// set checkboxes values
for (int i = 0; i < ChartView.NUM_SERIES; i++) {
checkBoxes[i].setChecked(chartFragment.isChartValueSeriesEnabled(i));
}
checkBoxes[ChartView.SPEED_SERIES].setText(chartFragment.isReportSpeed()
? R.string.stats_speed : R.string.stats_pace);
return new AlertDialog.Builder(getActivity())
.setNegativeButton(R.string.generic_cancel, null)
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
chartFragment.setMode(
radioGroup.getCheckedRadioButtonId() == R.id.chart_settings_by_distance
? ChartView.Mode.BY_DISTANCE : ChartView.Mode.BY_TIME);
for (int i = 0; i < ChartView.NUM_SERIES; i++) {
chartFragment.setChartValueSeriesEnabled(i, checkBoxes[i].isChecked());
}
chartFragment.update();
}
})
.setTitle(R.string.menu_chart_settings)
.setView(view)
.create();
}
}
@@ -0,0 +1,54 @@
/*
* Copyright 2012 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.settings;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
/**
* An activity for accessing chart settings.
*
* @author Jimmy Shih
*/
public class ChartSettingsActivity extends AbstractSettingsActivity {
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.chart_settings);
}
@Override
protected void onResume() {
super.onResume();
updateUi();
}
@SuppressWarnings("deprecation")
private void updateUi() {
CheckBoxPreference speedCheckBoxPreference = (CheckBoxPreference) findPreference(
getString(R.string.chart_show_speed_key));
boolean reportSpeed = PreferencesUtils.getBoolean(
this, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
speedCheckBoxPreference.setTitle(reportSpeed ? R.string.stats_speed
: R.string.stats_pace);
}
}
@@ -62,6 +62,16 @@ public class SettingsActivity extends AbstractSettingsActivity {
}
});
Preference chartPreference = findPreference(getString(R.string.settings_chart_key));
chartPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = IntentUtils.newIntent(SettingsActivity.this, ChartSettingsActivity.class);
startActivity(intent);
return true;
}
});
Preference statsPreference = findPreference(getString(R.string.settings_stats_key));
statsPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
@@ -42,6 +42,14 @@ public class PreferencesUtils {
public static final int AUTO_RESUME_TRACK_TIMEOUT_NEVER = 0;
public static final String BLUETOOTH_SENSOR_DEFAULT = "";
public static final boolean CHART_BY_DISTANCE_DEFAULT = true;
public static final boolean CHART_SHOW_CADENCE_DEFAULT = true;
public static final boolean CHART_SHOW_ELEVATION_DEFAULT = true;
public static final boolean CHART_SHOW_HEART_RATE_DEFAULT = true;
public static final boolean CHART_SHOW_POWER_DEFAULT = true;
public static final boolean CHART_SHOW_SPEED_DEFAULT = true;
public static final String DEFAULT_ACTIVITY_DEFAULT = "";
public static final boolean DEFAULT_MAP_PUBLIC_DEFAULT = true;
public static final int MAX_RECORDING_DISTANCE_DEFAULT = 200;
@@ -120,7 +120,7 @@ public class ChartFragmentTest extends AndroidTestCase {
*/
public void testFillDataPoint_distanceMetric() {
// By distance.
chartFragment.getChartView().setMode(ChartView.Mode.BY_DISTANCE);
chartFragment.setChartByDistance(true);
// Resets last location and writes first location.
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation();
double[] point = fillDataPointTestHelper(myTracksLocation1);
@@ -160,6 +160,8 @@ public class ChartFragmentTest extends AndroidTestCase {
* {@link ChartFragment#fillDataPoint(Location, double[])}.
*/
public void testFillDataPoint_distanceImperial() {
// By distance.
chartFragment.setChartByDistance(true);
// Setups to use imperial.
chartFragment.setMetricUnits(false);
@@ -204,7 +206,7 @@ public class ChartFragmentTest extends AndroidTestCase {
*/
public void testFillDataPoint_time() {
// By time
chartFragment.getChartView().setMode(ChartView.Mode.BY_TIME);
chartFragment.setChartByDistance(false);
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation();
double[] point = fillDataPointTestHelper(myTracksLocation1);
assertEquals(0.0, point[0]);