In the start up flow, ask the user if he wants to enable Google Drive sync.

This commit is contained in:
Jimmy Shih
2013-02-19 18:41:26 -08:00
parent ae1740cacd
commit 883596b388
7 changed files with 175 additions and 5 deletions
@@ -32,6 +32,7 @@ import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils;
import com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity;
import com.google.android.apps.mytracks.io.spreadsheets.SendSpreadsheetsActivity;
import com.google.android.apps.mytracks.io.sync.SyncUtils;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
@@ -43,6 +44,7 @@ import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
@@ -287,7 +289,19 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
private void startNextActivity() {
Class<?> next;
if (sendRequest.isSendDrive()) {
if (sendRequest.isDriveShare()) {
if (sendRequest.isDriveEnableSync()) {
PreferencesUtils.setBoolean(this, R.string.drive_sync_key, true);
// Turn off everything
SyncUtils.disableSync(this);
// Turn on sync
ContentResolver.setMasterSyncAutomatically(true);
// Enable sync for account
SyncUtils.enableSync(sendRequest.getAccount());
return;
} else if (sendRequest.isDriveShare()) {
AddEmailsDialogFragment.newInstance(sendRequest.getTrackId())
.show(getSupportFragmentManager(), AddEmailsDialogFragment.ADD_EMAILS_DIALOG_TAG);
return;
@@ -28,6 +28,8 @@ import com.google.android.apps.mytracks.fragments.ConfirmDialogFragment.ConfirmC
import com.google.android.apps.mytracks.fragments.DeleteAllTrackDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment.DeleteOneTrackCaller;
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.EulaCaller;
import com.google.android.apps.mytracks.fragments.WelcomeDialogFragment;
@@ -93,7 +95,7 @@ import java.util.Locale;
* @author Leif Hendrik Wilden
*/
public class TrackListActivity extends AbstractSendToGoogleActivity
implements EulaCaller, WelcomeCaller, ConfirmCaller, DeleteOneTrackCaller {
implements EulaCaller, WelcomeCaller, EnableSyncCaller, ConfirmCaller, DeleteOneTrackCaller {
private static final String TAG = TrackListActivity.class.getSimpleName();
private static final String START_GPS_KEY = "start_gps_key";
@@ -720,8 +722,32 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
});
if (dialog != null) {
dialog.show();
return;
}
}
showEnableSync();
}
private void showEnableSync() {
if (EulaUtils.getShowEnableSync(this)) {
Fragment fragment = getSupportFragmentManager()
.findFragmentByTag(EnableSyncDialogFragment.ENABLE_SYNC_DIALOG_TAG);
if (fragment == null) {
new EnableSyncDialogFragment().show(
getSupportFragmentManager(), EnableSyncDialogFragment.ENABLE_SYNC_DIALOG_TAG);
}
}
}
@Override
public void onEnableSyncDone(boolean enable) {
EulaUtils.setShowEnableSync(this);
if (enable) {
SendRequest sendRequest = new SendRequest(-1L);
sendRequest.setSendDrive(true);
sendRequest.setDriveEnableSync(true);
sendToGoogle(sendRequest);
}
}
/**
@@ -0,0 +1,87 @@
/*
* 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.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.
*
* @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 Dialog onCreateDialog(Bundle savedInstanceState) {
fragmentActivity = getActivity();
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
R.string.generic_cancel, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
caller.onEnableSyncDone(false);
}
}).setPositiveButton(R.string.generic_ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
caller.onEnableSyncDone(true);
}
}).setTitle(R.string.enable_sync_title).setMessage(R.string.enable_sync_message).create();
}
@Override
public void onCancel(DialogInterface arg0) {
caller.onEnableSyncDone(false);
}
}
@@ -36,6 +36,7 @@ public class SendRequest implements Parcelable {
private boolean sendFusionTables = false;
private boolean sendSpreadsheets = false;
private boolean driveEnableSync = false;
private boolean driveShare = false;
private String driveShareEmails = null;
@@ -97,6 +98,14 @@ public class SendRequest implements Parcelable {
this.sendSpreadsheets = sendSpreadsheets;
}
public boolean isDriveEnableSync() {
return driveEnableSync;
}
public void setDriveEnableSync(boolean driveEnableSync) {
this.driveEnableSync = driveEnableSync;
}
public boolean isDriveShare() {
return driveShare;
}
@@ -199,6 +208,7 @@ public class SendRequest implements Parcelable {
sendMaps = in.readByte() == 1;
sendFusionTables = in.readByte() == 1;
sendSpreadsheets = in.readByte() == 1;
driveEnableSync = in.readByte() == 1;
driveShare = in.readByte() == 1;
driveShareEmails = in.readString();
mapsShare = in.readByte() == 1;
@@ -225,6 +235,7 @@ public class SendRequest implements Parcelable {
out.writeByte((byte) (sendMaps ? 1 : 0));
out.writeByte((byte) (sendFusionTables ? 1 : 0));
out.writeByte((byte) (sendSpreadsheets ? 1 : 0));
out.writeByte((byte) (driveEnableSync ? 1 : 0));
out.writeByte((byte) (driveShare ? 1 : 0));
out.writeString(driveShareEmails);
out.writeByte((byte) (mapsShare ? 1 : 0));
@@ -31,6 +31,7 @@ public class EulaUtils {
// Accepting Google mobile terms of service
private static final String ACCEPT_EULA_PREFERENCE_KEY = "eula.google_mobile_tos_accepted";
private static final String SHOW_WELCOME_PREFERENCE_KEY = "showWelcome";
private static final String SHOW_ENABLE_SYNC_PREFERENCE_KEY = "showEnableSync";
private EulaUtils() {}
@@ -49,7 +50,15 @@ public class EulaUtils {
public static void setShowWelcome(Context context) {
setValue(context, SHOW_WELCOME_PREFERENCE_KEY, false);
}
public static boolean getShowEnableSync(Context context) {
return getValue(context, SHOW_ENABLE_SYNC_PREFERENCE_KEY, true);
}
public static void setShowEnableSync(Context context) {
setValue(context, SHOW_ENABLE_SYNC_PREFERENCE_KEY, false);
}
private static boolean getValue(Context context, String key, boolean defaultValue) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
EULA_PREFERENCE_FILE, Context.MODE_PRIVATE);