adapter = ArrayAdapter.createFromResource(
this, R.array.activity_types, android.R.layout.simple_dropdown_item_1line);
activityType.setAdapter(adapter);
- trackDescription = (EditText) findViewById(R.id.track_edit_track_description);
- trackDescription.setText(track.getDescription());
+ description = (EditText) findViewById(R.id.track_edit_description);
+ description.setText(track.getDescription());
Button save = (Button) findViewById(R.id.track_edit_save);
save.setOnClickListener(this);
Button cancel = (Button) findViewById(R.id.track_edit_cancel);
- if (getIntent().getBooleanExtra(SHOW_CANCEL, true)) {
+ if (getIntent().getBooleanExtra(EXTRA_SHOW_CANCEL, true)) {
+ setTitle(R.string.menu_edit);
cancel.setOnClickListener(this);
cancel.setVisibility(View.VISIBLE);
} else {
- cancel.setVisibility(View.INVISIBLE);
+ setTitle(R.string.track_edit_new_track_title);
+ cancel.setVisibility(View.GONE);
}
}
@Override
- public void onClick(View view) {
- switch (view.getId()) {
- case R.id.track_edit_save:
- save();
- finish();
- break;
- case R.id.track_edit_cancel:
- finish();
- break;
- default:
- finish();
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() != android.R.id.home) {
+ return false;
}
+ finish();
+ return true;
}
- private void save() {
- track.setName(trackName.getText().toString());
- track.setCategory(activityType.getText().toString());
- track.setDescription(trackDescription.getText().toString());
- myTracksProviderUtils.updateTrack(track);
+ @Override
+ public void onClick(View view) {
+ if (view.getId() == R.id.track_edit_save) {
+ track.setName(name.getText().toString());
+ track.setCategory(activityType.getText().toString());
+ track.setDescription(description.getText().toString());
+ myTracksProviderUtils.updateTrack(track);
+ }
+ finish();
}
}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java
index 8e21f4b1a..455ffd029 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java
@@ -16,23 +16,19 @@
package com.google.android.apps.mytracks;
-import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.TracksColumns;
+import com.google.android.apps.mytracks.fragments.DeleteAllDialogFragment;
+import com.google.android.apps.mytracks.fragments.EulaDialogFragment;
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
import com.google.android.apps.mytracks.services.ITrackRecordingService;
import com.google.android.apps.mytracks.services.ServiceUtils;
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
-import com.google.android.apps.mytracks.util.CheckUnitsUtils;
-import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.apps.mytracks.util.EulaUtils;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.maps.mytracks.R;
-import android.app.AlertDialog;
-import android.app.Dialog;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
@@ -40,10 +36,8 @@ import android.database.Cursor;
import android.os.Bundle;
import android.os.Parcelable;
import android.speech.tts.TextToSpeech;
-import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
-import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
@@ -67,12 +61,6 @@ import android.widget.Toast;
public class TrackListActivity extends FragmentActivity {
private static final String TAG = TrackListActivity.class.getSimpleName();
- private static final String CHECK_UNITS_DIALOG_TAG = "checkUnitsDialog";
- private static final String DELETE_ALL_DIALOG_TAG = "deleteAllDialog";
- private static final String EULA_DIALOG_TAG = "eulaDialog";
- private static final String EXPORT_ALL_DIALOG_TAG = "exportAllDialog";
-
- private static final int WELCOME_ACTIVITY_REQUEST_CODE = 0;
private static final String[] PROJECTION = new String[] {
TracksColumns._ID,
@@ -171,7 +159,7 @@ public class TrackListActivity extends FragmentActivity {
public void onItemClick(AdapterView> parent, View view, int position, long id) {
Intent intent = new Intent(TrackListActivity.this, TrackDetailActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
- .putExtra(TrackDetailActivity.TRACK_ID, id);
+ .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, id);
startActivity(intent);
}
});
@@ -240,9 +228,11 @@ public class TrackListActivity extends FragmentActivity {
});
if (!EulaUtils.getEulaValue(this)) {
- Fragment fragment = getSupportFragmentManager().findFragmentByTag(EULA_DIALOG_TAG);
+ Fragment fragment = getSupportFragmentManager()
+ .findFragmentByTag(EulaDialogFragment.EULA_DIALOG_TAG);
if (fragment == null) {
- new EulaDialogFragment().show(getSupportFragmentManager(), EULA_DIALOG_TAG);
+ EulaDialogFragment.newInstance(false).show(
+ getSupportFragmentManager(), EulaDialogFragment.EULA_DIALOG_TAG);
}
}
}
@@ -259,34 +249,25 @@ public class TrackListActivity extends FragmentActivity {
trackRecordingServiceConnection.unbind();
}
- @Override
- public void onActivityResult(int requestCode, int resultCode, final Intent results) {
- if (requestCode == WELCOME_ACTIVITY_REQUEST_CODE) {
- if (!CheckUnitsUtils.getCheckUnitsValue(this)) {
- /*
- * See bug http://code.google.com/p/android/issues/detail?id=23761.
- * Cannot use
- * CheckUnitsDialogFragment().show(getSupportFragmentManager(),
- * CHECK_UNITS_DIALOG_TAG). Need to use commitAllowingStateLoss with the
- * support package.
- */
- FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
- fragmentTransaction.add(new CheckUnitsDialogFragment(), CHECK_UNITS_DIALOG_TAG);
- fragmentTransaction.commitAllowingStateLoss();
- }
- }
- }
-
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.track_list, menu);
-
- recordTrack = menu.findItem(R.id.menu_record_track);
- stopRecording = menu.findItem(R.id.menu_stop_recording);
- search = menu.findItem(R.id.menu_search);
- importAll = menu.findItem(R.id.menu_import_all);
- exportAll = menu.findItem(R.id.menu_export_all);
- deleteAll = menu.findItem(R.id.menu_delete_all);
+ String fileTypes[] = getResources().getStringArray(R.array.file_types);
+ menu.findItem(R.id.track_list_export_gpx)
+ .setTitle(getString(R.string.menu_export_all_format, fileTypes[0]));
+ menu.findItem(R.id.track_list_export_kml)
+ .setTitle(getString(R.string.menu_export_all_format, fileTypes[1]));
+ menu.findItem(R.id.track_list_export_csv)
+ .setTitle(getString(R.string.menu_export_all_format, fileTypes[2]));
+ menu.findItem(R.id.track_list_export_tcx)
+ .setTitle(getString(R.string.menu_export_all_format, fileTypes[3]));
+
+ recordTrack = menu.findItem(R.id.track_list_record_track);
+ stopRecording = menu.findItem(R.id.track_list_stop_recording);
+ search = menu.findItem(R.id.track_list_search);
+ importAll = menu.findItem(R.id.track_list_import_all);
+ exportAll = menu.findItem(R.id.track_list_export_all);
+ deleteAll = menu.findItem(R.id.track_list_delete_all);
ApiAdapterFactory.getApiAdapter().configureSearchWidget(this, search);
updateMenu();
@@ -327,34 +308,48 @@ public class TrackListActivity extends FragmentActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case R.id.menu_record_track:
+ case R.id.track_list_record_track:
updateMenuItems(true);
startRecording();
return true;
- case R.id.menu_stop_recording:
+ case R.id.track_list_stop_recording:
updateMenuItems(false);
stopRecording();
return true;
- case R.id.menu_search:
+ case R.id.track_list_search:
return ApiAdapterFactory.getApiAdapter().handleSearchMenuSelection(this);
- case R.id.menu_import_all:
+ case R.id.track_list_import_all:
startActivity(
new Intent(this, ImportActivity.class).putExtra(ImportActivity.EXTRA_IMPORT_ALL, true));
return true;
- case R.id.menu_export_all:
- new ExportAllDialogFragment().show(getSupportFragmentManager(), EXPORT_ALL_DIALOG_TAG);
+ case R.id.track_list_export_gpx:
+ startActivity(new Intent(this, ExportActivity.class).putExtra(
+ ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.GPX));
return true;
- case R.id.menu_delete_all:
- new DeleteAllDialogFragment().show(getSupportFragmentManager(), DELETE_ALL_DIALOG_TAG);
+ case R.id.track_list_export_kml:
+ startActivity(new Intent(this, ExportActivity.class).putExtra(
+ ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.KML));
return true;
- case R.id.menu_aggregated_statistics:
+ case R.id.track_list_export_csv:
+ startActivity(new Intent(this, ExportActivity.class).putExtra(
+ ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.CSV));
+ return true;
+ case R.id.track_list_export_tcx:
+ startActivity(new Intent(this, ExportActivity.class).putExtra(
+ ExportActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.TCX));
+ return true;
+ case R.id.track_list_delete_all:
+ new DeleteAllDialogFragment().show(
+ getSupportFragmentManager(), DeleteAllDialogFragment.DELETE_ALL_DIALOG_TAG);
+ return true;
+ case R.id.track_list_aggregated_statistics:
startActivity(new Intent(this, AggregatedStatsActivity.class));
return true;
- case R.id.menu_settings:
+ case R.id.track_list_settings:
startActivity(new Intent(this, SettingsActivity.class));
return true;
- case R.id.menu_help:
- startActivity(new Intent(this, WelcomeActivity.class));
+ case R.id.track_list_help:
+ startActivity(new Intent(this, HelpActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
@@ -392,14 +387,20 @@ public class TrackListActivity extends FragmentActivity {
ITrackRecordingService service = trackRecordingServiceConnection.getServiceIfBound();
if (service != null) {
try {
+ /*
+ * Remembers the recordingTrackId before endCurrentTrack sets the shared
+ * preferences, R.string.recording_track_key, to -1L, and the
+ * sharedPreferenceChangedListener sets the recordingTrackId variable to
+ * -1L.
+ */
+ long trackId = recordingTrackId;
service.endCurrentTrack();
- if (recordingTrackId != -1L) {
+ if (trackId != -1L) {
Intent intent = new Intent(this, TrackEditActivity.class)
- .putExtra(TrackEditActivity.SHOW_CANCEL, false)
- .putExtra(TrackEditActivity.TRACK_ID, recordingTrackId);
+ .putExtra(TrackEditActivity.EXTRA_SHOW_CANCEL, false)
+ .putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackId);
startActivity(intent);
}
- recordingTrackId = -1L;
} catch (Exception e) {
Log.d(TAG, "Unable to stop recording.", e);
}
@@ -416,117 +417,4 @@ public class TrackListActivity extends FragmentActivity {
}
return super.onKeyUp(keyCode, event);
}
-
- /**
- * Check Units DialogFragment.
- */
- public static class CheckUnitsDialogFragment extends DialogFragment {
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
-
- return new AlertDialog.Builder(getActivity()).setCancelable(true)
- .setOnCancelListener(new DialogInterface.OnCancelListener() {
- public void onCancel(DialogInterface dialog) {
- CheckUnitsUtils.setCheckUnitsValue(getActivity());
- }
- })
- .setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- CheckUnitsUtils.setCheckUnitsValue(getActivity());
-
- int position = ((AlertDialog) dialog).getListView().getSelectedItemPosition();
- SharedPreferences sharedPreferences = getActivity()
- .getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
- ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(sharedPreferences.edit()
- .putBoolean(getString(R.string.metric_units_key), position == 0));
- }
- })
- .setSingleChoiceItems(new CharSequence[] { getString(R.string.preferred_units_metric),
- getString(R.string.preferred_units_imperial) }, 0, null)
- .setTitle(R.string.preferred_units_title)
- .create();
- }
- }
-
- /**
- * Delete All DialogFragment.
- */
- public static class DeleteAllDialogFragment extends DialogFragment {
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- return DialogUtils.createConfirmationDialog(getActivity(),
- R.string.track_list_delete_all_confirm_message, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- MyTracksProviderUtils.Factory.get(getActivity()).deleteAllTracks();
- }
- });
- }
- };
-
- /**
- * Eula DialogFragment.
- */
- public static class EulaDialogFragment extends DialogFragment {
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- return new AlertDialog.Builder(getActivity())
- .setCancelable(true)
- .setMessage(EulaUtils.getEulaMessage(getActivity()))
- .setNegativeButton(R.string.eula_decline, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- getActivity().finish();
- }
- })
- .setOnCancelListener(new DialogInterface.OnCancelListener() {
- @Override
- public void onCancel(DialogInterface dialog) {
- getActivity().finish();
- }
- })
- .setPositiveButton(R.string.eula_accept, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- EulaUtils.setEulaValue(getActivity());
- getActivity().startActivityForResult(
- new Intent(getActivity(), WelcomeActivity.class), WELCOME_ACTIVITY_REQUEST_CODE);
- }
- })
- .setTitle(R.string.eula_title)
- .create();
- }
- }
-
- /**
- * Export All DialogFragment.
- */
- public static class ExportAllDialogFragment extends DialogFragment {
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- String fileTypes[] = getResources().getStringArray(R.array.file_types);
- String[] choices = new String[fileTypes.length];
- for (int i = 0; i < fileTypes.length; i++) {
- choices[i] = getString(R.string.menu_export_all_format, fileTypes[i]);
- }
- 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) {
- int index = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
- Intent intent = new Intent(getActivity(), ExportActivity.class).putExtra(
- ExportActivity.EXTRA_TRACK_FILE_FORMAT,
- (Parcelable) TrackFileFormat.values()[index]);
- getActivity().startActivity(intent);
- }
- })
- .setSingleChoiceItems(choices, 0, null)
- .setTitle(R.string.menu_export_all)
- .create();
- }
- }
}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/WelcomeActivity.java b/MyTracks/src/com/google/android/apps/mytracks/WelcomeActivity.java
deleted file mode 100644
index 2a1f5f42d..000000000
--- a/MyTracks/src/com/google/android/apps/mytracks/WelcomeActivity.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright 2008 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;
-
-import com.google.android.apps.mytracks.util.EulaUtils;
-import com.google.android.apps.mytracks.util.SystemUtils;
-import com.google.android.maps.mytracks.R;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.content.DialogInterface;
-import android.os.Bundle;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.TextView;
-
-/**
- * An activity that displays a welcome screen.
- *
- * @author Sandor Dornbush
- */
-public class WelcomeActivity extends Activity {
-
- private static final int DIALOG_ABOUT_ID = 0;
- private static final int DIALOG_EULA_ID = 1;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.welcome);
- findViewById(R.id.welcome_ok).setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- finish();
- }
- });
- findViewById(R.id.welcome_about).setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- showDialog(DIALOG_ABOUT_ID);
- }
- });
- }
-
- @Override
- protected Dialog onCreateDialog(int id) {
- switch (id) {
- case DIALOG_ABOUT_ID:
- View view = getLayoutInflater().inflate(R.layout.about, null);
- TextView aboutVersion = (TextView) view.findViewById(R.id.about_version);
- aboutVersion.setText(SystemUtils.getMyTracksVersion(this));
- return new AlertDialog.Builder(this)
- .setCancelable(true)
- .setNegativeButton(R.string.about_license, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- showDialog(DIALOG_EULA_ID);
- }
- })
- .setPositiveButton(R.string.generic_ok, null)
- .setTitle(R.string.my_tracks_app_name)
- .setView(view)
- .create();
- case DIALOG_EULA_ID:
- return new AlertDialog.Builder(this)
- .setCancelable(true)
- .setMessage(EulaUtils.getEulaMessage(this))
- .setPositiveButton(R.string.generic_ok, null)
- .setTitle(R.string.eula_title)
- .create();
- default:
- return null;
- }
- }
-}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/AboutDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/AboutDialogFragment.java
new file mode 100644
index 000000000..dced8b993
--- /dev/null
+++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/AboutDialogFragment.java
@@ -0,0 +1,58 @@
+/*
+ * 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.util.SystemUtils;
+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.TextView;
+
+/**
+ * A DialogFragment to show information about My Tracks.
+ *
+ * @author Jimmy Shih
+ */
+public class AboutDialogFragment extends DialogFragment {
+
+ public static final String ABOUT_DIALOG_TAG = "aboutDialog";
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ View view = getActivity().getLayoutInflater().inflate(R.layout.about, null);
+ TextView aboutVersion = (TextView) view.findViewById(R.id.about_version);
+ aboutVersion.setText(SystemUtils.getMyTracksVersion(getActivity()));
+ return new AlertDialog.Builder(getActivity())
+ .setCancelable(true)
+ .setNegativeButton(R.string.about_license, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ EulaDialogFragment.newInstance(true).show(
+ getActivity().getSupportFragmentManager(), EulaDialogFragment.EULA_DIALOG_TAG);
+ }
+ })
+ .setPositiveButton(R.string.generic_ok, null)
+ .setTitle(R.string.help_about)
+ .setView(view)
+ .create();
+ }
+}
\ No newline at end of file
diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/CheckUnitsDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/CheckUnitsDialogFragment.java
new file mode 100644
index 000000000..2370392d2
--- /dev/null
+++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/CheckUnitsDialogFragment.java
@@ -0,0 +1,69 @@
+/*
+ * 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.Constants;
+import com.google.android.apps.mytracks.util.ApiAdapterFactory;
+import com.google.android.apps.mytracks.util.CheckUnitsUtils;
+import com.google.android.maps.mytracks.R;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
+
+/**
+ * A DialogFragment to check preferred units.
+ *
+ * @author Jimmy Shih
+ */
+public class CheckUnitsDialogFragment extends DialogFragment {
+
+ public static final String CHECK_UNITS_DIALOG_TAG = "checkUnitsDialog";
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+
+ return new AlertDialog.Builder(getActivity())
+ .setCancelable(true)
+ .setOnCancelListener(new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ CheckUnitsUtils.setCheckUnitsValue(getActivity());
+ }
+ })
+ .setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ CheckUnitsUtils.setCheckUnitsValue(getActivity());
+
+ int position = ((AlertDialog) dialog).getListView().getSelectedItemPosition();
+ SharedPreferences sharedPreferences = getActivity()
+ .getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
+ ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(sharedPreferences.edit()
+ .putBoolean(getString(R.string.metric_units_key), position == 0));
+ }
+ })
+ .setSingleChoiceItems(new CharSequence[] { getString(R.string.preferred_units_metric),
+ getString(R.string.preferred_units_imperial) }, 0, null)
+ .setTitle(R.string.preferred_units_title)
+ .create();
+ }
+}
\ No newline at end of file
diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/DeleteAllDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/DeleteAllDialogFragment.java
new file mode 100644
index 000000000..1c845378c
--- /dev/null
+++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/DeleteAllDialogFragment.java
@@ -0,0 +1,47 @@
+/*
+ * 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.content.MyTracksProviderUtils;
+import com.google.android.apps.mytracks.util.DialogUtils;
+import com.google.android.maps.mytracks.R;
+
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
+
+/**
+ * A DialogFragment to delete all tracks.
+ *
+ * @author Jimmy Shih
+ */
+public class DeleteAllDialogFragment extends DialogFragment {
+
+ public static final String DELETE_ALL_DIALOG_TAG = "deleteAllDialog";
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ return DialogUtils.createConfirmationDialog(getActivity(),
+ R.string.track_list_delete_all_confirm_message, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ MyTracksProviderUtils.Factory.get(getActivity()).deleteAllTracks();
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/EulaDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/EulaDialogFragment.java
new file mode 100644
index 000000000..2f2a83300
--- /dev/null
+++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/EulaDialogFragment.java
@@ -0,0 +1,86 @@
+/*
+ * 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.util.EulaUtils;
+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;
+
+/**
+ * A DialogFragment to show EULA.
+ *
+ * @author Jimmy Shih
+ */
+public class EulaDialogFragment extends DialogFragment {
+
+ public static final String EULA_DIALOG_TAG = "eulaDialog";
+ private static final String KEY_HAS_ACCEPTED = "hasAccepted";
+
+ /**
+ * Creates a new instance of {@link EulaDialogFragment}.
+ *
+ * @param hasAccepted true if the user has accepted the eula.
+ */
+ public static EulaDialogFragment newInstance(boolean hasAccepted) {
+ Bundle bundle = new Bundle();
+ bundle.putBoolean(KEY_HAS_ACCEPTED, hasAccepted);
+
+ EulaDialogFragment eulaDialogFragment = new EulaDialogFragment();
+ eulaDialogFragment.setArguments(bundle);
+ return eulaDialogFragment;
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ boolean hasAccepted = getArguments().getBoolean(KEY_HAS_ACCEPTED);
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
+ .setCancelable(true)
+ .setMessage(EulaUtils.getEulaMessage(getActivity()))
+ .setTitle(R.string.eula_title);
+
+ if (hasAccepted) {
+ builder.setPositiveButton(R.string.generic_ok, null);
+ } else {
+ builder.setNegativeButton(R.string.eula_decline, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ getActivity().finish();
+ }
+ })
+ .setOnCancelListener(new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ getActivity().finish();
+ }
+ })
+ .setPositiveButton(R.string.eula_accept, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ EulaUtils.setEulaValue(getActivity());
+ new WelcomeDialogFragment().show(
+ getActivity().getSupportFragmentManager(), WelcomeDialogFragment.WELCOME_DIALOG_TAG);
+ }
+ });
+ }
+ return builder.create();
+ }
+}
\ No newline at end of file
diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/WelcomeDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/WelcomeDialogFragment.java
new file mode 100644
index 000000000..f437eccc6
--- /dev/null
+++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/WelcomeDialogFragment.java
@@ -0,0 +1,63 @@
+/*
+ * 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.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;
+
+/**
+ * A DialogFrament to show the welcome info.
+ *
+ * @author Jimmy Shih
+ */
+public class WelcomeDialogFragment extends DialogFragment {
+
+ public static final String WELCOME_DIALOG_TAG = "welcomeDialog";
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ View view = getActivity().getLayoutInflater().inflate(R.layout.welcome, null);
+ return new AlertDialog.Builder(getActivity())
+ .setCancelable(true)
+ .setOnCancelListener(new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ checkUnits();
+ }
+ })
+ .setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ checkUnits();
+ }
+ })
+ .setTitle(R.string.welcome_title)
+ .setView(view)
+ .create();
+ }
+
+ private void checkUnits() {
+ new CheckUnitsDialogFragment().show(
+ getActivity().getSupportFragmentManager(), CheckUnitsDialogFragment.CHECK_UNITS_DIALOG_TAG);
+ }
+}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveActivity.java
index 8bc003459..025938e48 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveActivity.java
@@ -20,7 +20,6 @@ import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.apps.mytracks.util.FileUtils;
-import com.google.android.apps.mytracks.util.PlayTrackUtils;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
@@ -48,8 +47,13 @@ public class SaveActivity extends Activity {
public static final String EXTRA_SHARE_TRACK = "share_track";
public static final String EXTRA_PLAY_TRACK = "play_track";
+ public static final String KML_MIME_TYPE = "application/vnd.google-earth.kml+xml";
+ public static final String GOOGLE_EARTH_PACKAGE = "com.google.earth";
+
private static final String TAG = SaveActivity.class.getSimpleName();
-
+ private static final String TOUR_FEATURE_ID = "com.google.earth.EXTRA.tour_feature_id";
+ private static final String GOOGLE_EARTH_CLASS = "com.google.earth.EarthActivity";
+
private static final int DIALOG_PROGRESS_ID = 0;
private static final int DIALOG_RESULT_ID = 1;
@@ -207,9 +211,9 @@ public class SaveActivity extends Activity {
} else if (playTrack) {
Intent intent = new Intent()
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
- .putExtra(PlayTrackUtils.TOUR_FEATURE_ID, KmlTrackWriter.TOUR_FEATURE_ID)
- .setClassName(PlayTrackUtils.GOOGLE_EARTH_PACKAGE, PlayTrackUtils.GOOGLE_EARTH_CLASS)
- .setDataAndType(Uri.fromFile(new File(filePath)), PlayTrackUtils.KML_MIME_TYPE);
+ .putExtra(TOUR_FEATURE_ID, KmlTrackWriter.TOUR_FEATURE_ID)
+ .setClassName(GOOGLE_EARTH_PACKAGE, GOOGLE_EARTH_CLASS)
+ .setDataAndType(Uri.fromFile(new File(filePath)), KML_MIME_TYPE);
startActivity(intent);
}
}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java
index 27925710c..f92deabfc 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java
@@ -486,7 +486,7 @@ public class TrackRecordingService extends Service {
System.currentTimeMillis());
Intent intent = new Intent(this, TrackDetailActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
- .putExtra(TrackDetailActivity.TRACK_ID, recordingTrackId);
+ .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, recordingTrackId);
PendingIntent contentIntent = PendingIntent.getActivity(
this, 0 /* requestCode */, intent, 0 /* flags */);
notification.setLatestEventInfo(this, getString(R.string.my_tracks_app_name),
diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/Api11Adapter.java b/MyTracks/src/com/google/android/apps/mytracks/util/Api11Adapter.java
index 638a32f84..e609b91c6 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/util/Api11Adapter.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/util/Api11Adapter.java
@@ -32,13 +32,18 @@ import android.widget.SearchView;
@TargetApi(11)
public class Api11Adapter extends Api10Adapter {
+ @Override
+ public void hideTitle(Activity activity) {
+ // Do nothing
+ }
+
@Override
public void configureActionBarHomeAsUp(Activity activity) {
ActionBar actionBar = activity.getActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
-
+
@Override
public void configureSearchWidget(Activity activity, MenuItem menuItem) {
SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/Api7Adapter.java b/MyTracks/src/com/google/android/apps/mytracks/util/Api7Adapter.java
index 81dea19a6..fb6d5cffb 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/util/Api7Adapter.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/util/Api7Adapter.java
@@ -104,17 +104,20 @@ public class Api7Adapter implements ApiAdapter {
}
@Override
- public void configureActionBarHomeAsUp(Activity activity) {
- // Action bar not available, just hide the title and let actions be shown
- // via the regular menu.
+ public void hideTitle(Activity activity) {
activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
}
-
+
+ @Override
+ public void configureActionBarHomeAsUp(Activity activity) {
+ // Do nothing
+ }
+
@Override
public void configureSearchWidget(Activity activity, MenuItem menuItem) {
- // Do nothing
+ // Do nothing
}
-
+
@Override
public boolean handleSearchMenuSelection(Activity activity) {
activity.onSearchRequested();
diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/ApiAdapter.java b/MyTracks/src/com/google/android/apps/mytracks/util/ApiAdapter.java
index e108620f3..62b469633 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/util/ApiAdapter.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/util/ApiAdapter.java
@@ -100,14 +100,26 @@ public interface ApiAdapter {
* @param bluetoothDevice
*/
public BluetoothSocket getBluetoothSocket(BluetoothDevice bluetoothDevice) throws IOException;
-
+
+ /**
+ * Hides the title. If the platform supports the action bar, do nothing.
+ * Ideally, with the action bar, we would like to collapse the navigation tabs
+ * into the action bar. However, collapsing is not supported by the
+ * compatibility library.
+ *
+ * Due to changes in API level 11.
+ *
+ * @param activity the activity
+ */
+ public void hideTitle(Activity activity);
+
/**
* Configures the action bar with the Home button as an Up button. If the
- * system doesn't support action bar, hide the title bar.
+ * platform doesn't support the action bar, do nothing.
*
* Due to changes in API level 11.
*
- * @param activity the current activity
+ * @param activity the activity
*/
public void configureActionBarHomeAsUp(Activity activity);
diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/PlayTrackUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/PlayTrackUtils.java
deleted file mode 100644
index 28cdf39e3..000000000
--- a/MyTracks/src/com/google/android/apps/mytracks/util/PlayTrackUtils.java
+++ /dev/null
@@ -1,108 +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.util;
-
-import com.google.android.apps.mytracks.io.file.SaveActivity;
-import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
-import com.google.android.maps.mytracks.R;
-
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.net.Uri;
-import android.os.Parcelable;
-
-import java.util.List;
-
-/**
- * Utilities for playing a track on Google Earth.
- *
- * @author Jimmy Shih
- */
-public class PlayTrackUtils {
-
- /**
- * KML mime type.
- */
- public static final String KML_MIME_TYPE = "application/vnd.google-earth.kml+xml";
- public static final String TOUR_FEATURE_ID = "com.google.earth.EXTRA.tour_feature_id";
-
- public static final String GOOGLE_EARTH_PACKAGE = "com.google.earth";
- public static final String GOOGLE_EARTH_CLASS = "com.google.earth.EarthActivity";
- private static final String EARTN_MARKET_URI = "market://details?id=" + GOOGLE_EARTH_PACKAGE;
-
- private PlayTrackUtils() {}
-
- /**
- * Returns true if a Google Earth app that can handle KML mine type is
- * installed.
- *
- * @param context the context
- */
- public static boolean isEarthInstalled(Context context) {
- List infos = context.getPackageManager().queryIntentActivities(
- new Intent().setType(KML_MIME_TYPE), PackageManager.MATCH_DEFAULT_ONLY);
- for (ResolveInfo info : infos) {
- if (info.activityInfo != null && info.activityInfo.packageName != null
- && info.activityInfo.packageName.equals(GOOGLE_EARTH_PACKAGE)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Plays a track by sending an intent to {@link SaveActivity}.
- *
- * @param context the context
- * @param trackId the track id
- */
- public static void playTrack(Context context, long trackId) {
- AnalyticsUtils.sendPageViews(context, "/action/play");
-
- Intent intent = new Intent(context, SaveActivity.class)
- .putExtra(SaveActivity.EXTRA_TRACK_ID, trackId)
- .putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.KML)
- .putExtra(SaveActivity.EXTRA_PLAY_TRACK, true);
- context.startActivity(intent);
- }
-
- /**
- * Creates a dialog to install Google Earth from the Android Market.
- *
- * @param context the context
- */
- public static Dialog createInstallEarthDialog(final Context context) {
- return new AlertDialog.Builder(context)
- .setCancelable(true)
- .setMessage(R.string.track_detail_install_earth_message)
- .setNegativeButton(android.R.string.cancel, null)
- .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Intent intent = new Intent();
- intent.setData(Uri.parse(EARTN_MARKET_URI));
- context.startActivity(intent);
- }
- })
- .create();
- }
-}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java b/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java
index 369539b84..c80bd6ca3 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java
@@ -148,7 +148,7 @@ public class TrackWidgetProvider
Intent intent = new Intent(context, TrackDetailActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
if (track != null) {
- intent.putExtra(TrackDetailActivity.TRACK_ID, track.getId());
+ intent.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, track.getId());
}
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.appwidget_track_statistics, pendingIntent);
diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/ChartActivityTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/ChartFragmentTest.java
similarity index 54%
rename from MyTracksTest/src/com/google/android/apps/mytracks/ChartActivityTest.java
rename to MyTracksTest/src/com/google/android/apps/mytracks/ChartFragmentTest.java
index 1ed95955a..69418ddd6 100644
--- a/MyTracksTest/src/com/google/android/apps/mytracks/ChartActivityTest.java
+++ b/MyTracksTest/src/com/google/android/apps/mytracks/ChartFragmentTest.java
@@ -13,152 +13,100 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
+
package com.google.android.apps.mytracks;
import com.google.android.apps.mytracks.content.MyTracksLocation;
import com.google.android.apps.mytracks.content.Sensor;
import com.google.android.apps.mytracks.content.Sensor.SensorDataSet;
import com.google.android.apps.mytracks.util.UnitConversions;
-import com.google.android.maps.mytracks.R;
-import android.app.Instrumentation;
import android.location.Location;
-import android.test.ActivityInstrumentationTestCase2;
-import android.view.View;
-import android.widget.ZoomControls;
+import android.test.AndroidTestCase;
/**
- * Tests {@link ChartActivity}.
- *
+ * Tests {@link ChartFragment}.
+ *
* @author Youtao Liu
*/
-public class ChartActivityTest extends ActivityInstrumentationTestCase2 {
+public class ChartFragmentTest extends AndroidTestCase {
- private Instrumentation instrumentation;
- private ChartActivity chartActivity;
- private View zoomIn;
- private View zoomOut;
- private int currentZoomLevel;
+ private ChartFragment chartFragment;
- // 10 is same with the default value in ChartView
- private final int MAX_ZOOM_LEVEL = 10;
- private final int MIN_ZOOM_LEVEL = 1;
- // The ratio from meter/second to kilometer/hour, the conversion is 60 * 60 /
- // 1000 = 3.6.
- private final double METER_PER_SECOND_TO_KILOMETER_PER_HOUR = 3.6;
- private final double KILOMETER_TO_METER = 1000.0;
- private final double HOURS_PER_UNIT = 60;
-
- public ChartActivityTest() {
- super(ChartActivity.class);
- }
+ private final double HOURS_PER_UNIT = 60.0;
@Override
protected void setUp() throws Exception {
- super.setUp();
- instrumentation = getInstrumentation();
- chartActivity = getActivity();
+ chartFragment = new ChartFragment();
+ chartFragment.setChartView(new ChartView(getContext()));
}
/**
- * Tests zooming in and zooming out.
- */
- public void testZoomInAndZoomOut() {
- currentZoomLevel = chartActivity.getChartView().getZoomLevel();
- chartActivity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- ZoomControls zoomControls = (ZoomControls) chartActivity.findViewById(R.id.elevation_zoom);
- zoomIn = zoomControls.getChildAt(0);
- zoomOut = zoomControls.getChildAt(1);
- // Invoke following two methods method to initial the display of
- // ZoomControls.
- zoomControls.setIsZoomInEnabled(chartActivity.getChartView().canZoomIn());
- zoomControls.setIsZoomOutEnabled(chartActivity.getChartView().canZoomOut());
- // Click zoomIn button to disable.
- for (int i = currentZoomLevel; i > MIN_ZOOM_LEVEL; i--) {
- zoomIn.performClick();
- }
- }
- });
- instrumentation.waitForIdleSync();
- assertEquals(false, zoomIn.isEnabled());
- assertEquals(true, zoomOut.isEnabled());
- chartActivity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- // Click to the second max zoom level
- for (int i = MIN_ZOOM_LEVEL; i < MAX_ZOOM_LEVEL - 1; i++) {
- zoomOut.performClick();
- assertEquals(true, zoomIn.isEnabled());
- assertEquals(true, zoomOut.isEnabled());
- }
- zoomOut.performClick();
- }
- });
- instrumentation.waitForIdleSync();
- assertEquals(true, zoomIn.isEnabled());
- assertEquals(false, zoomOut.isEnabled());
- }
-
- /**
- * Tests the logic to get the incorrect values of sensor in {@link
- * ChartActivity#fillDataPoint(Location, double[])}.
+ * Tests the logic to get the incorrect values of sensor in
+ * {@link ChartFragment#fillDataPoint(Location, double[])}
*/
public void testFillDataPoint_sensorIncorrect() {
MyTracksLocation myTracksLocation = TrackStubUtils.createMyTracksLocation();
+
// No input.
- double[] point = fillDataPointTestHelper(myTracksLocation, false);
+ double[] point = fillDataPointTestHelper(myTracksLocation);
assertEquals(Double.NaN, point[3]);
assertEquals(Double.NaN, point[4]);
assertEquals(Double.NaN, point[5]);
// Input incorrect state.
// Creates SensorData.
- Sensor.SensorData.Builder powerData = Sensor.SensorData.newBuilder().setValue(20)
- .setState(Sensor.SensorState.NONE);
- Sensor.SensorData.Builder cadenceData = Sensor.SensorData.newBuilder().setValue(20)
- .setState(Sensor.SensorState.NONE);
- Sensor.SensorData.Builder heartRateData = Sensor.SensorData.newBuilder().setValue(20)
- .setState(Sensor.SensorState.NONE);
+ Sensor.SensorData.Builder powerData = Sensor.SensorData.newBuilder()
+ .setValue(20).setState(Sensor.SensorState.NONE);
+ Sensor.SensorData.Builder cadenceData = Sensor.SensorData.newBuilder()
+ .setValue(20).setState(Sensor.SensorState.NONE);
+ Sensor.SensorData.Builder heartRateData = Sensor.SensorData.newBuilder()
+ .setValue(20).setState(Sensor.SensorState.NONE);
// Creates SensorDataSet.
SensorDataSet sensorDataSet = myTracksLocation.getSensorDataSet();
- sensorDataSet = sensorDataSet.toBuilder().setPower(powerData).setCadence(cadenceData)
- .setHeartRate(heartRateData).build();
+ sensorDataSet = sensorDataSet.toBuilder()
+ .setPower(powerData)
+ .setCadence(cadenceData)
+ .setHeartRate(heartRateData)
+ .build();
myTracksLocation.setSensorData(sensorDataSet);
// Test.
- point = fillDataPointTestHelper(myTracksLocation, false);
+ point = fillDataPointTestHelper(myTracksLocation);
assertEquals(Double.NaN, point[3]);
assertEquals(Double.NaN, point[4]);
assertEquals(Double.NaN, point[5]);
}
/**
- * Tests the logic to get the correct values of sensor in {@link
- * ChartActivity#fillDataPoint(Location, double[])}.
+ * Tests the logic to get the correct values of sensor in
+ * {@link ChartFragment#fillDataPoint(Location, double[])}.
*/
public void testFillDataPoint_sensorCorrect() {
MyTracksLocation myTracksLocation = TrackStubUtils.createMyTracksLocation();
// No input.
- double[] point = fillDataPointTestHelper(myTracksLocation, false);
+ double[] point = fillDataPointTestHelper(myTracksLocation);
assertEquals(Double.NaN, point[3]);
assertEquals(Double.NaN, point[4]);
assertEquals(Double.NaN, point[5]);
// Creates SensorData.
- Sensor.SensorData.Builder powerData = Sensor.SensorData.newBuilder().setValue(20)
- .setState(Sensor.SensorState.SENDING);
- Sensor.SensorData.Builder cadenceData = Sensor.SensorData.newBuilder().setValue(20)
- .setState(Sensor.SensorState.SENDING);
- Sensor.SensorData.Builder heartRateData = Sensor.SensorData.newBuilder().setValue(20)
- .setState(Sensor.SensorState.SENDING);
+ Sensor.SensorData.Builder powerData = Sensor.SensorData.newBuilder()
+ .setValue(20).setState(Sensor.SensorState.SENDING);
+ Sensor.SensorData.Builder cadenceData = Sensor.SensorData.newBuilder()
+ .setValue(20).setState(Sensor.SensorState.SENDING);
+ Sensor.SensorData.Builder heartRateData = Sensor.SensorData.newBuilder()
+ .setValue(20).setState(Sensor.SensorState.SENDING);
+
// Creates SensorDataSet.
SensorDataSet sensorDataSet = myTracksLocation.getSensorDataSet();
- sensorDataSet = sensorDataSet.toBuilder().setPower(powerData).setCadence(cadenceData)
- .setHeartRate(heartRateData).build();
+ sensorDataSet = sensorDataSet.toBuilder()
+ .setPower(powerData)
+ .setCadence(cadenceData)
+ .setHeartRate(heartRateData)
+ .build();
myTracksLocation.setSensorData(sensorDataSet);
// Test.
- point = fillDataPointTestHelper(myTracksLocation, false);
+ point = fillDataPointTestHelper(myTracksLocation);
assertEquals(20.0, point[3]);
assertEquals(20.0, point[4]);
assertEquals(20.0, point[5]);
@@ -166,61 +114,63 @@ public class ChartActivityTest extends ActivityInstrumentationTestCase2