Reducing the number of strings by removing strings specific to

a Google service.
This commit is contained in:
Jimmy Shih
2011-11-11 17:33:05 -08:00
parent 52eb7bffb6
commit 89fb6f6bd8
18 changed files with 85 additions and 202 deletions
@@ -23,7 +23,7 @@ package com.google.android.apps.mytracks;
*/
public interface ProgressIndicator {
public void setProgressMessage(int resId);
public void setProgressMessage(String message);
public void clearProgressMessage();
public void setProgressValue(int percent);
@@ -93,7 +93,9 @@ public class SendToDocs {
private void doUpload(long trackId) {
// TODO
statusMessage = activity.getString(R.string.send_google_error_docs);
String errorFormat = activity.getString(R.string.send_google_error_service);
String serviceName = activity.getString(SendType.DOCS.getServiceName());
statusMessage = String.format(errorFormat, serviceName);
success = false;
try {
@@ -116,13 +118,11 @@ public class SendToDocs {
Log.d(Constants.TAG, "SendToDocs: Uploading to spreadsheet");
success = uploadToDocs(track);
if (success) {
String format = createdNewSpreadSheet
? activity.getString(R.string.send_google_success_new_doc)
: activity.getString(R.string.send_google_success_existing_doc);
String successFormat = createdNewSpreadSheet
? activity.getString(R.string.send_google_success_new)
: activity.getString(R.string.send_google_success_existing);
String url = activity.getString(SendType.DOCS.getServiceUrl());
statusMessage = String.format(format, url);
} else {
statusMessage = activity.getString(R.string.send_google_error_docs);
statusMessage = String.format(successFormat, serviceName, url);
}
Log.d(Constants.TAG, "SendToDocs: Done.");
} finally {
@@ -169,11 +169,14 @@ public class SendToFusionTables implements Runnable {
}
private void doUpload() {
String statusMessage = context.getString(R.string.send_google_error_fusion_tables);
String errorFormat = context.getString(R.string.send_google_error_service);
String serviceName = context.getString(SendType.FUSION_TABLES.getServiceName());
String statusMessage = String.format(errorFormat, serviceName);
boolean success = true;
try {
progressIndicator.setProgressValue(PROGRESS_INITIALIZATION);
progressIndicator.setProgressMessage(R.string.send_google_progress_reading_track);
progressIndicator.setProgressMessage(
context.getString(R.string.send_google_progress_reading_track));
// Get the track meta-data
Track track = providerUtils.getTrack(trackId);
@@ -186,13 +189,15 @@ public class SendToFusionTables implements Runnable {
// Create a new table:
progressIndicator.setProgressValue(PROGRESS_FUSION_TABLE_CREATE);
progressIndicator.setProgressMessage(R.string.send_google_progress_creating_fusion_table);
String creatingFormat = context.getString(R.string.send_google_progress_creating);
progressIndicator.setProgressMessage(String.format(creatingFormat, serviceName));
if (!createNewTable(track) || !makeTableUnlisted()) {
return;
}
progressIndicator.setProgressValue(PROGRESS_UPLOAD_DATA_MIN);
progressIndicator.setProgressMessage(R.string.send_google_progress_sending_fusion_tables);
String sendingFormat = context.getString(R.string.send_google_progress_sending);
progressIndicator.setProgressMessage(String.format(sendingFormat, serviceName));
// Upload all of the segments of the track plus start/end markers
if (!uploadAllTrackPoints(track, originalDescription)) {
@@ -206,9 +211,9 @@ public class SendToFusionTables implements Runnable {
return;
}
String format = context.getString(R.string.send_google_success_fusion_tables);
String successFormat = context.getString(R.string.send_google_success_new);
String url = context.getString(SendType.FUSION_TABLES.getServiceUrl());
statusMessage = String.format(format, url);
statusMessage = String.format(successFormat, serviceName, url);
Log.d(Constants.TAG, "SendToFusionTables: Done: " + success);
progressIndicator.setProgressValue(PROGRESS_COMPLETE);
} finally {
@@ -99,10 +99,13 @@ public class SendToMyMaps implements Runnable {
}
private void doUpload() {
String statusMessage = context.getString(R.string.send_google_error_my_maps);
String errorFormat = context.getString(R.string.send_google_error_service);
String serviceName = context.getString(SendType.MYMAPS.getServiceName());
String statusMessage = String.format(errorFormat, serviceName);
boolean success = true;
try {
progressIndicator.setProgressMessage(R.string.send_google_progress_reading_track);
progressIndicator.setProgressMessage(
context.getString(R.string.send_google_progress_reading_track));
// Get the track meta-data
Track track = providerUtils.getTrack(trackId);
@@ -128,7 +131,8 @@ public class SendToMyMaps implements Runnable {
context.getString(R.string.default_map_public_key), true);
}
progressIndicator.setProgressMessage(R.string.send_google_progress_creating_map);
String creatingFormat = context.getString(R.string.send_google_progress_creating);
progressIndicator.setProgressMessage(String.format(creatingFormat, serviceName));
StringBuilder mapIdBuilder = new StringBuilder();
success = mapsClient.createNewMap(
@@ -172,11 +176,10 @@ public class SendToMyMaps implements Runnable {
}
if (success) {
String format = isNewMap
? context.getString(R.string.send_google_success_new_map)
: context.getString(R.string.send_google_success_existing_map);
String successFormat = isNewMap ? context.getString(R.string.send_google_success_new)
: context.getString(R.string.send_google_success_existing);
String url = context.getString(SendType.MYMAPS.getServiceUrl());
statusMessage = String.format(format, url);
statusMessage = String.format(successFormat, serviceName, url);
}
Log.d(TAG, "SendToMyMaps: Done: " + success);
progressIndicator.setProgressValue(100);
@@ -236,7 +239,8 @@ public class SendToMyMaps implements Runnable {
new DoubleBuffer(Constants.ELEVATION_SMOOTHING_FACTOR);
List<Location> locations = new ArrayList<Location>(MAX_POINTS_PER_UPLOAD);
progressIndicator.setProgressMessage(R.string.send_google_progress_reading_track);
progressIndicator.setProgressMessage(
context.getString(R.string.send_google_progress_reading_track));
Location lastLocation = null;
do {
if (totalLocationsRead % 100 == 0) {
@@ -309,7 +313,8 @@ public class SendToMyMaps implements Runnable {
private boolean prepareAndUploadPoints(Track track, List<Location> locations) {
progressIndicator.setProgressMessage(R.string.send_google_progress_preparing_track);
progressIndicator.setProgressMessage(
context.getString(R.string.send_google_progress_preparing_track));
updateProgress();
int numLocations = locations.size();
@@ -323,7 +328,9 @@ public class SendToMyMaps implements Runnable {
ArrayList<Track> splitTracks = prepareLocations(track, locations);
// Start uploading them
progressIndicator.setProgressMessage(R.string.send_google_progress_sending_my_maps);
String sendingFormat = context.getString(R.string.send_google_progress_sending);
String serviceName = context.getString(SendType.MYMAPS.getServiceName());
progressIndicator.setProgressMessage(String.format(sendingFormat, serviceName));
for (Track splitTrack : splitTracks) {
if (totalSegmentsUploaded > 1) {
splitTrack.setName(splitTrack.getName() + " "
@@ -403,7 +403,7 @@ public class SendActivity extends Activity implements ProgressIndicator {
private SendState authenticateToGoogleMaps() {
Log.d(TAG, "SendActivity.authenticateToGoogleMaps");
progressDialog.setProgress(0);
progressDialog.setMessage(getString(R.string.send_google_progress_auth_my_maps));
progressDialog.setMessage(getAuthenticatingProgressMessage(SendType.MYMAPS));
authenticate(Constants.AUTHENTICATE_TO_MY_MAPS, MyMapsConstants.SERVICE_NAME);
// AUTHENTICATE_TO_MY_MAPS callback calls sendToGoogleMaps
return SendState.NOT_READY;
@@ -478,7 +478,7 @@ public class SendActivity extends Activity implements ProgressIndicator {
private SendState authenticateToFusionTables() {
progressDialog.setProgress(0);
progressDialog.setMessage(getString(R.string.send_google_progress_auth_fusion_tables));
progressDialog.setMessage(getAuthenticatingProgressMessage(SendType.FUSION_TABLES));
authenticate(Constants.AUTHENTICATE_TO_FUSION_TABLES, SendToFusionTables.SERVICE_ID);
// AUTHENTICATE_TO_FUSION_TABLES callback calls sendToFusionTables
return SendState.NOT_READY;
@@ -533,7 +533,7 @@ public class SendActivity extends Activity implements ProgressIndicator {
private SendState authenticateToGoogleDocs() {
setProgressValue(0);
setProgressMessage(R.string.send_google_progress_auth_docs);
setProgressMessage(getAuthenticatingProgressMessage(SendType.DOCS));
authenticate(Constants.AUTHENTICATE_TO_DOCLIST, SendToDocs.GDATA_SERVICE_NAME_DOCLIST);
// AUTHENTICATE_TO_DOCLIST callback calls authenticateToGoogleTrix
return SendState.NOT_READY;
@@ -541,7 +541,7 @@ public class SendActivity extends Activity implements ProgressIndicator {
private SendState authenticateToGoogleTrix() {
setProgressValue(30);
setProgressMessage(R.string.send_google_progress_auth_docs);
setProgressMessage(getAuthenticatingProgressMessage(SendType.DOCS));
authenticate(Constants.AUTHENTICATE_TO_TRIX, SendToDocs.GDATA_SERVICE_NAME_TRIX);
// AUTHENTICATE_TO_TRIX callback calls sendToGoogleDocs
return SendState.NOT_READY;
@@ -552,7 +552,9 @@ public class SendActivity extends Activity implements ProgressIndicator {
tracker.trackPageView("/send/docs");
setProgressValue(50);
setProgressMessage(R.string.send_google_progress_sending_docs);
String format = getString(R.string.send_google_progress_sending);
String serviceName = getString(SendType.DOCS.getServiceName());
setProgressMessage(String.format(format, serviceName));
final SendToDocs sender = new SendToDocs(this,
authMap.get(SendToDocs.GDATA_SERVICE_NAME_TRIX),
authMap.get(SendToDocs.GDATA_SERVICE_NAME_DOCLIST),
@@ -878,12 +880,24 @@ public class SendActivity extends Activity implements ProgressIndicator {
sendToFusionTablesTableId = null;
}
/**
* Gets a progress message indicating My Tracks is authenticating to a
* service.
*
* @param type the type of service
*/
private String getAuthenticatingProgressMessage(SendType type) {
String format = getString(R.string.send_google_progress_authenticating);
String serviceName = getString(type.getServiceName());
return String.format(format, serviceName);
}
@Override
public void setProgressMessage(final int resId) {
public void setProgressMessage(final String message) {
runOnUiThread(new Runnable() {
public void run() {
if (progressDialog != null) {
progressDialog.setMessage(getString(resId));
progressDialog.setMessage(message);
}
}
});