Add menu option to Sync to Google Drive.

This commit is contained in:
Jimmy Shih
2013-06-24 14:09:25 -07:00
parent 176b2b05d3
commit 2d4cabf4ef
13 changed files with 250 additions and 129 deletions
+19 -23
View File
@@ -1184,6 +1184,12 @@ limitations under the License.
Character limit: ~20 (1 line)"> Character limit: ~20 (1 line)">
Share Share
</string> </string>
<string name="menu_sync_drive"
translation_description="In the menu, to sync to Google Drive.
Character limit: ~20 (1 line)">
Sync to Google Drive
</string>
<string name="menu_show_on_map" <string name="menu_show_on_map"
translation_description="In the menu, to show a track or a marker on the map. translation_description="In the menu, to show a track or a marker on the map.
@@ -1581,15 +1587,6 @@ limitations under the License.
Character limit: ~23 (1 line)"> Character limit: ~23 (1 line)">
Switch account Switch account
</string> </string>
<string name="settings_google_drive_sync_confirm_message"
translation_description="In the 'Accounts and sync' settings, the confirmation message when
checking the 'Sync to Google Drive' checkbox.
%1$s account name. E.g., 'foo@foo.com'.
%2$s folder name. E.g., 'My Tracks'.">
All files in the %1$s Google Drive &#8216;%2$s&#8217; folder will be imported as new tracks. If
not desired, move the files to a different folder beforehand.
</string>
<string name="settings_google_drive_sync_summary_on" <string name="settings_google_drive_sync_summary_on"
translation_description="In the 'Accounts and sync' settings, the summary for the 'Sync to translation_description="In the 'Accounts and sync' settings, the summary for the 'Sync to
Google Drive' checkbox when it is checked explaining that all tracks will be synced to a Google Drive' checkbox when it is checked explaining that all tracks will be synced to a
@@ -1598,13 +1595,6 @@ limitations under the License.
%1$s account name. E.g., 'foo@foo.com'."> %1$s account name. E.g., 'foo@foo.com'.">
All tracks will be synced to %1$s Google Drive All tracks will be synced to %1$s Google Drive
</string> </string>
<string name="settings_google_drive_sync_title"
translation_description="In the 'Accounts and sync' settings, the checkbox to sync tracks with
Google Drive.
Character limit: ~23 (1 line)">
Sync to Google Drive
</string>
<!-- Settings Map --> <!-- Settings Map -->
<string name="settings_map_medium" <string name="settings_map_medium"
@@ -2164,16 +2154,22 @@ limitations under the License.
Total time Total time
</string> </string>
<!-- Sync --> <!-- Sync Drive -->
<string name="sync_enable_message" <string name="sync_drive_confirm_message"
translation_description="The dialog message asking the user if he wants to enable sync with translation_description="The dialog message to confirm sync to Google Drive.
Google Drive.">
%1$s account name. E.g., 'foo@foo.com'.
%2$s folder name. E.g., 'My Tracks'.">
All files in the %1$s Google Drive &#8216;%2$s&#8217; folder will be imported as new tracks. If
not desired, move the files to a different folder beforehand.
</string>
<string name="sync_drive_enable_message"
translation_description="The dialog message to enable sync to Google Drive.">
This will allow you to view your tracks in Google Drive and view the tracks shared with you. All This will allow you to view your tracks in Google Drive and view the tracks shared with you. All
tracks synced to Google Drive will be private by default. tracks synced to Google Drive will be private by default.
</string> </string>
<string name="sync_enable_title" <string name="sync_drive_title"
translation_description="The dialog title asking the user if he wants to enable sync with Google translation_description="The dialog title to sync to Google Drive.">
Drive.">
Sync with Google Drive? Sync with Google Drive?
</string> </string>
+1 -1
View File
@@ -23,5 +23,5 @@ limitations under the License.
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/drive_sync_key" android:key="@string/drive_sync_key"
android:title="@string/settings_google_drive_sync_title" /> android:title="@string/menu_sync_drive" />
</PreferenceScreen> </PreferenceScreen>
@@ -22,6 +22,8 @@ import com.google.android.apps.mytracks.fragments.ChooseAccountDialogFragment;
import com.google.android.apps.mytracks.fragments.ChooseAccountDialogFragment.ChooseAccountCaller; import com.google.android.apps.mytracks.fragments.ChooseAccountDialogFragment.ChooseAccountCaller;
import com.google.android.apps.mytracks.fragments.ConfirmDialogFragment; import com.google.android.apps.mytracks.fragments.ConfirmDialogFragment;
import com.google.android.apps.mytracks.fragments.ConfirmDialogFragment.ConfirmCaller; import com.google.android.apps.mytracks.fragments.ConfirmDialogFragment.ConfirmCaller;
import com.google.android.apps.mytracks.fragments.ConfirmSyncDialogFragment;
import com.google.android.apps.mytracks.fragments.ConfirmSyncDialogFragment.ConfirmSyncCaller;
import com.google.android.apps.mytracks.fragments.InstallEarthDialogFragment; import com.google.android.apps.mytracks.fragments.InstallEarthDialogFragment;
import com.google.android.apps.mytracks.fragments.ShareTrackDialogFragment; import com.google.android.apps.mytracks.fragments.ShareTrackDialogFragment;
import com.google.android.apps.mytracks.fragments.ShareTrackDialogFragment.ShareTrackCaller; import com.google.android.apps.mytracks.fragments.ShareTrackDialogFragment.ShareTrackCaller;
@@ -65,7 +67,7 @@ import java.io.IOException;
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActivity implements public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActivity implements
ChooseAccountCaller, CheckPermissionCaller, ShareTrackCaller, ConfirmCaller { ChooseAccountCaller, ConfirmSyncCaller, CheckPermissionCaller, ShareTrackCaller, ConfirmCaller {
private static final String TAG = AbstractMyTracksActivity.class.getSimpleName(); private static final String TAG = AbstractMyTracksActivity.class.getSimpleName();
private static final String SEND_REQUEST_KEY = "send_request_key"; private static final String SEND_REQUEST_KEY = "send_request_key";
@@ -132,24 +134,36 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
} }
sendRequest.setAccount(new Account(googleAccount, Constants.ACCOUNT_TYPE)); sendRequest.setAccount(new Account(googleAccount, Constants.ACCOUNT_TYPE));
// Check Drive permission if (sendRequest.isSendDrive() && sendRequest.isDriveSync() && sendRequest.isDriveSyncConfirm()) {
boolean needDrivePermission = sendRequest.isSendDrive(); new ConfirmSyncDialogFragment().show(
if (!needDrivePermission && sendRequest.isSendFusionTables()) { getSupportFragmentManager(), ConfirmSyncDialogFragment.CONFIRM_SYNC_DIALOG_TAG);
needDrivePermission = PreferencesUtils.getBoolean(this,
R.string.export_google_fusion_tables_public_key,
PreferencesUtils.EXPORT_GOOGLE_FUSION_TABLES_PUBLIC_DEFAULT);
}
if (!needDrivePermission) {
needDrivePermission = sendRequest.isSendSpreadsheets();
}
if (needDrivePermission) {
Fragment fragment = CheckPermissionFragment.newInstance(
sendRequest.getAccount().name, SendToGoogleUtils.DRIVE_SCOPE);
getSupportFragmentManager()
.beginTransaction().add(fragment, CheckPermissionFragment.CHECK_PERMISSION_TAG).commit();
} else { } else {
onDrivePermissionSuccess(); onConfirmSyncDone(true);
}
}
@Override
public void onConfirmSyncDone(boolean enable) {
if (enable) {
// Check Drive permission
boolean needDrivePermission = sendRequest.isSendDrive();
if (!needDrivePermission && sendRequest.isSendFusionTables()) {
needDrivePermission = PreferencesUtils.getBoolean(this,
R.string.export_google_fusion_tables_public_key,
PreferencesUtils.EXPORT_GOOGLE_FUSION_TABLES_PUBLIC_DEFAULT);
}
if (!needDrivePermission) {
needDrivePermission = sendRequest.isSendSpreadsheets();
}
if (needDrivePermission) {
Fragment fragment = CheckPermissionFragment.newInstance(
sendRequest.getAccount().name, SendToGoogleUtils.DRIVE_SCOPE);
getSupportFragmentManager().beginTransaction()
.add(fragment, CheckPermissionFragment.CHECK_PERMISSION_TAG).commit();
} else {
onDrivePermissionSuccess();
}
} }
} }
@@ -19,10 +19,10 @@ package com.google.android.apps.mytracks;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.TracksColumns; import com.google.android.apps.mytracks.content.TracksColumns;
import com.google.android.apps.mytracks.fragments.ConfirmSyncDialogFragment;
import com.google.android.apps.mytracks.fragments.ConfirmSyncDialogFragment.ConfirmSyncCaller;
import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment; import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment.DeleteTrackCaller; import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment.DeleteTrackCaller;
import com.google.android.apps.mytracks.fragments.EnableSyncDialogFragment;
import com.google.android.apps.mytracks.fragments.EnableSyncDialogFragment.EnableSyncCaller;
import com.google.android.apps.mytracks.fragments.EulaDialogFragment; import com.google.android.apps.mytracks.fragments.EulaDialogFragment;
import com.google.android.apps.mytracks.fragments.EulaDialogFragment.EulaCaller; import com.google.android.apps.mytracks.fragments.EulaDialogFragment.EulaCaller;
import com.google.android.apps.mytracks.fragments.FileTypeDialogFragment; import com.google.android.apps.mytracks.fragments.FileTypeDialogFragment;
@@ -93,7 +93,7 @@ import java.util.Locale;
* @author Leif Hendrik Wilden * @author Leif Hendrik Wilden
*/ */
public class TrackListActivity extends AbstractSendToGoogleActivity public class TrackListActivity extends AbstractSendToGoogleActivity
implements EulaCaller, ConfirmSyncCaller, DeleteTrackCaller, FileTypeCaller { implements EulaCaller, EnableSyncCaller, DeleteTrackCaller, FileTypeCaller {
private static final String TAG = TrackListActivity.class.getSimpleName(); private static final String TAG = TrackListActivity.class.getSimpleName();
private static final int GOOGLE_PLAY_SERVICES_REQUEST_CODE = 0; private static final int GOOGLE_PLAY_SERVICES_REQUEST_CODE = 0;
@@ -293,10 +293,10 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
// Menu items // Menu items
private MenuItem searchMenuItem; private MenuItem searchMenuItem;
private MenuItem startGpsMenuItem; private MenuItem startGpsMenuItem;
private MenuItem importAllMenuItem;
private MenuItem exportAllMenuItem;
private MenuItem deleteAllMenuItem;
private MenuItem refreshMenuItem; private MenuItem refreshMenuItem;
private MenuItem exportAllMenuItem;
private MenuItem importAllMenuItem;
private MenuItem deleteAllMenuItem;
private MenuItem feedbackMenuItem; private MenuItem feedbackMenuItem;
private boolean startGps = false; // true to start gps private boolean startGps = false; // true to start gps
@@ -469,10 +469,10 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
searchMenuItem = menu.findItem(R.id.track_list_search); searchMenuItem = menu.findItem(R.id.track_list_search);
startGpsMenuItem = menu.findItem(R.id.track_list_start_gps); startGpsMenuItem = menu.findItem(R.id.track_list_start_gps);
importAllMenuItem = menu.findItem(R.id.track_list_import_all);
exportAllMenuItem = menu.findItem(R.id.track_list_export_all);
deleteAllMenuItem = menu.findItem(R.id.track_list_delete_all);
refreshMenuItem = menu.findItem(R.id.track_list_refresh); refreshMenuItem = menu.findItem(R.id.track_list_refresh);
exportAllMenuItem = menu.findItem(R.id.track_list_export_all);
importAllMenuItem = menu.findItem(R.id.track_list_import_all);
deleteAllMenuItem = menu.findItem(R.id.track_list_delete_all);
feedbackMenuItem = menu.findItem(R.id.track_list_feedback); feedbackMenuItem = menu.findItem(R.id.track_list_feedback);
feedbackMenuItem.setVisible(ApiAdapterFactory.getApiAdapter().isGoogleFeedbackAvailable()); feedbackMenuItem.setVisible(ApiAdapterFactory.getApiAdapter().isGoogleFeedbackAvailable());
@@ -533,27 +533,37 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
} }
myTracksLocationManager.close(); myTracksLocationManager.close();
return true; return true;
case R.id.track_list_import_all: case R.id.track_list_refresh:
FileTypeDialogFragment.newInstance(R.id.track_list_import_all, if (driveSync) {
R.string.import_selection_title, R.string.import_selection_option, 2) SyncUtils.syncNow(this);
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG); } else {
PreferencesUtils.setString(
this, R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
SendRequest sendRequest = new SendRequest(-1L);
sendRequest.setSendDrive(true);
sendRequest.setDriveSync(true);
sendRequest.setDriveSyncConfirm(true);
sendToGoogle(sendRequest);
}
return true;
case R.id.track_list_aggregated_statistics:
intent = IntentUtils.newIntent(this, AggregatedStatsActivity.class);
startActivity(intent);
return true; return true;
case R.id.track_list_export_all: case R.id.track_list_export_all:
FileTypeDialogFragment.newInstance(R.id.track_list_export_all, FileTypeDialogFragment.newInstance(R.id.track_list_export_all,
R.string.export_all_title, R.string.export_all_option, 4) R.string.export_all_title, R.string.export_all_option, 4)
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG); .show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
return true; return true;
case R.id.track_list_import_all:
FileTypeDialogFragment.newInstance(R.id.track_list_import_all,
R.string.import_selection_title, R.string.import_selection_option, 2)
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
return true;
case R.id.track_list_delete_all: case R.id.track_list_delete_all:
DeleteTrackDialogFragment.newInstance(true, new long[] {}) DeleteTrackDialogFragment.newInstance(true, new long[] {})
.show(getSupportFragmentManager(), DeleteTrackDialogFragment.DELETE_TRACK_DIALOG_TAG); .show(getSupportFragmentManager(), DeleteTrackDialogFragment.DELETE_TRACK_DIALOG_TAG);
return true; return true;
case R.id.track_list_aggregated_statistics:
intent = IntentUtils.newIntent(this, AggregatedStatsActivity.class);
startActivity(intent);
return true;
case R.id.track_list_refresh:
SyncUtils.syncNow(this);
return true;
case R.id.track_list_settings: case R.id.track_list_settings:
intent = IntentUtils.newIntent(this, SettingsActivity.class); intent = IntentUtils.newIntent(this, SettingsActivity.class);
startActivity(intent); startActivity(intent);
@@ -693,17 +703,16 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
private void showEnableSync() { private void showEnableSync() {
if (EulaUtils.getShowEnableSync(this)) { if (EulaUtils.getShowEnableSync(this)) {
Fragment fragment = getSupportFragmentManager() Fragment fragment = getSupportFragmentManager()
.findFragmentByTag(ConfirmSyncDialogFragment.CONFIRM_SYNC_DIALOG_TAG); .findFragmentByTag(EnableSyncDialogFragment.ENABLE_SYNC_DIALOG_TAG);
if (fragment == null) { if (fragment == null) {
ConfirmSyncDialogFragment.newInstance( new EnableSyncDialogFragment().show(
R.string.sync_enable_title, getString(R.string.sync_enable_message)) getSupportFragmentManager(), EnableSyncDialogFragment.ENABLE_SYNC_DIALOG_TAG);
.show(getSupportFragmentManager(), ConfirmSyncDialogFragment.CONFIRM_SYNC_DIALOG_TAG);
} }
} }
} }
@Override @Override
public void onConfirmSyncDone(boolean enable) { public void onEnableSyncDone(boolean enable) {
EulaUtils.setShowEnableSync(this); EulaUtils.setShowEnableSync(this);
if (enable) { if (enable) {
SendRequest sendRequest = new SendRequest(-1L); SendRequest sendRequest = new SendRequest(-1L);
@@ -728,18 +737,18 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
isGpsStarted ? R.drawable.menu_stop_gps : R.drawable.menu_start_gps); isGpsStarted ? R.drawable.menu_stop_gps : R.drawable.menu_start_gps);
} }
} }
if (importAllMenuItem != null) { if (refreshMenuItem != null) {
importAllMenuItem.setVisible(!isRecording); refreshMenuItem.setTitle(driveSync ? R.string.menu_refresh : R.string.menu_sync_drive);
} }
if (exportAllMenuItem != null) { if (exportAllMenuItem != null) {
exportAllMenuItem.setVisible(!isRecording); exportAllMenuItem.setVisible(!isRecording);
} }
if (importAllMenuItem != null) {
importAllMenuItem.setVisible(!isRecording);
}
if (deleteAllMenuItem != null) { if (deleteAllMenuItem != null) {
deleteAllMenuItem.setVisible(!isRecording); deleteAllMenuItem.setVisible(!isRecording);
} }
if (refreshMenuItem != null) {
refreshMenuItem.setVisible(driveSync);
}
} }
/** /**
@@ -50,22 +50,9 @@ public class ConfirmSyncDialogFragment extends DialogFragment {
public static final String CONFIRM_SYNC_DIALOG_TAG = "confirmSyncDialog"; public static final String CONFIRM_SYNC_DIALOG_TAG = "confirmSyncDialog";
private static final String KEY_TITLE_ID = "titleId";
private static final String KEY_MESSAGE = "message";
private ConfirmSyncCaller caller; private ConfirmSyncCaller caller;
private FragmentActivity fragmentActivity; private FragmentActivity fragmentActivity;
public static ConfirmSyncDialogFragment newInstance(int titleId, String message) {
Bundle bundle = new Bundle();
bundle.putInt(KEY_TITLE_ID, titleId);
bundle.putString(KEY_MESSAGE, message);
ConfirmSyncDialogFragment confirmSyncDialogFragment = new ConfirmSyncDialogFragment();
confirmSyncDialogFragment.setArguments(bundle);
return confirmSyncDialogFragment;
}
@Override @Override
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
super.onAttach(activity); super.onAttach(activity);
@@ -91,8 +78,10 @@ public class ConfirmSyncDialogFragment extends DialogFragment {
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
int titleId = getArguments().getInt(KEY_TITLE_ID); String googleAccount = PreferencesUtils.getString(
String message = getArguments().getString(KEY_MESSAGE); fragmentActivity, R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
String message = getString(
R.string.sync_drive_confirm_message, googleAccount, getString(R.string.my_tracks_app_name));
return new AlertDialog.Builder(fragmentActivity).setMessage(message) return new AlertDialog.Builder(fragmentActivity).setMessage(message)
.setNegativeButton(R.string.generic_no, new OnClickListener() { .setNegativeButton(R.string.generic_no, new OnClickListener() {
@Override @Override
@@ -104,7 +93,7 @@ public class ConfirmSyncDialogFragment extends DialogFragment {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
caller.onConfirmSyncDone(true); caller.onConfirmSyncDone(true);
} }
}).setTitle(titleId).create(); }).setTitle(R.string.sync_drive_title).create();
} }
@Override @Override
@@ -0,0 +1,99 @@
/*
* Copyright 2013 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.fragments;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
/**
* A DialogFrament to enable sync to Google Drive.
*
* @author Jimmy Shih
*/
public class EnableSyncDialogFragment extends DialogFragment {
/**
* Interface for caller of this dialog fragment.
*
* @author Jimmy Shih
*/
public interface EnableSyncCaller {
/**
* Called when enable sync is done.
*/
public void onEnableSyncDone(boolean enable);
}
public static final String ENABLE_SYNC_DIALOG_TAG = "enableSyncDialog";
private EnableSyncCaller caller;
private FragmentActivity fragmentActivity;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
caller = (EnableSyncCaller) activity;
} catch (ClassCastException e) {
throw new ClassCastException(
activity.toString() + " must implement " + EnableSyncCaller.class.getSimpleName());
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
fragmentActivity = getActivity();
if (PreferencesUtils.getBoolean(
fragmentActivity, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT)) {
dismiss();
caller.onEnableSyncDone(false);
return;
}
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(fragmentActivity).setMessage(R.string.sync_drive_enable_message)
.setNegativeButton(R.string.generic_no, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
caller.onEnableSyncDone(false);
}
}).setPositiveButton(R.string.generic_yes, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
caller.onEnableSyncDone(true);
}
}).setTitle(R.string.sync_drive_title).create();
}
@Override
public void onCancel(DialogInterface arg0) {
caller.onEnableSyncDone(false);
}
}
@@ -37,6 +37,7 @@ public class SendRequest implements Parcelable {
private boolean sendSpreadsheets = false; private boolean sendSpreadsheets = false;
private boolean driveSync = false; // to enable Drive sync private boolean driveSync = false; // to enable Drive sync
private boolean driveSyncConfirm = false;
private boolean driveShare = false; // to enable Drive share private boolean driveShare = false; // to enable Drive share
private String driveShareEmails = null; // for driveShare, emails to share private String driveShareEmails = null; // for driveShare, emails to share
private boolean driveSharePublic = false; // for driveShare, share as public private boolean driveSharePublic = false; // for driveShare, share as public
@@ -102,6 +103,14 @@ public class SendRequest implements Parcelable {
this.driveSync = driveSync; this.driveSync = driveSync;
} }
public boolean isDriveSyncConfirm() {
return driveSyncConfirm;
}
public void setDriveSyncConfirm(boolean driveSyncConfirm) {
this.driveSyncConfirm = driveSyncConfirm;
}
public boolean isDriveShare() { public boolean isDriveShare() {
return driveShare; return driveShare;
} }
@@ -181,6 +190,7 @@ public class SendRequest implements Parcelable {
sendFusionTables = in.readByte() == 1; sendFusionTables = in.readByte() == 1;
sendSpreadsheets = in.readByte() == 1; sendSpreadsheets = in.readByte() == 1;
driveSync = in.readByte() == 1; driveSync = in.readByte() == 1;
driveSyncConfirm = in.readByte() == 1;
driveShare = in.readByte() == 1; driveShare = in.readByte() == 1;
driveShareEmails = in.readString(); driveShareEmails = in.readString();
driveSharePublic = in.readByte() == 1; driveSharePublic = in.readByte() == 1;
@@ -205,6 +215,7 @@ public class SendRequest implements Parcelable {
out.writeByte((byte) (sendFusionTables ? 1 : 0)); out.writeByte((byte) (sendFusionTables ? 1 : 0));
out.writeByte((byte) (sendSpreadsheets ? 1 : 0)); out.writeByte((byte) (sendSpreadsheets ? 1 : 0));
out.writeByte((byte) (driveSync ? 1 : 0)); out.writeByte((byte) (driveSync ? 1 : 0));
out.writeByte((byte) (driveSyncConfirm ? 1 : 0));
out.writeByte((byte) (driveShare ? 1 : 0)); out.writeByte((byte) (driveShare ? 1 : 0));
out.writeString(driveShareEmails); out.writeString(driveShareEmails);
out.writeByte((byte) (driveSharePublic ? 1 : 0)); out.writeByte((byte) (driveSharePublic ? 1 : 0));
@@ -144,14 +144,12 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity {
this, R.string.settings_google_account_confirm_message, null); this, R.string.settings_google_account_confirm_message, null);
break; break;
case DIALOG_CONFIRM_DRIVE_SYNC_ON: case DIALOG_CONFIRM_DRIVE_SYNC_ON:
dialog = DialogUtils.createConfirmationDialog(this, dialog = DialogUtils.createConfirmationDialog(this, R.string.sync_drive_title,
R.string.settings_google_drive_sync_confirm_message, R.string.sync_drive_confirm_message, null, new DialogInterface.OnClickListener() {
new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface d, int button) { public void onClick(DialogInterface d, int button) {
final String googleAccount = PreferencesUtils.getString( final String googleAccount = PreferencesUtils.getString(GoogleSettingsActivity.this,
GoogleSettingsActivity.this, R.string.google_account_key, R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
/* /*
* This class, a PreferenceActivity, needs to support api level * This class, a PreferenceActivity, needs to support api level
* 8+, thus cannot use CheckPermissionFragment because a * 8+, thus cannot use CheckPermissionFragment because a
@@ -181,7 +179,7 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity {
}); });
thread.start(); thread.start();
} }
}); }, null);
break; break;
default: default:
dialog = null; dialog = null;
@@ -237,8 +235,7 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity {
}); });
break; break;
case DIALOG_CONFIRM_DRIVE_SYNC_ON: case DIALOG_CONFIRM_DRIVE_SYNC_ON:
alertDialog.setMessage(getString( alertDialog.setMessage(getString(R.string.sync_drive_confirm_message, googleAccount,
R.string.settings_google_drive_sync_confirm_message, googleAccount,
getString(R.string.my_tracks_app_name))); getString(R.string.my_tracks_app_name)));
break; break;
default: default:
@@ -43,27 +43,27 @@ public class DialogUtils {
*/ */
public static Dialog createConfirmationDialog( public static Dialog createConfirmationDialog(
Context context, int messageId, DialogInterface.OnClickListener okListener) { Context context, int messageId, DialogInterface.OnClickListener okListener) {
return createConfirmationDialog(context, messageId, null, okListener, null); return createConfirmationDialog(
context, R.string.generic_confirm_title, messageId, null, okListener, null);
} }
/** /**
* Creates a confirmation dialog. * Creates a confirmation dialog.
* *
* @param context the context * @param context the context
* @param titleId the titleId
* @param messageId the messageId * @param messageId the messageId
* @param view the view * @param view the view
* @param okListener the listener when OK is clicked * @param okListener the listener when OK is clicked
* @param cancelListener the listener when cancel is clicked * @param cancelListener the listener when cancel is clicked
*/ */
public static Dialog createConfirmationDialog( public static Dialog createConfirmationDialog(Context context, int titleId, int messageId,
Context context, int messageId, View view, DialogInterface.OnClickListener okListener, View view, DialogInterface.OnClickListener okListener,
DialogInterface.OnClickListener cancelListener) { DialogInterface.OnClickListener cancelListener) {
AlertDialog.Builder builder = new AlertDialog.Builder(context) AlertDialog.Builder builder = new AlertDialog.Builder(context).setCancelable(true)
.setCancelable(true)
.setIcon(android.R.drawable.ic_dialog_alert) .setIcon(android.R.drawable.ic_dialog_alert)
.setNegativeButton(R.string.generic_no, cancelListener) .setNegativeButton(R.string.generic_no, cancelListener)
.setPositiveButton(R.string.generic_yes, okListener) .setPositiveButton(R.string.generic_yes, okListener).setTitle(titleId);
.setTitle(R.string.generic_confirm_title);
if (messageId != -1) { if (messageId != -1) {
builder.setMessage(messageId); builder.setMessage(messageId);
} }
@@ -128,6 +128,7 @@ public class SendRequestTest extends AndroidTestCase {
parcel.writeByte((byte) 1); parcel.writeByte((byte) 1);
parcel.writeByte((byte) 1); parcel.writeByte((byte) 1);
parcel.writeByte((byte) 1); parcel.writeByte((byte) 1);
parcel.writeByte((byte) 1);
parcel.writeString(DRIVE_SHARE_EMAILS); parcel.writeString(DRIVE_SHARE_EMAILS);
parcel.writeByte((byte) 1); parcel.writeByte((byte) 1);
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE); Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
@@ -145,6 +146,7 @@ public class SendRequestTest extends AndroidTestCase {
assertTrue(sendRequest.isSendFusionTables()); assertTrue(sendRequest.isSendFusionTables());
assertTrue(sendRequest.isSendSpreadsheets()); assertTrue(sendRequest.isSendSpreadsheets());
assertTrue(sendRequest.isDriveSync()); assertTrue(sendRequest.isDriveSync());
assertTrue(sendRequest.isDriveSyncConfirm());
assertTrue(sendRequest.isDriveShare()); assertTrue(sendRequest.isDriveShare());
assertEquals(DRIVE_SHARE_EMAILS, sendRequest.getDriveShareEmails()); assertEquals(DRIVE_SHARE_EMAILS, sendRequest.getDriveShareEmails());
assertTrue(sendRequest.isDriveSharePublic()); assertTrue(sendRequest.isDriveSharePublic());
@@ -169,6 +171,7 @@ public class SendRequestTest extends AndroidTestCase {
parcel.writeByte((byte) 0); parcel.writeByte((byte) 0);
parcel.writeByte((byte) 0); parcel.writeByte((byte) 0);
parcel.writeByte((byte) 0); parcel.writeByte((byte) 0);
parcel.writeByte((byte) 0);
parcel.writeString(null); parcel.writeString(null);
parcel.writeByte((byte) 0); parcel.writeByte((byte) 0);
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE); Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
@@ -186,6 +189,7 @@ public class SendRequestTest extends AndroidTestCase {
assertFalse(sendRequest.isSendFusionTables()); assertFalse(sendRequest.isSendFusionTables());
assertFalse(sendRequest.isSendSpreadsheets()); assertFalse(sendRequest.isSendSpreadsheets());
assertFalse(sendRequest.isDriveSync()); assertFalse(sendRequest.isDriveSync());
assertFalse(sendRequest.isDriveSyncConfirm());
assertFalse(sendRequest.isDriveShare()); assertFalse(sendRequest.isDriveShare());
assertNull(sendRequest.getDriveShareEmails()); assertNull(sendRequest.getDriveShareEmails());
assertFalse(sendRequest.isDriveSharePublic()); assertFalse(sendRequest.isDriveSharePublic());
@@ -211,7 +215,8 @@ public class SendRequestTest extends AndroidTestCase {
boolean sendMaps = parcel.readByte() == 1; boolean sendMaps = parcel.readByte() == 1;
boolean sendFusionTables = parcel.readByte() == 1; boolean sendFusionTables = parcel.readByte() == 1;
boolean sendSpreadsheets = parcel.readByte() == 1; boolean sendSpreadsheets = parcel.readByte() == 1;
boolean driveEnableSync = parcel.readByte() == 1; boolean driveSync = parcel.readByte() == 1;
boolean driveSyncConfirm = parcel.readByte() == 1;
boolean driveShare = parcel.readByte() == 1; boolean driveShare = parcel.readByte() == 1;
String dirveShareEmails = parcel.readString(); String dirveShareEmails = parcel.readString();
boolean driveSharePublic = parcel.readByte() == 1; boolean driveSharePublic = parcel.readByte() == 1;
@@ -226,7 +231,8 @@ public class SendRequestTest extends AndroidTestCase {
assertFalse(sendMaps); assertFalse(sendMaps);
assertFalse(sendFusionTables); assertFalse(sendFusionTables);
assertFalse(sendSpreadsheets); assertFalse(sendSpreadsheets);
assertFalse(driveEnableSync); assertFalse(driveSync);
assertFalse(driveSyncConfirm);
assertFalse(driveShare); assertFalse(driveShare);
assertNull(dirveShareEmails); assertNull(dirveShareEmails);
assertFalse(driveSharePublic); assertFalse(driveSharePublic);
@@ -248,6 +254,7 @@ public class SendRequestTest extends AndroidTestCase {
sendRequest.setSendFusionTables(true); sendRequest.setSendFusionTables(true);
sendRequest.setSendSpreadsheets(true); sendRequest.setSendSpreadsheets(true);
sendRequest.setDriveSync(true); sendRequest.setDriveSync(true);
sendRequest.setDriveSyncConfirm(true);
sendRequest.setDriveShare(true); sendRequest.setDriveShare(true);
sendRequest.setDriveShareEmails(DRIVE_SHARE_EMAILS); sendRequest.setDriveShareEmails(DRIVE_SHARE_EMAILS);
sendRequest.setDriveSharePublic(true); sendRequest.setDriveSharePublic(true);
@@ -267,7 +274,8 @@ public class SendRequestTest extends AndroidTestCase {
boolean sendMaps = parcel.readByte() == 1; boolean sendMaps = parcel.readByte() == 1;
boolean sendFusionTables = parcel.readByte() == 1; boolean sendFusionTables = parcel.readByte() == 1;
boolean sendSpreadsheets = parcel.readByte() == 1; boolean sendSpreadsheets = parcel.readByte() == 1;
boolean driveEnableSync = parcel.readByte() == 1; boolean driveSync = parcel.readByte() == 1;
boolean driveSyncConfirm = parcel.readByte() == 1;
boolean driveShare = parcel.readByte() == 1; boolean driveShare = parcel.readByte() == 1;
String driveShareEmails = parcel.readString(); String driveShareEmails = parcel.readString();
boolean driveSharePublic = parcel.readByte() == 1; boolean driveSharePublic = parcel.readByte() == 1;
@@ -282,7 +290,8 @@ public class SendRequestTest extends AndroidTestCase {
assertTrue(sendMaps); assertTrue(sendMaps);
assertTrue(sendFusionTables); assertTrue(sendFusionTables);
assertTrue(sendSpreadsheets); assertTrue(sendSpreadsheets);
assertTrue(driveEnableSync); assertTrue(driveSync);
assertTrue(driveSyncConfirm);
assertTrue(driveShare); assertTrue(driveShare);
assertEquals(DRIVE_SHARE_EMAILS, driveShareEmails); assertEquals(DRIVE_SHARE_EMAILS, driveShareEmails);
assertTrue(driveSharePublic); assertTrue(driveSharePublic);
@@ -340,7 +340,7 @@ public class EndToEndTestUtils {
if ((getButtonOnScreen(activityMytracks.getString(R.string.eula_accept), false, false) != null)) { if ((getButtonOnScreen(activityMytracks.getString(R.string.eula_accept), false, false) != null)) {
getButtonOnScreen(activityMytracks.getString(R.string.eula_accept), true, true); getButtonOnScreen(activityMytracks.getString(R.string.eula_accept), true, true);
} }
if (SOLO.waitForText(activityMytracks.getString(R.string.sync_enable_title))) { if (SOLO.waitForText(activityMytracks.getString(R.string.sync_drive_title))) {
// Click for Sync with Google Drive(Don't enable sync as default). // Click for Sync with Google Drive(Don't enable sync as default).
getButtonOnScreen(activityMytracks.getString(R.string.generic_no), true, true); getButtonOnScreen(activityMytracks.getString(R.string.generic_no), true, true);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
@@ -428,27 +428,26 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
EndToEndTestUtils.SOLO.clickOnText(GoogleUtils.ACCOUNT_NAME_1); EndToEndTestUtils.SOLO.clickOnText(GoogleUtils.ACCOUNT_NAME_1);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.waitForText(activityMyTracks EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.settings_google_drive_sync_title)); .getString(R.string.menu_sync_drive));
assertTrue(EndToEndTestUtils.findTextView( assertTrue(EndToEndTestUtils.findTextView(
activityMyTracks.getString(R.string.settings_google_drive_sync_title)).isEnabled()); activityMyTracks.getString(R.string.menu_sync_drive)).isEnabled());
} else { } else {
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.value_none)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.value_none));
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.waitForText(activityMyTracks EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.settings_google_drive_sync_title)); .getString(R.string.menu_sync_drive));
assertFalse(EndToEndTestUtils.findTextView( assertFalse(EndToEndTestUtils.findTextView(
activityMyTracks.getString(R.string.settings_google_drive_sync_title)).isEnabled()); activityMyTracks.getString(R.string.menu_sync_drive)).isEnabled());
return; return;
} }
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
.getString(R.string.settings_google_drive_sync_title)); .getString(R.string.menu_sync_drive));
boolean isSyncChecked = false; boolean isSyncChecked = false;
if (EndToEndTestUtils.SOLO if (EndToEndTestUtils.SOLO.waitForText(
.waitForText(activityMyTracks activityMyTracks.getString(R.string.sync_drive_confirm_message).split("%")[0], 1,
.getString(R.string.settings_google_drive_sync_confirm_message).split("%")[0], 1, EndToEndTestUtils.SHORT_WAIT_TIME)) {
EndToEndTestUtils.SHORT_WAIT_TIME)) {
isSyncChecked = true; isSyncChecked = true;
} else { } else {
isSyncChecked = false; isSyncChecked = false;
@@ -203,12 +203,10 @@ public class SyncTestUtils {
CheckBox syncCheckBox = EndToEndTestUtils.SOLO.getCurrentViews(CheckBox.class).get(0); CheckBox syncCheckBox = EndToEndTestUtils.SOLO.getCurrentViews(CheckBox.class).get(0);
if (!syncCheckBox.isChecked()) { if (!syncCheckBox.isChecked()) {
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.settings_google_drive_sync_title)); .getString(R.string.menu_sync_drive));
EndToEndTestUtils.SOLO.waitForText( EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.activityMytracks.getString(
EndToEndTestUtils.activityMytracks.getString( R.string.sync_drive_confirm_message).split("%")[0], 1, EndToEndTestUtils.SHORT_WAIT_TIME);
R.string.settings_google_drive_sync_confirm_message).split("%")[0], 1,
EndToEndTestUtils.SHORT_WAIT_TIME);
Assert.assertTrue(EndToEndTestUtils.SOLO.searchText(accountName, true)); Assert.assertTrue(EndToEndTestUtils.SOLO.searchText(accountName, true));
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_yes)); .getString(R.string.generic_yes));