mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Remove ChooseMapActivity.
This commit is contained in:
@@ -212,9 +212,6 @@ limitations under the License.
|
||||
<activity android:name="com.google.android.apps.mytracks.io.drive.SendDriveActivity" />
|
||||
<activity android:name="com.google.android.apps.mytracks.io.file.SaveActivity" />
|
||||
<activity android:name="com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesActivity" />
|
||||
<activity
|
||||
android:label="@string/maps_list_title"
|
||||
android:name="com.google.android.apps.mytracks.io.maps.ChooseMapActivity" />
|
||||
<activity android:name="com.google.android.apps.mytracks.io.maps.SendMapsActivity" />
|
||||
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity" />
|
||||
<activity android:name="com.google.android.apps.mytracks.io.spreadsheets.SendSpreadsheetsActivity" />
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2010 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.
|
||||
-->
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent" >
|
||||
<ListView
|
||||
android:id="@+id/choose_map_list_view"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent" />
|
||||
<TextView
|
||||
android:id="@+id/choose_map_empty_view"
|
||||
style="@style/ListEmptyTextView" >
|
||||
</TextView>
|
||||
</merge>
|
||||
@@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2010 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp" >
|
||||
<TextView
|
||||
android:id="@+id/choose_map_item_title"
|
||||
android:singleLine="true"
|
||||
style="@style/TextLarge" />
|
||||
<TextView
|
||||
android:id="@+id/choose_map_item_description"
|
||||
android:singleLine="false"
|
||||
android:textColor="@android:color/secondary_text_dark"
|
||||
style="@style/TextSmall" />
|
||||
<TextView
|
||||
android:id="@+id/choose_map_item_search_status"
|
||||
android:singleLine="true"
|
||||
style="@style/TextSmall" />
|
||||
</LinearLayout>
|
||||
@@ -935,38 +935,6 @@ limitations under the License.
|
||||
Select all
|
||||
</string>
|
||||
|
||||
<!-- Maps List -->
|
||||
<string name="maps_list_error"
|
||||
translation_description="When sending a track to an existing Google Map, the text on the Maps'
|
||||
list page informing the user that his maps cannot be loaded at this time.">
|
||||
Your maps could not be loaded at this time.
|
||||
</string>
|
||||
<string name="maps_list_no_maps"
|
||||
translation_description="When sending a track to an existing Google Map, the text on the 'Maps'
|
||||
list page informing the user that he doesn't have any maps.">
|
||||
You don\'t have any maps.
|
||||
</string>
|
||||
<string name="maps_list_progress_message"
|
||||
translation_description="When sending a track to an existing Google Map, the progress message
|
||||
informing the user that his maps are being loaded.">
|
||||
Loading your Google Maps…
|
||||
</string>
|
||||
<string name="maps_list_public_label"
|
||||
translation_description="When sending a track to an existing Google Map, in the 'Maps' list
|
||||
page, the label next to the maps that are public, as opposed to being unlisted.">
|
||||
Public
|
||||
</string>
|
||||
<string name="maps_list_title"
|
||||
translation_description="When sending a track to an existing Google Map, the title of the page
|
||||
asking the user to pick a map.">
|
||||
Pick a Map
|
||||
</string>
|
||||
<string name="maps_list_unlisted_label"
|
||||
translation_description="When sending a track to an existing Google Map, in the 'Maps' list
|
||||
page, the label next to the maps that are unlisted, as opposed to being public.">
|
||||
Unlisted
|
||||
</string>
|
||||
|
||||
<!-- Marker -->
|
||||
<string name="marker_add_error"
|
||||
translation_description="When adding a marker, the message indicating error due to no GPS
|
||||
|
||||
@@ -32,7 +32,6 @@ import com.google.android.apps.mytracks.io.file.SaveActivity;
|
||||
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
|
||||
import com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesActivity;
|
||||
import com.google.android.apps.mytracks.io.gdata.maps.MapsConstants;
|
||||
import com.google.android.apps.mytracks.io.maps.ChooseMapActivity;
|
||||
import com.google.android.apps.mytracks.io.maps.SendMapsActivity;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils;
|
||||
@@ -200,8 +199,7 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
||||
if (packageName != null && className != null) {
|
||||
sendRequest.setMapsSharePackageName(packageName);
|
||||
sendRequest.setMapsShareClassName(className);
|
||||
Intent intent = IntentUtils.newIntent(
|
||||
this, sendRequest.isMapsExistingMap() ? ChooseMapActivity.class : SendMapsActivity.class)
|
||||
Intent intent = IntentUtils.newIntent(this, SendMapsActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||
startActivity(intent);
|
||||
}
|
||||
@@ -320,7 +318,7 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
||||
getSupportFragmentManager(), ChooseActivityDialogFragment.CHOOSE_ACTIVITY_DIALOG_TAG);
|
||||
return;
|
||||
}
|
||||
next = sendRequest.isMapsExistingMap() ? ChooseMapActivity.class : SendMapsActivity.class;
|
||||
next = SendMapsActivity.class;
|
||||
} else if (sendRequest.isSendFusionTables()) {
|
||||
next = SendFusionTablesActivity.class;
|
||||
} else if (sendRequest.isSendSpreadsheets()) {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.google.android.apps.mytracks.io.drive;
|
||||
|
||||
import com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesActivity;
|
||||
import com.google.android.apps.mytracks.io.maps.ChooseMapActivity;
|
||||
import com.google.android.apps.mytracks.io.maps.SendMapsActivity;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendActivity;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendAsyncTask;
|
||||
@@ -62,7 +61,7 @@ public class SendDriveActivity extends AbstractSendActivity {
|
||||
return UploadResultActivity.class;
|
||||
} else {
|
||||
if (sendRequest.isSendMaps()) {
|
||||
return sendRequest.isMapsExistingMap() ? ChooseMapActivity.class : SendMapsActivity.class;
|
||||
return SendMapsActivity.class;
|
||||
} else if (sendRequest.isSendFusionTables()) {
|
||||
return SendFusionTablesActivity.class;
|
||||
} else if (sendRequest.isSendSpreadsheets()) {
|
||||
|
||||
@@ -1,248 +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.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.io.gdata.maps.MapsMapMetadata;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
|
||||
import com.google.android.apps.mytracks.util.DialogUtils;
|
||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
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.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* An activity to choose a Google Map.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class ChooseMapActivity extends Activity {
|
||||
|
||||
private static final int DIALOG_PROGRESS_ID = 0;
|
||||
private static final int DIALOG_ERROR_ID = 1;
|
||||
|
||||
private SendRequest sendRequest;
|
||||
private ChooseMapAsyncTask asyncTask;
|
||||
@VisibleForTesting
|
||||
ArrayAdapter<ListItem> arrayAdapter;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
sendRequest = getIntent().getParcelableExtra(SendRequest.SEND_REQUEST_KEY);
|
||||
setContentView(R.layout.choose_map);
|
||||
|
||||
arrayAdapter = new ArrayAdapter<ListItem>(this, R.layout.choose_map_item, new ArrayList<
|
||||
ListItem>()) {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if (convertView == null) {
|
||||
convertView = getLayoutInflater().inflate(R.layout.choose_map_item, parent, false);
|
||||
}
|
||||
MapsMapMetadata mapData = getItem(position).getMapData();
|
||||
|
||||
TextView title = (TextView) convertView.findViewById(R.id.choose_map_item_title);
|
||||
title.setText(mapData.getTitle());
|
||||
|
||||
TextView description = (TextView) convertView.findViewById(
|
||||
R.id.choose_map_item_description);
|
||||
String descriptionText = mapData.getDescription();
|
||||
if (descriptionText == null || descriptionText.equals("")) {
|
||||
description.setVisibility(View.GONE);
|
||||
} else {
|
||||
description.setVisibility(View.VISIBLE);
|
||||
description.setText(descriptionText);
|
||||
}
|
||||
|
||||
TextView searchStatus = (TextView) convertView.findViewById(
|
||||
R.id.choose_map_item_search_status);
|
||||
searchStatus.setTextColor(mapData.getSearchable() ? Color.RED : Color.GREEN);
|
||||
searchStatus.setText(mapData.getSearchable() ? R.string.maps_list_public_label
|
||||
: R.string.maps_list_unlisted_label);
|
||||
return convertView;
|
||||
}
|
||||
};
|
||||
|
||||
ListView list = (ListView) findViewById(R.id.choose_map_list_view);
|
||||
list.setEmptyView(findViewById(R.id.choose_map_empty_view));
|
||||
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
startNextActivity(arrayAdapter.getItem(position).getMapId());
|
||||
}
|
||||
});
|
||||
list.setAdapter(arrayAdapter);
|
||||
|
||||
Object retained = getLastNonConfigurationInstance();
|
||||
if (retained instanceof ChooseMapAsyncTask) {
|
||||
asyncTask = (ChooseMapAsyncTask) retained;
|
||||
asyncTask.setActivity(this);
|
||||
} else {
|
||||
asyncTask = new ChooseMapAsyncTask(this, sendRequest.getAccount());
|
||||
asyncTask.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object onRetainNonConfigurationInstance() {
|
||||
asyncTask.setActivity(null);
|
||||
return asyncTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
switch (id) {
|
||||
case DIALOG_PROGRESS_ID:
|
||||
return DialogUtils.createSpinnerProgressDialog(
|
||||
this, R.string.maps_list_progress_message, new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
asyncTask.cancel(true);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
case DIALOG_ERROR_ID:
|
||||
return new AlertDialog.Builder(this)
|
||||
.setCancelable(true)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setMessage(R.string.maps_list_error)
|
||||
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int arg1) {
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.setTitle(R.string.generic_error_title)
|
||||
.create();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes when the associated AsyncTask completes.
|
||||
*
|
||||
* @param success true if success
|
||||
* @param mapIds an array of map ids
|
||||
* @param mapData an array of map data
|
||||
*/
|
||||
public void onAsyncTaskCompleted(
|
||||
boolean success, ArrayList<String> mapIds, ArrayList<MapsMapMetadata> mapData) {
|
||||
removeProgressDialog();
|
||||
if (success) {
|
||||
arrayAdapter.clear();
|
||||
// To prevent displaying the emptyView message momentarily before the
|
||||
// arrayAdapter is set, don't set the emptyView message in the xml layout.
|
||||
// Instead, set it only when needed.
|
||||
if (mapIds.size() == 0) {
|
||||
TextView emptyView = (TextView) findViewById(R.id.choose_map_empty_view);
|
||||
emptyView.setText(R.string.maps_list_no_maps);
|
||||
} else {
|
||||
for (int i = 0; i < mapIds.size(); i++) {
|
||||
arrayAdapter.add(new ListItem(mapIds.get(i), mapData.get(i)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
showErrorDialog();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the progress dialog.
|
||||
*/
|
||||
public void showProgressDialog() {
|
||||
showDialog(DIALOG_PROGRESS_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the error dialog.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void showErrorDialog() {
|
||||
showDialog(DIALOG_ERROR_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the progress dialog.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void removeProgressDialog() {
|
||||
removeDialog(DIALOG_PROGRESS_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the next activity, {@link SendMapsActivity}.
|
||||
*
|
||||
* @param mapId the chosen map id
|
||||
*/
|
||||
private void startNextActivity(String mapId) {
|
||||
sendRequest.setMapsExistingMapId(mapId);
|
||||
Intent intent = IntentUtils.newIntent(this, SendMapsActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* A class containing {@link ChooseMapActivity} list item.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
@VisibleForTesting
|
||||
class ListItem {
|
||||
private String mapId;
|
||||
private MapsMapMetadata mapData;
|
||||
|
||||
private ListItem(String mapId, MapsMapMetadata mapData) {
|
||||
this.mapId = mapId;
|
||||
this.mapData = mapData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the map id.
|
||||
*/
|
||||
public String getMapId() {
|
||||
return mapId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the map data.
|
||||
*/
|
||||
public MapsMapMetadata getMapData() {
|
||||
return mapData;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,239 +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.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.io.gdata.GDataClientFactory;
|
||||
import com.google.android.apps.mytracks.io.gdata.maps.MapFeatureEntry;
|
||||
import com.google.android.apps.mytracks.io.gdata.maps.MapsClient;
|
||||
import com.google.android.apps.mytracks.io.gdata.maps.MapsConstants;
|
||||
import com.google.android.apps.mytracks.io.gdata.maps.MapsGDataConverter;
|
||||
import com.google.android.apps.mytracks.io.gdata.maps.MapsMapMetadata;
|
||||
import com.google.android.apps.mytracks.io.gdata.maps.XmlMapsGDataParserFactory;
|
||||
import com.google.android.common.gdata.AndroidXmlParserFactory;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.wireless.gdata.client.GDataClient;
|
||||
import com.google.wireless.gdata.client.HttpException;
|
||||
import com.google.wireless.gdata.parser.GDataParser;
|
||||
import com.google.wireless.gdata.parser.ParseException;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* AsyncTask for {@link ChooseMapActivity} to get all the maps from Google Maps.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class ChooseMapAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
private static final String TAG = ChooseMapAsyncTask.class.getSimpleName();
|
||||
|
||||
private ChooseMapActivity activity;
|
||||
private final Account account;
|
||||
private final Context context;
|
||||
private final GDataClient gDataClient;
|
||||
private final MapsClient mapsClient;
|
||||
|
||||
/**
|
||||
* True if can retry sending to Google Fusion Tables.
|
||||
*/
|
||||
private boolean canRetry;
|
||||
|
||||
/**
|
||||
* True if the AsyncTask has completed.
|
||||
*/
|
||||
private boolean completed;
|
||||
|
||||
/**
|
||||
* True if the result is success.
|
||||
*/
|
||||
private boolean success;
|
||||
|
||||
// The following variables are for per request states
|
||||
private String authToken;
|
||||
private ArrayList<String> mapIds;
|
||||
private ArrayList<MapsMapMetadata> mapData;
|
||||
|
||||
public ChooseMapAsyncTask(ChooseMapActivity activity, Account account) {
|
||||
this.activity = activity;
|
||||
this.account = account;
|
||||
|
||||
this.context = activity.getApplicationContext();
|
||||
this.gDataClient = GDataClientFactory
|
||||
.getGDataClient(activity.getApplicationContext());
|
||||
this.mapsClient = new MapsClient(
|
||||
GDataClientFactory.getGDataClient(activity.getApplicationContext()),
|
||||
new XmlMapsGDataParserFactory(new AndroidXmlParserFactory()));
|
||||
|
||||
canRetry = true;
|
||||
completed = false;
|
||||
success = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the activity associated with this AyncTask.
|
||||
*
|
||||
* @param activity the activity.
|
||||
*/
|
||||
public void setActivity(ChooseMapActivity activity) {
|
||||
this.activity = activity;
|
||||
if (completed && activity != null) {
|
||||
activity.onAsyncTaskCompleted(success, mapIds, mapData);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
activity.showProgressDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
try {
|
||||
return getMaps();
|
||||
} finally {
|
||||
if (gDataClient != null) {
|
||||
gDataClient.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result) {
|
||||
success = result;
|
||||
completed = true;
|
||||
if (activity != null) {
|
||||
activity.onAsyncTaskCompleted(success, mapIds, mapData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the maps from Google Maps.
|
||||
*
|
||||
* @return true if success.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
boolean getMaps() {
|
||||
// Reset the per request states
|
||||
authToken = null;
|
||||
mapIds = new ArrayList<String>();
|
||||
mapData = new ArrayList<MapsMapMetadata>();
|
||||
|
||||
try {
|
||||
authToken = AccountManager.get(context).blockingGetAuthToken(
|
||||
account, MapsConstants.SERVICE_NAME, false);
|
||||
} catch (OperationCanceledException e) {
|
||||
Log.d(TAG, "Unable to get auth token", e);
|
||||
return retryUpload();
|
||||
} catch (AuthenticatorException e) {
|
||||
Log.d(TAG, "Unable to get auth token", e);
|
||||
return retryUpload();
|
||||
} catch (IOException e) {
|
||||
Log.d(TAG, "Unable to get auth token", e);
|
||||
return retryUpload();
|
||||
}
|
||||
|
||||
if (isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
GDataParser gDataParser = null;
|
||||
try {
|
||||
gDataParser = mapsClient.getParserForFeed(
|
||||
MapFeatureEntry.class, MapsClient.getMapsFeed(), authToken);
|
||||
gDataParser.init();
|
||||
while (gDataParser.hasMoreData()) {
|
||||
MapFeatureEntry entry = (MapFeatureEntry) gDataParser.readNextEntry(null);
|
||||
mapIds.add(MapsGDataConverter.getMapidForEntry(entry));
|
||||
mapData.add(MapsGDataConverter.getMapMetadataForEntry(entry));
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
Log.d(TAG, "Unable to get maps", e);
|
||||
return retryUpload();
|
||||
} catch (IOException e) {
|
||||
Log.d(TAG, "Unable to get maps", e);
|
||||
return retryUpload();
|
||||
} catch (HttpException e) {
|
||||
Log.d(TAG, "Unable to get maps", e);
|
||||
return retryUpload();
|
||||
} finally {
|
||||
if (gDataParser != null) {
|
||||
gDataParser.close();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retries upload. Invalidates the authToken. If can retry, invokes
|
||||
* {@link ChooseMapAsyncTask#getMaps()}. Returns false if cannot retry.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
boolean retryUpload() {
|
||||
if (isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AccountManager.get(context).invalidateAuthToken(Constants.ACCOUNT_TYPE, authToken);
|
||||
if (canRetry) {
|
||||
canRetry = false;
|
||||
return getMaps();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the complete status of task.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
boolean getCompleted() {
|
||||
return completed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the complete status of task.
|
||||
* @param completed
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void setCompleted(boolean completed) {
|
||||
this.completed = completed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status of canRetry.
|
||||
* @param canRetry status of canRetry
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void setCanRetry(boolean canRetry) {
|
||||
this.canRetry = canRetry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status of canRetry.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
boolean getCanRetry() {
|
||||
return canRetry;
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,7 @@ public class SendMapsActivity extends AbstractSendActivity {
|
||||
|
||||
@Override
|
||||
protected AbstractSendAsyncTask createAsyncTask() {
|
||||
return new SendMapsAsyncTask(
|
||||
this, sendRequest.getTrackId(), sendRequest.getAccount(), sendRequest.getMapsExistingMapId());
|
||||
return new SendMapsAsyncTask(this, sendRequest.getTrackId(), sendRequest.getAccount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -83,7 +83,6 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
||||
|
||||
private final long trackId;
|
||||
private final Account account;
|
||||
private final String chooseMapId;
|
||||
private final MyTracksProviderUtils myTracksProviderUtils;
|
||||
private final Context context;
|
||||
private final GDataClient gDataClient;
|
||||
@@ -95,9 +94,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
||||
private String mapId;
|
||||
int currentSegment;
|
||||
|
||||
public SendMapsAsyncTask(
|
||||
SendMapsActivity activity, long trackId, Account account, String chooseMapId) {
|
||||
this(activity, trackId, account, chooseMapId, MyTracksProviderUtils.Factory.get(
|
||||
public SendMapsAsyncTask(SendMapsActivity activity, long trackId, Account account) {
|
||||
this(activity, trackId, account, MyTracksProviderUtils.Factory.get(
|
||||
activity.getApplicationContext()));
|
||||
}
|
||||
|
||||
@@ -106,11 +104,10 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public SendMapsAsyncTask(SendMapsActivity activity, long trackId, Account account,
|
||||
String chooseMapId, MyTracksProviderUtils myTracksProviderUtils) {
|
||||
MyTracksProviderUtils myTracksProviderUtils) {
|
||||
super(activity);
|
||||
this.trackId = trackId;
|
||||
this.account = account;
|
||||
this.chooseMapId = chooseMapId;
|
||||
this.myTracksProviderUtils = myTracksProviderUtils;
|
||||
context = activity.getApplicationContext();
|
||||
|
||||
@@ -218,30 +215,25 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (chooseMapId != null) {
|
||||
mapId = chooseMapId;
|
||||
return true;
|
||||
} else {
|
||||
boolean defaultMapPublic = PreferencesUtils.getBoolean(context,
|
||||
R.string.export_google_maps_public_key,
|
||||
PreferencesUtils.EXPORT_GOOGLE_MAPS_PUBLIC_DEFAULT);
|
||||
try {
|
||||
String description = track.getCategory() + "\n" + track.getDescription() + "\n"
|
||||
+ context.getString(R.string.send_google_by_my_tracks, "", "");
|
||||
mapId = SendMapsUtils.createNewMap(
|
||||
track.getName(), description, defaultMapPublic, mapsClient, authToken);
|
||||
} catch (ParseException e) {
|
||||
Log.d(TAG, "Unable to create a new map", e);
|
||||
return false;
|
||||
} catch (HttpException e) {
|
||||
Log.d(TAG, "Unable to create a new map", e);
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
Log.d(TAG, "Unable to create a new map", e);
|
||||
return false;
|
||||
}
|
||||
return mapId != null;
|
||||
boolean defaultMapPublic = PreferencesUtils.getBoolean(context,
|
||||
R.string.export_google_maps_public_key, PreferencesUtils.EXPORT_GOOGLE_MAPS_PUBLIC_DEFAULT);
|
||||
try {
|
||||
String description = track.getCategory() + "\n" + track.getDescription() + "\n"
|
||||
+ context.getString(R.string.send_google_by_my_tracks, "", "");
|
||||
mapId = SendMapsUtils.createNewMap(
|
||||
track.getName(), description, defaultMapPublic, mapsClient, authToken);
|
||||
} catch (ParseException e) {
|
||||
Log.d(TAG, "Unable to create a new map", e);
|
||||
return false;
|
||||
} catch (HttpException e) {
|
||||
Log.d(TAG, "Unable to create a new map", e);
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
Log.d(TAG, "Unable to create a new map", e);
|
||||
return false;
|
||||
}
|
||||
return mapId != null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,8 +43,6 @@ public class SendRequest implements Parcelable {
|
||||
private boolean mapsShare = false;
|
||||
private String mapsSharePackageName = null;
|
||||
private String mapsShareClassName = null;
|
||||
private boolean mapsExistingMap = false;
|
||||
private String mapsExistingMapId = null;
|
||||
|
||||
private Account account = null;
|
||||
|
||||
@@ -146,22 +144,6 @@ public class SendRequest implements Parcelable {
|
||||
this.mapsShareClassName = mapsShareClassName;
|
||||
}
|
||||
|
||||
public boolean isMapsExistingMap() {
|
||||
return mapsExistingMap;
|
||||
}
|
||||
|
||||
public void setMapsExistingMap(boolean mapsExistingMap) {
|
||||
this.mapsExistingMap = mapsExistingMap;
|
||||
}
|
||||
|
||||
public String getMapsExistingMapId() {
|
||||
return mapsExistingMapId;
|
||||
}
|
||||
|
||||
public void setMapsExistingMapId(String mapsExistingMapId) {
|
||||
this.mapsExistingMapId = mapsExistingMapId;
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
@@ -214,8 +196,6 @@ public class SendRequest implements Parcelable {
|
||||
mapsShare = in.readByte() == 1;
|
||||
mapsSharePackageName = in.readString();
|
||||
mapsShareClassName = in.readString();
|
||||
mapsExistingMap = in.readByte() == 1;
|
||||
mapsExistingMapId = in.readString();
|
||||
account = in.readParcelable(null);
|
||||
driveSuccess = in.readByte() == 1;
|
||||
mapsSuccess = in.readByte() == 1;
|
||||
@@ -241,8 +221,6 @@ public class SendRequest implements Parcelable {
|
||||
out.writeByte((byte) (mapsShare ? 1 : 0));
|
||||
out.writeString(mapsSharePackageName);
|
||||
out.writeString(mapsShareClassName);
|
||||
out.writeByte((byte) (mapsExistingMap ? 1 : 0));
|
||||
out.writeString(mapsExistingMapId);
|
||||
out.writeParcelable(account, 0);
|
||||
out.writeByte((byte) (driveSuccess ? 1 : 0));
|
||||
out.writeByte((byte) (mapsSuccess ? 1 : 0));
|
||||
|
||||
@@ -1,144 +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.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.io.gdata.maps.MapsMapMetadata;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Tests the {@link ChooseMapActivity}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class ChooseMapActivityTest extends AndroidTestCase {
|
||||
|
||||
private static final String MAP_ID = "mapid";
|
||||
private static final String MAP_TITLE = "title";
|
||||
private static final String MAP_DESC = "desc";
|
||||
|
||||
private ArrayList<String> mapIds = new ArrayList<String>();
|
||||
private ArrayList<MapsMapMetadata> mapDatas = new ArrayList<MapsMapMetadata>();
|
||||
private boolean errorDialogShown = false;
|
||||
private boolean progressDialogRemoved = false;
|
||||
|
||||
/**
|
||||
* Creates a class to override some methods of {@link ChooseMapActivity} to
|
||||
* makes it testable.
|
||||
*
|
||||
* @author youtaol
|
||||
*/
|
||||
public class ChooseMapActivityMock extends ChooseMapActivity {
|
||||
/**
|
||||
* By overriding this method, avoids to start next activity.
|
||||
*/
|
||||
@Override
|
||||
public void startActivity(Intent intent) {}
|
||||
|
||||
/**
|
||||
* By overriding this method, avoids to show an error dialog and set the
|
||||
* show flag to true.
|
||||
*/
|
||||
@Override
|
||||
public void showErrorDialog() {
|
||||
errorDialogShown = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* By overriding this method, avoids to show an error dialog and set the
|
||||
* show flag to true.
|
||||
*/
|
||||
@Override
|
||||
public void removeProgressDialog() {
|
||||
progressDialogRemoved = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link ChooseMapActivity#onAsyncTaskCompleted(boolean, ArrayList, ArrayList)}
|
||||
* . An alert dialog should be shown when there is no map.
|
||||
*/
|
||||
public void testOnAsyncTaskCompleted_fail() {
|
||||
ChooseMapActivityMock chooseMapActivityMock = new ChooseMapActivityMock();
|
||||
errorDialogShown = false;
|
||||
progressDialogRemoved = false;
|
||||
chooseMapActivityMock.onAsyncTaskCompleted(false, null, null);
|
||||
assertTrue(progressDialogRemoved);
|
||||
assertTrue(errorDialogShown);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link ChooseMapActivity#onAsyncTaskCompleted(boolean, ArrayList, ArrayList)}
|
||||
* . Check the logic when there is only map.
|
||||
*/
|
||||
public void testOnAsyncTaskCompleted_success_oneMap() {
|
||||
ChooseMapActivityMock chooseMapActivityMock = new ChooseMapActivityMock();
|
||||
chooseMapActivityMock.arrayAdapter = new ArrayAdapter<ChooseMapActivity.ListItem>(getContext(),
|
||||
R.layout.choose_map_item);
|
||||
simulateMaps(1);
|
||||
chooseMapActivityMock.onAsyncTaskCompleted(true, mapIds, mapDatas);
|
||||
assertEquals(1, chooseMapActivityMock.arrayAdapter.getCount());
|
||||
assertEquals(MAP_ID + "0", chooseMapActivityMock.arrayAdapter.getItem(0).getMapId());
|
||||
assertEquals(MAP_TITLE + "0", chooseMapActivityMock.arrayAdapter.getItem(0).getMapData()
|
||||
.getTitle());
|
||||
assertEquals(MAP_DESC + "0", chooseMapActivityMock.arrayAdapter.getItem(0).getMapData()
|
||||
.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link ChooseMapActivity#onAsyncTaskCompleted(boolean, ArrayList, ArrayList)}
|
||||
* . Check the logic when there are 10 maps.
|
||||
*/
|
||||
public void testOnAsyncTaskCompleted_success_twoMaps() {
|
||||
ChooseMapActivityMock chooseMapActivityMock = new ChooseMapActivityMock();
|
||||
chooseMapActivityMock.arrayAdapter = new ArrayAdapter<ChooseMapActivity.ListItem>(getContext(),
|
||||
R.layout.choose_map_item);
|
||||
simulateMaps(10);
|
||||
chooseMapActivityMock.onAsyncTaskCompleted(true, mapIds, mapDatas);
|
||||
assertEquals(10, chooseMapActivityMock.arrayAdapter.getCount());
|
||||
assertEquals(MAP_ID + "9", chooseMapActivityMock.arrayAdapter.getItem(9).getMapId());
|
||||
assertEquals(MAP_TITLE + "9", chooseMapActivityMock.arrayAdapter.getItem(9).getMapData()
|
||||
.getTitle());
|
||||
assertEquals(MAP_DESC + "9", chooseMapActivityMock.arrayAdapter.getItem(9).getMapData()
|
||||
.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates map data for the test.
|
||||
*
|
||||
* @param number of data should be simulated.
|
||||
*/
|
||||
private void simulateMaps(int number) {
|
||||
mapIds = new ArrayList<String>();
|
||||
mapDatas = new ArrayList<MapsMapMetadata>();
|
||||
for (int i = 0; i < number; i++) {
|
||||
mapIds.add(MAP_ID + i);
|
||||
MapsMapMetadata metaData = new MapsMapMetadata();
|
||||
metaData.setTitle(MAP_TITLE + i);
|
||||
metaData.setDescription(MAP_DESC + i);
|
||||
metaData.setSearchable(true);
|
||||
mapDatas.add(metaData);
|
||||
}
|
||||
}
|
||||
}
|
||||
-199
@@ -1,199 +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.maps;
|
||||
|
||||
import com.google.android.testing.mocking.AndroidMock;
|
||||
import com.google.android.testing.mocking.UsesMocks;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Tests {@link ChooseMapAsyncTask}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class ChooseMapAsyncTaskTest extends AndroidTestCase {
|
||||
|
||||
private ChooseMapActivity chooseMapActivityMock;
|
||||
private Account account;
|
||||
private static final String ACCOUNT_NAME = "AccountName";
|
||||
private static final String ACCOUNT_TYPE = "AccountType";
|
||||
private boolean getMapsStatus = false;
|
||||
|
||||
public class ChooseMapAsyncTaskMock extends ChooseMapAsyncTask {
|
||||
|
||||
public ChooseMapAsyncTaskMock(ChooseMapActivity activity, Account account) {
|
||||
super(activity, account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates this method to override {@link ChooseMapAsyncTask#getMaps()}.
|
||||
*
|
||||
* @return mock the return value of getMaps().
|
||||
*/
|
||||
@Override
|
||||
boolean getMaps() {
|
||||
return getMapsStatus;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link ChooseMapAsyncTask#setActivity(ChooseMapActivity)} when the
|
||||
* task is completed. Makes sure it calls
|
||||
* {@link ChooseMapActivity#onAsyncTaskCompleted(boolean, ArrayList, ArrayList)}
|
||||
* .
|
||||
*/
|
||||
public void testSetActivity_completed() {
|
||||
setup();
|
||||
chooseMapActivityMock.onAsyncTaskCompleted(false, null, null);
|
||||
AndroidMock.replay(chooseMapActivityMock);
|
||||
ChooseMapAsyncTask chooseMapAsyncTask = new ChooseMapAsyncTask(chooseMapActivityMock, account);
|
||||
chooseMapAsyncTask.setCompleted(true);
|
||||
chooseMapAsyncTask.setActivity(chooseMapActivityMock);
|
||||
AndroidMock.verify(chooseMapActivityMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@link ChooseMapAsyncTask#setActivity(ChooseMapActivity)} when the
|
||||
* task is not completed. Makes sure
|
||||
* {@link ChooseMapActivity#onAsyncTaskCompleted(boolean, ArrayList, ArrayList)}
|
||||
* is not invoked.
|
||||
*/
|
||||
public void testSetActivity_notCompleted() {
|
||||
setup();
|
||||
AndroidMock.replay(chooseMapActivityMock);
|
||||
ChooseMapAsyncTask chooseMapAsyncTask = new ChooseMapAsyncTask(chooseMapActivityMock, account);
|
||||
chooseMapAsyncTask.setCompleted(false);
|
||||
chooseMapAsyncTask.setActivity(chooseMapActivityMock);
|
||||
AndroidMock.verify(chooseMapActivityMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link ChooseMapAsyncTask#setActivity(ChooseMapActivity)} when the
|
||||
* activity is null. Makes sure
|
||||
* {@link ChooseMapActivity#onAsyncTaskCompleted(boolean, ArrayList, ArrayList)}
|
||||
* is not invoked.
|
||||
*/
|
||||
public void testSetActivity_nullActivity() {
|
||||
setup();
|
||||
AndroidMock.replay(chooseMapActivityMock);
|
||||
ChooseMapAsyncTask chooseMapAsyncTask = new ChooseMapAsyncTask(chooseMapActivityMock, account);
|
||||
chooseMapAsyncTask.setCompleted(true);
|
||||
chooseMapAsyncTask.setActivity(null);
|
||||
AndroidMock.verify(chooseMapActivityMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link ChooseMapAsyncTask#onPostExecute(Boolean)} when the
|
||||
* result is true. Makes sure
|
||||
* {@link ChooseMapActivity#onAsyncTaskCompleted(boolean, ArrayList, ArrayList)}
|
||||
* is invoked.
|
||||
*/
|
||||
public void testOnPostExecute_trueResult() {
|
||||
setup();
|
||||
chooseMapActivityMock.onAsyncTaskCompleted(true, null, null);
|
||||
AndroidMock.replay(chooseMapActivityMock);
|
||||
ChooseMapAsyncTask chooseMapAsyncTask = new ChooseMapAsyncTask(chooseMapActivityMock, account);
|
||||
chooseMapAsyncTask.onPostExecute(true);
|
||||
AndroidMock.verify(chooseMapActivityMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link ChooseMapAsyncTask#onPostExecute(Boolean)} when the
|
||||
* result is false. Makes sure
|
||||
* {@link ChooseMapActivity#onAsyncTaskCompleted(boolean, ArrayList, ArrayList)}
|
||||
* is invoked.
|
||||
*/
|
||||
public void testOnPostExecute_falseResult() {
|
||||
setup();
|
||||
chooseMapActivityMock.onAsyncTaskCompleted(false, null, null);
|
||||
AndroidMock.replay(chooseMapActivityMock);
|
||||
ChooseMapAsyncTask chooseMapAsyncTask = new ChooseMapAsyncTask(chooseMapActivityMock, account);
|
||||
chooseMapAsyncTask.onPostExecute(false);
|
||||
AndroidMock.verify(chooseMapActivityMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link ChooseMapAsyncTask#retryUpload()}. Make sure can
|
||||
* not retry again after have retried once and failed.
|
||||
*/
|
||||
public void testRetryUpload() throws Exception {
|
||||
setup();
|
||||
AndroidMock.replay(chooseMapActivityMock);
|
||||
ChooseMapAsyncTaskMock chooseMapAsyncTaskTMock = new ChooseMapAsyncTaskMock(
|
||||
chooseMapActivityMock, account);
|
||||
chooseMapAsyncTaskTMock.setCanRetry(false);
|
||||
getMapsStatus = true;
|
||||
assertFalse(chooseMapAsyncTaskTMock.retryUpload());
|
||||
AndroidMock.verify(chooseMapActivityMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link ChooseMapAsyncTask#retryUpload()}. Make sure can
|
||||
* retry after get maps failed and never retry before.
|
||||
*/
|
||||
public void testRetryUpload_retryOnce() throws Exception {
|
||||
setup();
|
||||
AndroidMock.replay(chooseMapActivityMock);
|
||||
ChooseMapAsyncTaskMock chooseMapAsyncTaskTMock = new ChooseMapAsyncTaskMock(
|
||||
chooseMapActivityMock, account);
|
||||
chooseMapAsyncTaskTMock.setCanRetry(true);
|
||||
getMapsStatus = false;
|
||||
assertFalse(chooseMapAsyncTaskTMock.retryUpload());
|
||||
// Can only retry once.
|
||||
assertFalse(chooseMapAsyncTaskTMock.getCanRetry());
|
||||
AndroidMock.verify(chooseMapActivityMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link ChooseMapAsyncTask#retryUpload()}. Make sure will
|
||||
* not retry after get maps successfully.
|
||||
*/
|
||||
public void testRetryUpload_successGetMaps() throws Exception {
|
||||
setup();
|
||||
AndroidMock.replay(chooseMapActivityMock);
|
||||
ChooseMapAsyncTaskMock chooseMapAsyncTaskTMock = new ChooseMapAsyncTaskMock(
|
||||
chooseMapActivityMock, account);
|
||||
chooseMapAsyncTaskTMock.setCanRetry(true);
|
||||
getMapsStatus = true;
|
||||
assertTrue(chooseMapAsyncTaskTMock.retryUpload());
|
||||
// Can only retry once.
|
||||
assertFalse(chooseMapAsyncTaskTMock.getCanRetry());
|
||||
AndroidMock.verify(chooseMapActivityMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initials setup for test.
|
||||
*/
|
||||
void setup() {
|
||||
setupChooseMapActivityMock();
|
||||
account = new Account(ACCOUNT_NAME, ACCOUNT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a mock object of ChooseMapActivity.
|
||||
*/
|
||||
@UsesMocks(ChooseMapActivity.class)
|
||||
private void setupChooseMapActivityMock() {
|
||||
chooseMapActivityMock = AndroidMock.createMock(ChooseMapActivity.class);
|
||||
// This is used in the constructor of ChooseMapAsyncTask.
|
||||
AndroidMock.expect(chooseMapActivityMock.getApplicationContext()).andReturn(getContext()).anyTimes();
|
||||
}
|
||||
|
||||
}
|
||||
+12
-29
@@ -42,7 +42,6 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||
public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
||||
|
||||
private static final long TRACK_ID = 1;
|
||||
private static final String MAP_ID = "MapID_1";
|
||||
// Records the run times of {@link SendMapsAsyncTaskMock#uploadMarker(String,
|
||||
// String, String, Location)}
|
||||
private int uploadMarkerCounter = 0;
|
||||
@@ -61,8 +60,8 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
||||
private boolean prepareAndUploadPointsResult = false;
|
||||
|
||||
private SendMapsAsyncTaskMock(SendMapsActivity activity, long trackId, Account account,
|
||||
String chooseMapId, MyTracksProviderUtils myTracksProviderUtils) {
|
||||
super(activity, trackId, account, chooseMapId, myTracksProviderUtils);
|
||||
MyTracksProviderUtils myTracksProviderUtils) {
|
||||
super(activity, trackId, account, myTracksProviderUtils);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,10 +101,8 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
||||
|
||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock);
|
||||
SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock,
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), sendRequest.getMapsExistingMapId(),
|
||||
myTracksProviderUtilsMock);
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), myTracksProviderUtilsMock);
|
||||
sendMapsAsyncTask.saveResult();
|
||||
assertEquals(sendRequest.getMapsExistingMapId(), track.getMapId());
|
||||
AndroidMock.verify(sendMapsActivityMock, myTracksProviderUtilsMock);
|
||||
}
|
||||
|
||||
@@ -118,26 +115,12 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock);
|
||||
// Makes chooseMapId to null.
|
||||
SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock,
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), null, myTracksProviderUtilsMock);
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), myTracksProviderUtilsMock);
|
||||
// Returns false for an exception would be thrown.
|
||||
assertFalse(sendMapsAsyncTask.fetchSendMapId(track));
|
||||
AndroidMock.verify(sendMapsActivityMock, myTracksProviderUtilsMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendMapsAsyncTask#fetchSendMapId(Track)} when
|
||||
* chooseMapId is not null. And makes sure it returns false.
|
||||
*/
|
||||
public void testFetchSendMapId_notNullMapID() {
|
||||
Track track = TrackStubUtils.createTrack(1);
|
||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock);
|
||||
SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock,
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), MAP_ID, myTracksProviderUtilsMock);
|
||||
assertTrue(sendMapsAsyncTask.fetchSendMapId(track));
|
||||
assertEquals(MAP_ID, sendMapsAsyncTask.getMapId());
|
||||
AndroidMock.verify(sendMapsActivityMock, myTracksProviderUtilsMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendMapsAsyncTask#uploadAllTrackPoints(Track)} when
|
||||
* cursor is null. And makes sure it returns false.
|
||||
@@ -148,7 +131,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
||||
.andReturn(null);
|
||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock);
|
||||
SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock,
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), MAP_ID, myTracksProviderUtilsMock);
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), myTracksProviderUtilsMock);
|
||||
assertFalse(sendMapsAsyncTask.uploadAllTrackPoints(track));
|
||||
AndroidMock.verify(sendMapsActivityMock, myTracksProviderUtilsMock);
|
||||
}
|
||||
@@ -171,7 +154,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
||||
|
||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
||||
SendMapsAsyncTaskMock sendMapsAsyncTask = new SendMapsAsyncTaskMock(sendMapsActivityMock,
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), MAP_ID, myTracksProviderUtilsMock);
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), myTracksProviderUtilsMock);
|
||||
sendMapsAsyncTask.uploadMarkerResult[0] = false;
|
||||
assertFalse(sendMapsAsyncTask.uploadAllTrackPoints(track));
|
||||
assertEquals(1, uploadMarkerCounter);
|
||||
@@ -198,7 +181,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
||||
|
||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
||||
SendMapsAsyncTaskMock sendMapsAsyncTask = new SendMapsAsyncTaskMock(sendMapsActivityMock,
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), MAP_ID, myTracksProviderUtilsMock);
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), myTracksProviderUtilsMock);
|
||||
// For will be failed when run prepareAndUploadPoints, it no require to
|
||||
// set uploadMarkerResult[1].
|
||||
sendMapsAsyncTask.uploadMarkerResult[0] = true;
|
||||
@@ -228,7 +211,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
||||
|
||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
||||
SendMapsAsyncTaskMock sendMapsAsyncTask = new SendMapsAsyncTaskMock(sendMapsActivityMock,
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), MAP_ID, myTracksProviderUtilsMock);
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), myTracksProviderUtilsMock);
|
||||
sendMapsAsyncTask.uploadMarkerResult[0] = true;
|
||||
sendMapsAsyncTask.uploadMarkerResult[1] = false;
|
||||
sendMapsAsyncTask.prepareAndUploadPointsResult = true;
|
||||
@@ -257,7 +240,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
||||
|
||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
||||
SendMapsAsyncTaskMock sendMapsAsyncTask = new SendMapsAsyncTaskMock(sendMapsActivityMock,
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), MAP_ID, myTracksProviderUtilsMock);
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), myTracksProviderUtilsMock);
|
||||
sendMapsAsyncTask.uploadMarkerResult[0] = true;
|
||||
sendMapsAsyncTask.uploadMarkerResult[1] = true;
|
||||
sendMapsAsyncTask.prepareAndUploadPointsResult = true;
|
||||
@@ -278,7 +261,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
||||
Constants.MAX_LOADED_WAYPOINTS_POINTS)).andReturn(null);
|
||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock);
|
||||
SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock,
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), MAP_ID, myTracksProviderUtilsMock);
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), myTracksProviderUtilsMock);
|
||||
assertTrue(sendMapsAsyncTask.uploadWaypoints());
|
||||
AndroidMock.verify(sendMapsActivityMock, myTracksProviderUtilsMock);
|
||||
}
|
||||
@@ -301,7 +284,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
||||
|
||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
||||
SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock,
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), MAP_ID, myTracksProviderUtilsMock);
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), myTracksProviderUtilsMock);
|
||||
|
||||
assertTrue(sendMapsAsyncTask.uploadWaypoints());
|
||||
AndroidMock.verify(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
||||
@@ -332,7 +315,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
||||
|
||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
||||
SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock,
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), MAP_ID, myTracksProviderUtilsMock);
|
||||
sendRequest.getTrackId(), sendRequest.getAccount(), myTracksProviderUtilsMock);
|
||||
sendMapsAsyncTask.setMapsGDataConverter(mapsGDataConverterMock);
|
||||
// Would be failed for there is no source for uploading.
|
||||
assertFalse(sendMapsAsyncTask.uploadWaypoints());
|
||||
|
||||
-41
@@ -33,7 +33,6 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
private static final String MAPS_SHARE_CLASS_NAME = "class";
|
||||
private final static String ACCOUNTNAME = "testAccount1";
|
||||
private final static String ACCOUNTYPE = "testType1";
|
||||
private final static String MAPS_EXISTING_MAP_ID = "mapId1";
|
||||
private final static String DRIVE_SHARE_EMAILS = "foo@foo.com";
|
||||
|
||||
@Override
|
||||
@@ -73,17 +72,6 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
assertEquals(true, sendRequest.isSendSpreadsheets());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isMapsExistingMap()}. The value should
|
||||
* be set to false which is its default value when it is initialed in setup
|
||||
* method.
|
||||
*/
|
||||
public void testIsNewMap() {
|
||||
assertEquals(false, sendRequest.isMapsExistingMap());
|
||||
sendRequest.setMapsExistingMap(true);
|
||||
assertEquals(true, sendRequest.isMapsExistingMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#getAccount()}. The value should be set
|
||||
* to null which is its default value when it is initialed in setup method.
|
||||
@@ -95,17 +83,6 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
assertEquals(account, sendRequest.getAccount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#getMapsExistingMapId()}. The value
|
||||
* should be set to null which is its default value when it is initialed in
|
||||
* setup method.
|
||||
*/
|
||||
public void testGetMapsExistingMapId() {
|
||||
assertEquals(null, sendRequest.getMapsExistingMapId());
|
||||
sendRequest.setMapsExistingMapId("1");
|
||||
assertEquals("1", "1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isMapsSuccess()}. The value should be
|
||||
* set to false which is its default value when it is initialed in setup
|
||||
@@ -156,8 +133,6 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeString("");
|
||||
parcel.writeString("");
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeString(MAPS_EXISTING_MAP_ID);
|
||||
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
||||
parcel.writeParcelable(account, 0);
|
||||
parcel.writeByte((byte) 1);
|
||||
@@ -177,8 +152,6 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
assertTrue(sendRequest.isMapsShare());
|
||||
assertEquals("", sendRequest.getMapsSharePackageName());
|
||||
assertEquals("", sendRequest.getMapsShareClassName());
|
||||
assertTrue(sendRequest.isMapsExistingMap());
|
||||
assertEquals(MAPS_EXISTING_MAP_ID, sendRequest.getMapsExistingMapId());
|
||||
assertEquals(account, sendRequest.getAccount());
|
||||
assertTrue(sendRequest.isDriveSuccess());
|
||||
assertTrue(sendRequest.isMapsSuccess());
|
||||
@@ -203,8 +176,6 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeString(null);
|
||||
parcel.writeString(null);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeString(MAPS_EXISTING_MAP_ID);
|
||||
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
||||
parcel.writeParcelable(account, 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
@@ -224,8 +195,6 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
assertFalse(sendRequest.isMapsShare());
|
||||
assertNull(sendRequest.getMapsSharePackageName());
|
||||
assertNull(sendRequest.getMapsShareClassName());
|
||||
assertFalse(sendRequest.isMapsExistingMap());
|
||||
assertEquals(MAPS_EXISTING_MAP_ID, sendRequest.getMapsExistingMapId());
|
||||
assertEquals(account, sendRequest.getAccount());
|
||||
assertFalse(sendRequest.isDriveSuccess());
|
||||
assertFalse(sendRequest.isMapsSuccess());
|
||||
@@ -253,8 +222,6 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
boolean mapsShare = parcel.readByte() == 1;
|
||||
String mapsSharePackageName = parcel.readString();
|
||||
String mapsShareClassName = parcel.readString();
|
||||
boolean mapsExistingMap = parcel.readByte() == 1;
|
||||
String mapsExistingMapId = parcel.readString();
|
||||
Parcelable account = parcel.readParcelable(null);
|
||||
boolean driveSuccess = parcel.readByte() == 1;
|
||||
boolean mapsSuccess = parcel.readByte() == 1;
|
||||
@@ -271,8 +238,6 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
assertFalse(mapsShare);
|
||||
assertNull(mapsSharePackageName);
|
||||
assertNull(mapsShareClassName);
|
||||
assertFalse(mapsExistingMap);
|
||||
assertNull(mapsExistingMapId);
|
||||
assertNull(account);
|
||||
assertFalse(driveSuccess);
|
||||
assertFalse(mapsSuccess);
|
||||
@@ -295,8 +260,6 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
sendRequest.setMapsShare(true);
|
||||
sendRequest.setMapsSharePackageName(MAPS_SHARE_PACKAGE_NAME);
|
||||
sendRequest.setMapsShareClassName(MAPS_SHARE_CLASS_NAME);
|
||||
sendRequest.setMapsExistingMap(true);
|
||||
sendRequest.setMapsExistingMapId(MAPS_EXISTING_MAP_ID);
|
||||
Account accountNew = new Account(ACCOUNTNAME + "2", ACCOUNTYPE + "2");
|
||||
sendRequest.setAccount(accountNew);
|
||||
sendRequest.setMapsSuccess(true);
|
||||
@@ -318,8 +281,6 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
boolean mapsShare = parcel.readByte() == 1;
|
||||
String mapsSharePackageName = parcel.readString();
|
||||
String mapsShareClassName = parcel.readString();
|
||||
boolean mapsExistingMap = parcel.readByte() == 1;
|
||||
String mapsExistingMapId = parcel.readString();
|
||||
Parcelable account = parcel.readParcelable(null);
|
||||
boolean driveSuccess = parcel.readByte() == 1;
|
||||
boolean mapsSuccess = parcel.readByte() == 1;
|
||||
@@ -336,8 +297,6 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
assertTrue(mapsShare);
|
||||
assertEquals(MAPS_SHARE_PACKAGE_NAME, mapsSharePackageName);
|
||||
assertEquals(MAPS_SHARE_CLASS_NAME, mapsShareClassName);
|
||||
assertTrue(mapsExistingMap);
|
||||
assertEquals(MAPS_EXISTING_MAP_ID, mapsExistingMapId);
|
||||
assertEquals(accountNew, account);
|
||||
assertTrue(driveSuccess);
|
||||
assertTrue(mapsSuccess);
|
||||
|
||||
Reference in New Issue
Block a user