diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java index 7b04731f6..2ad895d8a 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java @@ -22,7 +22,6 @@ import com.google.android.apps.mytracks.content.TrackDataHub; import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.WaypointCreationRequest; import com.google.android.apps.mytracks.fragments.ChartFragment; -import com.google.android.apps.mytracks.fragments.ChooseActivityDialogFragment; import com.google.android.apps.mytracks.fragments.ChooseUploadServiceDialogFragment; import com.google.android.apps.mytracks.fragments.ConfirmDialogFragment; import com.google.android.apps.mytracks.fragments.ConfirmDialogFragment.ConfirmCaller; @@ -431,6 +430,7 @@ public class TrackDetailActivity extends AbstractMyTracksActivity @Override public void onConfirmDone(int confirmId, long confirmTrackId) { + SendRequest sendRequest; Intent intent; switch (confirmId) { case R.string.confirm_play_earth_key: @@ -442,12 +442,17 @@ public class TrackDetailActivity extends AbstractMyTracksActivity startActivity(intent); break; case R.string.confirm_share_map_key: - AnalyticsUtils.sendPageViews(this, "/action/share"); - ChooseActivityDialogFragment.newInstance(confirmTrackId, null).show( - getSupportFragmentManager(), ChooseActivityDialogFragment.CHOOSE_ACTIVITY_DIALOG_TAG); + AnalyticsUtils.sendPageViews(this, "/action/share_map"); + sendRequest = new SendRequest(trackId); + sendRequest.setSendMaps(true); + sendRequest.setMapsShare(true); + intent = IntentUtils.newIntent(this, AccountChooserActivity.class) + .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); + startActivity(intent); break; case R.string.confirm_share_drive_key: - SendRequest sendRequest = new SendRequest(trackId); + AnalyticsUtils.sendPageViews(this, "/action/share_drive"); + sendRequest = new SendRequest(trackId); sendRequest.setSendDrive(true); sendRequest.setDriveShare(true); intent = IntentUtils.newIntent(this, AccountChooserActivity.class) diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/ChooseActivityDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/ChooseActivityDialogFragment.java index c4bbf1f13..aa8eeec1c 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/fragments/ChooseActivityDialogFragment.java +++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/ChooseActivityDialogFragment.java @@ -16,11 +16,10 @@ package com.google.android.apps.mytracks.fragments; -import com.google.android.apps.mytracks.io.sendtogoogle.AccountChooserActivity; -import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest; import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.maps.mytracks.R; +import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; @@ -51,37 +50,49 @@ import java.util.List; */ public class ChooseActivityDialogFragment extends DialogFragment { + /** + * Interface for caller of this dialog fragment. + * + * @author Jimmy Shih + */ + public interface ChooseActivityCaller { + + /** + * Called when choose activity is done. + */ + public void onChooseActivityDone(String packageName, String className); + } + public static final String CHOOSE_ACTIVITY_DIALOG_TAG = "chooseActivityDialog"; - private static final String KEY_TRACK_ID = "trackId"; - private static final String KEY_TRACK_URL = "trackUrl"; - - private FragmentActivity activity; + private ChooseActivityCaller caller; + private FragmentActivity fragmentActivity; private PackageManager packageManager; - - public static ChooseActivityDialogFragment newInstance(long trackId, String trackUrl) { - Bundle bundle = new Bundle(); - bundle.putLong(KEY_TRACK_ID, trackId); - bundle.putString(KEY_TRACK_URL, trackUrl); - - ChooseActivityDialogFragment chooseActivityDialogFragment = new ChooseActivityDialogFragment(); - chooseActivityDialogFragment.setArguments(bundle); - return chooseActivityDialogFragment; + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + try { + caller = (ChooseActivityCaller) activity; + } catch (ClassCastException e) { + throw new ClassCastException( + activity.toString() + " must implement " + ChooseActivityCaller.class.getSimpleName()); + } } - + @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - activity = getActivity(); - packageManager = activity.getPackageManager(); + fragmentActivity = getActivity(); + packageManager = fragmentActivity.getPackageManager(); List displayInfos = getDisplayInfos(); - ArrayAdapter arrayAdapter = new ArrayAdapter(activity, + ArrayAdapter arrayAdapter = new ArrayAdapter(fragmentActivity, R.layout.choose_activity_list_item, R.id.choose_activity_list_item_text1, displayInfos) { @Override public View getView(int position, View convertView, ViewGroup parent) { View view; if (convertView == null) { - view = activity.getLayoutInflater() + view = fragmentActivity.getLayoutInflater() .inflate(R.layout.choose_activity_list_item, parent, false); } else { view = convertView; @@ -101,47 +112,32 @@ public class ChooseActivityDialogFragment extends DialogFragment { return view; } }; - return new AlertDialog.Builder(activity) - .setSingleChoiceItems(arrayAdapter, 0, new DialogInterface.OnClickListener() { + return new AlertDialog.Builder(fragmentActivity).setSingleChoiceItems( + arrayAdapter, 0, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { AlertDialog alertDialog = (AlertDialog) dialog; DisplayInfo displayInfo = (DisplayInfo) alertDialog.getListView() .getItemAtPosition(which); ActivityInfo activityInfo = displayInfo.resolveInfo.activityInfo; - String packageName = activityInfo.applicationInfo.packageName; - String className = activityInfo.name; - - long trackId = getArguments().getLong(KEY_TRACK_ID); - String trackUrl = getArguments().getString(KEY_TRACK_URL); - if (trackUrl == null) { - SendRequest sendRequest = new SendRequest(trackId); - sendRequest.setSendMaps(true); - sendRequest.setNewMap(true); - sendRequest.setSharingAppPackageName(packageName); - sendRequest.setSharingAppClassName(className); - Intent intent = IntentUtils.newIntent(activity, AccountChooserActivity.class) - .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); - startActivity(intent); - dismiss(); - } else { - Intent intent = IntentUtils.newShareUrlIntent( - activity, trackId, trackUrl, packageName, className); - startActivity(intent); - activity.finish(); - } + caller.onChooseActivityDone( + activityInfo.applicationInfo.packageName, activityInfo.name); } - }) - .setTitle(R.string.share_track_picker_title) - .create(); + }).setTitle(R.string.share_track_picker_title).create(); } + @Override + public void onCancel(DialogInterface dialog) { + super.onCancel(dialog); + caller.onChooseActivityDone(null, null); + } + /** * Gets the display info. */ private List getDisplayInfos() { List displayInfos = new ArrayList(); - Intent intent = ShareCompat.IntentBuilder.from(activity) + Intent intent = ShareCompat.IntentBuilder.from(fragmentActivity) .setType(IntentUtils.TEXT_PLAIN_TYPE).getIntent(); List resolveInfos = packageManager.queryIntentActivities( intent, PackageManager.MATCH_DEFAULT_ONLY); diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/ChooseUploadServiceDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/ChooseUploadServiceDialogFragment.java index 7af04dfac..b9a26b730 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/fragments/ChooseUploadServiceDialogFragment.java +++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/ChooseUploadServiceDialogFragment.java @@ -175,7 +175,7 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment { sendRequest.setSendMaps(mapsCheckBox.isChecked()); sendRequest.setSendFusionTables(fusionTablesCheckBox.isChecked()); sendRequest.setSendSpreadsheets(spreadsheetsCheckBox.isChecked()); - sendRequest.setNewMap(!existingMapRadioButton.isChecked()); + sendRequest.setMapsExistingMap(existingMapRadioButton.isChecked()); sendStats(); Intent intent = IntentUtils.newIntent(activity, AccountChooserActivity.class) .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/drive/SendDriveActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/drive/SendDriveActivity.java index 3ab5726e2..270791944 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/drive/SendDriveActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/drive/SendDriveActivity.java @@ -62,7 +62,7 @@ public class SendDriveActivity extends AbstractSendActivity { return UploadResultActivity.class; } else { if (sendRequest.isSendMaps()) { - return sendRequest.isNewMap() ? SendMapsActivity.class : ChooseMapActivity.class; + return sendRequest.isMapsExistingMap() ? ChooseMapActivity.class : SendMapsActivity.class; } else if (sendRequest.isSendFusionTables()) { return SendFusionTablesActivity.class; } else if (sendRequest.isSendSpreadsheets()) { diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/maps/ChooseMapActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/maps/ChooseMapActivity.java index 815830e81..e50f74869 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/maps/ChooseMapActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/maps/ChooseMapActivity.java @@ -209,7 +209,7 @@ public class ChooseMapActivity extends Activity { * @param mapId the chosen map id */ private void startNextActivity(String mapId) { - sendRequest.setMapId(mapId); + sendRequest.setMapsExistingMapId(mapId); Intent intent = IntentUtils.newIntent(this, SendMapsActivity.class) .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); startActivity(intent); diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsActivity.java index 65db21053..7dee7ef39 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsActivity.java @@ -37,7 +37,7 @@ public class SendMapsActivity extends AbstractSendActivity { @Override protected AbstractSendAsyncTask createAsyncTask() { return new SendMapsAsyncTask( - this, sendRequest.getTrackId(), sendRequest.getAccount(), sendRequest.getMapId()); + this, sendRequest.getTrackId(), sendRequest.getAccount(), sendRequest.getMapsExistingMapId()); } @Override diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/AccountChooserActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/AccountChooserActivity.java index fc6249240..264a9a17b 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/AccountChooserActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/AccountChooserActivity.java @@ -21,6 +21,8 @@ import com.google.android.apps.mytracks.fragments.AddEmailsDialogFragment; import com.google.android.apps.mytracks.fragments.AddEmailsDialogFragment.AddEmailsCaller; import com.google.android.apps.mytracks.fragments.ChooseAccountDialogFragment; import com.google.android.apps.mytracks.fragments.ChooseAccountDialogFragment.ChooseAccountCaller; +import com.google.android.apps.mytracks.fragments.ChooseActivityDialogFragment; +import com.google.android.apps.mytracks.fragments.ChooseActivityDialogFragment.ChooseActivityCaller; import com.google.android.apps.mytracks.io.drive.SendDriveActivity; import com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesActivity; import com.google.android.apps.mytracks.io.gdata.maps.MapsConstants; @@ -52,7 +54,7 @@ import java.io.IOException; * @author Jimmy Shih */ public class AccountChooserActivity extends FragmentActivity - implements ChooseAccountCaller, AddEmailsCaller { + implements ChooseAccountCaller, AddEmailsCaller, ChooseActivityCaller { private static final String TAG = AccountChooserActivity.class.getSimpleName(); @@ -121,6 +123,19 @@ public class AccountChooserActivity extends FragmentActivity finish(); } + @Override + public void onChooseActivityDone(String packageName, String className) { + if (packageName != null && className != null) { + sendRequest.setMapsSharePackageName(packageName); + sendRequest.setMapsShareClassName(className); + Intent intent = IntentUtils.newIntent( + this, sendRequest.isMapsExistingMap() ? ChooseMapActivity.class : SendMapsActivity.class) + .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); + startActivity(intent); + } + finish(); + } + /** * Checks the Drive permission. */ @@ -284,7 +299,12 @@ public class AccountChooserActivity extends FragmentActivity next = SendDriveActivity.class; } } else if (sendRequest.isSendMaps()) { - next = sendRequest.isNewMap() ? SendMapsActivity.class : ChooseMapActivity.class; + if (sendRequest.isMapsShare()) { + new ChooseActivityDialogFragment().show( + getSupportFragmentManager(), ChooseActivityDialogFragment.CHOOSE_ACTIVITY_DIALOG_TAG); + return; + } + next = sendRequest.isMapsExistingMap() ? ChooseMapActivity.class : SendMapsActivity.class; } else if (sendRequest.isSendFusionTables()) { next = SendFusionTablesActivity.class; } else if (sendRequest.isSendSpreadsheets()) { diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/SendRequest.java b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/SendRequest.java index 2731c1cad..eb03bb61f 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/SendRequest.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/SendRequest.java @@ -21,8 +21,8 @@ import android.os.Parcel; import android.os.Parcelable; /** - * Send request states for sending a track to Google Maps, Google Fusion Tables, - * and Google Spreadsheets. + * Send request states for sending a track to Google Drive, Google Maps, Google + * Fusion Tables, and Google Spreadsheets. * * @author Jimmy Shih */ @@ -31,17 +31,22 @@ public class SendRequest implements Parcelable { public static final String SEND_REQUEST_KEY = "sendRequest"; private long trackId = -1L; - private String sharingAppPackageName = null; - private String sharingAppClassName = null; private boolean sendDrive = false; private boolean sendMaps = false; private boolean sendFusionTables = false; private boolean sendSpreadsheets = false; + private boolean driveShare = false; private String driveShareEmails = null; - private boolean newMap = false; + + private boolean mapsShare = false; + private String mapsSharePackageName = null; + private String mapsShareClassName = null; + private boolean mapsExistingMap = false; + private String mapsExistingMapId = null; + private Account account = null; - private String mapId = null; + private boolean driveSuccess = false; private boolean mapsSuccess = false; private boolean spreadsheetsSuccess = false; @@ -56,109 +61,38 @@ public class SendRequest implements Parcelable { this.trackId = trackId; } - /** - * Get the track id. - */ public long getTrackId() { return trackId; } - /** - * Gets the sharing app package name. - */ - public String getSharingAppPackageName() { - return sharingAppPackageName; - } - - /** - * Sets the sharing app package name. - * - * @param sharingAppPackageName the sharing app package name - */ - public void setSharingAppPackageName(String sharingAppPackageName) { - this.sharingAppPackageName = sharingAppPackageName; - } - - /** - * Gets the sharing app class name. - */ - public String getSharingAppClassName() { - return sharingAppClassName; - } - - /** - * Sets the sharing app class name. - * - * @param sharingAppClassName the sharing app class name - */ - public void setSharingAppClassName(String sharingAppClassName) { - this.sharingAppClassName = sharingAppClassName; - } - - /** - * True if the user has selected the send to Google Drive option. - */ public boolean isSendDrive() { return sendDrive; } - /** - * Sets the send to Google Drive option. - * - * @param sendDrive true if the user has selected the send to Google Drive - * option - */ public void setSendDrive(boolean sendDrive) { this.sendDrive = sendDrive; } - /** - * 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 Spreadsheets option. - */ public boolean isSendSpreadsheets() { return sendSpreadsheets; } - /** - * Sets the send to Google Spreadsheets option. - * - * @param sendSpreadsheets true if the user has selected the send to Google - * Spreadsheets option - */ public void setSendSpreadsheets(boolean sendSpreadsheets) { this.sendSpreadsheets = sendSpreadsheets; } @@ -166,147 +100,113 @@ public class SendRequest implements Parcelable { public boolean isDriveShare() { return driveShare; } - + public void setDriveShare(boolean driveShare) { this.driveShare = driveShare; } - + public String getDriveShareEmails() { return driveShareEmails; } - + public void setDriveShareEmails(String driveShareEmails) { this.driveShareEmails = driveShareEmails; } - - /** - * True if the user has selected to create a new Google Maps. - */ - public boolean isNewMap() { - return newMap; + + public boolean isMapsShare() { + return mapsShare; } - /** - * 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; + public void setMapsShare(boolean mapsShare) { + this.mapsShare = mapsShare; + } + + public String getMapsSharePackageName() { + return mapsSharePackageName; + } + + public void setMapsSharePackageName(String mapsSharePackageName) { + this.mapsSharePackageName = mapsSharePackageName; + } + + public String getMapsShareClassName() { + return mapsShareClassName; + } + + public void setMapsShareClassName(String mapsShareClassName) { + this.mapsShareClassName = mapsShareClassName; + } + + public boolean isMapsExistingMap() { + return mapsExistingMap; + } + + public void setMapsExistingMap(boolean mapsExistingMap) { + this.mapsExistingMap = mapsExistingMap; + } + + public String getMapsExistingMapId() { + return mapsExistingMapId; + } + + public void setMapsExistingMapId(String mapsExistingMapId) { + this.mapsExistingMapId = mapsExistingMapId; } - /** - * 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 Drive is success. - */ public boolean isDriveSuccess() { return driveSuccess; } - /** - * Sets the Google Drive result. - * - * @param driveSuccess true if sending to Google Drive is success - */ public void setDriveSuccess(boolean driveSuccess) { this.driveSuccess = driveSuccess; } - /** - * 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 Spreadsheets is success. - */ public boolean isSpreadsheetsSuccess() { return spreadsheetsSuccess; } - /** - * Sets the Google Spreadsheets result. - * - * @param spreadsheetsSuccess true if sending to Google Spreadsheets is - * success - */ - public void setSpreadsheetSuccess(boolean spreadsheetsSuccess) { + public void setSpreadsheetsSuccess(boolean spreadsheetsSuccess) { this.spreadsheetsSuccess = spreadsheetsSuccess; } private SendRequest(Parcel in) { trackId = in.readLong(); - sharingAppPackageName = in.readString(); - sharingAppClassName = in.readString(); sendDrive = in.readByte() == 1; sendMaps = in.readByte() == 1; sendFusionTables = in.readByte() == 1; sendSpreadsheets = in.readByte() == 1; driveShare = in.readByte() == 1; driveShareEmails = in.readString(); - newMap = in.readByte() == 1; + mapsShare = in.readByte() == 1; + mapsSharePackageName = in.readString(); + mapsShareClassName = in.readString(); + mapsExistingMap = in.readByte() == 1; + mapsExistingMapId = in.readString(); account = in.readParcelable(null); - mapId = in.readString(); driveSuccess = in.readByte() == 1; mapsSuccess = in.readByte() == 1; fusionTablesSuccess = in.readByte() == 1; @@ -321,17 +221,18 @@ public class SendRequest implements Parcelable { @Override public void writeToParcel(Parcel out, int flags) { out.writeLong(trackId); - out.writeString(sharingAppPackageName); - out.writeString(sharingAppClassName); out.writeByte((byte) (sendDrive ? 1 : 0)); out.writeByte((byte) (sendMaps ? 1 : 0)); out.writeByte((byte) (sendFusionTables ? 1 : 0)); out.writeByte((byte) (sendSpreadsheets ? 1 : 0)); out.writeByte((byte) (driveShare ? 1 : 0)); out.writeString(driveShareEmails); - out.writeByte((byte) (newMap ? 1 : 0)); + out.writeByte((byte) (mapsShare ? 1 : 0)); + out.writeString(mapsSharePackageName); + out.writeString(mapsShareClassName); + out.writeByte((byte) (mapsExistingMap ? 1 : 0)); + out.writeString(mapsExistingMapId); out.writeParcelable(account, 0); - out.writeString(mapId); out.writeByte((byte) (driveSuccess ? 1 : 0)); out.writeByte((byte) (mapsSuccess ? 1 : 0)); out.writeByte((byte) (fusionTablesSuccess ? 1 : 0)); diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadResultActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadResultActivity.java index 4efe8b8f1..7ce4f8136 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadResultActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadResultActivity.java @@ -19,6 +19,7 @@ package com.google.android.apps.mytracks.io.sendtogoogle; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.fragments.ChooseActivityDialogFragment; +import com.google.android.apps.mytracks.fragments.ChooseActivityDialogFragment.ChooseActivityCaller; import com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesUtils; import com.google.android.apps.mytracks.io.maps.SendMapsUtils; import com.google.android.apps.mytracks.util.IntentUtils; @@ -43,7 +44,7 @@ import android.widget.TextView; * * @author Jimmy Shih */ -public class UploadResultActivity extends FragmentActivity { +public class UploadResultActivity extends FragmentActivity implements ChooseActivityCaller { private static final String TAG = UploadResultActivity.class.getSimpleName(); @VisibleForTesting @@ -70,9 +71,9 @@ public class UploadResultActivity extends FragmentActivity { if (sendRequest.isSendMaps() && sendRequest.isMapsSuccess()) { shareUrl = SendMapsUtils.getMapUrl(track); - if (sendRequest.getSharingAppPackageName() != null) { + if (sendRequest.getMapsSharePackageName() != null) { Intent intent = IntentUtils.newShareUrlIntent(this, sendRequest.getTrackId(), shareUrl, - sendRequest.getSharingAppPackageName(), sendRequest.getSharingAppClassName()); + sendRequest.getMapsSharePackageName(), sendRequest.getMapsShareClassName()); startActivity(intent); finish(); return; @@ -181,8 +182,7 @@ public class UploadResultActivity extends FragmentActivity { R.string.share_track_share_url, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - ChooseActivityDialogFragment.newInstance(sendRequest.getTrackId(), shareUrl).show( - getSupportFragmentManager(), + new ChooseActivityDialogFragment().show(getSupportFragmentManager(), ChooseActivityDialogFragment.CHOOSE_ACTIVITY_DIALOG_TAG); } }); @@ -190,4 +190,14 @@ public class UploadResultActivity extends FragmentActivity { resultDialog = builder.create(); return resultDialog; } + + @Override + public void onChooseActivityDone(String packageName, String className) { + if (packageName != null && className != null) { + Intent intent = IntentUtils.newShareUrlIntent( + this, sendRequest.getTrackId(), shareUrl, packageName, className); + startActivity(intent); + } + finish(); + } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/spreadsheets/SendSpreadsheetsActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/spreadsheets/SendSpreadsheetsActivity.java index c8e88ea4e..6fa0acb6b 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/spreadsheets/SendSpreadsheetsActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/spreadsheets/SendSpreadsheetsActivity.java @@ -44,7 +44,7 @@ public class SendSpreadsheetsActivity extends AbstractSendActivity { @Override protected void startNextActivity(boolean success, boolean isCancel) { - sendRequest.setSpreadsheetSuccess(success); + sendRequest.setSpreadsheetsSuccess(success); Intent intent = IntentUtils.newIntent(this, UploadResultActivity.class) .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); startActivity(intent); diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTaskTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTaskTest.java index 05930134c..a8793780d 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTaskTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTaskTest.java @@ -102,10 +102,10 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase { AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock); SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock, - sendRequest.getTrackId(), sendRequest.getAccount(), sendRequest.getMapId(), + sendRequest.getTrackId(), sendRequest.getAccount(), sendRequest.getMapsExistingMapId(), myTracksProviderUtilsMock); sendMapsAsyncTask.saveResult(); - assertEquals(sendRequest.getMapId(), track.getMapId()); + assertEquals(sendRequest.getMapsExistingMapId(), track.getMapId()); AndroidMock.verify(sendMapsActivityMock, myTracksProviderUtilsMock); } diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/io/sendtogoogle/SendRequestTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/io/sendtogoogle/SendRequestTest.java index 7447e3e38..bdd38df82 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/io/sendtogoogle/SendRequestTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/io/sendtogoogle/SendRequestTest.java @@ -29,13 +29,13 @@ public class SendRequestTest extends AndroidTestCase { private SendRequest sendRequest; - private static final String SHARING_APP_PACKAGE_NAME = "package"; - private static final String SHARING_APP_CLASS_NAME = "class"; + private static final String MAPS_SHARE_PACKAGE_NAME = "package"; + private static final String MAPS_SHARE_CLASS_NAME = "class"; private final static String ACCOUNTNAME = "testAccount1"; private final static String ACCOUNTYPE = "testType1"; - private final static String MAPID = "mapId1"; + private final static String MAPS_EXISTING_MAP_ID = "mapId1"; private final static String DRIVE_SHARE_EMAILS = "foo@foo.com"; - + @Override protected void setUp() throws Exception { super.setUp(); @@ -63,8 +63,9 @@ public class SendRequestTest extends AndroidTestCase { } /** - * Tests the method {@link SendRequest#isSendSpreadsheets()}. The value should be set - * to false which is its default value when it is initialed in setup method. + * Tests the method {@link SendRequest#isSendSpreadsheets()}. The value should + * be set to false which is its default value when it is initialed in setup + * method. */ public void testIsSendSpreadsheets() { assertEquals(false, sendRequest.isSendSpreadsheets()); @@ -73,13 +74,14 @@ public class SendRequestTest extends AndroidTestCase { } /** - * Tests the method {@link SendRequest#isNewMap()}. The value should be set to - * false which is its default value when it is initialed in setup method. + * Tests the method {@link SendRequest#isMapsExistingMap()}. The value should + * be set to false which is its default value when it is initialed in setup + * method. */ public void testIsNewMap() { - assertEquals(false, sendRequest.isNewMap()); - sendRequest.setNewMap(true); - assertEquals(true, sendRequest.isNewMap()); + assertEquals(false, sendRequest.isMapsExistingMap()); + sendRequest.setMapsExistingMap(true); + assertEquals(true, sendRequest.isMapsExistingMap()); } /** @@ -94,12 +96,13 @@ public class SendRequestTest extends AndroidTestCase { } /** - * Tests the method {@link SendRequest#getMapId()}. The value should be set to - * null which is its default value when it is initialed in setup method. + * Tests the method {@link SendRequest#getMapsExistingMapId()}. The value + * should be set to null which is its default value when it is initialed in + * setup method. */ - public void testGetMapId() { - assertEquals(null, sendRequest.getMapId()); - sendRequest.setMapId("1"); + public void testGetMapsExistingMapId() { + assertEquals(null, sendRequest.getMapsExistingMapId()); + sendRequest.setMapsExistingMapId("1"); assertEquals("1", "1"); } @@ -126,13 +129,13 @@ public class SendRequestTest extends AndroidTestCase { } /** - * Tests the method {@link SendRequest#isSpreadsheetsSuccess()}. The value should be - * set to false which is its default value when it is initialed in setup - * method. + * Tests the method {@link SendRequest#isSpreadsheetsSuccess()}. The value + * should be set to false which is its default value when it is initialed in + * setup method. */ public void testIsSpreadsheetsSuccess() { assertEquals(false, sendRequest.isSpreadsheetsSuccess()); - sendRequest.setSpreadsheetSuccess(true); + sendRequest.setSpreadsheetsSuccess(true); assertEquals(true, sendRequest.isSpreadsheetsSuccess()); } @@ -143,8 +146,6 @@ public class SendRequestTest extends AndroidTestCase { Parcel parcel = Parcel.obtain(); parcel.setDataPosition(0); parcel.writeLong(2); - parcel.writeString(""); - parcel.writeString(""); parcel.writeByte((byte) 1); parcel.writeByte((byte) 1); parcel.writeByte((byte) 1); @@ -152,9 +153,12 @@ public class SendRequestTest extends AndroidTestCase { parcel.writeByte((byte) 1); parcel.writeString(DRIVE_SHARE_EMAILS); parcel.writeByte((byte) 1); + parcel.writeString(""); + parcel.writeString(""); + parcel.writeByte((byte) 1); + parcel.writeString(MAPS_EXISTING_MAP_ID); Account account = new Account(ACCOUNTNAME, ACCOUNTYPE); parcel.writeParcelable(account, 0); - parcel.writeString(MAPID); parcel.writeByte((byte) 1); parcel.writeByte((byte) 1); parcel.writeByte((byte) 1); @@ -162,17 +166,18 @@ public class SendRequestTest extends AndroidTestCase { parcel.setDataPosition(0); sendRequest = SendRequest.CREATOR.createFromParcel(parcel); assertEquals(2, sendRequest.getTrackId()); - assertEquals("", sendRequest.getSharingAppPackageName()); - assertEquals("", sendRequest.getSharingAppClassName()); assertTrue(sendRequest.isSendDrive()); assertTrue(sendRequest.isSendMaps()); assertTrue(sendRequest.isSendFusionTables()); assertTrue(sendRequest.isSendSpreadsheets()); assertTrue(sendRequest.isDriveShare()); assertEquals(DRIVE_SHARE_EMAILS, sendRequest.getDriveShareEmails()); - assertTrue(sendRequest.isNewMap()); + assertTrue(sendRequest.isMapsShare()); + assertEquals("", sendRequest.getMapsSharePackageName()); + assertEquals("", sendRequest.getMapsShareClassName()); + assertTrue(sendRequest.isMapsExistingMap()); + assertEquals(MAPS_EXISTING_MAP_ID, sendRequest.getMapsExistingMapId()); assertEquals(account, sendRequest.getAccount()); - assertEquals(MAPID, sendRequest.getMapId()); assertTrue(sendRequest.isDriveSuccess()); assertTrue(sendRequest.isMapsSuccess()); assertTrue(sendRequest.isFusionTablesSuccess()); @@ -186,8 +191,6 @@ public class SendRequestTest extends AndroidTestCase { Parcel parcel = Parcel.obtain(); parcel.setDataPosition(0); parcel.writeLong(4); - parcel.writeString(null); - parcel.writeString(null); parcel.writeByte((byte) 0); parcel.writeByte((byte) 0); parcel.writeByte((byte) 0); @@ -195,9 +198,12 @@ public class SendRequestTest extends AndroidTestCase { parcel.writeByte((byte) 0); parcel.writeString(null); parcel.writeByte((byte) 0); + parcel.writeString(null); + parcel.writeString(null); + parcel.writeByte((byte) 0); + parcel.writeString(MAPS_EXISTING_MAP_ID); Account account = new Account(ACCOUNTNAME, ACCOUNTYPE); parcel.writeParcelable(account, 0); - parcel.writeString(MAPID); parcel.writeByte((byte) 0); parcel.writeByte((byte) 0); parcel.writeByte((byte) 0); @@ -205,17 +211,18 @@ public class SendRequestTest extends AndroidTestCase { parcel.setDataPosition(0); sendRequest = SendRequest.CREATOR.createFromParcel(parcel); assertEquals(4, sendRequest.getTrackId()); - assertNull(sendRequest.getSharingAppPackageName()); - assertNull(sendRequest.getSharingAppClassName()); assertFalse(sendRequest.isSendDrive()); assertFalse(sendRequest.isSendMaps()); assertFalse(sendRequest.isSendFusionTables()); assertFalse(sendRequest.isSendSpreadsheets()); assertFalse(sendRequest.isDriveShare()); assertNull(sendRequest.getDriveShareEmails()); - assertFalse(sendRequest.isNewMap()); + assertFalse(sendRequest.isMapsShare()); + assertNull(sendRequest.getMapsSharePackageName()); + assertNull(sendRequest.getMapsShareClassName()); + assertFalse(sendRequest.isMapsExistingMap()); + assertEquals(MAPS_EXISTING_MAP_ID, sendRequest.getMapsExistingMapId()); assertEquals(account, sendRequest.getAccount()); - assertEquals(MAPID, sendRequest.getMapId()); assertFalse(sendRequest.isDriveSuccess()); assertFalse(sendRequest.isMapsSuccess()); assertFalse(sendRequest.isFusionTablesSuccess()); @@ -232,33 +239,35 @@ public class SendRequestTest extends AndroidTestCase { sendRequest.writeToParcel(parcel, 1); parcel.setDataPosition(0); long trackId = parcel.readLong(); - String sharingAppPackageName = parcel.readString(); - String sharingAppClassName = parcel.readString(); boolean sendDrive = parcel.readByte() == 1; boolean sendMaps = parcel.readByte() == 1; boolean sendFusionTables = parcel.readByte() == 1; boolean sendSpreadsheets = parcel.readByte() == 1; boolean driveShare = parcel.readByte() == 1; String dirveShareEmails = parcel.readString(); - boolean newMap = parcel.readByte() == 1; + boolean mapsShare = parcel.readByte() == 1; + String mapsSharePackageName = parcel.readString(); + String mapsShareClassName = parcel.readString(); + boolean mapsExistingMap = parcel.readByte() == 1; + String mapsExistingMapId = parcel.readString(); Parcelable account = parcel.readParcelable(null); - String mapId = parcel.readString(); boolean driveSuccess = parcel.readByte() == 1; boolean mapsSuccess = parcel.readByte() == 1; boolean fusionTablesSuccess = parcel.readByte() == 1; boolean spreadsheetsSuccess = parcel.readByte() == 1; assertEquals(1, trackId); - assertNull(sharingAppPackageName); - assertNull(sharingAppClassName); assertFalse(sendDrive); assertFalse(sendMaps); assertFalse(sendFusionTables); assertFalse(sendSpreadsheets); assertFalse(driveShare); assertNull(dirveShareEmails); - assertFalse(newMap); + assertFalse(mapsShare); + assertNull(mapsSharePackageName); + assertNull(mapsShareClassName); + assertFalse(mapsExistingMap); + assertNull(mapsExistingMapId); assertNull(account); - assertNull(mapId); assertFalse(driveSuccess); assertFalse(mapsSuccess); assertFalse(fusionTablesSuccess); @@ -270,54 +279,57 @@ public class SendRequestTest extends AndroidTestCase { */ public void testWriteToParcel() { sendRequest = new SendRequest(4); - sendRequest.setSharingAppPackageName(SHARING_APP_PACKAGE_NAME); - sendRequest.setSharingAppClassName(SHARING_APP_CLASS_NAME); sendRequest.setSendDrive(true); sendRequest.setSendMaps(true); sendRequest.setSendFusionTables(true); sendRequest.setSendSpreadsheets(true); sendRequest.setDriveShare(true); sendRequest.setDriveShareEmails(DRIVE_SHARE_EMAILS); - sendRequest.setNewMap(true); + sendRequest.setMapsShare(true); + sendRequest.setMapsSharePackageName(MAPS_SHARE_PACKAGE_NAME); + sendRequest.setMapsShareClassName(MAPS_SHARE_CLASS_NAME); + sendRequest.setMapsExistingMap(true); + sendRequest.setMapsExistingMapId(MAPS_EXISTING_MAP_ID); Account accountNew = new Account(ACCOUNTNAME + "2", ACCOUNTYPE + "2"); sendRequest.setAccount(accountNew); - sendRequest.setMapId(MAPID); sendRequest.setMapsSuccess(true); sendRequest.setDriveSuccess(true); sendRequest.setFusionTablesSuccess(true); - sendRequest.setSpreadsheetSuccess(true); + sendRequest.setSpreadsheetsSuccess(true); Parcel parcel = Parcel.obtain(); parcel.setDataPosition(0); sendRequest.writeToParcel(parcel, 1); parcel.setDataPosition(0); long trackId = parcel.readLong(); - String sharingAppPackageName = parcel.readString(); - String sharingAppClassName = parcel.readString(); boolean sendDrive = parcel.readByte() == 1; boolean sendMaps = parcel.readByte() == 1; boolean sendFusionTables = parcel.readByte() == 1; boolean sendSpreadsheets = parcel.readByte() == 1; boolean shareDrive = parcel.readByte() == 1; String driveShareEmails = parcel.readString(); - boolean newMap = parcel.readByte() == 1; + boolean mapsShare = parcel.readByte() == 1; + String mapsSharePackageName = parcel.readString(); + String mapsShareClassName = parcel.readString(); + boolean mapsExistingMap = parcel.readByte() == 1; + String mapsExistingMapId = parcel.readString(); Parcelable account = parcel.readParcelable(null); - String mapId = parcel.readString(); boolean driveSuccess = parcel.readByte() == 1; boolean mapsSuccess = parcel.readByte() == 1; boolean fusionTablesSuccess = parcel.readByte() == 1; boolean spreadsheetsSuccess = parcel.readByte() == 1; assertEquals(4, trackId); - assertEquals(SHARING_APP_PACKAGE_NAME, sharingAppPackageName); - assertEquals(SHARING_APP_CLASS_NAME, sharingAppClassName); assertTrue(sendDrive); assertTrue(sendMaps); assertTrue(sendFusionTables); assertTrue(sendSpreadsheets); assertTrue(shareDrive); assertEquals(DRIVE_SHARE_EMAILS, driveShareEmails); - assertTrue(newMap); + assertTrue(mapsShare); + assertEquals(MAPS_SHARE_PACKAGE_NAME, mapsSharePackageName); + assertEquals(MAPS_SHARE_CLASS_NAME, mapsShareClassName); + assertTrue(mapsExistingMap); + assertEquals(MAPS_EXISTING_MAP_ID, mapsExistingMapId); assertEquals(accountNew, account); - assertEquals(MAPID, mapId); assertTrue(driveSuccess); assertTrue(mapsSuccess); assertTrue(fusionTablesSuccess); diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadResultActivityTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadResultActivityTest.java index 858b9fbd5..32d20b21b 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadResultActivityTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/io/sendtogoogle/UploadResultActivityTest.java @@ -130,7 +130,7 @@ public class UploadResultActivityTest extends sendRequest.setSendSpreadsheets(isSendSpreadsheets); sendRequest.setMapsSuccess(isMapsSuccess); sendRequest.setFusionTablesSuccess(isFusionTablesSuccess); - sendRequest.setSpreadsheetSuccess(isSpreadsheetSuccess); + sendRequest.setSpreadsheetsSuccess(isSpreadsheetSuccess); intent.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest); setActivityIntent(intent); uploadResultActivity = this.getActivity();