forked from upstream-mirrors/OpenTracks
merge heads
This commit is contained in:
+3
-3
@@ -54,7 +54,6 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
|||||||
private static final String APP_NAME_PREFIX = "Google-MyTracks-";
|
private static final String APP_NAME_PREFIX = "Google-MyTracks-";
|
||||||
private static final String SQL_KEY = "sql=";
|
private static final String SQL_KEY = "sql=";
|
||||||
private static final String CONTENT_TYPE = "application/x-www-form-urlencoded";
|
private static final String CONTENT_TYPE = "application/x-www-form-urlencoded";
|
||||||
private static final String SERVICE_ID = "fusiontables";
|
|
||||||
private static final String FUSION_TABLES_BASE_URL =
|
private static final String FUSION_TABLES_BASE_URL =
|
||||||
"https://www.google.com/fusiontables/api/query";
|
"https://www.google.com/fusiontables/api/query";
|
||||||
private static final int MAX_POINTS_PER_UPLOAD = 2048;
|
private static final int MAX_POINTS_PER_UPLOAD = 2048;
|
||||||
@@ -121,7 +120,8 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
|||||||
currentSegment = 1;
|
currentSegment = 1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
authToken = AccountManager.get(context).blockingGetAuthToken(account, SERVICE_ID, false);
|
authToken = AccountManager.get(context).blockingGetAuthToken(
|
||||||
|
account, SendFusionTablesUtils.SERVICE, false);
|
||||||
} catch (OperationCanceledException e) {
|
} catch (OperationCanceledException e) {
|
||||||
Log.d(TAG, "Unable to get auth token", e);
|
Log.d(TAG, "Unable to get auth token", e);
|
||||||
return retryTask();
|
return retryTask();
|
||||||
@@ -170,7 +170,7 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void invalidateToken() {
|
protected void invalidateToken() {
|
||||||
AccountManager.get(context).invalidateAuthToken(SERVICE_ID, authToken);
|
AccountManager.get(context).invalidateAuthToken(SendFusionTablesUtils.SERVICE, authToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
@@ -36,6 +36,7 @@ import java.util.Locale;
|
|||||||
*/
|
*/
|
||||||
public class SendFusionTablesUtils {
|
public class SendFusionTablesUtils {
|
||||||
|
|
||||||
|
public static final String SERVICE = "fusiontables";
|
||||||
private static final String UTF8 = "UTF8";
|
private static final String UTF8 = "UTF8";
|
||||||
private static final String TABLE_ID = "tableid";
|
private static final String TABLE_ID = "tableid";
|
||||||
private static final String MAP_URL = "https://www.google.com/fusiontables/embedviz?"
|
private static final String MAP_URL = "https://www.google.com/fusiontables/embedviz?"
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import com.google.wireless.gdata.client.GDataServiceClient;
|
|||||||
*/
|
*/
|
||||||
public class DocumentsClient extends GDataServiceClient {
|
public class DocumentsClient extends GDataServiceClient {
|
||||||
/** The name of the service, dictated to be 'wise' by the protocol. */
|
/** The name of the service, dictated to be 'wise' by the protocol. */
|
||||||
private static final String SERVICE = "writely";
|
public static final String SERVICE = "writely";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new DocumentsClient.
|
* Creates a new DocumentsClient.
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import java.io.InputStream;
|
|||||||
*/
|
*/
|
||||||
public class SpreadsheetsClient extends GDataServiceClient {
|
public class SpreadsheetsClient extends GDataServiceClient {
|
||||||
/** The name of the service, dictated to be 'wise' by the protocol. */
|
/** The name of the service, dictated to be 'wise' by the protocol. */
|
||||||
private static final String SERVICE = "wise";
|
public static final String SERVICE = "wise";
|
||||||
|
|
||||||
/** Standard base feed url for spreadsheets. */
|
/** Standard base feed url for spreadsheets. */
|
||||||
public static final String SPREADSHEETS_BASE_FEED_URL =
|
public static final String SPREADSHEETS_BASE_FEED_URL =
|
||||||
|
|||||||
+120
-6
@@ -18,6 +18,10 @@ package com.google.android.apps.mytracks.io.sendtogoogle;
|
|||||||
import com.google.android.apps.mytracks.Constants;
|
import com.google.android.apps.mytracks.Constants;
|
||||||
import com.google.android.apps.mytracks.io.docs.SendDocsActivity;
|
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.SendFusionTablesActivity;
|
||||||
|
import com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesUtils;
|
||||||
|
import com.google.android.apps.mytracks.io.gdata.docs.DocumentsClient;
|
||||||
|
import com.google.android.apps.mytracks.io.gdata.docs.SpreadsheetsClient;
|
||||||
|
import com.google.android.apps.mytracks.io.gdata.maps.MapsConstants;
|
||||||
import com.google.android.apps.mytracks.io.maps.ChooseMapActivity;
|
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.SendMapsActivity;
|
||||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||||
@@ -25,6 +29,10 @@ import com.google.android.maps.mytracks.R;
|
|||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
|
import android.accounts.AccountManagerCallback;
|
||||||
|
import android.accounts.AccountManagerFuture;
|
||||||
|
import android.accounts.AuthenticatorException;
|
||||||
|
import android.accounts.OperationCanceledException;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
@@ -34,6 +42,9 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A chooser to select an account.
|
* A chooser to select an account.
|
||||||
@@ -42,9 +53,29 @@ import android.os.Bundle;
|
|||||||
*/
|
*/
|
||||||
public class AccountChooserActivity extends Activity {
|
public class AccountChooserActivity extends Activity {
|
||||||
|
|
||||||
|
private static final String TAG = AccountChooserActivity.class.getSimpleName();
|
||||||
|
|
||||||
private static final int NO_ACCOUNT_DIALOG = 1;
|
private static final int NO_ACCOUNT_DIALOG = 1;
|
||||||
private static final int CHOOSE_ACCOUNT_DIALOG = 2;
|
private static final int CHOOSE_ACCOUNT_DIALOG = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A callback after getting the permission to access a Google service.
|
||||||
|
*
|
||||||
|
* @author Jimmy Shih
|
||||||
|
*/
|
||||||
|
private interface PermissionCallback {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To be invoked when the permission is granted.
|
||||||
|
*/
|
||||||
|
public void onSuccess();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To be invoked when the permission is not granted.
|
||||||
|
*/
|
||||||
|
public void onFailure();
|
||||||
|
}
|
||||||
|
|
||||||
private SendRequest sendRequest;
|
private SendRequest sendRequest;
|
||||||
private Account[] accounts;
|
private Account[] accounts;
|
||||||
private int selectedAccountIndex;
|
private int selectedAccountIndex;
|
||||||
@@ -56,7 +87,8 @@ public class AccountChooserActivity extends Activity {
|
|||||||
accounts = AccountManager.get(this).getAccountsByType(Constants.ACCOUNT_TYPE);
|
accounts = AccountManager.get(this).getAccountsByType(Constants.ACCOUNT_TYPE);
|
||||||
|
|
||||||
if (accounts.length == 1) {
|
if (accounts.length == 1) {
|
||||||
startNextActivity(accounts[0]);
|
sendRequest.setAccount(accounts[0]);
|
||||||
|
getPermission(MapsConstants.SERVICE_NAME, sendRequest.isSendMaps(), mapsCallback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +170,9 @@ public class AccountChooserActivity extends Activity {
|
|||||||
Editor editor = prefs.edit();
|
Editor editor = prefs.edit();
|
||||||
editor.putString(getString(R.string.preferred_account_key), account.name);
|
editor.putString(getString(R.string.preferred_account_key), account.name);
|
||||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
||||||
startNextActivity(account);
|
|
||||||
|
sendRequest.setAccount(account);
|
||||||
|
getPermission(MapsConstants.SERVICE_NAME, sendRequest.isSendMaps(), mapsCallback);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return builder.create();
|
return builder.create();
|
||||||
@@ -147,6 +181,89 @@ public class AccountChooserActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PermissionCallback spreadsheetsCallback = new PermissionCallback() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess() {
|
||||||
|
startNextActivity();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onFailure() {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private PermissionCallback docsCallback = new PermissionCallback() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess() {
|
||||||
|
getPermission(SpreadsheetsClient.SERVICE, sendRequest.isSendDocs(), spreadsheetsCallback);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onFailure() {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private PermissionCallback fusionTablesCallback = new PermissionCallback() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess() {
|
||||||
|
getPermission(DocumentsClient.SERVICE, sendRequest.isSendDocs(), docsCallback);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onFailure() {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private PermissionCallback mapsCallback = new PermissionCallback() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess() {
|
||||||
|
getPermission(
|
||||||
|
SendFusionTablesUtils.SERVICE, sendRequest.isSendFusionTables(), fusionTablesCallback);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onFailure() {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the user permission to access a service.
|
||||||
|
*
|
||||||
|
* @param authTokenType the auth token type of the service
|
||||||
|
* @param needPermission true if need the permission
|
||||||
|
* @param callback callback after getting the permission
|
||||||
|
*/
|
||||||
|
private void getPermission(
|
||||||
|
String authTokenType, boolean needPermission, final PermissionCallback callback) {
|
||||||
|
if (needPermission) {
|
||||||
|
AccountManager.get(this).getAuthToken(sendRequest.getAccount(), authTokenType, null, this,
|
||||||
|
new AccountManagerCallback<Bundle>() {
|
||||||
|
@Override
|
||||||
|
public void run(AccountManagerFuture<Bundle> future) {
|
||||||
|
try {
|
||||||
|
if (future.getResult().getString(AccountManager.KEY_AUTHTOKEN) != null) {
|
||||||
|
callback.onSuccess();
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "auth token is null");
|
||||||
|
callback.onFailure();
|
||||||
|
}
|
||||||
|
} catch (OperationCanceledException e) {
|
||||||
|
Log.d(TAG, "Unable to get auth token", e);
|
||||||
|
callback.onFailure();
|
||||||
|
} catch (AuthenticatorException e) {
|
||||||
|
Log.d(TAG, "Unable to get auth token", e);
|
||||||
|
callback.onFailure();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.d(TAG, "Unable to get auth token", e);
|
||||||
|
callback.onFailure();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
|
} else {
|
||||||
|
callback.onSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the next activity. If
|
* Starts the next activity. If
|
||||||
* <p>
|
* <p>
|
||||||
@@ -160,11 +277,8 @@ public class AccountChooserActivity extends Activity {
|
|||||||
* <p>
|
* <p>
|
||||||
* !sendMaps && !sendFusionTables && !sendDocs -> {@link UploadResultActivity}
|
* !sendMaps && !sendFusionTables && !sendDocs -> {@link UploadResultActivity}
|
||||||
*
|
*
|
||||||
* @param account the chosen account
|
|
||||||
*/
|
*/
|
||||||
private void startNextActivity(Account account) {
|
private void startNextActivity() {
|
||||||
sendRequest.setAccount(account);
|
|
||||||
|
|
||||||
Class<?> next;
|
Class<?> next;
|
||||||
if (sendRequest.isSendMaps()) {
|
if (sendRequest.isSendMaps()) {
|
||||||
next = sendRequest.isNewMap() ? SendMapsActivity.class : ChooseMapActivity.class;
|
next = sendRequest.isNewMap() ? SendMapsActivity.class : ChooseMapActivity.class;
|
||||||
|
|||||||
Reference in New Issue
Block a user