diff --git a/MyTracks/AndroidManifest.xml b/MyTracks/AndroidManifest.xml
index 4c67b6bb0..6b9aa585a 100755
--- a/MyTracks/AndroidManifest.xml
+++ b/MyTracks/AndroidManifest.xml
@@ -205,7 +205,6 @@ limitations under the License.
-
diff --git a/MyTracks/res/layout/upload_service_chooser.xml b/MyTracks/res/layout/choose_upload_service.xml
similarity index 74%
rename from MyTracks/res/layout/upload_service_chooser.xml
rename to MyTracks/res/layout/choose_upload_service.xml
index d97cf5de8..3b24cf482 100644
--- a/MyTracks/res/layout/upload_service_chooser.xml
+++ b/MyTracks/res/layout/choose_upload_service.xml
@@ -25,24 +25,24 @@ limitations under the License.
+ style="@style/ChooseUploadServiceImageView" />
+ style="@style/ChooseUploadServiceCheckBox" />
-
+
@@ -51,21 +51,21 @@ limitations under the License.
+ style="@style/ChooseUploadServiceImageView" />
+ style="@style/ChooseUploadServiceCheckBox" />
+ style="@style/ChooseUploadServiceImageView" />
+ style="@style/ChooseUploadServiceCheckBox" />
\ No newline at end of file
diff --git a/MyTracks/res/values/styles.xml b/MyTracks/res/values/styles.xml
index abf407a1b..cd6dae0d8 100644
--- a/MyTracks/res/values/styles.xml
+++ b/MyTracks/res/values/styles.xml
@@ -31,6 +31,17 @@ limitations under the License.
- fill_parent
- horizontal
+
+
+
+
-
-
-
-
\ No newline at end of file
diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java
index f3e5aee81..3cfb8963c 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java
@@ -23,6 +23,7 @@ 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.ChooseActivityDialogFragment;
+import com.google.android.apps.mytracks.fragments.ChooseUploadServiceDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment.DeleteOneTrackCaller;
import com.google.android.apps.mytracks.fragments.FrequencyDialogFragment;
@@ -32,7 +33,6 @@ import com.google.android.apps.mytracks.fragments.StatsFragment;
import com.google.android.apps.mytracks.io.file.SaveActivity;
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
-import com.google.android.apps.mytracks.io.sendtogoogle.UploadServiceChooserActivity;
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
import com.google.android.apps.mytracks.settings.SettingsActivity;
import com.google.android.apps.mytracks.util.AnalyticsUtils;
@@ -289,9 +289,9 @@ public class TrackDetailActivity extends AbstractMyTracksActivity implements Del
.show(getSupportFragmentManager(), FrequencyDialogFragment.FREQUENCY_DIALOG_TAG);
return true;
case R.id.track_detail_send_google:
- intent = IntentUtils.newIntent(this, UploadServiceChooserActivity.class)
- .putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId));
- startActivity(intent);
+ ChooseUploadServiceDialogFragment.newInstance(new SendRequest(trackId)).show(
+ getSupportFragmentManager(),
+ ChooseUploadServiceDialogFragment.CHOOSE_UPLOAD_SERVICE_DIALOG_TAG);
return true;
case R.id.track_detail_save_gpx:
startSaveActivity(TrackFileFormat.GPX);
diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/ChooseUploadServiceDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/ChooseUploadServiceDialogFragment.java
new file mode 100644
index 000000000..8534e379e
--- /dev/null
+++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/ChooseUploadServiceDialogFragment.java
@@ -0,0 +1,172 @@
+/*
+ * 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.io.sendtogoogle.AccountChooserActivity;
+import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
+import com.google.android.apps.mytracks.util.AnalyticsUtils;
+import com.google.android.apps.mytracks.util.IntentUtils;
+import com.google.android.apps.mytracks.util.PreferencesUtils;
+import com.google.android.maps.mytracks.R;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
+import android.view.View;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.CompoundButton.OnCheckedChangeListener;
+import android.widget.RadioButton;
+import android.widget.TableRow;
+import android.widget.Toast;
+
+import java.util.ArrayList;
+
+/**
+ * A DialogFragment to choose upload service.
+ *
+ * @author Jimmy Shih
+ */
+public class ChooseUploadServiceDialogFragment extends DialogFragment {
+
+ public static final String CHOOSE_UPLOAD_SERVICE_DIALOG_TAG = "chooseUploadService";
+
+ private static final String KEY_SEND_REQUEST = "sendRequest";
+
+ public static ChooseUploadServiceDialogFragment newInstance(SendRequest sendRequest) {
+ Bundle bundle = new Bundle();
+ bundle.putParcelable(KEY_SEND_REQUEST, sendRequest);
+
+ ChooseUploadServiceDialogFragment chooseUploadServiceDialogFragment =
+ new ChooseUploadServiceDialogFragment();
+ chooseUploadServiceDialogFragment.setArguments(bundle);
+ return chooseUploadServiceDialogFragment;
+ }
+
+ private SendRequest sendRequest;
+
+ private CheckBox mapsCheckBox;
+ private CheckBox fusionTablesCheckBox;
+ private CheckBox docsCheckBox;
+
+ private TableRow mapsOptionTableRow;
+ private RadioButton existingMapRadioButton;
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ sendRequest = getArguments().getParcelable(KEY_SEND_REQUEST);
+ View view = getActivity().getLayoutInflater().inflate(R.layout.choose_upload_service, null);
+
+ mapsCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_maps);
+ fusionTablesCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_fusion_tables);
+ docsCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_docs);
+
+ mapsCheckBox.setChecked(PreferencesUtils.getBoolean(
+ getActivity(), R.string.send_to_maps_key, PreferencesUtils.SEND_TO_MAPS_DEFAULT));
+ fusionTablesCheckBox.setChecked(PreferencesUtils.getBoolean(
+ getActivity(), R.string.send_to_fusion_tables_key,
+ PreferencesUtils.SEND_TO_FUSION_TABLES_DEFAULT));
+ docsCheckBox.setChecked(PreferencesUtils.getBoolean(
+ getActivity(), R.string.send_to_docs_key, PreferencesUtils.SEND_TO_DOCS_DEFAULT));
+
+ mapsCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
+ public void onCheckedChanged(CompoundButton button, boolean checked) {
+ updateMapsOption();
+ }
+ });
+
+ mapsOptionTableRow = (TableRow) view.findViewById(R.id.choose_upload_service_maps_options);
+ RadioButton newMapRadioButton = (RadioButton) view.findViewById(
+ R.id.choose_upload_service_new_map);
+ existingMapRadioButton = (RadioButton) view.findViewById(
+ R.id.choose_upload_service_existing_map);
+
+ updateMapsOption();
+ if (PreferencesUtils.getBoolean(getActivity(), R.string.pick_existing_map_key,
+ PreferencesUtils.PICK_EXISTING_MAP_DEFAULT)) {
+ existingMapRadioButton.setChecked(true);
+ } else {
+ newMapRadioButton.setChecked(true);
+ }
+
+ return new AlertDialog.Builder(getActivity()).setNegativeButton(R.string.generic_cancel, null)
+ .setPositiveButton(R.string.send_google_send_now, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ PreferencesUtils.setBoolean(
+ getActivity(), R.string.pick_existing_map_key, existingMapRadioButton.isChecked());
+ PreferencesUtils.setBoolean(
+ getActivity(), R.string.send_to_maps_key, mapsCheckBox.isChecked());
+ PreferencesUtils.setBoolean(getActivity(), R.string.send_to_fusion_tables_key,
+ fusionTablesCheckBox.isChecked());
+ PreferencesUtils.setBoolean(
+ getActivity(), R.string.send_to_docs_key, docsCheckBox.isChecked());
+ if (mapsCheckBox.isChecked() || fusionTablesCheckBox.isChecked()
+ || docsCheckBox.isChecked()) {
+ startNextActivity();
+ } else {
+ Toast.makeText(
+ getActivity(), R.string.send_google_no_service_selected, Toast.LENGTH_LONG)
+ .show();
+ }
+ }
+ })
+ .setTitle(R.string.send_google_title)
+ .setView(view)
+ .create();
+ }
+
+ /**
+ * Updates map option.
+ */
+ private void updateMapsOption() {
+ mapsOptionTableRow.setVisibility(mapsCheckBox.isChecked() ? View.VISIBLE : View.GONE);
+ }
+
+ /**
+ * Starts the next activity, {@link AccountChooserActivity}.
+ */
+ private void startNextActivity() {
+ sendStats();
+ sendRequest.setSendMaps(mapsCheckBox.isChecked());
+ sendRequest.setSendFusionTables(fusionTablesCheckBox.isChecked());
+ sendRequest.setSendDocs(docsCheckBox.isChecked());
+ sendRequest.setNewMap(!existingMapRadioButton.isChecked());
+ Intent intent = IntentUtils.newIntent(getActivity(), AccountChooserActivity.class)
+ .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
+ startActivity(intent);
+ }
+
+ /**
+ * Sends stats to Google Analytics.
+ */
+ private void sendStats() {
+ ArrayList pages = new ArrayList();
+ if (sendRequest.isSendMaps()) {
+ pages.add("/send/maps");
+ }
+ if (sendRequest.isSendFusionTables()) {
+ pages.add("/send/fusion_tables");
+ }
+ if (sendRequest.isSendDocs()) {
+ pages.add("/send/docs");
+ }
+ AnalyticsUtils.sendPageViews(getActivity(), pages.toArray(new String[pages.size()]));
+ }
+}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadServiceChooserActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadServiceChooserActivity.java
deleted file mode 100644
index d5ec6e443..000000000
--- a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadServiceChooserActivity.java
+++ /dev/null
@@ -1,237 +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.io.sendtogoogle;
-
-import com.google.android.apps.mytracks.util.AnalyticsUtils;
-import com.google.android.apps.mytracks.util.IntentUtils;
-import com.google.android.apps.mytracks.util.PreferencesUtils;
-import com.google.android.maps.mytracks.R;
-import com.google.common.annotations.VisibleForTesting;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.CheckBox;
-import android.widget.CompoundButton;
-import android.widget.CompoundButton.OnCheckedChangeListener;
-import android.widget.RadioButton;
-import android.widget.TableRow;
-import android.widget.Toast;
-
-import java.util.ArrayList;
-
-/**
- * A chooser to select the Google services to upload a track to.
- *
- * @author Jimmy Shih
- */
-public class UploadServiceChooserActivity extends Activity {
-
- private static final int DIALOG_CHOOSER_ID = 0;
-
- private SendRequest sendRequest;
- private AlertDialog alertDialog;
-
- private CheckBox mapsCheckBox;
- private CheckBox fusionTablesCheckBox;
- private CheckBox docsCheckBox;
-
- private TableRow mapsOptionTableRow;
- private RadioButton newMapRadioButton;
- private RadioButton existingMapRadioButton;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- sendRequest = getIntent().getParcelableExtra(SendRequest.SEND_REQUEST_KEY);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- showDialog(DIALOG_CHOOSER_ID);
- }
-
- @Override
- protected Dialog onCreateDialog(int id) {
- if (id != DIALOG_CHOOSER_ID) {
- return null;
- }
- View view = getLayoutInflater().inflate(R.layout.upload_service_chooser, null);
-
- mapsCheckBox = (CheckBox) view.findViewById(R.id.send_google_maps);
- fusionTablesCheckBox = (CheckBox) view.findViewById(R.id.send_google_fusion_tables);
- docsCheckBox = (CheckBox) view.findViewById(R.id.send_google_docs);
-
- mapsOptionTableRow = (TableRow) view.findViewById(R.id.send_google_maps_option_row);
- newMapRadioButton = (RadioButton) view.findViewById(R.id.send_google_new_map);
- existingMapRadioButton = (RadioButton) view.findViewById(R.id.send_google_existing_map);
-
- // Setup checkboxes
- OnCheckedChangeListener checkBoxListener = new OnCheckedChangeListener() {
- public void onCheckedChanged(CompoundButton button, boolean checked) {
- updateStateBySelection();
- }
- };
- mapsCheckBox.setOnCheckedChangeListener(checkBoxListener);
- fusionTablesCheckBox.setOnCheckedChangeListener(checkBoxListener);
- docsCheckBox.setOnCheckedChangeListener(checkBoxListener);
-
- // Setup initial state
- initState();
-
- // Update state based on current selection
- updateStateBySelection();
-
- alertDialog = new AlertDialog.Builder(this)
- .setCancelable(true)
- .setNegativeButton(R.string.generic_cancel, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- finish();
- }
- })
- .setOnCancelListener(new DialogInterface.OnCancelListener() {
- @Override
- public void onCancel(DialogInterface d) {
- finish();
- }
- })
- .setPositiveButton(R.string.send_google_send_now, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- saveState();
- if (sendMaps() || sendFusionTables() || sendDocs()) {
- startNextActivity();
- } else {
- Toast.makeText(UploadServiceChooserActivity.this,
- R.string.send_google_no_service_selected, Toast.LENGTH_LONG).show();
- finish();
- }
- }
- })
- .setTitle(R.string.send_google_title)
- .setView(view)
- .create();
- return alertDialog;
- }
-
- /**
- * Initializes the UI state based on the shared preferences.
- */
- @VisibleForTesting
- void initState() {
- boolean pickExistingMap = PreferencesUtils.getBoolean(
- this, R.string.pick_existing_map_key, PreferencesUtils.PICK_EXISTING_MAP_DEFAULT);
-
- newMapRadioButton.setChecked(!pickExistingMap);
- existingMapRadioButton.setChecked(pickExistingMap);
-
- mapsCheckBox.setChecked(PreferencesUtils.getBoolean(
- this, R.string.send_to_maps_key, PreferencesUtils.SEND_TO_MAPS_DEFAULT));
- fusionTablesCheckBox.setChecked(PreferencesUtils.getBoolean(
- this, R.string.send_to_fusion_tables_key, PreferencesUtils.SEND_TO_FUSION_TABLES_DEFAULT));
- docsCheckBox.setChecked(PreferencesUtils.getBoolean(
- this, R.string.send_to_docs_key, PreferencesUtils.SEND_TO_DOCS_DEFAULT));
- }
-
- /**
- * Updates the UI state based on the current selection.
- */
- private void updateStateBySelection() {
- mapsOptionTableRow.setVisibility(sendMaps() ? View.VISIBLE : View.GONE);
- }
-
- /**
- * Saves the UI state to the shared preferences.
- */
- @VisibleForTesting
- void saveState() {
- PreferencesUtils.setBoolean(
- this, R.string.pick_existing_map_key, existingMapRadioButton.isChecked());
- PreferencesUtils.setBoolean(this, R.string.send_to_maps_key, sendMaps());
- PreferencesUtils.setBoolean(this, R.string.send_to_fusion_tables_key, sendFusionTables());
- PreferencesUtils.setBoolean(this, R.string.send_to_docs_key, sendDocs());
- }
-
- /**
- * Returns true to send to Google Maps.
- */
- private boolean sendMaps() {
- return mapsCheckBox.isChecked();
- }
-
- /**
- * Returns true to send to Google Fusion Tables.
- */
- private boolean sendFusionTables() {
- return fusionTablesCheckBox.isChecked();
- }
-
- /**
- * Returns true to send to Google Docs.
- */
- private boolean sendDocs() {
- return docsCheckBox.isChecked();
- }
-
- /**
- * Starts the next activity, {@link AccountChooserActivity}.
- */
- @VisibleForTesting
- protected void startNextActivity() {
- sendStats();
- sendRequest.setSendMaps(sendMaps());
- sendRequest.setSendFusionTables(sendFusionTables());
- sendRequest.setSendDocs(sendDocs());
- sendRequest.setNewMap(!existingMapRadioButton.isChecked());
- Intent intent = IntentUtils.newIntent(this, AccountChooserActivity.class)
- .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
- startActivity(intent);
- finish();
- }
-
- /**
- * Sends stats to Google Analytics.
- */
- private void sendStats() {
- ArrayList pages = new ArrayList();
- if (sendRequest.isSendMaps()) {
- pages.add("/send/maps");
- }
- if (sendRequest.isSendFusionTables()) {
- pages.add("/send/fusion_tables");
- }
- if (sendRequest.isSendDocs()) {
- pages.add("/send/docs");
- }
- AnalyticsUtils.sendPageViews(this, pages.toArray(new String[pages.size()]));
- }
-
- @VisibleForTesting
- AlertDialog getAlertDialog() {
- return alertDialog;
- }
-
- @VisibleForTesting
- SendRequest getSendRequest() {
- return sendRequest;
- }
-}
diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadServiceChooserActivityTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadServiceChooserActivityTest.java
deleted file mode 100644
index 44e1c93fc..000000000
--- a/MyTracksTest/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadServiceChooserActivityTest.java
+++ /dev/null
@@ -1,219 +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.io.sendtogoogle;
-
-import com.google.android.apps.mytracks.util.PreferencesUtils;
-import com.google.android.maps.mytracks.R;
-
-import android.app.Instrumentation;
-import android.content.Intent;
-import android.test.ActivityInstrumentationTestCase2;
-import android.widget.CheckBox;
-import android.widget.RadioButton;
-
-/**
- * Tests the {@link UploadServiceChooserActivity}.
- *
- * @author Youtao Liu
- */
-public class UploadServiceChooserActivityTest extends
- ActivityInstrumentationTestCase2 {
-
- private Instrumentation instrumentation;
- private UploadServiceChooserActivity uploadServiceChooserActivity;
-
- public UploadServiceChooserActivityTest() {
- super(UploadServiceChooserActivity.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- instrumentation = getInstrumentation();
- }
-
- /**
- * Tests the logic to display all options.
- */
- public void testOnCreateDialog_displayAll() {
- // Initials activity to display all send items.
- initialActivity();
- instrumentation.waitForIdleSync();
- assertTrue(getMapsCheckBox().isShown());
- assertTrue(getFusionTablesCheckBox().isShown());
- assertTrue(getDocsCheckBox().isShown());
-
- // Clicks to disable all send items.
- uploadServiceChooserActivity.runOnUiThread(new Runnable() {
- public void run() {
- if (getMapsCheckBox().isChecked()) {
- getMapsCheckBox().performClick();
- }
- if (getFusionTablesCheckBox().isChecked()) {
- getFusionTablesCheckBox().performClick();
- }
- if (getDocsCheckBox().isChecked()) {
- getDocsCheckBox().performClick();
- }
- }
- });
- instrumentation.waitForIdleSync();
- assertTrue(getMapsCheckBox().isShown());
- assertTrue(getFusionTablesCheckBox().isShown());
- assertTrue(getDocsCheckBox().isShown());
-
- assertFalse(getNewMapRadioButton().isShown());
- assertFalse(getExistingMapRadioButton().isShown());
- }
-
- /**
- * Tests the logic to initial state of check box to unchecked. This test cover
- * code in method {@link UploadServiceChooserActivity#onCreateDialog(int)},
- * {@link UploadServiceChooserActivity#initState()}.
- */
- public void testOnCreateDialog_initStateUnchecked() {
- initialActivity();
- // Initial all values to false in SharedPreferences.
- PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key, false);
- PreferencesUtils.setBoolean(
- uploadServiceChooserActivity, R.string.send_to_fusion_tables_key, false);
- PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key, false);
- uploadServiceChooserActivity.runOnUiThread(new Runnable() {
- public void run() {
- uploadServiceChooserActivity.initState();
- }
- });
- instrumentation.waitForIdleSync();
- assertFalse(getMapsCheckBox().isChecked());
- assertFalse(getFusionTablesCheckBox().isChecked());
- assertFalse(getDocsCheckBox().isChecked());
- }
-
- /**
- * Tests the logic to initial state of check box to checked. This test cover
- * code in method {@link UploadServiceChooserActivity#onCreateDialog(int)},
- * {@link UploadServiceChooserActivity#initState()}.
- */
- public void testOnCreateDialog_initStateChecked() {
- initialActivity();
- // Initial all values to true in SharedPreferences.
- PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.pick_existing_map_key, true);
- PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key, true);
- PreferencesUtils.setBoolean(
- uploadServiceChooserActivity, R.string.send_to_fusion_tables_key, true);
- PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key, true);
- uploadServiceChooserActivity.runOnUiThread(new Runnable() {
- public void run() {
- uploadServiceChooserActivity.initState();
- }
- });
- instrumentation.waitForIdleSync();
- assertTrue(getMapsCheckBox().isChecked());
- assertTrue(getFusionTablesCheckBox().isChecked());
- assertTrue(getDocsCheckBox().isChecked());
- assertTrue(getExistingMapRadioButton().isChecked());
-
- assertFalse(getNewMapRadioButton().isChecked());
- }
-
- /**
- * Tests the logic of saveState when click send button. This test cover code
- * in method {@link UploadServiceChooserActivity#initState()} and
- * {@link UploadServiceChooserActivity#saveState()},
- */
- public void testOnCreateDialog_saveState() {
- initialActivity();
- // Initial all values to true in SharedPreferences.
- PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key, true);
- PreferencesUtils.setBoolean(
- uploadServiceChooserActivity, R.string.send_to_fusion_tables_key, true);
- PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key, true);
- uploadServiceChooserActivity.runOnUiThread(new Runnable() {
- public void run() {
- uploadServiceChooserActivity.initState();
- }
- });
- instrumentation.waitForIdleSync();
- uploadServiceChooserActivity.saveState();
- // All values in SharedPreferences must be changed.
- assertTrue(PreferencesUtils.getBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key,
- PreferencesUtils.SEND_TO_MAPS_DEFAULT));
- assertTrue(PreferencesUtils.getBoolean(
- uploadServiceChooserActivity, R.string.send_to_fusion_tables_key,
- PreferencesUtils.SEND_TO_FUSION_TABLES_DEFAULT));
- assertTrue(PreferencesUtils.getBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key,
- PreferencesUtils.SEND_TO_DOCS_DEFAULT));
- }
-
- /**
- * Tests the logic of startNextActivity when click send button. This test
- * cover code in method {@link UploadServiceChooserActivity#initState()} and
- * {@link UploadServiceChooserActivity#startNextActivity()}.
- */
- public void testOnCreateDialog_startNextActivity() {
- initialActivity();
- // Initial all values to true or false in SharedPreferences.
- PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key, true);
- PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key, true);
- PreferencesUtils.setBoolean(
- uploadServiceChooserActivity, R.string.send_to_fusion_tables_key, false);
- uploadServiceChooserActivity.runOnUiThread(new Runnable() {
- public void run() {
- uploadServiceChooserActivity.initState();
- }
- });
- instrumentation.waitForIdleSync();
- uploadServiceChooserActivity.startNextActivity();
- // All values in SendRequest must be same as set above.
- assertTrue(uploadServiceChooserActivity.getSendRequest().isSendMaps());
- assertTrue(uploadServiceChooserActivity.getSendRequest().isSendDocs());
-
- assertFalse(uploadServiceChooserActivity.getSendRequest().isSendFusionTables());
- }
-
- /**
- * Initials a activity to be tested.
- */
- private void initialActivity() {
- Intent intent = new Intent();
- intent.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(1L));
- setActivityIntent(intent);
- uploadServiceChooserActivity = this.getActivity();
- }
-
- private CheckBox getMapsCheckBox() {
- return (CheckBox) uploadServiceChooserActivity.getAlertDialog().findViewById(R.id.send_google_maps);
- }
-
- private CheckBox getFusionTablesCheckBox() {
- return (CheckBox) uploadServiceChooserActivity.getAlertDialog().findViewById(
- R.id.send_google_fusion_tables);
- }
-
- private CheckBox getDocsCheckBox() {
- return (CheckBox) uploadServiceChooserActivity.getAlertDialog().findViewById(R.id.send_google_docs);
- }
-
- private RadioButton getNewMapRadioButton() {
- return (RadioButton) uploadServiceChooserActivity.getAlertDialog().findViewById(
- R.id.send_google_new_map);
- }
-
- private RadioButton getExistingMapRadioButton() {
- return (RadioButton) uploadServiceChooserActivity.getAlertDialog().findViewById(
- R.id.send_google_existing_map);
- }
-}