forked from upstream-mirrors/OpenTracks
Clean up Send to Google code.
Remove SendActivity and SendType. Pass SendRequest from one activity to the next.
This commit is contained in:
@@ -235,14 +235,6 @@ limitations under the License.
|
||||
android:value="com.google.android.apps.mytracks.SearchActivity" />
|
||||
</activity>
|
||||
|
||||
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.SendActivity"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<data android:mimeType="vnd.android.cursor.item/vnd.google.track" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name="com.google.android.apps.mytracks.io.file.SaveActivity"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||
android:noHistory="true">
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.google.android.apps.mytracks.content.TrackDataHub;
|
||||
import com.google.android.apps.mytracks.content.TrackDataHub.ListenerDataType;
|
||||
import com.google.android.apps.mytracks.content.TrackDataListener;
|
||||
import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.services.tasks.StatusAnnouncerTask;
|
||||
import com.google.android.apps.mytracks.stats.DoubleBuffer;
|
||||
import com.google.android.apps.mytracks.stats.TripStatisticsBuilder;
|
||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||
|
||||
@@ -35,10 +35,6 @@ public abstract class Constants {
|
||||
|
||||
/*
|
||||
* onActivityResult request codes:
|
||||
*
|
||||
* TODO: These should be moved to the
|
||||
* activities that call startActivityForResult. Thus do not need to keep a
|
||||
* global order across all activities.
|
||||
*/
|
||||
public static final int SHOW_TRACK = 0;
|
||||
public static final int SHARE_GPX_FILE = 1;
|
||||
@@ -51,11 +47,6 @@ public abstract class Constants {
|
||||
public static final int SAVE_TCX_FILE = 8;
|
||||
public static final int SHOW_WAYPOINT = 9;
|
||||
public static final int WELCOME = 10;
|
||||
public static final int CHOOSE_ACCOUNT = 11;
|
||||
public static final int CHOOSE_MAP = 12;
|
||||
public static final int SEND_MAPS = 13;
|
||||
public static final int SEND_FUSION_TABLES = 14;
|
||||
public static final int SEND_DOCS = 15;
|
||||
|
||||
/*
|
||||
* Menu ids:
|
||||
|
||||
@@ -25,9 +25,8 @@ import com.google.android.apps.mytracks.content.TrackDataListener;
|
||||
import com.google.android.apps.mytracks.content.TracksColumns;
|
||||
import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.io.file.SaveActivity;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendType;
|
||||
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.tasks.StatusAnnouncerTask;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.GeoRect;
|
||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||
@@ -41,7 +40,6 @@ import android.content.Intent;
|
||||
import android.location.Location;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.provider.Settings;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
import android.util.Log;
|
||||
@@ -467,21 +465,18 @@ public class MapActivity extends com.google.android.maps.MapActivity
|
||||
long trackId = dataHub.getSelectedTrackId();
|
||||
switch (item.getItemId()) {
|
||||
case Constants.MENU_SEND_TO_GOOGLE:
|
||||
intent = new Intent(this, UploadServiceChooserActivity.class);
|
||||
intent.putExtra(UploadServiceChooserActivity.TRACK_ID, trackId);
|
||||
intent = new Intent(this, UploadServiceChooserActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId, true, true, true));
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case Constants.MENU_SHARE_MAP:
|
||||
intent = new Intent(this, UploadServiceChooserActivity.class);
|
||||
intent.putExtra(UploadServiceChooserActivity.TRACK_ID, trackId);
|
||||
intent.putExtra(UploadServiceChooserActivity.SEND_TYPE, (Parcelable) SendType.MAPS);
|
||||
intent = new Intent(this, UploadServiceChooserActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId, true, false, false));
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case Constants.MENU_SHARE_FUSION_TABLE:
|
||||
intent = new Intent(this, UploadServiceChooserActivity.class);
|
||||
intent.putExtra(UploadServiceChooserActivity.TRACK_ID, trackId);
|
||||
intent.putExtra(
|
||||
UploadServiceChooserActivity.SEND_TYPE, (Parcelable) SendType.FUSION_TABLES);
|
||||
intent = new Intent(this, UploadServiceChooserActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId, false, true, false));
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case Constants.MENU_SAVE_GPX_FILE:
|
||||
|
||||
@@ -28,7 +28,6 @@ import com.google.android.apps.mytracks.io.file.TempFileCleaner;
|
||||
import com.google.android.apps.mytracks.services.ITrackRecordingService;
|
||||
import com.google.android.apps.mytracks.services.ServiceUtils;
|
||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
||||
import com.google.android.apps.mytracks.services.tasks.StatusAnnouncerTask;
|
||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||
import com.google.android.apps.mytracks.util.EulaUtil;
|
||||
import com.google.android.apps.mytracks.util.SystemUtils;
|
||||
|
||||
@@ -168,9 +168,8 @@ public class SearchActivity extends ListActivity {
|
||||
/**
|
||||
* Shows the given search results.
|
||||
* Must be run from the UI thread.
|
||||
* @param data
|
||||
*
|
||||
* @param scoredResults the results to show, properly ordered
|
||||
* @param data the results to show, properly ordered
|
||||
*/
|
||||
private void showSearchResults(List<? extends Map<String, ?>> data) {
|
||||
SimpleAdapter adapter = new SimpleAdapter(this, data,
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.google.android.apps.mytracks.content.TrackDataHub.ListenerDataType;
|
||||
import com.google.android.apps.mytracks.content.TrackDataListener;
|
||||
import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.services.ServiceUtils;
|
||||
import com.google.android.apps.mytracks.services.tasks.StatusAnnouncerTask;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
@@ -19,7 +19,7 @@ import static com.google.android.apps.mytracks.Constants.TAG;
|
||||
|
||||
import com.google.android.apps.mytracks.content.TracksColumns;
|
||||
import com.google.android.apps.mytracks.io.file.SaveActivity;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendType;
|
||||
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.ServiceUtils;
|
||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
||||
@@ -36,7 +36,6 @@ import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Parcelable;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
@@ -175,21 +174,18 @@ public class TrackList extends ListActivity
|
||||
case Constants.MENU_WRITE_TO_SD_CARD:
|
||||
return false;
|
||||
case Constants.MENU_SEND_TO_GOOGLE:
|
||||
intent = new Intent(this, UploadServiceChooserActivity.class);
|
||||
intent.putExtra(UploadServiceChooserActivity.TRACK_ID, trackId);
|
||||
intent = new Intent(this, UploadServiceChooserActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId, true, true, true));
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case Constants.MENU_SHARE_MAP:
|
||||
intent = new Intent(this, UploadServiceChooserActivity.class);
|
||||
intent.putExtra(UploadServiceChooserActivity.TRACK_ID, trackId);
|
||||
intent.putExtra(UploadServiceChooserActivity.SEND_TYPE, (Parcelable) SendType.MAPS);
|
||||
intent = new Intent(this, UploadServiceChooserActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId, true, false, false));
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case Constants.MENU_SHARE_FUSION_TABLE:
|
||||
intent = new Intent(this, UploadServiceChooserActivity.class);
|
||||
intent.putExtra(UploadServiceChooserActivity.TRACK_ID, trackId);
|
||||
intent.putExtra(
|
||||
UploadServiceChooserActivity.SEND_TYPE, (Parcelable) SendType.FUSION_TABLES);
|
||||
intent = new Intent(this, UploadServiceChooserActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId, false, true, false));
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case Constants.MENU_SAVE_GPX_FILE:
|
||||
|
||||
@@ -208,7 +208,7 @@ public class SearchEngine {
|
||||
* Retrieves waypoints matching the given query from the database.
|
||||
*
|
||||
* @param query the query to retrieve for
|
||||
* @param tracks list to fill with the resulting waypoints
|
||||
* @param waypoints list to fill with the resulting waypoints
|
||||
*/
|
||||
private void retrieveWaypoints(SearchQuery query, ArrayList<Waypoint> waypoints) {
|
||||
String queryLikeSelection2 = "%" + query.textQuery + "%";
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.io.docs;
|
||||
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
@@ -32,43 +33,23 @@ import android.os.Bundle;
|
||||
*/
|
||||
public class SendDocsActivity extends Activity {
|
||||
|
||||
// parameters in the input intent
|
||||
public static final String ACCOUNT = "account";
|
||||
public static final String TRACK_ID = "trackId";
|
||||
|
||||
// parameters in the output intent
|
||||
public static final String SUCCESS = "success";
|
||||
|
||||
private static final int PROGRESS_DIALOG = 1;
|
||||
|
||||
private SendRequest sendRequest;
|
||||
private SendDocsAsyncTask asyncTask;
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
sendRequest = getIntent().getParcelableExtra(SendRequest.SEND_REQUEST_KEY);
|
||||
|
||||
Object retained = getLastNonConfigurationInstance();
|
||||
if (retained instanceof SendDocsAsyncTask) {
|
||||
asyncTask = (SendDocsAsyncTask) retained;
|
||||
asyncTask.setActivity(this);
|
||||
} else {
|
||||
Intent intent = getIntent();
|
||||
Account account = intent.getParcelableExtra(ACCOUNT);
|
||||
if (account == null) {
|
||||
setResult(RESULT_OK, new Intent().putExtra(SUCCESS, false));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
long trackId = intent.getLongExtra(TRACK_ID, -1L);
|
||||
if (trackId == -1L) {
|
||||
setResult(RESULT_OK, new Intent().putExtra(SUCCESS, false));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
asyncTask = new SendDocsAsyncTask(this, account, trackId);
|
||||
asyncTask = new SendDocsAsyncTask(this, sendRequest.getTrackId(), sendRequest.getAccount());
|
||||
asyncTask.execute();
|
||||
}
|
||||
}
|
||||
@@ -95,8 +76,7 @@ public class SendDocsActivity extends Activity {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
asyncTask.cancel(true);
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
startNextActivity(false);
|
||||
}
|
||||
});
|
||||
return progressDialog;
|
||||
@@ -111,9 +91,7 @@ public class SendDocsActivity extends Activity {
|
||||
* @param success true if success
|
||||
*/
|
||||
public void onAsyncTaskCompleted(boolean success) {
|
||||
Intent intent = new Intent().putExtra(SUCCESS, success);
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
startNextActivity(success);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,4 +109,17 @@ public class SendDocsActivity extends Activity {
|
||||
progressDialog.setProgress(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the next activity.
|
||||
*
|
||||
* @param success true if sendDocs is success
|
||||
*/
|
||||
private void startNextActivity(boolean success) {
|
||||
sendRequest.setDocsSuccess(success);
|
||||
Intent intent = new Intent(this, UploadResultActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ public class SendDocsAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
private static final String TAG = SendDocsAsyncTask.class.getSimpleName();
|
||||
|
||||
private SendDocsActivity activity;
|
||||
private final Account account;
|
||||
private final long trackId;
|
||||
private final Account account;
|
||||
private final Context context;
|
||||
private final MyTracksProviderUtils myTracksProviderUtils;
|
||||
private final GDataClient gDataClient;
|
||||
@@ -82,10 +82,10 @@ public class SendDocsAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
private String spreadsheetId;
|
||||
private String worksheetId;
|
||||
|
||||
public SendDocsAsyncTask(SendDocsActivity activity, Account account, long trackId) {
|
||||
public SendDocsAsyncTask(SendDocsActivity activity, long trackId, Account account) {
|
||||
this.activity = activity;
|
||||
this.account = account;
|
||||
this.trackId = trackId;
|
||||
this.account = account;
|
||||
|
||||
context = activity.getApplicationContext();
|
||||
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
|
||||
|
||||
+35
-28
@@ -15,9 +15,11 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.io.fusiontables;
|
||||
|
||||
import com.google.android.apps.mytracks.io.docs.SendDocsActivity;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
@@ -42,42 +44,24 @@ import android.os.Bundle;
|
||||
*/
|
||||
public class SendFusionTablesActivity extends Activity {
|
||||
|
||||
// parameters in the input intent
|
||||
public static final String ACCOUNT = "account";
|
||||
public static final String TRACK_ID = "trackId";
|
||||
|
||||
// parameters in the output intent
|
||||
public static final String SUCCESS = "success";
|
||||
|
||||
private static final int PROGRESS_DIALOG = 1;
|
||||
|
||||
private SendRequest sendRequest;
|
||||
private SendFusionTablesAsyncTask asyncTask;
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
sendRequest = getIntent().getParcelableExtra(SendRequest.SEND_REQUEST_KEY);
|
||||
|
||||
Object retained = getLastNonConfigurationInstance();
|
||||
if (retained instanceof SendFusionTablesAsyncTask) {
|
||||
asyncTask = (SendFusionTablesAsyncTask) retained;
|
||||
asyncTask.setActivity(this);
|
||||
} else {
|
||||
Intent intent = getIntent();
|
||||
Account account = intent.getParcelableExtra(ACCOUNT);
|
||||
if (account == null) {
|
||||
setResult(RESULT_OK, new Intent().putExtra(SUCCESS, false));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
long trackId = intent.getLongExtra(TRACK_ID, -1L);
|
||||
if (trackId == -1L) {
|
||||
setResult(RESULT_OK, new Intent().putExtra(SUCCESS, false));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
asyncTask = new SendFusionTablesAsyncTask(this, account, trackId);
|
||||
asyncTask = new SendFusionTablesAsyncTask(
|
||||
this, sendRequest.getTrackId(), sendRequest.getAccount());
|
||||
asyncTask.execute();
|
||||
}
|
||||
}
|
||||
@@ -104,8 +88,7 @@ public class SendFusionTablesActivity extends Activity {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
asyncTask.cancel(true);
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
startNextActivity(false, true);
|
||||
}
|
||||
});
|
||||
return progressDialog;
|
||||
@@ -120,8 +103,7 @@ public class SendFusionTablesActivity extends Activity {
|
||||
* @param success true if success
|
||||
*/
|
||||
public void onAsyncTaskCompleted(boolean success) {
|
||||
setResult(RESULT_OK, new Intent().putExtra(SUCCESS, success));
|
||||
finish();
|
||||
startNextActivity(success, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,4 +121,29 @@ public class SendFusionTablesActivity extends Activity {
|
||||
progressDialog.setProgress(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the next activity.
|
||||
*
|
||||
* @param success true if sendFusionTables is success
|
||||
* @param isCancel true if it is a cancel request
|
||||
*/
|
||||
private void startNextActivity(boolean success, boolean isCancel) {
|
||||
sendRequest.setFusionTablesSuccess(success);
|
||||
|
||||
Class<?> next;
|
||||
if (isCancel) {
|
||||
next = UploadResultActivity.class;
|
||||
} else {
|
||||
if (sendRequest.isSendDocs()) {
|
||||
next = SendDocsActivity.class;
|
||||
} else {
|
||||
next = UploadResultActivity.class;
|
||||
}
|
||||
}
|
||||
Intent intent = new Intent(this, next)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -76,8 +76,8 @@ public class SendFusionTablesAsyncTask extends AsyncTask<Void, Integer, Boolean>
|
||||
private SendFusionTablesActivity activity;
|
||||
|
||||
private final Context context;
|
||||
private final Account account;
|
||||
private final long trackId;
|
||||
private final Account account;
|
||||
private final MyTracksProviderUtils myTracksProviderUtils;
|
||||
private final HttpRequestFactory httpRequestFactory;
|
||||
|
||||
@@ -102,10 +102,10 @@ public class SendFusionTablesAsyncTask extends AsyncTask<Void, Integer, Boolean>
|
||||
int currentSegment;
|
||||
|
||||
public SendFusionTablesAsyncTask(
|
||||
SendFusionTablesActivity activity, Account account, long trackId) {
|
||||
SendFusionTablesActivity activity, long trackId, Account account) {
|
||||
this.activity = activity;
|
||||
this.account = account;
|
||||
this.trackId = trackId;
|
||||
this.account = account;
|
||||
|
||||
context = activity.getApplicationContext();
|
||||
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
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.maps.mytracks.R;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
@@ -45,15 +45,10 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class ChooseMapActivity extends Activity {
|
||||
|
||||
// parameters in the input intent
|
||||
public static final String ACCOUNT = "account";
|
||||
|
||||
// parameters in the output intent
|
||||
public static final String MAP_ID = "mapId";
|
||||
|
||||
private static final int PROGRESS_DIALOG = 1;
|
||||
private static final int ERROR_DIALOG = 2;
|
||||
|
||||
private SendRequest sendRequest;
|
||||
private ChooseMapAsyncTask asyncTask;
|
||||
private ProgressDialog progressDialog;
|
||||
private ArrayAdapter<ListItem> arrayAdapter;
|
||||
@@ -61,6 +56,7 @@ public class ChooseMapActivity extends Activity {
|
||||
@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<
|
||||
@@ -99,9 +95,7 @@ public class ChooseMapActivity extends Activity {
|
||||
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
setResult(
|
||||
RESULT_OK, new Intent().putExtra(MAP_ID, arrayAdapter.getItem(position).getMapId()));
|
||||
finish();
|
||||
startNextActivity(arrayAdapter.getItem(position).getMapId());
|
||||
}
|
||||
});
|
||||
list.setAdapter(arrayAdapter);
|
||||
@@ -111,14 +105,7 @@ public class ChooseMapActivity extends Activity {
|
||||
asyncTask = (ChooseMapAsyncTask) retained;
|
||||
asyncTask.setActivity(this);
|
||||
} else {
|
||||
Intent intent = getIntent();
|
||||
Account account = intent.getParcelableExtra(ACCOUNT);
|
||||
if (account == null) {
|
||||
setResult(RESULT_OK, new Intent().putExtra(MAP_ID, (String) null));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
asyncTask = new ChooseMapAsyncTask(this, account);
|
||||
asyncTask = new ChooseMapAsyncTask(this, sendRequest.getAccount());
|
||||
asyncTask.execute();
|
||||
}
|
||||
}
|
||||
@@ -141,7 +128,6 @@ public class ChooseMapActivity extends Activity {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
asyncTask.cancel(true);
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
@@ -156,14 +142,12 @@ public class ChooseMapActivity extends Activity {
|
||||
builder.setPositiveButton(R.string.generic_ok, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int arg1) {
|
||||
setResult(RESULT_OK, new Intent().putExtra(MAP_ID, (String) null));
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
setResult(RESULT_OK, new Intent().putExtra(MAP_ID, (String) null));
|
||||
finish();
|
||||
}
|
||||
});
|
||||
@@ -208,6 +192,19 @@ public class ChooseMapActivity extends Activity {
|
||||
showDialog(PROGRESS_DIALOG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the next activity, {@link SendMapsActivity}.
|
||||
*
|
||||
* @param mapId the chosen map id
|
||||
*/
|
||||
private void startNextActivity(String mapId) {
|
||||
sendRequest.setMapId(mapId);
|
||||
Intent intent = new Intent(this, SendMapsActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* A class containing {@link ChooseMapActivity} list item.
|
||||
*
|
||||
|
||||
@@ -15,9 +15,12 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.io.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.io.docs.SendDocsActivity;
|
||||
import com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesActivity;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
@@ -32,44 +35,24 @@ import android.os.Bundle;
|
||||
*/
|
||||
public class SendMapsActivity extends Activity {
|
||||
|
||||
// parameters in the input intent
|
||||
public static final String ACCOUNT = "account";
|
||||
public static final String TRACK_ID = "trackId";
|
||||
public static final String MAP_ID = "mapId";
|
||||
|
||||
// parameters in the output intent
|
||||
public static final String SUCCESS = "success";
|
||||
|
||||
private static final int PROGRESS_DIALOG = 1;
|
||||
|
||||
private SendRequest sendRequest;
|
||||
private SendMapsAsyncTask asyncTask;
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
sendRequest = getIntent().getParcelableExtra(SendRequest.SEND_REQUEST_KEY);
|
||||
|
||||
Object retained = getLastNonConfigurationInstance();
|
||||
if (retained instanceof SendMapsAsyncTask) {
|
||||
asyncTask = (SendMapsAsyncTask) retained;
|
||||
asyncTask.setActivity(this);
|
||||
} else {
|
||||
Intent intent = getIntent();
|
||||
Account account = intent.getParcelableExtra(ACCOUNT);
|
||||
if (account == null) {
|
||||
setResult(RESULT_OK, new Intent().putExtra(SUCCESS, false));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
long trackId = intent.getLongExtra(TRACK_ID, -1L);
|
||||
if (trackId == -1L) {
|
||||
setResult(RESULT_OK, new Intent().putExtra(SUCCESS, false));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
String mapId = intent.getStringExtra(MAP_ID);
|
||||
|
||||
asyncTask = new SendMapsAsyncTask(this, account, trackId, mapId);
|
||||
asyncTask = new SendMapsAsyncTask(
|
||||
this, sendRequest.getTrackId(), sendRequest.getAccount(), sendRequest.getMapId());
|
||||
asyncTask.execute();
|
||||
}
|
||||
}
|
||||
@@ -96,8 +79,7 @@ public class SendMapsActivity extends Activity {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
asyncTask.cancel(true);
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
startNextActivity(false, true);
|
||||
}
|
||||
});
|
||||
return progressDialog;
|
||||
@@ -112,8 +94,7 @@ public class SendMapsActivity extends Activity {
|
||||
* @param success true if success
|
||||
*/
|
||||
public void onAsyncTaskCompleted(boolean success) {
|
||||
setResult(RESULT_OK, new Intent().putExtra(SUCCESS, success));
|
||||
finish();
|
||||
startNextActivity(success, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,4 +112,31 @@ public class SendMapsActivity extends Activity {
|
||||
progressDialog.setProgress(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the next activity.
|
||||
*
|
||||
* @param success true if sendMaps is success
|
||||
* @param isCancel true if it is a cancel request
|
||||
*/
|
||||
private void startNextActivity(boolean success, boolean isCancel) {
|
||||
sendRequest.setMapsSuccess(success);
|
||||
|
||||
Class<?> next;
|
||||
if (isCancel) {
|
||||
next = UploadResultActivity.class;
|
||||
} else {
|
||||
if (sendRequest.isSendFusionTables()) {
|
||||
next = SendFusionTablesActivity.class;
|
||||
} else if (sendRequest.isSendDocs()) {
|
||||
next = SendDocsActivity.class;
|
||||
} else {
|
||||
next = UploadResultActivity.class;
|
||||
}
|
||||
}
|
||||
Intent intent = new Intent(this, next)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ public class SendMapsAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
private static final String TAG = SendMapsAsyncTask.class.getSimpleName();
|
||||
|
||||
private SendMapsActivity activity;
|
||||
private final Account account;
|
||||
private final long trackId;
|
||||
private final Account account;
|
||||
private final String chooseMapId;
|
||||
private final Context context;
|
||||
private final MyTracksProviderUtils myTracksProviderUtils;
|
||||
@@ -109,10 +109,10 @@ public class SendMapsAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
int currentSegment;
|
||||
|
||||
public SendMapsAsyncTask(
|
||||
SendMapsActivity activity, Account account, long trackId, String chooseMapId) {
|
||||
SendMapsActivity activity, long trackId, Account account, String chooseMapId) {
|
||||
this.activity = activity;
|
||||
this.account = account;
|
||||
this.trackId = trackId;
|
||||
this.account = account;
|
||||
this.chooseMapId = chooseMapId;
|
||||
|
||||
context = activity.getApplicationContext();
|
||||
|
||||
+51
-37
@@ -16,6 +16,10 @@
|
||||
package com.google.android.apps.mytracks.io.sendtogoogle;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.io.docs.SendDocsActivity;
|
||||
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.util.ApiAdapterFactory;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
@@ -32,46 +36,34 @@ import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* A chooser to select an account. To be called with
|
||||
* {@link Activity#startActivityForResult(Intent, int)}. Returns
|
||||
* {@link Activity#RESULT_CANCELED} if the user cancels the activity. Otherwise,
|
||||
* returns {@link Activity#RESULT_OK} with an intent containing the selected
|
||||
* account. The selected account is stored as an {@link Account} in the
|
||||
* {@link AccountChooserActivity#ACCOUNT} item of the intent. The selected
|
||||
* account can be null.
|
||||
* A chooser to select an account.
|
||||
*
|
||||
* @author jshih@google.com (Jimmy Shih)
|
||||
*/
|
||||
public class AccountChooserActivity extends Activity {
|
||||
|
||||
/**
|
||||
* Key for storing an {@link Account} in an {@link Intent}.
|
||||
*/
|
||||
public static final String ACCOUNT = "account";
|
||||
|
||||
private static final int NO_ACCOUNT_DIALOG = 1;
|
||||
private static final int CHOOSE_ACCOUNT_DIALOG = 2;
|
||||
|
||||
private SendRequest sendRequest;
|
||||
private Account[] accounts;
|
||||
private int selectedAccountIndex;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
sendRequest = getIntent().getParcelableExtra(SendRequest.SEND_REQUEST_KEY);
|
||||
accounts = AccountManager.get(this).getAccountsByType(Constants.ACCOUNT_TYPE);
|
||||
|
||||
if (accounts.length == 1) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(ACCOUNT, accounts[0]);
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
startNextActivity(accounts[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
SharedPreferences prefs = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
String preferredAccount = prefs.getString(getString(R.string.preferred_account_key), "");
|
||||
|
||||
selectedAccountIndex = -1;
|
||||
selectedAccountIndex = 0;
|
||||
for (int i = 0; i < accounts.length; i++) {
|
||||
if (accounts[i].name.equals(preferredAccount)) {
|
||||
selectedAccountIndex = i;
|
||||
@@ -102,15 +94,11 @@ public class AccountChooserActivity extends Activity {
|
||||
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(ACCOUNT, (Account) null);
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
@@ -134,31 +122,23 @@ public class AccountChooserActivity extends Activity {
|
||||
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.generic_cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Account account = null;
|
||||
if (selectedAccountIndex != -1) {
|
||||
account = accounts[selectedAccountIndex];
|
||||
SharedPreferences prefs = getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putString(getString(R.string.preferred_account_key), account.name);
|
||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
||||
}
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(ACCOUNT, account);
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
Account account = accounts[selectedAccountIndex];
|
||||
SharedPreferences prefs = getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putString(getString(R.string.preferred_account_key), account.name);
|
||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
||||
startNextActivity(account);
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
@@ -166,4 +146,38 @@ public class AccountChooserActivity extends Activity {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the next activity. If
|
||||
* <p>
|
||||
* sendMaps and newMap -> {@link SendMapsActivity}
|
||||
* <p>
|
||||
* sendMaps and !newMap -> {@link ChooseMapActivity}
|
||||
* <p>
|
||||
* !sendMaps && sendFusionTables -> {@link SendFusionTablesActivity}
|
||||
* <p>
|
||||
* !sendMaps && !sendFusionTables && sendDocs -> {@link SendDocsActivity}
|
||||
* <p>
|
||||
* !sendMaps && !sendFusionTables && !sendDocs -> {@link UploadResultActivity}
|
||||
*
|
||||
* @param account the chosen account
|
||||
*/
|
||||
private void startNextActivity(Account account) {
|
||||
sendRequest.setAccount(account);
|
||||
|
||||
Class<?> next;
|
||||
if (sendRequest.isSendMaps()) {
|
||||
next = sendRequest.isNewMap() ? SendMapsActivity.class : ChooseMapActivity.class;
|
||||
} else if (sendRequest.isSendFusionTables()) {
|
||||
next = SendFusionTablesActivity.class;
|
||||
} else if (sendRequest.isSendDocs()) {
|
||||
next = SendDocsActivity.class;
|
||||
} else {
|
||||
next = UploadResultActivity.class;
|
||||
}
|
||||
Intent intent = new Intent(this, next)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -1,419 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 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 static com.google.android.apps.mytracks.Constants.TAG;
|
||||
|
||||
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.io.docs.SendDocsActivity;
|
||||
import com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesActivity;
|
||||
import com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesUtils;
|
||||
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.maps.SendMapsUtils;
|
||||
import com.google.android.apps.mytracks.util.SystemUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Helper activity for managing the sending of tracks to Google services.
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class SendActivity extends Activity {
|
||||
|
||||
// Items in the intent that starts the activity.
|
||||
public static final String TRACK_ID = "trackId";
|
||||
public static final String SHARE_URL = "shareUrl";
|
||||
public static final String SEND_MAPS = "sendMaps";
|
||||
public static final String SEND_FUSION_TABLES = "sendFusionTables";
|
||||
public static final String SEND_DOCS = "sendDocs";
|
||||
public static final String CREATE_MAP = "createMap";
|
||||
|
||||
// Keys for saved state variables.
|
||||
private static final String STATE_STATE = "state";
|
||||
private static final String STATE_ACCOUNT = "account";
|
||||
private static final String STATE_MAP_ID = "mapId";
|
||||
private static final String STATE_DOCS_SUCCESS = "docsSuccess";
|
||||
private static final String STATE_FUSION_TABLES_SUCCESS = "fusionTablesSuccess";
|
||||
private static final String STATE_MAPS_SUCCESS = "mapsSuccess";
|
||||
|
||||
/** States for the state machine that defines the upload process. */
|
||||
private enum SendState {
|
||||
CHOOSE_ACCOUNT,
|
||||
CHOOSE_MAP,
|
||||
START,
|
||||
SEND_TO_MAPS,
|
||||
SEND_TO_MAPS_DONE,
|
||||
SEND_TO_FUSION_TABLES,
|
||||
SEND_TO_FUSION_TABLES_DONE,
|
||||
SEND_TO_DOCS,
|
||||
SEND_TO_DOCS_DONE,
|
||||
SHOW_RESULTS,
|
||||
FINISH,
|
||||
DONE,
|
||||
NOT_READY
|
||||
}
|
||||
|
||||
// Set in Activity.onCreate
|
||||
private MyTracksProviderUtils providerUtils;
|
||||
private GoogleAnalyticsTracker tracker;
|
||||
|
||||
// Send request information. Set by the intent that starts the activity.
|
||||
private long sendTrackId;
|
||||
private boolean shareRequest;
|
||||
private boolean sendToMaps;
|
||||
private boolean sendToMapsNewMap;
|
||||
private boolean sendToFusionTables;
|
||||
private boolean sendToDocs;
|
||||
|
||||
// Current sending state.
|
||||
private SendState currentState;
|
||||
|
||||
// Authentication information.
|
||||
private Account account;
|
||||
|
||||
// Map id from choosing a Google Map
|
||||
private String mapId;
|
||||
|
||||
// Send result information. Used by the results dialog.
|
||||
private boolean sendToMapsSuccess;
|
||||
private boolean sendToFusionTablesSuccess;
|
||||
private boolean sendToDocsSuccess;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Log.d(TAG, "SendActivity.onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (!handleIntent()) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
providerUtils = MyTracksProviderUtils.Factory.get(this);
|
||||
|
||||
tracker = GoogleAnalyticsTracker.getInstance();
|
||||
// Start the tracker in manual dispatch mode...
|
||||
tracker.start(getString(R.string.my_tracks_analytics_id),
|
||||
getApplicationContext());
|
||||
tracker.setProductVersion("android-mytracks",
|
||||
SystemUtils.getMyTracksVersion(this));
|
||||
|
||||
resetState();
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
restoreInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
// If we had the instance restored after it was done, reset it.
|
||||
if (currentState == SendState.DONE) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
// Execute the state machine, at the start or restored state.
|
||||
Log.w(TAG, "Starting at state " + currentState);
|
||||
executeStateMachine(currentState);
|
||||
}
|
||||
|
||||
private boolean handleIntent() {
|
||||
Intent intent = getIntent();
|
||||
sendTrackId = intent.getLongExtra(TRACK_ID, -1L);
|
||||
if (sendTrackId == -1L) {
|
||||
return false;
|
||||
}
|
||||
sendToMaps = intent.getBooleanExtra(SEND_MAPS, false);
|
||||
sendToFusionTables = intent.getBooleanExtra(SEND_FUSION_TABLES, false);
|
||||
sendToDocs = intent.getBooleanExtra(SEND_DOCS, false);
|
||||
if (!sendToMaps && !sendToFusionTables && !sendToDocs) {
|
||||
return false;
|
||||
}
|
||||
sendToMapsNewMap = intent.getBooleanExtra(CREATE_MAP, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void restoreInstanceState(Bundle savedInstanceState) {
|
||||
currentState = SendState.values()[savedInstanceState.getInt(STATE_STATE)];
|
||||
account = savedInstanceState.getParcelable(STATE_ACCOUNT);
|
||||
mapId = savedInstanceState.getString(STATE_MAP_ID);
|
||||
sendToMapsSuccess = savedInstanceState.getBoolean(STATE_MAPS_SUCCESS);
|
||||
sendToFusionTablesSuccess = savedInstanceState.getBoolean(STATE_FUSION_TABLES_SUCCESS);
|
||||
sendToDocsSuccess = savedInstanceState.getBoolean(STATE_DOCS_SUCCESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(STATE_STATE, currentState.ordinal());
|
||||
outState.putParcelable(STATE_ACCOUNT, account);
|
||||
outState.putString(STATE_MAP_ID, mapId);
|
||||
outState.putBoolean(STATE_MAPS_SUCCESS, sendToMapsSuccess);
|
||||
outState.putBoolean(STATE_FUSION_TABLES_SUCCESS, sendToFusionTablesSuccess);
|
||||
outState.putBoolean(STATE_DOCS_SUCCESS, sendToDocsSuccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
Log.d(TAG, "SendActivity.onStop, state=" + currentState);
|
||||
tracker.dispatch();
|
||||
tracker.stop();
|
||||
}
|
||||
|
||||
private void executeStateMachine(SendState startState) {
|
||||
currentState = startState;
|
||||
|
||||
// If a state handler returns NOT_READY, it means it's waiting for some
|
||||
// event, and will call this method again when it happens.
|
||||
while (currentState != SendState.DONE &&
|
||||
currentState != SendState.NOT_READY) {
|
||||
Log.d(TAG, "Executing state " + currentState);
|
||||
currentState = executeState(currentState);
|
||||
Log.d(TAG, "New state is " + currentState);
|
||||
}
|
||||
}
|
||||
|
||||
private SendState executeState(SendState state) {
|
||||
switch (state) {
|
||||
case CHOOSE_ACCOUNT:
|
||||
return chooseAccount();
|
||||
case CHOOSE_MAP:
|
||||
return chooseMap();
|
||||
case START:
|
||||
return startSend();
|
||||
case SEND_TO_MAPS:
|
||||
return sendToGoogleMaps();
|
||||
case SEND_TO_MAPS_DONE:
|
||||
return onSendToGoogleMapsDone();
|
||||
case SEND_TO_FUSION_TABLES:
|
||||
return sendToFusionTables();
|
||||
case SEND_TO_FUSION_TABLES_DONE:
|
||||
return onSendToFusionTablesDone();
|
||||
case SEND_TO_DOCS:
|
||||
return sendToGoogleDocs();
|
||||
case SEND_TO_DOCS_DONE:
|
||||
return onSendToGoogleDocsDone();
|
||||
case SHOW_RESULTS:
|
||||
return onSendToGoogleDone();
|
||||
case FINISH:
|
||||
return onAllDone();
|
||||
default:
|
||||
Log.e(TAG, "Reached a non-executable state");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private SendState chooseAccount() {
|
||||
Intent intent = new Intent(this, AccountChooserActivity.class);
|
||||
startActivityForResult(intent, Constants.CHOOSE_ACCOUNT);
|
||||
return SendState.NOT_READY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates the process to send tracks to google.
|
||||
* This is called once the user has selected sending options via the
|
||||
* SendToGoogleDialog.
|
||||
*/
|
||||
private SendState startSend() {
|
||||
if (sendToMaps) {
|
||||
return SendState.SEND_TO_MAPS;
|
||||
} else if (sendToFusionTables) {
|
||||
return SendState.SEND_TO_FUSION_TABLES;
|
||||
} else if (sendToDocs) {
|
||||
return SendState.SEND_TO_DOCS;
|
||||
} else {
|
||||
Log.w(TAG, "Nowhere to upload to");
|
||||
return SendState.FINISH;
|
||||
}
|
||||
}
|
||||
|
||||
private SendState chooseMap() {
|
||||
if (!sendToMapsNewMap) {
|
||||
Intent intent = new Intent(this, ChooseMapActivity.class)
|
||||
.putExtra(ChooseMapActivity.ACCOUNT, account);
|
||||
startActivityForResult(intent, Constants.CHOOSE_MAP);
|
||||
return SendState.NOT_READY;
|
||||
} else {
|
||||
return SendState.START;
|
||||
}
|
||||
}
|
||||
|
||||
private SendState sendToGoogleMaps() {
|
||||
tracker.trackPageView("/send/maps");
|
||||
Intent intent = new Intent(this, SendMapsActivity.class)
|
||||
.putExtra(SendMapsActivity.ACCOUNT, account)
|
||||
.putExtra(SendMapsActivity.TRACK_ID, sendTrackId)
|
||||
.putExtra(SendMapsActivity.MAP_ID, mapId);
|
||||
startActivityForResult(intent, Constants.SEND_MAPS);
|
||||
return SendState.NOT_READY;
|
||||
}
|
||||
|
||||
private SendState onSendToGoogleMapsDone() {
|
||||
if (sendToFusionTables) {
|
||||
return SendState.SEND_TO_FUSION_TABLES;
|
||||
} else if (sendToDocs) {
|
||||
return SendState.SEND_TO_DOCS;
|
||||
} else {
|
||||
return SendState.SHOW_RESULTS;
|
||||
}
|
||||
}
|
||||
|
||||
private SendState sendToFusionTables() {
|
||||
tracker.trackPageView("/send/fusion_tables");
|
||||
Intent intent = new Intent(this, SendFusionTablesActivity.class)
|
||||
.putExtra(SendFusionTablesActivity.ACCOUNT, account)
|
||||
.putExtra(SendFusionTablesActivity.TRACK_ID, sendTrackId);
|
||||
startActivityForResult(intent, Constants.SEND_FUSION_TABLES);
|
||||
return SendState.NOT_READY;
|
||||
}
|
||||
|
||||
private SendState onSendToFusionTablesDone() {
|
||||
if (sendToDocs) {
|
||||
return SendState.SEND_TO_DOCS;
|
||||
} else {
|
||||
return SendState.SHOW_RESULTS;
|
||||
}
|
||||
}
|
||||
|
||||
private SendState sendToGoogleDocs() {
|
||||
tracker.trackPageView("/send/docs");
|
||||
Intent intent = new Intent(this, SendDocsActivity.class)
|
||||
.putExtra(SendFusionTablesActivity.ACCOUNT, account)
|
||||
.putExtra(SendFusionTablesActivity.TRACK_ID, sendTrackId);
|
||||
startActivityForResult(intent, Constants.SEND_DOCS);
|
||||
return SendState.NOT_READY;
|
||||
}
|
||||
|
||||
private SendState onSendToGoogleDocsDone() {
|
||||
return SendState.SHOW_RESULTS;
|
||||
}
|
||||
|
||||
private SendState onSendToGoogleDone() {
|
||||
tracker.dispatch();
|
||||
Track track = providerUtils.getTrack(sendTrackId);
|
||||
String mapsUrl = sendToMaps && sendToMapsSuccess ? SendMapsUtils.getMapUrl(track) : null;
|
||||
String fusionTablesUrl = sendToFusionTables && sendToFusionTablesSuccess
|
||||
? SendFusionTablesUtils.getMapUrl(track) : null;
|
||||
Intent intent = new Intent(this, UploadResultActivity.class)
|
||||
.putExtra(UploadResultActivity.HAS_MAPS_RESULT, sendToMaps)
|
||||
.putExtra(UploadResultActivity.HAS_FUSION_TABLES_RESULT, sendToFusionTables)
|
||||
.putExtra(UploadResultActivity.HAS_DOCS_RESULT, sendToDocs)
|
||||
.putExtra(UploadResultActivity.MAPS_SUCCESS, sendToMapsSuccess)
|
||||
.putExtra(UploadResultActivity.FUSION_TABLES_SUCCESS, sendToFusionTablesSuccess)
|
||||
.putExtra(UploadResultActivity.DOCS_SUCCESS, sendToDocsSuccess)
|
||||
.putExtra(UploadResultActivity.SHARE_REQUEST, shareRequest)
|
||||
.putExtra(UploadResultActivity.MAPS_URL, mapsUrl)
|
||||
.putExtra(UploadResultActivity.FUSION_TABLES_URL, fusionTablesUrl);
|
||||
startActivity(intent);
|
||||
return SendState.FINISH;
|
||||
}
|
||||
|
||||
private SendState onAllDone() {
|
||||
finish();
|
||||
return SendState.DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode,
|
||||
final Intent results) {
|
||||
SendState nextState = null;
|
||||
switch (requestCode) {
|
||||
case Constants.CHOOSE_ACCOUNT: {
|
||||
if (resultCode == RESULT_CANCELED) {
|
||||
nextState = SendState.FINISH;
|
||||
break;
|
||||
}
|
||||
account = results.getParcelableExtra(AccountChooserActivity.ACCOUNT);
|
||||
if (account == null) {
|
||||
nextState = SendState.FINISH;
|
||||
break;
|
||||
}
|
||||
nextState = SendState.CHOOSE_MAP;
|
||||
break;
|
||||
}
|
||||
case Constants.CHOOSE_MAP: {
|
||||
if (resultCode == RESULT_CANCELED) {
|
||||
nextState = SendState.FINISH;
|
||||
break;
|
||||
}
|
||||
mapId = results.getStringExtra(ChooseMapActivity.MAP_ID);
|
||||
if (mapId == null) {
|
||||
nextState = SendState.FINISH;
|
||||
break;
|
||||
}
|
||||
nextState = SendState.START;
|
||||
break;
|
||||
}
|
||||
case Constants.SEND_MAPS: {
|
||||
if (resultCode == RESULT_CANCELED) {
|
||||
nextState = SendState.FINISH;
|
||||
break;
|
||||
}
|
||||
sendToMapsSuccess = results.getBooleanExtra(SendMapsActivity.SUCCESS, false);
|
||||
nextState = SendState.SEND_TO_MAPS_DONE;
|
||||
break;
|
||||
}
|
||||
case Constants.SEND_FUSION_TABLES: {
|
||||
if (resultCode == RESULT_CANCELED) {
|
||||
nextState = SendState.FINISH;
|
||||
break;
|
||||
}
|
||||
sendToFusionTablesSuccess = results.getBooleanExtra(
|
||||
SendFusionTablesActivity.SUCCESS, false);
|
||||
nextState = SendState.SEND_TO_FUSION_TABLES_DONE;
|
||||
break;
|
||||
}
|
||||
case Constants.SEND_DOCS: {
|
||||
if (resultCode == RESULT_CANCELED) {
|
||||
nextState = SendState.FINISH;
|
||||
break;
|
||||
}
|
||||
sendToDocsSuccess = results.getBooleanExtra(SendDocsActivity.SUCCESS, false);
|
||||
nextState = SendState.SEND_TO_DOCS_DONE;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
Log.e(TAG, "Unrequested result: " + requestCode);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (nextState != null) {
|
||||
executeStateMachine(nextState);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets status information for sending to Maps/Fusion Tables/Docs.
|
||||
*/
|
||||
private void resetState() {
|
||||
currentState = SendState.CHOOSE_ACCOUNT;
|
||||
account = null;
|
||||
mapId = null;
|
||||
sendToMapsSuccess = false;
|
||||
sendToFusionTablesSuccess = false;
|
||||
sendToDocsSuccess = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* 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 android.accounts.Account;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
/**
|
||||
* Send request states for sending a track to Google Maps, Google Fusion Tables,
|
||||
* and Google Docs.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class SendRequest implements Parcelable {
|
||||
|
||||
public static final String SEND_REQUEST_KEY = "sendRequest";
|
||||
|
||||
private long trackId = -1L;
|
||||
private boolean showMaps = false;
|
||||
private boolean showFusionTables = false;
|
||||
private boolean showDocs = false;
|
||||
private boolean sendMaps = false;
|
||||
private boolean sendFusionTables = false;
|
||||
private boolean sendDocs = false;
|
||||
private boolean newMap = false;
|
||||
private Account account = null;
|
||||
private String mapId = null;
|
||||
private boolean mapsSuccess = false;
|
||||
private boolean docsSuccess = false;
|
||||
private boolean fusionTablesSuccess = false;
|
||||
|
||||
/**
|
||||
* Creates a new send request.
|
||||
*
|
||||
* @param trackId the track id
|
||||
* @param showMaps true to show the Google Maps option
|
||||
* @param showFusionTables true to show the Google Fusion Tables option
|
||||
* @param showDocs true to show the Google Docs option
|
||||
*/
|
||||
public SendRequest(long trackId, boolean showMaps, boolean showFusionTables, boolean showDocs) {
|
||||
this.trackId = trackId;
|
||||
this.showMaps = showMaps;
|
||||
this.showFusionTables = showFusionTables;
|
||||
this.showDocs = showDocs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the track id.
|
||||
*/
|
||||
public long getTrackId() {
|
||||
return trackId;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if showing the send to Google Maps option.
|
||||
*/
|
||||
public boolean isShowMaps() {
|
||||
return showMaps;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if showing the send to Google Fusion Tables option.
|
||||
*/
|
||||
public boolean isShowFusionTables() {
|
||||
return showFusionTables;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if showing the send to Google Docs option.
|
||||
*/
|
||||
public boolean isShowDocs() {
|
||||
return showDocs;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if showing all the send options.
|
||||
*/
|
||||
public boolean isShowAll() {
|
||||
return showMaps && showFusionTables && showDocs;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the user has selected the send to Google Maps option.
|
||||
*/
|
||||
public boolean isSendMaps() {
|
||||
return sendMaps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the send to Google Maps option.
|
||||
*
|
||||
* @param sendMaps true if the user has selected the send to Google Maps
|
||||
* option
|
||||
*/
|
||||
public void setSendMaps(boolean sendMaps) {
|
||||
this.sendMaps = sendMaps;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the user has selected the send to Google Fusion Tables option.
|
||||
*/
|
||||
public boolean isSendFusionTables() {
|
||||
return sendFusionTables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the send to Google Fusion Tables option.
|
||||
*
|
||||
* @param sendFusionTables true if the user has selected the send to Google
|
||||
* Fusion Tables option
|
||||
*/
|
||||
public void setSendFusionTables(boolean sendFusionTables) {
|
||||
this.sendFusionTables = sendFusionTables;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the user has selected the send to Google Docs option.
|
||||
*/
|
||||
public boolean isSendDocs() {
|
||||
return sendDocs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the send to Google Docs option.
|
||||
*
|
||||
* @param sendDocs true if the user has selected the send to Google Docs
|
||||
* option
|
||||
*/
|
||||
public void setSendDocs(boolean sendDocs) {
|
||||
this.sendDocs = sendDocs;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the user has selected to create a new Google Maps.
|
||||
*/
|
||||
public boolean isNewMap() {
|
||||
return newMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new map option.
|
||||
*
|
||||
* @param newMap true if the user has selected to create a new Google Maps.
|
||||
*/
|
||||
public void setNewMap(boolean newMap) {
|
||||
this.newMap = newMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the account.
|
||||
*/
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the account.
|
||||
*
|
||||
* @param account the account
|
||||
*/
|
||||
public void setAccount(Account account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the selected map id if the user has selected to send a track to an
|
||||
* existing Google Maps.
|
||||
*/
|
||||
public String getMapId() {
|
||||
return mapId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the map id.
|
||||
*
|
||||
* @param mapId the map id
|
||||
*/
|
||||
public void setMapId(String mapId) {
|
||||
this.mapId = mapId;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if sending to Google Maps is success.
|
||||
*/
|
||||
public boolean isMapsSuccess() {
|
||||
return mapsSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Google Maps result.
|
||||
*
|
||||
* @param mapsSuccess true if sending to Google Maps is success
|
||||
*/
|
||||
public void setMapsSuccess(boolean mapsSuccess) {
|
||||
this.mapsSuccess = mapsSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if sending to Google Fusion Tables is success.
|
||||
*/
|
||||
public boolean isFusionTablesSuccess() {
|
||||
return fusionTablesSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Google Fusion Tables result.
|
||||
*
|
||||
* @param fusionTablesSuccess true if sending to Google Fusion Tables is
|
||||
* success
|
||||
*/
|
||||
public void setFusionTablesSuccess(boolean fusionTablesSuccess) {
|
||||
this.fusionTablesSuccess = fusionTablesSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if sending to Google Docs is success.
|
||||
*/
|
||||
public boolean isDocsSuccess() {
|
||||
return docsSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Google Docs result.
|
||||
*
|
||||
* @param docsSuccess true if sending to Google Docs is success
|
||||
*/
|
||||
public void setDocsSuccess(boolean docsSuccess) {
|
||||
this.docsSuccess = docsSuccess;
|
||||
}
|
||||
|
||||
private SendRequest(Parcel in) {
|
||||
trackId = in.readLong();
|
||||
showMaps = in.readByte() == 1;
|
||||
showFusionTables = in.readByte() == 1;
|
||||
showDocs = in.readByte() == 1;
|
||||
sendMaps = in.readByte() == 1;
|
||||
sendFusionTables = in.readByte() == 1;
|
||||
sendDocs = in.readByte() == 1;
|
||||
newMap = in.readByte() == 1;
|
||||
account = in.readParcelable(null);
|
||||
mapId = in.readString();
|
||||
mapsSuccess = in.readByte() == 1;
|
||||
fusionTablesSuccess = in.readByte() == 1;
|
||||
docsSuccess = in.readByte() == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeLong(trackId);
|
||||
out.writeByte((byte) (showMaps ? 1 : 0));
|
||||
out.writeByte((byte) (showFusionTables ? 1 : 0));
|
||||
out.writeByte((byte) (showDocs ? 1 : 0));
|
||||
out.writeByte((byte) (sendMaps ? 1 : 0));
|
||||
out.writeByte((byte) (sendFusionTables ? 1 : 0));
|
||||
out.writeByte((byte) (sendDocs ? 1 : 0));
|
||||
out.writeByte((byte) (newMap ? 1 : 0));
|
||||
out.writeParcelable(account, 0);
|
||||
out.writeString(mapId);
|
||||
out.writeByte((byte) (mapsSuccess ? 1 : 0));
|
||||
out.writeByte((byte) (fusionTablesSuccess ? 1 : 0));
|
||||
out.writeByte((byte) (docsSuccess ? 1 : 0));
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<SendRequest> CREATOR = new Parcelable.Creator<
|
||||
SendRequest>() {
|
||||
public SendRequest createFromParcel(Parcel in) {
|
||||
return new SendRequest(in);
|
||||
}
|
||||
|
||||
public SendRequest[] newArray(int size) {
|
||||
return new SendRequest[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 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.maps.mytracks.R;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
/**
|
||||
* Enumerates the services to which we can upload track data.
|
||||
*
|
||||
* @author Matthew Simmons
|
||||
*/
|
||||
public enum SendType implements Parcelable {
|
||||
MAPS(R.string.send_google_maps,
|
||||
R.string.send_google_maps_url),
|
||||
FUSION_TABLES(R.string.send_google_fusion_tables,
|
||||
R.string.send_google_fusion_tables_url),
|
||||
DOCS(R.string.send_google_docs,
|
||||
R.string.send_google_docs_url);
|
||||
|
||||
private int serviceName;
|
||||
private int serviceUrl;
|
||||
|
||||
private SendType(int serviceName, int serviceUrl) {
|
||||
this.serviceName = serviceName;
|
||||
this.serviceUrl = serviceUrl;
|
||||
}
|
||||
|
||||
/** Returns the resource ID for the printable (short) name of the service */
|
||||
public int getServiceName() {
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
/** Returns the resource ID for the service's URL */
|
||||
public int getServiceUrl() {
|
||||
return serviceUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(ordinal());
|
||||
}
|
||||
|
||||
public static final Creator<SendType> CREATOR = new Creator<SendType>() {
|
||||
|
||||
@Override
|
||||
public SendType createFromParcel(Parcel source) {
|
||||
return SendType.values()[source.readInt()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendType[] newArray(int size) {
|
||||
return new SendType[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
+32
-48
@@ -16,6 +16,10 @@
|
||||
package com.google.android.apps.mytracks.io.sendtogoogle;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesUtils;
|
||||
import com.google.android.apps.mytracks.io.maps.SendMapsUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -38,54 +42,34 @@ import android.widget.TextView;
|
||||
*/
|
||||
public class UploadResultActivity extends Activity {
|
||||
|
||||
public static final String HAS_MAPS_RESULT = "hasMapsResult";
|
||||
public static final String HAS_FUSION_TABLES_RESULT = "hasFusionTablesResult";
|
||||
public static final String HAS_DOCS_RESULT = "hasDocsResult";
|
||||
|
||||
public static final String MAPS_SUCCESS = "mapsSuccess";
|
||||
public static final String FUSION_TABLES_SUCCESS = "fusionTablesSuccess";
|
||||
public static final String DOCS_SUCCESS = "docsSuccess";
|
||||
|
||||
public static final String SHARE_REQUEST = "shareRequest";
|
||||
|
||||
public static final String MAPS_URL = "mapsUrl";
|
||||
public static final String FUSION_TABLES_URL = "fusionTablesUrl";
|
||||
|
||||
private static final String TEXT_PLAIN_TYPE = "text/plain";
|
||||
private static final int RESULT_DIALOG = 1;
|
||||
|
||||
private boolean hasMapsResult;
|
||||
private boolean hasFusionTablesResult;
|
||||
private boolean hasDocsResult;
|
||||
|
||||
private boolean mapsSuccess;
|
||||
private boolean fusionTablesSuccess;
|
||||
private boolean docsSuccess;
|
||||
|
||||
private boolean shareRequest;
|
||||
private SendRequest sendRequest;
|
||||
private Track track;
|
||||
private String shareUrl;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Intent intent = getIntent();
|
||||
hasMapsResult = intent.getBooleanExtra(HAS_MAPS_RESULT, false);
|
||||
hasFusionTablesResult = intent.getBooleanExtra(HAS_FUSION_TABLES_RESULT, false);
|
||||
hasDocsResult = intent.getBooleanExtra(HAS_DOCS_RESULT, false);
|
||||
if (!hasMapsResult && !hasFusionTablesResult && !hasDocsResult) {
|
||||
finish();
|
||||
return;
|
||||
sendRequest = getIntent().getParcelableExtra(SendRequest.SEND_REQUEST_KEY);
|
||||
track = null;
|
||||
shareUrl = null;
|
||||
|
||||
if (sendRequest.isSendMaps() && sendRequest.isMapsSuccess()) {
|
||||
shareUrl = SendMapsUtils.getMapUrl(getTrack());
|
||||
}
|
||||
mapsSuccess = intent.getBooleanExtra(MAPS_SUCCESS, false);
|
||||
fusionTablesSuccess = intent.getBooleanExtra(FUSION_TABLES_SUCCESS, false);
|
||||
docsSuccess = intent.getBooleanExtra(DOCS_SUCCESS, false);
|
||||
if (shareUrl == null && sendRequest.isSendFusionTables()
|
||||
&& sendRequest.isFusionTablesSuccess()) {
|
||||
shareUrl = SendFusionTablesUtils.getMapUrl(getTrack());
|
||||
}
|
||||
}
|
||||
|
||||
shareRequest = intent.getBooleanExtra(SHARE_REQUEST, false);
|
||||
|
||||
String mapsUrl = intent.getStringExtra(MAPS_URL);
|
||||
String fusionTablesUrl = intent.getStringExtra(FUSION_TABLES_URL);
|
||||
shareUrl = mapsUrl != null ? mapsUrl : fusionTablesUrl;
|
||||
private Track getTrack() {
|
||||
if (track == null) {
|
||||
track = MyTracksProviderUtils.Factory.get(this).getTrack(sendRequest.getTrackId());
|
||||
}
|
||||
return track;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,28 +102,28 @@ public class UploadResultActivity extends Activity {
|
||||
TextView errorFooter = (TextView) view.findViewById(R.id.upload_result_error_footer);
|
||||
|
||||
boolean hasError = false;
|
||||
if (!hasMapsResult) {
|
||||
if (!sendRequest.isSendMaps()) {
|
||||
mapsResult.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (!mapsSuccess) {
|
||||
if (!sendRequest.isMapsSuccess()) {
|
||||
mapsResultIcon.setImageResource(R.drawable.failure);
|
||||
hasError = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasFusionTablesResult) {
|
||||
if (!sendRequest.isSendFusionTables()) {
|
||||
fusionTablesResult.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (!fusionTablesSuccess) {
|
||||
if (!sendRequest.isFusionTablesSuccess()) {
|
||||
fusionTablesResultIcon.setImageResource(R.drawable.failure);
|
||||
hasError = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasDocsResult) {
|
||||
if (!sendRequest.isSendDocs()) {
|
||||
docsResult.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (!docsSuccess) {
|
||||
if (!sendRequest.isDocsSuccess()) {
|
||||
docsResultIcon.setImageResource(R.drawable.failure);
|
||||
hasError = true;
|
||||
}
|
||||
@@ -166,16 +150,16 @@ public class UploadResultActivity extends Activity {
|
||||
getString(R.string.generic_ok), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (shareRequest && shareUrl != null) {
|
||||
if (!sendRequest.isShowAll() && shareUrl != null) {
|
||||
startShareUrlActivity(shareUrl);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
// Add a Share URL button if not a shareRequest and shareUrl
|
||||
// Add a Share URL button if showing all the options and a shareUrl
|
||||
// exists
|
||||
if (!shareRequest && shareUrl != null) {
|
||||
if (sendRequest.isShowAll() && shareUrl != null) {
|
||||
builder.setNegativeButton(getString(R.string.send_google_result_share_url),
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
||||
+59
-65
@@ -15,8 +15,10 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.io.sendtogoogle;
|
||||
|
||||
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||
import com.google.android.apps.mytracks.util.SystemUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -43,20 +45,9 @@ import android.widget.TableRow;
|
||||
*/
|
||||
public class UploadServiceChooserActivity extends Activity {
|
||||
|
||||
/**
|
||||
* The track id.
|
||||
*/
|
||||
public static final String TRACK_ID = "trackId";
|
||||
|
||||
/**
|
||||
* The send type. Null to send to all Google services.
|
||||
*/
|
||||
public static final String SEND_TYPE = "sendType";
|
||||
|
||||
private static final int SERVICE_PICKER_DIALOG = 1;
|
||||
|
||||
private long trackId;
|
||||
private SendType sendType;
|
||||
private SendRequest sendRequest;
|
||||
|
||||
private TableRow mapsTableRow;
|
||||
private TableRow fusionTablesTableRow;
|
||||
@@ -76,10 +67,7 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Intent intent = getIntent();
|
||||
trackId = intent.getLongExtra(TRACK_ID, -1L);
|
||||
sendType = intent.getParcelableExtra(SEND_TYPE);
|
||||
sendRequest = getIntent().getParcelableExtra(SendRequest.SEND_REQUEST_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,23 +124,15 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
send.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
saveState();
|
||||
Intent intent = new Intent(UploadServiceChooserActivity.this, SendActivity.class);
|
||||
intent.putExtra(SendActivity.TRACK_ID, trackId);
|
||||
intent.putExtra(SendActivity.SHARE_URL, sendType != null);
|
||||
intent.putExtra(SendActivity.SEND_MAPS, sendMaps());
|
||||
intent.putExtra(SendActivity.SEND_FUSION_TABLES, sendFusionTables());
|
||||
intent.putExtra(SendActivity.SEND_DOCS, sendDocs());
|
||||
intent.putExtra(SendActivity.CREATE_MAP, !existingMapRadioButton.isChecked());
|
||||
startActivity(intent);
|
||||
finish();
|
||||
startNextActivity();
|
||||
}
|
||||
});
|
||||
|
||||
// Setup initial state
|
||||
initState();
|
||||
|
||||
// Update state based on sendType
|
||||
updateStateBySendType();
|
||||
// Update state based on sendRequest
|
||||
updateStateBySendRequest();
|
||||
|
||||
// Update state based on current user selection
|
||||
updateStateBySelection();
|
||||
@@ -180,21 +160,21 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the UI state based on the sendType.
|
||||
* Updates the UI state based on sendRequest.
|
||||
*/
|
||||
private void updateStateBySendType() {
|
||||
if (sendType == SendType.MAPS) {
|
||||
mapsCheckBox.setChecked(true);
|
||||
} else if (sendType == SendType.FUSION_TABLES) {
|
||||
fusionTablesCheckBox.setChecked(true);
|
||||
} else if (sendType == SendType.DOCS) {
|
||||
docsCheckBox.setChecked(true);
|
||||
} else {
|
||||
// sendType == null
|
||||
private void updateStateBySendRequest() {
|
||||
if (!sendRequest.isShowAll()) {
|
||||
if (sendRequest.isShowMaps()) {
|
||||
mapsCheckBox.setChecked(true);
|
||||
} else if (sendRequest.isShowFusionTables()) {
|
||||
fusionTablesCheckBox.setChecked(true);
|
||||
} else if (sendRequest.isShowDocs()) {
|
||||
docsCheckBox.setChecked(true);
|
||||
}
|
||||
}
|
||||
mapsTableRow.setVisibility(showMaps() ? View.VISIBLE : View.GONE);
|
||||
fusionTablesTableRow.setVisibility(showFusionTables() ? View.VISIBLE : View.GONE);
|
||||
docsTableRow.setVisibility(showDocs() ? View.VISIBLE : View.GONE);
|
||||
mapsTableRow.setVisibility(sendRequest.isShowMaps() ? View.VISIBLE : View.GONE);
|
||||
fusionTablesTableRow.setVisibility(sendRequest.isShowFusionTables() ? View.VISIBLE : View.GONE);
|
||||
docsTableRow.setVisibility(sendRequest.isShowDocs() ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -213,7 +193,7 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(
|
||||
getString(R.string.pick_existing_map_key), existingMapRadioButton.isChecked());
|
||||
if (sendType == null) {
|
||||
if (sendRequest.isShowAll()) {
|
||||
editor.putBoolean(getString(R.string.send_to_maps_key), sendMaps());
|
||||
editor.putBoolean(getString(R.string.send_to_fusion_tables_key), sendFusionTables());
|
||||
editor.putBoolean(getString(R.string.send_to_docs_key), sendDocs());
|
||||
@@ -221,45 +201,59 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true to show the Google Maps option.
|
||||
*/
|
||||
private boolean showMaps() {
|
||||
return sendType == null || sendType == SendType.MAPS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true to show the Google Fusion Tables option.
|
||||
*/
|
||||
private boolean showFusionTables() {
|
||||
return sendType == null || sendType == SendType.FUSION_TABLES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true to show the Google Docs option.
|
||||
*/
|
||||
private boolean showDocs() {
|
||||
return sendType == null || sendType == SendType.DOCS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true to send to Google Maps.
|
||||
*/
|
||||
private boolean sendMaps() {
|
||||
return showMaps() && mapsCheckBox.isChecked();
|
||||
return sendRequest.isShowMaps() && mapsCheckBox.isChecked();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true to send to Google Fusion Tables.
|
||||
*/
|
||||
private boolean sendFusionTables() {
|
||||
return showFusionTables() && fusionTablesCheckBox.isChecked();
|
||||
return sendRequest.isShowFusionTables() && fusionTablesCheckBox.isChecked();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true to send to Google Docs.
|
||||
*/
|
||||
private boolean sendDocs() {
|
||||
return showDocs() && docsCheckBox.isChecked();
|
||||
return sendRequest.isShowDocs() && docsCheckBox.isChecked();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the next activity, {@link AccountChooserActivity}.
|
||||
*/
|
||||
private void startNextActivity() {
|
||||
sendStats();
|
||||
sendRequest.setSendMaps(sendMaps());
|
||||
sendRequest.setSendFusionTables(sendFusionTables());
|
||||
sendRequest.setSendDocs(sendDocs());
|
||||
sendRequest.setNewMap(!existingMapRadioButton.isChecked());
|
||||
Intent intent = new Intent(this, AccountChooserActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends stats to Google Analytics.
|
||||
*/
|
||||
private void sendStats() {
|
||||
GoogleAnalyticsTracker tracker = GoogleAnalyticsTracker.getInstance();
|
||||
tracker.start(getString(R.string.my_tracks_analytics_id), getApplicationContext());
|
||||
tracker.setProductVersion("android-mytracks", SystemUtils.getMyTracksVersion(this));
|
||||
if (sendRequest.isSendMaps()) {
|
||||
tracker.trackPageView("/send/maps");
|
||||
}
|
||||
if (sendRequest.isSendFusionTables()) {
|
||||
tracker.trackPageView("/send/fusion_tables");
|
||||
}
|
||||
if (sendRequest.isSendDocs()) {
|
||||
tracker.trackPageView("/send/docs");
|
||||
}
|
||||
tracker.dispatch();
|
||||
tracker.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ public interface MyTracksProviderUtils {
|
||||
* Caller owns the returned cursor and is responsible for closing it.
|
||||
*
|
||||
* @param selection a given selection
|
||||
* @param selecttionArgs parameters for the given selection
|
||||
* @param selectionArgs parameters for the given selection
|
||||
* @param order the order to return results in
|
||||
* @return a cursor of the selected tracks
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user