Removing many indirections I had introduced.

This commit is contained in:
Rodrigo Damazio
2011-03-16 12:58:41 -07:00
parent 55d4a90041
commit 802cf51cf9
9 changed files with 31 additions and 95 deletions
@@ -18,9 +18,9 @@ package com.google.android.apps.mytracks;
import com.google.android.accounts.Account; import com.google.android.accounts.Account;
import com.google.android.apps.mytracks.io.AuthManager; import com.google.android.apps.mytracks.io.AuthManager;
import com.google.android.apps.mytracks.io.AuthManagerFactory; import com.google.android.apps.mytracks.io.AuthManagerFactory;
import com.google.android.apps.mytracks.io.MyMapsFactory;
import com.google.android.apps.mytracks.io.mymaps.MapsFacade; import com.google.android.apps.mytracks.io.mymaps.MapsFacade;
import com.google.android.apps.mytracks.io.mymaps.MapsService; import com.google.android.apps.mytracks.io.mymaps.MapsFacadeImpl;
import com.google.android.apps.mytracks.io.mymaps.MyMapsConstants;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import android.app.Activity; import android.app.Activity;
@@ -84,7 +84,7 @@ public class MyMapsList extends Activity implements MapsFacade.MapsListCallback
super.onCreate(icicle); super.onCreate(icicle);
auth = AuthManagerFactory.getAuthManager(this, GET_LOGIN, null, true, auth = AuthManagerFactory.getAuthManager(this, GET_LOGIN, null, true,
MapsService.getServiceName()); MyMapsConstants.SERVICE_NAME);
setContentView(R.layout.list); setContentView(R.layout.list);
@@ -125,7 +125,7 @@ public class MyMapsList extends Activity implements MapsFacade.MapsListCallback
auth.doLogin(new Runnable() { auth.doLogin(new Runnable() {
public void run() { public void run() {
// Runs in UI thread. // Runs in UI thread.
mapsClient = MyMapsFactory.newMapsClient(MyMapsList.this, auth); mapsClient = new MapsFacadeImpl(MyMapsList.this, auth);
startLookup(); startLookup();
} }
@@ -200,7 +200,7 @@ public class MyMapsList extends Activity implements MapsFacade.MapsListCallback
shareIntent.putExtra(Intent.EXTRA_TEXT, String.format( shareIntent.putExtra(Intent.EXTRA_TEXT, String.format(
getText(R.string.share_map_body_format).toString(), getText(R.string.share_map_body_format).toString(),
listItem[1], listItem[1],
MapsService.buildMapUrl(listItem[0]))); MapsFacadeImpl.buildMapUrl(listItem[0])));
startActivity(Intent.createChooser(shareIntent, startActivity(Intent.createChooser(shareIntent,
getText(R.string.share_map).toString())); getText(R.string.share_map).toString()));
return true; return true;
@@ -35,7 +35,8 @@ import com.google.android.apps.mytracks.io.TempFileCleaner;
import com.google.android.apps.mytracks.io.TrackWriter; import com.google.android.apps.mytracks.io.TrackWriter;
import com.google.android.apps.mytracks.io.TrackWriterFactory; import com.google.android.apps.mytracks.io.TrackWriterFactory;
import com.google.android.apps.mytracks.io.TrackWriterFactory.TrackFileFormat; import com.google.android.apps.mytracks.io.TrackWriterFactory.TrackFileFormat;
import com.google.android.apps.mytracks.io.mymaps.MapsService; import com.google.android.apps.mytracks.io.mymaps.MapsFacadeImpl;
import com.google.android.apps.mytracks.io.mymaps.MyMapsConstants;
import com.google.android.apps.mytracks.io.sendtogoogle.ResultDialogFactory; import com.google.android.apps.mytracks.io.sendtogoogle.ResultDialogFactory;
import com.google.android.apps.mytracks.io.sendtogoogle.SendDialog; import com.google.android.apps.mytracks.io.sendtogoogle.SendDialog;
import com.google.android.apps.mytracks.io.sendtogoogle.SendResult; import com.google.android.apps.mytracks.io.sendtogoogle.SendResult;
@@ -606,7 +607,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
Track selectedTrack = providerUtils.getTrack(selectedTrackId); Track selectedTrack = providerUtils.getTrack(selectedTrackId);
if (selectedTrack != null) { if (selectedTrack != null) {
if (!TextUtils.isEmpty(selectedTrack.getMapId())) { if (!TextUtils.isEmpty(selectedTrack.getMapId())) {
shareLinkToMap(MapsService.buildMapUrl(selectedTrack.getMapId())); shareLinkToMap(MapsFacadeImpl.buildMapUrl(selectedTrack.getMapId()));
} else if (!TextUtils.isEmpty(selectedTrack.getTableId())) { } else if (!TextUtils.isEmpty(selectedTrack.getTableId())) {
shareLinkToMap(getFusionTablesUrl(selectedTrackId)); shareLinkToMap(getFusionTablesUrl(selectedTrackId));
} else { } else {
@@ -1028,7 +1029,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
setProgressMessage( setProgressMessage(
R.string.progress_message_authenticating_mymaps); R.string.progress_message_authenticating_mymaps);
authenticate(results, MyTracksConstants.AUTHENTICATE_TO_MY_MAPS, authenticate(results, MyTracksConstants.AUTHENTICATE_TO_MY_MAPS,
MapsService.getServiceName()); MyMapsConstants.SERVICE_NAME);
// AUTHENTICATE_TO_MY_MAPS callback calls sendToGoogleMaps // AUTHENTICATE_TO_MY_MAPS callback calls sendToGoogleMaps
} }
@@ -1225,7 +1226,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
String url = null; String url = null;
if (sentToMyMaps && sendToMyMapsSuccess) { if (sentToMyMaps && sendToMyMapsSuccess) {
// Prefer a link to My Maps // Prefer a link to My Maps
url = MapsService.buildMapUrl(sendToMyMapsMapId); url = MapsFacadeImpl.buildMapUrl(sendToMyMapsMapId);
} else if (sentToFusionTables && sendToFusionTablesSuccess) { } else if (sentToFusionTables && sendToFusionTablesSuccess) {
// Otherwise try using the link to fusion tables // Otherwise try using the link to fusion tables
url = getFusionTablesUrl(sendToTrackId); url = getFusionTablesUrl(sendToTrackId);
@@ -1,31 +0,0 @@
package com.google.android.apps.mytracks.io;
import com.google.android.apps.mytracks.io.gdata.GDataClientFactory;
import com.google.android.apps.mytracks.io.mymaps.MapsFacade;
import com.google.android.apps.mytracks.io.mymaps.MapsService;
import android.app.Activity;
/**
* Factory to easily instantiate a {@link MapsFacade}.
*
* @author Rodrigo Damazio
*/
public class MyMapsFactory {
/**
* Creates a new Maps fa�ade interface instance.
*
* @param context current context
* @param auth a valid authentication manager
* @return the fa�ade
*/
public static MapsFacade newMapsClient(Activity context, final AuthManager auth) {
MapsFacade client = MapsService.newClient(context,
GDataClientFactory.getGDataClient(context),
auth);
return client;
}
private MyMapsFactory() {}
}
@@ -23,6 +23,7 @@ import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.io.mymaps.MapsFacade; import com.google.android.apps.mytracks.io.mymaps.MapsFacade;
import com.google.android.apps.mytracks.io.mymaps.MapsFacade.WaypointData; import com.google.android.apps.mytracks.io.mymaps.MapsFacade.WaypointData;
import com.google.android.apps.mytracks.io.mymaps.MapsFacadeImpl;
import com.google.android.apps.mytracks.stats.DoubleBuffer; import com.google.android.apps.mytracks.stats.DoubleBuffer;
import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.stats.TripStatistics;
import com.google.android.apps.mytracks.util.MyTracksUtils; import com.google.android.apps.mytracks.util.MyTracksUtils;
@@ -111,7 +112,7 @@ public class SendToMyMaps implements Runnable {
track.setDescription("<p>" + track.getDescription() + "</p><p>" track.setDescription("<p>" + track.getDescription() + "</p><p>"
+ stringUtils.generateTrackDescription(track, null, null) + "</p>"); + stringUtils.generateTrackDescription(track, null, null) + "</p>");
mapsClient = MyMapsFactory.newMapsClient(context, auth); mapsClient = new MapsFacadeImpl(context, auth);
// Create a new map if necessary: // Create a new map if necessary:
boolean isNewMap = mapId.equals(NEW_MAP_ID); boolean isNewMap = mapId.equals(NEW_MAP_ID);
@@ -36,6 +36,10 @@ class MapsClient extends GDataServiceClient {
return MyMapsConstants.SERVICE_NAME; return MyMapsConstants.SERVICE_NAME;
} }
public static String buildMapUrl(String mapId) {
return MyMapsConstants.MAPSHOP_BASE_URL + "?msa=0&msid=" + mapId;
}
public static String getMapsFeed() { public static String getMapsFeed() {
if (DEBUG) { if (DEBUG) {
Log.d("Maps Client", "Requesting map feed:"); Log.d("Maps Client", "Requesting map feed:");
@@ -4,7 +4,6 @@ package com.google.android.apps.mytracks.io.mymaps;
import com.google.android.apps.mytracks.io.AuthManager; import com.google.android.apps.mytracks.io.AuthManager;
import com.google.android.maps.GeoPoint; import com.google.android.maps.GeoPoint;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import com.google.wireless.gdata.client.GDataClient;
import com.google.wireless.gdata.client.HttpException; import com.google.wireless.gdata.client.HttpException;
import com.google.wireless.gdata.data.Entry; import com.google.wireless.gdata.data.Entry;
import com.google.wireless.gdata.parser.GDataParser; import com.google.wireless.gdata.parser.GDataParser;
@@ -15,17 +14,17 @@ import android.location.Location;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Implementation of the Maps access abstraction. * Implementation of the Maps access abstraction.
* *
* @author Rodrigo Damazio * @author Rodrigo Damazio
*/ */
class MapsFacadeImpl implements MapsFacade { public class MapsFacadeImpl implements MapsFacade {
private static final String END_ICON_URL = private static final String END_ICON_URL =
"http://maps.google.com/mapfiles/ms/micons/red-dot.png"; "http://maps.google.com/mapfiles/ms/micons/red-dot.png";
private static final String START_ICON_URL = private static final String START_ICON_URL =
@@ -36,12 +35,11 @@ class MapsFacadeImpl implements MapsFacade {
private final MyMapsGDataConverter gdataConverter; private final MyMapsGDataConverter gdataConverter;
private final String authToken; private final String authToken;
public MapsFacadeImpl(Context context, GDataClient gdataClient, public MapsFacadeImpl(Context context, AuthManager auth) {
AuthManager auth) {
this.context = context; this.context = context;
this.authToken = auth.getAuthToken(); this.authToken = auth.getAuthToken();
wrapper = new MyMapsGDataWrapper(context, gdataClient, auth); wrapper = new MyMapsGDataWrapper(context, auth);
wrapper.setRetryOnAuthFailure(true); wrapper.setRetryOnAuthFailure(true);
try { try {
@@ -51,6 +49,10 @@ class MapsFacadeImpl implements MapsFacade {
} }
} }
public static String buildMapUrl(String mapId) {
return MapsClient.buildMapUrl(mapId);
}
@Override @Override
public boolean getMapsList(final MapsListCallback callback) { public boolean getMapsList(final MapsListCallback callback) {
return wrapper.runQuery(new MyMapsGDataWrapper.QueryFunction() { return wrapper.runQuery(new MyMapsGDataWrapper.QueryFunction() {
@@ -1,42 +0,0 @@
// Copyright 2011 Google Inc. All Rights Reserved.
package com.google.android.apps.mytracks.io.mymaps;
import com.google.android.apps.mytracks.io.AuthManager;
import com.google.wireless.gdata.client.GDataClient;
import android.app.Activity;
/**
* Entry point for the maps service library.
*
* @author Rodrigo Damazio
*/
public class MapsService {
private MapsService() {}
/**
* Creates a new fa�ade to access Google Maps.
*
* @param context current context
* @param gDataClient GData client to use for access
* @param stringProvider interface to provide i18n'ed resources
* @param authToken the authentication token to access the service with
* @return the service fa�ade
*/
public static MapsFacade newClient(
Activity context,
GDataClient gDataClient,
AuthManager auth) {
return new MapsFacadeImpl(context, gDataClient, auth);
}
/** Returns the service name to authenticate to for providing the authentication token above. */
public static String getServiceName() {
return MyMapsConstants.SERVICE_NAME;
}
/** Builds and returns the user-visible URL for a map given its map ID. */
public static String buildMapUrl(String mapId) {
return MyMapsConstants.MAPSHOP_BASE_URL + "?msa=0&msid=" + mapId;
}
}
@@ -4,9 +4,9 @@ package com.google.android.apps.mytracks.io.mymaps;
/** /**
* Constants for My Maps. * Constants for My Maps.
*/ */
class MyMapsConstants { public class MyMapsConstants {
public static final String TAG = "MapsApi"; static final String TAG = "MapsApi";
public static final String MAPSHOP_BASE_URL = static final String MAPSHOP_BASE_URL =
"http://maps.google.com/maps/ms"; "http://maps.google.com/maps/ms";
public static final String SERVICE_NAME = "local"; public static final String SERVICE_NAME = "local";
@@ -2,6 +2,7 @@
package com.google.android.apps.mytracks.io.mymaps; package com.google.android.apps.mytracks.io.mymaps;
import com.google.android.apps.mytracks.io.AuthManager; import com.google.android.apps.mytracks.io.AuthManager;
import com.google.android.apps.mytracks.io.gdata.GDataClientFactory;
import com.google.android.common.gdata.AndroidXmlParserFactory; import com.google.android.common.gdata.AndroidXmlParserFactory;
import com.google.wireless.gdata.client.GDataClient; import com.google.wireless.gdata.client.GDataClient;
import com.google.wireless.gdata.client.HttpException; import com.google.wireless.gdata.client.HttpException;
@@ -65,8 +66,8 @@ class MyMapsGDataWrapper {
private int retriesPending; private int retriesPending;
private boolean cleanupCalled; private boolean cleanupCalled;
public MyMapsGDataWrapper(Context context, GDataClient gdataClient, AuthManager auth) { public MyMapsGDataWrapper(Context context, AuthManager auth) {
androidGdataClient = gdataClient; androidGdataClient = GDataClientFactory.getGDataClient(context);
this.auth = auth; this.auth = auth;
client = client =
new MapsClient(androidGdataClient, new XmlMapsGDataParserFactory( new MapsClient(androidGdataClient, new XmlMapsGDataParserFactory(